예제 #1
1
  public void nextStep() {
    ArrayList<Game> selectedGames = new ArrayList<Game>();

    TreePath[] tps = this.checkboxTree.getCheckingPaths();

    for (TreePath tp : tps) {
      if (tp.getPathCount() == 3) {
        DefaultMutableTreeNode gameNode = (DefaultMutableTreeNode) tp.getLastPathComponent();
        Game g = (Game) gameNode.getUserObject();
        selectedGames.add(g);
      }
    }

    /*		for(Game g : selectedGames) {
    			System.out.println(g.getTitle() + " : " + g.getShortDescription());
    			System.out.println("-------");
    		}

    		System.out.println("####");
    */
    this.getController().setGamesToInstall(selectedGames);
    ArrayList<Game> unselectedGames = this.games;
    unselectedGames.removeAll(selectedGames);
    this.getController().setGamesToUninstall(unselectedGames);
    this.getController().nextStep();
  }
예제 #2
0
  @Override
  public void mouseMoved(MouseEvent e) {
    if (e.getSource() == browseTree) {
      browseTreeRenderer.setMousePointInTree(e.getPoint());

      TreePath path = browseTree.getPathForLocation(e.getX(), e.getY());
      if (path != null) {
        if (!(path.getLastPathComponent() instanceof ListableEntry)) return;

        ListableEntry fse = (ListableEntry) path.getLastPathComponent();
        if (fse != lastInspectedFSE || lastOnIcon != browseTreeRenderer.pointOnIcon(e.getPoint())) {
          long size = fse.getSize();
          frame.setStatusHint(fse.getName() + ": " + Util.niceSize(size));
          if (lastInspectedFSE != null)
            browseTree.repaint(browseTree.getPathBounds(lastInspectedFSE.getPath()));
          lastInspectedFSE = fse;
          lastOnIcon = browseTreeRenderer.pointOnIcon(e.getPoint());
          browseTree.repaint(browseTree.getPathBounds(path));
        }
      } else {
        if (lastInspectedFSE != null) {
          Rectangle r = browseTree.getPathBounds(lastInspectedFSE.getPath());
          lastInspectedFSE = null;
          browseTree.repaint(r);
        }
      }
    }
  }
  public void treeWillExpand(TreeExpansionEvent e) {

    // get the tree path which will be expanded
    TreePath path = e.getPath();
    if (path == null) {
      return;
    }

    // get the directory at the node
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    File selDir = (File) node.getUserObject();

    // remove old entries
    if (node.getChildCount() > 0) {
      node.removeAllChildren();
    }

    // get all the subdirectories
    File childDirs[] = selDir.listFiles(this);
    if (childDirs == null) {
      return;
    }

    // add the subdirectories
    Arrays.sort(childDirs);
    for (int i = 0; i < childDirs.length; i++) {
      if (childDirs[i].isHidden()) {
        if (showHidden) {
          node.add(new DefaultMutableTreeNode(childDirs[i]));
        }
      } else {
        node.add(new DefaultMutableTreeNode(childDirs[i]));
      }
    }
  }
예제 #4
0
 /** Updates the contents of the right panel. */
 private void updateEntryPane() {
   ViewPositions pos = Utilities.getViewPositions(entryPane);
   TreePath[] paths = treePane.getTree().getSelectionPaths();
   TreePath path = null;
   if ((paths != null) && (paths.length == 1)) {
     path = paths[0];
   }
   lastIndexTreePath = path;
   if (path != null) {
     Object node = path.getLastPathComponent();
     if (node instanceof IndexTreeNode) {
       entryPane.updateStandardIndex(((IndexTreeNode) node).getIndex());
     } else if (node instanceof VLVIndexTreeNode) {
       entryPane.updateVLVIndex(((VLVIndexTreeNode) node).getIndex());
     } else if (node == standardIndexes) {
       String backendName = (String) backends.getSelectedItem();
       entryPane.updateBackendIndexes(backendName);
     } else if (node == vlvIndexes) {
       String backendName = (String) backends.getSelectedItem();
       entryPane.updateBackendVLVIndexes(backendName);
     } else {
       entryPane.displayVoid();
     }
   } else {
     if ((paths != null) && (paths.length > 1)) {
       entryPane.displayMultiple();
     } else {
       entryPane.displayVoid();
     }
   }
   Utilities.updateViewPositions(pos);
 }
예제 #5
0
    public void valueChanged(ListSelectionEvent e) {
      if (e.getSource() == _table.getSelectionModel()) {
        _table.getPathForRow(_table.getSelectedRow());

        // is there already a highlighted part?
        if (_currentSelectedPart != null) {
          // unhighlight previous selected text
          // restoring its style
          try {
            String text =
                _hexStyledDoc.getText(
                    _currentSelectedPart.getOffset(), _currentSelectedPart.getLength());
            _hexStyledDoc.remove(
                _currentSelectedPart.getOffset(), _currentSelectedPart.getLength());
            _hexStyledDoc.insertString(
                _currentSelectedPart.getOffset(),
                text,
                _hexStyledDoc.getStyle(
                    _currentSelectedPart.getPacketNode().getModelPart().getType().getName()));
          } catch (BadLocationException e1) {
            e1.printStackTrace();
          }
        }
        TreePath tp = _table.getPathForRow(_table.getSelectedRow());
        if (tp != null && ((DataPartNode) tp.getLastPathComponent()).isLeaf()) {
          _currentSelectedPart = (DataPartNode) tp.getLastPathComponent();
          ViewPane.this.highlightSelectedPart(_currentSelectedPart);
        }
      }
    }
예제 #6
0
  /**
   * A tool group has been added. Batched adds will come through the toolsAdded method.
   *
   * @param evt The event that caused this method to be called
   */
  public void toolGroupAdded(ToolGroupEvent evt) {
    ToolGroup group = (ToolGroup) evt.getSource();
    ToolGroup tool = (ToolGroup) evt.getChild();

    TreePath path = buildTreePath(group);

    // System.out.println("group added " + group.getName() + " kid " + tool.getName());

    Object[] children = new Object[1];
    int[] indicies = new int[1];
    int index;

    ToolGroupTreeNode parent = (ToolGroupTreeNode) path.getLastPathComponent();
    ToolGroupTreeNode child = new ToolGroupTreeNode(tool, parent);
    parent.insert(child, parent.getChildCount());

    index = getIndexOfChild(parent, child);
    indicies[0] = index;
    children[0] = child;

    TreeModelEvent treeEvent = new TreeModelEvent(this, path, indicies, children);
    fireTreeNodesInserted(treeEvent);

    tool.addToolGroupListener(this);
  }
  @NotNull
  public Change[] getSelectedChanges() {
    Set<Change> changes = new LinkedHashSet<Change>();

    final TreePath[] paths = getSelectionPaths();
    if (paths == null) {
      return new Change[0];
    }

    for (TreePath path : paths) {
      ChangesBrowserNode<?> node = (ChangesBrowserNode) path.getLastPathComponent();
      changes.addAll(node.getAllChangesUnder());
    }

    if (changes.isEmpty()) {
      final List<VirtualFile> selectedModifiedWithoutEditing = getSelectedModifiedWithoutEditing();
      if (selectedModifiedWithoutEditing != null && !selectedModifiedWithoutEditing.isEmpty()) {
        for (VirtualFile file : selectedModifiedWithoutEditing) {
          AbstractVcs vcs = ProjectLevelVcsManager.getInstance(myProject).getVcsFor(file);
          if (vcs == null) continue;
          final VcsCurrentRevisionProxy before =
              VcsCurrentRevisionProxy.create(file, myProject, vcs.getKeyInstanceMethod());
          if (before != null) {
            ContentRevision afterRevision = new CurrentContentRevision(new FilePathImpl(file));
            changes.add(new Change(before, afterRevision, FileStatus.HIJACKED));
          }
        }
      }
    }

    return changes.toArray(new Change[changes.size()]);
  }
 public void removeSelectionPaths(TreePath[] paths) {
   for (int i = 0; i < paths.length; i++) {
     TreePath path = paths[i];
     if (path.getPathCount() == 1) super.removeSelectionPaths(new TreePath[] {path});
     else toggleRemoveSelection(path);
   }
 }
 @Override
 public Object getData(String dataId) {
   if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
     TreePath[] paths = getSelectionPaths();
     if (paths == null) return null;
     final ArrayList<Navigatable> navigatables = new ArrayList<Navigatable>();
     for (TreePath path : paths) {
       Object lastPathComponent = path.getLastPathComponent();
       if (lastPathComponent instanceof DefaultMutableTreeNode) {
         DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastPathComponent;
         Object userObject = node.getUserObject();
         if (userObject instanceof Navigatable) {
           navigatables.add((Navigatable) userObject);
         } else if (node instanceof Navigatable) {
           navigatables.add((Navigatable) node);
         }
       }
     }
     if (navigatables.isEmpty()) {
       return null;
     } else {
       return navigatables.toArray(new Navigatable[navigatables.size()]);
     }
   }
   if (myTreeStructure instanceof AbstractTreeStructureBase) {
     return ((AbstractTreeStructureBase) myTreeStructure)
         .getDataFromProviders(getSelectedNodes(AbstractTreeNode.class), dataId);
   }
   return null;
 }
예제 #10
0
 // todo eliminate code duplication in BaseLogicalViewProjectPane
 private <T extends TreeNode> T getSelectedTreeNode(Class<T> nodeClass) {
   TreePath selectionPath = getTree().getSelectionPath();
   if (selectionPath == null) return null;
   Object selectedNode = selectionPath.getLastPathComponent();
   if (!(nodeClass.isInstance(selectedNode))) return null;
   return (T) selectedNode;
 }
예제 #11
0
 /** Returns whether the given path is currently checked. */
 public boolean isChecked(TreePath path) {
   if (isExplicitlyChecked(path)) {
     return true;
   } else {
     return path.getParentPath() != null && isChecked(path.getParentPath());
   }
 }
예제 #12
0
  public void mouseClicked(MouseEvent me) {
    TreePath path = tree.getPathForLocation(me.getX(), me.getY());
    if (path == null) return;
    if (me.getX() > tree.getPathBounds(path).x + hotspot) return;

    OIDObject oo = null;

    if (path.getLastPathComponent() instanceof LazyOIDTreeNode) {
      oo = (OIDObject) ((LazyOIDTreeNode) path.getLastPathComponent()).getUserObject();
    } else if (path.getLastPathComponent() instanceof DefaultMutableTreeNode) {
      oo = (OIDObject) ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
    }

    if (!oo.isActive()) {
      return;
    }

    tree.clearSelection();
    boolean selected = selectionModel.isPathSelected(path, true);
    selectionModel.removeTreeSelectionListener(this);

    try {
      if (selected) selectionModel.removeSelectionPath(path);
      else selectionModel.addSelectionPath(path);
    } finally {
      selectionModel.addTreeSelectionListener(this);
      tree.treeDidChange();
      otsl.valueChanged();
    }
  }
    /**
     * Called whenever the value of the selection changes.
     *
     * @param e the event that characterizes the change.
     */
    public void valueChanged(final TreeSelectionEvent e) {
      addExpandedNode(getRowForPath(e.getPath()));

      if (updateFromExternalSource) {
        return;
      }

      updateFromInternalSource = true;
      try {
        final ReportDocumentContext renderContext = getRenderContext();
        if (renderContext == null) {
          return;
        }

        final TreePath[] treePaths = getSelectionPaths();
        if (treePaths == null) {
          selectionModel.clearSelection();
          renderContext.getSelectionModel().clearSelection();
          return;
        }

        final DocumentContextSelectionModel selectionModel = renderContext.getSelectionModel();
        final Object[] data = new Object[treePaths.length];
        for (int i = 0; i < treePaths.length; i++) {
          final TreePath path = treePaths[i];
          data[i] = path.getLastPathComponent();
        }
        selectionModel.setSelectedElements(data);
      } finally {
        updateFromInternalSource = false;
      }
    }
예제 #14
0
  /**
   * When called it will traverse all visible leaves in the browseTree and collapse them if they
   * have been open for too long and are not selected.
   */
  private void collapseOldNodes() {
    Stack<ListableEntry> toConsider =
        new Stack<
            ListableEntry>(); // this is a stack of expanded nodes that need their children (and
                              // themselves) to be considered.
    toConsider.push(fs.getBrowseRoot()); // we know these are always expanded, and uncollapsable.
    toConsider.push(fs.getSearchRoot()); // "               "                    "

    // a) mark all uncollapsable nodes
    TreePath[] selecteds = browseTree.getSelectionPaths();
    if (selecteds != null) {
      for (TreePath selected : selecteds) {
        for (Object toMark :
            selected.getPath()) { // a selected nodes and their ancestors are not collapsable.
          expandedTimes.put(toMark, System.currentTimeMillis());
        }
      }
    }

    // b) collapse old expanded nodes.
    while (!toConsider.empty()) {
      for (FileSystemEntry child : toConsider.pop().getAllChildren()) {
        if (browseTree.isExpanded(child.getPath())) {
          toConsider.push(child);
          if (System.currentTimeMillis() - expandedTimes.get(child)
              > FS2Constants.CLIENT_BROWSETREE_COLLAPSE_INTERVAL) {
            browseTree.collapsePath(child.getPath());
            expandedTimes.remove(child);
          }
        }
      }
    }
  }
  @Override
  public void valueChanged(TreeSelectionEvent e) {
    TreePath newLeadSelectionPath = e.getNewLeadSelectionPath();
    if (newLeadSelectionPath == null) {
      return;
    }
    Object lastPathComponent = newLeadSelectionPath.getLastPathComponent();
    if (lastPathComponent instanceof ValueSourceTreeNode) {

      valueSourceNode = (ValueSourceTreeNode) lastPathComponent;
      // get the selected PVC
      ValueSource selectedValueSource = (ValueSource) valueSourceNode.getUserObject();

      if (selectedValueSource == currentValueSource) {
        return;
      }

      // change current PlotValueConfig
      currentValueSource = selectedValueSource;

      adaptGUI();
    } else {
      currentValueSource = null;
      valueSourceNode = null;
    }
  }
예제 #16
0
    @Override
    public void mouseClicked(MouseEvent event) {
      JTree tree = (JTree) event.getSource();
      int x = event.getX();
      int y = event.getY();
      int row = tree.getRowForLocation(x, y);
      TreePath path = tree.getPathForRow(row);

      if (path != null) {
        CheckBoxTreeNode node = (CheckBoxTreeNode) path.getLastPathComponent();

        if (node != null) {
          boolean isSelected = !node.isSelected();
          node.setSelected(isSelected);
          ((DefaultTreeModel) tree.getModel()).nodeStructureChanged(node);
        }
      }

      // 查看整棵树的选择项
      for (int i = 0; i < tree.getRowCount(); i++) {
        TreePath treePath = tree.getPathForRow(i);
        CheckBoxTreeNode treeNode = (CheckBoxTreeNode) treePath.getLastPathComponent();

        if (treeNode.getUserObject() instanceof ServerConfigForModel) {
          if (treeNode.isSelected) {
            filter.setServerId(((ServerConfigForModel) treeNode.getUserObject()).getId());
          } else {
            filter.removeServerId(((ServerConfigForModel) treeNode.getUserObject()).getId());
          }
        }
      }
      filterOpcItem();
    }
  private TreePath find2(JTree tree, TreePath parent, Village pNode, int depth) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    DefaultMutableTreeNode o = (DefaultMutableTreeNode) node;

    // If equal, go down the branch
    if (o.getUserObject().equals(pNode)) {
      // If at end, return match
      return parent;
    } else {
      // Traverse children
      if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children(); e.hasMoreElements(); ) {
          TreeNode n = (TreeNode) e.nextElement();
          TreePath path = parent.pathByAddingChild(n);
          TreePath result = find2(tree, path, pNode, depth + 1);
          // Found a match
          if (result != null) {
            return result;
          }
        }
      }
    }
    // No match at this branch
    return null;
  }
예제 #18
0
 @Override
 public String getToolTipText(MouseEvent evt) {
   Point p = evt.getPoint();
   TreePath tp = getClosestPathForLocation(p.x, p.y);
   Object node = tp.getLastPathComponent();
   if (node instanceof PlaylistTreeNode) {
     PlaylistTreeNode ptn = (PlaylistTreeNode) node;
     int unseen = ptn.numUnseenTracks;
     if (unseen > 0) {
       String nt = numItems(unseen, "new track");
       if (ptn.hasComments) {
         // html allows us to have linebreaks
         return "<html>" + nt + "<br>Unread comments</html>";
       } else return nt;
     }
     if (ptn.hasComments) return "Unread comments";
   } else if (node instanceof LibraryTreeNode) {
     LibraryTreeNode ltn = (LibraryTreeNode) node;
     int unseen = ltn.numUnseenTracks;
     if (unseen > 0) {
       String nt = numItems(unseen, "new track");
       if (ltn.hasComments) {
         // html allows us to have linebreaks
         return "<html>" + nt + "<br>Unread comments</html>";
       } else return nt;
     }
     if (ltn.hasComments) return "Unread comments";
   }
   return null;
 }
  public int getRowForPath(final TreePath path) {
    if (!isVisible(path)) {
      return -1;
    }

    VariableHeightStateNode correspondingNode = (VariableHeightStateNode) getStateNodeForPath(path);
    if (correspondingNode != null) {
      return correspondingNode.getRow();
    }

    VariableHeightStateNode parent =
        (VariableHeightStateNode) getStateNodeForPath(path.getParentPath());

    int modelIndex = parent.getModelIndexOfChild(path.getLastPathComponent());
    int rowIncrement = 0;
    for (int i = 0; i < modelIndex; i++) {
      rowIncrement++;

      Object modelNode = parent.getModelChildNode(i);
      StateNode childNode = parent.getChild(modelNode);
      if (childNode != null) {
        rowIncrement += childNode.getTotalChildrenCount();
      }
    }
    return parent.getRow() + rowIncrement + 1;
  }
  private void addNodeToTree(
      JTree.DropLocation dropLocation,
      LayerTreeModel model,
      INode node,
      boolean alreadyInTree,
      int offset) {
    TreePath p = dropLocation.getPath();
    boolean noparent = p == null;
    INode parent = null;
    int index = 0;

    if (!noparent) {
      parent = (INode) p.getLastPathComponent();
      index = dropLocation.getChildIndex();

      if (index < 0) index = parent.getChildCount();
      else index += offset;
    }

    if (alreadyInTree) {
      if (!noparent) {
        if (node == parent || nodeAncestorOf(node, parent)) return;
        if (node.getParent() == parent && index > model.getIndexOfChild(parent, node)) index--;
      }

      model.removeNodeFromParent(node, false);
    }

    if (noparent) model.addToRoot(node, true);
    else model.insertNodeInto(node, parent, index, true);
  }
 private CheckedTreeNode getSelectedNode() {
   TreePath selectionPath = myTree.getSelectionPath();
   if (selectionPath != null) {
     return (CheckedTreeNode) selectionPath.getLastPathComponent();
   }
   return null;
 }
  @Override
  protected Transferable createTransferable(JComponent source) {
    dropLocation = null;

    if (source == null) return null;

    TreeTransferable t = null;
    if (source == layersTree) {
      TreePath[] dragPaths = layersTree.getSelectionPaths();
      if (dragPaths != null) {
        t = new TreeTransferable(layersTree, dragPaths);
      }
    } else if (source == datasetTree) {
      TreePath[] dragPaths = datasetTree.getSelectionPaths();
      if (dragPaths != null) {
        List<TreePath> paths = new ArrayList<TreePath>();

        for (TreePath dragPath : dragPaths) {
          Object o = dragPath.getLastPathComponent();
          if (o != null && o instanceof DefaultMutableTreeNode) {
            Object uo = ((DefaultMutableTreeNode) o).getUserObject();
            if (uo != null && uo instanceof ILayerDefinition) paths.add(dragPath);
          }
        }

        if (!paths.isEmpty()) {
          TreePath[] p = paths.toArray(new TreePath[paths.size()]);
          t = new TreeTransferable(datasetTree, p);
        }
      }
    }
    return t;
  }
예제 #23
0
 public void valueChanged(TreeSelectionEvent e) {
   TreePath tp = e.getNewLeadSelectionPath();
   if (tp == null) return;
   Object selNode = tp.getLastPathComponent();
   if (selNode instanceof ButtonTreeNode) {
     ButtonTreeNode btn = (ButtonTreeNode) selNode;
     btn.onClick();
     setSelectionPath(e.getOldLeadSelectionPath());
     return;
   }
   if (!(selNode instanceof SelectableTreeNode)) return;
   SelectableTreeNode stn = (SelectableTreeNode) selNode;
   if (stn.wantSelect()) {
     sideBar.clearSelectionExcept(FriendTree.this);
     // If this is a library or playlist node with comments, and the comments tab is showing,
     // mark the
     // comments as read
     FriendTreeModel m = getModel();
     if (stn instanceof LibraryTreeNode) {
       LibraryTreeNode ltn = (LibraryTreeNode) stn;
       ContentPanel cp = frame.mainPanel.getContentPanel("library/" + ltn.userId);
       // library content panel gets created on demand, so might be null
       if (cp != null && cp.tabPane.getSelectedIndex() == 1)
         m.markLibraryCommentsAsRead(ltn.userId);
     } else if (stn instanceof PlaylistTreeNode) {
       PlaylistTreeNode ptn = (PlaylistTreeNode) stn;
       long plId = ptn.getPlaylist().getPlaylistId();
       ContentPanel cp = frame.mainPanel.getContentPanel("playlist/" + plId);
       if (cp.tabPane.getSelectedIndex() == 1) m.markPlaylistCommentsAsRead(plId);
     }
     if (stn.handleSelect()) m.firePathToRootChanged(stn);
   } else setSelectionPath(e.getOldLeadSelectionPath());
 }
예제 #24
0
  private void updateSelectionFromTree() {
    TreePath[] treePaths = myTree.getSelectionPaths();
    if (treePaths != null) {
      List<NamedConfigurable> selectedConfigurables = new ArrayList<NamedConfigurable>();
      for (TreePath path : treePaths) {
        Object lastPathComponent = path.getLastPathComponent();
        if (lastPathComponent instanceof MyNode) {
          selectedConfigurables.add(((MyNode) lastPathComponent).getConfigurable());
        }
      }
      if (selectedConfigurables.size() > 1 && updateMultiSelection(selectedConfigurables)) {
        return;
      }
    }

    final TreePath path = myTree.getSelectionPath();
    if (path != null) {
      final Object lastPathComp = path.getLastPathComponent();
      if (!(lastPathComp instanceof MyNode)) return;
      final MyNode node = (MyNode) lastPathComp;
      setSelectedNode(node);
    } else {
      setSelectedNode(null);
    }
  }
예제 #25
0
  private void selectInCallTree(JipMethod selectedMethod) {

    if (selectedMethod == null) {
      mCallTree.clearSelection();
      return;
    }

    // is this method already selected?
    TreePath curPath = mCallTree.getSelectionPath();
    if (curPath != null) {
      TreeNode curNode = (TreeNode) curPath.getLastPathComponent();
      JipMethod curMethod = curNode.getMethodOrNull();
      if (curMethod != null && curMethod.equals(selectedMethod)) {
        // we're done.
        return;
      }
    }

    TreePath newPath = mCallTreeRoot.findPathForMethod(selectedMethod);
    if (newPath == null) {
      System.out.println("no path to " + selectedMethod);
      return;
    }

    mCallTree.setSelectionPath(newPath);
    mCallTree.scrollPathToVisible(newPath);
  }
 private void syncBrowser() {
   if (myTree.getSelectionModel().getSelectionCount() != 1) {
     myBrowser.showEmpty();
   } else {
     TreePath pathSelected = myTree.getSelectionModel().getLeadSelectionPath();
     if (pathSelected != null) {
       final InspectionTreeNode node = (InspectionTreeNode) pathSelected.getLastPathComponent();
       if (node instanceof RefElementNode) {
         final RefElementNode refElementNode = (RefElementNode) node;
         final CommonProblemDescriptor problem = refElementNode.getProblem();
         final RefEntity refSelected = refElementNode.getElement();
         if (problem != null) {
           showInBrowser(refSelected, problem);
         } else {
           showInBrowser(refSelected);
         }
       } else if (node instanceof ProblemDescriptionNode) {
         final ProblemDescriptionNode problemNode = (ProblemDescriptionNode) node;
         showInBrowser(problemNode.getElement(), problemNode.getDescriptor());
       } else if (node instanceof InspectionNode) {
         showInBrowser(((InspectionNode) node).getToolWrapper());
       } else {
         myBrowser.showEmpty();
       }
     }
   }
 }
 @Override
 public void keyPressed(KeyEvent e) {
   TreePath path = myTree.getLeadSelectionPath();
   if (path == null) return;
   final Object lastComponent = path.getLastPathComponent();
   if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     if (lastComponent instanceof ParentNode) return;
     doOKAction();
     e.consume();
   } else if (e.getKeyCode() == KeyEvent.VK_INSERT) {
     if (lastComponent instanceof ElementNode) {
       final DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent;
       if (!mySelectedNodes.contains(node)) {
         if (node.getNextNode() != null) {
           myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
         }
       } else {
         if (node.getNextNode() != null) {
           myTree.removeSelectionPath(new TreePath(node.getPath()));
           myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
           myTree.repaint();
         }
       }
       e.consume();
     }
   }
 }
 private static boolean isMoveSupported(JTree tree, int dir) {
   final TreePath[] selectionPaths = tree.getSelectionPaths();
   if (selectionPaths != null) {
     DefaultMutableTreeNode parent = null;
     for (TreePath treePath : selectionPaths)
       if (treePath.getLastPathComponent() != null) {
         final DefaultMutableTreeNode node =
             (DefaultMutableTreeNode) treePath.getLastPathComponent();
         if (parent == null) {
           parent = (DefaultMutableTreeNode) node.getParent();
         }
         if (parent != node.getParent()) {
           return false;
         }
         if (dir > 0) {
           if (parent.getIndex(node) == parent.getChildCount() - 1) {
             return false;
           }
         } else {
           if (parent.getIndex(node) == 0) {
             return false;
           }
         }
       }
     return true;
   }
   return false;
 }
예제 #29
0
  @Override
  public void valueChanged(TreeSelectionEvent e) {
    if (e.getSource() == colors && !locked) {
      TreeSelectionModel tsm = colors.getSelectionModel();
      TreePath tp[] = tsm.getSelectionPaths();
      if (tp == null) return;
      Vector<ClassedItem> tmp = new Vector<ClassedItem>();
      for (TreePath element : tp) {
        try {
          Object[] path = element.getPath();
          ClassedItem ci = new ClassedItem(path[1].toString(), path[2].toString());
          tmp.add(ci);
        } catch (Exception exp) {
          // User did not select a leafnode
        }
      }

      if (sceneElement instanceof NenyaImageSceneElement) {
        ((NenyaImageSceneElement) sceneElement).setColorList(tmp.toArray(new ClassedItem[0]));
      }
      if (sceneElement instanceof NenyaTileSceneElement) {
        ((NenyaTileSceneElement) sceneElement).setColorList(tmp.toArray(new ClassedItem[0]));
      }
      if (sceneElement instanceof NenyaComponentSceneElement) {
        ((NenyaComponentSceneElement) sceneElement)
            .getComponents()[itemList.getSelectedIndex()].setColorList(
                tmp.toArray(new ClassedItem[0]));
      }

      submitElement(sceneElement, null);
    } else {
      super.valueChanged(e);
    }
  }
 /*
  * Drop Event Handlers
  */
 private TreeNode getNodeForEvent(DropTargetDragEvent dtde) {
   Point p = dtde.getLocation();
   DropTargetContext dtc = dtde.getDropTargetContext();
   JTree tree = (JTree) dtc.getComponent();
   TreePath path = tree.getClosestPathForLocation(p.x, p.y);
   return (TreeNode) path.getLastPathComponent();
 }