Search in sources :

Example 1 with NumberRangeModel

use of org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel in project cytoscape-impl by cytoscape.

the class FilterSettingPanel method getRangerSlider.

private JRangeSliderExtended getRangerSlider(NumericFilter pFilter) {
    NumberIndex theIndex = createNumberIndex(pFilter);
    if (theIndex != null) {
        pFilter.setIndex(theIndex);
    } else {
    // System.out.println("theIndex == null");
    }
    NumberRangeModel rangeModel = null;
    if (theIndex == null) {
        rangeModel = new NumberRangeModel(0, 0, 0, 0);
    } else {
        Class<?> dataType = getAttributeDataType(pFilter.getNetwork(), pFilter.getControllingAttribute(), pFilter.getIndexType());
        // Initialize the search values, lowBound and highBound
        if (pFilter.getLowBound() == null) {
            pFilter.setLowBound(theIndex.getMinimumValue());
        }
        if (pFilter.getHighBound() == null) {
            pFilter.setHighBound(theIndex.getMaximumValue());
        }
        if (dataType == Double.class) {
            Double lowB = (Double) pFilter.getLowBound();
            Double highB = (Double) pFilter.getHighBound();
            Double min = (Double) theIndex.getMinimumValue();
            Double max = (Double) theIndex.getMaximumValue();
            rangeModel = new NumberRangeModel(lowB.doubleValue(), highB.doubleValue(), min.doubleValue(), max.doubleValue());
        } else if (dataType == Integer.class) {
            rangeModel = new NumberRangeModel(pFilter.getLowBound(), pFilter.getHighBound(), theIndex.getMinimumValue(), theIndex.getMaximumValue());
        }
    }
    JRangeSliderExtended rangeSlider = new JRangeSliderExtended(rangeModel, JRangeSlider.HORIZONTAL, JRangeSlider.LEFTRIGHT_TOPBOTTOM);
    rangeSlider.setMinimumSize(new Dimension(100, 20));
    rangeSlider.setPreferredSize(new Dimension(100, 20));
    RangeSelectionListener rangeSelectionListener = new RangeSelectionListener(rangeSlider);
    rangeSlider.addChangeListener(rangeSelectionListener);
    rangeSlider.setName(pFilter.getControllingAttribute());
    RangeSlideMouseAdapter l = new RangeSlideMouseAdapter();
    rangeSlider.addMouseListener(l);
    MyMouseInputAdapter myMouseInputAdapter = new MyMouseInputAdapter();
    rangeSlider.addMouseMotionListener(myMouseInputAdapter);
    return rangeSlider;
}
Also used : NumberIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.NumberIndex) NumberRangeModel(org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel) JRangeSliderExtended(org.cytoscape.filter.internal.widgets.slider.JRangeSliderExtended) Dimension(java.awt.Dimension)

Example 2 with NumberRangeModel

use of org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel in project cytoscape-impl by cytoscape.

the class PopupDaemon method stateChanged.

/**
 * Upon state change, pop-up a tiny window with low-high.
 *
 * @param e ChangeEvent Object.
 */
public void stateChanged(ChangeEvent e) {
    NumberRangeModel model = (NumberRangeModel) getModel();
    Number low = (Number) model.getLowValue();
    Number high = (Number) model.getHighValue();
    Number min = (Number) model.getMinValue();
    Number max = (Number) model.getMaxValue();
    DecimalFormat format;
    String lowStr = null;
    String highStr = null;
    if (low instanceof Integer) {
        lowStr = Integer.toString((Integer) low);
        highStr = Integer.toString((Integer) high);
    } else {
        if ((max.doubleValue() - min.doubleValue()) < .001) {
            format = new DecimalFormat("0.###E0");
        } else if ((max.doubleValue() - min.doubleValue()) > 100000) {
            format = new DecimalFormat("0.###E0");
        } else {
            format = new DecimalFormat("###,###.000");
        }
        lowStr = format.format(low);
        highStr = format.format(high);
    }
    if (isVisible()) {
        if (popup == null) {
            PopupFactory popupFactory = PopupFactory.getSharedInstance();
            JPanel panel = new JPanel();
            panel.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));
            panel.setPreferredSize(getPreferredSize());
            panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
            popupLow = new JLabel(lowStr);
            popupLow.setBorder(new EmptyBorder(6, 2, 6, 2));
            popupHigh = new JLabel(highStr);
            popupHigh.setBorder(new EmptyBorder(6, 2, 6, 2));
            panel.add(popupLow);
            panel.add(Box.createHorizontalGlue());
            panel.add(popupHigh);
            popup = popupFactory.getPopup(this, panel, getLocationOnScreen().x, getLocationOnScreen().y + getPreferredSize().height + 2);
            popupDaemon = new PopupDaemon(this, 2000);
            popup.show();
            popupDaemon.restart();
        } else {
            popupLow.setText(lowStr);
            popupHigh.setText(highStr);
            popupDaemon.restart();
        }
    }
}
Also used : NumberRangeModel(org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel) DecimalFormat(java.text.DecimalFormat) LineBorder(javax.swing.border.LineBorder) EmptyBorder(javax.swing.border.EmptyBorder)

Example 3 with NumberRangeModel

use of org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel in project cytoscape-impl by cytoscape.

the class FilterSettingPanel method refreshIndicesForWidgets.

// Refresh indices for widget after network switch or Cytoscape.ATTRIBUTES_CHANGED event is received
// The method may be triggered by event of NETWORK_VIEW_FOCUSED
public void refreshIndicesForWidgets() {
    // Check if each widget has associatd index, if not, try to create one
    // System.out.println("FilterSettingpanel:refreshIndicesForWidgets()...\n");
    List<CyFilter> children = theFilter.getChildren();
    if ((children == null) || (children.size() == 0)) {
        return;
    }
    CyNetwork network = applicationManager.getCurrentNetwork();
    for (int i = 0; i < children.size(); i++) {
        CyFilter child = children.get(i);
        if (child instanceof StringFilter) {
            if (pnlCustomSettings.getComponent(i * 5 + 3) instanceof TextIndexComboBox) {
                TextIndexComboBox theBox = (TextIndexComboBox) pnlCustomSettings.getComponent(i * 5 + 3);
                if (network != null) {
                    CyNetworkView networkView = applicationManager.getCurrentNetworkView();
                    if (networkView != null) {
                        TextIndex textIndex = createTextIndex((StringFilter) child);
                        ;
                        if (textIndex != null) {
                            theBox.setTextIndex(textIndex);
                            StringFilter aFilter = (StringFilter) child;
                            aFilter.setIndex(textIndex);
                        }
                    }
                }
            }
        }
        if (child instanceof NumericFilter) {
            if (pnlCustomSettings.getComponent(i * 5 + 3) instanceof JRangeSliderExtended) {
                JRangeSliderExtended theSlider = (JRangeSliderExtended) pnlCustomSettings.getComponent(i * 5 + 3);
                if (network != null) {
                    CyNetworkView networkView = applicationManager.getCurrentNetworkView();
                    if (networkView != null) {
                        NumberIndex numIndex = createNumberIndex((NumericFilter) child);
                        ;
                        if (numIndex != null) {
                            NumberRangeModel rangeModel = (NumberRangeModel) theSlider.getModel();
                            rangeModel.setMinValue(numIndex.getMinimumValue());
                            rangeModel.setMaxValue(numIndex.getMaximumValue());
                            NumericFilter aFilter = (NumericFilter) child;
                            aFilter.setIndex(numIndex);
                        }
                    }
                }
            }
        }
    }
}
Also used : CyFilter(org.cytoscape.filter.internal.filters.model.CyFilter) TextIndexComboBox(org.cytoscape.filter.internal.widgets.autocomplete.view.TextIndexComboBox) NumberIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.NumberIndex) TextIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.TextIndex) NumericFilter(org.cytoscape.filter.internal.filters.model.NumericFilter) NumberRangeModel(org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel) CyNetwork(org.cytoscape.model.CyNetwork) StringFilter(org.cytoscape.filter.internal.filters.model.StringFilter) JRangeSliderExtended(org.cytoscape.filter.internal.widgets.slider.JRangeSliderExtended) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 4 with NumberRangeModel

use of org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel in project cytoscape-impl by cytoscape.

the class RangeSelectionListener method stateChanged.

/**
 * State Change Event.
 *
 * @param e ChangeEvent Object.
 */
public void stateChanged(ChangeEvent e) {
    final CyNetwork cyNetwork = applicationManager.getCurrentNetwork();
    GenericIndex index = quickFind.getIndex(cyNetwork);
    NumberRangeModel model = (NumberRangeModel) slider.getModel();
    if (slider.isVisible()) {
        if (index instanceof NumberIndex) {
            Number lowValue = (Number) model.getLowValue();
            Number highValue = (Number) model.getHighValue();
            quickFind.selectRange(cyNetwork, lowValue, highValue);
        }
    }
}
Also used : GenericIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex) NumberIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.NumberIndex) NumberRangeModel(org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel) CyNetwork(org.cytoscape.model.CyNetwork)

Aggregations

NumberRangeModel (org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel)4 NumberIndex (org.cytoscape.filter.internal.widgets.autocomplete.index.NumberIndex)3 JRangeSliderExtended (org.cytoscape.filter.internal.widgets.slider.JRangeSliderExtended)2 CyNetwork (org.cytoscape.model.CyNetwork)2 Dimension (java.awt.Dimension)1 DecimalFormat (java.text.DecimalFormat)1 EmptyBorder (javax.swing.border.EmptyBorder)1 LineBorder (javax.swing.border.LineBorder)1 CyFilter (org.cytoscape.filter.internal.filters.model.CyFilter)1 NumericFilter (org.cytoscape.filter.internal.filters.model.NumericFilter)1 StringFilter (org.cytoscape.filter.internal.filters.model.StringFilter)1 GenericIndex (org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex)1 TextIndex (org.cytoscape.filter.internal.widgets.autocomplete.index.TextIndex)1 TextIndexComboBox (org.cytoscape.filter.internal.widgets.autocomplete.view.TextIndexComboBox)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1