List of usage examples for javax.swing.tree DefaultMutableTreeNode add
public void add(MutableTreeNode newChild)
newChild
from its parent and makes it a child of this node by adding it to the end of this node's child array. From source file:edu.ucla.stat.SOCR.chart.ChartTree.java
/** * Creates the tree node for the pie chart demos. * //from w ww .j ava2 s. c o m * @return A populated tree node. */ private MutableTreeNode createPieChartsNode() { DefaultMutableTreeNode root = new DefaultMutableTreeNode("Pie Charts"); DefaultMutableTreeNode n1 = new DefaultMutableTreeNode( new DemoDescription("edu.ucla.stat.SOCR.chart.demo.PieChartDemo1", "PieChartDemo1")); DefaultMutableTreeNode n2 = new DefaultMutableTreeNode( new DemoDescription("edu.ucla.stat.SOCR.chart.demo.PieChartDemo2", "PieChartDemo2")); DefaultMutableTreeNode n3 = new DefaultMutableTreeNode( new DemoDescription("edu.ucla.stat.SOCR.chart.demo.PieChartDemo4", "PieChartDemo4")); DefaultMutableTreeNode n4 = new DefaultMutableTreeNode( new DemoDescription("edu.ucla.stat.SOCR.chart.demo.PieChart3DDemo1", "PieChart3DDemo1")); DefaultMutableTreeNode n5 = new DefaultMutableTreeNode( new DemoDescription("edu.ucla.stat.SOCR.chart.demo.PieChart3DDemo2", "PieChart3DDemo2")); DefaultMutableTreeNode n6 = new DefaultMutableTreeNode( new DemoDescription("edu.ucla.stat.SOCR.chart.demo.PieChart3DDemo3", "PieChart3DDemo3")); DefaultMutableTreeNode n7 = new DefaultMutableTreeNode(new DemoDescription( "edu.ucla.stat.SOCR.chart.demo.MultiplePieChartDemo1", "MultiplePieChartDemo1")); DefaultMutableTreeNode n8 = new DefaultMutableTreeNode( new DemoDescription("edu.ucla.stat.SOCR.chart.demo.RingChartDemo1", "RingChartDemo1")); root.add(n1); root.add(n2); root.add(n3); root.add(n4); root.add(n5); root.add(n6); // root.add(n7); root.add(n8); return root; }
From source file:org.jfree.chart.demo.SuperDemo.java
private MutableTreeNode createAreaChartsNode() { DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Area Charts"); DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode( new DemoDescription("AreaChartDemo1", "AreaChartDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode( new DemoDescription("StackedXYAreaChartDemo1", "StackedXYAreaChartDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode( new DemoDescription("StackedXYAreaChartDemo2", "StackedXYAreaChartDemo2.java")); DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode( new DemoDescription("XYAreaChartDemo1", "XYAreaChartDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode5 = new DefaultMutableTreeNode( new DemoDescription("XYAreaChartDemo2", "XYAreaChartDemo2.java")); DefaultMutableTreeNode defaultmutabletreenode6 = new DefaultMutableTreeNode( new DemoDescription("XYStepAreaRendererDemo1", "XYStepAreaRendererDemo1.java")); defaultmutabletreenode.add(defaultmutabletreenode1); defaultmutabletreenode.add(defaultmutabletreenode2); defaultmutabletreenode.add(defaultmutabletreenode3); defaultmutabletreenode.add(defaultmutabletreenode4); defaultmutabletreenode.add(defaultmutabletreenode5); defaultmutabletreenode.add(defaultmutabletreenode6); return defaultmutabletreenode; }
From source file:gov.nih.nci.ncicb.cadsr.contexttree.service.impl.CDEBrowserTreeServiceImpl.java
private void addAllcscsiNodes(List cscsiList, Map cscsiMap, String contextId, DefaultMutableTreeNode csNode, List templateTypes, Map cscsiholderMap, TreeIdGenerator idGen) { if (cscsiList == null || cscsiMap == null || csNode == null || cscsiholderMap == null) return;//from w w w . ja v a 2 s. c om ListIterator it = cscsiList.listIterator(); while (it.hasNext()) { String cscsiId = (String) it.next(); ClassSchemeItem cscsi = (ClassSchemeItem) cscsiMap.get(cscsiId); String aUniquesId = contextId + cscsi.getCsCsiIdseq() + System.currentTimeMillis(); DefaultMutableTreeNode node = this.getWebNode(cscsi.getClassSchemeItemName(), aUniquesId); csNode.add(node); aUniquesId = idGen.getNewId(); Map categoryMap = addInitialCategoryNodes(node, aUniquesId, templateTypes); CsCsiCategorytHolder cscsiCatHolder = new CsCsiCategorytHolder(); cscsiCatHolder.setNode(node); cscsiCatHolder.setCategoryHolder(categoryMap); cscsiholderMap.put(cscsiId, cscsiCatHolder); } }
From source file:com.clough.android.adbv.view.MainFrame.java
private void refreshDatabase() { inputQuery = ""; invalidateInputOutput();/* w ww. ja va 2 s .c o m*/ new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { try { Thread.sleep(100); } catch (InterruptedException ex) { } try { String tableNames = MainFrame.this.ioManager.getTableNames(); tableNameJSONArray = new JSONArray(tableNames); } catch (IOManagerException ex) { showDeviceDisconnectedDialog(); } return null; } @Override protected void done() { closeProgressDialog(); } }.execute(); showProgressDialog(true, 0, "Waiting for table list"); tableInfoTree.removeAll(); tableInfoTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); final DefaultMutableTreeNode databaseDMTN = new DefaultMutableTreeNode(databaseName); tableInfoTree.setModel(new DefaultTreeModel(databaseDMTN)); new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { try { Thread.sleep(100); } catch (InterruptedException ex) { } try { tables = new String[tableNameJSONArray.length()]; queries = new String[tableNameJSONArray.length()]; columns = new String[tableNameJSONArray.length()][]; columnInfos = new String[tableNameJSONArray.length()][][]; for (int i = 0; i < tableNameJSONArray.length(); i++) { tables[i] = tableNameJSONArray.getJSONObject(i).getString("name"); DefaultMutableTreeNode tableDMTN = new DefaultMutableTreeNode(tables[i]); databaseDMTN.add(tableDMTN); queries[i] = tableNameJSONArray.getJSONObject(i).getString("sql"); String tableColumnInfo = MainFrame.this.ioManager.getTableColumnInfo(tables[i]); JSONArray columnJSONArray = new JSONArray(tableColumnInfo); columns[i] = new String[columnJSONArray.length()]; columnInfos[i] = new String[columnJSONArray.length()][]; for (int j = 0; j < columnJSONArray.length(); j++) { JSONObject columnJSONObject = columnJSONArray.getJSONObject(j); columns[i][j] = columnJSONObject.getString("name"); columnInfos[i][j] = new String[4]; DefaultMutableTreeNode columnDMTN = new DefaultMutableTreeNode(columns[i][j]); columnInfos[i][j][0] = "Column ID : " + String.valueOf(columnJSONObject.getInt("cid")); columnDMTN.add(new DefaultMutableTreeNode(columnInfos[i][j][0])); columnInfos[i][j][1] = "Type : " + columnJSONObject.getString("type"); columnDMTN.add(new DefaultMutableTreeNode(columnInfos[i][j][1])); columnInfos[i][j][2] = "Def value : " + String.valueOf(columnJSONObject.getString("dflt_value")); columnDMTN.add(new DefaultMutableTreeNode(columnInfos[i][j][2])); columnInfos[i][j][3] = "Not NULL : " + String.valueOf((columnJSONObject.getInt("notnull") == 1)); columnDMTN.add(new DefaultMutableTreeNode(columnInfos[i][j][3])); tableDMTN.add(columnDMTN); } databaseDMTN.add(tableDMTN); waitingDialog.incrementProgressBar(); } } catch (IOManagerException ex) { showDeviceDisconnectedDialog(); } return null; } @Override protected void done() { closeProgressDialog(); } }.execute(); showProgressDialog(false, tableNameJSONArray.length(), "Getting info of " + tableNameJSONArray.length() + " tables"); tableInfoTree.expandPath(new TreePath((TreeNode) tableInfoTree.getModel().getRoot())); tableNameJSONArray = null; }
From source file:org.jfree.chart.demo.SuperDemo.java
private MutableTreeNode createExperimentalNode() { DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Experimental"); DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode( new DemoDescription("DialDemo1", "DialDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode( new DemoDescription("DialDemo2", "DialDemo2.java")); DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode( new DemoDescription("DialDemo3", "DialDemo3.java")); DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode( new DemoDescription("DialDemo4", "DialDemo4.java")); DefaultMutableTreeNode defaultmutabletreenode5 = new DefaultMutableTreeNode( new DemoDescription("DialDemo5", "DialDemo5.java")); DefaultMutableTreeNode defaultmutabletreenode6 = new DefaultMutableTreeNode( new DemoDescription("LogAxisDemo1", "LogAxisDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode7 = new DefaultMutableTreeNode( new DemoDescription("XYTitleAnnotationDemo1", "XYTitleAnnotationDemo1.java")); defaultmutabletreenode.add(defaultmutabletreenode1); defaultmutabletreenode.add(defaultmutabletreenode2); defaultmutabletreenode.add(defaultmutabletreenode3); defaultmutabletreenode.add(defaultmutabletreenode4); defaultmutabletreenode.add(defaultmutabletreenode5); defaultmutabletreenode.add(defaultmutabletreenode6); defaultmutabletreenode.add(defaultmutabletreenode7); return defaultmutabletreenode; }
From source file:gov.nih.nci.ncicb.cadsr.contexttree.service.impl.CDEBrowserTreeServiceImpl.java
/** * @returns two maps with contextid as key and value a holder object containing web node * one containg the forms with no protocol and other with protocols *//*from w w w. ja va 2s .c o m*/ public List getAllContextProtocolNodes(TreeFunctions treeFunctions, TreeIdGenerator idGen) throws Exception { Map protoCSMap = this.getFormClassificationNodes(treeFunctions, idGen, CaDSRConstants.FORM_CS_TYPE, CaDSRConstants.FORM_CSI_TYPE); Map treeNodeMap = new HashMap(); Map allFormsWithProtocol = new HashMap(); Map allFormsWithNoProtocol = new HashMap(); FormDAO dao = daoFactory.getFormDAO(); List forms = dao.getAllFormsOrderByContextProtocol(); Map protocolHolder = new HashMap(); Iterator iter = forms.iterator(); while (iter.hasNext()) { Form currForm = (Form) iter.next(); String currContextId = null; // When the form and the Protocol belongs to different context, the Protocol // context takes priority if (currForm.getProtocols() != null && currForm.getProtocols().size() > 0) currContextId = currForm.getProtocols().get(0).getConteIdseq(); if (currContextId == null) currContextId = currForm.getContext().getConteIdseq(); Map currCSMap = (Map) protoCSMap.get(currContextId); String currProtoIdSeq = null; if (currForm.getProtocols() != null && currForm.getProtocols().size() > 0) currProtoIdSeq = currForm.getProtocols().get(0).getProtoIdseq(); DefaultMutableTreeNode formNode = getFormNode(idGen.getNewId(), currForm, treeFunctions, false); // add form node to protocol node if (currProtoIdSeq != null && !currProtoIdSeq.equals("")) { List protocolList = (List) allFormsWithProtocol.get(currContextId); if (protocolList == null) { protocolList = new ArrayList(); allFormsWithProtocol.put(currContextId, protocolList); } DefaultMutableTreeNode protoNode = (DefaultMutableTreeNode) protocolHolder.get(currProtoIdSeq); if (protoNode == null) { protoNode = getProtocolNode(idGen.getNewId(), currForm.getProtocols().get(0), currContextId, treeFunctions); protocolHolder.put(currProtoIdSeq, protoNode); protocolList.add(protoNode); treeNodeMap.clear(); } // check and see if form need to be added to cs tree if (currForm.getClassifications() == null || currForm.getClassifications().size() == 0) { protoNode.add(formNode); } else { //add formNode to csTree this.copyCSTree(currForm, currCSMap, treeNodeMap, formNode, protoNode, idGen); } } else { /** for release 3.0.1, forms without protocol is not displayed, uncomment this * code to display them //forms do not have protocol DefaultMutableTreeNode noProtocolNode = (DefaultMutableTreeNode)allFormsWithNoProtocol.get(currContextId); if (noProtocolNode == null) { noProtocolNode=getWebNode("No Protocol", idGen.getNewId()); allFormsWithNoProtocol.put(currContextId, noProtocolNode); treeNodeMap.clear(); } if (currForm.getClassifications() == null || currForm.getClassifications().size() == 0) { noProtocolNode.add(formNode); } else { this.copyCSTree(currForm, currCSMap, treeNodeMap, formNode, noProtocolNode, idGen); } */ } } List resultList = new ArrayList(); resultList.add(0, allFormsWithNoProtocol); resultList.add(1, allFormsWithProtocol); return resultList; }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java
public void exploreBean(DefaultMutableTreeNode root, String classname, String parentPath) { try {//from w ww . j a va2 s. com root.removeAllChildren(); if (parentPath.length() > 0) parentPath += "."; Class clazz = Class.forName(classname, true, IReportManager.getInstance().getReportClassLoader()); java.beans.PropertyDescriptor[] pd = org.apache.commons.beanutils.PropertyUtils .getPropertyDescriptors(clazz); for (int nd = 0; nd < pd.length; ++nd) { String fieldName = pd[nd].getName(); if (pd[nd].getPropertyType() != null && pd[nd].getReadMethod() != null) { Class clazzRT = pd[nd].getPropertyType(); if (clazzRT.isPrimitive()) { clazzRT = MethodUtils.getPrimitiveWrapper(clazzRT); } String returnType = clazzRT.getName(); JRDesignField field = new JRDesignField(); field.setName(fieldName); field.setValueClassName(returnType); if (isPathOnDescription()) { field.setDescription(parentPath + fieldName); } else { field.setName(parentPath + fieldName); } TreeJRField jtf = new TreeJRField(); jtf.setField(field); jtf.setObj(pd[nd].getPropertyType()); boolean bChildrens = true; if (pd[nd].getPropertyType().isPrimitive() || pd[nd].getPropertyType().getName().startsWith("java.lang.")) { bChildrens = false; } root.add(new DefaultMutableTreeNode(jtf, bChildrens)); } } jTree1.expandPath(new TreePath(root.getPath())); jTree1.updateUI(); } catch (ClassNotFoundException cnf) { javax.swing.JOptionPane.showMessageDialog(this, Misc.formatString( //"messages.BeanInspectorPanel.classNotFoundError", I18n.getString("BeanInspectorPanel.Message.Error"), new Object[] { cnf.getMessage() }), I18n.getString("BeanInspectorPanel.Message.Error2"), javax.swing.JOptionPane.ERROR_MESSAGE); return; } catch (Exception ex) { ex.printStackTrace(); javax.swing.JOptionPane.showMessageDialog(this, ex.getMessage(), I18n.getString("BeanInspectorPanel.Message.Error2"), javax.swing.JOptionPane.ERROR_MESSAGE); return; } }
From source file:gdt.jgui.entity.JEntityDigestDisplay.java
private void instantiateComponentNode(DefaultMutableTreeNode facetComponentNode) { try {/*from ww w. j a v a 2 s.c om*/ String facetComponentLocator$ = (String) facetComponentNode.getUserObject(); Properties locator = Locator.toProperties(facetComponentLocator$); Entigrator entigrator = console.getEntigrator(entihome$); String facetClass$ = locator.getProperty(BaseHandler.HANDLER_CLASS); String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); JFacetOpenItem facetOpenItem = (JFacetOpenItem) JConsoleHandler.getHandlerInstance(entigrator, facetClass$); // System.out.println("EntityDigestDisplay:instantiateComponentNode:facetOpenItem="+facetOpenItem.getClass().getName()); String facetOpenItemLocator$ = facetOpenItem.getLocator(); facetOpenItemLocator$ = Locator.append(facetComponentLocator$, Entigrator.ENTIHOME, entihome$); facetOpenItemLocator$ = Locator.append(facetComponentLocator$, EntityHandler.ENTITY_KEY, entityKey$); facetOpenItem.instantiate(console, facetOpenItemLocator$); DefaultMutableTreeNode[] na = facetOpenItem.getDigest(); if (na == null) return; String nodeLocator$; for (DefaultMutableTreeNode aNa : na) { nodeLocator$ = (String) aNa.getUserObject(); nodeLocator$ = Locator.append(nodeLocator$, NODE_NUMBER, String.valueOf(nodeNumber++)); nodeLocator$ = Locator.append(nodeLocator$, COMPONENT_KEY, entityKey$); aNa.setUserObject(nodeLocator$); facetComponentNode.add(aNa); setSubnodesNumbers(aNa); } } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); } }
From source file:display.containers.FileManager.java
public Container getPane() { //if (gui==null) { fileSystemView = FileSystemView.getFileSystemView(); desktop = Desktop.getDesktop(); JPanel detailView = new JPanel(new BorderLayout(3, 3)); //fileTableModel = new FileTableModel(); table = new JTable(); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setAutoCreateRowSorter(true);/*from w ww . jav a2 s.c om*/ table.setShowVerticalLines(false); table.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getClickCount() >= 2) { Point p = e.getPoint(); int row = table.convertRowIndexToModel(table.rowAtPoint(p)); int column = table.convertColumnIndexToModel(table.columnAtPoint(p)); if (row >= 0 && column >= 0) { mouseDblClicked(row, column); } } } }); table.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent arg0) { } @Override public void keyReleased(KeyEvent arg0) { if (KeyEvent.VK_DELETE == arg0.getKeyCode()) { if (mode != 2) { parentFrame.setLock(true); parentFrame.getProgressBarPanel().setVisible(true); Thread t = new Thread(new Runnable() { @Override public void run() { try { deleteSelectedFiles(); } catch (IOException e) { JOptionPane.showMessageDialog(parentFrame, "Error during the deletion.", "Deletion error", JOptionPane.ERROR_MESSAGE); WindowManager.mwLogger.log(Level.SEVERE, "Error during the deletion.", e); } finally { parentFrame.setLock(false); refresh(); parentFrame.getProgressBarPanel().setVisible(false); } } }); t.start(); } else { if (UserProfile.CURRENT_USER.getLevel() == 3) { parentFrame.setLock(true); parentFrame.getProgressBarPanel().setVisible(true); Thread delThread = new Thread(new Runnable() { @Override public void run() { int[] rows = table.getSelectedRows(); int[] columns = table.getSelectedColumns(); for (int i = 0; i < rows.length; i++) { if (!continueAction) { continueAction = true; return; } int row = table.convertRowIndexToModel(rows[i]); try { deleteServerFile(row); } catch (Exception e) { WindowManager.mwLogger.log(Level.SEVERE, "Error during the deletion.", e); } } refresh(); parentFrame.setLock(false); parentFrame.getProgressBarPanel().setVisible(false); } }); delThread.start(); } } } } @Override public void keyPressed(KeyEvent arg0) { // TODO Auto-generated method stub } }); table.getSelectionModel().addListSelectionListener(listSelectionListener); JScrollPane tableScroll = new JScrollPane(table); Dimension d = tableScroll.getPreferredSize(); tableScroll.setPreferredSize(new Dimension((int) d.getWidth(), (int) d.getHeight() / 2)); detailView.add(tableScroll, BorderLayout.CENTER); // the File tree DefaultMutableTreeNode root = new DefaultMutableTreeNode(); treeModel = new DefaultTreeModel(root); table.getRowSorter().addRowSorterListener(new RowSorterListener() { @Override public void sorterChanged(RowSorterEvent e) { ((FileTableModel) table.getModel()).fireTableDataChanged(); } }); // show the file system roots. File[] roots = fileSystemView.getRoots(); for (File fileSystemRoot : roots) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(fileSystemRoot); root.add(node); //showChildren(node); // File[] files = fileSystemView.getFiles(fileSystemRoot, true); for (File file : files) { if (file.isDirectory()) { node.add(new DefaultMutableTreeNode(file)); } } // } JScrollPane treeScroll = new JScrollPane(); Dimension preferredSize = treeScroll.getPreferredSize(); Dimension widePreferred = new Dimension(200, (int) preferredSize.getHeight()); treeScroll.setPreferredSize(widePreferred); JPanel fileView = new JPanel(new BorderLayout(3, 3)); detailView.add(fileView, BorderLayout.SOUTH); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeScroll, detailView); JPanel simpleOutput = new JPanel(new BorderLayout(3, 3)); progressBar = new JProgressBar(); simpleOutput.add(progressBar, BorderLayout.EAST); progressBar.setVisible(false); showChildren(getCurrentDir().toPath()); //table.setDragEnabled(true); table.setColumnSelectionAllowed(false); // Menu popup Pmenu = new JPopupMenu(); changeProjectitem = new JMenuItem("Reassign"); renameProjectitem = new JMenuItem("Rename"); twitem = new JMenuItem("To workspace"); tlitem = new JMenuItem("To local"); processitem = new JMenuItem("Select for process"); switch (mode) { case 0: Pmenu.add(twitem); twitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtnlocalTowork().doClick(); } }); break; case 1: Pmenu.add(tlitem); Pmenu.add(processitem); tlitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtnWorkTolocal().doClick(); } }); processitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { SwingUtilities.invokeLater(new Runnable() { public void run() { // Recupere les lignes selectionnees int[] indices = table.getSelectedRows(); // On recupere les fichiers correspondants ArrayList<File> files = new ArrayList<File>(); for (int i = 0; i < indices.length; i++) { int row = table.convertRowIndexToModel(indices[i]); File fi = ((FileTableModel) table.getModel()).getFile(row); if (fi.isDirectory()) files.add(fi); } ImageProcessingFrame imf = new ImageProcessingFrame(files); } }); } }); break; case 2: if (UserProfile.CURRENT_USER.getLevel() == 3) { Pmenu.add(changeProjectitem); Pmenu.add(renameProjectitem); } Pmenu.add(twitem); twitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtndistToWorkspace().doClick(); } }); Pmenu.add(tlitem); tlitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtndistToLocal().doClick(); } }); break; } changeProjectitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { table.setEnabled(false); File from = ((FileTableModel) table.getModel()) .getFile(table.convertRowIndexToModel(table.getSelectedRows()[0])); ReassignProjectPanel reas = new ReassignProjectPanel(from.toPath()); // mode creation de liens Popup popup = PopupFactory.getSharedInstance().getPopup(WindowManager.MAINWINDOW, reas, (int) WindowManager.MAINWINDOW.getX() + 200, (int) WindowManager.MAINWINDOW.getY() + 150); reas.setPopupWindow(popup); popup.show(); table.setEnabled(true); } }); renameProjectitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { table.setEnabled(false); final File from = ((FileTableModel) table.getModel()) .getFile(table.convertRowIndexToModel(table.getSelectedRows()[0])); JDialog.setDefaultLookAndFeelDecorated(true); String s = (String) JOptionPane.showInputDialog(WindowManager.MAINWINDOW, "New project name ?", "Rename project", JOptionPane.PLAIN_MESSAGE, null, null, from.getName()); //If a string was returned, say so. if ((s != null) && (s.length() > 0)) { ProjectDAO pdao = new MySQLProjectDAO(); if (new File(from.getParent() + File.separator + s).exists()) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (A file with this filename already exists)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); WindowManager.mwLogger.log(Level.SEVERE, "Error during file project renaming (" + from.getName() + "). [Duplication error]"); } else { try { boolean succeed = pdao.renameProject(from.getName(), s); if (!succeed) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (no project with this name)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); } else { from.renameTo(new File(from.getParent() + File.separator + s)); // on renomme le repertoire nifti ou dicom correspondant si il existe switch (from.getParentFile().getName()) { case ServerInfo.NRI_ANALYSE_NAME: if (new File(from.getAbsolutePath().replaceAll(ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)).exists()) try { Files.move(Paths.get(from.getAbsolutePath().replaceAll( ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)), Paths.get(from.getParent().replaceAll( ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME) + File.separator + s)); } catch (IOException e) { e.printStackTrace(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (error with file system)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); WindowManager.mwLogger.log(Level.SEVERE, "Error during file project renaming (" + from.getName() + ")", e); } //from.renameTo(new File(from.getParent().replaceAll(ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)+File.separator+s)); break; case ServerInfo.NRI_DICOM_NAME: if (new File(from.getAbsolutePath().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)).exists()) try { Files.move(Paths.get(from.getAbsolutePath().replaceAll( ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)), Paths.get(from.getParent().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME) + File.separator + s)); } catch (IOException e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (error with file system)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); e.printStackTrace(); WindowManager.mwLogger.log(Level.SEVERE, "Error during file project renaming (" + from.getName() + ")", e); } //from.renameTo(new File(from.getParent().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)+File.separator+s)); break; } refresh(); } } catch (final SQLException e) { WindowManager.mwLogger.log(Level.SEVERE, "Error during SQL project renaming", e); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Exception : " + e.toString(), "Openning error", JOptionPane.ERROR_MESSAGE); } }); } } } table.setEnabled(true); } }); table.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent me) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent me) { if (me.getButton() == 3 && table.getSelectedRowCount() > 0) { int row = table.convertRowIndexToModel(table.rowAtPoint(me.getPoint())); changeProjectitem.setVisible(isPatient(((FileTableModel) table.getModel()).getFile(row))); renameProjectitem.setVisible(isProject(((FileTableModel) table.getModel()).getFile(row))); Pmenu.show(me.getComponent(), me.getX(), me.getY()); } } }); // //} return tableScroll; }
From source file:org.jfree.chart.demo.SuperDemo.java
private MutableTreeNode createCombinedAxisChartsNode() { DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Combined Axis Charts"); DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode( new DemoDescription("CombinedCategoryPlotDemo1", "CombinedCategoryPlotDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode( new DemoDescription("CombinedCategoryPlotDemo2", "CombinedCategoryPlotDemo2.java")); DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode( new DemoDescription("CombinedTimeSeriesDemo1", "CombinedTimeSeriesDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode( new DemoDescription("CombinedXYPlotDemo1", "CombinedXYPlotDemo1.java")); DefaultMutableTreeNode defaultmutabletreenode5 = new DefaultMutableTreeNode( new DemoDescription("CombinedXYPlotDemo2", "CombinedXYPlotDemo2.java")); DefaultMutableTreeNode defaultmutabletreenode6 = new DefaultMutableTreeNode( new DemoDescription("CombinedXYPlotDemo3", "CombinedXYPlotDemo3.java")); DefaultMutableTreeNode defaultmutabletreenode7 = new DefaultMutableTreeNode( new DemoDescription("CombinedXYPlotDemo4", "CombinedXYPlotDemo4.java")); defaultmutabletreenode.add(defaultmutabletreenode1); defaultmutabletreenode.add(defaultmutabletreenode2); defaultmutabletreenode.add(defaultmutabletreenode3); defaultmutabletreenode.add(defaultmutabletreenode4); defaultmutabletreenode.add(defaultmutabletreenode5); defaultmutabletreenode.add(defaultmutabletreenode6); defaultmutabletreenode.add(defaultmutabletreenode7); return defaultmutabletreenode; }