Example usage for javax.swing JScrollBar getMaximum

List of usage examples for javax.swing JScrollBar getMaximum

Introduction

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

Prototype

public int getMaximum() 

Source Link

Document

The maximum value of the scrollbar is maximum - extent.

Usage

From source file:org.openmicroscopy.shoola.agents.dataBrowser.browser.BrowserModel.java

/**
 * Implemented as specified by the {@link Browser} interface.
 * @see Browser#scrollToNode(ImageDisplay)
 *//*from   w  ww.j a  v  a2  s .com*/
public void scrollToNode(ImageDisplay node) {
    if (node == null)
        return;
    JScrollPane pane = rootDisplay.getDeskDecorator();
    Rectangle bounds = node.getBounds();
    Rectangle viewRect = pane.getViewport().getViewRect();
    if (viewRect.contains(bounds))
        return;
    JScrollBar hBar = pane.getHorizontalScrollBar();
    if (hBar.isVisible()) {
        int x = bounds.x;
        int max = hBar.getMaximum();
        if (x > max)
            x = max;
        hBar.setValue(x);
    }
    JScrollBar vBar = pane.getVerticalScrollBar();
    if (vBar.isVisible()) {
        int y = bounds.y;
        int max = vBar.getMaximum();
        if (y > max)
            y = max;
        vBar.setValue(y);
    }
}

From source file:org.tinymediamanager.ui.dialogs.ImageChooserDialog.java

private void downloadAndPreviewImage(String url) {
    Runnable task = new Runnable() {
        @Override//from   w ww . ja va  2  s .co  m
        public void run() {
            try {
                final MediaArtwork art;
                switch (type) {
                case BANNER:
                    art = new MediaArtwork("", MediaArtworkType.BANNER);
                    break;
                case CLEARART:
                    art = new MediaArtwork("", MediaArtworkType.CLEARART);
                    break;
                case DISC:
                    art = new MediaArtwork("", MediaArtworkType.DISC);
                    break;
                case FANART:
                    art = new MediaArtwork("", MediaArtworkType.BACKGROUND);
                    break;
                case LOGO:
                    art = new MediaArtwork("", MediaArtworkType.LOGO);
                    break;
                case CLEARLOGO:
                    art = new MediaArtwork("", MediaArtworkType.CLEARLOGO);
                    break;
                case POSTER:
                    art = new MediaArtwork("", MediaArtworkType.POSTER);
                    break;
                case SEASON:
                    art = new MediaArtwork("", MediaArtworkType.SEASON);
                    break;
                case THUMB:
                    art = new MediaArtwork("", MediaArtworkType.THUMB);
                    break;
                default:
                    return;
                }
                art.setDefaultUrl(tfImageUrl.getText());
                art.setPreviewUrl(tfImageUrl.getText());

                Url url = new Url(art.getPreviewUrl());
                final BufferedImage bufferedImage = ImageCache.createImage(url.getBytes());

                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        addImage(bufferedImage, art);

                        // scroll down
                        JScrollBar vertical = scrollPane.getVerticalScrollBar();
                        vertical.setValue(vertical.getMaximum());
                    }
                });
                tfImageUrl.setText("");
            } catch (Exception e) {
                LOGGER.error("could not download manually entered image url: " + tfImageUrl.getText());
            }
        }
    };
    task.run();
}

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);//from  w w w.  j a  v 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;
}