public TreePanel (DefaultMutableTreeNode root, ControlPanel pcp, boolean isMainPanel) { new TreePanel(root,pcp,isMainPanel,null); }
void closeAll(boolean die) { quitting = die; if (!visiblePanels.isEmpty()) { propertiesChanged = true; saveProperties(); } for (Enumeration e = panels.elements(); e.hasMoreElements();) { TreePanel p = (TreePanel)e.nextElement(); p.close(); } //if(quitting) panels.clear(); quitting = true; }
public void windowActivated(WindowEvent e) { WindowManager.setWindow(getFrame()); }
public void treeCollapsed (TreeExpansionEvent ev) { String evPathString = ev.getPath().toString(); evPathString = evPathString.substring(evPathString.indexOf("[")+1,evPathString.lastIndexOf("]")); evPathString = evPathString.substring(getTitle().length()+2,evPathString.length()); String rootPath = getRootPath().toString(); rootPath = rootPath.substring(rootPath.indexOf("[")+1,rootPath.lastIndexOf("]")); String path = "["+rootPath +", "+evPathString+"]"; pcp.unsetExpandedStateProperty(path); }
void setVisible() { if (pFrame!=null && !pFrame.isVisible()) { restoreExpandedNodes(); if (defaultLocation!=null) pFrame.setLocation(defaultLocation); pFrame.setVisible(true); // close expanded path to this panel in its parent panel (if visible and if the path is expanded) DefaultMutableTreeNode parent = (DefaultMutableTreeNode)root.getParent(); if (parent!=null) { TreePanel pnl = pcp.getPanelForNode(parent); if (pnl!=null && pnl.isVisible()) { TreeNode[] rPath = root.getPath(); TreeNode[] pPath = pnl.getRootNode().getPath(); DefaultMutableTreeNode[] tPath = new DefaultMutableTreeNode[rPath.length-pPath.length+1]; for(int i=0; i<tPath.length; i++) tPath[i] = (DefaultMutableTreeNode)rPath[i+pPath.length-1]; //TreePath path = new TreePath(rPath); TreePath localPath = new TreePath(tPath); pnl.getTree().collapsePath(localPath); } } } if (pcp!=null) pcp.setPanelShowingProperty(getRootPath().toString()); }
void restoreGeometry(TreePanel panel) { String pTitle = panel.getRootPath().toString(); pTitle = pStr2Key(pTitle); if (pTitle.equals("Control_Panel")) pTitle = "Control_Panel.@Main"; if (IJ.debugMode) IJ.log("CP.restoreGeometry: "+pTitle); String geom = Prefs.get(pTitle, null); if (geom!=null) { int[] coords = s2ints(geom); if (coords!=null && coords.length==4) panel.setBounds(coords[0],coords[1],coords[2],coords[3]); else { Point pnt = panel.getDefaultLocation(); if (pnt!=null) panel.getFrame().setLocation((int)pnt.getX(),(int)pnt.getY()); } } }
public void treeExpanded(TreeExpansionEvent ev) { TreePath evPath = ev.getPath(); //DefaultMutableTreeNode node = (DefaultMutableTreeNode)evPath.getLastPathComponent(); String evPathString = ev.getPath().toString(); evPathString = pcp.pStr2Key(evPathString); evPathString = evPathString.substring(getTitle().length()+1,evPathString.length()); String rootPath = getRootPath().toString(); rootPath = pcp.pStr2Key(rootPath); //String path = rootPath+"."+evPathString; String path = rootPath+"."+evPathString; if (pcp.hasPanelShowingProperty(path)) { Hashtable panels = pcp.getPanels(); TreePanel p = (TreePanel)panels.get(path); if(p!=null) p.close(); } pcp.setExpandedStateProperty(path); }
public void buildTreePanel() { pFrame=new JFrame(title); pFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); pTreeModel = new DefaultTreeModel(root); pTree=new JTree(pTreeModel); pTree.setEditable(false); pTree.putClientProperty("JTree.lineStyle","Angled"); pTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); pTree.setRootVisible(false); pTree.setShowsRootHandles(true); //pTree.setDragEnabled(true); JScrollPane ptView=new JScrollPane(pTree); addMenu(); pFrame.getContentPane().add(ptView, BorderLayout.CENTER); addListeners(); pFrame.pack(); if (defaultLocation!=null) { if (IJ.debugMode) IJ.log("CP.buildTreePanel: "+defaultLocation); pFrame.setLocation(defaultLocation.x, defaultLocation.y); } else pcp.restoreGeometry(this); //restoreExpandedNodes(); if (pFrame.getLocation().x==0) GUI.center(pFrame); setVisible(); ImageJ ij = IJ.getInstance(); ij.addWindowListener(this); pFrame.addKeyListener(ij); pTree.addKeyListener(ij); }
void recordGeometry(TreePanel panel) { String pTitle = panel.getRootPath().toString(); pTitle = pStr2Key(pTitle); JFrame frame = panel.getFrame(); if (frame!=null) { Rectangle rect=frame.getBounds(); String xCoord = (new Integer(rect.x)).toString(); String yCoord = (new Integer(rect.y)).toString(); String width = (new Integer(rect.width)).toString(); String height = (new Integer(rect.height)).toString(); if (pTitle.equals("Control_Panel")) pTitle = "Control_Panel.@Main"; String geometry = xCoord+" "+yCoord+" "+width+" "+height; if (IJ.debugMode) IJ.log("CP.recordGeometry: "+pTitle+" "+geometry); Prefs.set(pTitle, geometry); } }
void registerPanel(TreePanel panel) { String key = pStr2Key(panel.getRootPath().toString()); panels.put(key,panel); setPanelShowingProperty(panel.getRootPath().toString()); propertiesChanged=true; }
public TreePanel(DefaultMutableTreeNode root, ControlPanel pcp, boolean isMainPanel, Point location) { this.root=root; this.pcp=pcp; this.isMainPanel = isMainPanel; defaultLocation = location; rootPath=new TreePath(root.getPath()); title = (String)root.getUserObject(); buildTreePanel(); pcp.registerPanel(this); }
void addListeners() { addActionListener(this); pFrame.addWindowListener(this); pFrame.addComponentListener(new ComponentAdapter() {
void setVisible() { if (pFrame!=null && !pFrame.isVisible()) { restoreExpandedNodes(); if (defaultLocation!=null) pFrame.setLocation(defaultLocation); pFrame.setVisible(true); // close expanded path to this panel in its parent panel (if visible and if the path is expanded) DefaultMutableTreeNode parent = (DefaultMutableTreeNode)root.getParent(); if (parent!=null) { TreePanel pnl = pcp.getPanelForNode(parent); if (pnl!=null && pnl.isVisible()) { TreeNode[] rPath = root.getPath(); TreeNode[] pPath = pnl.getRootNode().getPath(); DefaultMutableTreeNode[] tPath = new DefaultMutableTreeNode[rPath.length-pPath.length+1]; for(int i=0; i<tPath.length; i++) tPath[i] = (DefaultMutableTreeNode)rPath[i+pPath.length-1]; //TreePath path = new TreePath(rPath); TreePath localPath = new TreePath(tPath); pnl.getTree().collapsePath(localPath); } } } if (pcp!=null) pcp.setPanelShowingProperty(getRootPath().toString()); }
void restoreGeometry(TreePanel panel) { String pTitle = panel.getRootPath().toString(); pTitle = pStr2Key(pTitle); if (pTitle.equals("Control_Panel")) pTitle = "Control_Panel.@Main"; if (IJ.debugMode) IJ.log("CP.restoreGeometry: "+pTitle); String geom = Prefs.get(pTitle, null); if (geom!=null) { int[] coords = s2ints(geom); if (coords!=null && coords.length==4) panel.setBounds(coords[0],coords[1],coords[2],coords[3]); else { Point pnt = panel.getDefaultLocation(); if (pnt!=null) panel.getFrame().setLocation((int)pnt.getX(),(int)pnt.getY()); } } }
public void treeExpanded(TreeExpansionEvent ev) { TreePath evPath = ev.getPath(); //DefaultMutableTreeNode node = (DefaultMutableTreeNode)evPath.getLastPathComponent(); String evPathString = ev.getPath().toString(); evPathString = pcp.pStr2Key(evPathString); evPathString = evPathString.substring(getTitle().length()+1,evPathString.length()); String rootPath = getRootPath().toString(); rootPath = pcp.pStr2Key(rootPath); //String path = rootPath+"."+evPathString; String path = rootPath+"."+evPathString; if (pcp.hasPanelShowingProperty(path)) { Hashtable panels = pcp.getPanels(); TreePanel p = (TreePanel)panels.get(path); if(p!=null) p.close(); } pcp.setExpandedStateProperty(path); }
public void buildTreePanel() { pFrame=new JFrame(title); pFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); pTreeModel = new DefaultTreeModel(root); pTree=new JTree(pTreeModel); pTree.setEditable(false); pTree.putClientProperty("JTree.lineStyle","Angled"); pTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); pTree.setRootVisible(false); pTree.setShowsRootHandles(true); //pTree.setDragEnabled(true); JScrollPane ptView=new JScrollPane(pTree); addMenu(); pFrame.getContentPane().add(ptView, BorderLayout.CENTER); addListeners(); pFrame.pack(); if (defaultLocation!=null) { if (IJ.debugMode) IJ.log("CP.buildTreePanel: "+defaultLocation); pFrame.setLocation(defaultLocation.x, defaultLocation.y); } else pcp.restoreGeometry(this); //restoreExpandedNodes(); if (pFrame.getLocation().x==0) GUI.center(pFrame); setVisible(); ImageJ ij = IJ.getInstance(); ij.addWindowListener(this); pFrame.addKeyListener(ij); pTree.addKeyListener(ij); }
public void treeCollapsed (TreeExpansionEvent ev) { String evPathString = ev.getPath().toString(); evPathString = evPathString.substring(evPathString.indexOf("[")+1,evPathString.lastIndexOf("]")); evPathString = evPathString.substring(getTitle().length()+2,evPathString.length()); String rootPath = getRootPath().toString(); rootPath = rootPath.substring(rootPath.indexOf("[")+1,rootPath.lastIndexOf("]")); String path = "["+rootPath +", "+evPathString+"]"; pcp.unsetExpandedStateProperty(path); }
void recordGeometry(TreePanel panel) { String pTitle = panel.getRootPath().toString(); pTitle = pStr2Key(pTitle); JFrame frame = panel.getFrame(); if (frame!=null) { Rectangle rect=frame.getBounds(); String xCoord = (new Integer(rect.x)).toString(); String yCoord = (new Integer(rect.y)).toString(); String width = (new Integer(rect.width)).toString(); String height = (new Integer(rect.height)).toString(); if (pTitle.equals("Control_Panel")) pTitle = "Control_Panel.@Main"; String geometry = xCoord+" "+yCoord+" "+width+" "+height; if (IJ.debugMode) IJ.log("CP.recordGeometry: "+pTitle+" "+geometry); Prefs.set(pTitle, geometry); } }
void registerPanel(TreePanel panel) { String key = pStr2Key(panel.getRootPath().toString()); panels.put(key,panel); setPanelShowingProperty(panel.getRootPath().toString()); propertiesChanged=true; }