List of usage examples for javax.swing JComboBox addItemListener
public void addItemListener(ItemListener aListener)
ItemListener
. From source file:demos.TreeCollapse.java
@SuppressWarnings("unchecked") public TreeCollapse() { // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree();/* w w w . j a v a 2 s .c om*/ layout = new TreeLayout<String, Integer>(graph); collapser = new TreeCollapser(); radialLayout = new RadialTreeLayout<String, Integer>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<String, Integer>(layout, new Dimension(600, 600)); vv.setBackground(Color.white); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); rings = new Rings(); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Radial"); radial.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { // layout.setRadial(true); vv.setGraphLayout(radialLayout); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { // layout.setRadial(false); vv.setGraphLayout(layout); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection<?> picked = new HashSet<Object>(vv.getPickedVertexState().getPicked()); if (picked.size() == 1) { Object root = picked.iterator().next(); Forest<?, ?> inGraph = (Forest<?, ?>) layout.getGraph(); try { collapser.collapse(vv.getGraphLayout(), inGraph, root); } catch (InstantiationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); for (Object v : picked) { if (v instanceof Forest) { Forest inGraph = (Forest) layout.getGraph(); collapser.expand(inGraph, (Forest) v); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); controls.add(collapse); controls.add(expand); content.add(controls, BorderLayout.SOUTH); }
From source file:com.google.code.facebook.graph.sna.applet.VertexCollapseDemo.java
public VertexCollapseDemo() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); collapser = new GraphCollapser(graph); layout = new FRLayout(graph); Dimension preferredSize = new Dimension(400, 400); final VisualizationModel visualizationModel = new DefaultVisualizationModel(layout, preferredSize); vv = new VisualizationViewer(visualizationModel, preferredSize); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction()); final PredicatedParallelEdgeIndexFunction eif = PredicatedParallelEdgeIndexFunction.getInstance(); final Set exclusions = new HashSet(); eif.setPredicate(new Predicate() { public boolean evaluate(Object e) { return exclusions.contains(e); }/* w w w.jav a 2s . c om*/ }); vv.getRenderContext().setParallelEdgeIndexFunction(eif); vv.setBackground(Color.white); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller() { /* (non-Javadoc) * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction#getToolTipText(java.lang.Object) */ @Override public String transform(Object v) { if (v instanceof Graph) { return ((Graph) v).getVertices().toString(); } return super.transform(v); } }); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if (picked.size() > 1) { Graph inGraph = layout.getGraph(); Graph clusterGraph = collapser.getClusterGraph(inGraph, picked); Graph g = collapser.collapse(layout.getGraph(), clusterGraph); double sumx = 0; double sumy = 0; for (Object v : picked) { Point2D p = (Point2D) layout.transform(v); sumx += p.getX(); sumy += p.getY(); } Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / picked.size()); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); layout.setLocation(clusterGraph, cp); vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton compressEdges = new JButton("Compress Edges"); compressEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); exclusions.addAll(edges); vv.repaint(); } } }); JButton expandEdges = new JButton("Expand Edges"); expandEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); exclusions.removeAll(edges); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); for (Object v : picked) { if (v instanceof Graph) { Graph g = collapser.expand(layout.getGraph(), (Graph) v); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton reset = new JButton("Reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { layout.setGraph(graph); exclusions.clear(); vv.repaint(); } }); JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog((JComponent) e.getSource(), instructions, "Help", JOptionPane.PLAIN_MESSAGE); } }); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); zoomControls.add(plus); zoomControls.add(minus); controls.add(zoomControls); JPanel collapseControls = new JPanel(new GridLayout(3, 1)); collapseControls.setBorder(BorderFactory.createTitledBorder("Picked")); collapseControls.add(collapse); collapseControls.add(expand); collapseControls.add(compressEdges); collapseControls.add(expandEdges); collapseControls.add(reset); controls.add(collapseControls); controls.add(modeBox); controls.add(help); content.add(controls, BorderLayout.SOUTH); }
From source file:TreeColapse.java
@SuppressWarnings("unchecked") public TreeColapse() throws IOException { // create a simple graph for the demo graph = new DelegateForest<Node, Integer>(); createTree();/*from w ww.ja va2s.co m*/ layout = new TreeLayout<Node, Integer>(graph); collapser = new TreeCollapser(); radialLayout = new RadialTreeLayout<Node, Integer>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<Node, Integer>(layout, new Dimension(600, 600)); vv.setBackground(Color.white); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); //vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Node>()); vv.getRenderContext().setVertexLabelTransformer(new Transformer<Node, String>() { public String transform(Node e) { return (e.getName()); } }); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); rings = new Rings(); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Radial"); radial.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { // layout.setRadial(true); vv.setGraphLayout(radialLayout); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { // layout.setRadial(false); vv.setGraphLayout(layout); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if (picked.size() == 1) { Object root = picked.iterator().next(); Forest inGraph = (Forest) layout.getGraph(); try { collapser.collapse(vv.getGraphLayout(), inGraph, root); } catch (InstantiationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); for (Object v : picked) { if (v instanceof Forest) { Forest inGraph = (Forest) layout.getGraph(); collapser.expand(inGraph, (Forest) v); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); controls.add(collapse); controls.add(expand); content.add(controls, BorderLayout.SOUTH); }
From source file:gridvisual.GridVisualize.java
public GridVisualize() { // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree();//from w ww. j a va 2 s .c o m layout = new TreeLayout<String, Integer>(graph); radialLayout = new BalloonLayout<String, Integer>(graph); radialLayout.setSize(new Dimension(900, 900)); vv = new VisualizationViewer<String, Integer>(layout, new Dimension(600, 600)); vv.setBackground(Color.white); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); rings = new Rings(radialLayout); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); hyperbolicViewSupport = new ViewLensSupport<String, Integer>(vv, new HyperbolicShapeTransformer(vv, vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), new ModalLensGraphMouse()); graphMouse.addItemListener(hyperbolicViewSupport.getGraphMouse().getModeListener()); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); vv.scaleToLayout(scaler); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Balloon"); radial.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, layout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, radialLayout, layout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); final JRadioButton hyperView = new JRadioButton("Hyperbolic View"); hyperView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { hyperbolicViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); controls.add(hyperView); content.add(controls, BorderLayout.SOUTH); for (String v : layout.getGraph().getVertices()) { java.awt.Point p = nodeTable.get(new Integer(Integer.parseInt(v))).coord; layout.setLocation(v, p); } /* Transformer<Integer,Paint> vertexPaint = new Transformer<Integer,Paint>() { public Paint transform(Integer i) { return Color.GREEN; } };*/ /* Transformer<Integer, Paint> vertexPaint = new Transformer<Integer, Paint>() { private final Color[] palette = {Color.GREEN, Color.BLUE, Color.RED}; public Paint transform(Integer i) { return palette[i.intValue() % palette.length]; } };*/ vv.getRenderContext().setVertexFillPaintTransformer(new MyTransformer(this.nodeTable)); }
From source file:com.google.code.facebook.graph.sna.applet.VertexCollapseDemoWithLayouts.java
public VertexCollapseDemoWithLayouts() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); collapsedGraph = graph;/*from ww w. ja v a 2 s.c o m*/ collapser = new GraphCollapser(graph); layout = new FRLayout(graph); Dimension preferredSize = new Dimension(400, 400); final VisualizationModel visualizationModel = new DefaultVisualizationModel(layout, preferredSize); vv = new VisualizationViewer(visualizationModel, preferredSize); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction()); final PredicatedParallelEdgeIndexFunction eif = PredicatedParallelEdgeIndexFunction.getInstance(); final Set exclusions = new HashSet(); eif.setPredicate(new Predicate() { public boolean evaluate(Object e) { return exclusions.contains(e); } }); vv.getRenderContext().setParallelEdgeIndexFunction(eif); vv.setBackground(Color.white); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller() { /* (non-Javadoc) * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction#getToolTipText(java.lang.Object) */ @Override public String transform(Object v) { if (v instanceof Graph) { return ((Graph) v).getVertices().toString(); } return super.transform(v); } }); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if (picked.size() > 1) { Graph inGraph = layout.getGraph(); Graph clusterGraph = collapser.getClusterGraph(inGraph, picked); Graph g = collapser.collapse(layout.getGraph(), clusterGraph); collapsedGraph = g; double sumx = 0; double sumy = 0; for (Object v : picked) { Point2D p = (Point2D) layout.transform(v); sumx += p.getX(); sumy += p.getY(); } Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / picked.size()); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); layout.setLocation(clusterGraph, cp); vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton compressEdges = new JButton("Compress Edges"); compressEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); exclusions.addAll(edges); vv.repaint(); } } }); JButton expandEdges = new JButton("Expand Edges"); expandEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); exclusions.removeAll(edges); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); for (Object v : picked) { if (v instanceof Graph) { Graph g = collapser.expand(layout.getGraph(), (Graph) v); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton reset = new JButton("Reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { layout.setGraph(graph); exclusions.clear(); vv.repaint(); } }); JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog((JComponent) e.getSource(), instructions, "Help", JOptionPane.PLAIN_MESSAGE); } }); Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, vv)); jcb.setSelectedItem(FRLayout.class); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); zoomControls.add(plus); zoomControls.add(minus); controls.add(zoomControls); JPanel collapseControls = new JPanel(new GridLayout(3, 1)); collapseControls.setBorder(BorderFactory.createTitledBorder("Picked")); collapseControls.add(collapse); collapseControls.add(expand); collapseControls.add(compressEdges); collapseControls.add(expandEdges); collapseControls.add(reset); controls.add(collapseControls); controls.add(modeBox); controls.add(help); controls.add(jcb); content.add(controls, BorderLayout.SOUTH); }
From source file:ch.admin.hermes.etl.load.HermesETLApplication.java
/** * CommandLine parse und fehlende Argumente verlangen * @param args Args// w w w. java 2s . com * @throws ParseException */ private static void parseCommandLine(String[] args) throws Exception { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // HACK um UTF-8 CharSet fuer alle Dateien zu setzen (http://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding) System.setProperty("file.encoding", "UTF-8"); Field charset = Charset.class.getDeclaredField("defaultCharset"); charset.setAccessible(true); charset.set(null, null); // commandline Options - FremdsystemSite, Username und Password Options options = new Options(); options.addOption("s", true, "Zielsystem - URL"); options.addOption("u", true, "Zielsystem - Username"); options.addOption("p", true, "Zielsystem - Password"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); site = cmd.getOptionValue("s"); user = cmd.getOptionValue("u"); passwd = cmd.getOptionValue("p"); // restliche Argumente pruefen - sonst usage ausgeben String[] others = cmd.getArgs(); if (others.length >= 1 && (others[0].endsWith(".js") || others[0].endsWith(".ftl"))) script = others[0]; if (others.length >= 2 && others[1].endsWith(".xml")) model = others[1]; // Dialog mit allen Werten zusammenstellen JComboBox<String> scenarios = new JComboBox<String>(crawler.getScenarios()); JTextField tsite = new JTextField(45); tsite.setText(site); JTextField tuser = new JTextField(16); tuser.setText(user); JPasswordField tpasswd = new JPasswordField(16); tpasswd.setText(passwd); final JTextField tscript = new JTextField(45); tscript.setText(script); final JTextField tmodel = new JTextField(45); tmodel.setText(model); JPanel myPanel = new JPanel(new GridLayout(6, 2)); myPanel.add(new JLabel("Szenario (von http://www.hermes.admin.ch):")); myPanel.add(scenarios); myPanel.add(new JLabel("XML Model:")); myPanel.add(tmodel); JPanel pmodel = new JPanel(); pmodel.add(tmodel); JButton bmodel = new JButton("..."); pmodel.add(bmodel); bmodel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model = getFile("Szenario XML Model", new String[] { "XML Model" }, new String[] { ".xml" }); if (model != null) tmodel.setText(model); } }); myPanel.add(pmodel); scenarios.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { try { Object o = e.getItem(); tmodel.setText(crawler.getModelURL(o.toString())); scenario = o.toString(); } catch (Exception e1) { } } }); // Script myPanel.add(new JLabel("Umwandlungs-Script:")); JPanel pscript = new JPanel(); pscript.add(tscript); JButton bscript = new JButton("..."); pscript.add(bscript); myPanel.add(pscript); bscript.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { script = getFile("JavaScript/Freemarker Umwandlungs-Script", new String[] { "JavaScript", "Freemarker" }, new String[] { ".js", ".ftl" }); if (script != null) tscript.setText(script); } }); // Zielsystem Angaben myPanel.add(new JLabel("Zielsystem URL:")); myPanel.add(tsite); myPanel.add(new JLabel("Zielsystem Benutzer:")); myPanel.add(tuser); myPanel.add(new JLabel("Zielsystem Password:")); myPanel.add(tpasswd); // Trick um Feld scenario und model zu setzen. if (scenarios.getItemCount() >= 8) scenarios.setSelectedIndex(8); // Dialog int result = JOptionPane.showConfirmDialog(null, myPanel, "HERMES 5 XML Model nach Fremdsystem/Format", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { site = tsite.getText(); user = tuser.getText(); passwd = new String(tpasswd.getPassword()); model = tmodel.getText(); script = tscript.getText(); } else System.exit(1); if (model == null || script == null || script.trim().length() == 0) usage(); if (script.endsWith(".js")) if (site == null || user == null || passwd == null || user.trim().length() == 0 || passwd.trim().length() == 0) usage(); }
From source file:es.urjc.ia.fia.genericSearch.statistics.JUNGStatistics.java
@Override public void showStatistics() { // Layout: tree and radial treeLayout = new TreeLayout<AuxVertex, ACTION>(this.tree, 35, 100); radialLayout = new RadialTreeLayout<AuxVertex, ACTION>(this.tree, 35, 130); radialLayout.setSize(new Dimension(200 * (this.tree.getHeight() + 1), 200 * (this.tree.getHeight() + 1))); // The BasicVisualizationServer<V,E> is parameterized by the edge types vv = new VisualizationViewer<AuxVertex, ACTION>(treeLayout); vv.setPreferredSize(new Dimension(800, 600)); //Sets the viewing area size vv.setBackground(Color.white); // Background color vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<AuxVertex>()); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<AuxVertex, ACTION>()); // Setup up a new vertex to paint transformer Transformer<AuxVertex, Paint> vertexPaint = new Transformer<AuxVertex, Paint>() { @Override//from ww w .j av a2 s. co m public Paint transform(AuxVertex arg0) { if (arg0.getState().isSolution() && arg0.isExplored()) { return Color.GREEN; } else if (arg0.isExplored()) { return Color.CYAN; } else if (arg0.isDuplicated()) { return Color.GRAY; } else { return Color.WHITE; } } }; // Tooltip for vertex Transformer<AuxVertex, String> toolTipsState = new Transformer<AuxVertex, String>() { @Override public String transform(AuxVertex arg0) { String sortInfo = ""; if (arg0.isExplored()) { if (arg0.getState().isSolution() && arg0.isExplored()) { sortInfo = "<u><i>Solution state " + arg0.getExplored() + "</i></u>"; } else { sortInfo = "<u><i>Explored state " + arg0.getExplored() + "</i></u>"; } } else if (arg0.isDuplicated()) { sortInfo = "<u><i>Duplicated state </i></u>"; } else { sortInfo = "<u><i>Unexplored state</i></u>"; } return "<html><p>" + sortInfo + "</p>" + "<p>State: " + arg0.getState().toString() + "</p>" + "<p>Cost: " + arg0.getState().getSolutionCost() + "</p></html>"; } }; vv.setVertexToolTipTransformer(toolTipsState); // Tooltip for edge Transformer<ACTION, String> toolTipsAction = new Transformer<ACTION, String>() { @Override public String transform(ACTION arg0) { return "Cost: " + arg0.cost(); } }; vv.setEdgeToolTipTransformer(toolTipsAction); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<AuxVertex, ACTION>()); vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<ACTION>()); vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); // Create a graph mouse and add it to the visualization component DefaultModalGraphMouse<State<ACTION>, ACTION> gm = new DefaultModalGraphMouse<State<ACTION>, ACTION>(); gm.setMode(ModalGraphMouse.Mode.TRANSFORMING); vv.setGraphMouse(gm); vv.addKeyListener(gm.getModeKeyListener()); JFrame vFrame = new JFrame("Statistics Tree View"); vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /* vFrame.getContentPane().add(vv); vFrame.pack(); vFrame.setVisible(true); */ rings = new Rings(); Container content = vFrame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); JComboBox modeBox = gm.getModeComboBox(); modeBox.addItemListener(gm.getModeListener()); gm.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Radial"); radial.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LayoutTransition<AuxVertex, ACTION> lt = new LayoutTransition<AuxVertex, ACTION>(vv, treeLayout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<AuxVertex, ACTION> lt = new LayoutTransition<AuxVertex, ACTION>(vv, radialLayout, treeLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); /* * Statistics */ JLabel stats = new JLabel(); long totalTime = endTime.getTime() - initTime.getTime(); stats.setText("<html>" + "<b>Total States:</b> " + this.totalStates + "<br>" + "<b>Explored States:</b> " + this.explorerStates + "<br>" + "<b>Duplicated States (detected):</b> " + this.duplicatedStates + "<br>" + "<b>Solution States:</b> " + this.solutionStates + "<br>" + "<b>Total time: </b>" + totalTime + " milliseconds" + "</html>"); JPanel legend = new JPanel(); legend.setLayout(new BoxLayout(legend, BoxLayout.Y_AXIS)); JLabel len = new JLabel("<html><b>Lengend</b></html>"); JLabel lexpl = new JLabel("Explored state"); lexpl.setBackground(Color.CYAN); lexpl.setOpaque(true); JLabel lune = new JLabel("Unexplored state"); lune.setBackground(Color.WHITE); lune.setOpaque(true); JLabel ldupl = new JLabel("Duplicated state"); ldupl.setBackground(Color.GRAY); ldupl.setOpaque(true); JLabel lsol = new JLabel("Solution state"); lsol.setBackground(Color.GREEN); lsol.setOpaque(true); legend.add(len); legend.add(lexpl); legend.add(lune); legend.add(ldupl); legend.add(lsol); JPanel controls = new JPanel(); controls.add(stats); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); //controls.add(modeBox); controls.add(legend); content.add(controls, BorderLayout.SOUTH); vFrame.pack(); vFrame.setVisible(true); }
From source file:fr.free.hd.servers.gui.FaceView.java
private JPanel createPosition() { JPanel panel = new JPanel(new GridLayout(5, 0)); final JSlider slider = new JSlider(); final JSlider sliderDegree = new JSlider(); final JSlider sliderX = new JSlider(); final JSlider sliderY = new JSlider(); slider.setMinimum(0);/*from w w w . j a v a 2 s .com*/ slider.setMaximum(1000); sliderX.setMinimum(-1000); sliderX.setMaximum(1000); sliderX.setMajorTickSpacing(100); sliderX.setPaintLabels(true); sliderX.setPaintTicks(true); sliderX.setPaintTrack(true); sliderY.setMinimum(-1000); sliderY.setMaximum(1000); sliderY.setMajorTickSpacing(100); sliderY.setPaintLabels(true); sliderY.setPaintTicks(true); sliderY.setPaintTrack(true); sliderDegree.setMinimum(0); sliderDegree.setMaximum(360); sliderDegree.setMajorTickSpacing(20); sliderDegree.setPaintLabels(true); sliderDegree.setPaintTicks(true); sliderDegree.setPaintTrack(true); final JComboBox box = new JComboBox(HandPositionEnum.values()); box.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { position = (HandPositionEnum) e.getItem(); updateLabel(); } }); panel.add(box); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { switch (position) { case HAND_POSITION_BOUCHE: face.setBoucheRatio(slider.getValue()); break; case HAND_POSITION_COTE: face.setCoteRatio(slider.getValue()); break; case HAND_POSITION_COU: face.setCouRatio(slider.getValue()); break; case HAND_POSITION_MENTON: face.setMentonRatio(slider.getValue()); break; case HAND_POSITION_PAUMETTE: face.setPaumetteRatio(slider.getValue()); break; } updateLabel(); } }); sliderDegree.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { switch (position) { case HAND_POSITION_BOUCHE: face.setBoucheDegree(sliderDegree.getValue()); break; case HAND_POSITION_COTE: face.setCoteDegree(sliderDegree.getValue()); break; case HAND_POSITION_COU: face.setCouDegree(sliderDegree.getValue()); break; case HAND_POSITION_MENTON: face.setMentonDegree(sliderDegree.getValue()); break; case HAND_POSITION_PAUMETTE: face.setPaumetteDegree(sliderDegree.getValue()); break; } updateLabel(); } }); sliderX.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { switch (position) { case HAND_POSITION_BOUCHE: face.setBoucheX(sliderX.getValue()); break; case HAND_POSITION_COTE: face.setCoteX(sliderX.getValue()); break; case HAND_POSITION_COU: face.setCouX(sliderX.getValue()); break; case HAND_POSITION_MENTON: face.setMentonX(sliderX.getValue()); break; case HAND_POSITION_PAUMETTE: face.setPaumetteX(sliderX.getValue()); break; } updateLabel(); } }); sliderY.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { switch (position) { case HAND_POSITION_BOUCHE: face.setBoucheY(sliderY.getValue()); break; case HAND_POSITION_COTE: face.setCoteY(sliderY.getValue()); break; case HAND_POSITION_COU: face.setCouY(sliderY.getValue()); break; case HAND_POSITION_MENTON: face.setMentonY(sliderY.getValue()); break; case HAND_POSITION_PAUMETTE: face.setPaumetteY(sliderY.getValue()); break; } updateLabel(); } }); panel.add(slider); panel.add(sliderX); panel.add(sliderY); panel.add(sliderDegree); return panel; }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.graph.CollapsableGraphView.java
public CollapsableGraphView(Graph graph, boolean val) throws HeadlessException { super();/*from w ww. j a v a2 s. c o m*/ setGraph(graph); layout = new FRLayout(graph); Dimension preferredSize = new Dimension(400, 400); final VisualizationModel visualizationModel = new DefaultVisualizationModel(layout, preferredSize); VisualizationViewer vv = new VisualizationViewer(visualizationModel, preferredSize); vv.addGraphMouseListener(new CollapsableGraphMouseListener<Number>()); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeTransformer()); PickedState<Integer> picked_state = vv.getPickedVertexState(); // create decorators vv.getRenderContext().setVertexFillPaintTransformer(IB_TransformerFactory.getDefaultPaintTransformer(vv)); setVisViewer(vv); final PredicatedParallelEdgeIndexFunction eif = PredicatedParallelEdgeIndexFunction.getInstance(); final Set exclusions = new HashSet(); eif.setPredicate(new Predicate() { public boolean evaluate(Object e) { return exclusions.contains(e); } }); vv.getRenderContext().setParallelEdgeIndexFunction(eif); vv.setBackground(Color.white); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller() { /* * (non-Javadoc) * * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction# * getToolTipText(java.lang.Object) */ @Override public String transform(Object v) { if (v instanceof Graph) { return ((Graph) v).getVertices().toString(); } return super.transform(v); } }); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Collapsing the graph"); // Pick all port zeros, and their IMMEDIATE links // PickManager.getInstance().pickAllSwitches(vv); VisualizationViewer vv = getVisViewer(); Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if (picked.size() > 1) { System.out.println("CGV: The number picked is: " + picked.size()); Graph inGraph = layout.getGraph(); Graph clusterGraph = collapser.getClusterGraph(inGraph, picked); Graph g = collapser.collapse(layout.getGraph(), clusterGraph); collapsedGraph = g; double sumx = 0; double sumy = 0; for (Object v : picked) { Point2D p = (Point2D) layout.transform(v); sumx += p.getX(); sumy += p.getY(); } Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / picked.size()); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); layout.setLocation(clusterGraph, cp); vv.getPickedVertexState().clear(); vv.repaint(); } // Collection picked = new // HashSet(vv.getPickedVertexState().getPicked()); // if (picked.size() > 1) // { // Graph inGraph = layout.getGraph(); // Graph clusterGraph = collapser.getClusterGraph(inGraph, picked); // // Graph g = collapser.collapse(layout.getGraph(), clusterGraph); // collapsedGraph = g; // double sumx = 0; // double sumy = 0; // for (Object v : picked) // { // Point2D p = (Point2D) layout.transform(v); // sumx += p.getX(); // sumy += p.getY(); // } // Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / // picked.size()); // vv.getRenderContext().getParallelEdgeIndexFunction().reset(); // layout.setGraph(g); // layout.setLocation(clusterGraph, cp); // vv.getPickedVertexState().clear(); // vv.repaint(); // } } }); JButton compressEdges = new JButton("Compress Edges"); compressEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); getExclusions().addAll(edges); vv.repaint(); } } }); JButton expandEdges = new JButton("Expand Edges"); expandEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); getExclusions().removeAll(edges); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); for (Object v : picked) { if (v instanceof Graph) { Graph g = collapser.expand(layout.getGraph(), (Graph) v); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton reset = new JButton("Reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); Graph g = getGraph(); layout.setGraph(g); getExclusions().clear(); vv.repaint(); } }); JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog((JComponent) e.getSource(), getInstructions(), "Help", JOptionPane.PLAIN_MESSAGE); } }); Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, vv, this)); jcb.setSelectedItem(FRLayout.class); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); zoomControls.add(plus); zoomControls.add(minus); controls.add(zoomControls); JPanel collapseControls = new JPanel(new GridLayout(3, 1)); collapseControls.setBorder(BorderFactory.createTitledBorder("Picked")); collapseControls.add(collapse); collapseControls.add(expand); collapseControls.add(compressEdges); collapseControls.add(expandEdges); collapseControls.add(reset); controls.add(collapseControls); controls.add(modeBox); controls.add(help); controls.add(jcb); content.add(controls, BorderLayout.SOUTH); }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupportDemo.java
private Component createToolBar() { JToolBar result = new JToolBar(); result.setFloatable(false);/*from w ww .ja v a2 s .co m*/ result.add(RANDOM_DATA.toAction(chart)).setIcon(FontAwesome.FA_RANDOM.getIcon(getForeground(), 16f)); JComboBox<RendererType> types = new JComboBox<>( support.getSupportedRendererTypes().toArray(new RendererType[0])); types.setMaximumSize(new Dimension(150, 100)); types.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { RendererType type = (RendererType) e.getItem(); chart.getXYPlot().setRenderer(support.createRenderer(type)); chart.getXYPlot().setBackgroundPaint(support.getPlotColor()); chart.setBackgroundPaint(colorSchemeSupport.getBackColor()); } }); types.setSelectedIndex(1); result.add(types); return result; }