Java Code Examples for javax.swing.JTree#setRootVisible()

The following examples show how to use javax.swing.JTree#setRootVisible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassHierarchyPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ClassHierarchyPanel(boolean isView) {
    initComponents();
    if (!isView) {
        toolBar.remove(0);
        toolBar.remove(0);
        subtypeButton.setFocusable(true);
        supertypeButton.setFocusable(true);
    }
    setName(NbBundle.getMessage(getClass(), "CTL_ClassHierarchyTopComponent")); // NOI18N
    setToolTipText(NbBundle.getMessage(getClass(), "HINT_ClassHierarchyTopComponent")); // NOI18N
    tree = new JTree();
    treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
    tree.setModel(treeModel);
    tree.setToggleClickCount(0);
    tree.setCellRenderer(new TreeRenderer());
    tree.putClientProperty("JTree.lineStyle", "Angled");  //NOI18N
    tree.expandRow(0);
    tree.setShowsRootHandles(true);
    tree.setSelectionRow(0);
    tree.setRootVisible(false);
    hierarchyPane.add(tree);
    hierarchyPane.setViewportView(tree);
    tree.addMouseListener(mouseListener);
}
 
Example 2
Source File: ObjectSelector.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
public ObjectSelector() {
	super( "Object Selector" );
	setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
	addWindowListener(FrameBox.getCloseListener("ShowObjectSelector"));
	addWindowFocusListener(new MyFocusListener());

	top = new DefaultMutableTreeNode();
	treeModel = new DefaultTreeModel(top);
	tree = new JTree();
	tree.setModel(treeModel);
	tree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
	tree.setRootVisible(false);
	tree.setShowsRootHandles(true);
	tree.setInvokesStopCellEditing(true);

	treeView = new JScrollPane(tree);
	getContentPane().add(treeView);

	entSequence = 0;

	addComponentListener(FrameBox.getSizePosAdapter(this, "ObjectSelectorSize", "ObjectSelectorPos"));

	tree.addTreeSelectionListener( new MyTreeSelectionListener() );
	treeModel.addTreeModelListener( new MyTreeModelListener(tree) );

	tree.addMouseListener(new MyMouseListener());
	tree.addKeyListener(new MyKeyListener());
}
 
Example 3
Source File: TreeUtil.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void createTree(JTree jTree1, String[] leaves) {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("", true);
    jTree1.setModel(new DefaultTreeModel(root));
    jTree1.setRootVisible(false);
    DefaultMutableTreeNode currentNode = root;
    Map<String, DefaultMutableTreeNode> pathList = new HashMap<String, DefaultMutableTreeNode>();
    for (int i = 0; i < leaves.length; i++) {

        String[] s = leaves[i].split("/");
        for (int j = 0; j < s.length; j++) {

            DefaultMutableTreeNode node = new DefaultMutableTreeNode(s[j], j != s.length - 1);
            String path = getPath(currentNode.getUserObjectPath()) + getPath(node.getUserObjectPath());
            DefaultMutableTreeNode pathNode = pathList.get(path);

            if (pathNode == null) {
                pathList.put(path, node);
                currentNode.add(node);
            } else {
                node = pathNode;
            }

            currentNode = node;
        }
        currentNode = root;
    }
}
 
Example 4
Source File: CatalogTree.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public CatalogTree(final LeafSelectionListener leafSelectionListener, AppContext appContext, UIContext uiContext) {
    this.appContext = appContext;
    this.uiContext = uiContext;
    jTree = new JTree();
    jTree.setRootVisible(false);
    ((DefaultTreeModel) jTree.getModel()).setRoot(CatalogTreeUtils.createRootNode());
    CatalogTreeUtils.addCellRenderer(jTree);
    addWillExpandListener();
    CatalogTreeUtils.addTreeSelectionListener(jTree, leafSelectionListener);
}
 
Example 5
Source File: LastNodeLowerHalfDrop.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private JScrollPane getContent() {
    jTree = new JTree(getTreeModel());
    jTree.setRootVisible(false);
    jTree.setDragEnabled(true);
    jTree.setDropMode(DropMode.INSERT);
    jTree.setTransferHandler(new TreeTransferHandler());
    jTree.getSelectionModel().setSelectionMode(
            TreeSelectionModel.SINGLE_TREE_SELECTION);
    expandTree(jTree);
    return new JScrollPane(jTree);
}
 
Example 6
Source File: FabricMainWindow.java    From fabric-loader with Apache License 2.0 5 votes vote down vote up
private static JPanel createTreePanel(FabricStatusNode rootNode, FabricTreeWarningLevel minimumWarningLevel,
	IconSet iconSet) {
	JPanel panel = new JPanel();
	panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

	TreeNode treeNode = new CustomTreeNode(null, rootNode, minimumWarningLevel);

	DefaultTreeModel model = new DefaultTreeModel(treeNode);
	JTree tree = new JTree(model);
	tree.setRootVisible(false);

	for (int row = 0; row < tree.getRowCount(); row++) {
		if (!tree.isVisible(tree.getPathForRow(row))) {
			continue;
		}

		CustomTreeNode node = ((CustomTreeNode) tree.getPathForRow(row).getLastPathComponent());

		if (node.node.expandByDefault || node.node.getMaximumWarningLevel().isAtLeast(FabricTreeWarningLevel.WARN)) {
			tree.expandRow(row);
		}
	}

	ToolTipManager.sharedInstance().registerComponent(tree);
	tree.setCellRenderer(new CustomTreeCellRenderer(iconSet));

	JScrollPane scrollPane = new JScrollPane(tree);
	panel.add(scrollPane);

	return panel;
}
 
Example 7
Source File: ColopediaPanel.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds the JTree which represents the navigation menu and then returns it
 *
 * @return The navigation tree.
 */
private JTree buildTree() {
    String name = Messages.message("colopedia");
    DefaultMutableTreeNode root
        = new DefaultMutableTreeNode(new ColopediaTreeItem(null, null, name, null));

    FreeColClient fcc = getFreeColClient();
    new TerrainDetailPanel(fcc, this).addSubTrees(root);
    new ResourcesDetailPanel(fcc, this).addSubTrees(root);
    new GoodsDetailPanel(fcc, this).addSubTrees(root);
    new UnitDetailPanel(fcc, this).addSubTrees(root);
    new BuildingDetailPanel(fcc, this).addSubTrees(root);
    new FatherDetailPanel(fcc, this).addSubTrees(root);
    new NationDetailPanel(fcc, this).addSubTrees(root);
    new NationTypeDetailPanel(fcc, this).addSubTrees(root);
    new ConceptDetailPanel(fcc, this).addSubTrees(root);

    DefaultTreeModel treeModel = new DefaultTreeModel(root);
    tree = new JTree(treeModel) {
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(
                    (int)(200 * getImageLibrary().getScaleFactor()),
                    super.getPreferredSize().height);
            }
        };
    tree.setRootVisible(false);
    tree.setCellRenderer(new ColopediaTreeCellRenderer());
    tree.setOpaque(false);
    tree.addTreeSelectionListener(this);

    listPanel.add(tree);
    Enumeration allNodes = root.depthFirstEnumeration();
    while (allNodes.hasMoreElements()) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) allNodes.nextElement();
        ColopediaTreeItem item = (ColopediaTreeItem) node.getUserObject();
        nodeMap.put(item.getId(), node);
    }
    return tree;
}
 
Example 8
Source File: SongListPanel.java    From HubPlayer with GNU General Public License v3.0 5 votes vote down vote up
private void initComponent(String... defaultNodes) {

		// 树组件
		topNode = new DefaultMutableTreeNode();

		// node表默认的列表 [0]表示列表中的歌曲数
		for (int i = 0; i < defaultNodes.length; i++) {
			DefaultMutableTreeNode node = new DefaultMutableTreeNode(
					defaultNodes[i] + "[0]");
			topNode.add(node);
		}

		tree = new JTree(topNode);
		// tree.setPreferredSize(new Dimension(290, 400));
		tree.startEditingAtPath(new TreePath(new Object[] { topNode,
				topNode.getFirstChild() }));

		// 隐藏根节点
		tree.setRootVisible(false);

		getViewport().add(tree);

		// 文件选择器处理
		fileChooser = new JFileChooser();
		songFilter = new FileNameExtensionFilter("音频文件(*.mid;*.mp3;*.wav)",
				"mid", "MID", "mp3", "MP3", "wav", "WAV");
		lrcFilter = new FileNameExtensionFilter("歌词文件(*.lrc)", "lrc", "LRC");

		songlist = new Vector<SongNode>();
	}
 
Example 9
Source File: ElementTreePanel.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
Example 10
Source File: ProcessingComponent.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
private void setupTreeViews() {
  tiProcessingRoot = new DefaultMutableTreeNode("Processing queues");
  msLevelNodes = new DPPMSLevelTreeNode[MSLevel.cropValues().length];
  for (MSLevel mslevel : MSLevel.cropValues()) {
    msLevelNodes[mslevel.ordinal()] = new DPPMSLevelTreeNode(mslevel);
    tiProcessingRoot.add(msLevelNodes[mslevel.ordinal()]);
  }

  tiAllModulesRoot = new DefaultMutableTreeNode("Modules");

  // create category items dynamically, if a new category is added later on.
  DPPModuleCategoryTreeNode[] moduleCategories =
      new DPPModuleCategoryTreeNode[ModuleSubCategory.values().length];
  for (int i = 0; i < moduleCategories.length; i++) {
    moduleCategories[i] = new DPPModuleCategoryTreeNode(ModuleSubCategory.values()[i]);
    tiAllModulesRoot.add(moduleCategories[i]);
  }

  // add modules to their module category items
  Collection<MZmineModule> moduleList = MZmineCore.getAllModules();
  for (MZmineModule module : moduleList) {
    if (module instanceof DataPointProcessingModule) {
      DataPointProcessingModule dppm = (DataPointProcessingModule) module;
      // only add modules that have applicable ms levels
      // add each module as a child of the module category items
      for (DPPModuleCategoryTreeNode catItem : moduleCategories) {
        if (dppm.getModuleSubCategory().equals(catItem.getCategory())) {
          catItem.add(new DPPModuleTreeNode(dppm));
        }
      }
    }
  }

  // add the categories to the root item
  tvProcessing = new JTree(tiProcessingRoot);
  tvAllModules = new JTree(tiAllModulesRoot);

  tvProcessing.setCellRenderer(new DisableableTreeCellRenderer());

  tvAllModules.setRootVisible(true);
  tvProcessing.setRootVisible(true);
  expandAllNodes(tvAllModules);
}
 
Example 11
Source File: ElementTreePanel.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
Example 12
Source File: ElementTreePanel.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
Example 13
Source File: ElementTreePanel.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
Example 14
Source File: BroadcastDialog.java    From SmartIM with Apache License 2.0 4 votes vote down vote up
protected void initTree(JTree tree) {
    tree.setCellRenderer(new CheckBoxTreeCellRenderer());
    tree.setShowsRootHandles(false);
    tree.setRootVisible(false);
    tree.addMouseListener(new CheckBoxTreeNodeSelectionListener());
}
 
Example 15
Source File: ElementTreePanel.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
Example 16
Source File: ElementTreePanel.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
Example 17
Source File: ElementTreePanel.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
Example 18
Source File: ElementTreePanel.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
Example 19
Source File: ProcessingComponent.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
private void setupTreeViews() {
  tiProcessingRoot = new DefaultMutableTreeNode("Processing queues");
  msLevelNodes = new DPPMSLevelTreeNode[MSLevel.cropValues().length];
  for (MSLevel mslevel : MSLevel.cropValues()) {
    msLevelNodes[mslevel.ordinal()] = new DPPMSLevelTreeNode(mslevel);
    tiProcessingRoot.add(msLevelNodes[mslevel.ordinal()]);
  }

  tiAllModulesRoot = new DefaultMutableTreeNode("Modules");

  // create category items dynamically, if a new category is added later
  // on.
  DPPModuleCategoryTreeNode[] moduleCategories =
      new DPPModuleCategoryTreeNode[ModuleSubCategory.values().length];
  for (int i = 0; i < moduleCategories.length; i++) {
    moduleCategories[i] = new DPPModuleCategoryTreeNode(ModuleSubCategory.values()[i]);
    tiAllModulesRoot.add(moduleCategories[i]);
  }

  // add modules to their module category items
  Collection<MZmineModule> moduleList = MZmineCore.getAllModules();
  for (MZmineModule module : moduleList) {
    if (module instanceof DataPointProcessingModule) {
      DataPointProcessingModule dppm = (DataPointProcessingModule) module;
      // only add modules that have applicable ms levels
      // add each module as a child of the module category items
      for (DPPModuleCategoryTreeNode catItem : moduleCategories) {
        if (dppm.getModuleSubCategory().equals(catItem.getCategory())) {
          catItem.add(new DPPModuleTreeNode(dppm));
        }
      }
    }
  }

  // add the categories to the root item
  tvProcessing = new JTree(tiProcessingRoot);
  tvAllModules = new JTree(tiAllModulesRoot);

  tvProcessing.setCellRenderer(new DisableableTreeCellRenderer());

  tvAllModules.setRootVisible(true);
  tvProcessing.setRootVisible(true);
  expandAllNodes(tvAllModules);
}
 
Example 20
Source File: ModelInfoTreeUI.java    From CQL with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Default constructor
 *
 * @param inFrame
 */
public ModelInfoTreeUI(F inFrame) {
	// Create the top node.
	_topNode = new DefaultMutableTreeNode("EA Sketch");
	_theFrame = inFrame;
	_newPosition = new Point(50, 50);

	// Create a tree that allows one selection at a time.
	_infoTreeModel = new DefaultTreeModel(_topNode);
	_infoTree = new JTree(_infoTreeModel);

	_infoTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	_infoTree.setRootVisible(false); // Hides root node
	_infoTree.setShowsRootHandles(true); // Shows nodes off root

	DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();

	renderer.setOpenIcon(null);
	renderer.setClosedIcon(null);
	renderer.setLeafIcon(null);
	_infoTree.setCellRenderer(renderer);

	// Add tree into scroll pane and then to this pane
	this.setViewportView(_infoTree);
	this.setMinimumSize(new Dimension(150, 200));

	_popupMenu = new JPopupMenu();

	buildPopupMenu();

	// Create Category Heads
	_tree_entities = new DefaultMutableTreeNode("Entities");

	_topNode.add(_tree_entities);

	_tree_constraints = new DefaultMutableTreeNode("Constraints");

	_topNode.add(_tree_constraints);

	_tree_constraints_commutative = new DefaultMutableTreeNode("Commutative Diagrams");

	_tree_constraints.add(_tree_constraints_commutative);

	_tree_constraints_product = new DefaultMutableTreeNode("Product Constraints");

	_tree_constraints.add(_tree_constraints_product);

	_tree_constraints_pullback = new DefaultMutableTreeNode("Pullback Constraints");

	_tree_constraints.add(_tree_constraints_pullback);

	_tree_constraints_equalizer = new DefaultMutableTreeNode("Equalizer Constraints");

	_tree_constraints.add(_tree_constraints_equalizer);

	_tree_constraints_sum = new DefaultMutableTreeNode("Sum Constraints");

	_tree_constraints.add(_tree_constraints_sum);

	_tree_constraints_limit = new DefaultMutableTreeNode("Limit Constraints");

	_tree_constraints.add(_tree_constraints_limit);

	// Initialize ArrayList of expansion state information
	expanState = new ArrayList<>();
}