List of usage examples for javax.swing JToggleButton JToggleButton
public JToggleButton(Action a)
From source file:L2RTreeLayoutDemo.java
public L2RTreeLayoutDemo() { // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree();//from w w w.java 2 s. c om treeLayout = new TreeLayout<String, Integer>(graph); radialLayout = new RadialTreeLayout<String, Integer>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<String, Integer>(treeLayout, 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(); setLtoR(vv); 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) { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, treeLayout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, radialLayout, treeLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); setLtoR(vv); vv.removePreRenderPaintable(rings); } 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); content.add(controls, BorderLayout.SOUTH); }
From source file:by.bsuir.main.Graph.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public Graph() {/*from w w w .j ava2 s . c o m*/ // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); if (Edge.devEdges.size() > 0) ctreateTreeForDevices(); else createTree(); treeLayout = new TreeLayout<String, Integer>(graph); radialLayout = new RadialTreeLayout<String, Integer>(graph); radialLayout.setSize(new Dimension(500, 400)); vv = new VisualizationViewer<String, Integer>(treeLayout, new Dimension(500, 400)); 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(); 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) { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, treeLayout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(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")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); content.add(controls, BorderLayout.SOUTH); }
From source file:edu.uci.ics.jung.samples.L2RTreeLayoutDemo.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public L2RTreeLayoutDemo() { // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree();//from w w w . j a v a 2s . c o m treeLayout = new TreeLayout<String, Integer>(graph); radialLayout = new RadialTreeLayout<String, Integer>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<String, Integer>(treeLayout, 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(); setLtoR(vv); 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) { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, treeLayout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, radialLayout, treeLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); setLtoR(vv); vv.removePreRenderPaintable(rings); } 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); content.add(controls, BorderLayout.SOUTH); }
From source file:demos.TreeCollapse.java
@SuppressWarnings("unchecked") public TreeCollapse() { // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree();/*from ww w . j a va 2 s. c o m*/ 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.TreeCollapseDemo.java
@SuppressWarnings("unchecked") public TreeCollapseDemo() { // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree();/* w w w . j av a 2 s . co m*/ 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(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:jung.test.TreeLayoutDemo.java
public TreeLayoutDemo() { // create a simple graph for the demo //graph = new DelegateForest<String,DefaultWeightedEdge>(); graph = new DelegateTree<String, DefaultWeightedEdge>(); createTree();/*from w w w . j av a 2 s . c om*/ treeLayout = new TreeLayout<String, DefaultWeightedEdge>(graph); radialLayout = new RadialTreeLayout<String, DefaultWeightedEdge>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<String, DefaultWeightedEdge>(treeLayout, 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(); 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) { LayoutTransition<String, DefaultWeightedEdge> lt = new LayoutTransition<String, DefaultWeightedEdge>( vv, treeLayout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<String, DefaultWeightedEdge> lt = new LayoutTransition<String, DefaultWeightedEdge>( 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")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); content.add(controls, BorderLayout.SOUTH); }
From source file:au.edu.uwa.csse.plot.Clustering.java
private void setUpView(Graph graph) throws IOException { //Create a simple layout frame //specify the Fruchterman-Rheingold layout algorithm final AggregateLayout<Integer, Number> layout = new AggregateLayout<Integer, Number>( new FRLayout<Integer, Number>(graph)); vv = new VisualizationViewer<Integer, Number>(layout); vv.setBackground(Color.white); vv.setVertexToolTipTransformer(Plot.vertexLabelTransformer); //Tell the renderer to use our own customized color rendering vv.getRenderContext()// ww w .j a v a 2 s. c om .setVertexFillPaintTransformer(MapTransformer.<Integer, Paint>getInstance(vertexPaints)); vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<Integer, Paint>() { public Paint transform(Integer v) { if (vv.getPickedVertexState().isPicked(v)) { return Color.cyan; } else { return Color.BLACK; } } }); vv.getRenderContext().setEdgeDrawPaintTransformer(MapTransformer.<Number, Paint>getInstance(edgePaints)); vv.getRenderContext().setEdgeStrokeTransformer(new Transformer<Number, Stroke>() { protected final Stroke THIN = new BasicStroke(1); protected final Stroke THICK = new BasicStroke(2); public Stroke transform(Number e) { Paint c = edgePaints.get(e); if (c == Color.LIGHT_GRAY) return THIN; else return THICK; } }); //add restart button JButton scramble = new JButton("Restart"); scramble.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Layout layout = vv.getGraphLayout(); layout.initialize(); Relaxer relaxer = vv.getModel().getRelaxer(); if (relaxer != null) { relaxer.stop(); relaxer.prerelax(); relaxer.relax(); } } }); DefaultModalGraphMouse gm = new DefaultModalGraphMouse(); vv.setGraphMouse(gm); final JToggleButton groupVertices = new JToggleButton("Group Clusters"); //Create slider to adjust the number of edges to remove when clustering final JSlider edgeBetweennessSlider = new JSlider(JSlider.HORIZONTAL); edgeBetweennessSlider.setBackground(Color.WHITE); edgeBetweennessSlider.setPreferredSize(new Dimension(210, 50)); edgeBetweennessSlider.setPaintTicks(true); edgeBetweennessSlider.setMaximum(graph.getEdgeCount()); edgeBetweennessSlider.setMinimum(0); edgeBetweennessSlider.setValue(0); edgeBetweennessSlider.setMajorTickSpacing(10); edgeBetweennessSlider.setPaintLabels(true); edgeBetweennessSlider.setPaintTicks(true); // edgeBetweennessSlider.setBorder(BorderFactory.createLineBorder(Color.black)); //TO DO: edgeBetweennessSlider.add(new JLabel("Node Size (PageRank With Priors):")); //I also want the slider value to appear final JPanel eastControls = new JPanel(); eastControls.setOpaque(true); eastControls.setLayout(new BoxLayout(eastControls, BoxLayout.Y_AXIS)); eastControls.add(Box.createVerticalGlue()); eastControls.add(edgeBetweennessSlider); final String COMMANDSTRING = "Edges removed for clusters: "; final String eastSize = COMMANDSTRING + edgeBetweennessSlider.getValue(); final TitledBorder sliderBorder = BorderFactory.createTitledBorder(eastSize); eastControls.setBorder(sliderBorder); //eastControls.add(eastSize); eastControls.add(Box.createVerticalGlue()); groupVertices.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { clusterAndRecolor(layout, edgeBetweennessSlider.getValue(), similarColors, e.getStateChange() == ItemEvent.SELECTED); vv.repaint(); } }); clusterAndRecolor(layout, 0, similarColors, groupVertices.isSelected()); edgeBetweennessSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (!source.getValueIsAdjusting()) { int numEdgesToRemove = source.getValue(); clusterAndRecolor(layout, numEdgesToRemove, similarColors, groupVertices.isSelected()); sliderBorder.setTitle(COMMANDSTRING + edgeBetweennessSlider.getValue()); eastControls.repaint(); vv.validate(); vv.repaint(); } } }); Container content = getContentPane(); content.add(new GraphZoomScrollPane(vv)); JPanel south = new JPanel(); JPanel grid = new JPanel(new GridLayout(2, 1)); grid.add(scramble); grid.add(groupVertices); south.add(grid); south.add(eastControls); JPanel p = new JPanel(); p.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); p.add(gm.getModeComboBox()); south.add(p); content.add(south, BorderLayout.SOUTH); }
From source file:com.rapidminer.gui.new_plotter.gui.GlobalConfigurationPanel.java
private void createComponents() { // create panel for global configuration {/* w w w. java 2 s. c om*/ // add title label JLabel titleLabel = new ResourceLabel("plotter.configuration_dialog.chart_title"); String title = getPlotConfiguration().getTitleText(); if (title == null) { title = ""; } titleTextField = new JTextField(title); titleLabel.setLabelFor(titleTextField); titleTextField.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { return; } @Override public void keyReleased(KeyEvent e) { String newTitle = titleTextField.getText(); String titleText = getCurrentPlotInstance().getMasterPlotConfiguration().getTitleText(); if (titleText != null) { if (!titleText.equals(newTitle) || titleText == null && newTitle.length() > 0) { if (newTitle.length() > 0) { getPlotConfiguration().setTitleText(newTitle); } else { getPlotConfiguration().setTitleText(null); } } } else { if (newTitle.length() > 0) { getPlotConfiguration().setTitleText(newTitle); } else { getPlotConfiguration().setTitleText(null); } } if (newTitle.equals("Iris") && SwingTools.isControlOrMetaDown(e) && e.getKeyCode() == KeyEvent.VK_D) { startAnimation(); } } @Override public void keyPressed(KeyEvent e) { return; } }); titleTextField.setPreferredSize(new Dimension(115, 23)); titleConfigButton = new JToggleButton(new PopupAction(true, "plotter.configuration_dialog.open_popup", chartTitleConfigurationContainer, PopupPosition.HORIZONTAL)); addThreeComponentRow(this, titleLabel, titleTextField, titleConfigButton); } // add orientation check box { JLabel plotOrientationLabel = new ResourceLabel( "plotter.configuration_dialog.global_config_panel.plot_orientation"); PlotOrientation[] orientations = { PlotOrientation.HORIZONTAL, PlotOrientation.VERTICAL }; plotOrientationComboBox = new JComboBox(orientations); plotOrientationLabel.setLabelFor(plotOrientationComboBox); plotOrientationComboBox.setRenderer(new EnumComboBoxCellRenderer("plotter")); plotOrientationComboBox.setSelectedIndex(0); plotOrientationComboBox.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { return; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { getPlotConfiguration() .setOrientation((PlotOrientation) plotOrientationComboBox.getSelectedItem()); } @Override public void popupMenuCanceled(PopupMenuEvent e) { return; } }); addTwoComponentRow(this, plotOrientationLabel, plotOrientationComboBox); } // add legend popup button { JLabel legendStyleConfigureLabel = new ResourceLabel( "plotter.configuration_dialog.global_config_panel.legend_style"); JToggleButton legendStyleConfigButton = new JToggleButton( new PopupAction(true, "plotter.configuration_dialog.open_popup", legendConfigContainer, PopupAction.PopupPosition.HORIZONTAL)); legendStyleConfigureLabel.setLabelFor(legendStyleConfigButton); addTwoComponentRow(this, legendStyleConfigureLabel, legendStyleConfigButton); } // add legend popup button { JLabel axisStyleConfigureLabel = new ResourceLabel( "plotter.configuration_dialog.global_config_panel.axis_style"); JToggleButton axisStyleConfigureButton = new JToggleButton( new PopupAction(true, "plotter.configuration_dialog.open_popup", axisConfigurationContainer, PopupAction.PopupPosition.HORIZONTAL)); axisStyleConfigureLabel.setLabelFor(axisStyleConfigureButton); addTwoComponentRow(this, axisStyleConfigureLabel, axisStyleConfigureButton); } // add color scheme dialog button { JLabel colorConfigureLabel = new ResourceLabel( "plotter.configuration_dialog.global_config_panel.color_scheme"); colorsSchemesComboBoxModel = new DefaultComboBoxModel(); colorSchemesComboBox = new JComboBox(colorsSchemesComboBoxModel); colorConfigureLabel.setLabelFor(colorSchemesComboBox); colorSchemesComboBox.setRenderer(new ColorSchemeComboBoxRenderer()); colorSchemesComboBox.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { return; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { ColorScheme colorScheme = (ColorScheme) colorSchemesComboBox.getSelectedItem(); if (colorScheme != null) { getPlotConfiguration().setActiveColorScheme(colorScheme.getName()); } } @Override public void popupMenuCanceled(PopupMenuEvent e) { return; } }); JButton colorConfigButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.open_color_scheme_dialog") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { createColorSchemeDialog(); } }); addThreeComponentRow(this, colorConfigureLabel, colorSchemesComboBox, colorConfigButton); } // add plot background color { plotBackGroundColorLabel = new ResourceLabel( "plotter.configuration_dialog.global_config_panel.select_plot_background_color"); plotBackgroundColorChooserButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.select_plot_color") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { createPlotBackgroundColorDialog(); } }); plotBackGroundColorLabel.setLabelFor(plotBackgroundColorChooserButton); addTwoComponentRow(this, plotBackGroundColorLabel, plotBackgroundColorChooserButton); } // add chart background color { frameBackGroundColorLabel = new ResourceLabel( "plotter.configuration_dialog.global_config_panel.select_frame_background_color"); frameBackgroundColorChooserButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.select_frame_color") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { createFrameBackgroundColorDialog(); } }); frameBackGroundColorLabel.setLabelFor(frameBackgroundColorChooserButton); addTwoComponentRow(this, frameBackGroundColorLabel, frameBackgroundColorChooserButton); // GridBagConstraints itemConstraint = new GridBagConstraints(); // itemConstraint.gridwidth = GridBagConstraints.REMAINDER; // itemConstraint.weightx = 1.0; // this.add(frameBackgroundColorChooserButton, itemConstraint); } // add spacer panel { JPanel spacerPanel = new JPanel(); GridBagConstraints itemConstraint = new GridBagConstraints(); itemConstraint.fill = GridBagConstraints.BOTH; itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.gridwidth = GridBagConstraints.REMAINDER; this.add(spacerPanel, itemConstraint); } }
From source file:SoundManagerTest.java
/** * Creates a button (either JButton or JToggleButton). *///from w w w.j av a 2s.com public AbstractButton createButton(String name, boolean canToggle) { AbstractButton button; if (canToggle) { button = new JToggleButton(name); } else { button = new JButton(name); } button.addActionListener(this); button.setIgnoreRepaint(true); button.setFocusable(false); return button; }
From source file:com.google.code.facebook.graph.sna.applet.BalloonLayoutDemo.java
public BalloonLayoutDemo() { // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree();//from ww w . ja v a 2s . com 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); }