Exemplo n.º 1
0
 /** Setd the desired cell renderer on this tree. This is exposed for redefinition by subclases. */
 protected void setCellRenderer(NavigatorView view, JTree tree) {
   if (view == null) {
     return;
   }
   Map map = view.getHelpSet().getCombinedMap();
   tree.setCellRenderer(new BasicSearchCellRenderer(map));
 }
Exemplo n.º 2
0
 /**
  * Constructor.
  *
  * @param tree a JTree
  */
 public CheckTreeManager(JTree tree) {
   this.tree = tree;
   selectionModel = new CheckTreeSelectionModel(tree.getModel());
   tree.setCellRenderer(new CheckTreeCellRenderer(tree.getCellRenderer(), selectionModel));
   tree.addMouseListener(this);
   tree.addMouseMotionListener(this);
   selectionModel.addTreeSelectionListener(this);
 }
 private static JTree createTree() {
   JTree resultsTree = new JTree();
   resultsTree.setName("TREEVIEW");
   resultsTree.setRootVisible(false);
   resultsTree.setEditable(false);
   resultsTree.setShowsRootHandles(true);
   resultsTree.setCellRenderer(new FailureCellRenderer());
   ToolTipManager tipManager = ToolTipManager.sharedInstance();
   tipManager.registerComponent(resultsTree);
   resultsTree.addKeyListener(new EnterPressListener());
   return resultsTree;
 }
  private JPanel createToolPanel() {
    configurationOverrideCombo.setModel(configurationOverrideModel);
    final int preferredHeight = configurationOverrideCombo.getPreferredSize().height;
    configurationOverrideCombo.setPreferredSize(new Dimension(250, preferredHeight));
    configurationOverrideCombo.setMaximumSize(new Dimension(350, preferredHeight));

    treeModel = new ResultTreeModel();

    resultsTree = new Tree(treeModel);
    resultsTree.setRootVisible(false);

    final TreeSelectionListener treeSelectionListener = new ToolWindowSelectionListener();
    resultsTree.addTreeSelectionListener(treeSelectionListener);
    final MouseListener treeMouseListener = new ToolWindowMouseListener();
    resultsTree.addMouseListener(treeMouseListener);
    resultsTree.setCellRenderer(new ResultTreeRenderer());

    progressLabel = new JLabel(" ");
    progressBar = new JProgressBar(JProgressBar.HORIZONTAL);
    progressBar.setMinimum(0);
    final Dimension progressBarSize = new Dimension(100, progressBar.getPreferredSize().height);
    progressBar.setMinimumSize(progressBarSize);
    progressBar.setPreferredSize(progressBarSize);
    progressBar.setMaximumSize(progressBarSize);

    progressPanel = new JToolBar(JToolBar.HORIZONTAL);
    progressPanel.add(Box.createHorizontalStrut(4));
    progressPanel.add(new JLabel(CheckStyleBundle.message("plugin.toolwindow.override")));
    progressPanel.add(Box.createHorizontalStrut(4));
    progressPanel.add(configurationOverrideCombo);
    progressPanel.add(Box.createHorizontalStrut(4));
    progressPanel.addSeparator();
    progressPanel.add(Box.createHorizontalStrut(4));
    progressPanel.add(progressLabel);
    progressPanel.add(Box.createHorizontalGlue());
    progressPanel.setFloatable(false);
    progressPanel.setBackground(UIManager.getColor("Panel.background"));
    progressPanel.setBorder(null);

    final JPanel toolPanel = new JPanel(new BorderLayout());
    toolPanel.add(new JBScrollPane(resultsTree), BorderLayout.CENTER);
    toolPanel.add(progressPanel, BorderLayout.NORTH);

    ToolTipManager.sharedInstance().registerComponent(resultsTree);

    return toolPanel;
  }
Exemplo n.º 5
0
  /**
   * 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;
  }
  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;
  }
Exemplo n.º 7
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);
  }
Exemplo n.º 8
0
  public void show(List<Rule> rules) {
    if (original != null) config.restoreState(original);
    dialog = new JDialog(owner, true);
    dialog.setTitle(messages.getString("guiConfigWindowTitle"));

    Collections.sort(rules, new CategoryComparator());

    // close dialog when user presses Escape key:
    final KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    final ActionListener actionListener =
        new ActionListener() {
          @Override
          public void actionPerformed(@SuppressWarnings("unused") ActionEvent actionEvent) {
            dialog.setVisible(false);
          }
        };
    final JRootPane rootPane = dialog.getRootPane();
    rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);

    // JPanel
    final JPanel checkBoxPanel = new JPanel();
    checkBoxPanel.setLayout(new GridBagLayout());
    GridBagConstraints cons = new GridBagConstraints();
    cons.anchor = GridBagConstraints.NORTHWEST;
    cons.gridx = 0;
    cons.weightx = 1.0;
    cons.weighty = 1.0;
    cons.fill = GridBagConstraints.BOTH;
    DefaultMutableTreeNode rootNode = createTree(rules);
    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
    treeModel.addTreeModelListener(
        new TreeModelListener() {

          @Override
          public void treeNodesChanged(TreeModelEvent e) {
            DefaultMutableTreeNode node =
                (DefaultMutableTreeNode) e.getTreePath().getLastPathComponent();
            int index = e.getChildIndices()[0];
            node = (DefaultMutableTreeNode) (node.getChildAt(index));
            if (node instanceof RuleNode) {
              RuleNode o = (RuleNode) node;
              if (o.getRule().isDefaultOff()) {
                if (o.isEnabled()) {
                  config.getEnabledRuleIds().add(o.getRule().getId());
                } else {
                  config.getEnabledRuleIds().remove(o.getRule().getId());
                }
              } else {
                if (o.isEnabled()) {
                  config.getDisabledRuleIds().remove(o.getRule().getId());
                } else {
                  config.getDisabledRuleIds().add(o.getRule().getId());
                }
              }
            }
            if (node instanceof CategoryNode) {
              CategoryNode o = (CategoryNode) node;
              if (o.isEnabled()) {
                config.getDisabledCategoryNames().remove(o.getCategory().getName());
              } else {
                config.getDisabledCategoryNames().add(o.getCategory().getName());
              }
            }
          }

          @Override
          public void treeNodesInserted(TreeModelEvent e) {}

          @Override
          public void treeNodesRemoved(TreeModelEvent e) {}

          @Override
          public void treeStructureChanged(TreeModelEvent e) {}
        });
    configTree = new JTree(treeModel);
    configTree.setRootVisible(false);
    configTree.setEditable(false);
    configTree.setCellRenderer(new CheckBoxTreeCellRenderer());
    TreeListener.install(configTree);
    checkBoxPanel.add(configTree, cons);

    MouseAdapter ma =
        new MouseAdapter() {
          private void handlePopupEvent(MouseEvent e) {
            final JTree tree = (JTree) e.getSource();

            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
              return;
            }

            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();

            TreePath[] paths = tree.getSelectionPaths();

            boolean isSelected = false;
            if (paths != null) {
              for (TreePath selectionPath : paths) {
                if (selectionPath.equals(path)) {
                  isSelected = true;
                }
              }
            }
            if (!isSelected) {
              tree.setSelectionPath(path);
            }
            if (node.isLeaf()) {
              JPopupMenu popup = new JPopupMenu();
              final JMenuItem aboutRuleMenuItem =
                  new JMenuItem(messages.getString("guiAboutRuleMenu"));
              aboutRuleMenuItem.addActionListener(
                  new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                      RuleNode node = (RuleNode) tree.getSelectionPath().getLastPathComponent();
                      Rule rule = node.getRule();
                      Language lang = config.getLanguage();
                      if (lang == null) {
                        lang = Language.getLanguageForLocale(Locale.getDefault());
                      }
                      Tools.showRuleInfoDialog(
                          tree,
                          messages.getString("guiAboutRuleTitle"),
                          rule.getDescription(),
                          rule,
                          messages,
                          lang.getShortNameWithCountryAndVariant());
                    }
                  });
              popup.add(aboutRuleMenuItem);
              popup.show(tree, e.getX(), e.getY());
            }
          }

          @Override
          public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
              handlePopupEvent(e);
            }
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
              handlePopupEvent(e);
            }
          }
        };
    configTree.addMouseListener(ma);
    final JPanel treeButtonPanel = new JPanel();
    cons = new GridBagConstraints();
    cons.gridx = 0;
    cons.gridy = 0;
    final JButton expandAllButton = new JButton(messages.getString("guiExpandAll"));
    treeButtonPanel.add(expandAllButton, cons);
    expandAllButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            TreeNode root = (TreeNode) configTree.getModel().getRoot();
            TreePath parent = new TreePath(root);
            for (Enumeration categ = root.children(); categ.hasMoreElements(); ) {
              TreeNode n = (TreeNode) categ.nextElement();
              TreePath child = parent.pathByAddingChild(n);
              configTree.expandPath(child);
            }
          }
        });

    cons.gridx = 1;
    cons.gridy = 0;
    final JButton collapseAllbutton = new JButton(messages.getString("guiCollapseAll"));
    treeButtonPanel.add(collapseAllbutton, cons);
    collapseAllbutton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            TreeNode root = (TreeNode) configTree.getModel().getRoot();
            TreePath parent = new TreePath(root);
            for (Enumeration categ = root.children(); categ.hasMoreElements(); ) {
              TreeNode n = (TreeNode) categ.nextElement();
              TreePath child = parent.pathByAddingChild(n);
              configTree.collapsePath(child);
            }
          }
        });

    final JPanel motherTonguePanel = new JPanel();
    motherTonguePanel.add(new JLabel(messages.getString("guiMotherTongue")), cons);
    motherTongueBox = new JComboBox(getPossibleMotherTongues());
    if (config.getMotherTongue() != null) {
      motherTongueBox.setSelectedItem(config.getMotherTongue().getTranslatedName(messages));
    }
    motherTongueBox.addItemListener(
        new ItemListener() {

          @Override
          public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
              Language motherTongue;
              if (motherTongueBox.getSelectedItem() instanceof String) {
                motherTongue =
                    getLanguageForLocalizedName(motherTongueBox.getSelectedItem().toString());
              } else {
                motherTongue = (Language) motherTongueBox.getSelectedItem();
              }
              config.setMotherTongue(motherTongue);
            }
          }
        });
    motherTonguePanel.add(motherTongueBox, cons);

    final JPanel portPanel = new JPanel();
    portPanel.setLayout(new GridBagLayout());
    // TODO: why is this now left-aligned?!?!
    cons = new GridBagConstraints();
    cons.insets = new Insets(0, 4, 0, 0);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.anchor = GridBagConstraints.WEST;
    cons.fill = GridBagConstraints.NONE;
    cons.weightx = 0.0f;
    if (!insideOOo) {
      serverCheckbox = new JCheckBox(Tools.getLabel(messages.getString("guiRunOnPort")));
      serverCheckbox.setMnemonic(Tools.getMnemonic(messages.getString("guiRunOnPort")));
      serverCheckbox.setSelected(config.getRunServer());
      portPanel.add(serverCheckbox, cons);
      serverCheckbox.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
              serverPortField.setEnabled(serverCheckbox.isSelected());
              serverSettingsCheckbox.setEnabled(serverCheckbox.isSelected());
            }
          });
      serverCheckbox.addItemListener(
          new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
              config.setRunServer(serverCheckbox.isSelected());
            }
          });

      serverPortField = new JTextField(Integer.toString(config.getServerPort()));
      serverPortField.setEnabled(serverCheckbox.isSelected());
      serverSettingsCheckbox = new JCheckBox(Tools.getLabel(messages.getString("useGUIConfig")));
      // TODO: without this the box is just a few pixels small, but why??:
      serverPortField.setMinimumSize(new Dimension(100, 25));
      cons.gridx = 1;
      portPanel.add(serverPortField, cons);
      serverPortField
          .getDocument()
          .addDocumentListener(
              new DocumentListener() {

                @Override
                public void insertUpdate(DocumentEvent e) {
                  changedUpdate(e);
                }

                @Override
                public void removeUpdate(DocumentEvent e) {
                  changedUpdate(e);
                }

                @Override
                public void changedUpdate(DocumentEvent e) {
                  try {
                    int serverPort = Integer.parseInt(serverPortField.getText());
                    if (serverPort > -1 && serverPort < 65536) {
                      serverPortField.setForeground(null);
                      config.setServerPort(serverPort);
                    } else {
                      serverPortField.setForeground(Color.RED);
                    }
                  } catch (NumberFormatException ex) {
                    serverPortField.setForeground(Color.RED);
                  }
                }
              });

      cons.gridx = 0;
      cons.gridy = 10;
      serverSettingsCheckbox.setMnemonic(Tools.getMnemonic(messages.getString("useGUIConfig")));
      serverSettingsCheckbox.setSelected(config.getUseGUIConfig());
      serverSettingsCheckbox.setEnabled(config.getRunServer());
      serverSettingsCheckbox.addItemListener(
          new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
              config.setUseGUIConfig(serverSettingsCheckbox.isSelected());
            }
          });
      portPanel.add(serverSettingsCheckbox, cons);
    }

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    okButton = new JButton(Tools.getLabel(messages.getString("guiOKButton")));
    okButton.setMnemonic(Tools.getMnemonic(messages.getString("guiOKButton")));
    okButton.addActionListener(this);
    cancelButton = new JButton(Tools.getLabel(messages.getString("guiCancelButton")));
    cancelButton.setMnemonic(Tools.getMnemonic(messages.getString("guiCancelButton")));
    cancelButton.addActionListener(this);
    cons = new GridBagConstraints();
    cons.insets = new Insets(0, 4, 0, 0);
    buttonPanel.add(okButton, cons);
    buttonPanel.add(cancelButton, cons);

    final Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.fill = GridBagConstraints.BOTH;
    contentPane.add(new JScrollPane(checkBoxPanel), cons);

    cons.gridx = 0;
    cons.gridy = 1;
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.LINE_END;
    contentPane.add(treeButtonPanel, cons);

    cons.gridx = 0;
    cons.gridy = 2;
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.WEST;
    contentPane.add(motherTonguePanel, cons);

    cons.gridx = 0;
    cons.gridy = 3;
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.WEST;
    contentPane.add(portPanel, cons);

    cons.gridx = 0;
    cons.gridy = 4;
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.EAST;
    contentPane.add(buttonPanel, cons);

    dialog.pack();
    dialog.setSize(500, 500);
    // center on screen:
    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    final Dimension frameSize = dialog.getSize();
    dialog.setLocation(
        screenSize.width / 2 - frameSize.width / 2, screenSize.height / 2 - frameSize.height / 2);
    dialog.setLocationByPlatform(true);
    dialog.setVisible(true);
  }
Exemplo n.º 9
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);
  }
  /**
   * 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);
  }
Exemplo n.º 13
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);
  }
Exemplo n.º 14
0
  /** Constructor - creates layout. */
  public HelpFrame() {
    setTitle("Web-Harvest Help");
    setIconImage(((ImageIcon) ResourceManager.HELP32_ICON).getImage());

    this.topNode = new DefaultMutableTreeNode();
    this.treeModel = new DefaultTreeModel(this.topNode);
    try {
      String helpContent = CommonUtil.readStringFromUrl(ResourceManager.getHelpContentUrl());
      XmlNode xmlNode = XmlParser.parse(new InputSource(new StringReader(helpContent)));
      createNodes(topNode, xmlNode);
    } catch (Exception e) {
      e.printStackTrace();
      GuiUtils.showErrorMessage("Error reading help content!");
    }

    tree = new JTree(topNode);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setBorder(new EmptyBorder(5, 5, 5, 5));
    tree.setCellRenderer(
        new DefaultTreeCellRenderer() {
          public Component getTreeCellRendererComponent(
              JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            DefaultTreeCellRenderer renderer =
                (DefaultTreeCellRenderer)
                    super.getTreeCellRendererComponent(
                        tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
              DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) value;
              Object userObject = defaultMutableTreeNode.getUserObject();
              if (userObject instanceof TopicInfo) {
                TopicInfo topicInfo = (TopicInfo) userObject;
                renderer.setIcon(
                    topicInfo.subtopicCount == 0
                        ? ResourceManager.HELPTOPIC_ICON
                        : ResourceManager.HELPDIR_ICON);
              }
            }
            return renderer;
          }
        });
    tree.addTreeSelectionListener(this);

    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    htmlPane.setContentType("text/html");
    htmlPane.setEditorKit(new HTMLEditorKit());
    htmlPane.setBorder(new EmptyBorder(5, 5, 5, 5));

    JSplitPane splitPane = new ProportionalSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setResizeWeight(0.0d);
    splitPane.setBorder(null);

    JScrollPane treeScrollPane = new WHScrollPane(tree);
    treeScrollPane.getViewport().setBackground(Color.white);
    treeScrollPane.setBackground(Color.white);
    splitPane.setLeftComponent(treeScrollPane);
    splitPane.setRightComponent(new WHScrollPane(htmlPane));
    splitPane.setDividerLocation(0.3d);

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(splitPane, BorderLayout.CENTER);

    pack();
  }
  protected TreeTable createOptionsTree(CodeStyleSettings settings) {
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    Map<String, DefaultMutableTreeNode> groupsMap = new THashMap<String, DefaultMutableTreeNode>();

    List<Option> sorted = sortOptions(ContainerUtil.concat(myOptions, myCustomOptions));
    for (Option each : sorted) {
      if (!(myCustomOptions.contains(each)
          || myAllowedOptions.contains(each.field.getName())
          || myShowAllStandardOptions)) continue;

      String group = each.groupName;
      MyTreeNode newNode = new MyTreeNode(each, each.title, settings);

      DefaultMutableTreeNode groupNode = groupsMap.get(group);
      if (groupNode != null) {
        groupNode.add(newNode);
      } else {
        String groupName;

        if (group == null) {
          groupName = each.title;
          groupNode = newNode;
        } else {
          groupName = group;
          groupNode = new DefaultMutableTreeNode(groupName);
          groupNode.add(newNode);
        }
        groupsMap.put(groupName, groupNode);
        rootNode.add(groupNode);
      }
    }

    ListTreeTableModel model = new ListTreeTableModel(rootNode, COLUMNS);
    TreeTable treeTable =
        new TreeTable(model) {
          @Override
          public TreeTableCellRenderer createTableRenderer(TreeTableModel treeTableModel) {
            TreeTableCellRenderer tableRenderer = super.createTableRenderer(treeTableModel);
            UIUtil.setLineStyleAngled(tableRenderer);
            tableRenderer.setRootVisible(false);
            tableRenderer.setShowsRootHandles(true);

            return tableRenderer;
          }

          @Override
          public TableCellRenderer getCellRenderer(int row, int column) {
            TreePath treePath = getTree().getPathForRow(row);
            if (treePath == null) return super.getCellRenderer(row, column);

            Object node = treePath.getLastPathComponent();

            @SuppressWarnings("unchecked")
            TableCellRenderer renderer = COLUMNS[column].getRenderer(node);
            return renderer == null ? super.getCellRenderer(row, column) : renderer;
          }

          @Override
          public TableCellEditor getCellEditor(int row, int column) {
            TreePath treePath = getTree().getPathForRow(row);
            if (treePath == null) return super.getCellEditor(row, column);

            Object node = treePath.getLastPathComponent();
            @SuppressWarnings("unchecked")
            TableCellEditor editor = COLUMNS[column].getEditor(node);
            return editor == null ? super.getCellEditor(row, column) : editor;
          }
        };
    new TreeTableSpeedSearch(treeTable).setComparator(new SpeedSearchComparator(false));

    treeTable.setRootVisible(false);

    final JTree tree = treeTable.getTree();
    tree.setCellRenderer(myTitleRenderer);
    tree.setShowsRootHandles(true);
    // myTreeTable.setRowHeight(new JComboBox(new String[]{"Sample
    // Text"}).getPreferredSize().height);
    treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    treeTable.setTableHeader(null);

    expandTree(tree);

    treeTable.getColumnModel().getSelectionModel().setAnchorSelectionIndex(1);
    treeTable.getColumnModel().getSelectionModel().setLeadSelectionIndex(1);

    int maxWidth = tree.getPreferredScrollableViewportSize().width + 10;
    final TableColumn titleColumn = treeTable.getColumnModel().getColumn(0);
    titleColumn.setPreferredWidth(maxWidth);
    titleColumn.setMinWidth(maxWidth);
    titleColumn.setMaxWidth(maxWidth);
    titleColumn.setResizable(false);

    // final TableColumn levelColumn = treeTable.getColumnModel().getColumn(1);
    // TODO[max]: better preffered size...
    // TODO[kb]: Did I fixed it by making the last column floating?
    // levelColumn.setPreferredWidth(valueSize.width);
    // levelColumn.setMaxWidth(valueSize.width);
    // levelColumn.setMinWidth(valueSize.width);
    // levelColumn.setResizable(false);

    final Dimension valueSize =
        new JLabel(ApplicationBundle.message("option.table.sizing.text")).getPreferredSize();
    treeTable.setPreferredScrollableViewportSize(
        new Dimension(maxWidth + valueSize.width + 10, 20));

    return treeTable;
  }
  public JTreeAdapterBreadCrumbTest() {
    super("BreadCrumb test");

    File[] roots = File.listRoots();
    FileTreeNode rootTreeNode = new FileTreeNode(roots);
    JTree tree = new JTree(rootTreeNode);
    tree.setRootVisible(false);
    tree.setCellRenderer(new FileTreeCellRenderer());

    this.bar = new BreadcrumbTreeAdapterSelector(tree);
    this.bar
        .getModel()
        .addPathListener(
            new BreadcrumbPathListener() {
              @Override
              public void breadcrumbPathEvent(BreadcrumbPathEvent event) {
                SwingUtilities.invokeLater(
                    new Runnable() {
                      @Override
                      public void run() {
                        final List<BreadcrumbItem<Object>> newPath = bar.getModel().getItems();
                        System.out.println("New path is ");
                        for (BreadcrumbItem<Object> item : newPath) {
                          FileTreeNode node = (FileTreeNode) item.getData();
                          if (node.file == null) continue;
                          System.out.println("\t" + node.file.getName());
                        }

                        if (newPath.size() > 0) {
                          SwingWorker<List<StringValuePair<Object>>, Void> worker =
                              new SwingWorker<List<StringValuePair<Object>>, Void>() {
                                @Override
                                protected List<StringValuePair<Object>> doInBackground()
                                    throws Exception {
                                  return bar.getCallback().getLeafs(newPath);
                                }

                                @Override
                                protected void done() {
                                  try {
                                    FileListModel model = new FileListModel();
                                    List<StringValuePair<Object>> leafs = get();
                                    for (StringValuePair<Object> leaf : leafs) {
                                      FileTreeNode node = (FileTreeNode) leaf.getValue();
                                      model.add(node.file);
                                    }
                                    model.sort();
                                    fileList.setModel(model);
                                  } catch (Exception exc) {
                                  }
                                }
                              };
                          worker.execute();
                        }
                        return;
                      }
                    });
              }
            });

    this.setLayout(new BorderLayout());
    this.add(bar, BorderLayout.NORTH);

    this.fileList = new JList();
    this.fileList.setCellRenderer(new FileListRenderer());
    JScrollPane fileListScrollPane = new JScrollPane(this.fileList);
    fileListScrollPane.setBorder(new TitledBorder("File list"));

    this.add(fileListScrollPane, BorderLayout.CENTER);
  }
    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;
    }