Exemplo n.º 1
0
    /** {@inheritDoc} */
    @Override
    public Component getTreeCellRendererComponent(
        final JTree aTree,
        final Object aValue,
        final boolean aSelected,
        final boolean aExpanded,
        final boolean aLeaf,
        final int aRow,
        final boolean aHasFocus) {
      Object value = aValue;

      if (value instanceof DefaultMutableTreeNode) {
        value = ((DefaultMutableTreeNode) value).getUserObject();
      }

      if (value instanceof ElementGroup) {
        ElementGroup elementGroup = (ElementGroup) value;
        value = elementGroup.getName();
      } else if (value instanceof SignalElement) {
        SignalElement signalElement = (SignalElement) value;
        value = signalElement.getLabel();
      }

      JLabel delegate =
          (JLabel)
              super.getTreeCellRendererComponent(
                  aTree, value, aSelected, aExpanded, aLeaf, aRow, aHasFocus);
      return delegate;
    }
Exemplo n.º 2
0
  /** Adds a new group to our tree and element model. */
  final void addNewGroup() {
    DefaultTreeModel model = (DefaultTreeModel) this.tree.getModel();

    boolean groupSummaryVisibleByDefault = UIManager.getBoolean(GROUP_SUMMARY_VISIBLE_DEFAULT);
    boolean scopeVisibleByDefault = UIManager.getBoolean(ANALOG_SCOPE_VISIBLE_DEFAULT);

    int groupCount = this.model.getGroups().size();
    String name = String.format("Group %d", Integer.valueOf(groupCount + 1));

    // Create model structure...
    ElementGroup newGroup = this.model.addGroup(name);
    newGroup.setVisible(true);

    SignalElement groupSummaryElement = SignalElement.createGroupSummaryElement(newGroup);
    groupSummaryElement.setEnabled(groupSummaryVisibleByDefault);
    newGroup.addElement(groupSummaryElement);

    SignalElement analogScopeElement = SignalElement.createAnalogScopeElement(newGroup);
    analogScopeElement.setEnabled(scopeVisibleByDefault);
    newGroup.addElement(analogScopeElement);

    // Create tree structure...
    ElementTreeNode rootNode = (ElementTreeNode) model.getRoot();

    ElementTreeNode groupNode = new ElementTreeNode(newGroup);
    rootNode.add(groupNode);

    groupNode.add(new ElementTreeNode(groupSummaryElement));
    groupNode.add(new ElementTreeNode(analogScopeElement));

    int index = rootNode.getIndex(groupNode);

    model.nodesWereInserted(rootNode, new int[] {index});
    model.nodeStructureChanged(groupNode);

    this.tree.expandRow(index);
  }