Search in sources :

Example 1 with AdjustmentListener

use of java.awt.event.AdjustmentListener in project frostwire by frostwire.

the class AbstractLibraryTableMediator method getScrolledTablePane.

@Override
protected JComponent getScrolledTablePane() {
    JComponent comp = super.getScrolledTablePane();
    if (adjustmentListener == null) {
        adjustmentListener = new AdjustmentListener() {

            public void adjustmentValueChanged(AdjustmentEvent e) {
                adjustmentListener_adjustmentValueChanged(e);
            }
        };
        SCROLL_PANE.getVerticalScrollBar().addAdjustmentListener(adjustmentListener);
    }
    return comp;
}
Also used : AdjustmentEvent(java.awt.event.AdjustmentEvent) AdjustmentListener(java.awt.event.AdjustmentListener)

Example 2 with AdjustmentListener

use of java.awt.event.AdjustmentListener in project jdk8u_jdk by JetBrains.

the class JScrollBar method fireAdjustmentValueChanged.

/**
     * Notify listeners that the scrollbar's model has changed.
     *
     * @see #addAdjustmentListener
     * @see EventListenerList
     */
private void fireAdjustmentValueChanged(int id, int type, int value, boolean isAdjusting) {
    Object[] listeners = listenerList.getListenerList();
    AdjustmentEvent e = null;
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == AdjustmentListener.class) {
            if (e == null) {
                e = new AdjustmentEvent(this, id, type, value, isAdjusting);
            }
            ((AdjustmentListener) listeners[i + 1]).adjustmentValueChanged(e);
        }
    }
}
Also used : AdjustmentEvent(java.awt.event.AdjustmentEvent) AdjustmentListener(java.awt.event.AdjustmentListener)

Example 3 with AdjustmentListener

use of java.awt.event.AdjustmentListener in project sirix by sirixdb.

the class TextView method addAdjustmentListener.

/**
 * Add an {@link AdjustmentListener} which handles addition of text once
 * scrolled.
 */
private void addAdjustmentListener() {
    final JScrollBar vertScrollBar = getVerticalScrollBar();
    vertScrollBar.setValue(vertScrollBar.getMinimum());
    if (vertScrollBar.getAdjustmentListeners().length == 0) {
        vertScrollBar.addAdjustmentListener(new AdjustmentListener() {

            @Override
            public void adjustmentValueChanged(final AdjustmentEvent pEvt) {
                /*
					 * getValueIsAdjusting() returns true if the user is currently
					 * dragging the scrollbar's knob and has not picked a final value.
					 */
                if (pEvt.getValueIsAdjusting()) {
                    // The user is dragging the knob.
                    return;
                }
                final int lineHeight = mText.getFontMetrics(mText.getFont()).getHeight();
                final int value = pEvt.getValue();
                final int result = value - mTempValue;
                mLineChanges = result / lineHeight;
                LOGWRAPPER.debug("line changes: " + mLineChanges);
                if (mLineChanges > 0) {
                    try {
                        mLineChanges += 5;
                        processStAX(State.UPDATE);
                    } catch (final XMLStreamException | BadLocationException e) {
                        LOGWRAPPER.error(e.getMessage(), e);
                    }
                }
                mTempValue = value;
            }
        });
    }
}
Also used : AdjustmentEvent(java.awt.event.AdjustmentEvent) AdjustmentListener(java.awt.event.AdjustmentListener) JScrollBar(javax.swing.JScrollBar)

Example 4 with AdjustmentListener

use of java.awt.event.AdjustmentListener in project TrakEM2 by trakem2.

the class Display3DGUI method newPanelColors.

private static final JPanel newPanelColors(final Image3DUniverse univ) {
    final JPanel p = new JPanel();
    p.setBackground(Color.white);
    final GridBagLayout gb = new GridBagLayout();
    final GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.NORTHWEST;
    c.fill = GridBagConstraints.HORIZONTAL;
    p.setLayout(gb);
    final String[] labels = new String[] { "Red", "Green", "Blue" };
    final JScrollBar[] sliders = new JScrollBar[3];
    final JTextField[] typers = new JTextField[3];
    for (int i = 0; i < 3; ++i) {
        final JScrollBar slider = new JScrollBar(JScrollBar.HORIZONTAL, 255, 1, 0, 256);
        sliders[i] = slider;
        final JTextField typer = new IntegerField(255, 3);
        typers[i] = typer;
        final int k = i;
        slider.addAdjustmentListener(new AdjustmentListener() {

            @Override
            public void adjustmentValueChanged(final AdjustmentEvent e) {
                final Content content = univ.getSelected();
                if (null == content) {
                    Utils.log("Nothing selected!");
                    return;
                }
                Color3f color = content.getColor();
                // default to yellow
                if (null == color)
                    color = new Color3f(1, 1, 0);
                final float[] co = new float[3];
                color.get(co);
                co[k] = e.getValue() / 255.0f;
                content.setColor(new Color3f(co));
                typer.setText(Integer.toString(e.getValue()));
            }
        });
        typer.addKeyListener(new SliderTyperLink(univ, slider, typer));
        final JLabel l = new JLabel(labels[i]);
        // Layout
        c.gridx = 0;
        c.gridy = i;
        gb.setConstraints(l, c);
        p.add(l);
        c.gridx = 1;
        c.weightx = 1;
        c.fill = GridBagConstraints.HORIZONTAL;
        gb.setConstraints(slider, c);
        p.add(slider);
        c.gridx = 2;
        c.weightx = 0;
        c.fill = GridBagConstraints.NONE;
        gb.setConstraints(typer, c);
        p.add(typer);
    }
    // Alpha slider
    c.gridx = 0;
    c.gridy += 1;
    final JLabel aL = new JLabel("Alpha:");
    gb.setConstraints(aL, c);
    p.add(aL);
    c.gridx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    final JScrollBar alphaSlider = new JScrollBar(JScrollBar.HORIZONTAL, 255, 1, 0, 256);
    gb.setConstraints(alphaSlider, c);
    p.add(alphaSlider);
    c.gridx = 2;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    final JTextField alphaTyper = new IntegerField(255, 3);
    gb.setConstraints(alphaTyper, c);
    p.add(alphaTyper);
    alphaSlider.addAdjustmentListener(new AdjustmentListener() {

        @Override
        public void adjustmentValueChanged(final AdjustmentEvent e) {
            final Content content = univ.getSelected();
            if (null == content) {
                Utils.log("Nothing selected!");
                return;
            }
            final float alpha = e.getValue() / 255.0f;
            content.setTransparency(1 - alpha);
            alphaTyper.setText(Integer.toString(e.getValue()));
        }
    });
    alphaTyper.addKeyListener(new SliderTyperLink(univ, alphaSlider, alphaTyper));
    // Button to colorize randomly
    c.gridx = 0;
    c.gridy += 1;
    c.gridwidth = 3;
    c.weightx = 1;
    c.insets = new Insets(15, 4, 4, 4);
    final JButton r = new JButton("Assign random colors to all");
    r.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            randomizeColors(univ);
        }
    });
    gb.setConstraints(r, c);
    p.add(r);
    addTitledLineBorder(p, "Colors");
    univ.addUniverseListener(new UniverseListener() {

        @Override
        public void universeClosed() {
        }

        @Override
        public void transformationUpdated(final View arg0) {
        }

        @Override
        public void transformationStarted(final View arg0) {
        }

        @Override
        public void transformationFinished(final View arg0) {
        }

        @Override
        public void contentSelected(final Content arg0) {
            if (null == arg0) {
                return;
            }
            Color3f color = arg0.getColor();
            // default to yellow
            if (null == color)
                color = new Color3f(1, 1, 0);
            final float[] co = new float[3];
            color.get(co);
            for (int i = 0; i < 3; ++i) {
                // Disallow the slider from firing an event when its value is adjusted
                sliders[i].setValueIsAdjusting(true);
                final int val = (int) (co[i] * 255);
                typers[i].setText(Integer.toString(val));
                sliders[i].setValue(val);
            }
            // After all are set, re-enable, which triggers events (the color will be set three times...)
            for (int i = 0; i < 3; ++i) {
                sliders[i].setValueIsAdjusting(false);
            }
            // Alpha slider:
            alphaSlider.setValueIsAdjusting(true);
            final int alpha = (int) ((1 - arg0.getTransparency()) * 255);
            alphaTyper.setText(Integer.toString(alpha));
            alphaSlider.setValue(alpha);
            alphaSlider.setValueIsAdjusting(false);
        }

        @Override
        public void contentRemoved(final Content arg0) {
        }

        @Override
        public void contentChanged(final Content arg0) {
            if (arg0 == univ.getSelected()) {
                contentSelected(arg0);
            }
        }

        @Override
        public void contentAdded(final Content arg0) {
        }

        @Override
        public void canvasResized() {
        }
    });
    return p;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) AdjustmentEvent(java.awt.event.AdjustmentEvent) Color3f(org.scijava.vecmath.Color3f) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) IntegerField(ini.trakem2.utils.IntegerField) JTextField(javax.swing.JTextField) UniverseListener(ij3d.UniverseListener) View(org.scijava.java3d.View) JScrollBar(javax.swing.JScrollBar) ActionListener(java.awt.event.ActionListener) Content(ij3d.Content) AdjustmentListener(java.awt.event.AdjustmentListener)

Example 5 with AdjustmentListener

use of java.awt.event.AdjustmentListener in project OsmAnd-tools by osmandapp.

the class JScrollPopupMenu method getScrollBar.

protected JScrollBar getScrollBar() {
    if (popupScrollBar == null) {
        popupScrollBar = new JScrollBar(JScrollBar.VERTICAL);
        popupScrollBar.addAdjustmentListener(new AdjustmentListener() {

            @Override
            public void adjustmentValueChanged(AdjustmentEvent e) {
                doLayout();
                repaint();
            }
        });
        popupScrollBar.setVisible(true);
    }
    return popupScrollBar;
}
Also used : AdjustmentEvent(java.awt.event.AdjustmentEvent) AdjustmentListener(java.awt.event.AdjustmentListener) JScrollBar(javax.swing.JScrollBar)

Aggregations

AdjustmentEvent (java.awt.event.AdjustmentEvent)9 AdjustmentListener (java.awt.event.AdjustmentListener)9 JScrollBar (javax.swing.JScrollBar)3 BorderLayout (java.awt.BorderLayout)2 JPanel (javax.swing.JPanel)2 JScrollPane (javax.swing.JScrollPane)2 ActionEvent (com.codename1.ui.events.ActionEvent)1 Content (ij3d.Content)1 UniverseListener (ij3d.UniverseListener)1 IntegerField (ini.trakem2.utils.IntegerField)1 Container (java.awt.Container)1 Dimension (java.awt.Dimension)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 WeakReference (java.lang.ref.WeakReference)1