Example usage for javax.swing JSlider setMajorTickSpacing

List of usage examples for javax.swing JSlider setMajorTickSpacing

Introduction

In this page you can find the example usage for javax.swing JSlider setMajorTickSpacing.

Prototype

@BeanProperty(visualUpdate = true, description = "Sets the number of values between major tick marks.")
public void setMajorTickSpacing(int n) 

Source Link

Document

This method sets the major tick spacing.

Usage

From source file:external.jung.demo.RoadEditorDemo.java

/**
 * create an instance of a simple graph with popup controls to create a
 * graph.//w  w  w .jav  a  2s  .c  o  m
 *
 */
public RoadEditorDemo() {
    roadGraphHelper = new RoadGraphHelper();
    this.graph = roadGraphHelper.createRoadGraph();
    this.layout = new StaticLayout<Vertex3DInfo, Edge3DInfo>(graph, new Dimension(600, 600));
    this.roadGraphHelper.setLayout(layout);

    vv = new VisualizationViewer<Vertex3DInfo, Edge3DInfo>(layout);
    vv.setBackground(Color.white);

    vv.getRenderContext().setVertexLabelTransformer(
            MapTransformer.<Vertex3DInfo, String>getInstance(LazyMap.<Vertex3DInfo, String>decorate(
                    new HashMap<Vertex3DInfo, String>(), new ToStringLabeller<Vertex3DInfo>())));
    vv.getRenderContext().setEdgeLabelTransformer(
            MapTransformer.<Edge3DInfo, String>getInstance(LazyMap.<Edge3DInfo, String>decorate(
                    new HashMap<Edge3DInfo, String>(), new ToStringLabeller<Edge3DInfo>())));
    vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer());
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<Vertex3DInfo, Edge3DInfo>());

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);

    final EditingModalGraphMouse<Vertex3DInfo, Edge3DInfo> graphMouse = new EditingModalGraphMouse<Vertex3DInfo, Edge3DInfo>(
            vv.getRenderContext(), roadGraphHelper.vertexFactory, roadGraphHelper.edgeFactory);

    // the EditingGraphMouse will pass mouse event coordinates to the
    // vertexLocations function to set the locations of the vertices as
    // they are created
    //        graphMouse.setVertexLocations(vertexLocations);
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    graphMouse.setMode(ModalGraphMouse.Mode.EDITING);

    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 help = new JButton("Build");
    help.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //edgeAngle();
            roadGraphHelper.resetExtraDraw();
            roadGraphHelper.vertexIntersect();
            vv.repaint();

        }
    });

    AnnotationControls<Vertex3DInfo, Edge3DInfo> annotationControls = new AnnotationControls<Vertex3DInfo, Edge3DInfo>(
            graphMouse.getAnnotatingPlugin());
    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    JComboBox modeBox = graphMouse.getModeComboBox();
    controls.add(modeBox);
    controls.add(annotationControls.getAnnotationsToolBar());
    controls.add(help);

    JSlider slider2 = new JSlider();
    slider2.setBorder(BorderFactory.createTitledBorder("Size"));
    slider2.setMajorTickSpacing(20);
    slider2.setMinorTickSpacing(5);
    slider2.setPaintTicks(true);
    controls.add(slider2);
    slider2.addChangeListener(new SliderListener());

    JPanel checkBoxes = new JPanel();
    //checkBoxes.setLayout(new GridLayout(1, 5));
    layer1Check = new JCheckBox("Layer1");
    layer1Check.setSelected(true);

    layer2Check = new JCheckBox("Layer2");
    layer2Check.setSelected(true);

    layer3Check = new JCheckBox("Layer3");
    layer3Check.setSelected(true);

    layer4Check = new JCheckBox("Layer4");
    layer4Check.setSelected(true);
    layer5Check = new JCheckBox("Layer5");
    layer5Check.setSelected(true);
    checkBoxes.add(layer1Check);
    checkBoxes.add(layer2Check);
    checkBoxes.add(layer3Check);
    checkBoxes.add(layer4Check);
    checkBoxes.add(layer5Check);
    JPanel twoLine = new JPanel();
    twoLine.setLayout(new GridLayout(2, 1));
    content.add(twoLine, BorderLayout.SOUTH);
    twoLine.add(controls);
    twoLine.add(checkBoxes);
    // 
    vv.addPostRenderPaintable(new PaintRoad());
    vv.addPreRenderPaintable(new PaintRoadUnder());
    vv.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            //edgeAngle();
            roadGraphHelper.resetExtraDraw();
            roadGraphHelper.vertexIntersect();
            vv.repaint();

        }
    });

}

From source file:fr.free.hd.servers.gui.FaceView.java

private JPanel createMouth() {
    JPanel panel = new JPanel(new GridLayout(3, 0));
    final JSlider slider = new JSlider();
    final JSlider sliderX = new JSlider();
    final JSlider sliderY = new JSlider();
    slider.setMinimum(0);//from   w  w  w.  j av  a 2s  .co  m
    slider.setMaximum(1000);
    slider.setMajorTickSpacing(100);
    slider.setPaintLabels(true);
    slider.setPaintTicks(true);
    slider.setPaintTrack(true);
    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);

    sliderX.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            face.setMouthXPercent(sliderX.getValue());
            updateLabel();
        }
    });
    sliderY.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            face.setMouthYPercent(sliderY.getValue());
            updateLabel();
        }
    });
    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            face.setMouthRatio(slider.getValue());
            updateLabel();
        }
    });

    panel.add(slider);
    panel.add(sliderX);
    panel.add(sliderY);

    return panel;
}

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()/*w w  w  .  java  2  s.co m*/
            .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:AtomPanel.java

private void commonInit() {
    //initial time series plots
    initJFreeChart();//  w w w.  j a  va2  s  .  com
    startFlag = false;

    //create control panel
    //        JPanel panel=new JPanel(new GridLayout(1,2));
    //add control buttons to control panel
    /*
    startButton=new JButton("Start");
    startButton.addActionListener(this);
    pauseButton=new JButton("Pause");
    pauseButton.addActionListener(this);
    stopButton=new JButton("Stop");
    stopButton.addActionListener(this);
    panel.add(startButton);
    panel.add(pauseButton);
    panel.add(stopButton);
    */
    JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    //Create the slider
    JSlider faRateSlider = new JSlider(JSlider.HORIZONTAL, L_MIN, L_MAX, L_INIT);
    faRateSlider.setName("faRate");
    faRateSlider.addChangeListener(this);
    faRateSlider.setMajorTickSpacing(30);
    faRateSlider.setPaintTicks(true);

    //Create the label table
    Hashtable labelTable = new Hashtable();
    labelTable.put(new Integer(L_MIN), new JLabel("0.1%"));
    labelTable.put(new Integer((L_MIN + L_MAX) / 2), new JLabel("   False Alarm Rate"));
    labelTable.put(new Integer(L_MAX), new JLabel("1%"));
    faRateSlider.setLabelTable(labelTable);

    faRateSlider.setPaintLabels(true);
    panel.add(faRateSlider);
    // window size slider
    JSlider wdSzSlider = new JSlider(JSlider.HORIZONTAL, L_MIN, L_MAX, WDL_INIT);
    wdSzSlider.setName("wdSz");
    wdSzSlider.addChangeListener(this);
    wdSzSlider.setMajorTickSpacing(30);
    wdSzSlider.setPaintTicks(true);

    //Create the label table
    Hashtable wdTable = new Hashtable();
    wdTable.put(new Integer(L_MIN), new JLabel("20"));
    wdTable.put(new Integer((L_MIN + L_MAX) / 2), new JLabel("   Window Size"));
    wdTable.put(new Integer(L_MAX), new JLabel("200"));
    wdSzSlider.setLabelTable(wdTable);

    wdSzSlider.setPaintLabels(true);
    panel.add(wdSzSlider);
    if (AtomUtils.PCAType.pcaTrack == this.pcaType) { // new: tracking delta bar
        JSlider deltaSlider = new JSlider(JSlider.HORIZONTAL, L_MIN, L_MAX, L_INIT);
        deltaSlider.setName("delta");
        deltaSlider.addChangeListener(this);
        deltaSlider.setMajorTickSpacing(30);
        deltaSlider.setPaintTicks(true);

        //Create the label table
        labelTable = new Hashtable();
        labelTable.put(new Integer(L_MIN), new JLabel("0%"));
        labelTable.put(new Integer((L_MIN + L_MAX) / 2), new JLabel("   Tracking Threshold"));
        labelTable.put(new Integer(L_MAX), new JLabel("20%"));
        deltaSlider.setLabelTable(labelTable);

        deltaSlider.setPaintLabels(true);
        panel.add(deltaSlider);

        // tracking saving label
        trackSaveLabel = new JLabel();
        trackSaveLabel.setText("Saved/Total:0/0");
        panel.add(trackSaveLabel);
    }
    if (AtomUtils.PCAType.pcaTrackAdjust == this.pcaType) {
        JSlider devSlider = new JSlider(JSlider.HORIZONTAL, L_MIN, L_MAX, L_INIT);
        devSlider.setName("devbnd");
        devSlider.addChangeListener(this);
        devSlider.setMajorTickSpacing(30);
        devSlider.setPaintTicks(true);

        //Create the label table
        labelTable = new Hashtable();
        labelTable.put(new Integer(L_MIN), new JLabel("0%"));
        labelTable.put(new Integer((L_MIN + L_MAX) / 2), new JLabel("   Deviation Bound"));
        labelTable.put(new Integer(L_MAX), new JLabel("1%"));
        devSlider.setLabelTable(labelTable);

        devSlider.setPaintLabels(true);
        panel.add(devSlider);

        // tracking saving label
        trackSaveLabel = new JLabel();
        trackSaveLabel.setText("Saved/Total:0/0");
        panel.add(trackSaveLabel);
    }
    add(panel, BorderLayout.SOUTH);

}

From source file:cimat.tesis.sna.visualization.ClusteringDemo.java

private void setUpView(BufferedReader br) throws IOException {

    Factory<Number> vertexFactory = new Factory<Number>() {
        int n = 0;

        public Number create() {
            return n++;
        }/* w w  w . j  a v a  2  s  . c  om*/
    };
    Factory<Number> edgeFactory = new Factory<Number>() {
        int n = 0;

        public Number create() {
            return n++;
        }
    };

    PajekNetReader<Graph<Number, Number>, Number, Number> pnr = new PajekNetReader<Graph<Number, Number>, Number, Number>(
            vertexFactory, edgeFactory);

    final Graph<Number, Number> graph = new SparseMultigraph<Number, Number>();

    pnr.load(br, graph);

    //Create a simple layout frame
    //specify the Fruchterman-Rheingold layout algorithm
    final AggregateLayout<Number, Number> layout = new AggregateLayout<Number, Number>(
            new FRLayout<Number, Number>(graph));

    vv = new VisualizationViewer<Number, Number>(layout);
    vv.setBackground(Color.white);
    //Tell the renderer to use our own customized color rendering
    vv.getRenderContext()
            .setVertexFillPaintTransformer(MapTransformer.<Number, Paint>getInstance(vertexPaints));
    vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<Number, Paint>() {
        public Paint transform(Number 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:geovista.network.gui.ClusteringDemo.java

private void setUpView() throws IOException {

    /*//from  w w w  .j  a va  2  s .com
     * Factory<Integer> vertexFactory = new Factory<Integer>() { int n = 0;
     * public Integer create() { return n++; } }; Factory<Number>
     * edgeFactory = new Factory<Number>() { int n = 0; public Number
     * create() { return n++; } };
     */

    /*
     * PajekNetReader<Graph<Integer, Number>, Integer,Number> pnr = new
     * PajekNetReader<Graph<Integer, Number>, Integer,Number>(vertexFactory,
     * edgeFactory);
     * 
     * final Graph<Integer,Number> graph = new SparseMultigraph<Integer,
     * Number>();
     * 
     * pnr.load(br, graph);
     */

    // Create a simple layout frame
    // specify the Fruchterman-Rheingold layout algorithm
    layout = new AggregateLayout<Integer, Number>(new FRLayout<Integer, Number>(g));

    vv = new VisualizationViewer<Integer, Number>(layout);
    vv.setBackground(Color.white);
    // Tell the renderer to use our own customized color rendering
    vv.getRenderContext()
            .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.blue;
            } 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(g.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 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);
    /*
     * 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();
            }
        }
    });

    cluster_panel.add(groupVertices);
    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(cluster_panel);
    // south.add
    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:fr.free.hd.servers.gui.FaceView.java

private JPanel createKind() {
    JPanel panel = new JPanel(new GridLayout(3, 0));
    final JSlider sliderX = new JSlider();
    final JSlider sliderY = new JSlider();
    final JComboBox box = new JComboBox(HandKeyEnum.values());
    sliderX.setMinimum(-1000);/*from   w w w. j  ava2 s .c om*/
    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);

    box.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            kind = (HandKeyEnum) e.getItem();
            updateLabel();
        }
    });
    panel.add(box);

    sliderX.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            switch (kind) {
            case HAND_KEY_2D:
                face.setAnchorX_2D(sliderX.getValue());
                break;
            case HAND_KEY_2M:
                face.setAnchorX_2M(sliderX.getValue());
                break;
            case HAND_KEY_1M:
                face.setAnchorX_1M(sliderX.getValue());
                break;
            case HAND_KEY_2V:
                face.setAnchorX_2V(sliderX.getValue());
                break;
            case HAND_KEY_3D:
                face.setAnchorX_3D(sliderX.getValue());
                break;
            case HAND_KEY_3G:
                face.setAnchorX_3G(sliderX.getValue());
                break;
            case HAND_KEY_4G:
                face.setAnchorX_4G(sliderX.getValue());
                break;
            case HAND_KEY_5M:
                face.setAnchorX_5M(sliderX.getValue());
                break;
            }
            updateLabel();
        }
    });
    sliderY.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            switch (kind) {
            case HAND_KEY_2D:
                face.setAnchorY_2D(sliderY.getValue());
                break;
            case HAND_KEY_2M:
                face.setAnchorY_2M(sliderY.getValue());
                break;
            case HAND_KEY_1M:
                face.setAnchorY_1M(sliderY.getValue());
                break;
            case HAND_KEY_2V:
                face.setAnchorY_2V(sliderY.getValue());
                break;
            case HAND_KEY_3D:
                face.setAnchorY_3D(sliderY.getValue());
                break;
            case HAND_KEY_3G:
                face.setAnchorY_3G(sliderY.getValue());
                break;
            case HAND_KEY_4G:
                face.setAnchorY_4G(sliderY.getValue());
                break;
            case HAND_KEY_5M:
                face.setAnchorY_5M(sliderY.getValue());
                break;
            }
            updateLabel();
        }
    });
    panel.add(sliderX);
    panel.add(sliderY);
    return panel;
}

From source file:JXTransformer.java

private JPanel createDemoPanel() {
        JPanel buttonPanel = new JPanel(new GridLayout(3, 2));
        TitledBorder titledBorder = BorderFactory.createTitledBorder("Try three sliders below !");
        Font titleFont = titledBorder.getTitleFont();
        titledBorder.setTitleFont(titleFont.deriveFont(titleFont.getSize2D() + 10));
        titledBorder.setTitleJustification(TitledBorder.CENTER);
        buttonPanel.setBorder(titledBorder);
        JButton b = new JButton("JButton");
        b.setPreferredSize(new Dimension(100, 50));
        buttonPanel.add(createTransformer(b));

        Vector<String> v = new Vector<String>();
        v.add("One");
        v.add("Two");
        v.add("Three");
        JList list = new JList(v);
        buttonPanel.add(createTransformer(list));

        buttonPanel.add(createTransformer(new JCheckBox("JCheckBox")));

        JSlider slider = new JSlider(0, 100);
        slider.setLabelTable(slider.createStandardLabels(25, 0));
        slider.setPaintLabels(true);/*w ww.  ja  va  2s . c o m*/
        slider.setPaintTicks(true);
        slider.setMajorTickSpacing(10);
        buttonPanel.add(createTransformer(slider));

        buttonPanel.add(createTransformer(new JRadioButton("JRadioButton")));
        final JLabel label = new JLabel("JLabel");
        label.addMouseListener(new MouseAdapter() {
            public void mouseEntered(MouseEvent e) {
                Font font = label.getFont();
                label.setFont(font.deriveFont(font.getSize2D() + 10));
            }

            public void mouseExited(MouseEvent e) {
                Font font = label.getFont();
                label.setFont(font.deriveFont(font.getSize2D() - 10));
            }
        });
        buttonPanel.add(createTransformer(label));

        return buttonPanel;
    }

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 va  2s  . c om*/
    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:gui.WikiCorpusClusteringView.java

/**
 *
 * @param br//from  w  ww.  j  av  a2  s  .c  om
 * @throws IOException
 */
private void setUpView(Graph graph) throws IOException {

    //Create a simple layout frame
    //specify the Fruchterman-Rheingold layout algorithm
    //        final AggregateLayout<Number, Number> layout =
    //                new AggregateLayout<Number, Number>(new FRLayout<Number, Number>(graph));

    //layout = new TreeLayout<String,Integer>(graph);
    Layout<Number, Number> layout = new KKLayout<Number, Number>(graph);
    layout.setSize(new Dimension(900, 900));

    vv = new VisualizationViewer<Number, Number>(layout);
    vv.setBackground(Color.white);
    //Tell the renderer to use our own customized color rendering
    vv.getRenderContext()
            .setVertexFillPaintTransformer(MapTransformer.<Number, Paint>getInstance(vertexPaints));
    vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<Number, Paint>() {
        public Paint transform(Number 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);
}