Example usage for javax.swing JScrollBar repaint

List of usage examples for javax.swing JScrollBar repaint

Introduction

In this page you can find the example usage for javax.swing JScrollBar repaint.

Prototype

public void repaint() 

Source Link

Document

Repaints this component.

Usage

From source file:lcmc.common.ui.ResourceGraph.java

protected final ViewScalingControl getScalingControl() {
    return new ViewScalingControl() {
        void superScale(final VisualizationServer thisVV, final float amount, final Point2D from) {
            super.scale(thisVV, amount, from);
        }/* w w w . j av a2  s. com*/

        @Override
        public void scale(final VisualizationServer vv, final float amount, final Point2D from) {
            final JScrollBar sbV = getScrollPane().getVerticalScrollBar();
            final JScrollBar sbH = getScrollPane().getHorizontalScrollBar();
            swingUtils.invokeLater(new Runnable() {
                @Override
                public void run() {
                    final Point2D prevPoint = getVisualizationViewer().getRenderContext()
                            .getMultiLayerTransformer().inverseTransform(Layer.VIEW, from);
                    final double scaledSoFar0 = getScaledSoFar();
                    float am = amount;
                    if (am < 1) {
                        if (scaledSoFar0 < 0.3) {
                            am = 1;
                        } else {
                            superScale(vv, 1 / am, new Point2D.Double(0, 0));
                        }
                    } else if (am > 1) {
                        if (scaledSoFar0 > 5) {
                            am = 1;
                        } else {
                            superScale(vv, 1 / am, new Point2D.Double(0, 0));
                        }
                    }
                    setScaledSoFar(scaledSoFar0 * am);
                    final Point2D p2 = getVisualizationViewer().getRenderContext().getMultiLayerTransformer()
                            .inverseTransform(Layer.VIEW, from);
                    final int valueY = (int) (sbV.getValue() + prevPoint.getY() - p2.getY());
                    sbV.setValue(valueY);
                    sbV.repaint();
                    final int valueX = (int) (sbH.getValue() + prevPoint.getX() - p2.getX());
                    sbH.setValue(valueX);
                    sbH.repaint();

                    vv.repaint();
                }
            });
        }
    };
}

From source file:lcmc.gui.ResourceGraph.java

/** Scale function. */
protected final ViewScalingControl getScalingControl() {
    return new ViewScalingControl() {
        void superScale(final VisualizationServer thisVV, final float amount, final Point2D from) {
            super.scale(thisVV, amount, from);
        }/*from w ww.  jav  a 2  s .  c  o  m*/

        @Override
        public void scale(final VisualizationServer thisVV, final float amount, final Point2D from) {
            final JScrollBar sbV = getScrollPane().getVerticalScrollBar();
            final JScrollBar sbH = getScrollPane().getHorizontalScrollBar();
            final Point2D last = posWithScrollbar(getLastPosition());
            final double fromX = from.getX() < last.getX() ? from.getX() : last.getX();
            final double fromY = from.getY() < last.getY() ? from.getY() : last.getY();
            final double width = getVisualizationViewer().getSize().getWidth();
            final double height = getVisualizationViewer().getSize().getHeight();
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    final Point2D prevPoint = getVisualizationViewer().getRenderContext()
                            .getMultiLayerTransformer().inverseTransform(Layer.VIEW, from);
                    final double scaledSoFar = getScaledSoFar();
                    float am = amount;
                    if (am < 1) {
                        if (scaledSoFar < 0.3) {
                            am = 1;
                        } else {
                            superScale(thisVV, 1 / am, new Point2D.Double(0, 0));
                        }
                    } else if (am > 1) {
                        if (scaledSoFar > 5) {
                            am = 1;
                        } else {
                            superScale(thisVV, 1 / am, new Point2D.Double(0, 0));
                        }
                    }
                    setScaledSoFar(scaledSoFar * am);
                    final Point2D p2 = getVisualizationViewer().getRenderContext().getMultiLayerTransformer()
                            .inverseTransform(Layer.VIEW, from);
                    final int valueY = (int) (sbV.getValue() + prevPoint.getY() - p2.getY());
                    sbV.setValue(valueY);
                    sbV.repaint();
                    final int valueX = (int) (sbH.getValue() + prevPoint.getX() - p2.getX());
                    sbH.setValue(valueX);
                    sbH.repaint();

                    thisVV.repaint();
                }
            });
        }
    };
}

From source file:savant.view.variation.swing.VariationModule.java

public void visibleRangeChanged(String ref, Range r) {
    if (r.getLength() > ResolutionSettings.getVariantLowToHighThreshold()) {
        showMessage(ZOOM_MESSAGE);// w  w  w.j  a va  2 s  .  co m
    } else {
        try {
            // Detach the adjustment listeners so that setting the maximum doesn't fire an event.
            for (JScrollBar sb : scrollers) {
                sb.removeAdjustmentListener(scrollerListener);
            }

            for (JScrollBar sb : scrollers) {
                sb.setMaximum(LocationController.getInstance().getMaxRangeEnd());
                sb.setValue(r.getFrom());
                sb.setVisibleAmount(r.getLength());
                sb.setBlockIncrement(r.getLength());
                sb.repaint();
            }
        } finally {
            // Reattach the adjustment listeners.
            for (JScrollBar sb : scrollers) {
                sb.addAdjustmentListener(scrollerListener);
            }
        }
    }
    rangeField.setText(String.format("%s:%d-%d", ref, r.getFrom(), r.getTo()));
}