nl.cloudfarming.client.geoviewer.jxmap.layerlist.LayerListPanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geoviewer-jxmap Show documentation
Show all versions of geoviewer-jxmap Show documentation
AgroSense geoviewer JXMap implementation. Contains a map/geoviewer TopComponent based on the JXMap classes from swingx.
The newest version!
/**
* Copyright (C) 2008-2012 AgroSense Foundation.
*
* AgroSense is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* There are special exceptions to the terms and conditions of the GPLv3 as it is applied to
* this software, see the FLOSS License Exception
* .
*
* AgroSense is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AgroSense. If not, see .
*/
package nl.cloudfarming.client.geoviewer.jxmap.layerlist;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.border.BevelBorder;
import net.miginfocom.swing.MigLayout;
import org.jdesktop.swingx.JXPanel;
import org.jdesktop.swingx.painter.CompoundPainter;
import org.jdesktop.swingx.painter.MattePainter;
import org.jdesktop.swingx.painter.PinstripePainter;
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.view.ListView;
import org.openide.explorer.view.NodeListModel;
/**
*
* @author Timon Veenstra
*/
public class LayerListPanel extends JXPanel implements ExplorerManager.Provider {
//TODO retrieve colors from a branded color scheme
//private static final Color COLOR_1 = new Color(191, 148, 6);
private static final Color COLOR_BASE = new Color(225, 225, 225);
private static final Color COLOR_SHADOW = new Color(150, 150, 150);
private static final Color COLOR_HIGH = new Color(210, 210, 210);
private final ListView listView = new ListView();
private final ExplorerManager explorerManager;
private JXPanel expandedListPanel;
private LayerListFoldedPanel foldedListPanel;
private JPanel mainPanel;
private CardLayout cardLayout;
private LayerListHeader header;
static final Dimension FULL_DIMENSION = new Dimension(200, 200);
static final Dimension HIDDEN_DIMENSION = new Dimension(LayerListFoldedButton.BUTTON_WIDTH+5, 200);
public LayerListPanel(final ExplorerManager explorerManager) {
// listView.setRootVisible(false);
this.explorerManager = explorerManager;
listView.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
listView.setPreferredSize(new Dimension(200, 200));
listView.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
initComponents();
}
private void initComponents() {
setOpaque(false);
expandedListPanel = new JXPanel();
expandedListPanel.setLayout(new MigLayout("wrap 1"));
setupPainters(expandedListPanel);
expandedListPanel.setBorder(new BevelBorder(BevelBorder.RAISED, COLOR_HIGH, COLOR_SHADOW));
expandedListPanel.setDoubleBuffered(true);
expandedListPanel.add(listView, "dock north");
expandedListPanel.setAlpha(.8f);
mainPanel = new JPanel();
mainPanel.setOpaque(false);
mainPanel.setPreferredSize(FULL_DIMENSION);
setLayout(new BorderLayout());
add(mainPanel, BorderLayout.CENTER);
header = new LayerListHeader(this);
add(header, BorderLayout.NORTH);
//AGROSENSE-1150 - can't find other way. need JList model to listen to changes
Component view = listView.getViewport().getView();
NodeListModel model = null;
if (view instanceof JList) {
JList list = (JList) view;
if (list.getModel() instanceof NodeListModel) {
model = (NodeListModel) list.getModel();
}
}
foldedListPanel = new LayerListFoldedPanel(explorerManager, model);
foldedListPanel.setBorder(new BevelBorder(BevelBorder.RAISED, COLOR_HIGH, COLOR_SHADOW));
cardLayout = new CardLayout();
mainPanel.setLayout(cardLayout);
mainPanel.add(expandedListPanel, "expanded");
mainPanel.add(foldedListPanel, "folded");
}
private void setupPainters(JXPanel panel) {
//Tom doesnt like the gloss :)
// GlossPainter gloss = new GlossPainter(new Color(1.0f, 1.0f, 1.0f, 0.2f),
// GlossPainter.GlossPosition.TOP);
PinstripePainter stripes = new PinstripePainter();
stripes.setPaint(new Color(1.0f, 1.0f, 1.0f, 0.17f));
stripes.setSpacing(5.0);
MattePainter matte = new MattePainter(COLOR_BASE);
panel.setBackgroundPainter(new CompoundPainter(matte,stripes));
}
@Override
public void addNotify() {
super.addNotify();
}
@Override
public ExplorerManager getExplorerManager() {
return explorerManager;
}
protected void validateComp() {
Container parent = mainPanel.getParent();
if (parent != null) {
if (parent instanceof JComponent) {
((JComponent) parent).revalidate();
} else {
parent.invalidate();
}
parent.doLayout();
parent.repaint();
}
}
public void expand() {
cardLayout.show(mainPanel, "expanded");
header.expand();
mainPanel.setPreferredSize(FULL_DIMENSION);
setPreferredSize(FULL_DIMENSION);
validateComp();
}
public void collapse() {
foldedListPanel.refresh();
mainPanel.setPreferredSize(HIDDEN_DIMENSION);
setPreferredSize(HIDDEN_DIMENSION);
cardLayout.show(mainPanel, "folded");
validateComp();
}
public void hideList() {
mainPanel.setVisible(false);
}
public void showList() {
mainPanel.setVisible(true);
}
public boolean isListHidden() {
return !mainPanel.isVisible();
}
}