예제 #1
0
 /**
  * Adds an element to the tree. It will open a window to let the user choose which type of element
  * (legend or rule) it must be.
  */
 public void addElement() {
   TreePath tp = tree.getSelectionPath();
   if (tp == null) {
     addRule();
   } else {
     Object select = tp.getLastPathComponent();
     if (select instanceof StyleWrapper) {
       addRule();
     } else {
       addLegend();
     }
   }
   refreshIcons();
 }
예제 #2
0
  /**
   * 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);
    }
  }