List of usage examples for javax.swing JSlider getValue
public int getValue()
From source file:pt.lsts.neptus.console.plugins.ImageLayers.java
private void rebuildControls() { scroll.removeAll();/*w w w . ja v a 2s . c o m*/ for (final ImageLayer il : layers) { scroll.add(new JLabel(il.getName())); final JSlider slider = new JSlider(0, 1000, (int) (il.getTransparency() * 1000)); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { il.setTransparency(slider.getValue() / 1000.0); } }); slider.setMinimumSize(new Dimension(20, 20)); scroll.add(slider); } scroll.doLayout(); scroll.revalidate(); }
From source file:savant.snp.SNPFinderPlugin.java
private void setupGUI(JPanel panel) { // add a toolbar JToolBar tb = new JToolBar(); tb.setName("SNP Finder Toolbar"); // add an ON/OFF checkbox JLabel lab_on = new JLabel("On/Off: "); JCheckBox cb_on = new JCheckBox(); cb_on.setSelected(isSNPFinderOn);/* w w w. j a v a 2 s .com*/ // what to do when a user clicks the checkbox cb_on.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // switch the SNP finder on/off setIsOn(!isSNPFinderOn); addMessage("Turning SNP finder " + (isSNPFinderOn ? "on" : "off")); } }); // add a Bookmarking ON/OFF checkbox JLabel lab_bm = new JLabel("Add Bookmarks: "); JCheckBox cb_bm = new JCheckBox(); cb_bm.setSelected(addBookmarks); // what to do when a user clicks the checkbox cb_bm.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // switch the SNP finder on/off setBookmarking(!addBookmarks); addMessage("Turning Bookmarking " + (addBookmarks ? "on" : "off")); } }); JLabel lab_sp = new JLabel("Heterozygosity: "); //add snp prior textfield final JTextField snpPriorField = new JTextField(String.valueOf(snpPrior), 4); snpPriorField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { setSNPPrior(Double.valueOf(snpPriorField.getText())); } catch (NumberFormatException ex) { snpPriorField.setText(String.valueOf(snpPrior)); } } }); int tfwidth = 35; int tfheight = 22; snpPriorField.setPreferredSize(new Dimension(tfwidth, tfheight)); snpPriorField.setMaximumSize(new Dimension(tfwidth, tfheight)); snpPriorField.setMinimumSize(new Dimension(tfwidth, tfheight)); // add a sensitivity slider JLabel lab_confidence = new JLabel("Confidence: "); final JSlider sens_slider = new JSlider(0, 50); sens_slider.setValue(confidence); final JLabel lab_confidence_status = new JLabel("" + sens_slider.getValue()); // what to do when a user slides the slider sens_slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { // set the snp finder's sensitivity lab_confidence_status.setText("" + sens_slider.getValue()); setSensitivity(sens_slider.getValue()); } }); // don't report the new setting until the user stops sliding sens_slider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { addMessage("Changed confidence to " + confidence); } }); // add a transparency slider JLabel lab_trans = new JLabel("Transparency: "); final JSlider trans_slider = new JSlider(0, 100); trans_slider.setValue(transparency); final JLabel lab_transparency_status = new JLabel("" + trans_slider.getValue()); // what to do when a user slides the slider trans_slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { // set the snp finder's transparency lab_transparency_status.setText("" + trans_slider.getValue()); setTransparency(trans_slider.getValue()); } }); // don't report the new setting until the user stops sliding trans_slider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { addMessage("Changed transparency to " + transparency); } }); // add the components to the GUI panel.setLayout(new BorderLayout()); tb.add(lab_on); tb.add(cb_on); tb.add(lab_bm); tb.add(cb_bm); tb.add(new JToolBar.Separator()); tb.add(lab_sp); tb.add(snpPriorField); tb.add(new JToolBar.Separator()); tb.add(lab_confidence); tb.add(sens_slider); tb.add(lab_confidence_status); tb.add(new JToolBar.Separator()); tb.add(lab_trans); tb.add(trans_slider); tb.add(lab_transparency_status); panel.add(tb, BorderLayout.NORTH); // add a text area to the GUI info = new JTextArea(); JScrollPane scrollPane = new JScrollPane(info); panel.add(scrollPane, BorderLayout.CENTER); }
From source file:se.llbit.chunky.renderer.ui.Adjuster.java
@Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); double value; if (logarithmic) { value = (double) (source.getValue() - source.getMinimum()) / (source.getMaximum() - source.getMinimum()); double logMin = FastMath.log10(min); double logMax = FastMath.log10(max); double scale = logMax - logMin; value = FastMath.pow(10, value * scale + logMin); } else {//from ww w . j a va 2s.com double scale = (max - min) / (source.getMaximum() - source.getMinimum()); value = (source.getValue() - source.getMinimum()) * scale + min; } setTextField(value); valueChanged(value); }
From source file:semgen.extraction.RadialGraph.Clusterer.java
public void setUpView() throws IOException { setTitle(SemGenTab.formatTabName(extractor.semsimmodel.getName())); layout = new AggregateLayout<String, Number>(new SemGenFRLayout<String, Number>(mygraph)); vv = new VisualizationViewer<String, Number>(layout); // this class will provide both label drawing and vertex shapes VertexLabelAsShapeRenderer<String, Number> vlasr = new VertexLabelAsShapeRenderer<String, Number>( vv.getRenderContext());// w w w. jav a 2s .com // customize the render context vv.getRenderContext().setVertexLabelTransformer( // this chains together Transformers so that the html tags // are prepended to the toString method output new ChainedTransformer<String, String>( new Transformer[] { new ToStringLabeller<String>(), new Transformer<String, String>() { public String transform(String input) { return input; } } })); vv.getRenderContext().setVertexShapeTransformer(vlasr); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.red)); vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.yellow)); vv.getRenderContext().setEdgeStrokeTransformer(new ConstantTransformer(new BasicStroke(2.5f))); // customize the renderer vv.getRenderer().setVertexLabelRenderer(vlasr); vv.setBackground(Color.white); // Tell the renderer to use our own customized color rendering vv.getRenderContext() .setVertexFillPaintTransformer(MapTransformer.<String, Paint>getInstance(vertexPaints)); vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<String, Paint>() { public Paint transform(String v) { if (vv.getPickedVertexState().isPicked(v)) { if (selectioncheckbox != null) { extractor.clusterpanel.remove(selectioncheckbox); } Set<DataStructure> dsuris = new HashSet<DataStructure>(); for (String dsname : vv.getPickedVertexState().getPicked()) { dsuris.add(extractor.semsimmodel.getDataStructure(dsname)); } Component[] clusters = extractor.clusterpanel.checkboxpanel.getComponents(); extractor.clusterpanel.checkboxpanel.removeAll(); for (int x = -1; x < clusters.length; x++) { if (x == -1 && selectioncheckbox == null) { selectioncheckbox = new ExtractorJCheckBox("Selected node(s)", dsuris); selectioncheckbox.addItemListener(extractor); extractor.clusterpanel.checkboxpanel.add(selectioncheckbox); } else if (x > -1) { extractor.clusterpanel.checkboxpanel.add(clusters[x]); } } refreshModulePanel(); return Color.cyan; } else { if (vv.getPickedVertexState().getPicked().isEmpty()) { if (selectioncheckbox != null) { extractor.clusterpanel.checkboxpanel.remove(selectioncheckbox); selectioncheckbox = null; } } refreshModulePanel(); 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("Shake"); scramble.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Layout<String, Number> layout = vv.getGraphLayout(); layout.initialize(); Relaxer relaxer = vv.getModel().getRelaxer(); if (relaxer != null) { relaxer.stop(); relaxer.prerelax(); relaxer.relax(); } } }); DefaultModalGraphMouse<Object, Object> gm = new DefaultModalGraphMouse<Object, Object>(); vv.setGraphMouse(gm); 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(350, 50)); edgeBetweennessSlider.setPaintTicks(true); edgeBetweennessSlider.setMaximum(mygraph.getEdgeCount()); edgeBetweennessSlider.setMinimum(0); edgeBetweennessSlider.setValue(0); if (mygraph.getEdgeCount() > 10) { edgeBetweennessSlider.setMajorTickSpacing(mygraph.getEdgeCount() / 10); } else { edgeBetweennessSlider.setMajorTickSpacing(1); } edgeBetweennessSlider.setPaintLabels(true); edgeBetweennessSlider.setPaintTicks(true); // 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(Box.createVerticalGlue()); groupVertices.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { clusterAndRecolor(layout, edgeBetweennessSlider.getValue(), similarColors, e.getStateChange() == ItemEvent.SELECTED); vv.repaint(); } }); 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(); } } }); clusterAndRecolor(layout, 0, similarColors, groupVertices.isSelected()); clusterpanel = new JPanel(); clusterpanel.setLayout(new BoxLayout(clusterpanel, BoxLayout.Y_AXIS)); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); clusterpanel.add(gzsp); 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); clusterpanel.add(south); clusterpanel.add(Box.createGlue()); semscroller = new SemGenScrollPane(sempanel); splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, semscroller, clusterpanel); splitpane.setDividerLocation(initsempanelwidth); splitpane.setDividerLocation(initsempanelwidth + 10); this.add(splitpane); this.setPreferredSize(new Dimension(950, 800)); this.pack(); this.setLocationRelativeTo(null); this.setVisible(true); }
From source file:test.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 .jav a 2s.co m }; 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); }