List of usage examples for weka.gui.treevisualizer TreeBuild create
public Node create(Reader t)
From source file:adams.flow.sink.WekaTreeVisualizer.java
License:Open Source License
/** * Creates a tree visualizer from the token. * //from w ww . j av a2s. com * @param token the input * @return the tree visualizer or null in case of an error */ protected TreeVisualizer createTreeVisualizer(Token token) { TreeVisualizer result; Reader reader; TreeBuild builder; Node top; NodePlace arrange; Object input; result = null; try { input = token.getPayload(); if (input instanceof WekaModelContainer) input = ((WekaModelContainer) input).getValue(WekaModelContainer.VALUE_MODEL); if (input instanceof String) { reader = new StringReader((String) input); } else if (input instanceof File) { reader = new BufferedReader(new FileReader(((File) input).getAbsolutePath())); } else { if (((Drawable) input).graphType() != Drawable.TREE) throw new IllegalArgumentException( token.getPayload().getClass().getName() + " does not generate a tree!"); reader = new StringReader(((Drawable) input).graph()); } } catch (Exception e) { handleException("Failed to instantiate reader for input!", e); return result; } builder = new TreeBuild(); top = null; arrange = new PlaceNode2(); try { top = builder.create(reader); result = new TreeVisualizer(null, top, arrange); } catch (Exception e) { handleException("Failed to parse dot notation!", e); } finally { if (reader != null) { try { reader.close(); } catch (Exception e) { // ignored } } } return result; }
From source file:adams.gui.menu.TreeVisualizer.java
License:Open Source License
/** * Launches the functionality of the menu item. *///from www. ja va2 s . c om @Override public void launch() { String filename; int retVal; TreeBuild builder; Node top; NodePlace arrange; ChildFrame frame; FileReader reader; if (m_Parameters.length == 0) { // choose file retVal = m_FileChooser.showOpenDialog(null); if (retVal != JFileChooser.APPROVE_OPTION) return; filename = m_FileChooser.getSelectedFile().getAbsolutePath(); } else { filename = new PlaceholderFile(m_Parameters[0]).getAbsolutePath(); } // build tree builder = new TreeBuild(); top = null; arrange = new PlaceNode2(); reader = null; try { reader = new FileReader(filename); top = builder.create(reader); } catch (Exception e) { GUIHelper.showErrorMessage(getOwner(), "Error loading file '" + filename + "':\n" + Utils.throwableToString(e)); return; } finally { if (reader != null) { try { reader.close(); } catch (Exception e) { // ignored } } } // create frame frame = createChildFrame(new weka.gui.treevisualizer.TreeVisualizer(null, top, arrange), GUIHelper.getDefaultDialogDimension()); frame.setTitle(frame.getTitle() + " - " + filename); }
From source file:de.fub.maps.project.detector.model.inference.impl.ShowGraphAction.java
License:Open Source License
private JComponent createTreeGraph(String graphDescriptor) { TreeBuild builder = new TreeBuild(); NodePlace placeNode = new PlaceNode2(); Node node = builder.create(new StringReader(graphDescriptor)); return new TreeVisualizer(null, node, placeNode); }
From source file:meka.gui.explorer.classify.ShowGraphs.java
License:Open Source License
/** * Returns the action lister to use in the menu. * * @param history the current history/*from w ww . j av a 2 s . co m*/ * @param index the selected history item * @return the listener */ @Override public ActionListener getActionListener(final ResultHistoryList history, final int index) { final MultiLabelDrawable d = (MultiLabelDrawable) getClassifier(history, index); return new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Map<Integer, String> graphs; Map<Integer, Integer> types; java.util.List<Integer> keys; try { types = d.graphType(); graphs = d.graph(); keys = new ArrayList<Integer>(types.keySet()); } catch (Exception ex) { System.err.println("Failed to obtain graph(s):"); ex.printStackTrace(); return; } JDialog dialog = new JDialog((Frame) null, history.getSuffixAt(index), false); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); JTabbedPane tabbed = new JTabbedPane(); dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(tabbed, BorderLayout.CENTER); for (Integer label : keys) { int type = types.get(label); JComponent comp = null; switch (type) { case MultiLabelDrawable.TREE: TreeBuild b = new TreeBuild(); PlaceNode2 arrange = new PlaceNode2(); Node top = b.create(new StringReader(graphs.get(label))); comp = new TreeVisualizer(null, top, arrange); break; case MultiLabelDrawable.BayesNet: GraphVisualizer g = new GraphVisualizer(); g.readDOT(new StringReader(graphs.get(label))); comp = g; break; default: System.err.println("Unsupported graph type for label " + label + ": " + type); } if (comp != null) tabbed.addTab("" + label, comp); } dialog.setSize(800, 600); dialog.setLocationRelativeTo(null); dialog.setVisible(true); } }; }