List of usage examples for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode
public DefaultMutableTreeNode()
From source file:Main.java
/** * Method by Adrian: [// w ww . j a v a 2 s. c o m * <a href="http://stackoverflow.com/a/15704264/5620200">StackOverflow</a> ] * & Mike: [ <a href= * "http://stackoverflow.com/questions/1542170/arranging-nodes-in-a-jtree"> * StackOverflow</a> ] * * @param node * @return */ @SuppressWarnings("unchecked") public static DefaultMutableTreeNode sort(DefaultMutableTreeNode node) { List<DefaultMutableTreeNode> children = Collections.list(node.children()); List<String> orgCnames = new ArrayList<String>(); List<String> cNames = new ArrayList<String>(); DefaultMutableTreeNode temParent = new DefaultMutableTreeNode(); for (DefaultMutableTreeNode child : children) { DefaultMutableTreeNode ch = (DefaultMutableTreeNode) child; temParent.insert(ch, 0); String uppser = ch.toString().toUpperCase(); // Not dependent on package name, so if duplicates are found // they will later on be confused. Adding this is of // very little consequence and fixes the issue. if (cNames.contains(uppser)) { uppser += "$COPY"; } cNames.add(uppser); orgCnames.add(uppser); if (!child.isLeaf()) { sort(child); } } Collections.sort(cNames); for (String name : cNames) { int indx = orgCnames.indexOf(name); int insertIndex = node.getChildCount(); node.insert(children.get(indx), insertIndex); } // Fixing folder placement for (int i = 0; i < node.getChildCount() - 1; i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i); for (int j = i + 1; j <= node.getChildCount() - 1; j++) { DefaultMutableTreeNode prevNode = (DefaultMutableTreeNode) node.getChildAt(j); if (!prevNode.isLeaf() && child.isLeaf()) { node.insert(child, j); node.insert(prevNode, i); } } } return node; }
From source file:fxts.stations.util.preferences.PreferencesNode.java
public PreferencesNode addNode(String aNameResID) { PreferencesNode childNode;/* www .jav a2 s. c om*/ for (int i = 0; i < mTreeNode.getChildCount(); i++) { childNode = (PreferencesNode) ((DefaultMutableTreeNode) mTreeNode.getChildAt(i)).getUserObject(); if (childNode.getName().equals(aNameResID)) { return childNode; } } //Same node not found. childNode = new PreferencesNode(aNameResID); DefaultMutableTreeNode newTreeNode = new DefaultMutableTreeNode(); newTreeNode.setUserObject(childNode); mTreeNode.add(newTreeNode); childNode.setTreeNode(newTreeNode); return childNode; }
From source file:net.landora.animeinfo.notifications.NotificationViewer.java
/** * Creates new form NotificationViewer//from w w w. j a v a2 s. co m */ public NotificationViewer() { initComponents(); setTitle("Anime Notifications"); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); notificationsNode = new DefaultMutableTreeNode("Notifications"); root.add(notificationsNode); treeModel = new DefaultTreeModel(root); treeItems.setModel(treeModel); // LazyTreeLoadingManager.getInstance().setup(treeItems); VideoManagerApp.getInstance().getEventBus().addHandlersWeak(this); }
From source file:com.hp.alm.ali.idea.entity.tree.HierarchicalEntityModel.java
public HierarchicalEntityModel(Project project, String entityType, boolean multiRoot, boolean initRoot) { super(new DefaultMutableTreeNode()); this.project = project; this.entityType = entityType; this.restService = project.getComponent(RestService.class); this.entityService = project.getComponent(EntityService.class); this.multiRoot = multiRoot; map = Collections.synchronizedMap(new HashMap<String, EntityNode>()); status = new DummyStatusIndicator(); if (initRoot) { initRootEntity();/*from w w w . ja v a 2 s. com*/ } }
From source file:Main.java
private TreeNode getNodes() { MyObject obj1 = new MyObject("1"); MyObject obj2 = new MyObject("1-1"); obj1.childs.add(obj2);/*from ww w .j a v a 2 s.c o m*/ obj2.childs.add(new MyObject("2-1")); obj2.childs.add(new MyObject("2-2")); obj1.childs.add(new MyObject("1-2")); obj1.childs.add(new MyObject("1-3")); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); construct(obj1, root); return root; }
From source file:com.autentia.wuija.widget.TreeComponent.java
private static DefaultMutableTreeNode createSingleNode(String nodeName, boolean isLeaf, boolean expanded) { final DefaultMutableTreeNode branchNode = new DefaultMutableTreeNode(); final IceUserObject branchObject = new IceUserObject(branchNode); branchObject.setText(nodeName);/*from w w w .ja v a 2 s .c o m*/ branchObject.setExpanded(expanded); branchObject.setLeaf(isLeaf); branchNode.setUserObject(branchObject); return branchNode; }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java
/** Creates new form BeanInspectorPanel */ public BeanInspectorPanel() { initComponents();//from www . j a va 2 s .co m DefaultTreeModel dttm = (DefaultTreeModel) jTree1.getModel(); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); jTree1.setModel(new DefaultTreeModel(root)); jTree1.setCellRenderer(new JBTreeCellRenderer()); //applyI18n(); }
From source file:it.cnr.icar.eric.client.ui.swing.ConceptsTreeModel.java
public ConceptsTreeModel(boolean updateOnCreate, RegistryObject rootTaxonomyElem) { super(new DefaultMutableTreeNode()); registryBrowser = RegistryBrowser.getInstance(); setRootTaxonomyElem(rootTaxonomyElem); // only update if parent component needs to if (updateOnCreate) { update();/* w w w. jav a 2 s.co m*/ } }
From source file:com.openbravo.pos.admin.RolesViewTree.java
private void createTree() { //Create the jtree root = new DefaultMutableTreeNode(); uTree = new CheckboxTree(root); root.setUserObject("All Permissions"); uTree.getCheckingModel().setCheckingMode(TreeCheckingModel.CheckingMode.PROPAGATE_PRESERVING_CHECK); uTree.clearSelection();//from w w w . j a v a2 s . c om DefaultCheckboxTreeCellRenderer renderer = (DefaultCheckboxTreeCellRenderer) uTree.getCellRenderer(); renderer.setLeafIcon(null); renderer.setClosedIcon(null); renderer.setOpenIcon(null); // set up listeners MouseListener ml = new MouseAdapter() { public void mousePressed(MouseEvent e) { int selRow = uTree.getRowForLocation(e.getX(), e.getY()); TreePath selPath = uTree.getPathForLocation(e.getX(), e.getY()); if (selPath != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getLastPathComponent(); // If using Right to left Language change the way the check tree works if (!uTree.getComponentOrientation().isLeftToRight()) { if (uTree.isPathChecked(new TreePath(node.getPath()))) { uTree.removeCheckingPath(new TreePath(node.getPath())); } else { uTree.addCheckingPath(new TreePath(node.getPath())); } } jPermissionDesc.setText(descriptionMap.get(node)); } } }; uTree.addMouseListener(ml); // when this listener is fired changes state to dirty uTree.addTreeCheckingListener(new TreeCheckingListener() { public void valueChanged(TreeCheckingEvent e) { passedDirty.setDirty(true); } }); try { // Get list of all the permisions in the database // and the list of sections dbPermissions = (List) m_dlAdmin.getAlldbPermissions(); branches = m_dlAdmin.getSectionsList(); } catch (BasicException ex) { Logger.getLogger(RolesViewTree.class.getName()).log(Level.SEVERE, null, ex); } // Create the main branches in the tree for (Object branch : branches) { section = ((StringUtils.substring(branch.toString(), 0, 2)).equals("##")) ? AppLocal.getIntString(StringUtils.right(branch.toString(), branch.toString().length() - 2)) : branch.toString(); root.add(new DefaultMutableTreeNode(section)); } classMap = new HashMap(); descriptionMap = new HashMap(); nodePaths = new HashMap(); // Replace displayname, Section and Description // from the database with the correct details from the permissions locale for (DBPermissionsInfo Perm : dbPermissions) { Perm.setDisplayName(((StringUtils.substring(Perm.getDisplayName(), 0, 2)).equals("##")) ? AppLocal.getIntString( StringUtils.right(Perm.getDisplayName(), Perm.getDisplayName().length() - 2)) : Perm.getDisplayName()); Perm.setSection(((StringUtils.substring(Perm.getSection(), 0, 2)).equals("##")) ? AppLocal.getIntString(StringUtils.right(Perm.getSection(), Perm.getSection().length() - 2)) : Perm.getSection()); Perm.setDescription(((StringUtils.substring(Perm.getDescription(), 0, 2)).equals("##")) ? AppLocal.getIntString( StringUtils.right(Perm.getDescription(), Perm.getDescription().length() - 2)) : Perm.getDescription()); } //put the list into order by display name sort(); // Create the leaf nodes & fill in hashmap's for (DBPermissionsInfo Perm : dbPermissions) { DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(Perm.getDisplayName(), false); if (searchNode(Perm.getSection(), root) != null) { searchNode(Perm.getSection(), root).add(newNode); classMap.put("[All Permissions, " + Perm.getSection() + ", " + newNode + "]", Perm.getClassName()); descriptionMap.put(newNode, Perm.getDescription()); nodePaths.put(Perm.getClassName(), newNode); } } root = sortTree(root); jScrollPane1.setViewportView(uTree); uTree.expandAll(); }
From source file:com.moss.bdbadmin.client.ui.BdbAdminClient.java
public BdbAdminClient(HttpClient httpClient, JFrame window, File configPath, ProxyFactory proxyFactory) { this.httpClient = httpClient; this.ancestor = window; this.configPath = configPath; this.proxyFactory = proxyFactory; try {/*from ww w . j av a2 s.co m*/ configJaxbContext = JAXBContext.newInstance(ServiceConfig.class); } catch (JAXBException ex) { throw new RuntimeException(ex); } JMenuItem newServiceItem = new JMenuItem("New Service"); newServiceItem.setAction(new NewServiceAction()); JMenu fileMenu = new JMenu("File"); fileMenu.add(newServiceItem); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); window.setJMenuBar(menuBar); window.setIconImage(new ImageIcon(this.getClass().getClassLoader().getResource("service.gif")).getImage()); this.root = new DefaultMutableTreeNode(); this.model = new DefaultTreeModel(root); getTree().setModel(model); getTree().setShowsRootHandles(true); getTree().setRootVisible(false); getTree().setCellRenderer(new Renderer()); getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); getTree().getSelectionModel().addTreeSelectionListener(new SelectionListener()); getTree().addMouseListener(new ContextMenuHandler()); addAncestorListener(new AncestorListener() { public void ancestorAdded(AncestorEvent event) { loadConfig(); } public void ancestorMoved(AncestorEvent event) { } public void ancestorRemoved(AncestorEvent event) { } }); }