Search in sources :

Example 16 with JSlider

use of javax.swing.JSlider in project vcell by virtualcell.

the class HistogramPanel method getHorzOffsetSlider.

private JSlider getHorzOffsetSlider() {
    if (horzOffsetSlider != null) {
        return horzOffsetSlider;
    }
    horzOffsetSlider = new JSlider();
    horzOffsetSlider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            if (originalTreeMap == null) {
                return;
            }
            int min = horzOffsetSlider.getValue();
            int max = min + originalTreeMap.lastKey() / horzScaleSlider.getValue();
            if (max > originalTreeMap.lastKey()) {
                min -= (max) - originalTreeMap.lastKey();
            }
            min = Math.max(originalTreeMap.firstKey(), min);
            max = Math.min(max, originalTreeMap.lastKey());
            viewPixelRange = new Range(min, max);
            updateLowHigh();
            repaint();
        }
    });
    horzOffsetSlider.setMinimum(0);
    horzOffsetSlider.setMaximum(33000);
    horzOffsetSlider.setValue(0);
    return horzOffsetSlider;
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) Range(org.vcell.util.Range)

Example 17 with JSlider

use of javax.swing.JSlider in project vcell by virtualcell.

the class OverlayEditorPanelJAI method getTimeSlider.

/**
 * This method initializes timeSlider
 *
 * @return javax.swing.JSlider
 */
private JSlider getTimeSlider() {
    if (timeSlider == null) {
        timeSlider = new JSlider(1, 1);
        timeSlider.setPaintLabels(true);
        timeSlider.setMajorTickSpacing(100);
        timeSlider.addChangeListener(new javax.swing.event.ChangeListener() {

            public void stateChanged(javax.swing.event.ChangeEvent e) {
                forceImage();
            }
        });
    }
    return timeSlider;
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener)

Example 18 with JSlider

use of javax.swing.JSlider in project vcell by virtualcell.

the class OptModelParamPanel method init.

public void init(OptContext optContext, NormalizedSampleFunction[] fittedROIs, LocalWorkspace localWorkspace) {
    this.optContext = optContext;
    this.fittedROIs = fittedROIs;
    this.localWorkspace = localWorkspace;
    Parameter[] parameters = optContext.getParameters();
    final GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 7, 7, 7, 0 };
    gridBagLayout.rowHeights = new int[] { 7, 7, 7, 7 };
    parameterPanel.setLayout(gridBagLayout);
    int gridLayout_Y = 0;
    for (int i = 0; i < parameters.length; i++) {
        final JLabel label = new JLabel();
        label.setText(parameters[i].getName());
        final GridBagConstraints gridBagConstraints0 = new GridBagConstraints();
        gridBagConstraints0.insets = new Insets(2, 2, 2, 2);
        gridBagConstraints0.anchor = GridBagConstraints.EAST;
        gridBagConstraints0.gridy = gridLayout_Y;
        gridBagConstraints0.gridx = 0;
        parameterPanel.add(label, gridBagConstraints0);
        JTextField textField = new JTextField();
        parameterValueTextFields.add(textField);
        textField.getDocument().addUndoableEditListener(EDIT_LISTENER);
        textField.setPreferredSize(new Dimension(125, 20));
        textField.addActionListener(OPTIMIZER_VALUE_ACTION_LISTENER);
        textField.setMinimumSize(new Dimension(125, 20));
        final GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(2, 2, 2, 0);
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints.gridy = gridLayout_Y;
        gridBagConstraints.gridx = 1;
        parameterPanel.add(textField, gridBagConstraints);
        JButton setButton = new JButton();
        parameterValueSetButtons.add(setButton);
        setButton.setMargin(new Insets(2, 1, 2, 1));
        setButton.addActionListener(SET_ACTION_LISTENER);
        setButton.setText("Set");
        final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
        gridBagConstraints_1.insets = new Insets(2, 0, 2, 2);
        gridBagConstraints_1.gridy = gridLayout_Y;
        gridBagConstraints_1.gridx = 2;
        parameterPanel.add(setButton, gridBagConstraints_1);
        JSlider slider = new JSlider();
        parameterValueSliders.add(slider);
        slider.addChangeListener(OPTIMIZER_SLIDER_CHANGE_LISTENER);
        slider.setPaintLabels(true);
        final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints();
        gridBagConstraints_4.weighty = 1;
        gridBagConstraints_4.insets = new Insets(2, 2, 2, 0);
        gridBagConstraints_4.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints_4.weightx = 1;
        gridBagConstraints_4.gridy = gridLayout_Y;
        gridBagConstraints_4.gridx = 3;
        parameterPanel.add(slider, gridBagConstraints_4);
        gridLayout_Y++;
    }
    for (JSlider slider : parameterValueSliders) {
        slider.removeChangeListener(OPTIMIZER_SLIDER_CHANGE_LISTENER);
    }
    try {
        for (int parameterIndex = 0; parameterIndex < parameters.length; parameterIndex++) {
            Parameter parameter = parameters[parameterIndex];
            JSlider slider = parameterValueSliders.get(parameterIndex);
            Hashtable<Integer, JComponent> sliderLabelTable = new Hashtable<Integer, JComponent>();
            slider.setMinimum(0);
            slider.setMaximum(2000);
            slider.setValue(0);
            sliderLabelTable.put(0, new JLabel(parameter.getLowerBound() + ""));
            sliderLabelTable.put(2000, new JLabel(parameter.getUpperBound() + ""));
            // 
            // way of doing a log scale
            // 
            // bleachWhileMonitorSliderLabelTable.put(new Integer(0), new JLabel(FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getLowerBound()+""));
            // bleachWhileMonitorSliderLabelTable.put(new Integer(20), new JLabel("1e-4"));
            // bleachWhileMonitorSliderLabelTable.put(new Integer(40), new JLabel("1e-3"));
            // bleachWhileMonitorSliderLabelTable.put(new Integer(60), new JLabel("1e-2"));
            // bleachWhileMonitorSliderLabelTable.put(new Integer(80), new JLabel("1e-1"));
            // bleachWhileMonitorSliderLabelTable.put(new Integer(100),new JLabel(FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getUpperBound()+""));
            // Kludge for WindowBuilder otherwise not display correctly
            slider.setLabelTable(null);
            slider.setLabelTable(sliderLabelTable);
        }
    } finally {
        for (JSlider slider : parameterValueSliders) {
            slider.addChangeListener(OPTIMIZER_SLIDER_CHANGE_LISTENER);
        }
    }
    double[] parameterValues = new double[parameters.length];
    for (int i = 0; i < parameters.length; i++) {
        parameterValues[i] = parameters[i].getInitialGuess();
    }
    setParameterValues(parameterValues);
    plotDerivedSimulationResults();
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) Hashtable(java.util.Hashtable) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) Parameter(cbit.vcell.opt.Parameter) WorkflowParameter(org.vcell.workflow.WorkflowParameter) JSlider(javax.swing.JSlider)

Example 19 with JSlider

use of javax.swing.JSlider in project vcell by virtualcell.

the class SurfaceEditor method getOpacityslider.

private JSlider getOpacityslider() {
    if (opacityslider == null) {
        opacityslider = new JSlider();
        opacityslider.setPaintLabels(true);
        opacityslider.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                if (!opacityslider.getValueIsAdjusting()) {
                    updateSurfaceOpacity();
                    getSurfaceCanvas1().repaint();
                }
            }
        });
        opacityslider.setMajorTickSpacing(25);
        opacityslider.setValue(75);
        opacityslider.setPaintTicks(true);
        opacityslider.setOrientation(SwingConstants.VERTICAL);
    }
    return opacityslider;
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener)

Example 20 with JSlider

use of javax.swing.JSlider in project jna by java-native-access.

the class AlphaMaskDemo method run.

public void run() {
    // Must find a graphics configuration with a depth of 32 bits
    GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
    frame = new JFrame("Alpha Mask Demo");
    alphaWindow = new JWindow(frame, gconfig);
    MouseInputAdapter handler = new MouseInputAdapter() {

        private Point offset;

        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e))
                offset = e.getPoint();
        }

        public void mouseReleased(MouseEvent e) {
            offset = null;
            // hit testing; not sure why it gets disabled
            if (System.getProperty("os.name").startsWith("Windows"))
                update(true, true);
        }

        public void mouseDragged(MouseEvent e) {
            if (offset != null) {
                Window w = (Window) e.getSource();
                Point where = e.getPoint();
                where.translate(-offset.x, -offset.y);
                Point loc = w.getLocationOnScreen();
                loc.translate(where.x, where.y);
                w.setLocation(loc.x, loc.y);
            }
        }
    };
    alphaWindow.addMouseListener(handler);
    alphaWindow.addMouseMotionListener(handler);
    JPanel p = new JPanel(new BorderLayout(8, 8));
    p.setBorder(new EmptyBorder(8, 8, 8, 8));
    p.setTransferHandler(new TransferHandler() {

        private static final long serialVersionUID = 1L;

        public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
            List<DataFlavor> list = Arrays.asList(transferFlavors);
            if (list.contains(URL_FLAVOR) || list.contains(URI_LIST_FLAVOR) || list.contains(DataFlavor.imageFlavor) || list.contains(DataFlavor.javaFileListFlavor)) {
                return true;
            }
            if (DataFlavor.selectBestTextFlavor(transferFlavors) != null) {
                return true;
            }
            System.out.println("No acceptable flavor found in " + Arrays.asList(transferFlavors));
            return false;
        }

        public boolean importData(JComponent comp, Transferable t) {
            try {
                if (t.isDataFlavorSupported(URL_FLAVOR)) {
                    URL url = (URL) t.getTransferData(URL_FLAVOR);
                    setImage(Toolkit.getDefaultToolkit().getImage(url));
                    return true;
                }
                if (t.isDataFlavorSupported(URI_LIST_FLAVOR)) {
                    String s = (String) t.getTransferData(URI_LIST_FLAVOR);
                    String[] uris = s.split("[\r\n]");
                    if (uris.length > 0) {
                        URL url = new URL(uris[0]);
                        setImage(Toolkit.getDefaultToolkit().getImage(url));
                        return true;
                    }
                    return false;
                }
                if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                    Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
                    setImage(image);
                    return true;
                }
                if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                    List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
                    File f = files.get(0);
                    URL url = new URL("file://" + f.toURI().toURL().getPath());
                    Image image = Toolkit.getDefaultToolkit().getImage(url);
                    setImage(image);
                    return true;
                }
                DataFlavor flavor = DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors());
                if (flavor != null) {
                    Reader reader = flavor.getReaderForText(t);
                    char[] buf = new char[512];
                    StringBuilder b = new StringBuilder();
                    int count;
                    // encoding wrong
                    while ((count = reader.read(buf)) > 0) {
                        for (int i = 0; i < count; i++) {
                            if (buf[i] != 0)
                                b.append(buf, i, 1);
                        }
                    }
                    String html = b.toString();
                    Pattern p = Pattern.compile("<img.*src=\"([^\\\"\">]+)\"", Pattern.CANON_EQ | Pattern.UNICODE_CASE);
                    Matcher m = p.matcher(html);
                    if (m.find()) {
                        URL url = new URL(m.group(1));
                        System.out.println("Load image from " + url);
                        Image image = Toolkit.getDefaultToolkit().getImage(url);
                        setImage(image);
                        return true;
                    }
                    System.out.println("Can't parse text: " + html);
                    return false;
                }
                System.out.println("No flavor available: " + Arrays.asList(t.getTransferDataFlavors()));
            } catch (UnsupportedFlavorException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Throwable e) {
                e.printStackTrace();
            }
            return false;
        }
    });
    p.add(new JLabel("<html><center>Drop an image with an alpha channel onto this window<br>" + "You may also adjust the overall transparency with the slider</center></html>"), BorderLayout.NORTH);
    final JSlider slider = new JSlider(0, 255, 255);
    slider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            int value = slider.getValue();
            setAlpha(value / 255f);
        }
    });
    p.add(slider, BorderLayout.SOUTH);
    frame.getContentPane().add(p);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    centerOnScreen(frame);
    frame.setVisible(true);
    p.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            update();
        }
    });
    try {
        URL url = getClass().getResource("tardis.png");
        if (url != null) {
            setImage(Toolkit.getDefaultToolkit().getImage(url));
        }
    } catch (Exception e) {
    }
}
Also used : JPanel(javax.swing.JPanel) Matcher(java.util.regex.Matcher) Reader(java.io.Reader) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) URL(java.net.URL) GraphicsConfiguration(java.awt.GraphicsConfiguration) DataFlavor(java.awt.datatransfer.DataFlavor) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JSlider(javax.swing.JSlider) List(java.util.List) ChangeListener(javax.swing.event.ChangeListener) EmptyBorder(javax.swing.border.EmptyBorder) Window(java.awt.Window) JWindow(javax.swing.JWindow) Pattern(java.util.regex.Pattern) MouseEvent(java.awt.event.MouseEvent) JWindow(javax.swing.JWindow) JComponent(javax.swing.JComponent) Transferable(java.awt.datatransfer.Transferable) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Point(java.awt.Point) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) ChangeEvent(javax.swing.event.ChangeEvent) TransferHandler(javax.swing.TransferHandler) File(java.io.File) MouseInputAdapter(javax.swing.event.MouseInputAdapter)

Aggregations

JSlider (javax.swing.JSlider)43 ChangeEvent (javax.swing.event.ChangeEvent)23 ChangeListener (javax.swing.event.ChangeListener)23 JLabel (javax.swing.JLabel)14 JPanel (javax.swing.JPanel)14 JButton (javax.swing.JButton)12 ActionEvent (java.awt.event.ActionEvent)11 ActionListener (java.awt.event.ActionListener)11 GridBagLayout (java.awt.GridBagLayout)8 Dimension (java.awt.Dimension)7 GridBagConstraints (java.awt.GridBagConstraints)7 BorderLayout (java.awt.BorderLayout)6 JCheckBox (javax.swing.JCheckBox)6 JComponent (javax.swing.JComponent)6 JToggleButton (javax.swing.JToggleButton)6 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 JRadioButton (javax.swing.JRadioButton)5 JTextField (javax.swing.JTextField)5 Color (java.awt.Color)4 Point (java.awt.Point)4