Пример #1
0
 public void valueChanged(TreeSelectionEvent e) {
   G2DTree tree = G2DTree.this;
   Object value = getLastSelectedPathComponent();
   if (value instanceof G2DTreeNode<?>) {
     G2DTreeNode<?> node = ((G2DTreeNode<?>) value);
     node.onSelected(tree);
   }
 }
Пример #2
0
 @SuppressWarnings("unchecked")
 public static G2DTreeNode getNode(MutableTreeNode root, String name) {
   try {
     Enumeration files = root.children();
     while (files.hasMoreElements()) {
       G2DTreeNode node = (G2DTreeNode) files.nextElement();
       if (node.getName().equals(name)) {
         return node;
       }
     }
   } catch (Exception err) {
     err.printStackTrace();
   }
   return null;
 }
Пример #3
0
 @Override
 public Component getTreeCellRendererComponent(
     JTree tree,
     Object value,
     boolean sel,
     boolean expanded,
     boolean leaf,
     int row,
     boolean hasFocus) {
   Component comp =
       super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
   if (value instanceof G2DTreeNode<?>) {
     G2DTreeNode<?> node = ((G2DTreeNode<?>) value);
     ImageIcon aicon = node.getIcon(false);
     if (aicon != null) {
       setIcon(aicon);
       comp.setSize(aicon.getIconWidth(), aicon.getIconHeight());
     }
   }
   return comp;
 }
Пример #4
0
    public void mousePressed(MouseEvent e) {
      G2DTree tree = G2DTree.this;
      int selRow = getRowForLocation(e.getX(), e.getY());
      TreePath selPath = getPathForLocation(e.getX(), e.getY());

      if (selRow != -1) {
        Object obj = selPath.getLastPathComponent();

        if (obj instanceof G2DTreeNode<?>) {
          G2DTreeNode<?> node = (G2DTreeNode<?>) obj;

          if (e.getButton() == MouseEvent.BUTTON1) {
            if (e.getClickCount() == 1) {
              node.onClicked(tree, e);
            } else if (e.getClickCount() == 2) {
              node.onDoubleClicked(tree, e);
            }
          } else if (e.getButton() == MouseEvent.BUTTON3) {
            node.onRightClicked(tree, e);
          }
        }
      }
    }