Esempio n. 1
0
  public static void dropSelectionButUnderPoint(JTree tree, Point treePoint) {
    final TreePath toRetain = tree.getPathForLocation(treePoint.x, treePoint.y);
    if (toRetain == null) return;

    TreePath[] selection = tree.getSelectionModel().getSelectionPaths();
    selection = selection == null ? new TreePath[0] : selection;
    for (TreePath each : selection) {
      if (toRetain.equals(each)) continue;
      tree.getSelectionModel().removeSelectionPath(each);
    }
  }
Esempio n. 2
0
    public ReplicatedTreeView(ReplicatedTree tree, Object title) throws Exception {
      this.tree = tree;
      tree.addReplicatedTreeListener(this);

      addNotify();
      setTitle("ReplicatedTreeDemo: mbr=" + title);

      tree_model = new DefaultTreeModel(root);
      jtree = new JTree(tree_model);
      jtree.setDoubleBuffered(true);
      jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

      JScrollPane scroll_pane = new JScrollPane(jtree);

      populateTree();

      getContentPane().add(scroll_pane, BorderLayout.CENTER);
      addWindowListener(this);

      table_model.setColumnIdentifiers(new String[] {"Name", "Value"});
      table_model.addTableModelListener(this);

      setTableColumnWidths();

      tablePanel = new JPanel();
      tablePanel.setLayout(new BorderLayout());
      tablePanel.add(table.getTableHeader(), BorderLayout.NORTH);
      tablePanel.add(table, BorderLayout.CENTER);

      getContentPane().add(tablePanel, BorderLayout.SOUTH);

      jtree.addTreeSelectionListener(this); // REVISIT

      MouseListener ml =
          new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
              int selRow = jtree.getRowForLocation(e.getX(), e.getY());
              TreePath selPath = jtree.getPathForLocation(e.getX(), e.getY());
              if (selRow != -1) {
                selected_node = makeFQN(selPath.getPath());
                jtree.setSelectionPath(selPath);

                if (e.getModifiers() == java.awt.event.InputEvent.BUTTON3_MASK) {
                  operationsPopup.show(e.getComponent(), e.getX(), e.getY());
                }
              }
            }
          };

      jtree.addMouseListener(ml);

      createMenus();
      setLocation(50, 50);
      setSize(
          getInsets().left + getInsets().right + 485, getInsets().top + getInsets().bottom + 367);

      init();
      setVisible(true);
    }
  private static void printImpl(
      JTree tree,
      Object root,
      Collection<String> strings,
      int level,
      boolean withSelection,
      @Nullable Condition<String> nodePrintCondition) {
    DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) root;

    final Object userObject = defaultMutableTreeNode.getUserObject();
    String nodeText;
    if (userObject != null) {
      nodeText = toString(userObject, null);
    } else {
      nodeText = "null";
    }

    if (nodePrintCondition != null && !nodePrintCondition.value(nodeText)) return;

    final StringBuilder buff = new StringBuilder();
    StringUtil.repeatSymbol(buff, ' ', level);

    final boolean expanded = tree.isExpanded(new TreePath(defaultMutableTreeNode.getPath()));
    if (!defaultMutableTreeNode.isLeaf()) {
      buff.append(expanded ? "-" : "+");
    }

    final boolean selected =
        tree.getSelectionModel().isPathSelected(new TreePath(defaultMutableTreeNode.getPath()));
    if (withSelection && selected) {
      buff.append("[");
    }

    buff.append(nodeText);

    if (withSelection && selected) {
      buff.append("]");
    }

    strings.add(buff.toString());

    int childCount = tree.getModel().getChildCount(root);
    if (expanded) {
      for (int i = 0; i < childCount; i++) {
        printImpl(
            tree,
            tree.getModel().getChild(root, i),
            strings,
            level + 1,
            withSelection,
            nodePrintCondition);
      }
    }
  }
 private void restoreUsageExpandState(final Collection<UsageState> states) {
   // always expand the last level group
   final DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTree.getModel().getRoot();
   for (int i = root.getChildCount() - 1; i >= 0; i--) {
     final DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt(i);
     if (child instanceof GroupNode) {
       final TreePath treePath = new TreePath(child.getPath());
       myTree.expandPath(treePath);
     }
   }
   myTree.getSelectionModel().clearSelection();
   for (final UsageState usageState : states) {
     usageState.restore();
   }
 }
Esempio n. 5
0
  public void uninstallUI(JComponent c) {
    HelpModel helpmodel = searchnav.getModel();

    searchnav.removeComponentListener(this);
    searchnav.removePropertyChangeListener(this);
    TreeSelectionModel tsm = tree.getSelectionModel();
    tsm.removeTreeSelectionListener(this);
    searchnav.setLayout(null);
    searchnav.removeAll();

    if (helpmodel != null) {
      helpmodel.removeHelpModelListener(this);
    }
    searchnav = null;
  }
  /**
   * Initialize the common user interface components.
   *
   * <p>
   */
  protected JButton[] initUI(
      String title, JComponent extraComps, String confirm, String[][] extra, String cancel) {
    JButton[] extraBtns = null;

    /* create dialog body components */
    {
      JPanel body = new JPanel();
      body.setName("MainDialogPanel");

      body.setLayout(new BoxLayout(body, BoxLayout.Y_AXIS));

      body.add(UIFactory.createPanelLabel("Existing Layouts:"));

      body.add(Box.createRigidArea(new Dimension(0, 4)));

      {
        DefaultMutableTreeNode root = new DefaultMutableTreeNode(new TreeData(), true);
        DefaultTreeModel model = new DefaultTreeModel(root, true);

        JTree tree = new JFancyTree(model);
        pTree = tree;
        tree.setName("DarkTree");

        tree.setCellRenderer(new JLayoutTreeCellRenderer());
        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

        {
          JScrollPane scroll =
              UIFactory.createScrollPane(
                  pTree,
                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED,
                  ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                  new Dimension(230, 120),
                  new Dimension(230, 150),
                  null);

          body.add(scroll);
        }
      }

      if (extraComps != null) body.add(extraComps);

      extraBtns = super.initUI(title, body, confirm, null, extra, cancel);
    }

    return extraBtns;
  }
    public static Image createImage(final JTree tree) {
      final TreeSelectionModel model = tree.getSelectionModel();
      final TreePath[] paths = model.getSelectionPaths();

      int count = 0;
      final List<ChangesBrowserNode> nodes = new ArrayList<ChangesBrowserNode>();
      for (final TreePath path : paths) {
        final ChangesBrowserNode node = (ChangesBrowserNode) path.getLastPathComponent();
        if (!node.isLeaf()) {
          nodes.add(node);
          count += node.getCount();
        }
      }

      for (TreePath path : paths) {
        final ChangesBrowserNode element = (ChangesBrowserNode) path.getLastPathComponent();
        boolean child = false;
        for (final ChangesBrowserNode node : nodes) {
          if (node.isNodeChild(element)) {
            child = true;
            break;
          }
        }

        if (!child) {
          if (element.isLeaf()) count++;
        } else if (!element.isLeaf()) {
          count -= element.getCount();
        }
      }

      final JLabel label = new JLabel(VcsBundle.message("changes.view.dnd.label", count));
      label.setOpaque(true);
      label.setForeground(tree.getForeground());
      label.setBackground(tree.getBackground());
      label.setFont(tree.getFont());
      label.setSize(label.getPreferredSize());
      final BufferedImage image =
          new BufferedImage(label.getWidth(), label.getHeight(), BufferedImage.TYPE_INT_ARGB);

      Graphics2D g2 = (Graphics2D) image.getGraphics();
      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
      label.paint(g2);
      g2.dispose();

      return image;
    }
  protected JTree createTree() {
    myFileSystemTree = new FileSystemTreeImpl(myProject, myChooserDescriptor);
    Disposer.register(myDisposable, myFileSystemTree);

    myFileSystemTree.addOkAction(
        new Runnable() {
          public void run() {
            doOKAction();
          }
        });
    JTree tree = myFileSystemTree.getTree();
    tree.setCellRenderer(new NodeRenderer());
    tree.getSelectionModel().addTreeSelectionListener(new FileTreeSelectionListener());
    tree.addTreeExpansionListener(new FileTreeExpansionListener());
    setOKActionEnabled(false);

    myFileSystemTree.addListener(
        new FileSystemTree.Listener() {
          public void selectionChanged(final List<VirtualFile> selection) {
            updatePathFromTree(selection, false);
          }
        },
        myDisposable);

    new FileDrop(
        tree,
        new FileDrop.Target() {
          public FileChooserDescriptor getDescriptor() {
            return myChooserDescriptor;
          }

          public boolean isHiddenShown() {
            return myFileSystemTree.areHiddensShown();
          }

          public void dropFiles(final List<VirtualFile> files) {
            if (!myChooserDescriptor.isChooseMultiple() && files.size() > 0) {
              selectInTree(new VirtualFile[] {files.get(0)}, true);
            } else {
              selectInTree(VfsUtilCore.toVirtualFileArray(files), true);
            }
          }
        });

    return tree;
  }
  /**
   * constructor that accepts a parent container. the parent will have methods that are required to
   * update the interface by communicating with the OLS webservice.
   */
  public TreeBrowser(OntologyBrowserDemo parent) {

    super(new GridLayout(1, 0));

    this.parent = parent;

    tree =
        new JTree(
            new DefaultTreeModel(
                new DefaultMutableTreeNode(new TermNode("Load Ontology to Browse", null))));
    tree.setEditable(false);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setShowsRootHandles(true);
    tree.addTreeSelectionListener(this);

    JScrollPane scrollPane = new JScrollPane(tree);
    add(scrollPane);
  }
 @NotNull
 private Collection<DefaultMutableTreeNode> getSelectedNodes() {
   if (!isValid()) {
     return Collections.emptyList();
   }
   JTree tree = myStructureViewComponent.getTree();
   if (tree == null) return Collections.emptyList();
   TreePath[] selected = tree.getSelectionModel().getSelectionPaths();
   if (selected == null || selected.length == 0) return Collections.emptyList();
   return ContainerUtil.map(
       selected,
       new Function<TreePath, DefaultMutableTreeNode>() {
         @Override
         public DefaultMutableTreeNode fun(TreePath treePath) {
           return (DefaultMutableTreeNode) treePath.getLastPathComponent();
         }
       });
 }
 private void captureUsagesExpandState(TreePath pathFrom, final Collection<UsageState> states) {
   if (!myTree.isExpanded(pathFrom)) {
     return;
   }
   final DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathFrom.getLastPathComponent();
   final int childCount = node.getChildCount();
   for (int idx = 0; idx < childCount; idx++) {
     final TreeNode child = node.getChildAt(idx);
     if (child instanceof UsageNode) {
       final Usage usage = ((UsageNode) child).getUsage();
       states.add(
           new UsageState(
               usage,
               myTree.getSelectionModel().isPathSelected(pathFrom.pathByAddingChild(child))));
     } else {
       captureUsagesExpandState(pathFrom.pathByAddingChild(child), states);
     }
   }
 }
Esempio n. 12
0
  /** Constructor. */
  public DatasetTreeView() {
    // the catalog tree
    tree =
        new JTree() {
          public JToolTip createToolTip() {
            return new MultilineTooltip();
          }
        };
    tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode(null, false)));
    tree.setCellRenderer(new MyTreeCellRenderer());

    tree.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            int selRow = tree.getRowForLocation(e.getX(), e.getY());
            if (selRow != -1) {
              TreeNode node = (TreeNode) tree.getLastSelectedPathComponent();
              if (node instanceof VariableNode) {
                VariableIF v = ((VariableNode) node).var;
                firePropertyChangeEvent(new PropertyChangeEvent(this, "Selection", null, v));
              }
            }

            if ((selRow != -1) && (e.getClickCount() == 2)) {
              // acceptSelected();
            }
          }
        });

    tree.putClientProperty("JTree.lineStyle", "Angled");
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setToggleClickCount(1);
    ToolTipManager.sharedInstance().registerComponent(tree);

    // layout
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);
  }
Esempio n. 13
0
  public void installUI(JComponent c) {
    searchnav = (JHelpSearchNavigator) c;
    HelpModel helpmodel = searchnav.getModel();

    searchnav.setLayout(new BorderLayout());
    searchnav.addPropertyChangeListener(this);
    searchnav.addComponentListener(this);
    if (helpmodel != null) {
      helpmodel.addHelpModelListener(this);
    }

    JLabel search =
        new JLabel(HelpUtilities.getString(HelpUtilities.getLocale(c), "search.findLabel"));
    searchparams = new JTextField("", 20);
    search.setLabelFor(searchparams);
    searchparams.addActionListener(searchAction);

    JPanel box = new JPanel();
    box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
    box.add(search);
    box.add(searchparams);

    searchnav.add("North", box);
    topNode = new DefaultMutableTreeNode();
    lastTOCnode = null;
    tree = new JTree(topNode);
    // public String convertValueToText(Object val
    TreeSelectionModel tsm = tree.getSelectionModel();
    tsm.addTreeSelectionListener(this);
    tree.setShowsRootHandles(false);
    tree.setRootVisible(false);
    sp = new JScrollPane();
    sp.getViewport().add(tree);
    searchnav.add("Center", sp);
    reloadData();
  }
Esempio n. 14
0
  public static ActionCallback showAndSelect(
      final JTree tree,
      int top,
      int bottom,
      final int row,
      final int previous,
      boolean addToSelection,
      final boolean scroll) {
    final TreePath path = tree.getPathForRow(row);

    if (path == null) return new ActionCallback.Done();

    final int size = tree.getRowCount();
    if (size == 0) {
      tree.clearSelection();
      return new ActionCallback.Done();
    }
    if (top < 0) {
      top = 0;
    }
    if (bottom >= size) {
      bottom = size - 1;
    }

    if (row >= tree.getRowCount()) return new ActionCallback.Done();

    if (!tree.isValid()) {
      tree.validate();
    }

    final Rectangle rowBounds = tree.getRowBounds(row);
    if (rowBounds == null) return new ActionCallback.Done();

    Rectangle topBounds = tree.getRowBounds(top);
    if (topBounds == null) {
      topBounds = rowBounds;
    }

    Rectangle bottomBounds = tree.getRowBounds(bottom);
    if (bottomBounds == null) {
      bottomBounds = rowBounds;
    }

    Rectangle bounds = topBounds.union(bottomBounds);
    bounds.x = rowBounds.x;
    bounds.width = rowBounds.width;

    final Rectangle visible = tree.getVisibleRect();
    if (visible.contains(bounds)) {
      bounds = null;
    } else {
      final Component comp =
          tree.getCellRenderer()
              .getTreeCellRendererComponent(
                  tree, path.getLastPathComponent(), true, true, false, row, false);

      if (comp instanceof SimpleColoredComponent) {
        final SimpleColoredComponent renderer = ((SimpleColoredComponent) comp);
        final Dimension scrollableSize = renderer.computePreferredSize(true);
        bounds.width = scrollableSize.width;
      }
    }

    final ActionCallback callback = new ActionCallback();

    if (!tree.isRowSelected(row)) {
      if (addToSelection) {
        tree.getSelectionModel().addSelectionPath(tree.getPathForRow(row));
      } else {
        tree.setSelectionRow(row);
      }
    }

    if (bounds != null) {
      final Range<Integer> range = getExpandControlRange(tree, path);
      if (range != null) {
        int delta = bounds.x - range.getFrom().intValue();
        bounds.x -= delta;
        bounds.width -= delta;
      }

      if (visible.width < bounds.width) {
        bounds.width = visible.width;
      }

      final Rectangle b1 = bounds;
      final Runnable runnable =
          new Runnable() {
            public void run() {
              if (scroll) {
                tree.scrollRectToVisible(b1);
              }
              callback.setDone();
            }
          };

      if (ApplicationManager.getApplication().isUnitTestMode()) {
        runnable.run();
      } else {
        SwingUtilities.invokeLater(runnable);
      }
    } else {
      callback.setDone();
    }

    return callback;
  }
Esempio n. 15
0
  public JComponent buildLeft() {
    String colSpec = FormLayoutUtil.getColSpec(LEFT_COL_SPEC, orientation);
    FormLayout layout = new FormLayout(colSpec, LEFT_ROW_SPEC);
    PanelBuilder builder = new PanelBuilder(layout);
    builder.setBorder(Borders.EMPTY_BORDER);
    builder.setOpaque(false);

    CellConstraints cc = new CellConstraints();

    JButton but = new JButton(LooksFrame.readImageIcon("kdevelop_down-32.png"));
    but.setToolTipText(Messages.getString("TrTab2.6"));
    but.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            TreePath path = tree.getSelectionModel().getSelectionPath();
            if (path != null && path.getLastPathComponent() instanceof TreeNodeSettings) {
              TreeNodeSettings node = ((TreeNodeSettings) path.getLastPathComponent());
              if (node.getPlayer() != null) {
                DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel(); // get the tree model
                // now get the index of the selected node in the DefaultTreeModel
                int index = dtm.getIndexOfChild(node.getParent(), node);
                // if selected node is first, return (can't move it up)
                if (index < node.getParent().getChildCount() - 1) {
                  dtm.insertNodeInto(
                      node, (DefaultMutableTreeNode) node.getParent(), index + 1); // move the node
                  dtm.reload();
                  for (int i = 0; i < tree.getRowCount(); i++) {
                    tree.expandRow(i);
                  }
                  tree.getSelectionModel().setSelectionPath(new TreePath(node.getPath()));
                  updateEngineModel();
                }
              }
            }
          }
        });
    builder.add(but, FormLayoutUtil.flip(cc.xy(2, 3), colSpec, orientation));

    JButton but2 = new JButton(LooksFrame.readImageIcon("up-32.png"));
    but2.setToolTipText(Messages.getString("TrTab2.6"));
    but2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            TreePath path = tree.getSelectionModel().getSelectionPath();
            if (path != null && path.getLastPathComponent() instanceof TreeNodeSettings) {
              TreeNodeSettings node = ((TreeNodeSettings) path.getLastPathComponent());
              if (node.getPlayer() != null) {
                DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel(); // get the tree model
                // now get the index of the selected node in the DefaultTreeModel
                int index = dtm.getIndexOfChild(node.getParent(), node);
                // if selected node is first, return (can't move it up)
                if (index != 0) {
                  dtm.insertNodeInto(
                      node, (DefaultMutableTreeNode) node.getParent(), index - 1); // move the node
                  dtm.reload();
                  for (int i = 0; i < tree.getRowCount(); i++) {
                    tree.expandRow(i);
                  }
                  tree.getSelectionModel().setSelectionPath(new TreePath(node.getPath()));
                  updateEngineModel();
                }
              }
            }
          }
        });
    builder.add(but2, FormLayoutUtil.flip(cc.xy(3, 3), colSpec, orientation));

    JButton but3 = new JButton(LooksFrame.readImageIcon("connect_no-32.png"));
    but3.setToolTipText(Messages.getString("TrTab2.0"));
    but3.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            TreePath path = tree.getSelectionModel().getSelectionPath();
            if (path != null
                && path.getLastPathComponent() instanceof TreeNodeSettings
                && ((TreeNodeSettings) path.getLastPathComponent()).getPlayer() != null) {
              ((TreeNodeSettings) path.getLastPathComponent())
                  .setEnable(!((TreeNodeSettings) path.getLastPathComponent()).isEnable());
              updateEngineModel();
              tree.updateUI();
            }
          }
        });
    builder.add(but3, FormLayoutUtil.flip(cc.xy(4, 3), colSpec, orientation));

    DefaultMutableTreeNode root = new DefaultMutableTreeNode(Messages.getString("TrTab2.11"));
    TreeNodeSettings commonEnc =
        new TreeNodeSettings(Messages.getString("TrTab2.5"), null, buildCommon());
    commonEnc
        .getConfigPanel()
        .addComponentListener(
            new ComponentAdapter() {
              @Override
              public void componentShown(ComponentEvent e) {
                handleCardComponentChange(e.getComponent());
              }
            });
    tabbedPane.add(commonEnc.id(), commonEnc.getConfigPanel());
    root.add(commonEnc);

    parent = new DefaultMutableTreeNode[5];
    parent[0] = new DefaultMutableTreeNode(Messages.getString("TrTab2.14"));
    parent[1] = new DefaultMutableTreeNode(Messages.getString("TrTab2.15"));
    parent[2] = new DefaultMutableTreeNode(Messages.getString("TrTab2.16"));
    parent[3] = new DefaultMutableTreeNode(Messages.getString("TrTab2.17"));
    parent[4] = new DefaultMutableTreeNode(Messages.getString("TrTab2.18"));
    root.add(parent[0]);
    root.add(parent[1]);
    root.add(parent[2]);
    root.add(parent[3]);
    root.add(parent[4]);

    tree =
        new JTree(new DefaultTreeModel(root)) {
          private static final long serialVersionUID = -6703434752606636290L;
        };
    tree.setRootVisible(false);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addTreeSelectionListener(
        new TreeSelectionListener() {
          @Override
          public void valueChanged(TreeSelectionEvent e) {
            if (e.getNewLeadSelectionPath() != null
                && e.getNewLeadSelectionPath().getLastPathComponent() instanceof TreeNodeSettings) {
              TreeNodeSettings tns =
                  (TreeNodeSettings) e.getNewLeadSelectionPath().getLastPathComponent();
              cl.show(tabbedPane, tns.id());
            }
          }
        });

    tree.setCellRenderer(new TreeRenderer());
    JScrollPane pane =
        new JScrollPane(
            tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

    builder.add(pane, FormLayoutUtil.flip(cc.xyw(2, 1, 4), colSpec, orientation));

    builder.addLabel(
        Messages.getString("TrTab2.19"),
        FormLayoutUtil.flip(cc.xyw(2, 5, 4), colSpec, orientation));
    builder.addLabel(
        Messages.getString("TrTab2.20"),
        FormLayoutUtil.flip(cc.xyw(2, 7, 4), colSpec, orientation));

    JPanel panel = builder.getPanel();

    // Apply the orientation to the panel and all components in it
    panel.applyComponentOrientation(orientation);

    return panel;
  }
  @Override
  public boolean onStart() {
    window = new JFrame("Interface Explorer");
    treeModel = new InterfaceTreeModel();
    treeModel.update("");
    tree = new JTree(treeModel);
    tree.setRootVisible(false);
    tree.setEditable(false);
    renderer = new HighlightTreeCellRenderer(tree.getCellRenderer());
    tree.setCellRenderer(renderer);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addTreeSelectionListener(
        new TreeSelectionListener() {
          private void addInfo(final String key, final String value, final boolean highlight) {
            final JPanel row = new JPanel();
            row.setAlignmentX(Component.LEFT_ALIGNMENT);
            row.setLayout(new BoxLayout(row, BoxLayout.X_AXIS));
            for (final String data : new String[] {key, value}) {
              final JLabel label = new JLabel(data);
              label.setAlignmentY(Component.TOP_ALIGNMENT);
              if (highlight) {
                label.setForeground(Color.magenta);
              }
              row.add(label);
            }
            infoArea.add(row);
          }

          public void valueChanged(final TreeSelectionEvent e) {
            final Object node = tree.getLastSelectedPathComponent();
            if (node == null || node instanceof RSInterfaceWrap) {
              return;
            }
            infoArea.removeAll();
            RSComponent iface = null;
            if (node instanceof RSComponentWrap) {
              iface = ((RSComponentWrap) node).wrapped;
            }
            if (iface == null) {
              return;
            }
            List<Integer> changes = new ArrayList<Integer>();
            for (int i = 0; i < HighLightWraps.size(); i++) {
              if (iface.getParent() == null) {
                if (HighLightWraps.get(i).getChild().getIndex() == iface.getIndex()
                    && HighLightWraps.get(i).getParent().getIndex()
                        == iface.getInterface().getIndex()) {
                  changes.add(HighLightWraps.get(i).getChange());
                }
              } else {
                if (HighLightWraps.get(i).getChild().getIndex() == iface.getParent().getIndex()
                    && HighLightWraps.get(i).getParent().getIndex()
                        == iface.getParent().getInterface().getIndex()) {
                  changes.add(HighLightWraps.get(i).getChange());
                }
              }
            }
            addInfo("Type: ", "" + iface.getType(), changes.contains(1));
            addInfo("SpecialType: ", "" + iface.getSpecialType(), changes.contains(2));
            addInfo("Bounds Index: ", "" + iface.getBoundsArrayIndex(), changes.contains(3));
            if (iface.getArea() != null) {
              Rectangle size = iface.getArea();
              addInfo("Size: ", size.width + "," + size.height, changes.contains(15));
            }
            addInfo("Model ID: ", "" + iface.getModelID(), changes.contains(4));
            addInfo("Texture ID: ", "" + iface.getBackgroundColor(), changes.contains(5));
            addInfo("Parent ID: ", "" + iface.getParentID(), changes.contains(6));
            addInfo("Text: ", "" + iface.getText(), changes.contains(7));
            addInfo("Tooltip: ", "" + iface.getTooltip(), changes.contains(8));
            addInfo("SelActionName: ", "" + iface.getSelectedActionName(), changes.contains(9));
            if (iface.getActions() != null) {
              String actions = "";
              for (final String action : iface.getActions()) {
                if (!actions.equals("")) {
                  actions += "\n";
                }
                actions += action;
              }
              addInfo("Actions: ", actions, changes.contains(10));
            }
            addInfo("Component ID: ", "" + iface.getComponentID(), changes.contains(11));
            addInfo(
                "Component Stack Size: ", "" + iface.getComponentStackSize(), changes.contains(12));
            addInfo(
                "Relative Location: ",
                "(" + iface.getRelativeX() + "," + iface.getRelativeY() + ")",
                changes.contains(13));
            addInfo(
                "Absolute Location: ",
                "(" + iface.getAbsoluteX() + "," + iface.getAbsoluteY() + ")",
                changes.contains(14));
            addInfo(
                "Rotation: ",
                "x: "
                    + iface.getXRotation()
                    + "  y: "
                    + iface.getYRotation()
                    + "  z: "
                    + iface.getZRotation(),
                changes.contains(16));
            setHighlightArea(iface.getArea());
            infoArea.validate();
            infoArea.repaint();
          }
        });
    final JDialog Help = new JDialog();
    JScrollPane jScrollPane1;
    JTextArea jTextArea1;
    jScrollPane1 = new JScrollPane();
    jTextArea1 = new JTextArea();
    Help.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    Help.setTitle("Help");
    Help.setResizable(false);
    jTextArea1.setColumns(20);
    jTextArea1.setEditable(false);
    jTextArea1.setFont(new java.awt.Font("MS UI Gothic", 0, 12));
    jTextArea1.setLineWrap(true);
    jTextArea1.setRows(5);
    jTextArea1.setText(
        "Once toggled the listener feature of the interface explorer will detect any changes made to Runescapes interfaces in realtime. If a change is found that interface and data will then be highlighted within the explorers tree model. To use the listener feature you would :\n\n1) Toggle the listener button as active\n2) Wait or commit changes in Runescape\n3) Repaint tree using repaint button or reclick interface folders in GUI\n\n\nTips : While listening for changes the tree model in the GUI will not update itself, changing colors. To refresh the GUI either use the repaint button or close and open Interface folder already within the tree model.");
    jTextArea1.setWrapStyleWord(true);
    jScrollPane1.setViewportView(jTextArea1);
    final GroupLayout layout = new GroupLayout(Help.getContentPane());
    Help.getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
                    .addContainerGap()));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(
                        jScrollPane1, GroupLayout.PREFERRED_SIZE, 220, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    Help.pack();
    JScrollPane scrollPane = new JScrollPane(tree);
    scrollPane.setPreferredSize(new Dimension(250, 500));
    window.add(scrollPane, BorderLayout.WEST);
    infoArea = new JPanel();
    infoArea.setLayout(new BoxLayout(infoArea, BoxLayout.Y_AXIS));
    scrollPane = new JScrollPane(infoArea);
    scrollPane.setPreferredSize(new Dimension(250, 500));
    window.add(scrollPane, BorderLayout.CENTER);
    final ActionListener actionListener =
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            treeModel.update(searchBox.getText());
            infoArea.removeAll();
            infoArea.validate();
            infoArea.repaint();
          }
        };
    final ActionListener toggleListener =
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            if (listenerButton.isSelected()) {
              log("Cleared");
              HighLightWraps.clear();
            }
            check();
          }
        };
    final ActionListener repaintListener =
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            log("Refreshed Tree");
            treeModel.fireTreeStructureChanged(treeModel.getRoot());
            infoArea.removeAll();
            infoArea.validate();
            infoArea.repaint();
          }
        };
    final ActionListener helpListener =
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            Help.setVisible(true);
          }
        };
    final JPanel toolArea = new JPanel();
    toolArea.setLayout(new FlowLayout(FlowLayout.LEFT));
    toolArea.add(new JLabel("Filter:"));
    searchBox = new JTextField(20);
    searchBox.addActionListener(actionListener);
    toolArea.add(searchBox);
    final JButton updateButton = new JButton("Update");
    final JButton repaintButton = new JButton("Repaint");
    final JButton helpButton = new JButton("Help");
    helpButton.addActionListener(helpListener);
    listenerButton.addActionListener(toggleListener);
    updateButton.addActionListener(actionListener);
    repaintButton.addActionListener(repaintListener);
    toolArea.add(updateButton);
    toolArea.add(listenerButton);
    toolArea.add(repaintButton);
    toolArea.add(helpButton);
    window.add(toolArea, BorderLayout.NORTH);
    window.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    window.pack();
    window.setVisible(true);
    return true;
  }
  public CustomizableActionsPanel() {

    //noinspection HardCodedStringLiteral
    Group rootGroup = new Group("root", null, null);
    final DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootGroup);
    DefaultTreeModel model = new DefaultTreeModel(root);
    myActionsTree.setModel(model);

    myActionsTree.setRootVisible(false);
    myActionsTree.setShowsRootHandles(true);
    UIUtil.setLineStyleAngled(myActionsTree);
    myActionsTree.setCellRenderer(new MyTreeCellRenderer());

    setButtonsDisabled();
    final ActionManager actionManager = ActionManager.getInstance();
    myActionsTree
        .getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              public void valueChanged(TreeSelectionEvent e) {
                final TreePath[] selectionPaths = myActionsTree.getSelectionPaths();
                final boolean isSingleSelection =
                    selectionPaths != null && selectionPaths.length == 1;
                myAddActionButton.setEnabled(isSingleSelection);
                if (isSingleSelection) {
                  final DefaultMutableTreeNode node =
                      (DefaultMutableTreeNode) selectionPaths[0].getLastPathComponent();
                  String actionId = getActionId(node);
                  if (actionId != null) {
                    final AnAction action = actionManager.getAction(actionId);
                    myEditIconButton.setEnabled(
                        action != null && action.getTemplatePresentation() != null);
                  } else {
                    myEditIconButton.setEnabled(false);
                  }
                } else {
                  myEditIconButton.setEnabled(false);
                }
                myAddSeparatorButton.setEnabled(isSingleSelection);
                myRemoveActionButton.setEnabled(selectionPaths != null);
                if (selectionPaths != null) {
                  for (TreePath selectionPath : selectionPaths) {
                    if (selectionPath.getPath() != null && selectionPath.getPath().length <= 2) {
                      setButtonsDisabled();
                      return;
                    }
                  }
                }
                myMoveActionUpButton.setEnabled(isMoveSupported(myActionsTree, -1));
                myMoveActionDownButton.setEnabled(isMoveSupported(myActionsTree, 1));
                myRestoreDefaultButton.setEnabled(!findActionsUnderSelection().isEmpty());
              }
            });

    myAddActionButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree);
            final TreePath selectionPath = myActionsTree.getLeadSelectionPath();
            if (selectionPath != null) {
              DefaultMutableTreeNode node =
                  (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
              final FindAvailableActionsDialog dlg = new FindAvailableActionsDialog();
              dlg.show();
              if (dlg.isOK()) {
                final Set<Object> toAdd = dlg.getTreeSelectedActionIds();
                if (toAdd == null) return;
                for (final Object o : toAdd) {
                  final ActionUrl url =
                      new ActionUrl(
                          ActionUrl.getGroupPath(new TreePath(node.getPath())),
                          o,
                          ActionUrl.ADDED,
                          node.getParent().getIndex(node) + 1);
                  addCustomizedAction(url);
                  ActionUrl.changePathInActionsTree(myActionsTree, url);
                  if (o instanceof String) {
                    DefaultMutableTreeNode current = new DefaultMutableTreeNode(url.getComponent());
                    current.setParent((DefaultMutableTreeNode) node.getParent());
                    editToolbarIcon((String) o, current);
                  }
                }
                ((DefaultTreeModel) myActionsTree.getModel()).reload();
              }
            }
            TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths);
          }
        });

    myEditIconButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            myRestoreAllDefaultButton.setEnabled(true);
            final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree);
            final TreePath selectionPath = myActionsTree.getLeadSelectionPath();
            if (selectionPath != null) {
              EditIconDialog dlg =
                  new EditIconDialog((DefaultMutableTreeNode) selectionPath.getLastPathComponent());
              dlg.show();
              if (dlg.isOK()) {
                myActionsTree.repaint();
              }
            }
            TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths);
          }
        });

    myAddSeparatorButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree);
            final TreePath selectionPath = myActionsTree.getLeadSelectionPath();
            if (selectionPath != null) {
              DefaultMutableTreeNode node =
                  (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
              final ActionUrl url =
                  new ActionUrl(
                      ActionUrl.getGroupPath(selectionPath),
                      Separator.getInstance(),
                      ActionUrl.ADDED,
                      node.getParent().getIndex(node) + 1);
              ActionUrl.changePathInActionsTree(myActionsTree, url);
              addCustomizedAction(url);
              ((DefaultTreeModel) myActionsTree.getModel()).reload();
            }
            TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths);
          }
        });

    myRemoveActionButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree);
            final TreePath[] selectionPath = myActionsTree.getSelectionPaths();
            if (selectionPath != null) {
              for (TreePath treePath : selectionPath) {
                final ActionUrl url = CustomizationUtil.getActionUrl(treePath, ActionUrl.DELETED);
                ActionUrl.changePathInActionsTree(myActionsTree, url);
                addCustomizedAction(url);
              }
              ((DefaultTreeModel) myActionsTree.getModel()).reload();
            }
            TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths);
          }
        });

    myMoveActionUpButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree);
            final TreePath[] selectionPath = myActionsTree.getSelectionPaths();
            if (selectionPath != null) {
              for (TreePath treePath : selectionPath) {
                final ActionUrl url = CustomizationUtil.getActionUrl(treePath, ActionUrl.MOVE);
                final int absolutePosition = url.getAbsolutePosition();
                url.setInitialPosition(absolutePosition);
                url.setAbsolutePosition(absolutePosition - 1);
                ActionUrl.changePathInActionsTree(myActionsTree, url);
                addCustomizedAction(url);
              }
              ((DefaultTreeModel) myActionsTree.getModel()).reload();
              TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths);
              for (TreePath path : selectionPath) {
                myActionsTree.addSelectionPath(path);
              }
            }
          }
        });

    myMoveActionDownButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree);
            final TreePath[] selectionPath = myActionsTree.getSelectionPaths();
            if (selectionPath != null) {
              for (int i = selectionPath.length - 1; i >= 0; i--) {
                TreePath treePath = selectionPath[i];
                final ActionUrl url = CustomizationUtil.getActionUrl(treePath, ActionUrl.MOVE);
                final int absolutePosition = url.getAbsolutePosition();
                url.setInitialPosition(absolutePosition);
                url.setAbsolutePosition(absolutePosition + 1);
                ActionUrl.changePathInActionsTree(myActionsTree, url);
                addCustomizedAction(url);
              }
              ((DefaultTreeModel) myActionsTree.getModel()).reload();
              TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths);
              for (TreePath path : selectionPath) {
                myActionsTree.addSelectionPath(path);
              }
            }
          }
        });

    myRestoreAllDefaultButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            mySelectedSchema.copyFrom(new CustomActionsSchema());
            patchActionsTreeCorrespondingToSchema(root);
            myRestoreAllDefaultButton.setEnabled(false);
          }
        });

    myRestoreDefaultButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List<ActionUrl> otherActions =
                new ArrayList<ActionUrl>(mySelectedSchema.getActions());
            otherActions.removeAll(findActionsUnderSelection());
            mySelectedSchema.copyFrom(new CustomActionsSchema());
            for (ActionUrl otherAction : otherActions) {
              mySelectedSchema.addAction(otherAction);
            }
            final List<TreePath> treePaths = TreeUtil.collectExpandedPaths(myActionsTree);
            patchActionsTreeCorrespondingToSchema(root);
            restorePathsAfterTreeOptimization(treePaths);
            myRestoreDefaultButton.setEnabled(false);
          }
        });

    patchActionsTreeCorrespondingToSchema(root);

    myTreeExpansionMonitor = TreeExpansionMonitor.install(myActionsTree);
  }
    protected JComponent createCenterPanel() {
      Group rootGroup =
          ActionsTreeUtil.createMainGroup(
              null, null, QuickListsManager.getInstance().getAllQuickLists());
      DefaultMutableTreeNode root = ActionsTreeUtil.createNode(rootGroup);
      DefaultTreeModel model = new DefaultTreeModel(root);
      myTree = new Tree();
      myTree.setModel(model);
      myTree.setCellRenderer(new MyTreeCellRenderer());
      final ActionManager actionManager = ActionManager.getInstance();

      mySetIconButton = new JButton(IdeBundle.message("button.set.icon"));
      mySetIconButton.setEnabled(false);
      mySetIconButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              final TreePath selectionPath = myTree.getSelectionPath();
              if (selectionPath != null) {
                doSetIcon(
                    (DefaultMutableTreeNode) selectionPath.getLastPathComponent(),
                    myTextField.getText(),
                    getContentPane());
                myTree.repaint();
              }
            }
          });
      myTextField = createBrowseField();
      myTextField
          .getTextField()
          .getDocument()
          .addDocumentListener(
              new DocumentAdapter() {
                protected void textChanged(DocumentEvent e) {
                  enableSetIconButton(actionManager);
                }
              });
      JPanel northPanel = new JPanel(new BorderLayout());
      northPanel.add(myTextField, BorderLayout.CENTER);
      final JLabel label = new JLabel(IdeBundle.message("label.icon.path"));
      label.setLabelFor(myTextField.getChildComponent());
      northPanel.add(label, BorderLayout.WEST);
      northPanel.add(mySetIconButton, BorderLayout.EAST);
      northPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
      JPanel panel = new JPanel(new BorderLayout());
      panel.add(northPanel, BorderLayout.NORTH);

      panel.add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER);
      myTree
          .getSelectionModel()
          .addTreeSelectionListener(
              new TreeSelectionListener() {
                public void valueChanged(TreeSelectionEvent e) {
                  enableSetIconButton(actionManager);
                  final TreePath selectionPath = myTree.getSelectionPath();
                  if (selectionPath != null) {
                    final DefaultMutableTreeNode node =
                        (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
                    final String actionId = getActionId(node);
                    if (actionId != null) {
                      final String iconPath = mySelectedSchema.getIconPath(actionId);
                      myTextField.setText(FileUtil.toSystemDependentName(iconPath));
                    }
                  }
                }
              });
      return panel;
    }
Esempio n. 19
0
  public ActionsTree() {
    myRoot = new DefaultMutableTreeNode(ROOT);

    myTree =
        new Tree(new MyModel(myRoot)) {
          @Override
          public void paint(Graphics g) {
            super.paint(g);
            Rectangle visibleRect = getVisibleRect();
            Rectangle clip = g.getClipBounds();
            for (int row = 0; row < getRowCount(); row++) {
              Rectangle rowBounds = getRowBounds(row);
              rowBounds.x = 0;
              rowBounds.width = Integer.MAX_VALUE;

              if (rowBounds.intersects(clip)) {
                Object node = getPathForRow(row).getLastPathComponent();

                if (node instanceof DefaultMutableTreeNode) {
                  Object data = ((DefaultMutableTreeNode) node).getUserObject();
                  Rectangle fullRowRect =
                      new Rectangle(
                          visibleRect.x, rowBounds.y, visibleRect.width, rowBounds.height);
                  paintRowData(this, data, fullRowRect, (Graphics2D) g);
                }
              }
            }
          }
        };
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);

    myTree.putClientProperty(WideSelectionTreeUI.STRIPED_CLIENT_PROPERTY, Boolean.TRUE);
    myTree.setCellRenderer(new KeymapsRenderer());
    myTree.addMouseMotionListener(
        new MouseMotionAdapter() {
          @Override
          public void mouseMoved(MouseEvent e) {
            String description = getDescription(e);
            if (description != null) {
              ActionMenu.showDescriptionInStatusBar(true, myTree, description);
            } else {
              ActionMenu.showDescriptionInStatusBar(false, myTree, null);
            }
          }

          @Nullable
          private String getDescription(@NotNull MouseEvent e) {
            TreePath path = myTree.getPathForLocation(e.getX(), e.getY());
            if (path == null) return null;

            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            if (node == null) return null;

            Object userObject = node.getUserObject();
            if (!(userObject instanceof String)) return null;

            String actionId = (String) userObject;
            AnAction action = ActionManager.getInstance().getActionOrStub(actionId);
            if (action == null) return null;

            return action.getTemplatePresentation().getDescription();
          }
        });

    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    myComponent =
        ScrollPaneFactory.createScrollPane(
            myTree,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  }
Esempio n. 20
0
 public void addTreeSelectionListener(TreeSelectionListener l) {
   myTree.getSelectionModel().addTreeSelectionListener(l);
 }
Esempio n. 21
0
 public static boolean isOverSelection(final JTree tree, final Point point) {
   TreePath path = tree.getPathForLocation(point.x, point.y);
   return path != null && tree.getSelectionModel().isPathSelected(path);
 }
  /**
   * Constructs a X509 certificate panel.
   *
   * @param certificates <tt>X509Certificate</tt> objects
   */
  public X509CertificatePanel(Certificate[] certificates) {
    setLayout(new BorderLayout(5, 5));

    // Certificate chain list
    TransparentPanel topPanel = new TransparentPanel(new BorderLayout());
    topPanel.add(
        new JLabel(
            "<html><body><b>"
                + R.getI18NString("service.gui.CERT_INFO_CHAIN")
                + "</b></body></html>"),
        BorderLayout.NORTH);

    DefaultMutableTreeNode top = new DefaultMutableTreeNode();
    DefaultMutableTreeNode previous = top;
    for (int i = certificates.length - 1; i >= 0; i--) {
      Certificate cert = certificates[i];
      DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert);
      previous.add(next);
      previous = next;
    }
    JTree tree = new JTree(top);
    tree.setBorder(new BevelBorder(BevelBorder.LOWERED));
    tree.setRootVisible(false);
    tree.setExpandsSelectedPaths(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setCellRenderer(
        new DefaultTreeCellRenderer() {

          @Override
          public Component getTreeCellRendererComponent(
              JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            JLabel component =
                (JLabel)
                    super.getTreeCellRendererComponent(
                        tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
              Object o = ((DefaultMutableTreeNode) value).getUserObject();
              if (o instanceof X509Certificate) {
                component.setText(getSimplifiedName((X509Certificate) o));
              } else {
                // We don't know how to represent this certificate type,
                // let's use the first 20 characters
                String text = o.toString();
                if (text.length() > 20) {
                  text = text.substring(0, 20);
                }
                component.setText(text);
              }
            }
            return component;
          }
        });
    tree.getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {

              @Override
              public void valueChanged(TreeSelectionEvent e) {
                valueChangedPerformed(e);
              }
            });
    tree.setSelectionPath(
        new TreePath((((DefaultTreeModel) tree.getModel()).getPathToRoot(previous))));
    topPanel.add(tree, BorderLayout.CENTER);

    add(topPanel, BorderLayout.NORTH);

    // Certificate details pane
    Caret caret = infoTextPane.getCaret();
    if (caret instanceof DefaultCaret) {
      ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    }

    /*
     * Make JEditorPane respect our default font because we will be using it
     * to just display text.
     */
    infoTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);

    infoTextPane.setOpaque(false);
    infoTextPane.setEditable(false);
    infoTextPane.setContentType("text/html");
    infoTextPane.setText(toString(certificates[0]));

    final JScrollPane certScroll = new JScrollPane(infoTextPane);
    certScroll.setPreferredSize(new Dimension(300, 500));
    add(certScroll, BorderLayout.CENTER);
  }
Esempio n. 23
0
  private ClientWindow(String name) {
    setTitle("ClientWindow");
    setContentPane(WindowPanel);
    pack();

    clientFacade = ClientFacade.getClientFacadeByClientName(name);
    NameLabel.setText(clientFacade.getClientName());

    productItemMap = clientFacade.getProductList();
    FormOrderPanel.setVisible(false);

    tableModel = new ProductsTableModel();
    ProductsTable.setModel(tableModel);

    root = new DefaultMutableTreeNode("ClientOrders");

    generateOrdersTree();

    OrdersTree.setModel(new DefaultTreeModel(root));
    OrdersTree.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
              TreePath pathSelected = OrdersTree.getSelectionPath();
              if (OrdersTree.isPathSelected(pathSelected)
                  && OrdersTree.getModel().isLeaf(pathSelected.getLastPathComponent())) {
                ManagerPopupMenu managerPopupMenu = new ManagerPopupMenu();
                managerPopupMenu.getJPopupMenu().show(e.getComponent(), e.getX(), e.getY());
              }
            }
          }
        });
    OrdersTree.setShowsRootHandles(true);
    OrdersTree.setRootVisible(true);

    OrdersTree.getSelectionModel()
        .addTreeSelectionListener(
            e -> {
              DefaultMutableTreeNode selectedNode =
                  (DefaultMutableTreeNode) OrdersTree.getLastSelectedPathComponent();
              if (selectedNode.isLeaf()) {
                if (!((String) selectedNode.getUserObject()).equals("ClientOrders")) {
                  List<ProductRow> productRowList =
                      clientFacade.getProductRowsByOrder(
                          clientFacade.getValidDate((String) selectedNode.getUserObject()));
                  productRowList
                      .stream()
                      .forEach(
                          productRow ->
                              ClientWindow.this.tableModel.addRow(
                                  productRow.getId(),
                                  productRow.getType(),
                                  productRow.getPrice(),
                                  productRow.getNumber()));

                  ProductsTable.revalidate();
                }
              }
            });

    Font font = new Font("Verdana", Font.PLAIN, 12);
    jMenuBar = new JMenuBar();
    jMenu = new JMenu("Actions");

    JMenuItem jCreateProviderOrderItem = new JMenuItem("Создать заказ");
    jCreateProviderOrderItem.setFont(font);
    jCreateProviderOrderItem.addActionListener(e -> openClientOrderForm());
    jMenu.add(jCreateProviderOrderItem);

    jMenu.addSeparator();

    JMenuItem jCloseItem = new JMenuItem("Закрыть");
    jCloseItem.setFont(font);
    jCloseItem.addActionListener(e -> close());
    jMenu.add(jCloseItem);

    jMenuBar.add(jMenu);
    MenuPanel.add(jMenuBar);

    OrderOkButton.addActionListener(e -> createClientOrder());
    OrderCancelButton.addActionListener(e -> closeClientOrderForm());
    TypeComboBox.addItemListener(e -> setPriceByType());
    AddProductButton.addActionListener(
        e -> {
          if (productItemList == null) {
            productItemList = new HashMap<String, ProductItem>();
          }
          productItemList.put(
              TypeComboBox.getSelectedItem().toString(),
              new ProductItem(
                  TypeComboBox.getSelectedItem().toString(),
                  PriceTextField.getText(),
                  AmountTextField.getText()));
        });

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);

    BurgerButton.addActionListener(e -> FastFoodTextArea.append(clientFacade.getBurger()));

    RunServerButton.addActionListener(e -> InfoTextArea.append(clientFacade.runServer()));

    StopServerButton.addActionListener(e -> InfoTextArea.append(clientFacade.stopServer()));
  }
Esempio n. 24
0
  /** Construct a new Help panel */
  public HelpPanel() {
    // Try to build our help tree, keeping an eye out for malformed URLs
    try {
      // root node
      top = new DefaultMutableTreeNode(new HelpItem("MIDIMatrix", "top"));

      // matrices node
      category = new DefaultMutableTreeNode(new HelpItem("Matrices", "matrices"));
      top.add(category);
      category.add(new DefaultMutableTreeNode(new HelpItem("Note Entry", "matrices-noteentry")));
      category.add(
          new DefaultMutableTreeNode(
              new HelpItem("Pitches, volume, and instruments", "matrices-metadata")));
      category.add(new DefaultMutableTreeNode(new HelpItem("Playback", "matrices-playback")));

      // sequences node
      category = new DefaultMutableTreeNode(new HelpItem("Sequences", "sequences"));
      top.add(category);
      category.add(
          new DefaultMutableTreeNode(new HelpItem("Parts of a sequence", "sequences-parts")));
      category.add(
          new DefaultMutableTreeNode(
              new HelpItem("Constructing a sequence", "sequences-construction")));
      category.add(new DefaultMutableTreeNode(new HelpItem("Playback", "sequences-playback")));

      // controls node
      category = new DefaultMutableTreeNode(new HelpItem("Controls", "controls"));
      top.add(category);
      category.add(
          new DefaultMutableTreeNode(new HelpItem("MIDI devices", "controls-mididevices")));
      category.add(new DefaultMutableTreeNode(new HelpItem("Saving", "controls-saving")));

      // about node
      category = new DefaultMutableTreeNode(new HelpItem("About", "about"));
      top.add(category);
      category.add(new DefaultMutableTreeNode(new HelpItem("Author", "about-author")));
      category.add(new DefaultMutableTreeNode(new HelpItem("License", "about-license")));

      // javadoc node
      // category = new DefaultMutableTreeNode(new HelpItem("JavaDoc", base + "javadoc/"));
      // top.add(category);
    } catch (MalformedURLException e) {
      top = new DefaultMutableTreeNode("ERROR");
    }
    helpTree = new JTree(top);
    helpTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    helpTree.addTreeSelectionListener(
        new TreeSelectionListener() {

          public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node =
                (DefaultMutableTreeNode) helpTree.getLastSelectedPathComponent();
            if (node == null) {
              return;
            }
            // try {
            helpPane.scrollToReference(((HelpItem) node.getUserObject()).getHash());
            /*} catch (IOException exc) {

                JOptionPane.showMessageDialog(
                        null,
                        "There was a problem fetching the help page " + exc.getMessage() + "\n" +
                        "Make sure you're connected to the internet before continuing",
                        "Help Oops!",
                        JOptionPane.ERROR_MESSAGE,
                        null);
            }*/
          }
        });

    treePane = new JScrollPane(helpTree);
    treePane.setPreferredSize(new Dimension(200, 750));

    helpPane = new JEditorPane();
    scroller = new JScrollPane(helpPane);
    helpPane.setEditable(false);
    helpPane.setPreferredSize(new Dimension(550, 750));
    helpPane.addHyperlinkListener(
        new HyperlinkListener() {

          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              JEditorPane pane = (JEditorPane) e.getSource();
              if (e instanceof HTMLFrameHyperlinkEvent) {
                HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
                HTMLDocument doc = (HTMLDocument) pane.getDocument();
                doc.processHTMLFrameHyperlinkEvent(evt);
                if (e.getDescription().indexOf("#") != -1) {
                  System.err.println("Found anchor");
                  pane.scrollToReference(
                      e.getDescription().substring(e.getDescription().indexOf("#")));
                }
              } else {
                try {
                  pane.setPage(e.getURL());
                } catch (Throwable t) {
                  t.printStackTrace();
                }
              }
            }
          }
        });
    try {
      helpPane.setPage(HelpPanel.class.getResource("help.xhtml"));
    } catch (IOException e) {
      helpPane.setText("Couldn't fetch help page, sorry!  " + e.getMessage());
    }

    content = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    content.add(treePane);
    content.add(scroller);

    add(content);
  }