
it.tidalwave.metadata.viewer.MetadataViewerTopComponent Maven / Gradle / Ivy
/*******************************************************************************
*
* blueMarine - open source photo workflow
* =======================================
*
* Copyright (C) 2003-2009 by Fabrizio Giudici
* Project home page: http://bluemarine.tidalwave.it
*
*******************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*******************************************************************************
*
* $Id: MetadataViewerTopComponent.java,v b89b0b568aeb 2010/02/17 15:26:52 fabrizio $
*
******************************************************************************/
package it.tidalwave.metadata.viewer;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import org.jdesktop.swingx.JXTaskPane;
import org.openide.loaders.DataObject;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
import org.openide.util.NbBundle;
import org.openide.util.Lookup;
import it.tidalwave.util.logging.Logger;
/*******************************************************************************
*
* @author Fabrizio Giudici
* @version $Id: MetadataViewerTopComponent.java,v b89b0b568aeb 2010/02/17 15:26:52 fabrizio $
*
******************************************************************************/
public class MetadataViewerTopComponent extends TopComponent
{
private static final String CLASS = MetadataViewerTopComponent.class.getName();
private static final Logger logger = Logger.getLogger(CLASS);
private static final String PREFERRED_ID = "MetadataViewerTopComponent";
private static MetadataViewerTopComponent instance;
protected final List panelProviders = new ArrayList();
@CheckForNull
protected DataObject dataObject;
@CheckForNull
protected DataObject pendingDataObject;
protected boolean needToApplyDataObject;
/***************************************************************************
*
*
**************************************************************************/
protected MetadataViewerTopComponent()
{
initComponents();
setName(NbBundle.getMessage(MetadataViewerTopComponent.class, "CTL_MetadataViewerTopComponent"));
installUIResources();
spTaskPaneContainer.setViewportBorder(BorderFactory.createEmptyBorder());
spTaskPaneContainer.setBorder(BorderFactory.createEmptyBorder());
for (final MetadataPanelProvider panelProvider : Lookup.getDefault().lookupAll(MetadataPanelProvider.class))
{
panelProviders.add(panelProvider);
final JComponent panel = panelProvider.createPanel();
fixPanel(panel);
final JXTaskPane taskPane = new JXTaskPane();
taskPane.setTitle(panelProvider.getDisplayName());
taskPane.add(panel); // FIXME: pass the DataObject
tpTaskPaneContainer.add(taskPane);
final JComponent contentPane = (JComponent)taskPane.getContentPane();
contentPane.setBorder(BorderFactory.createEmptyBorder());
}
}
/***************************************************************************
*
*
**************************************************************************/
@Override
public int getPersistenceType()
{
return TopComponent.PERSISTENCE_ALWAYS;
}
/***************************************************************************
*
*
**************************************************************************/
@Override
public void componentShowing()
{
if (needToApplyDataObject)
{
dataObject = pendingDataObject;
applyDataObject();
needToApplyDataObject = false;
pendingDataObject = null;
}
}
/***************************************************************************
*
*
**************************************************************************/
@Override
@Nonnull
protected String preferredID()
{
return PREFERRED_ID;
}
/***************************************************************************
*
* Poor man's look and feel customization.
*
**************************************************************************/
protected void fixPanel (@Nonnull final JComponent panel)
{
}
/***************************************************************************
*
* Poor man's look and feel customization, provided by subclasses.
*
**************************************************************************/
protected void installUIResources()
{
}
/***************************************************************************
*
*
**************************************************************************/
// FIXME: move to the controller?
protected void setDataObject (@Nonnull final DataObject dataObject)
{
if (isShowing())
{
this.dataObject = dataObject;
applyDataObject();
}
else
{
pendingDataObject = dataObject;
needToApplyDataObject = true;
}
}
/***************************************************************************
*
*
**************************************************************************/
private void applyDataObject()
{
for (final MetadataPanelProvider panelProvider : panelProviders)
{
panelProvider.setDataObject(dataObject);
}
}
/***************************************************************************
*
* This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*
**************************************************************************/
// //GEN-BEGIN:initComponents
private void initComponents() {
pnHeader = new javax.swing.JPanel();
lbMetadata = new javax.swing.JLabel();
spTaskPaneContainer = new javax.swing.JScrollPane();
tpTaskPaneContainer = new org.jdesktop.swingx.JXTaskPaneContainer();
pnHeader.setMaximumSize(new java.awt.Dimension(32767, 32));
pnHeader.setMinimumSize(new java.awt.Dimension(100, 32));
pnHeader.setPreferredSize(new java.awt.Dimension(100, 32));
org.openide.awt.Mnemonics.setLocalizedText(lbMetadata, "Metadata");
org.jdesktop.layout.GroupLayout pnHeaderLayout = new org.jdesktop.layout.GroupLayout(pnHeader);
pnHeader.setLayout(pnHeaderLayout);
pnHeaderLayout.setHorizontalGroup(
pnHeaderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(pnHeaderLayout.createSequentialGroup()
.add(lbMetadata)
.addContainerGap(343, Short.MAX_VALUE))
);
pnHeaderLayout.setVerticalGroup(
pnHeaderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(lbMetadata, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
);
spTaskPaneContainer.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
spTaskPaneContainer.setViewportBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
spTaskPaneContainer.setViewportView(tpTaskPaneContainer);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(pnHeader, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, spTaskPaneContainer, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(pnHeader, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(0, 0, 0)
.add(spTaskPaneContainer, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE))
);
}// //GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
protected javax.swing.JLabel lbMetadata;
protected javax.swing.JPanel pnHeader;
protected javax.swing.JScrollPane spTaskPaneContainer;
protected org.jdesktop.swingx.JXTaskPaneContainer tpTaskPaneContainer;
// End of variables declaration//GEN-END:variables
/***************************************************************************
*
* Gets default instance. Do not use directly: reserved for *.settings files only,
* i.e. deserialization routines; otherwise you could get a non-deserialized instance.
* To obtain the singleton instance, use {@link findInstance}.
*
**************************************************************************/
@Nonnull
public static synchronized MetadataViewerTopComponent getDefault()
{
if (instance == null)
{
instance = new MetadataViewerTopComponent();
}
return instance;
}
/***************************************************************************
*
* Obtain the MetadataViewerTopComponentTopComponent instance. Never call {@link #getDefault} directly!
*
**************************************************************************/
@Nonnull
public static synchronized MetadataViewerTopComponent findInstance()
{
final TopComponent topComponent = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
if (topComponent == null)
{
Logger.getLogger(MetadataViewerTopComponent.class.getName()).warning(
"Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
return getDefault();
}
if (topComponent instanceof MetadataViewerTopComponent)
{
return (MetadataViewerTopComponent) topComponent;
}
Logger.getLogger(MetadataViewerTopComponent.class.getName()).warning(
"There seem to be multiple components with the '" + PREFERRED_ID +
"' ID. That is a potential source of errors and unexpected behavior.");
return getDefault();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy