List of usage examples for javax.swing Box repaint
public void repaint()
From source file:geovista.network.gui.NodeLinkView.java
protected void addControls(final JPanel jp) { // Satellite/* w w w . j a v a2s. c o m*/ // JComboBox modeBox = graphMouse.getModeComboBox(); // modeBox.addItemListener(((DefaultModalGraphMouse)satellite.getGraphMouse()).getModeListener()); // Control Panel jp.setBackground(Color.WHITE); jp.setLayout(new BorderLayout()); jp.add(vv, BorderLayout.CENTER); JPanel control_panel = new JPanel(new GridLayout(5, 1)); jp.add(control_panel, BorderLayout.EAST); // File_Layout Panel Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); jcb.setRenderer(new DefaultListCellRenderer() { @Override 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); final Box file_layout_panel = Box.createVerticalBox(); file_layout_panel.setBorder(BorderFactory.createTitledBorder("File_Layout")); final JComboBox graph_chooser = new JComboBox(g_names); graph_chooser.addActionListener(new GraphChooser(jcb)); JPanel layoutPanel = new JPanel(); jcb.setAlignmentX(Component.CENTER_ALIGNMENT); layoutPanel.add(jcb); graph_chooser.setAlignmentX(Component.CENTER_ALIGNMENT); layoutPanel.add(graph_chooser); file_layout_panel.add(layoutPanel); // Basic Operation Panel 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 reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Layout<Integer, Number> layout = vv.getGraphLayout(); layout.initialize(); Relaxer relaxer = vv.getModel().getRelaxer(); if (relaxer != null) { relaxer.stop(); relaxer.prerelax(); relaxer.relax(); } } }); // Tranform and picking part final DefaultModalGraphMouse<Integer, Number> graphMouse = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(((DefaultModalGraphMouse<Integer, Number>) vv.getGraphMouse()).getModeListener()); JButton collapse = new JButton("Collapse"); JButton expand = new JButton("Expand"); final Box basic_panel = Box.createVerticalBox(); basic_panel.setBorder(BorderFactory.createTitledBorder("Basic_Operation")); JPanel zoomPanel = new JPanel(); // plus.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(plus); // minus.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(minus); // modeBox.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(modeBox); // reset.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(reset); // collapse.setAlignmentY(Component.CENTER_ALIGNMENT); zoomPanel.add(collapse); // expand.setAlignmentY(Component.CENTER_ALIGNMENT); zoomPanel.add(expand); basic_panel.add(zoomPanel); // Vertex Part String[] vertexScoreType = { "VertexScore", "Degree", "BarycenterScorer", "BetweennessCentrality", "ClosenessCentrality", "DistanceCentralityScorer", "EigenvectorCentrality" }; final JComboBox vertexScoreList = new JComboBox(vertexScoreType); vertexScoreList.setSelectedIndex(0); vertexScoreList.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { // Renderer.VertexLabel.Position position = // (Renderer.VertexLabel.Position)e.getItem(); // vv.getRenderer().getVertexLabelRenderer().setPosition(position); if (vertexScoreList.getSelectedIndex() == 0) { // vertexScores = new VertexScoreTransformer<Integer, // Double>(voltage_scores); // vv.getRenderContext().setVertexShapeTransformer(new // ConstantTransformer(null)); // vssa.setScaling(false); vv.getRenderContext().setVertexLabelTransformer(nonvertexLabel); vv.repaint(); } if (vertexScoreList.getSelectedIndex() == 1) { // vertexScores = new VertexScoreTransformer<Integer, // Double>(degreeScorer); /* * vssa = new * VertexShapeSizeAspect<Integer,Number>((Graph<Integer * ,Number>)g, transformerDegree); * vv.getRenderContext().setVertexShapeTransformer(vssa); * vssa.setScaling(true); */ vv.getRenderContext().setVertexLabelTransformer(vertexLabelDegree); vv.repaint(); } if (vertexScoreList.getSelectedIndex() == 2) { vssa = new VertexShapeSizeAspect<Integer, Number>((Graph<Integer, Number>) g, transformerBarycenter); vv.getRenderContext().setVertexShapeTransformer(vssa); vssa.setScaling(true); vv.getRenderContext().setVertexLabelTransformer(vertexLabelBarycenter); vv.repaint(); } if (vertexScoreList.getSelectedIndex() == 3) { // betweennessCentrality= new BetweennessCentrality(g); // voltages = new VertexScoreTransformer<Integer, // Double>(betweennessCentrality); vssa = new VertexShapeSizeAspect<Integer, Number>((Graph<Integer, Number>) g, transformerBetweenness); vv.getRenderContext().setVertexShapeTransformer(vssa); vssa.setScaling(true); vv.getRenderContext().setVertexLabelTransformer(vertexLabelBetweenness); vv.repaint(); } if (vertexScoreList.getSelectedIndex() == 4) { vssa = new VertexShapeSizeAspect<Integer, Number>((Graph<Integer, Number>) g, transformerCloseness); vv.getRenderContext().setVertexShapeTransformer(vssa); vssa.setScaling(true); vv.getRenderContext().setVertexLabelTransformer(vertexLabelCloseness); vv.repaint(); } if (vertexScoreList.getSelectedIndex() == 5) { vssa = new VertexShapeSizeAspect<Integer, Number>((Graph<Integer, Number>) g, transformerDistanceCentrality); vv.getRenderContext().setVertexShapeTransformer(vssa); vssa.setScaling(true); vv.getRenderContext().setVertexLabelTransformer(vertexLabelDistanceCentrality); vv.repaint(); } if (vertexScoreList.getSelectedIndex() == 6) { vssa = new VertexShapeSizeAspect<Integer, Number>((Graph<Integer, Number>) g, transformerEigenvector); vv.getRenderContext().setVertexShapeTransformer(vssa); vssa.setScaling(true); vv.getRenderContext().setVertexLabelTransformer(vertexLabelEigenvector); vv.repaint(); } } }); // cb.setSelectedItem(Renderer.VertexLabel.Position.SE); /* * v_shape = new JCheckBox("shape by degree"); * v_shape.addActionListener(this); v_size = new * JCheckBox("size by vertexScores"); v_size.addActionListener(this); * v_size.setSelected(true); v_aspect = new * JCheckBox("stretch by degree ratio"); * v_aspect.addActionListener(this); */ v_small = new JCheckBox("filter when degree < " + VertexDisplayPredicate.MIN_DEGREE); v_small.addActionListener(this); e_labels = new JCheckBox("show edge labels"); e_labels.addActionListener(this); // Vertex Panel final Box vertex_panel = Box.createVerticalBox(); vertex_panel.setBorder(BorderFactory.createTitledBorder("Vertices")); // vertex_panel.add(v_stroke); vertex_panel.add(vertexScoreList); // vertex_panel.add(v_degree_labels); /* * vertex_panel.add(v_shape); vertex_panel.add(v_size); * vertex_panel.add(v_aspect); */ vertex_panel.add(v_small); // Edge Part final Box edge_panel = Box.createVerticalBox(); edge_panel.setBorder(BorderFactory.createTitledBorder("Edges")); edge_panel.add(e_labels); 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(g.getEdgeCount()); edgeBetweennessSlider.setMinimum(0); edgeBetweennessSlider.setValue(0); edgeBetweennessSlider.setMajorTickSpacing(10); edgeBetweennessSlider.setPaintLabels(true); edgeBetweennessSlider.setPaintTicks(true); // Cluster Part final Box cluster_panel = Box.createVerticalBox(); cluster_panel.setBorder(BorderFactory.createTitledBorder("Cluster")); cluster_panel.add(edgeBetweennessSlider); final String COMMANDSTRING = "Edges removed for clusters: "; final String eastSize = COMMANDSTRING + edgeBetweennessSlider.getValue(); final TitledBorder sliderBorder = BorderFactory.createTitledBorder(eastSize); cluster_panel.setBorder(sliderBorder); cluster_panel.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()); cluster_panel.repaint(); vv.validate(); vv.repaint(); } } }); cluster_panel.add(groupVertices); control_panel.add(file_layout_panel); control_panel.add(vertex_panel); control_panel.add(edge_panel); control_panel.add(cluster_panel); control_panel.add(basic_panel); }