/** * Add a legend to the tree, in the currently selected RuleWrapper, after the currently selected * Legend (if any in both case). A RuleWrapper will be added in the case there is none. */ private void addLegend() { LegendUIChooser legendPicker = new LegendUIChooser(simpleStyleEditor); if (UIFactory.showDialog(legendPicker)) { // Recover the panel that was selected when the user clicked OK. ILegendPanel ilp = legendPicker.getSelectedPanel(); // Get the currently selected RuleWrapper, or the last one in this // style if none is currently selected. RuleWrapper currentrw = getSelectedRule(); StyleWrapper sw = simpleStyleEditor.getStyleWrapper(); if (currentrw == null) { if (sw.getSize() == 0) { addRule(); } currentrw = sw.getRuleWrapper(sw.getSize() - 1); } // Set the Legend's name. Legend legend = ilp.getLegend(); legend .getSymbolizer() .setName(getUniqueName(legend.getLegendTypeName(), currentrw.getRule(), 0)); // Add the panel to the LegendTree. ((LegendTreeModel) tree.getModel()).addElement(currentrw, ilp, getSelectedLegend()); // Automatically select the newly added legend in the tree. TreePath selectionPath = tree.getSelectionPath(); TreePath parent; if (selectionPath.getLastPathComponent() instanceof RuleWrapper) { parent = selectionPath; } else { parent = selectionPath.getParentPath(); } tree.setSelectionPath(parent.pathByAddingChild(ilp)); // Notify the SimpleStyleEditor that a Legend has been added. simpleStyleEditor.legendAdded(ilp); } }
/** * Create the thumbnail image * * @return */ public ImageIcon getThumbnail() { ILegendPanel legendPanel = (ILegendPanel) getSelected(); String legendId = legendPanel.getLegend().getLegendTypeId(); if (legendId.equals("org.orbisgis.legend.thematic.proportional.ProportionalPoint")) { return createImageIcon("thumbnail_proportionnal_point.png"); } else if (legendId.equals("org.orbisgis.legend.thematic.proportional.ProportionalLine")) { return createImageIcon("thumbnail_proportionnal_line.png"); } else if (legendId.equals("org.orbisgis.legend.thematic.constant.UniqueSymbolPoint")) { return createImageIcon("thumbnail_unique_point.png"); } else if (legendId.equals("org.orbisgis.legend.thematic.constant.UniqueSymbolLine")) { return createImageIcon("thumbnail_unique_line.png"); } else if (legendId.equals("org.orbisgis.legend.thematic.constant.UniqueSymbolArea")) { return createImageIcon("thumbnail_unique_area.png"); } else if (legendId.equals("org.orbisgis.legend.thematic.recode.RecodedLine")) { return createImageIcon("thumbnail_recoded_line.png"); } else if (legendId.equals("org.orbisgis.legend.thematic.recode.RecodedArea")) { return createImageIcon("thumbnail_recoded_area.png"); } else if (legendId.equals("org.orbisgis.legend.thematic.recode.RecodedPoint")) { return createImageIcon("thumbnail_recoded_point.png"); } else { return createImageIcon("thumbnail_not_found.png"); } }
private Component getComponent(ILegendPanel legend, JLabel lab) { lab.setText(legend.getLegend().getName()); return lab; }