Example usage for javax.swing JScrollBar setValue

List of usage examples for javax.swing JScrollBar setValue

Introduction

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

Prototype

@BeanProperty(bound = false, preferred = true, description = "The scrollbar's current value.")
public void setValue(int value) 

Source Link

Document

Sets 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);
        }//w  w  w .  j  a  v a 2 s . co m

        @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:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private void addBox() {
    final JPanel panel = createAParameterBox(false);
    combinationsPanel.add(panel);/*  w  w w. ja v a  2  s .c o m*/
    combinationsPanel.revalidate();

    combinationsScrPane.invalidate();
    combinationsScrPane.validate();
    final JScrollBar verticalScrollBar = combinationsScrPane.getVerticalScrollBar();
    verticalScrollBar.setValue(verticalScrollBar.getMaximum());
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

void showHideSubparameters(final JComboBox combobox, final SubmodelInfo info) {
    if (!combobox.isDisplayable()) {
        return;/*w  w  w. j a  v a 2  s. c  o  m*/
    }
    final ClassElement classElement = (ClassElement) combobox.getSelectedItem();

    info.setActualType(classElement.clazz, classElement.instance);
    final int level = calculateParameterLevel(info);
    for (int i = singleRunParametersPanel.getComponentCount() - 1; i >= level + 1; --i)
        singleRunParametersPanel.remove(i);

    if (classElement.clazz != null) {
        try {
            final List<ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?>> subparameters = ParameterTreeUtils
                    .fetchSubparameters(currentModelHandler, info);
            String title = "Configure " + info.getName().replaceAll("([A-Z])", " $1").trim();
            createAndDisplayAParameterPanel(subparameters, title, info, true, currentModelHandler);
        } catch (final ModelInformationException e) {
            info.setActualType(null, null);
            JOptionPane.showMessageDialog(wizard, new JLabel(e.getMessage()), "Error while analyizing model",
                    JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
            combobox.setSelectedIndex(0);
        }
    }

    parametersScrollPane.invalidate();
    parametersScrollPane.validate();
    final JScrollBar horizontalScrollBar = parametersScrollPane.getHorizontalScrollBar();
    horizontalScrollBar.setValue(horizontalScrollBar.getMaximum());
}

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);
        }//ww w  . ja v 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:org.nuclos.client.ui.collect.result.SearchResultStrategy.java

private void adjustVerticalScrollBarForSearch(boolean bRefreshOnly) {
    final CollectController<Clct> cc = getCollectController();
    final JViewport viewport = cc.getResultPanel().getResultTableScrollPane().getViewport();
    if (bRefreshOnly) {
        final Rectangle rect = cc.getResultTable().getCellRect(0, 0, true);
        final Rectangle viewRect = viewport.getViewRect();
        // There seem to be different opinions about what scrollRectToVisible has to do at SUN and everywhere else...
        rect.setLocation(viewRect.x, viewRect.y);//rect.x - viewRect.x, rect.y - viewRect.y);
        viewport.scrollRectToVisible(rect);
    } else {//  w  w w  . j  a  va  2 s .  c o  m
        Point viewPosition = viewport.getViewPosition();
        viewport.setViewPosition(new Point(viewPosition.x, 0));
    }
    final JScrollBar scrlbarVertical = cc.getResultPanel().getResultTableScrollPane().getVerticalScrollBar();
    scrlbarVertical.setValue(scrlbarVertical.getMinimum());
}

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

/**
 * Implemented as specified by the {@link Browser} interface.
 * @see Browser#scrollToNode(ImageDisplay)
 *///ww  w.j av  a 2 s.  c  om
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/*ww  w. j a  va2  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);//w  w w.j  ava  2 s  . 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}//from   w ww .ja  v  a  2  s  .  c om
 */
@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);
            }
        }
    }
}

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

/**
 * {@inheritDoc}//  w  ww .  java 2s . c o m
 */
@Override
public void mouseDragged(MouseEvent event) {

    setMouseModifier(event);

    GraphPaneController gpc = GraphPaneController.getInstance();
    int x2 = getConstrainedX(event);

    isDragging = true;

    if (gpc.isPanning()) {
        setCursor(new Cursor(Cursor.HAND_CURSOR));
    } else if (gpc.isZooming() || gpc.isSelecting()) {
        setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
    }

    // Check if scrollbar is present (only vertical pan if present)
    JScrollBar scroller = getVerticalScrollBar();
    boolean scroll = scroller.isVisible();

    if (scroll) {

        //get new points
        Point l = event.getLocationOnScreen();
        int currX = l.x;
        int currY = l.y;

        //magnitude
        int magX = Math.abs(currX - startX);
        int magY = Math.abs(currY - startY);

        if (magX >= magY) {
            //pan horizontally, reset vertical pan
            panVert = false;
            gpc.setMouseReleasePosition(transformXPixel(x2));
            scroller.setValue(initialScroll);
        } else {
            //pan vertically, reset horizontal pan
            panVert = true;
            gpc.setMouseReleasePosition(baseX);
            scroller.setValue(initialScroll - (currY - startY));
        }
    } else {
        //pan horizontally
        panVert = false;
        gpc.setMouseReleasePosition(transformXPixel(x2));
    }
}