Search in sources :

Example 31 with Layer

use of com.revolsys.swing.map.layer.Layer in project com.revolsys.open by revolsys.

the class LayerTreeNode method mouseClicked.

@Override
public void mouseClicked(final MouseEvent e) {
    final Object source = e.getSource();
    final JTree tree = getTree();
    if (source == tree) {
        final int clickCount = e.getClickCount();
        if (clickCount == 2 && SwingUtilities.isLeftMouseButton(e)) {
            final int x = e.getX();
            final int y = e.getY();
            final TreePath path = tree.getPathForLocation(x, y);
            final Layer layer = getLayer();
            final TreeUI ui = tree.getUI();
            final Rectangle bounds = ui.getPathBounds(tree, path);
            final int cX = x - bounds.x;
            final int index = cX / 21;
            int offset = 0;
            if (index == offset) {
                layer.setVisible(!layer.isVisible());
            }
            offset++;
            if (layer.isSelectSupported()) {
                if (index == offset) {
                    layer.setSelectable(!layer.isSelectable());
                }
                offset++;
            }
            if (!layer.isReadOnly()) {
                if (index == offset) {
                    layer.setEditable(!layer.isEditable());
                }
                offset++;
            }
        }
        e.consume();
    }
}
Also used : JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) Rectangle(java.awt.Rectangle) Layer(com.revolsys.swing.map.layer.Layer) AbstractLayer(com.revolsys.swing.map.layer.AbstractLayer) TreeUI(javax.swing.plaf.TreeUI)

Example 32 with Layer

use of com.revolsys.swing.map.layer.Layer in project com.revolsys.open by revolsys.

the class LayerTreeNode method loadChildrenDo.

@Override
protected List<BaseTreeNode> loadChildrenDo() {
    final Layer layer = getLayer();
    final LayerRenderer<? extends Layer> renderer = layer.getRenderer();
    if (renderer == null) {
        return Collections.emptyList();
    } else {
        final LayerRendererTreeNode rendererNode = new LayerRendererTreeNode(renderer);
        return Collections.<BaseTreeNode>singletonList(rendererNode);
    }
}
Also used : BaseTreeNode(com.revolsys.swing.tree.BaseTreeNode) Layer(com.revolsys.swing.map.layer.Layer) AbstractLayer(com.revolsys.swing.map.layer.AbstractLayer)

Example 33 with Layer

use of com.revolsys.swing.map.layer.Layer in project com.revolsys.open by revolsys.

the class LayerTreeNode method refreshIcon.

public void refreshIcon() {
    Icon icon;
    final Layer layer = getLayer();
    final List<Icon> icons = new ArrayList<>();
    if (!layer.isExists() && layer.isInitialized()) {
        icon = NOT_EXISTS_ICON;
    } else {
        final Icon layerIcon = layer.getIcon();
        if (layer.getRenderer() == null) {
            Icons.addIcon(icons, layerIcon, true);
        } else {
            final boolean visible = layer.isVisible();
            Icons.addIcon(icons, layerIcon, visible);
            if (layer.isSelectSupported()) {
                final boolean selectable = layer.isSelectable();
                Icons.addIcon(icons, SELECT_ICON, selectable);
            }
        }
        if (!layer.isReadOnly()) {
            final boolean editable = layer.isEditable();
            Icons.addIcon(icons, EDIT_ICON, editable);
        }
        if (icons.isEmpty()) {
            icon = null;
        } else if (icons.size() == 1) {
            icon = icons.get(0);
        } else {
            icon = ICON_CACHE.get(icons);
            if (icon == null) {
                icon = Icons.merge(icons, 5);
                ICON_CACHE.put(icons, icon);
            }
        }
    }
    setIcon(icon);
}
Also used : ArrayList(java.util.ArrayList) Icon(javax.swing.Icon) Layer(com.revolsys.swing.map.layer.Layer) AbstractLayer(com.revolsys.swing.map.layer.AbstractLayer)

Aggregations

Layer (com.revolsys.swing.map.layer.Layer)33 AbstractLayer (com.revolsys.swing.map.layer.AbstractLayer)18 LayerGroup (com.revolsys.swing.map.layer.LayerGroup)16 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)10 ArrayList (java.util.ArrayList)8 NullLayer (com.revolsys.swing.map.layer.NullLayer)5 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)4 BaseTreeNode (com.revolsys.swing.tree.BaseTreeNode)4 List (java.util.List)4 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 Geometry (com.revolsys.geometry.model.Geometry)3 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)3 TreePath (javax.swing.tree.TreePath)3 MapPanel (com.revolsys.swing.map.MapPanel)2 BaseMapLayerGroup (com.revolsys.swing.map.layer.BaseMapLayerGroup)2 Project (com.revolsys.swing.map.layer.Project)2 ElevationModelLayer (com.revolsys.swing.map.layer.elevation.ElevationModelLayer)2 Rectangle (java.awt.Rectangle)2 JTree (javax.swing.JTree)2 TreeUI (javax.swing.plaf.TreeUI)2