List of usage examples for javax.swing JRootPane putClientProperty
public final void putClientProperty(Object key, Object value)
From source file:jpad.MainEditor.java
public void openFile_OSX_Nix() { isOpen = true;//from w w w . j av a 2s . c om FilenameFilter awtFilter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { String lowercaseName = name.toLowerCase(); if (lowercaseName.endsWith(".txt")) return true; else return false; } }; FileDialog fd = new FileDialog(this, "Open Text File", FileDialog.LOAD); fd.setFilenameFilter(awtFilter); fd.setVisible(true); if (fd.getFile() == null) return; else curFile = fd.getDirectory() + fd.getFile(); //TODO: actually open the file try (FileInputStream inputStream = new FileInputStream(curFile)) { String allText = org.apache.commons.io.IOUtils.toString(inputStream); mainTextArea.setText(allText); } catch (Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), "Error While Reading", JOptionPane.ERROR_MESSAGE); } JRootPane root = this.getRootPane(); root.putClientProperty("Window.documentFile", new File(curFile)); root.putClientProperty("Window.documentModified", Boolean.FALSE); hasChanges = false; hasSavedToFile = true; this.setTitle(String.format("JPad - %s", curFile)); isOpen = false; }
From source file:jpad.MainEditor.java
public void saveAs_OSX_Nix() { String fileToSaveTo = null;/*www . j av a2 s . c om*/ FilenameFilter awtFilter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { String lowercaseName = name.toLowerCase(); if (lowercaseName.endsWith(".txt")) { return true; } else { return false; } } }; FileDialog fd = new FileDialog(this, "Save Text File", FileDialog.SAVE); fd.setDirectory(System.getProperty("java.home")); if (curFile == null) fd.setFile("Untitled.txt"); else fd.setFile(curFile); fd.setFilenameFilter(awtFilter); fd.setVisible(true); if (fd.getFile() != null) fileToSaveTo = fd.getDirectory() + fd.getFile(); else { fileToSaveTo = fd.getFile(); return; } curFile = fileToSaveTo; JRootPane root = this.getRootPane(); root.putClientProperty("Window.documentFile", new File(curFile)); hasChanges = false; hasSavedToFile = true; }
From source file:model.DrawTopologyDiagram.java
@Override public void init() { //create a graph Graph<VertexTopology, Number> ig = Graphs.<VertexTopology, Number>synchronizedDirectedGraph( new DirectedSparseMultigraph<VertexTopology, Number>()); ObservableGraph<VertexTopology, Number> og = new ObservableGraph<VertexTopology, Number>(ig); og.addGraphEventListener(new GraphEventListener<VertexTopology, Number>() { public void handleGraphEvent(GraphEvent<VertexTopology, Number> evt) { System.err.println("got " + evt); }// w ww. j a v a 2 s . co m }); this.g = og; //layouts //create a graphdraw // layout = new FRLayout2<String,Number>(g); // layout = new SpringLayout<String,Number>(g); // ((FRLayout)layout).setMaxIterations(200); layout = new KKLayout<VertexTopology, Number>(g); vv = new VisualizationViewer<VertexTopology, Number>(layout, new Dimension(600, 600)); createGraph(); Container content = getContentPane(); JPanel totalCasesPanel = new JPanel(); final JPanel scaleGrids = new JPanel(new GridLayout(0, 2)); scaleGrids.add(new JLabel(" Test Cases ")); scaleGrids.add(new JLabel(" ")); totalCasesPanel.add(scaleGrids); JPanel filteredCasesPanel = new JPanel(); final JPanel filteredGrids = new JPanel(new GridLayout(0, 2)); filteredGrids.add(new JLabel(" Filtered Cases ")); filteredGrids.add(new JLabel(" ")); filteredCasesPanel.add(filteredGrids); JRootPane rp = this.getRootPane(); rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); content.setLayout(new BorderLayout()); content.setBackground(java.awt.Color.lightGray); content.setFont(new Font("Serif", Font.PLAIN, 12)); vv.getModel().getRelaxer().setSleepTime(500); vv.setGraphMouse(new DefaultModalGraphMouse<VertexTopology, Number>()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv.setForeground(Color.white); FontMetrics fm = vv.getFontMetrics(vv.getFont()); int width = fm.stringWidth(g.toString()); Transformer<VertexTopology, Shape> vertexSize = new Transformer<VertexTopology, Shape>() { public Shape transform(VertexTopology i) { Ellipse2D circle = new Ellipse2D.Double(-20, -20, 40, 40); // in this case, the vertex is twice as large return circle; } }; vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller() { @Override public String transform(Object v) { return ((VertexTopology) v).getScreenName(); } }); vv.getRenderContext().setVertexShapeTransformer(vertexSize); //Get picked states final PickedState<VertexTopology> pickedState = vv.getPickedVertexState(); pickedState.addItemListener(new ItemListener() { ArrayList<TestCase> outputTestCase = new ArrayList<TestCase>(); final Map<String, JButton> createdBtns = new HashMap<String, JButton>(); Map<String, Integer> deviceSelected = new HashMap<String, Integer>(); // not useful ArrayList<String> endPointList = new ArrayList<String>(); @Override public void itemStateChanged(ItemEvent e) { // TODO Auto-generated method stub Object subject = e.getItem(); if (e.getStateChange() != 1) { scaleGrids.removeAll(); filteredGrids.removeAll(); endPointList.remove(getScreenName(subject)); outputTestCase.clear(); filteredGrids.repaint(); filteredGrids.add(new JLabel(" Filtered Cases ")); filteredGrids.add(new JLabel(" ")); scaleGrids.repaint(); scaleGrids.add(new JLabel(" Test Cases ")); scaleGrids.add(new JLabel(" ")); deviceSelected.clear(); } if (e.getStateChange() == 1) { for (TestCase testCase : outputTestCase) { scaleGrids.removeAll(); scaleGrids.add(new JLabel(" Test Cases ")); scaleGrids.add(new JLabel(" ")); filteredGrids.removeAll(); filteredGrids.add(new JLabel(" Filtered Cases ")); filteredGrids.add(new JLabel(" ")); } if (subject instanceof VertexTopology) { final VertexTopology edgePicked = (VertexTopology) subject; if (pickedState.isPicked(edgePicked)) { for (TestCase testCase : edgePicked.getTestCaseList()) { if (!outputTestCase.contains(testCase)) outputTestCase.add(testCase); System.out.println("The size for reference is " + testCase.inputReferenceMap.size() + testCase.getName()); System.out.println("The size for target is " + testCase.inputTargetMap.size() + testCase.getName()); } if (deviceSelected.get(edgePicked.getScreenName()) != null) deviceSelected.put(edgePicked.getScreenName(), deviceSelected.get(edgePicked.getScreenName()) + 1); else deviceSelected.put(edgePicked.getScreenName(), 1); endPointList.add(edgePicked.getScreenName()); } } } for (TestCase testCase : outputTestCase) { JButton btnCase = new JButton(testCase.getName()); scaleGrids.add(btnCase); if (testCase.getInputDeviceList().size() <= endPointList.size()) if (testCaseSelected(testCase, endPointList)) { JButton btnCaseFiltered = new JButton(testCase.getName()); filteredGrids.add(btnCaseFiltered); } ; } scaleGrids.revalidate(); scaleGrids.setVisible(true); } }); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); content.setPreferredSize(new Dimension(1400, 900)); content.add(vv); switchLayout = new JButton("Switch to SpringLayout"); // switchLayout.addActionListener(new ActionListener() { // // @SuppressWarnings("unchecked") // public void actionPerformed(ActionEvent ae) { // Dimension d = new Dimension(600,600); // if (switchLayout.getText().indexOf("Spring") > 0) { // switchLayout.setText("Switch to FRLayout"); // layout = new SpringLayout<String,Number>(g, // new ConstantTransformer(EDGE_LENGTH)); // layout.setSize(d); // vv.getModel().setGraphLayout(layout, d); // } else { // switchLayout.setText("Switch to SpringLayout"); // layout = new FRLayout<String,Number>(g, d); // vv.getModel().setGraphLayout(layout, d); // } // } // }); JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, totalCasesPanel, filteredCasesPanel); jSplitPane.setResizeWeight(.5d); content.add(switchLayout, BorderLayout.SOUTH); content.add(jSplitPane, BorderLayout.EAST); }
From source file:org.metacsp.utility.UI.ConstraintNetworkFrame.java
public ConstraintNetworkFrame(ObservableGraph<Variable, Constraint> graph, String title, final Callback cb) { super(title); this.g = graph; g.addGraphEventListener(new GraphEventListener<Variable, Constraint>() { @Override/* w w w.jav a 2s . co m*/ public void handleGraphEvent(GraphEvent<Variable, Constraint> evt) { vv.getRenderContext().getPickedVertexState().clear(); vv.getRenderContext().getPickedEdgeState().clear(); try { layout.initialize(); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { e.printStackTrace(); } StaticLayout<Variable, Constraint> staticLayout = new StaticLayout<Variable, Constraint>(g, layout); lt = new LayoutTransition<Variable, Constraint>(vv, vv.getGraphLayout(), staticLayout); animator = new MyAnimator(lt); animator.start(); //vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } catch (Exception e) { e.printStackTrace(); } } }); //create a graphdraw //layout = new FRLayout<Variable,Constraint>(g); //layout = new SpringLayout<Variable,Constraint>(g); //layout = new StaticLayout<Variable,Constraint>(g,new STNTransformer()); layout = new FRLayout2<Variable, Constraint>(g); //layout = new CircleLayout<Variable,Constraint>(g); //layout = new ISOMLayout<Variable,Constraint>(g); //layout = new KKLayout<Variable,Constraint>(g); layout.setSize(new Dimension(600, 600)); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { e.printStackTrace(); } Layout<Variable, Constraint> staticLayout = new StaticLayout<Variable, Constraint>(g, layout); vv = new VisualizationViewer<Variable, Constraint>(staticLayout, new Dimension(600, 600)); JRootPane rp = this.getRootPane(); rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); getContentPane().setLayout(new BorderLayout()); getContentPane().setBackground(java.awt.Color.lightGray); getContentPane().setFont(new Font("Serif", Font.PLAIN, 12)); vv.setGraphMouse(new DefaultModalGraphMouse<Variable, Constraint>()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.S); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Variable>()); vv.setForeground(Color.black); //draw edge labels Transformer<Constraint, String> stringer = new Transformer<Constraint, String>() { @Override public String transform(Constraint e) { try { return e.getEdgeLabel(); } catch (NullPointerException ex) { return ""; } } }; Transformer<Variable, Paint> vertexPaint = new Transformer<Variable, Paint>() { public Paint transform(Variable v) { return v.getColor(); } }; Transformer<Constraint, Paint> constraintPaint = new Transformer<Constraint, Paint>() { public Paint transform(Constraint c) { return c.getColor(); } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); // vv.getRenderContext().setEdgeFillPaintTransformer(constraintPaint); vv.getRenderContext().setEdgeLabelTransformer(stringer); // vv.getRenderContext().setEdgeDrawPaintTransformer(new PickableEdgePaintTransformer<Constraint>(vv.getPickedEdgeState(), Color.black, Color.cyan)); vv.getRenderContext().setEdgeDrawPaintTransformer(constraintPaint); vv.addComponentListener(new ComponentAdapter() { /** * @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent) */ @Override public void componentResized(ComponentEvent arg0) { super.componentResized(arg0); layout.setSize(arg0.getComponent().getSize()); } }); getContentPane().add(vv); performOperation = new JButton("Perform operation"); if (cb == null) performOperation.setEnabled(false); else performOperation.setEnabled(true); performOperation.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (cb != null) cb.performOperation(); } }); switchLayout = new JButton("Switch to SpringLayout"); switchLayout.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { Dimension d = vv.getSize();//new Dimension(600,600); if (switchLayout.getText().indexOf("Spring") > 0) { switchLayout.setText("Switch to FRLayout"); //layout = new SpringLayout<Variable,Constraint>(g, new ConstantTransformer(EDGE_LENGTH)); layout = new SpringLayout<Variable, Constraint>(g); layout.setSize(d); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { e.printStackTrace(); } StaticLayout<Variable, Constraint> staticLayout = new StaticLayout<Variable, Constraint>(g, layout); lt = new LayoutTransition<Variable, Constraint>(vv, vv.getGraphLayout(), staticLayout); Animator animator = new MyAnimator(lt); animator.start(); // vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } else { switchLayout.setText("Switch to SpringLayout"); layout = new FRLayout<Variable, Constraint>(g, d); layout.setSize(d); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } StaticLayout<Variable, Constraint> staticLayout = new StaticLayout<Variable, Constraint>(g, layout); lt = new LayoutTransition<Variable, Constraint>(vv, vv.getGraphLayout(), staticLayout); Animator animator = new MyAnimator(lt); animator.start(); //vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } } }); getContentPane().add(performOperation, BorderLayout.SOUTH); //getContentPane().add(switchLayout, BorderLayout.SOUTH); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.pack(); this.setVisible(true); }
From source file:org.metacsp.utility.UI.FiniteStateAutomatonFrame.java
public FiniteStateAutomatonFrame(ObservableGraph<String[], Interval> graph) { super("Constraint Network"); g = graph;/*from w w w.j a v a2s . co m*/ g.addGraphEventListener(new GraphEventListener<String[], Interval>() { public void handleGraphEvent(GraphEvent<String[], Interval> evt) { System.err.println("got " + evt); /****/ vv.getRenderContext().getPickedVertexState().clear(); vv.getRenderContext().getPickedEdgeState().clear(); try { layout.initialize(); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } StaticLayout<String[], Interval> staticLayout = new StaticLayout<String[], Interval>(g, layout); LayoutTransition<String[], Interval> lt = new LayoutTransition<String[], Interval>(vv, vv.getGraphLayout(), staticLayout); Animator animator = new Animator(lt); animator.start(); // vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } catch (Exception e) { System.out.println(e); } /****/ } }); //create a graphdraw //layout = new FRLayout<State,Interval>(g); //layout = new SpringLayout<State,Interval>(g); //layout = new StaticLayout<State,Interval>(g,new STNTransformer()); layout = new FRLayout2<String[], Interval>(g); //layout = new CircleLayout<State,Interval>(g); //layout = new ISOMLayout<State,Interval>(g); //layout = new KKLayout<State,Interval>(g); layout.setSize(new Dimension(600, 600)); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } Layout<String[], Interval> staticLayout = new StaticLayout<String[], Interval>(g, layout); vv = new VisualizationViewer<String[], Interval>(staticLayout, new Dimension(600, 600)); JRootPane rp = this.getRootPane(); rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); getContentPane().setLayout(new BorderLayout()); getContentPane().setBackground(java.awt.Color.lightGray); getContentPane().setFont(new Font("Serif", Font.PLAIN, 12)); vv.setGraphMouse(new DefaultModalGraphMouse<String[], Interval>()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.S); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String[]>()); vv.setForeground(Color.black); //draw edge labels Transformer<Interval, String> stringer = new Transformer<Interval, String>() { public String transform(Interval e) { return e.toString(); } }; vv.getRenderContext().setEdgeLabelTransformer(stringer); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Interval>(vv.getPickedEdgeState(), Color.black, Color.cyan)); vv.addComponentListener(new ComponentAdapter() { /** * @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent) */ @Override public void componentResized(ComponentEvent arg0) { super.componentResized(arg0); System.err.println("resized"); layout.setSize(arg0.getComponent().getSize()); } }); getContentPane().add(vv); switchLayout = new JButton("Switch to SpringLayout"); switchLayout.addActionListener(new ActionListener() { @SuppressWarnings("unchecked") public void actionPerformed(ActionEvent ae) { Dimension d = vv.getSize();//new Dimension(600,600); if (switchLayout.getText().indexOf("Spring") > 0) { switchLayout.setText("Switch to FRLayout"); //layout = new SpringLayout<State,Interval>(g, new ConstantTransformer(EDGE_LENGTH)); layout = new SpringLayout<String[], Interval>(g); layout.setSize(d); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } StaticLayout<String[], Interval> staticLayout = new StaticLayout<String[], Interval>(g, layout); LayoutTransition<String[], Interval> lt = new LayoutTransition<String[], Interval>(vv, vv.getGraphLayout(), staticLayout); Animator animator = new Animator(lt); animator.start(); // vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } else { switchLayout.setText("Switch to SpringLayout"); layout = new FRLayout<String[], Interval>(g, d); layout.setSize(d); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } StaticLayout<String[], Interval> staticLayout = new StaticLayout<String[], Interval>(g, layout); LayoutTransition<String[], Interval> lt = new LayoutTransition<String[], Interval>(vv, vv.getGraphLayout(), staticLayout); Animator animator = new Animator(lt); animator.start(); // vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } } }); getContentPane().add(switchLayout, BorderLayout.SOUTH); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); this.setVisible(true); }
From source file:org.spiderplan.tools.visulization.GraphFrame.java
/** * @param graph// ww w .j a va 2 s . c o m * @param history optional history of the graph * @param title * @param lC the layout * @param edgeLabels map from edges to string labels * @param w width of the window * @param h height of the window */ @SuppressWarnings({ "rawtypes", "unchecked" }) public GraphFrame(AbstractTypedGraph<V, E> graph, Vector<AbstractTypedGraph<V, E>> history, String title, LayoutClass lC, Map<E, String> edgeLabels, int w, int h) { super(title); this.edgeLabels = edgeLabels; this.g = new ObservableGraph<V, E>(graph); this.g.addGraphEventListener(this); this.defaultEdgeType = this.g.getDefaultEdgeType(); this.layoutClass = lC; this.history = history; this.setLayout(lC); layout.setSize(new Dimension(w, h)); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } // Layout<V,E> staticLayout = new StaticLayout<V,E>(g, layout); // Layout<V,E> staticLayout = new SpringLayout<V, E>(g); vv = new VisualizationViewer<V, E>(layout, new Dimension(w, h)); JRootPane rp = this.getRootPane(); rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); getContentPane().setLayout(new BorderLayout()); getContentPane().setBackground(java.awt.Color.lightGray); getContentPane().setFont(new Font("Serif", Font.PLAIN, 10)); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.S); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<V>()); vv.setForeground(Color.black); graphMouse = new EditingModalGraphMouse<V, E>(vv.getRenderContext(), null, null); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); // vv.getRenderContext().setEd vv.getRenderContext().setEdgeLabelTransformer(this); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<E>(vv.getPickedEdgeState(), Color.black, Color.cyan)); vv.addComponentListener(new ComponentAdapter() { /** * @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent) */ @Override public void componentResized(ComponentEvent arg0) { super.componentResized(arg0); layout.setSize(arg0.getComponent().getSize()); } }); getContentPane().add(vv); /** * Create simple container for stuff on SOUTH border of this JFrame */ Container c = new Container(); c.setLayout(new FlowLayout()); c.setBackground(java.awt.Color.lightGray); c.setFont(new Font("Serif", Font.PLAIN, 10)); /** * Button to dump jpeg */ dumpJPEG = new JButton("Dump"); dumpJPEG.addActionListener(this); dumpJPEG.setName("Dump"); c.add(dumpJPEG); /** * Button that creates offspring frame for selected vertices */ subGraphButton = new JButton("Subgraph"); subGraphButton.addActionListener(this); subGraphButton.setName("Subgraph"); c.add(subGraphButton); subGraphDepthLabel = new JLabel("Depth"); c.add(subGraphDepthLabel); subGraphDepth = new JTextField("0", 2); subGraphDepth.setHorizontalAlignment(SwingConstants.CENTER); subGraphDepth.setToolTipText("Depth of sub-graph created from selected nodes."); c.add(subGraphDepth); /** * Button that switches mouse mode */ switchMode = new JButton("Transformation"); switchMode.addActionListener(this); switchMode.setName("SwitchMode"); c.add(switchMode); /** * ComboBox for Layout selection: */ JComboBox layoutList; if (graph instanceof Forest) { String[] layoutStrings = { "Static", "Circle", "DAG", "Spring", "Spring2", "FR", "FR2", "Baloon", "ISOM", "KK", "PolarPoint", "RadialTree", "Tree" }; layoutList = new JComboBox(layoutStrings); } else { String[] layoutStrings = { "Static", "Circle", "DAG", "Spring", "Spring2", "FR", "FR2", "ISOM", "KK", "PolarPoint" }; layoutList = new JComboBox(layoutStrings); } layoutList.setSelectedIndex(5); layoutList.addActionListener(this); layoutList.setName("SelectLayout"); c.add(layoutList); /** * Add container to layout */ c.setVisible(true); getContentPane().add(c, BorderLayout.SOUTH); /** * Setup history scroll bar */ if (history != null) { historySlider = new JSlider(0, history.size() - 1, history.size() - 1); historySlider.addChangeListener(this); historySlider.setMajorTickSpacing(10); historySlider.setMinorTickSpacing(1); historySlider.setPaintTicks(true); historySlider.setPaintLabels(true); historySlider.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); Font font = new Font("Serif", Font.ITALIC, 15); historySlider.setFont(font); getContentPane().add(historySlider, BorderLayout.NORTH); } this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.pack(); this.setVisible(true); }
From source file:UNUSED.JUNGsamples.AddNodeDemo.java
@Override public void init() { //create a graph Graph<Number, Number> ig = Graphs .<Number, Number>synchronizedDirectedGraph(new DirectedSparseMultigraph<Number, Number>()); ObservableGraph<Number, Number> og = new ObservableGraph<Number, Number>(ig); og.addGraphEventListener(new GraphEventListener<Number, Number>() { public void handleGraphEvent(GraphEvent<Number, Number> evt) { System.err.println("got " + evt); }//from www . j av a 2s.c o m }); this.g = og; //create a graphdraw layout = new FRLayout2<Number, Number>(g); // ((FRLayout)layout).setMaxIterations(200); vv = new VisualizationViewer<Number, Number>(layout, new Dimension(600, 600)); JRootPane rp = this.getRootPane(); rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); getContentPane().setLayout(new BorderLayout()); getContentPane().setBackground(java.awt.Color.lightGray); getContentPane().setFont(new Font("Serif", Font.PLAIN, 12)); vv.getModel().getRelaxer().setSleepTime(500); vv.setGraphMouse(new DefaultModalGraphMouse<Number, Number>()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Number>()); vv.setForeground(Color.white); getContentPane().add(vv); switchLayout = new JButton("Switch to SpringLayout"); switchLayout.addActionListener(new ActionListener() { @SuppressWarnings("unchecked") public void actionPerformed(ActionEvent ae) { Dimension d = new Dimension(600, 600); if (switchLayout.getText().indexOf("Spring") > 0) { switchLayout.setText("Switch to FRLayout"); layout = new SpringLayout<Number, Number>(g, new ConstantTransformer(EDGE_LENGTH)); layout.setSize(d); vv.getModel().setGraphLayout(layout, d); } else { switchLayout.setText("Switch to SpringLayout"); layout = new FRLayout<Number, Number>(g, d); vv.getModel().setGraphLayout(layout, d); } } }); getContentPane().add(switchLayout, BorderLayout.SOUTH); timer = new Timer(); }