Example usage for javax.swing JScrollBar getValue

List of usage examples for javax.swing JScrollBar getValue

Introduction

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

Prototype

public int getValue() 

Source Link

Document

Returns the scrollbar's value.

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);
        }/*  www.j  a v a  2  s. c  om*/

        @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);
        }//  w  w  w .  ja v  a  2 s  .co 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.swing.GraphPane.java

public boolean render(Graphics2D g2, Range xRange, Range yRange) {
    LOG.trace("GraphPane.render(g2, " + xRange + ", " + yRange + ")");
    double oldUnitHeight = unitHeight;
    int oldYMax = yMax;

    // Paint a gradient from top to bottom
    GradientPaint gp0 = new GradientPaint(0, 0, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_TOP), 0,
            getHeight(), ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_BOTTOM));
    g2.setPaint(gp0);// w  w  w.j av  a2s. c o  m
    g2.fillRect(0, 0, getWidth(), getHeight());

    GraphPaneController gpc = GraphPaneController.getInstance();
    LocationController lc = LocationController.getInstance();
    JScrollBar scroller = getVerticalScrollBar();

    if (gpc.isPanning() && !isLocked()) {

        double fromX = transformXPos(gpc.getMouseClickPosition());
        double toX = transformXPos(gpc.getMouseReleasePosition());
        g2.translate(toX - fromX, 0);
    }

    // Deal with the progress-bar.
    if (tracks == null) {
        parentFrame.updateProgress();
        return false;
    } else {
        for (Track t : tracks) {
            if (t.getRenderer().isWaitingForData()) {
                String progressMsg = (String) t.getRenderer().getInstruction(DrawingInstruction.PROGRESS);
                setPreferredSize(new Dimension(getWidth(), 0));
                showProgress(progressMsg, -1.0);
                return false;
            }
        }
    }
    if (progressPanel != null) {
        remove(progressPanel);
        progressPanel = null;
    }

    int minYRange = Integer.MAX_VALUE;
    int maxYRange = Integer.MIN_VALUE;
    AxisType bestYAxis = AxisType.NONE;
    for (Track t : tracks) {

        // ask renderers for extra info on range; consolidate to maximum Y range
        AxisRange axisRange = (AxisRange) t.getRenderer().getInstruction(DrawingInstruction.AXIS_RANGE);

        if (axisRange != null) {
            int axisYMin = axisRange.getYMin();
            int axisYMax = axisRange.getYMax();
            if (axisYMin < minYRange) {
                minYRange = axisYMin;
            }
            if (axisYMax > maxYRange) {
                maxYRange = axisYMax;
            }
        }

        // Ask renderers if they want horizontal grid-lines; if any say yes, draw them.
        switch (t.getYAxisType(t.getResolution(xRange))) {
        case INTEGER_GRIDLESS:
            if (bestYAxis == AxisType.NONE) {
                bestYAxis = AxisType.INTEGER_GRIDLESS;
            }
            break;
        case INTEGER:
            if (bestYAxis != AxisType.REAL) {
                bestYAxis = AxisType.INTEGER;
            }
            break;
        case REAL:
            bestYAxis = AxisType.REAL;
            break;
        }
    }

    setXAxisType(tracks[0].getXAxisType(tracks[0].getResolution(xRange)));
    setXRange(xRange);
    setYAxisType(bestYAxis);
    Range consolidatedYRange = new Range(minYRange, maxYRange);

    setYRange(consolidatedYRange);
    consolidatedYRange = new Range(yMin, yMax);

    DrawingMode currentMode = tracks[0].getDrawingMode();

    boolean sameRange = (prevRange != null && xRange.equals(prevRange));
    if (!sameRange) {
        PopupPanel.hidePopup();
    }
    boolean sameMode = currentMode == prevMode;
    boolean sameSize = prevSize != null && getSize().equals(prevSize)
            && parentFrame.getFrameLandscape().getWidth() == oldWidth
            && parentFrame.getFrameLandscape().getHeight() == oldHeight;
    boolean sameRef = prevRef != null && lc.getReferenceName().equals(prevRef);
    boolean withinScrollBounds = bufferedImage != null && scroller.getValue() >= getOffset()
            && scroller.getValue() < getOffset() + getViewportHeight() * 2;

    //bufferedImage stores the current graphic for future use. If nothing
    //has changed in the track since the last render, bufferedImage will
    //be used to redraw the current view. This method allows for fast repaints
    //on tracks where nothing has changed (panning, selection, plumbline,...)

    //if nothing has changed draw buffered image
    if (sameRange && sameMode && sameSize && sameRef && !renderRequired && withinScrollBounds) {
        g2.drawImage(bufferedImage, 0, getOffset(), this);
        renderCurrentSelected(g2);

        //force unitHeight from last render
        unitHeight = oldUnitHeight;
        yMax = oldYMax;

    } else {
        // Otherwise prepare for new render.
        renderRequired = false;

        int h = getHeight();
        if (!forcedHeight) {
            h = Math.min(h, getViewportHeight() * 3);
        }
        LOG.debug("Requesting " + getWidth() + "\u00D7" + h + " bufferedImage.");
        bufferedImage = new BufferedImage(getWidth(), h, BufferedImage.TYPE_INT_RGB);
        if (bufferedImage.getHeight() == getHeight()) {
            setOffset(0);
        } else {
            setOffset(scroller.getValue() - getViewportHeight());
        }
        LOG.debug("Rendering fresh " + bufferedImage.getWidth() + "\u00D7" + bufferedImage.getHeight()
                + " bufferedImage at (0, " + getOffset() + ")");

        Graphics2D g3 = bufferedImage.createGraphics();
        g3.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        prevRange = xRange;
        prevSize = getSize();
        prevMode = tracks[0].getDrawingMode();
        prevRef = lc.getReferenceName();

        renderBackground(g3, xAxisType == AxisType.INTEGER || xAxisType == AxisType.REAL,
                yAxisType == AxisType.INTEGER || yAxisType == AxisType.REAL);

        // Call the actual render() methods.
        boolean nothingRendered = true;
        String message = null;
        int priority = -1;

        for (Track t : tracks) {
            // Change renderers' drawing instructions to reflect consolidated YRange
            AxisRange axes = (AxisRange) t.getRenderer().getInstruction(DrawingInstruction.AXIS_RANGE);

            if (axes == null) {
                axes = new AxisRange(xRange, consolidatedYRange);
            } else {
                axes = new AxisRange(axes.getXRange(), consolidatedYRange);
            }

            //System.out.println("Consolidated y range for " + t.getName() + " is " + consolidatedYRange);
            t.getRenderer().addInstruction(DrawingInstruction.AXIS_RANGE, axes);

            try {
                t.getRenderer().render(g3, this);
                nothingRendered = false;
            } catch (RenderingException rx) {
                if (rx.getPriority() > priority) {
                    // If we have more than one message with the same priority, the first one will end up being drawn.
                    message = rx.getMessage();
                    priority = rx.getPriority();
                }
            } catch (Throwable x) {
                // Renderer itself threw an exception.
                LOG.error("Error rendering " + t, x);
                message = MiscUtils.getMessage(x);
                priority = RenderingException.ERROR_PRIORITY;
            }
        }
        if (nothingRendered && message != null) {
            setPreferredSize(new Dimension(getWidth(), 0));
            revalidate();
            drawMessage(g3, message);
        }

        updateYMax();

        // If a change has occured that affects scrollbar...
        if (paneResize) {
            paneResize = false;

            // Change size of current frame
            if (getHeight() != newHeight) {
                Dimension newSize = new Dimension(getWidth(), newHeight);
                setPreferredSize(newSize);
                setSize(newSize);
                parentFrame.validate(); // Ensures that scroller.getMaximum() is up to date.

                // If pane is resized, scrolling always starts at the bottom.  The only place
                // where looks wrong is when we have a continuous track with negative values.
                scroller.setValue(scroller.getMaximum());
                repaint();
                return false;
            }
        } else if (oldViewHeight != -1 && oldViewHeight != getViewportHeight()) {
            int newViewHeight = getViewportHeight();
            int oldScroll = scroller.getValue();
            scroller.setValue(oldScroll + (oldViewHeight - newViewHeight));
            oldViewHeight = newViewHeight;
        }
        oldWidth = parentFrame.getFrameLandscape().getWidth();
        oldHeight = parentFrame.getFrameLandscape().getHeight();

        g2.drawImage(bufferedImage, 0, getOffset(), this);
        fireExportEvent(xRange, bufferedImage);

        renderCurrentSelected(g2);
    }
    return true;
}

From source file:savant.view.swing.GraphPane.java

/**
 * {@inheritDoc}//ww w  .  j ava  2s  .c  o m
 */
@Override
public void mouseWheelMoved(MouseWheelEvent e) {

    int notches = e.getWheelRotation();
    LocationController lc = LocationController.getInstance();

    if (MiscUtils.MAC && e.isMetaDown() || e.isControlDown()) {
        if (notches < 0) {
            lc.shiftRangeLeft();
        } else {
            lc.shiftRangeRight();
        }
    } else {
        if (InterfaceSettings.doesWheelZoom()) {
            if (notches < 0) {
                lc.zoomInOnMouse();
            } else {
                lc.zoomOutFromMouse();
            }
        } else {
            JScrollBar sb = getVerticalScrollBar();
            if (sb.isVisible()) {
                sb.setValue(sb.getValue() + notches * 15);
            }
        }
    }
}