List of usage examples for javax.swing JSlider setValue
@BeanProperty(bound = false, preferred = true, description = "The sliders current value.") public void setValue(int n)
From source file:SoundPlayer.java
void addMidiControls() { // Add a slider to control the tempo final JSlider tempo = new JSlider(50, 200); tempo.setValue((int) (sequencer.getTempoFactor() * 100)); tempo.setBorder(new TitledBorder("Tempo Adjustment (%)")); java.util.Hashtable labels = new java.util.Hashtable(); labels.put(new Integer(50), new JLabel("50%")); labels.put(new Integer(100), new JLabel("100%")); labels.put(new Integer(200), new JLabel("200%")); tempo.setLabelTable(labels);/*from www . j a va 2 s. c o m*/ tempo.setPaintLabels(true); // The event listener actually changes the tmpo tempo.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { sequencer.setTempoFactor(tempo.getValue() / 100.0f); } }); this.add(tempo); // Create rows of solo and checkboxes for each track Track[] tracks = sequence.getTracks(); for (int i = 0; i < tracks.length; i++) { final int tracknum = i; // Two checkboxes per track final JCheckBox solo = new JCheckBox("solo"); final JCheckBox mute = new JCheckBox("mute"); // The listeners solo or mute the track solo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sequencer.setTrackSolo(tracknum, solo.isSelected()); } }); mute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sequencer.setTrackMute(tracknum, mute.isSelected()); } }); // Build up a row Box box = Box.createHorizontalBox(); box.add(new JLabel("Track " + tracknum)); box.add(Box.createHorizontalStrut(10)); box.add(solo); box.add(Box.createHorizontalStrut(10)); box.add(mute); box.add(Box.createHorizontalGlue()); // And add it to this component this.add(box); } }
From source file:projects.hip.exec.HrDiagram.java
/** * Main constructor.//from www . jav a2 s .c om */ public HrDiagram() { hipStars = HipUtils.loadHipCatalogue(); method = METHOD.NAIVE; fMax = 1.0; final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values()); methodComboBox.setSelectedItem(method); methodComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { method = (METHOD) methodComboBox.getSelectedItem(); updateChart(); } }); final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f"); fSlider.setValue((int) Math.rint(100.0 * fMax / 2.0)); final JLabel fLabel = new JLabel(getFLabel()); // Create a change listener fot these ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (source == fSlider) { // Compute fractional parallax error from slider position double newF = (2.0 * source.getValue() / 100.0); fMax = newF; fLabel.setText(getFLabel()); } updateChart(); } }; fSlider.addChangeListener(cl); // Add a bit of padding to space things out fSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); // Present controls below the HR diagram JPanel controls = new JPanel(new GridLayout(2, 2)); controls.add(new JLabel("Distance estimation method:")); controls.add(methodComboBox); controls.add(fLabel); controls.add(fSlider); // Initialise the ChartPanel updateChart(); // Build the panel contents setLayout(new BorderLayout()); add(hrDiagPanel, BorderLayout.WEST); add(dDistPanel, BorderLayout.EAST); add(controls, BorderLayout.SOUTH); }
From source file:projects.upc.exec.HrDiagram.java
/** * Main constructor.//from w w w. j a v a 2 s.c om */ public HrDiagram() { List<UpcStar> upcStars = UpcUtils.loadUpcCatalogue(); List<UpcStar> hipStars = UpcUtils.getHipparcosSubset(upcStars); List<UpcStar> unmatchedStars = UpcUtils.getUnmatchedSubset(upcStars); upcStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(upcStars); hipStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(hipStars); unmatchedStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(unmatchedStars); logger.info("Loaded " + upcStarCrossMatches.size() + " UpcStars with SSA cross matches"); logger.info("Loaded " + hipStarCrossMatches.size() + " UpcStars with Hipparcos and SSA cross matches"); logger.info("Loaded " + unmatchedStarCrossMatches.size() + " UpcStars with no parallax cross-match, and with SSA cross matches"); starsToPlot = upcStarCrossMatches; useHip = false; method = METHOD.NAIVE; fMax = 1.0; final JCheckBox plotAllCheckBox = new JCheckBox("Plot all UPC stars: ", true); plotAllCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (plotAllCheckBox.isSelected()) { starsToPlot = upcStarCrossMatches; updateChart(); } } }); final JCheckBox plotHipCheckBox = new JCheckBox("Plot Hipparcos stars only: ", false); plotHipCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (plotHipCheckBox.isSelected()) { starsToPlot = hipStarCrossMatches; updateChart(); } } }); final JCheckBox plotUnmatchedCheckBox = new JCheckBox("Plot all stars with no external match: ", false); plotUnmatchedCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (plotUnmatchedCheckBox.isSelected()) { starsToPlot = unmatchedStarCrossMatches; updateChart(); } } }); final ButtonGroup bg = new ButtonGroup(); bg.add(plotHipCheckBox); bg.add(plotAllCheckBox); bg.add(plotUnmatchedCheckBox); JCheckBox useHipCheckBox = new JCheckBox("Use Hipparcos parallaxes when available", useHip); useHipCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { useHip = !useHip; updateChart(); } }); final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values()); methodComboBox.setSelectedItem(method); methodComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { method = (METHOD) methodComboBox.getSelectedItem(); updateChart(); } }); final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f"); fSlider.setValue((int) Math.rint(100.0 * fMax)); final JLabel fLabel = new JLabel(getFLabel()); // Create a change listener fot these ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (source == fSlider) { // Compute fractional parallax error from slider position double newF = (2.0 * source.getValue() / 100.0); fMax = newF; fLabel.setText(getFLabel()); } updateChart(); } }; fSlider.addChangeListener(cl); // Add a bit of padding to space things out fSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); // Present controls below the HR diagram JPanel controls = new JPanel(new GridLayout(3, 3)); controls.add(plotAllCheckBox); controls.add(plotHipCheckBox); controls.add(plotUnmatchedCheckBox); controls.add(new JLabel("Distance estimation method:")); controls.add(methodComboBox); controls.add(useHipCheckBox); controls.add(fLabel); controls.add(fSlider); // Initialise the ChartPanel updateChart(); // Build the panel contents setLayout(new BorderLayout()); add(chartPanel, BorderLayout.CENTER); add(controls, BorderLayout.SOUTH); }
From source file:SoundPlayer.java
JSlider createSlider(final FloatControl c) { if (c == null) return null; final JSlider s = new JSlider(0, 1000); final float min = c.getMinimum(); final float max = c.getMaximum(); final float width = max - min; float fval = c.getValue(); s.setValue((int) ((fval - min) / width * 1000)); java.util.Hashtable labels = new java.util.Hashtable(3); labels.put(new Integer(0), new JLabel(c.getMinLabel())); labels.put(new Integer(500), new JLabel(c.getMidLabel())); labels.put(new Integer(1000), new JLabel(c.getMaxLabel())); s.setLabelTable(labels);//from w w w . ja va2 s . c o m s.setPaintLabels(true); s.setBorder(new TitledBorder(c.getType().toString() + " " + c.getUnits())); s.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { int i = s.getValue(); float f = min + (i * width / 1000.0f); c.setValue(f); } }); return s; }
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 .jav a 2s.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: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++; }/*from ww w .j av a2s . 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 ww w . j a va 2 s .c o m*/ * 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:gui.WikiCorpusClusteringView.java
/** * * @param br/*from w ww . j a v a2s .co m*/ * @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); }
From source file:net.pms.encoders.VLCVideo.java
@Override public JComponent config() { // Apply the orientation for the locale Locale locale = new Locale(configuration.getLanguage()); ComponentOrientation orientation = ComponentOrientation.getOrientation(locale); String colSpec = FormLayoutUtil.getColSpec("right:pref, 3dlu, pref:grow, 7dlu, right:pref, 3dlu, pref:grow", orientation);/*from w w w. jav a 2s . co m*/ FormLayout layout = new FormLayout(colSpec, ""); // Here goes my 3rd try to learn JGoodies Form layout.setColumnGroups(new int[][] { { 1, 5 }, { 3, 7 } }); DefaultFormBuilder mainPanel = new DefaultFormBuilder(layout); mainPanel.appendSeparator(Messages.getString("VlcTrans.1")); mainPanel.append(experimentalCodecs = new JCheckBox(Messages.getString("VlcTrans.3"), configuration.isVlcExperimentalCodecs()), 3); experimentalCodecs.setContentAreaFilled(false); experimentalCodecs.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setVlcExperimentalCodecs(e.getStateChange() == ItemEvent.SELECTED); } }); mainPanel.append(audioSyncEnabled = new JCheckBox(Messages.getString("VlcTrans.4"), configuration.isVlcAudioSyncEnabled()), 3); audioSyncEnabled.setContentAreaFilled(false); audioSyncEnabled.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setVlcAudioSyncEnabled(e.getStateChange() == ItemEvent.SELECTED); } }); mainPanel.nextLine(); // Developer stuff. Theoretically is temporary mainPanel.appendSeparator(Messages.getString("VlcTrans.10")); // Add scale as a subpanel because it has an awkward layout mainPanel.append(Messages.getString("VlcTrans.11")); FormLayout scaleLayout = new FormLayout("pref,3dlu,pref", ""); DefaultFormBuilder scalePanel = new DefaultFormBuilder(scaleLayout); double startingScale = Double.valueOf(configuration.getVlcScale()); scalePanel.append(scale = new JTextField(String.valueOf(startingScale))); final JSlider scaleSlider = new JSlider(JSlider.HORIZONTAL, 0, 10, (int) (startingScale * 10)); scalePanel.append(scaleSlider); scaleSlider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent ce) { String value = String.valueOf((double) scaleSlider.getValue() / 10); scale.setText(value); configuration.setVlcScale(value); } }); scale.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { String typed = scale.getText(); if (!typed.matches("\\d\\.\\d")) { return; } double value = Double.parseDouble(typed); scaleSlider.setValue((int) (value * 10)); configuration.setVlcScale(String.valueOf(value)); } }); mainPanel.append(scalePanel.getPanel(), 3); // Audio sample rate FormLayout sampleRateLayout = new FormLayout( "right:pref, 3dlu, right:pref, 3dlu, right:pref, 3dlu, left:pref", ""); DefaultFormBuilder sampleRatePanel = new DefaultFormBuilder(sampleRateLayout); sampleRateOverride = new JCheckBox(Messages.getString("VlcTrans.17"), configuration.getVlcSampleRateOverride()); sampleRatePanel.append(Messages.getString("VlcTrans.18"), sampleRateOverride); sampleRate = new JTextField(configuration.getVlcSampleRate(), 8); sampleRate.setEnabled(configuration.getVlcSampleRateOverride()); sampleRate.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setVlcSampleRate(sampleRate.getText()); } }); sampleRatePanel.append(Messages.getString("VlcTrans.19"), sampleRate); sampleRateOverride.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { boolean checked = e.getStateChange() == ItemEvent.SELECTED; configuration.setVlcSampleRateOverride(checked); sampleRate.setEnabled(checked); } }); mainPanel.nextLine(); mainPanel.append(sampleRatePanel.getPanel(), 7); // Extra options mainPanel.nextLine(); mainPanel.append(Messages.getString("VlcTrans.20"), extraParams = new JTextField(), 5); return mainPanel.getPanel(); }
From source file:projects.wdlf47tuc.ProcessAllSwathcal.java
/** * Main entry point./* ww w . ja v a2s. c om*/ * * @param args * * @throws IOException * */ public ProcessAllSwathcal() { // Path to AllSwathcal.dat file File allSwathcal = new File( "/home/nrowell/Astronomy/Data/47_Tuc/Kalirai_2012/UVIS/www.stsci.edu/~jkalirai/47Tuc/AllSwathcal.dat"); // Read file contents into the List try (BufferedReader in = new BufferedReader(new FileReader(allSwathcal))) { String sourceStr; while ((sourceStr = in.readLine()) != null) { Source source = Source.parseSource(sourceStr); if (source != null) { allSources.add(source); } } } catch (IOException e) { } logger.info("Parsed " + allSources.size() + " Sources from AllSwathcal.dat"); // Initialise chart cmdPanel = new ChartPanel(updateDataAndPlotCmd(allSources)); cmdPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent e) { // Capture mouse click location, transform to graph coordinates and add // a point to the polygonal selection box. Point2D p = cmdPanel.translateScreenToJava2D(e.getTrigger().getPoint()); Rectangle2D plotArea = cmdPanel.getScreenDataArea(); XYPlot plot = (XYPlot) cmdPanel.getChart().getPlot(); double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge()); double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge()); points.add(new double[] { chartX, chartY }); cmdPanel.setChart(plotCmd()); } @Override public void chartMouseMoved(ChartMouseEvent arg0) { } }); // Create colour combo boxes final JComboBox<Filter> magComboBox = new JComboBox<Filter>(filters); final JComboBox<Filter> col1ComboBox = new JComboBox<Filter>(filters); final JComboBox<Filter> col2ComboBox = new JComboBox<Filter>(filters); // Set initial values magComboBox.setSelectedItem(magFilter); col1ComboBox.setSelectedItem(col1Filter); col2ComboBox.setSelectedItem(col2Filter); // Create an action listener for these ActionListener al = new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (evt.getSource() == magComboBox) { magFilter = (Filter) magComboBox.getSelectedItem(); } if (evt.getSource() == col1ComboBox) { col1Filter = (Filter) col1ComboBox.getSelectedItem(); } if (evt.getSource() == col2ComboBox) { col2Filter = (Filter) col2ComboBox.getSelectedItem(); } // Changed colour(s), so reset selection box coordinates points.clear(); cmdPanel.setChart(updateDataAndPlotCmd(allSources)); } }; magComboBox.addActionListener(al); col1ComboBox.addActionListener(al); col2ComboBox.addActionListener(al); // Add a bit of padding to space things out magComboBox.setBorder(new EmptyBorder(5, 5, 5, 5)); col1ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5)); col2ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5)); // Set up statistic sliders final JSlider magErrMaxSlider = GuiUtil.buildSlider(magErrorRangeMin, magErrorRangeMax, 3, "%3.3f"); final JSlider chi2MaxSlider = GuiUtil.buildSlider(chi2RangeMin, chi2RangeMax, 3, "%3.3f"); final JSlider sharpMinSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f"); final JSlider sharpMaxSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f"); // Set intial values magErrMaxSlider.setValue( (int) Math.rint(100.0 * (magErrMax - magErrorRangeMin) / (magErrorRangeMax - magErrorRangeMin))); chi2MaxSlider.setValue((int) Math.rint(100.0 * (chi2Max - chi2RangeMin) / (chi2RangeMax - chi2RangeMin))); sharpMinSlider .setValue((int) Math.rint(100.0 * (sharpMin - sharpRangeMin) / (sharpRangeMax - sharpRangeMin))); sharpMaxSlider .setValue((int) Math.rint(100.0 * (sharpMax - sharpRangeMin) / (sharpRangeMax - sharpRangeMin))); // Set labels & initial values final JLabel magErrMaxLabel = new JLabel(getMagErrMaxLabel()); final JLabel chi2MaxLabel = new JLabel(getChi2MaxLabel()); final JLabel sharpMinLabel = new JLabel(getSharpMinLabel()); final JLabel sharpMaxLabel = new JLabel(getSharpMaxLabel()); // Create a change listener fot these ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (source == magErrMaxSlider) { // Compute max mag error from slider position double newMagErrMax = magErrorRangeMin + (magErrorRangeMax - magErrorRangeMin) * (source.getValue() / 100.0); magErrMax = newMagErrMax; magErrMaxLabel.setText(getMagErrMaxLabel()); } if (source == chi2MaxSlider) { // Compute Chi2 max from slider position double newChi2Max = chi2RangeMin + (chi2RangeMax - chi2RangeMin) * (source.getValue() / 100.0); chi2Max = newChi2Max; chi2MaxLabel.setText(getChi2MaxLabel()); } if (source == sharpMinSlider) { // Compute sharp min from slider position double newSharpMin = sharpRangeMin + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0); sharpMin = newSharpMin; sharpMinLabel.setText(getSharpMinLabel()); } if (source == sharpMaxSlider) { // Compute sharp max from slider position double newSharpMax = sharpRangeMin + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0); sharpMax = newSharpMax; sharpMaxLabel.setText(getSharpMaxLabel()); } cmdPanel.setChart(updateDataAndPlotCmd(allSources)); } }; magErrMaxSlider.addChangeListener(cl); chi2MaxSlider.addChangeListener(cl); sharpMinSlider.addChangeListener(cl); sharpMaxSlider.addChangeListener(cl); // Add a bit of padding to space things out magErrMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); chi2MaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); sharpMinSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); sharpMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); // Text field to store distance modulus final JTextField distanceModulusField = new JTextField(Double.toString(mu)); distanceModulusField.setBorder(new EmptyBorder(5, 5, 5, 5)); Border compound = BorderFactory.createCompoundBorder(new LineBorder(this.getBackground(), 5), BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); final JButton lfButton = new JButton("Luminosity function for selection"); lfButton.setBorder(compound); lfButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Read distance modulus field try { double mu_new = Double.parseDouble(distanceModulusField.getText()); mu = mu_new; } catch (NullPointerException | NumberFormatException ex) { JOptionPane.showMessageDialog(lfButton, "Error parsing the distance modulus: " + ex.getMessage(), "Distance Modulus Error", JOptionPane.ERROR_MESSAGE); return; } if (boxedSources.isEmpty()) { JOptionPane.showMessageDialog(lfButton, "No sources are currently selected!", "Selection Error", JOptionPane.ERROR_MESSAGE); } else { computeAndPlotLuminosityFunction(boxedSources); } } }); final JButton clearSelectionButton = new JButton("Clear selection"); clearSelectionButton.setBorder(compound); clearSelectionButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { points.clear(); cmdPanel.setChart(plotCmd()); } }); JPanel controls = new JPanel(new GridLayout(9, 2)); controls.setBorder(new EmptyBorder(10, 10, 10, 10)); controls.add(new JLabel("Magnitude = ")); controls.add(magComboBox); controls.add(new JLabel("Colour 1 = ")); controls.add(col1ComboBox); controls.add(new JLabel("Colour 2 = ")); controls.add(col2ComboBox); controls.add(magErrMaxLabel); controls.add(magErrMaxSlider); controls.add(chi2MaxLabel); controls.add(chi2MaxSlider); controls.add(sharpMinLabel); controls.add(sharpMinSlider); controls.add(sharpMaxLabel); controls.add(sharpMaxSlider); controls.add(new JLabel("Adopted distance modulus = ")); controls.add(distanceModulusField); controls.add(lfButton); controls.add(clearSelectionButton); this.setLayout(new BorderLayout()); this.add(cmdPanel, BorderLayout.CENTER); this.add(controls, BorderLayout.SOUTH); this.validate(); }