List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject
public Object getUserObject()
From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java
public void updateP2PThumbnail(SearchResult result) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) getjTreeResults().getLastSelectedPathComponent(); if (node == null) { return;/*from ww w. j a v a 2 s . c om*/ } Object nodeInfo = null; DefaultMutableTreeNode nodeLeaf = null; if (node.getLevel() == 4 || (node.isLeaf() && node.getLevel() > 1)) { Object nodeInfoLeaf = null; if (node.getLevel() == 4) { nodeLeaf = node.getFirstLeaf(); nodeInfoLeaf = nodeLeaf.getUserObject(); } else { // Leaf nodeInfo = node.getUserObject(); nodeLeaf = node; nodeInfoLeaf = nodeInfo; } //SearchResult r = (SearchResult) nodeInfoLeaf; if (nodeInfoLeaf == result) { showThumbnail(result.getExtrafields().get("Thumbnail")); } } }
From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java
private void jTreeResultsValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jTreeResultsValueChanged DefaultMutableTreeNode node = (DefaultMutableTreeNode) getjTreeResults().getLastSelectedPathComponent(); if (node == null) { return;/*w w w. ja v a 2s. c om*/ } this.jButtonDownload.setEnabled(false); Object nodeInfo = null; DefaultMutableTreeNode nodeLeaf = null; if (node.getLevel() == 4 || (node.isLeaf() && node.getLevel() > 1)) { Object nodeInfoLeaf = null; if (node.getLevel() == 4) { nodeLeaf = node.getFirstLeaf(); nodeInfoLeaf = nodeLeaf.getUserObject(); } else { // Leaf nodeInfo = node.getUserObject(); nodeLeaf = node; nodeInfoLeaf = nodeInfo; } SearchResult r = (SearchResult) nodeInfoLeaf; Hashtable extras = r.getExtrafields(); String thumb = (String) extras.get("Thumbnail"); //System.out.println("Filename: " + r.getFileName()); //System.out.println("FileHash: " + r.getFileHash()); if (thumb != null) { showThumbnail(thumb); } else if (!SearchResult.class.isInstance(nodeInfoLeaf) && SearchResult.class.isInstance(nodeInfoLeaf)) { SearchResult res = searchTree.searchThumbnail(r.getFileName(), r.getFileHash()); if (res != null) { Hashtable extras2 = res.getExtrafields(); if (extras2 != null) { thumb = (String) extras2.get("Thumbnail"); if (thumb != null) { extras.put("Thumbnail", thumb); // put the thumbnail in the original SearchResult showThumbnail(thumb); } else { cleanThumbnails(); } } } } else if (SearchResult.class.isInstance(nodeInfoLeaf)) { searchTree.searchP2PThumbnail((SearchResult) r); cleanThumbnails(); } else { cleanThumbnails(); } } else { cleanThumbnails(); } //Controll the enable buttons if (node.isLeaf()) { jButtonDump.setEnabled(true); IPluginControllerUser plugins = null; try { plugins = this.clientCore.getUser().getPluginController(); if ((SearchResult) nodeInfo == null) { } if (!plugins.isLocalPlugin(((SearchResult) nodeInfo).getPluginName())) { jButtonDownload.setEnabled(true); jButtonSend.setEnabled(false); } else { jButtonSend.setEnabled(true); jButtonView.setEnabled(true); } } catch (RemoteException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } else { jButtonDump.setEnabled(false); jButtonDownload.setEnabled(false); jButtonView.setEnabled(false); jButtonSend.setEnabled(true); } }
From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java
private void jButtonViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonViewActionPerformed DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeResults.getLastSelectedPathComponent(); if (node == null) { return;/*from w ww.ja v a 2 s . c o m*/ } Object nodeInfo = node.getUserObject(); // int selected = this.jList1.getSelectedIndex(); if (node.isLeaf()) { if (SearchResult.class.isInstance(nodeInfo)) { SearchResult tmp = (SearchResult) nodeInfo; if (clientCore.isLocalServer()) { String path = tmp.getOrigin(); File f = new File(path); if (!f.exists()) { JOptionPane.showMessageDialog(this, "Dicoogle can't open this file, because this file does not exists in your file system. Try Dump button instead View!", "Error opening the file", JOptionPane.ERROR_MESSAGE); return; } if (ClientSettings.getInstance().getExtV() == null || ClientSettings.getInstance().getExtV().equals("")) { try { Desktop.getDesktop().open(new File(path)); } catch (IOException ex) { String folder = path.substring(0, path.lastIndexOf('/')); try { Desktop.getDesktop().open(new File(folder)); } catch (IOException ex1) { JOptionPane.showMessageDialog(this, "Dicoogle can't open this file!", "Error opening the file", JOptionPane.ERROR_MESSAGE); } } } else { try { ProcessBuilder pb = new ProcessBuilder(ClientSettings.getInstance().getExtV(), path); pb.start(); //Runtime.getRuntime().exec(ClientSettings.getInstance().getExtV() + " "+path); } catch (IOException ex) { //ex.printStackTrace(); String folder = path.substring(0, path.lastIndexOf('/')); try { Desktop.getDesktop().open(new File(folder)); } catch (IOException ex1) { JOptionPane.showMessageDialog(this, "Dicoogle can't open this file!", "Error opening the file", JOptionPane.ERROR_MESSAGE); } } } } else { try { SimpleEntry<RemoteFile, Integer> entry = UserRefs.getInstance().getSearch() .downloadFile(tmp); TransferStatus ts = new TransferStatus(entry.getKey()); FileReceiver receiver = new FileReceiver(entry.getKey(), clientCore.getServerAddress(), entry.getValue(), ts); Thread tReceiver = receiver; tReceiver.start(); ts.setVisible(true); ts.toFront(); } catch (RemoteException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } } } }
From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java
private void jButtonDownloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDownloadActionPerformed DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeResults.getLastSelectedPathComponent(); if (node == null) { return;/*from www . j a v a 2 s.c o m*/ } Object nodeInfo = node.getUserObject(); if (node.isLeaf() && SearchResult.class.isInstance(nodeInfo)) { try { SearchResult temp = (SearchResult) nodeInfo; UserRefs.getInstance().getSearch().RequestP2PFile(temp); } catch (RemoteException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java
/** * Checks if the options form is displayed * @return true if not displaying, true otherwise *//* w ww .j a v a 2s . c o m*/ private void showMetaData() { /** * Just show metadata for now **/ DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeResults.getLastSelectedPathComponent(); if (node != null && node.isLeaf() && node.getLevel() > 3) { Object nodeInfo = node.getUserObject(); SearchResult fileInfo = (SearchResult) nodeInfo; if (nodeInfo instanceof SearchResult) { IndexedMetaData metadataWindow = new IndexedMetaData(fileInfo, this); metadataWindow.setVisible(true); metadataWindow.toFront(); } } }
From source file:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java
public AsciidocBrowserApplication(final String[] args) { super("Asciidoc Browser"); setIconImage(Icons.APPLICATION.image()); setSize(1200, 1024);/*from w w w .jav a2s.c o m*/ addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { actionExit(); } }); JPanel buttonPanel = new JPanel(); backButton = new JButton(""); backButton.setIcon(Icons.BACK.icon()); backButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { actionBack(); } }); buttonPanel.setLayout(new MigLayout("", "[1px][][][][]", "[1px]")); JButton btnOptionsbutton = new JButton(""); btnOptionsbutton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { settingsDialog.setVisible(true); } }); btnOptionsbutton.setIcon(Icons.OPTIONS.icon()); buttonPanel.add(btnOptionsbutton, "flowx,cell 0 0"); backButton.setEnabled(false); buttonPanel.add(backButton, "cell 0 0,grow"); forwardButton = new JButton(""); forwardButton.setIcon(Icons.FORWARD.icon()); forwardButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { actionForward(); } }); forwardButton.setEnabled(false); buttonPanel.add(forwardButton, "cell 0 0,grow"); getContentPane().setLayout(new MigLayout("", "[793.00px,grow]", "[44px][930px]")); getContentPane().add(buttonPanel, "cell 0 0,growx,aligny top"); locationTextField = new JTextField(65); locationTextField.setText(""); locationTextField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB) { actionGo(); refreshDocumentTree(); } } }); locationTextField.setTransferHandler( new TextFieldTransferHandler(locationTextField.getTransferHandler(), new Runnable() { @Override public void run() { locationTextField.setText(""); } }, new Runnable() { @Override public void run() { actionGo(); refreshDocumentTree(); } })); homebutton = new JButton(""); homebutton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { locationTextField.setText(Settings.getHome()); actionGo(); refreshDocumentTree(); } }); refreshButton = new JButton(""); refreshButton.setToolTipText("Refresh"); refreshButton.setEnabled(false); refreshButton.setIcon(Icons.REFRESH.icon()); refreshButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { actionGo(); refreshPreview(); } }); buttonPanel.add(refreshButton, "cell 1 0"); homebutton.setIcon(Icons.HOME.icon()); buttonPanel.add(homebutton, "cell 2 0"); buttonPanel.add(locationTextField, "cell 3 0,grow"); treeSourceSplitPane = new JSplitPane(); treeSourceSplitPane.setResizeWeight(0.3); getContentPane().add(treeSourceSplitPane, "cell 0 1,grow"); treeScrollPane = new JScrollPane(); treeScrollPane.setMinimumSize(new Dimension(200, 200)); treeSourceSplitPane.setLeftComponent(treeScrollPane); documentTree = new DocumentTree(documentModel); documentTree.setCellRenderer(new TooltipsTreeCellRenderer()); ToolTipManager.sharedInstance().registerComponent(documentTree); ToolTipManager.sharedInstance().setInitialDelay(INITIAL_TOOLTIP_DELAY); ToolTipManager.sharedInstance().setReshowDelay(0); documentTree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(final TreeSelectionEvent tse) { TreePath newLeadSelectionPath = tse.getNewLeadSelectionPath(); if (newLeadSelectionPath != null && !newLeadSelectionPath.equals(currentSelectionPath)) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) newLeadSelectionPath .getLastPathComponent(); FileWrapper file = (FileWrapper) node.getUserObject(); showFile(file, true); refreshPreview(); } } }); treeScrollPane.setViewportView(documentTree); sourceEditorPane = new JEditorPane(); sourceEditorPane.setContentType("text/html"); sourceEditorPane.setEditable(false); sourceEditorPane.addHyperlinkListener(new HandleHyperlinkUpdate()); JScrollPane fileScrollPane = new JScrollPane(sourceEditorPane); fileScrollPane.setMinimumSize(new Dimension(600, 600)); documentTabbedPane = new JTabbedPane(SwingConstants.BOTTOM); documentTabbedPane.addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent ce) { refreshPreview(); } }); sourceLogSplitPane = new JSplitPane(); sourceLogSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); treeSourceSplitPane.setRightComponent(sourceLogSplitPane); sourceLogSplitPane.setTopComponent(documentTabbedPane); documentTabbedPane.add(fileScrollPane); documentTabbedPane.setTitleAt(0, "Source"); browserPane = new BrowserPane(); previewScrollPane = new JScrollPane(browserPane); documentTabbedPane.addTab("Preview", null, previewScrollPane, null); console = new JConsole(); System.setErr(console.getErr()); System.setOut(console.getOut()); sourceLogSplitPane.setBottomComponent(console); executor = new AsciidocExecutor(); }
From source file:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java
private void addFileWrapperChildren(final DefaultMutableTreeNode parentNode, final Object... parentPath) { FileWrapper parent = (FileWrapper) parentNode.getUserObject(); for (FileWrapper child : getChildren(parent)) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(child); parentNode.add(node);/*w w w . ja v a 2s . c o m*/ Object[] path = Arrays.copyOf(parentPath, parentPath.length + 1); path[parentPath.length] = node; paths.put(child, path); addFileWrapperChildren(node, path); } }
From source file:seleniumAutomation.flowControls.java
public static void parseNodes(javax.swing.tree.DefaultMutableTreeNode nodes) { for (int i = 0; i < nodes.getChildCount(); i++) { parseNodes((javax.swing.tree.DefaultMutableTreeNode) nodes.getChildAt(i)); }//from ww w . j av a 2s . c om if (nodes.getChildCount() == 0) { if (!testStep.isEmpty()) { if (!((javax.swing.tree.DefaultMutableTreeNode) nodes.getParent()).getLastChild().equals(nodes)) { testStep.add(nodes.getUserObject().toString()); } else { testStep.add(nodes.getUserObject().toString()); testSuite.put(testStep.get(0), testStep); testStep = new ArrayList<String>(); } } else { testStep = new ArrayList(); testStep.add(nodes.getUserObject().toString()); testSuite.put(testStep.get(0), testStep); } } }
From source file:ser321.media.MediaJavaClient.java
private void clearTree(DefaultMutableTreeNode root, DefaultTreeModel model) { try {//from w w w . java2 s. co m DefaultMutableTreeNode next = null; int subs = model.getChildCount(root); for (int k = subs - 1; k >= 0; k--) { next = (DefaultMutableTreeNode) model.getChild(root, k); debug("removing node labelled:" + (String) next.getUserObject()); model.removeNodeFromParent(next); } } catch (Exception ex) { System.out.println("Exception while trying to clear tree:"); ex.printStackTrace(); } }
From source file:ser321.media.MediaJavaClient.java
private DefaultMutableTreeNode getSubLabelled(DefaultMutableTreeNode root, String label) { DefaultMutableTreeNode ret = null; DefaultMutableTreeNode next = null; boolean found = false; for (Enumeration e = root.children(); e.hasMoreElements();) { next = (DefaultMutableTreeNode) e.nextElement(); debug("sub with label: " + (String) next.getUserObject()); if (((String) next.getUserObject()).equals(label)) { debug("found sub with label: " + label); found = true;//from w ww . ja va2 s .c o m break; } } if (found) ret = next; else ret = null; return ret; }