List of usage examples for javax.swing BoundedRangeModel addChangeListener
void addChangeListener(ChangeListener x);
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.setValue(1);//from w w w. j av a 2 s . c o m JFrame frame = new JFrame("ScrollBars R Us"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(anotherJScrollBar, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
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); System.out.println(model.getValueIsAdjusting()); JFrame frame = new JFrame("ScrollBars R Us"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(anotherJScrollBar, BorderLayout.NORTH); frame.setSize(300, 200);/*w w w. ja v a2s . c o m*/ frame.setVisible(true); }
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.setMaximum(10);// w w w . j av a 2s . com JFrame frame = new JFrame("ScrollBars R Us"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(anotherJScrollBar, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSlider slider = new JSlider(); BoundedRangeModel model = slider.getModel(); model.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { BoundedRangeModel m = (BoundedRangeModel) e.getSource(); System.out.println("Slider position changed to " + m.getValue()); }//from w w w . ja va 2 s .com }); getContentPane().add(slider); pack(); }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
private void recalcScrollBar(Plot plot) { if (plot instanceof XYPlot) { XYPlot hvp = (XYPlot) plot;/*from w w w . j a v a2 s . co m*/ ValueAxis axis = hvp.getDomainAxis(); axis.setLowerMargin(0); axis.setUpperMargin(0); Range rng = axis.getRange(); BoundedRangeModel scrollBarModel = this.chartScrollBar.getModel(); int len = scrollBarModel.getMaximum() - scrollBarModel.getMinimum(); if (rng.getLength() > 0) { scrollFactor = len / rng.getLength(); } double dblow = rng.getLowerBound(); int ilow = (int) (dblow * scrollFactor); scrollBarModel.setMinimum(ilow); int val = ilow; scrollBarModel.setValue(val); double dbup = rng.getUpperBound(); int iup = (int) (dbup * scrollFactor); scrollBarModel.setMaximum(iup); int ext = iup - ilow; scrollBarModel.setExtent(ext); scrollBarModel.addChangeListener(this); } }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
public void chartChanged(ChartChangeEvent event) { try {/*from w ww .j a v a 2 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
/** * Recalculates the scrollbar settings.//from w w w . j av a 2 s .co m * * @param plot the plot. */ private void recalcScrollBar(final Plot plot) { if (plot instanceof XYPlot) { final XYPlot hvp = (XYPlot) plot; final ValueAxis axis = hvp.getDomainAxis(); axis.setLowerMargin(0); axis.setUpperMargin(0); final Range rng = axis.getRange(); final BoundedRangeModel scrollBarModel = this.scrollBar.getModel(); final int len = scrollBarModel.getMaximum() - scrollBarModel.getMinimum(); if (rng.getLength() > 0) { this.scrollFactor = len / rng.getLength(); } final double dblow = rng.getLowerBound(); final int ilow = (int) (dblow * this.scrollFactor); scrollBarModel.setMinimum(ilow); final int val = ilow; scrollBarModel.setValue(val); final double dbup = rng.getUpperBound(); final int iup = (int) (dbup * this.scrollFactor); scrollBarModel.setMaximum(iup); final int ext = iup - ilow; scrollBarModel.setExtent(ext); scrollBarModel.addChangeListener(this); } }
From source file:apidemo.PanScrollZoomDemo.java
/** * Handles a {@link ChartChangeEvent}./*from w ww .j a v a 2 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);/* w w w .ja va 2s . c o 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
private void setSlider(final BoundedRangeModel s) { slider.setVisible(s != null);/*from w w w . j ava 2s . c o m*/ if (s == null) return; s.addChangeListener(this); adjustSlider(s); }