Example usage for javax.swing BoundedRangeModel removeChangeListener

List of usage examples for javax.swing BoundedRangeModel removeChangeListener

Introduction

In this page you can find the example usage for javax.swing BoundedRangeModel removeChangeListener.

Prototype

void removeChangeListener(ChangeListener x);

Source Link

Document

Removes a ChangeListener from the model's listener list.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {
    ChangeListener changeListener = new BoundedChangeListener();
    JScrollBar anotherJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
    BoundedRangeModel model = anotherJScrollBar.getModel();
    model.addChangeListener(changeListener);
    model.removeChangeListener(changeListener);

    JFrame frame = new JFrame("ScrollBars R Us");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(anotherJScrollBar, BorderLayout.NORTH);

    frame.setSize(300, 200);/*from  www  .jav a  2s . c om*/
    frame.setVisible(true);
}

From source file:Sketch.java

public void setModel(BoundedRangeModel m) {
    BoundedRangeModel old = model;
    if (old != null)
        old.removeChangeListener(this);

    if (m == null)
        model = new DefaultBoundedRangeModel();
    else/* w  ww. ja  v  a2 s  . c om*/
        model = m;
    model.addChangeListener(this);

    firePropertyChange("model", old, model);
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

public void chartChanged(ChartChangeEvent event) {
    try {/*  w  ww. j av a2  s  .  c o m*/
        if (event.getChart() == null) {
            return;
        }

        BoundedRangeModel scrollBarModel = this.chartScrollBar.getModel();
        if (scrollBarModel == null) {
            return;
        }

        boolean chartIsZoomed = false;

        Plot plot = event.getChart().getPlot();
        if (plot instanceof XYPlot) {
            XYPlot hvp = (XYPlot) plot;
            ValueAxis xAxis = hvp.getDomainAxis();
            Range xAxisRange = xAxis.getRange();

            // avoid recursion
            scrollBarModel.removeChangeListener(this);

            int low = (int) (xAxisRange.getLowerBound() * scrollFactor);
            scrollBarModel.setValue(low);
            int ext = (int) (xAxisRange.getUpperBound() * scrollFactor - low);
            scrollBarModel.setExtent(ext);

            // restore
            scrollBarModel.addChangeListener(this);

            // check if zoomed horizontally
            //Range hdr = hvp.getHorizontalDataRange(xAxis);
            Range hdr = hvp.getDataRange(xAxis);

            double len = hdr == null ? 0 : hdr.getLength();
            chartIsZoomed |= xAxisRange.getLength() < len;
        }

        if (!chartIsZoomed && plot instanceof XYPlot) {
            // check if zoomed vertically
            XYPlot vvp = (XYPlot) plot;
            ValueAxis yAxis = vvp.getRangeAxis();
            if (yAxis != null) {
                chartIsZoomed = yAxis.getLowerBound() > yMin || yAxis.getUpperBound() < yMax;
            }
        }

        // enable "zoom-out-buttons" if chart is zoomed
        // otherwise disable them
        chartPanButton.setEnabled(chartIsZoomed);
        chartZoomOutButton.setEnabled(chartIsZoomed);
        chartFitButton.setEnabled(chartIsZoomed);
        chartScrollBar.setEnabled(chartIsZoomed);
        if (!chartIsZoomed) {
            setPanMode(false);
            chartZoomButton.setSelected(true);
        }
    } catch (Exception e) {
        MsgBox.error(e.getMessage());
    }
}

From source file:apidemo.PanScrollZoomDemo.java

/**
 * Handles a {@link ChartChangeEvent}./*from ww w  .  ja v  a2  s. c  o m*/
 * 
 * @param event  the event.
 */
public void chartChanged(final ChartChangeEvent event) {
    try {
        if (event.getChart() == null) {
            return;
        }

        final BoundedRangeModel scrollBarModel = this.scrollBar.getModel();
        if (scrollBarModel == null) {
            return;
        }

        boolean chartIsZoomed = false;

        final Plot plot = event.getChart().getPlot();
        if (plot instanceof XYPlot) {
            final XYPlot hvp = (XYPlot) plot;
            final ValueAxis xAxis = hvp.getDomainAxis();
            final Range xAxisRange = xAxis.getRange();

            // avoid recursion
            scrollBarModel.removeChangeListener(this);

            final int low = (int) (xAxisRange.getLowerBound() * this.scrollFactor);
            scrollBarModel.setValue(low);
            final int ext = (int) (xAxisRange.getUpperBound() * this.scrollFactor - low);
            scrollBarModel.setExtent(ext);

            // restore
            scrollBarModel.addChangeListener(this);

            // check if zoomed horizontally
            //Range hdr = hvp.getHorizontalDataRange(xAxis);
            final Range hdr = hvp.getDataRange(xAxis);

            final double len = hdr == null ? 0 : hdr.getLength();
            chartIsZoomed |= xAxisRange.getLength() < len;
        }

        if (!chartIsZoomed && plot instanceof XYPlot) {
            // check if zoomed vertically
            final XYPlot vvp = (XYPlot) plot;
            ValueAxis yAxis = vvp.getRangeAxis();
            if (yAxis != null) {
                chartIsZoomed = yAxis.getLowerBound() > this.primYMinMax[0]
                        || yAxis.getUpperBound() < this.primYMinMax[1];

                // right y-axis
                if (!chartIsZoomed && plot instanceof XYPlot) {
                    final XYPlot xyPlot = (XYPlot) plot;
                    yAxis = xyPlot.getRangeAxis(1);
                    if (yAxis != null) {
                        chartIsZoomed = yAxis.getLowerBound() > this.secondYMinMax[0]
                                || yAxis.getUpperBound() < this.secondYMinMax[1];
                    }
                }
            }
        }

        // enable "zoom-out-buttons" if chart is zoomed
        // otherwise disable them
        this.panButton.setEnabled(chartIsZoomed);
        this.zoomOutButton.setEnabled(chartIsZoomed);
        this.fitButton.setEnabled(chartIsZoomed);
        this.scrollBar.setEnabled(chartIsZoomed);
        if (!chartIsZoomed) {
            setPanMode(false);
            this.zoomButton.setSelected(true);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.jcurl.demo.tactics.sg.BroomPromptScenario.java

public void propertyChange(final PropertyChangeEvent evt) {
    if (evt.getSource() == model) {
        if ("idx16".equals(evt.getPropertyName()))
            syncIndexM2V((Integer) evt.getNewValue(), pie);
        else if ("outTurn".equals(evt.getPropertyName()))
            syncHandleM2V((Boolean) evt.getNewValue(), handle);
        else if ("broom".equals(evt.getPropertyName()))
            syncBroomM2V((Point2D) evt.getNewValue(), scene);
        else if ("splitTimeMillis".equals(evt.getPropertyName())) {
            final BoundedRangeModel os = (BoundedRangeModel) evt.getOldValue();
            if (os != null)
                os.removeChangeListener(this);
            final BoundedRangeModel ns = (BoundedRangeModel) evt.getNewValue();
            if (ns != null)
                ns.addChangeListener(this);
            syncSpeedM2V(ns);//from   w  w  w. j a v  a  2s.co  m
        } else
            log.info(evt.getPropertyName() + " " + evt.getSource());
    } else
        log.warn("Unconsumed event from " + evt.getSource());
}

From source file:org.jcurl.zui.piccolo.BroomPromptSimple.java

public void propertyChange(final PropertyChangeEvent evt) {
    log.debug(evt.getPropertyName());/*w  ww  .  j a v  a 2 s.c  o  m*/
    if ("broom".equals(evt.getPropertyName()))
        setBroom((Point2D) evt.getNewValue());
    else if ("idx16".equals(evt.getPropertyName()))
        setIdx16((Integer) evt.getNewValue());
    else if ("outTurn".equals(evt.getPropertyName()))
        setOutTurn((Boolean) evt.getNewValue());
    else if ("splitTimeMillis".equals(evt.getPropertyName())) {
        final BoundedRangeModel os = (BoundedRangeModel) evt.getOldValue();
        if (os != null)
            os.removeChangeListener(this);
        setSlider((BoundedRangeModel) evt.getNewValue());
    }
}