コード例 #1
0
ファイル: InputFrame.java プロジェクト: raniaics/sip-creator
 public InputFrame(SipModel sipModel) {
   super(Which.INPUT, sipModel, "Input");
   sipModel.addParseListener(
       new SipModel.ParseListener() {
         @Override
         public void updatedRecord(MetadataRecord metadataRecord) {
           exec(new RecordSetter(metadataRecord));
         }
       });
   recordTree =
       new JTree(EMPTY_MODEL) {
         @Override
         public String getToolTipText(MouseEvent evt) {
           TreePath treePath = recordTree.getPathForLocation(evt.getX(), evt.getY());
           return treePath != null
               ? ((GroovyTreeNode) treePath.getLastPathComponent()).toolTip
               : "";
         }
       };
   recordTree.setToolTipText("Input Record");
   recordTree.setCellRenderer(new Renderer());
   recordTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
   recordTree.setTransferHandler(new TreeTransferHandler());
   filterField.addActionListener(rewind);
 }
コード例 #2
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));
 }
コード例 #3
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);
 }
コード例 #4
0
 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;
 }
コード例 #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;
  }
コード例 #6
0
ファイル: Controller.java プロジェクト: onyxbits/ScenePainter
  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;
  }
コード例 #7
0
  /**
   * Using the given AppContext, initialize the display.
   *
   * @param context Application context.
   */
  public void contextualize(AppContext context) {
    setContext(context);
    context.getEventBus().addMember(EventBus.MONITORING, new Handler());

    setLayout(new GridLayout(1, 1));

    _tree = new JTree();
    _tree.setModel(null);
    _tree.setCellRenderer(new ElementTreeCellRenderer());
    _tree.addMouseListener(new PopupHandler());
    _tree.putClientProperty("JTree.lineStyle", "Angled");
    _tree.setShowsRootHandles(true);
    JScrollPane scroller = new JScrollPane(_tree);
    add(scroller);

    setPreferredSize(new Dimension(250, 100));
    setMinimumSize(new Dimension(200, 100));
  }
コード例 #8
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);
  }
コード例 #9
0
  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;
  }
コード例 #10
0
ファイル: JoinOptimizer.java プロジェクト: haoguan/proj3
  /**
   * Helper function to display a Swing window with a tree representation of the specified list of
   * joins. See {@link #orderJoins}, which may want to call this when the analyze flag is true.
   *
   * @param js the join plan to visualize
   * @param pc the PlanCache accumulated whild building the optimal plan
   * @param stats table statistics for base tables
   * @param selectivities the selectivities of the filters over each of the tables (where tables are
   *     indentified by their alias or name if no alias is given)
   */
  private void printJoins(
      Vector<LogicalJoinNode> js,
      PlanCache pc,
      HashMap<String, TableStats> stats,
      HashMap<String, Double> selectivities) {

    JFrame f = new JFrame("Join Plan for " + p.getQuery());

    // Set the default close operation for the window,
    // or else the program won't exit when clicking close button
    f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    f.setVisible(true);

    f.setSize(300, 500);

    HashMap<String, DefaultMutableTreeNode> m = new HashMap<String, DefaultMutableTreeNode>();

    // int numTabs = 0;

    // int k;
    DefaultMutableTreeNode root = null, treetop = null;
    HashSet<LogicalJoinNode> pathSoFar = new HashSet<LogicalJoinNode>();
    boolean neither;

    System.out.println(js);
    for (LogicalJoinNode j : js) {
      pathSoFar.add(j);
      System.out.println("PATH SO FAR = " + pathSoFar);

      String table1Name = Database.getCatalog().getTableName(this.p.getTableId(j.t1Alias));
      String table2Name = Database.getCatalog().getTableName(this.p.getTableId(j.t2Alias));

      // Double c = pc.getCost(pathSoFar);
      neither = true;

      root =
          new DefaultMutableTreeNode(
              "Join "
                  + j
                  + " (Cost ="
                  + pc.getCost(pathSoFar)
                  + ", card = "
                  + pc.getCard(pathSoFar)
                  + ")");
      DefaultMutableTreeNode n = m.get(j.t1Alias);
      if (n == null) { // never seen this table before
        n =
            new DefaultMutableTreeNode(
                j.t1Alias
                    + " (Cost = "
                    + stats.get(table1Name).estimateScanCost()
                    + ", card = "
                    + stats.get(table1Name).estimateTableCardinality(selectivities.get(j.t1Alias))
                    + ")");
        root.add(n);
      } else {
        // make left child root n
        root.add(n);
        neither = false;
      }
      m.put(j.t1Alias, root);

      n = m.get(j.t2Alias);
      if (n == null) { // never seen this table before

        n =
            new DefaultMutableTreeNode(
                j.t2Alias == null
                    ? "Subplan"
                    : (j.t2Alias
                        + " (Cost = "
                        + stats.get(table2Name).estimateScanCost()
                        + ", card = "
                        + stats
                            .get(table2Name)
                            .estimateTableCardinality(selectivities.get(j.t2Alias))
                        + ")"));
        root.add(n);
      } else {
        // make right child root n
        root.add(n);
        neither = false;
      }
      m.put(j.t2Alias, root);

      // unless this table doesn't join with other tables,
      // all tables are accessed from root
      if (!neither) {
        for (String key : m.keySet()) {
          m.put(key, root);
        }
      }

      treetop = root;
    }

    JTree tree = new JTree(treetop);
    JScrollPane treeView = new JScrollPane(tree);

    tree.setShowsRootHandles(true);

    // Set the icon for leaf nodes.
    ImageIcon leafIcon = new ImageIcon("join.jpg");
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setOpenIcon(leafIcon);
    renderer.setClosedIcon(leafIcon);

    tree.setCellRenderer(renderer);

    f.setSize(300, 500);

    f.add(treeView);
    for (int i = 0; i < tree.getRowCount(); i++) {
      tree.expandRow(i);
    }

    if (js.size() == 0) {
      f.add(new JLabel("No joins in plan."));
    }

    f.pack();
  }
コード例 #11
0
  @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;
  }
コード例 #12
0
  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);
  }
コード例 #13
0
    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;
    }
コード例 #14
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);
  }
コード例 #15
0
  /**
   * 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);
  }