List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject
public Object getUserObject()
From source file:edu.brown.gui.CatalogViewer.java
/** * //from www. j a v a2s. c o m */ protected void viewerInit() { // ---------------------------------------------- // MENU // ---------------------------------------------- JMenu menu; JMenuItem menuItem; // // File Menu // menu = new JMenu("File"); menu.getPopupMenu().setLightWeightPopupEnabled(false); menu.setMnemonic(KeyEvent.VK_F); menu.getAccessibleContext().setAccessibleDescription("File Menu"); menuBar.add(menu); menuItem = new JMenuItem("Open Catalog From File"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From File"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_FILE); menu.add(menuItem); menuItem = new JMenuItem("Open Catalog From Jar"); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From Project Jar"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_JAR); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem("Quit", KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Quit Program"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.QUIT); menu.add(menuItem); // ---------------------------------------------- // CATALOG TREE PANEL // ---------------------------------------------- this.catalogTree = new JTree(); this.catalogTree.setEditable(false); this.catalogTree.setCellRenderer(new CatalogViewer.CatalogTreeRenderer()); this.catalogTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); this.catalogTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) CatalogViewer.this.catalogTree .getLastSelectedPathComponent(); if (node == null) return; Object user_obj = node.getUserObject(); String new_text = ""; // <html>"; boolean text_mode = true; if (user_obj instanceof WrapperNode) { CatalogType catalog_obj = ((WrapperNode) user_obj).getCatalogType(); new_text += CatalogViewer.this.getAttributesText(catalog_obj); } else if (user_obj instanceof AttributesNode) { AttributesNode wrapper = (AttributesNode) user_obj; new_text += wrapper.getAttributes(); } else if (user_obj instanceof PlanTreeCatalogNode) { final PlanTreeCatalogNode wrapper = (PlanTreeCatalogNode) user_obj; text_mode = false; CatalogViewer.this.mainPanel.remove(0); CatalogViewer.this.mainPanel.add(wrapper.getPanel(), BorderLayout.CENTER); CatalogViewer.this.mainPanel.validate(); CatalogViewer.this.mainPanel.repaint(); if (SwingUtilities.isEventDispatchThread() == false) { SwingUtilities.invokeLater(new Runnable() { public void run() { wrapper.centerOnRoot(); } }); } else { wrapper.centerOnRoot(); } } else { new_text += CatalogViewer.this.getSummaryText(); } // Text Mode if (text_mode) { if (CatalogViewer.this.text_mode == false) { CatalogViewer.this.mainPanel.remove(0); CatalogViewer.this.mainPanel.add(CatalogViewer.this.textInfoPanel); } CatalogViewer.this.textInfoTextArea.setText(new_text); // Scroll to top CatalogViewer.this.textInfoTextArea.grabFocus(); } CatalogViewer.this.text_mode = text_mode; } }); this.generateCatalogTree(this.catalog, this.catalog_file_path.getName()); // // Text Information Panel // this.textInfoPanel = new JPanel(); this.textInfoPanel.setLayout(new BorderLayout()); this.textInfoTextArea = new JTextArea(); this.textInfoTextArea.setEditable(false); this.textInfoTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); this.textInfoTextArea.setText(this.getSummaryText()); this.textInfoTextArea.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { // TODO Auto-generated method stub } @Override public void focusGained(FocusEvent e) { CatalogViewer.this.scrollTextInfoToTop(); } }); this.textInfoScroller = new JScrollPane(this.textInfoTextArea); this.textInfoPanel.add(this.textInfoScroller, BorderLayout.CENTER); this.mainPanel = new JPanel(new BorderLayout()); this.mainPanel.add(textInfoPanel, BorderLayout.CENTER); // // Search Toolbar // JPanel searchPanel = new JPanel(); searchPanel.setLayout(new BorderLayout()); JPanel innerSearchPanel = new JPanel(); innerSearchPanel.setLayout(new BoxLayout(innerSearchPanel, BoxLayout.X_AXIS)); innerSearchPanel.add(new JLabel("Search: ")); this.searchField = new JTextField(30); innerSearchPanel.add(this.searchField); searchPanel.add(innerSearchPanel, BorderLayout.EAST); this.searchField.addKeyListener(new KeyListener() { private String last = null; @Override public void keyReleased(KeyEvent e) { String value = CatalogViewer.this.searchField.getText().toLowerCase().trim(); if (!value.isEmpty() && (this.last == null || !this.last.equals(value))) { CatalogViewer.this.search(value); } this.last = value; } @Override public void keyTyped(KeyEvent e) { // Do nothing... } @Override public void keyPressed(KeyEvent e) { // Do nothing... } }); // Putting it all together JScrollPane scrollPane = new JScrollPane(this.catalogTree); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); topPanel.add(searchPanel, BorderLayout.NORTH); topPanel.add(scrollPane, BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, topPanel, this.mainPanel); splitPane.setDividerLocation(400); this.add(splitPane, BorderLayout.CENTER); }
From source file:edu.harvard.i2b2.query.QueryConceptTreePanel.java
public void treeExpanded(TreeExpansionEvent event) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent(); QueryConceptTreeNodeData data = (QueryConceptTreeNodeData) node.getUserObject(); jTree1.scrollPathToVisible(new TreePath(node)); //System.out.println("Node expanded: "+data.dimcode()); if (data.visualAttribute().equals("FA")) { data.visualAttribute("FAO"); } else if (data.visualAttribute().equals("CA")) { data.visualAttribute("CAO"); }//from ww w . jav a 2s . co m // check to see if child is a placeholder ('working...') // if so, make Web Service call to update children of node if (node.getChildCount() == 1) { final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getChildAt(0); if (((QueryConceptTreeNodeData) node1.getUserObject()).name().equalsIgnoreCase("working ......")) { final DefaultMutableTreeNode anode = node; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { populateChildNodes(anode); } }); } } else { for (int i = 0; i < node.getChildCount(); i++) { DefaultMutableTreeNode anode = (DefaultMutableTreeNode) node.getChildAt(0); QueryConceptTreeNodeData adata = (QueryConceptTreeNodeData) anode.getUserObject(); if (adata.visualAttribute().equals("FAO")) { adata.visualAttribute("FA"); } else if (adata.visualAttribute().equals("CAO")) { adata.visualAttribute("CA"); } } } }
From source file:jeplus.data.ParameterItem.java
private String[] createFormula(String funcstr) { // scan for parameter ids in the given string, and replace them with the corresponding search tag // 1. locate this parameter in the tree Enumeration nodes = Project.getParamTree().depthFirstEnumeration(); DefaultMutableTreeNode thisnode = Project.getParamTree(); while (nodes.hasMoreElements()) { thisnode = (DefaultMutableTreeNode) nodes.nextElement(); if (thisnode.getUserObject() == this) { break; }/*from w w w .j a v a2 s.c om*/ } Object[] items = thisnode.getUserObjectPath(); String newstr = ""; String bufstr = funcstr; for (int i = 0; i < items.length - 1; i++) { ParameterItem item = (ParameterItem) items[i]; newstr = bufstr.replace(item.getID(), item.getSearchString()); bufstr = newstr; } return new String[] { "?=" + newstr }; }
From source file:edu.harvard.i2b2.query.QueryConceptTreePanel.java
public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equalsIgnoreCase("Constrain Item ...")) { //JOptionPane.showMessageDialog(this, "Constrain Item ..."); //DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent(); //QueryConceptTreeNodeData ndata = (QueryConceptTreeNodeData) node.getUserObject(); //final QueryConstrainFrame cframe = new QueryConstrainFrame(ndata); //cframe.setTitle("Constrain Item: "+ndata.name()); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { //cframe.setVisible(true); }//from w w w . j a v a 2 s .c o m }); } else if (e.getActionCommand().equalsIgnoreCase("Delete Item")) { //JOptionPane.showMessageDialog(this, "Delete Item"); DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent(); treeModel.removeNodeFromParent(node); data().getItems().remove(node.getUserObject()); } }
From source file:jeplus.data.ParameterItem.java
private String[] createScript(String type, String funcstr) { // scan for parameter ids in the given string, and replace them with the corresponding search tag // 1. locate this parameter in the tree Enumeration nodes = Project.getParamTree().depthFirstEnumeration(); DefaultMutableTreeNode thisnode = Project.getParamTree(); while (nodes.hasMoreElements()) { thisnode = (DefaultMutableTreeNode) nodes.nextElement(); if (thisnode.getUserObject() == this) { break; }/* w w w. j a va2 s . c o m*/ } Object[] items = thisnode.getUserObjectPath(); // 2. split function string into func name and args String[] args = funcstr.split("\\s*,\\s*"); // 3. get a map from parameter id to search tags HashMap<String, String> tagmap = new HashMap<>(); for (int i = 0; i < items.length - 1; i++) { ParameterItem item = (ParameterItem) items[i]; tagmap.put(item.getID(), item.getSearchString()); } // 4. create script def string StringBuilder buf = new StringBuilder("call(").append(type); buf.append(", ").append(args[0]); for (int i = 1; i < args.length; i++) { buf.append(", "); if (tagmap.containsKey(args[i])) { buf.append(tagmap.get(args[i])); } else { buf.append(args[i]); } } buf.append(")"); return new String[] { buf.toString() }; }
From source file:org.jfree.chart.demo.SuperDemo.java
public void valueChanged(TreeSelectionEvent treeselectionevent) { TreePath treepath = treeselectionevent.getPath(); Object obj = treepath.getLastPathComponent(); if (obj != null) { DefaultMutableTreeNode defaultmutabletreenode = (DefaultMutableTreeNode) obj; Object obj1 = defaultmutabletreenode.getUserObject(); if (obj1 instanceof DemoDescription) { DemoDescription demodescription = (DemoDescription) obj1; SwingUtilities.invokeLater(new DisplayDemo(this, demodescription)); } else {/* w w w. j a v a 2 s . c o m*/ chartContainer.removeAll(); chartContainer.add(createNoDemoSelectedPanel()); displayPanel.validate(); displayDescription("select.html"); } } System.out.println(obj); }
From source file:com.moss.bdbadmin.client.ui.BdbAdminClient.java
private void saveConfig() { try {//from w w w . jav a 2 s .com ServiceConfig config = new ServiceConfig(); for (int i = 0; i < root.getChildCount(); i++) { DefaultMutableTreeNode serviceNode = (DefaultMutableTreeNode) root.getChildAt(i); ServiceContainer container = (ServiceContainer) serviceNode.getUserObject(); config.services().add(container.getInfo()); } Marshaller m = configJaxbContext.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(config, new FileOutputStream(configPath)); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(ancestor, "Could not save configuration from file: " + configPath, "Config Save Failed", JOptionPane.ERROR_MESSAGE); } }
From source file:com.moss.bdbadmin.client.ui.BdbAdminClient.java
private void rebuild(ServiceContainer container) { DefaultMutableTreeNode serviceNode = null; for (int i = 0; i < root.getChildCount(); i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i); ServiceContainer thisContainer = (ServiceContainer) node.getUserObject(); if (container == thisContainer) { serviceNode = node;//from w w w. j a v a 2 s .c om break; } } if (serviceNode == null) { throw new RuntimeException("Cannot find container in tree"); } Category rootCategory = container.getRootCategory(); if (rootCategory == null) { throw new NullPointerException(); } serviceNode.removeAllChildren(); buildCategory(serviceNode, rootCategory); model.nodeStructureChanged(serviceNode); }
From source file:de.tor.tribes.ui.views.DSWorkbenchSelectionFrame.java
private TreePath find2(JTree tree, TreePath parent, Village pNode, int depth) { TreeNode node = (TreeNode) parent.getLastPathComponent(); DefaultMutableTreeNode o = (DefaultMutableTreeNode) node; // If equal, go down the branch if (o.getUserObject().equals(pNode)) { // If at end, return match return parent; } else {//from ww w. ja v a2 s. co m // Traverse children if (node.getChildCount() >= 0) { for (Enumeration e = node.children(); e.hasMoreElements();) { TreeNode n = (TreeNode) e.nextElement(); TreePath path = parent.pathByAddingChild(n); TreePath result = find2(tree, path, pNode, depth + 1); // Found a match if (result != null) { return result; } } } } // No match at this branch return null; }
From source file:com.pironet.tda.SunJDKParser.java
private boolean checkForDuplicateThreadItem(Map directChildMap, DefaultMutableTreeNode node1) { ThreadInfo mi1 = (ThreadInfo) node1.getUserObject(); String name1 = mi1.getName(); for (Iterator iter2 = directChildMap.entrySet().iterator(); iter2.hasNext();) { DefaultMutableTreeNode node2 = (DefaultMutableTreeNode) ((Map.Entry) iter2.next()).getValue(); if (node1 == node2) { continue; }//from w w w. jav a2s .c o m ThreadInfo mi2 = (ThreadInfo) node2.getUserObject(); if (name1.equals(mi2.getName()) && node2.getChildCount() > 0) { node1.add((MutableTreeNode) node2.getFirstChild()); iter2.remove(); return true; } } return false; }