Search in sources :

Example 1 with AbstractGUITunableHandler

use of org.cytoscape.work.swing.AbstractGUITunableHandler 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)

Example 2 with AbstractGUITunableHandler

use of org.cytoscape.work.swing.AbstractGUITunableHandler in project cytoscape-impl by cytoscape.

the class JPanelTunableMutator method updateTunableFieldPanelMargins.

private void updateTunableFieldPanelMargins() {
    synchronized (lock) {
        if (updatingMargins || handlers == null)
            return;
        updatingMargins = true;
        int maxLeftWidth = 0, maxRightWidth = 0;
        boolean updateMargins = false;
        try {
            // 1st Pass: Get max left/right margin values if vertical form
            for (GUITunableHandler gh : handlers) {
                if (gh instanceof AbstractGUITunableHandler && !((AbstractGUITunableHandler) gh).isHorizontal()) {
                    final JPanel p = gh.getJPanel();
                    if (p instanceof TunableFieldPanel) {
                        updateMargins = true;
                        final TunableFieldPanel tfp = (TunableFieldPanel) p;
                        final JComponent label = tfp.getLabel() != null ? tfp.getLabel() : tfp.getMultiLineLabel();
                        final Component control = tfp.getControl();
                        if (label != null)
                            maxLeftWidth = Math.max(maxLeftWidth, label.getPreferredSize().width);
                        if (control != null)
                            maxRightWidth = Math.max(maxRightWidth, control.getPreferredSize().width);
                    }
                }
            }
            if (updateMargins) {
                // 2nd Pass: Use empty borders to properly align all fields and labels
                for (GUITunableHandler gh : handlers) {
                    final JPanel p = gh.getJPanel();
                    if (p instanceof TunableFieldPanel) {
                        // Update panel's left/right margin by setting an empty border
                        final TunableFieldPanel tfp = (TunableFieldPanel) p;
                        final JComponent label = tfp.getLabel() != null ? tfp.getLabel() : tfp.getMultiLineLabel();
                        final Component control = tfp.getControl();
                        if (control != null)
                            control.removeComponentListener(controlComponentListener);
                        int left = label == null ? 0 : maxLeftWidth - label.getPreferredSize().width;
                        int right = control == null ? 0 : maxRightWidth - control.getPreferredSize().width;
                        // TODO Do not set top/bottom
                        tfp.setBorder(BorderFactory.createEmptyBorder(2, left, 2, right));
                        // Also notify all dependents
                        gh.notifyDependents();
                        if (control != null)
                            control.addComponentListener(controlComponentListener);
                    }
                }
                repackEnclosingDialog(panelMap.get(handlers));
            }
        } finally {
            updatingMargins = false;
        }
    }
}
Also used : JPanel(javax.swing.JPanel) TunableFieldPanel(org.cytoscape.work.swing.AbstractGUITunableHandler.TunableFieldPanel) AbstractGUITunableHandler(org.cytoscape.work.swing.AbstractGUITunableHandler) GUITunableHandler(org.cytoscape.work.swing.GUITunableHandler) JComponent(javax.swing.JComponent) JComponent(javax.swing.JComponent) Component(java.awt.Component) AbstractGUITunableHandler(org.cytoscape.work.swing.AbstractGUITunableHandler)

Aggregations

AbstractGUITunableHandler (org.cytoscape.work.swing.AbstractGUITunableHandler)2 Component (java.awt.Component)1 JComponent (javax.swing.JComponent)1 JPanel (javax.swing.JPanel)1 TunableBoundedField (org.cytoscape.work.internal.tunables.utils.TunableBoundedField)1 TunableFieldPanel (org.cytoscape.work.swing.AbstractGUITunableHandler.TunableFieldPanel)1 GUITunableHandler (org.cytoscape.work.swing.GUITunableHandler)1 AbstractBounded (org.cytoscape.work.util.AbstractBounded)1 BoundedChangeListener (org.cytoscape.work.util.BoundedChangeListener)1