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;
 }
Exemplo n.º 4
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;
  }
Exemplo n.º 5
0
  private TreeModel buildModel(Object[] resolvers) {
    TreeModel fullModel = null;
    DefaultMutableTreeNode top = new DefaultMutableTreeNode(Tr.t("root"));

    try {
      cpos = null;
      for (Object resolver : resolvers) {
        if (resolver instanceof ColorPository) {
          cpos = (ColorPository) resolver;
          GraphCellRenderer graphCellRenderer = new GraphCellRenderer(cpos);
          colors.setCellRenderer(graphCellRenderer);
          break;
        }
      }
      Collection<ColorPository.ClassRecord> classes = cpos.getClasses();
      String[] classNames = new String[classes.size()];
      Iterator<ColorPository.ClassRecord> it = classes.iterator();
      int count = 0;
      while (it.hasNext()) {
        classNames[count] = it.next().name;
        count++;
      }
      Arrays.sort(classNames);

      for (String className : classNames) {
        ColorPository.ColorRecord[] colors = cpos.enumerateColors(className);
        String[] colorNames = new String[colors.length];
        for (int a = 0; a < colorNames.length; a++) {
          colorNames[a] = colors[a].name;
        }
        Arrays.sort(colorNames);

        DefaultMutableTreeNode tn = new DefaultMutableTreeNode(className);
        top.add(tn);
        for (String colorName : colorNames) {
          tn.add(new DefaultMutableTreeNode(colorName));
        }
      }

      fullModel = new DefaultTreeModel(top);
    } catch (Exception e) {
      fullModel = new DefaultTreeModel(new DefaultMutableTreeNode(Tr.t("root.failed")));
      // e.printStackTrace();
    }
    return fullModel;
  }
Exemplo n.º 6
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;
  }