Пример #1
0
 private void addRule() {
   // We must add it just after the currently selected Rule.
   // Let's find which one it is. If there is none, we add it at the
   // end of the list.
   MultiInputPanel mip = new MultiInputPanel(I18N.tr("Choose a name for your rule"));
   mip.addInput("RuleName", I18N.tr("Name of the Rule : "), new TextBoxType(10));
   mip.addValidation(
       new MIPValidation() {
         @Override
         public String validate(MultiInputPanel mid) {
           String ruleName = mid.getInput("RuleName");
           return ruleName.isEmpty() ? I18N.tr("Rule name cannot be null or empty.") : null;
         }
       });
   if (UIFactory.showDialog(mip)) {
     String s = mip.getInput("RuleName");
     LegendTreeModel tm = (LegendTreeModel) tree.getModel();
     // We need to link our new RuleWrapper with the layer we are editing.
     Rule temp = new Rule(simpleStyleEditor.getStyleWrapper().getStyle().getLayer());
     temp.setName(s);
     Legend leg =
         LegendFactory.getLegend(temp.getCompositeSymbolizer().getSymbolizerList().get(0));
     // Initialize a panel for this legend.
     ILegendPanel ilp = ILegendPanelFactory.getILegendPanel(simpleStyleEditor, leg);
     List<ILegendPanel> list = new ArrayList<ILegendPanel>();
     list.add(ilp);
     RuleWrapper nrw = new RuleWrapper(simpleStyleEditor, temp, list);
     tm.addElement(tm.getRoot(), nrw, getSelectedRule());
     simpleStyleEditor.legendAdded(nrw.getPanel());
   }
 }
Пример #2
0
 /** Move the currently selected element (if any) down in its structure. */
 public void moveSelectedElementDown() {
   TreePath tp = tree.getSelectionPath();
   Object select = tp.getLastPathComponent();
   if (select instanceof RuleWrapper) {
     LegendTreeModel tm = (LegendTreeModel) tree.getModel();
     tm.moveElementDown(tm.getRoot(), select);
     refreshIcons();
   } else if (select instanceof ILegendPanel) {
     RuleWrapper rw = (RuleWrapper) tp.getPath()[tp.getPath().length - 2];
     LegendTreeModel tm = (LegendTreeModel) tree.getModel();
     tm.moveElementDown(rw, select);
     refreshIcons();
   }
 }
Пример #3
0
 /**
  * Removes the currently selected element from the tree. If it is an inner node, all its children
  * will be lost.
  */
 public void removeSelectedElement() {
   TreePath tp = tree.getSelectionPath();
   Object select = tp.getLastPathComponent();
   LegendTreeModel tm = (LegendTreeModel) tree.getModel();
   if (select instanceof ILegendPanel) {
     RuleWrapper rw = (RuleWrapper) tp.getPath()[tp.getPath().length - 2];
     tree.setSelectionPath(null);
     tm.removeElement(rw, select);
     // We refresh the legend container
     simpleStyleEditor.showDialogForCurrentlySelectedLegend();
     // We refresh the icons
   } else if (select instanceof RuleWrapper) {
     tree.setSelectionPath(null);
     tm.removeElement(tm.getRoot(), select);
     simpleStyleEditor.showDialogForCurrentlySelectedLegend();
   }
   refreshIcons();
 }