Exemple #1
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();
   }
 }
Exemple #2
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();
 }
Exemple #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();
 }
Exemple #4
0
  public LegendTree(final SimpleStyleEditor simpleEditor) {
    simpleStyleEditor = simpleEditor;

    StyleWrapper style = simpleStyleEditor.getStyleWrapper();
    // We create our tree
    tree = new JTree();
    // We don't want to display the root.
    tree.setRootVisible(true);
    // We have a custom model to provide... Listeners on the TreeModel
    // are added by the tree when calling setModel.
    LegendTreeModel ltm = new LegendTreeModel(tree, style);
    tree.setModel(ltm);
    // ..A custom cell editor...
    LegendTreeCellEditor editor = new LegendTreeCellEditor();
    editor.setClickCountToStart(2);
    tree.setCellEditor(editor);
    // ...and a custom TreeCellRenderer.
    LegendCellRenderer lcr = new LegendCellRenderer(tree);
    tree.setCellRenderer(lcr);
    // We want to select only one element at a time.
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    selectAndShowFirstLegend(style);
    // We refresh icons when the selection changes.
    TreeSelectionListener tsl =
        EventHandler.create(TreeSelectionListener.class, this, "refreshIcons");
    tree.addTreeSelectionListener(tsl);
    // We refresh the CardLayout of the associated SimpleStyleEditor
    TreeSelectionListener select =
        EventHandler.create(TreeSelectionListener.class, simpleStyleEditor, "legendSelected");
    tree.addTreeSelectionListener(select);
    expandAll(tree);
    // We want an editable tree
    tree.setEditable(true);
    initButtons();
    this.setLayout(new BorderLayout());
    this.add(toolBar, BorderLayout.PAGE_START);
    JScrollPane scrollPane = new JScrollPane(tree);
    this.add(scrollPane, BorderLayout.CENTER);
    refreshIcons();
  }
Exemple #5
0
 void refresh() {
   refreshIcons();
   refreshModel();
 }