Example usage for javax.swing JSlider getValue

List of usage examples for javax.swing JSlider getValue

Introduction

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

Prototype

public int getValue() 

Source Link

Document

Returns the slider's current value from the BoundedRangeModel .

Usage

From source file:biomine.bmvis2.pipeline.BestPathHiderOperation.java

public JComponent getSettingsComponent(final SettingsChangeCallback settingsChangeCallback,
        final VisualGraph graph) {
    long nodeCount = graph.getAllNodes().size();

    if (oldCount != 0) {
        long newTarget = (target * nodeCount) / oldCount;
        this.target = Math.max(newTarget, target);
    } else//from w ww.j  av a 2s .  c o  m
        this.target = nodeCount;

    this.oldCount = nodeCount;

    JPanel ret = new JPanel();

    // if int overflows, we're fucked
    final JSlider sl = new JSlider(0, (int) nodeCount, (int) Math.min(target, nodeCount));
    sl.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent arg0) {
            if (target == sl.getValue())
                return;
            target = sl.getValue();
            settingsChangeCallback.settingsChanged(false);
        }
    });

    ret.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.gridy = 0;
    //c.gridwidth=2;

    ret.add(sl, c);
    c.gridy++;

    int choices = graph.getNodesOfInterest().size() + 1;

    Object[] items = new Object[choices];
    items[0] = "All PoIs";

    for (int i = 1; i < choices; i++) {
        items[i] = i + " nearest";
    }
    final JComboBox pathTypeBox = new JComboBox(items);
    pathTypeBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            int i = pathTypeBox.getSelectedIndex();
            grader.setPathK(i);
            settingsChangeCallback.settingsChanged(false);
        }
    });

    ret.add(new JLabel("hide by best path quality to:"), c);
    c.gridy++;
    ret.add(pathTypeBox, c);
    c.gridy++;

    System.out.println("new confpane nodeCount = " + nodeCount);

    final JCheckBox useMatchingColoring = new JCheckBox();
    ret.add(useMatchingColoring, c);

    useMatchingColoring.setAction(new AbstractAction("Use matching coloring") {
        public void actionPerformed(ActionEvent arg0) {
            matchColoring = useMatchingColoring.isSelected();
            settingsChangeCallback.settingsChanged(false);
        }
    });

    useMatchingColoring.setAlignmentX(JComponent.CENTER_ALIGNMENT);

    c.gridy++;

    final JCheckBox labelsBox = new JCheckBox();
    ret.add(labelsBox, c);

    labelsBox.setAction(new AbstractAction("Show goodness in node labels") {
        public void actionPerformed(ActionEvent arg0) {
            showLabel = labelsBox.isSelected();
            settingsChangeCallback.settingsChanged(false);
        }
    });

    return ret;
}

From source file:projects.hip.exec.HrDiagram.java

/**
 * Main constructor./*from   ww w  .j a  v  a 2s  .  co  m*/
 */
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:biomine.bmvis2.pipeline.EdgeGoodnessHider.java

public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    double maxEdge = 0;
    for (VisualEdge e : graph.getAllEdges()) {
        maxEdge = Math.max(maxEdge, e.getGoodness());
    }/*from w  w  w.ja v  a 2s. com*/

    final int scale = 100;
    final JSlider limitSlider = new JSlider();
    limitSlider.setMinimum(0);
    limitSlider.setMaximum(scale);
    limitSlider.setValue((int) (limit * scale));
    final JTextField limitText = new JTextField();
    limitText.setEditable(false);
    limitText.setText("" + limit);

    limitSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent arg0) {
            limit = limitSlider.getValue() / (double) scale;
            limitText.setText("" + limit);
            v.settingsChanged(false);
        }
    });

    JPanel ret = new JPanel();
    GridBagLayout bag = new GridBagLayout();
    ret.setLayout(bag);
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.fill = c.HORIZONTAL;
    ret.add(limitSlider, c);
    c.gridy++;
    ret.add(limitText, c);
    return ret;
}

From source file:com.floreantpos.config.ui.TerminalConfigurationView.java

private void initComponents() {
    setLayout(new BorderLayout());

    JPanel contentPanel = new JPanel(new MigLayout("gap 5px 10px", "[][][grow]", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    JLabel lblTerminalNumber = new JLabel(Messages.getString("TerminalConfigurationView.TERMINAL_NUMBER")); //$NON-NLS-1$
    contentPanel.add(lblTerminalNumber, "alignx left,aligny center"); //$NON-NLS-1$

    tfTerminalNumber = new IntegerTextField();
    tfTerminalNumber.setColumns(10);//from w  w  w  .  j a v a 2s  . c  o  m
    contentPanel.add(tfTerminalNumber, "aligny top,wrap"); //$NON-NLS-1$

    JLabel lblTerminalLocation = new JLabel(Messages.getString("TerminalConfigurationView.24")); //$NON-NLS-1$
    taTerminalLocation = new JTextArea();
    taTerminalLocation.setLineWrap(true);
    taTerminalLocation.setPreferredSize(PosUIManager.getSize(350, 40));

    JScrollPane taScrollPane = new JScrollPane(taTerminalLocation);

    contentPanel.add(new JLabel(Messages.getString("TerminalConfigurationView.9"))); //$NON-NLS-1$
    tfSecretKeyLength = new IntegerTextField(3);
    contentPanel.add(tfSecretKeyLength, "wrap"); //$NON-NLS-1$

    contentPanel.add(cbShowDbConfiguration, "spanx 3"); //$NON-NLS-1$

    cbAutoLogoff.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (cbAutoLogoff.isSelected()) {
                tfLogoffTime.setEnabled(true);
            } else {
                tfLogoffTime.setEnabled(false);
            }
        }
    });
    contentPanel.add(cbAutoLogoff, "newline"); //$NON-NLS-1$
    contentPanel.add(tfLogoffTime, "wrap"); //$NON-NLS-1$

    contentPanel.add(cbTranslatedName, "span 2"); //$NON-NLS-1$
    contentPanel.add(cbFullscreenMode, "newline, span"); //$NON-NLS-1$
    contentPanel.add(cbUseSettlementPrompt, "newline, span"); //$NON-NLS-1$
    contentPanel.add(cbShowBarCodeOnReceipt, "newline,span"); //$NON-NLS-1$
    contentPanel.add(cbGroupKitchenReceiptItems, "newline,span"); //$NON-NLS-1$
    contentPanel.add(chkEnabledMultiCurrency, "newline,span"); //$NON-NLS-1$
    contentPanel.add(chkAllowToDelPrintedItem, "newline,span"); //$NON-NLS-1$
    contentPanel.add(chkAllowQuickMaintenance, "newline,span"); //$NON-NLS-1$
    contentPanel.add(chkModifierCannotExceedMaxLimit, "newline,span"); //$NON-NLS-1$

    contentPanel.add(new JLabel(Messages.getString("TerminalConfigurationView.17")), "newline"); //$NON-NLS-1$//$NON-NLS-2$
    contentPanel.add(cbFonts, "span 2, wrap"); //$NON-NLS-1$

    Vector<String> defaultViewList = new Vector<String>();

    List<OrderType> orderTypes = Application.getInstance().getOrderTypes();
    if (orderTypes != null) {
        for (OrderType orderType : orderTypes) {
            defaultViewList.add(orderType.getName());
        }
    }
    defaultViewList.add(SwitchboardOtherFunctionsView.VIEW_NAME);
    defaultViewList.add(KitchenDisplayView.VIEW_NAME);
    defaultViewList.add(SwitchboardView.VIEW_NAME);

    cbDefaultView = new JComboBox<String>(defaultViewList);

    contentPanel.add(new JLabel("Default View"), "newline"); //$NON-NLS-1$//$NON-NLS-2$
    contentPanel.add(cbDefaultView, "span 2, wrap"); //$NON-NLS-1$

    contentPanel.add(lblTerminalLocation, "alignx left,aligny top"); //$NON-NLS-1$
    contentPanel.add(taScrollPane, "aligny top, spanx 2,wrap"); //$NON-NLS-1$

    JPanel touchConfigurationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 20, 10));
    touchConfigurationPanel.setBorder(BorderFactory.createTitledBorder("-")); //$NON-NLS-1$
    touchConfigurationPanel.add(new JLabel(Messages.getString("TerminalConfigurationView.18"))); //$NON-NLS-1$
    tfButtonHeight = new IntegerTextField(5);
    //touchConfigPanel.add(tfButtonHeight);

    int FPS_MIN = 10;
    int FPS_MAX = 50;
    int FPS_INIT = 10;
    jsResize = new JSlider(JSlider.HORIZONTAL, FPS_MIN, FPS_MAX, FPS_INIT);
    jsResize.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) {
                double fps = (int) source.getValue();
                fps = fps / 10;
                tfScaleFactor.setText(String.valueOf(fps));
            }
        }
    });
    touchConfigurationPanel.add(jsResize);

    //touchConfigPanel.add(new JLabel("Menu item button height"));
    tfScaleFactor = new DoubleTextField(5);
    touchConfigurationPanel.add(tfScaleFactor);

    //touchConfigPanel.add(new JLabel(Messages.getString("TerminalConfigurationView.20"))); //$NON-NLS-1$
    tfFontSize = new IntegerTextField(5);
    //touchConfigPanel.add(tfFontSize);

    contentPanel.add(touchConfigurationPanel, "span 3, wrap"); //$NON-NLS-1$

    addCashDrawerConfig();

    JScrollPane scrollPane = new JScrollPane(contentPanel);
    scrollPane.setBorder(null);
    add(scrollPane);
}

From source file:projects.upc.exec.HrDiagram.java

/**
 * Main constructor.//from   w  w  w. j  a v a  2 s . c o m
 */
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:Human1.java

public void stateChanged(ChangeEvent e) {
    JSlider source = (JSlider) e.getSource();
    int value = source.getValue();
    if (source == rShoulderSlider) {
        setRShoulderRot(value);/*from   www.j  a  v a 2s.c om*/
        rShoulderSliderLabel.setText(Integer.toString(value));
    } else if (source == rElbowSlider) {
        setRElbowRot(value);
        rElbowSliderLabel.setText(Integer.toString(value));
    } else if (source == lShoulderSlider) {
        setLShoulderRot(value);
        lShoulderSliderLabel.setText(Integer.toString(value));
    } else if (source == lElbowSlider) {
        setLElbowRot(value);
        lElbowSliderLabel.setText(Integer.toString(value));
    }
}

From source file:io.github.jeremgamer.editor.panels.MusicFrame.java

public MusicFrame(JFrame frame, final GeneralSave gs) {

    ArrayList<BufferedImage> icons = new ArrayList<BufferedImage>();
    try {//w  w w . java  2 s.  c o m
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon16.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon32.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon64.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon128.png")));
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    this.setIconImages((List<? extends Image>) icons);

    this.setTitle("Musique");
    this.setSize(new Dimension(300, 225));

    this.addWindowListener(new WindowListener() {
        @Override
        public void windowActivated(WindowEvent event) {
        }

        @Override
        public void windowClosed(WindowEvent event) {
        }

        @Override
        public void windowClosing(WindowEvent event) {
            try {
                gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (clip != null) {
                clip.stop();
                clip.close();
                try {
                    audioStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void windowDeactivated(WindowEvent event) {
        }

        @Override
        public void windowDeiconified(WindowEvent event) {
        }

        @Override
        public void windowIconified(WindowEvent event) {
        }

        @Override
        public void windowOpened(WindowEvent event) {
        }
    });

    this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));

    this.setModal(true);
    this.setLocationRelativeTo(frame);

    JPanel properties = new JPanel();
    properties.setBorder(BorderFactory.createTitledBorder("Lecture"));
    ButtonGroup bg = new ButtonGroup();
    bg.add(one);
    bg.add(loop);
    one.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JRadioButton rb = (JRadioButton) event.getSource();
            if (rb.isSelected()) {
                gs.set("music.reading", 0);
                try {
                    gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (clip != null) {
                    if (clip.isRunning())
                        clip.loop(0);
                }
            }
        }
    });
    loop.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JRadioButton rb = (JRadioButton) event.getSource();
            if (rb.isSelected()) {
                gs.set("music.reading", 1);
                try {
                    gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (clip != null) {
                    if (clip.isRunning())
                        clip.loop(Clip.LOOP_CONTINUOUSLY);
                }
            }
        }
    });
    properties.add(one);
    properties.add(loop);
    if (gs.getInt("music.reading") == 0) {
        one.setSelected(true);
    } else {
        loop.setSelected(true);
    }

    volume.setMaximum(100);
    volume.setMinimum(0);
    volume.setValue(30);
    volume.setPaintTicks(true);
    volume.setPaintLabels(true);
    volume.setMinorTickSpacing(10);
    volume.setMajorTickSpacing(20);
    volume.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent event) {
            JSlider slider = (JSlider) event.getSource();
            double value = slider.getValue();
            gain = value / 100;
            dB = (float) (Math.log(gain) / Math.log(10.0) * 20.0);
            if (clip != null)
                gainControl.setValue(dB);
            gs.set("music.volume", (int) value);
        }
    });
    volume.setValue(gs.getInt("music.volume"));
    properties.add(volume);
    properties.setPreferredSize(new Dimension(300, 125));

    content.add(properties);

    JPanel browsePanel = new JPanel();
    browsePanel.setBorder(BorderFactory.createTitledBorder(""));
    JButton browse = new JButton("Parcourir...");
    if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) {
        preview.setEnabled(false);
        browse.setText("");
        try {
            browse.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    browse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JButton button = (JButton) event.getSource();
            if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) {
                if (clip != null) {
                    clip.stop();
                    clip.close();
                    try {
                        audioStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                name.setText("");
                preview.setEnabled(false);
                button.setText("Parcourir...");
                button.setIcon(null);
                new File("projects/" + Editor.getProjectName() + "/music.wav").delete();
                gs.set("music.name", "");
            } else {
                String path = null;
                JFileChooser chooser = new JFileChooser(Editor.lastPath);
                FileNameExtensionFilter filter = new FileNameExtensionFilter("Audio (WAV)", "wav");
                chooser.setFileFilter(filter);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                int option = chooser.showOpenDialog(null);
                if (option == JFileChooser.APPROVE_OPTION) {
                    path = chooser.getSelectedFile().getAbsolutePath();
                    Editor.lastPath = chooser.getSelectedFile().getParent();
                    copyMusic(new File(path));
                    button.setText("");
                    try {
                        button.setIcon(
                                new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    gs.set("music.name", new File(path).getName());
                    try {
                        gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    name.setText(new File(path).getName());
                    preview.setEnabled(true);
                }
            }
        }

    });
    if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) {
        preview.setEnabled(true);
    } else {
        preview.setEnabled(false);
    }
    preview.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JToggleButton tb = (JToggleButton) event.getSource();
            if (tb.isSelected()) {
                try {
                    audioStream = AudioSystem.getAudioInputStream(
                            new File("projects/" + Editor.getProjectName() + "/music.wav"));
                    format = audioStream.getFormat();
                    info = new DataLine.Info(Clip.class, format);
                    clip = (Clip) AudioSystem.getLine(info);
                    clip.open(audioStream);
                    clip.start();
                    gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
                    gainControl.setValue(dB);
                    if (loop.isSelected()) {
                        clip.loop(Clip.LOOP_CONTINUOUSLY);
                    } else {
                        clip.loop(0);
                    }
                    clip.addLineListener(new LineListener() {
                        @Override
                        public void update(LineEvent event) {
                            Clip clip = (Clip) event.getSource();
                            if (!clip.isRunning()) {
                                preview.setSelected(false);
                                clip.stop();
                                clip.close();
                                try {
                                    audioStream.close();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                    });
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            } else {
                clip.stop();
                clip.close();
                try {
                    audioStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    });
    JPanel buttons = new JPanel();
    buttons.setLayout(new BorderLayout());
    buttons.add(browse, BorderLayout.WEST);
    buttons.add(preview, BorderLayout.EAST);
    browsePanel.setLayout(new BorderLayout());
    browsePanel.add(buttons, BorderLayout.NORTH);
    browsePanel.add(name, BorderLayout.SOUTH);

    name.setPreferredSize(new Dimension(280, 25));
    name.setText(gs.getString("music.name"));
    content.add(browsePanel);

    this.setContentPane(content);
    this.setVisible(true);
}

From source file:EdgeLabelDemo.java

/**
 * create an instance of a simple graph with controls to
 * demo the label positioning features//w ww  .  ja v a  2  s  .  com
 * 
 */
@SuppressWarnings("serial")
public EdgeLabelDemo() {

    // create a simple graph for the demo
    graph = new SparseMultigraph<Integer, Number>();
    Integer[] v = createVertices(3);
    createEdges(v);

    Layout<Integer, Number> layout = new CircleLayout<Integer, Number>(graph);
    vv = new VisualizationViewer<Integer, Number>(layout, new Dimension(600, 400));
    vv.setBackground(Color.white);

    vertexLabelRenderer = vv.getRenderContext().getVertexLabelRenderer();
    edgeLabelRenderer = vv.getRenderContext().getEdgeLabelRenderer();

    Transformer<Number, String> stringer = new Transformer<Number, String>() {
        public String transform(Number e) {
            return "Edge:" + graph.getEndpoints(e).toString();
        }
    };
    vv.getRenderContext().setEdgeLabelTransformer(stringer);
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.cyan));
    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.red, Color.yellow));
    // add my listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<Integer>());

    // create a frome to hold the graph
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    Container content = getContentPane();
    content.add(panel);

    final DefaultModalGraphMouse<Integer, Number> graphMouse = new DefaultModalGraphMouse<Integer, Number>();
    vv.setGraphMouse(graphMouse);

    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());
        }
    });

    ButtonGroup radio = new ButtonGroup();
    JRadioButton lineButton = new JRadioButton("Line");
    lineButton.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<Integer, Number>());
                vv.repaint();
            }
        }
    });

    JRadioButton quadButton = new JRadioButton("QuadCurve");
    quadButton.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<Integer, Number>());
                vv.repaint();
            }
        }
    });

    JRadioButton cubicButton = new JRadioButton("CubicCurve");
    cubicButton.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.CubicCurve<Integer, Number>());
                vv.repaint();
            }
        }
    });
    radio.add(lineButton);
    radio.add(quadButton);
    radio.add(cubicButton);

    graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);

    JCheckBox rotate = new JCheckBox("<html><center>EdgeType<p>Parallel</center></html>");
    rotate.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            AbstractButton b = (AbstractButton) e.getSource();
            edgeLabelRenderer.setRotateEdgeLabels(b.isSelected());
            vv.repaint();
        }
    });
    rotate.setSelected(true);
    MutableDirectionalEdgeValue mv = new MutableDirectionalEdgeValue(.5, .7);
    vv.getRenderContext().setEdgeLabelClosenessTransformer(mv);
    JSlider directedSlider = new JSlider(mv.getDirectedModel()) {
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.width /= 2;
            return d;
        }
    };
    JSlider undirectedSlider = new JSlider(mv.getUndirectedModel()) {
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.width /= 2;
            return d;
        }
    };

    JSlider edgeOffsetSlider = new JSlider(0, 50) {
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.width /= 2;
            return d;
        }
    };
    edgeOffsetSlider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            JSlider s = (JSlider) e.getSource();
            AbstractEdgeShapeTransformer<Integer, Number> aesf = (AbstractEdgeShapeTransformer<Integer, Number>) vv
                    .getRenderContext().getEdgeShapeTransformer();
            aesf.setControlOffsetIncrement(s.getValue());
            vv.repaint();
        }

    });

    Box controls = Box.createHorizontalBox();

    JPanel zoomPanel = new JPanel(new GridLayout(0, 1));
    zoomPanel.setBorder(BorderFactory.createTitledBorder("Scale"));
    zoomPanel.add(plus);
    zoomPanel.add(minus);

    JPanel edgePanel = new JPanel(new GridLayout(0, 1));
    edgePanel.setBorder(BorderFactory.createTitledBorder("EdgeType Type"));
    edgePanel.add(lineButton);
    edgePanel.add(quadButton);
    edgePanel.add(cubicButton);

    JPanel rotatePanel = new JPanel();
    rotatePanel.setBorder(BorderFactory.createTitledBorder("Alignment"));
    rotatePanel.add(rotate);

    JPanel labelPanel = new JPanel(new BorderLayout());
    JPanel sliderPanel = new JPanel(new GridLayout(3, 1));
    JPanel sliderLabelPanel = new JPanel(new GridLayout(3, 1));
    JPanel offsetPanel = new JPanel(new BorderLayout());
    offsetPanel.setBorder(BorderFactory.createTitledBorder("Offset"));
    sliderPanel.add(directedSlider);
    sliderPanel.add(undirectedSlider);
    sliderPanel.add(edgeOffsetSlider);
    sliderLabelPanel.add(new JLabel("Directed", JLabel.RIGHT));
    sliderLabelPanel.add(new JLabel("Undirected", JLabel.RIGHT));
    sliderLabelPanel.add(new JLabel("Edges", JLabel.RIGHT));
    offsetPanel.add(sliderLabelPanel, BorderLayout.WEST);
    offsetPanel.add(sliderPanel);
    labelPanel.add(offsetPanel);
    labelPanel.add(rotatePanel, BorderLayout.WEST);

    JPanel modePanel = new JPanel(new GridLayout(2, 1));
    modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    modePanel.add(graphMouse.getModeComboBox());

    controls.add(zoomPanel);
    controls.add(edgePanel);
    controls.add(labelPanel);
    controls.add(modePanel);
    content.add(controls, BorderLayout.SOUTH);
    quadButton.setSelected(true);
}

From source file:AtomPanel.java

/** Listen to the slider. */
public void stateChanged(ChangeEvent e) {
    JSlider source = (JSlider) e.getSource();
    if ("faRate".equals(source.getName())) {
        if (!source.getValueIsAdjusting()) {
            double L = (double) source.getValue();
            falseAlarmRate = 0.001 * L; // L is 1-10, map it to 0.001-0.01
        }//from   ww w. ja v a2s .  co  m
    } else if ("wdSz".equals(source.getName())) { //"window size"
        if (!source.getValueIsAdjusting()) {
            double L = (double) source.getValue();
            wdSz = 20 * (int) (L); // L is 1-10, map it to 40-400
        }
    } else if ("delta".equals(source.getName())) { //"delta"
        if (!source.getValueIsAdjusting()) {
            double L = (double) source.getValue();
            percent = 0.02 * (L - 1); // L is 1-10, map it to 0-0.2
        }
    } else if ("devbnd".equals(source.getName())) { //"deviation bound"
        if (!source.getValueIsAdjusting()) {
            double L = (double) source.getValue();
            devBnd = 0.001 * (L - 1) / 9; // L is 1-10, map it to 0-0.01
        }
    }
}

From source file:PolygonOffset.java

public void stateChanged(ChangeEvent e) {
    JSlider source = (JSlider) e.getSource();
    curInt = source.getValue();
    curLog = curInt / scale;/* w ww  .  ja  v  a2s . com*/
    current = (float) exp10(curLog);

    valueChanged();
}