Search in sources :

Example 1 with TunableBoundedField

use of org.cytoscape.work.internal.tunables.utils.TunableBoundedField in project cytoscape-impl by cytoscape.

the class BoundedHandler method initPanel.

private void initPanel(T bounded) {
    double min = ((Number) bounded.getLowerBound()).doubleValue();
    double max = ((Number) bounded.getUpperBound()).doubleValue();
    double range = max - min;
    final DecimalFormat format = getDecimalFormat(range);
    final JLabel label = new JLabel();
    if (useSlider) {
        label.setText(title);
        slider = new TunableSlider(title, (Number) bounded.getLowerBound(), (Number) bounded.getUpperBound(), (Number) bounded.getValue(), bounded.isLowerBoundStrict(), bounded.isUpperBoundStrict(), format);
        slider.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                if (!isUpdating)
                    handle();
            }
        });
        updateFieldPanel(panel, label, slider, horizontal);
        panel.validate();
        setTooltip(getTooltip(), label, slider);
    } else {
        // Do something reasonable for max and min...
        // At some point, we should use superscripts for scientific notation...
        label.setText(title + " (max: " + format.format((Number) bounded.getLowerBound()) + " min: " + format.format((Number) bounded.getUpperBound()) + ")");
        boundedField = new TunableBoundedField((Number) bounded.getValue(), (Number) bounded.getLowerBound(), (Number) bounded.getUpperBound(), bounded.isLowerBoundStrict(), bounded.isUpperBoundStrict());
        boundedField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!isUpdating)
                    handle();
            }
        });
        boundedField.addFocusListener(new FocusAdapter() {

            @Override
            public void focusLost(FocusEvent e) {
                if (!isUpdating)
                    handle();
            }
        });
        updateFieldPanel(panel, label, boundedField, horizontal);
        panel.validate();
        setTooltip(getTooltip(), label, boundedField);
    }
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) TunableBoundedField(org.cytoscape.work.internal.tunables.utils.TunableBoundedField) ActionEvent(java.awt.event.ActionEvent) DecimalFormat(java.text.DecimalFormat) JLabel(javax.swing.JLabel) FocusEvent(java.awt.event.FocusEvent) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) BoundedChangeListener(org.cytoscape.work.util.BoundedChangeListener) ChangeListener(javax.swing.event.ChangeListener) TunableSlider(org.cytoscape.work.internal.tunables.utils.TunableSlider)

Example 2 with TunableBoundedField

use of org.cytoscape.work.internal.tunables.utils.TunableBoundedField in project cytoscape-impl by cytoscape.

the class BoundedHandler method update.

@Override
public void update() {
    isUpdating = true;
    try {
        final T bounded = getBounded();
        if (lastBounded != bounded) {
            lastBounded = bounded;
            // Make sure we're the only handler for this Tunable that's listening
            // for changes.  If we're in the middle of a refresh, we can sometimes
            // be in a state where there are two...
            BoundedChangeListener<N> found = null;
            List<BoundedChangeListener<N>> listeners = ((AbstractBounded) lastBounded).getListeners();
            for (BoundedChangeListener<N> listener : listeners) {
                if (listener instanceof AbstractGUITunableHandler && ((AbstractGUITunableHandler) listener).getQualifiedName().equals(this.getQualifiedName()))
                    found = listener;
            }
            if (found != null)
                lastBounded.removeListener(found);
            lastBounded.addListener(this);
            panel.removeAll();
            initPanel(bounded);
        } else {
            if (useSlider) {
                Number n = (Number) bounded.getValue();
                slider.setValue(n);
            } else {
                boundedField = new TunableBoundedField((Number) bounded.getValue(), (Number) bounded.getLowerBound(), (Number) bounded.getUpperBound(), bounded.isLowerBoundStrict(), bounded.isUpperBoundStrict());
            }
        }
    } catch (Exception e) {
        logger.error("Could not update bounded value", e);
    }
    isUpdating = false;
}
Also used : BoundedChangeListener(org.cytoscape.work.util.BoundedChangeListener) TunableBoundedField(org.cytoscape.work.internal.tunables.utils.TunableBoundedField) AbstractBounded(org.cytoscape.work.util.AbstractBounded) AbstractGUITunableHandler(org.cytoscape.work.swing.AbstractGUITunableHandler)

Aggregations

TunableBoundedField (org.cytoscape.work.internal.tunables.utils.TunableBoundedField)2 BoundedChangeListener (org.cytoscape.work.util.BoundedChangeListener)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 FocusAdapter (java.awt.event.FocusAdapter)1 FocusEvent (java.awt.event.FocusEvent)1 DecimalFormat (java.text.DecimalFormat)1 JLabel (javax.swing.JLabel)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1 TunableSlider (org.cytoscape.work.internal.tunables.utils.TunableSlider)1 AbstractGUITunableHandler (org.cytoscape.work.swing.AbstractGUITunableHandler)1 AbstractBounded (org.cytoscape.work.util.AbstractBounded)1