@Override protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) { int x = (int) trackBounds.getX(); int y = (int) trackBounds.getY(); int w = (int) trackBounds.getWidth(); int h = (int) trackBounds.getHeight(); g.setColor(Colors.SCROLLBAR_TRACK_BACKGROUND); g.fillRect(x - 1, y - 1, w + 2, h + 2); g.setColor(Colors.SCROLLBAR_TRACK_BORDER); if (this.scrollbar.getOrientation() == Adjustable.HORIZONTAL) { g.drawLine(x, y, x + w, y); } else { g.drawLine(x, y, x, y + h); } }
@Override protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) { int x = (int) thumbBounds.getX(); int y = (int) thumbBounds.getY(); int w = (int) thumbBounds.getWidth(); int h = (int) thumbBounds.getHeight(); if (c.isEnabled() && w > 0 && h > 0) { if (this.scrollbar.getOrientation() == Adjustable.HORIZONTAL) { h -= 1; y++; drawHorizThumb(g, x, y, w, h); } else { w -= 1; x++; drawVertThumb(g, x, y, w, h); } } }
public static void handleWheelScrolling(ScrollPane sp, MouseWheelEvent e) { if (log.isLoggable(PlatformLogger.Level.FINER)) { log.finer("x = " + e.getX() + ", y = " + e.getY() + ", src is " + e.getSource()); } int increment = 0; if (sp != null && e.getScrollAmount() != 0) { Adjustable adj = getAdjustableToScroll(sp); if (adj != null) { increment = getIncrementFromAdjustable(adj, e); if (log.isLoggable(PlatformLogger.Level.FINER)) { log.finer("increment from adjustable(" + adj.getClass() + ") : " + increment); } scrollAdjustable(adj, increment); } } }
public static int getIncrementFromAdjustable(Adjustable adj, MouseWheelEvent e) { if (log.isLoggable(PlatformLogger.Level.FINE)) { if (adj == null) { log.fine("Assertion (adj != null) failed"); } } int increment = 0; if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { increment = e.getUnitsToScroll() * adj.getUnitIncrement(); } else if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) { increment = adj.getBlockIncrement() * e.getWheelRotation(); } return increment; }
@Override void initializeImpl() { super.initializeImpl(); final Scrollbar target = getTarget(); setLineIncrement(target.getUnitIncrement()); setPageIncrement(target.getBlockIncrement()); setValues(target.getValue(), target.getVisibleAmount(), target.getMinimum(), target.getMaximum()); final int orientation = target.getOrientation(); final JScrollBar delegate = getDelegate(); synchronized (getDelegateLock()) { delegate.setOrientation(orientation == Scrollbar.HORIZONTAL ? Adjustable.HORIZONTAL : Adjustable.VERTICAL); delegate.addAdjustmentListener(this); } }
/** * Constructs * * @param objPpreferencesJDialog * @param bytPpreferenceType */ public PreferenceByteGlobalJScrollBar(PreferencesJDialog objPpreferencesJDialog, byte bytPpreferenceType) { super(Adjustable.HORIZONTAL); this.objGpreferencesJDialog = objPpreferencesJDialog; this.bytGpreferenceType = bytPpreferenceType; this.setOpaque(true); switch (this.bytGpreferenceType) { case Constants.bytS_BYTE_GLOBAL_GAMMA_CORRECTION: this.setValues( this.objGpreferencesJDialog.bytGbyteGlobalAA[this.bytGpreferenceType][Constants.bytS_UNCLASS_INITIAL], 1, Constants.bytS_BYTE_GLOBAL_GAMMA_CORRECTION_MINIMUM_VALUE, Constants.bytS_BYTE_GLOBAL_GAMMA_CORRECTION_MAXIMUM_VALUE + 1); this.setBlockIncrement(3); break; } this.addAdjustmentListener(this); }
/** * Scrolls pane to top. * * @throws TimeoutExpiredException */ public void scrollToTop() { output.printTrace("Scroll ScrollPane to top\n" + toStringSource()); output.printGolden("Scroll ScrollPane to top"); produceTimeRestricted(new Action<Void, Void>() { @Override public Void launch(Void obj) { driver.scrollToMinimum(ScrollPaneOperator.this, Adjustable.VERTICAL); return null; } @Override public String getDescription() { return "Scrolling"; } @Override public String toString() { return "ScrollPaneOperator.scrollToTop.Action{description = " + getDescription() + '}'; } }, "ScrollbarOperator.WholeScrollTimeout"); }
/** * Scrolls pane to bottom. * * @throws TimeoutExpiredException */ public void scrollToBottom() { output.printTrace("Scroll ScrollPane to bottom\n" + toStringSource()); output.printGolden("Scroll ScrollPane to bottom"); produceTimeRestricted(new Action<Void, Void>() { @Override public Void launch(Void obj) { driver.scrollToMaximum(ScrollPaneOperator.this, Adjustable.VERTICAL); return null; } @Override public String getDescription() { return "Scrolling"; } @Override public String toString() { return "ScrollPaneOperator.scrollToBottom.Action{description = " + getDescription() + '}'; } }, "ScrollbarOperator.WholeScrollTimeout"); }
/** * Scrolls pane to left. * * @throws TimeoutExpiredException */ public void scrollToLeft() { output.printTrace("Scroll ScrollPane to left\n" + toStringSource()); output.printGolden("Scroll ScrollPane to left"); produceTimeRestricted(new Action<Void, Void>() { @Override public Void launch(Void obj) { driver.scrollToMinimum(ScrollPaneOperator.this, Adjustable.HORIZONTAL); return null; } @Override public String getDescription() { return "Scrolling"; } @Override public String toString() { return "ScrollPaneOperator.scrollToLeft.Action{description = " + getDescription() + '}'; } }, "ScrollbarOperator.WholeScrollTimeout"); }
/** * Scrolls pane to right. * * @throws TimeoutExpiredException */ public void scrollToRight() { output.printTrace("Scroll ScrollPane to right\n" + toStringSource()); output.printGolden("Scroll ScrollPane to right"); produceTimeRestricted(new Action<Void, Void>() { @Override public Void launch(Void obj) { driver.scrollToMaximum(ScrollPaneOperator.this, Adjustable.HORIZONTAL); return null; } @Override public String getDescription() { return "Scrolling"; } @Override public String toString() { return "ScrollPaneOperator.scrollToRight.Action{description = " + getDescription() + '}'; } }, "ScrollbarOperator.WholeScrollTimeout"); }
@Override public int getScrollDirection() { int sp = (orientation == Adjustable.HORIZONTAL) ? (int) getScrollPosition().getX() : (int) getScrollPosition().getY(); Point pnt = SwingUtilities.convertPoint(comp, x, y, ((Container) getSource()).getComponents()[0]); int cp = (orientation == Adjustable.HORIZONTAL) ? pnt.x : pnt.y; int sl = (orientation == Adjustable.HORIZONTAL) ? (int) getViewportSize().getWidth() : (int) getViewportSize().getHeight(); int cl = (orientation == Adjustable.HORIZONTAL) ? width : height; if (cp <= sp) { return ScrollAdjuster.DECREASE_SCROLL_DIRECTION; } else if ((cp + cl) > (sp + sl) && cp > sp) { return ScrollAdjuster.INCREASE_SCROLL_DIRECTION; } else { return ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION; } }
public final JScrollBar getHorizontalScrollBar(ColorPalette cp) { for(int index = 0; index<cp.getComponentCount(); index++) { Component comp = cp.getComponent(index); if(comp instanceof JScrollBar) { JScrollBar jsb = (JScrollBar)comp; if(jsb.getOrientation()==Adjustable.HORIZONTAL) { return jsb; } } } int max = getHorizontalScrollMax(cp); if(max>1) { JScrollBar hBar = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, max); hBar.addAdjustmentListener(scrollBarListener); cp.add(hBar); hBar.putClientProperty("JComponent.sizeVariant", "mini"); hBar.setCursor(Cursor.getDefaultCursor()); updateScrollBarBounds(cp); return hBar; } return null; }
public final JScrollBar getVerticalScrollBar(ColorPalette cp) { for(int index = 0; index<cp.getComponentCount(); index++) { Component comp = cp.getComponent(index); if(comp instanceof JScrollBar) { JScrollBar jsb = (JScrollBar)comp; if(jsb.getOrientation()==Adjustable.VERTICAL) { return jsb; } } } int max = getVerticalScrollMax(cp); if(max>1) { JScrollBar vBar = new JScrollBar(Adjustable.VERTICAL, 0, 0, 0, max); vBar.addAdjustmentListener(scrollBarListener); cp.add(vBar); vBar.putClientProperty("JComponent.sizeVariant", "mini"); vBar.setCursor(Cursor.getDefaultCursor()); updateScrollBarBounds(cp); return vBar; } return null; }
public void scroll(final int movement) { ScrollbarLocationManipulation locationManipulation = new ScrollbarLocationManipulation(); perform("locating scroll bar", locationManipulation); moveMouseToOffset(locationManipulation.getX(), locationManipulation.getY()); performGesture(new MousePressGesture(InputEvent.BUTTON1_MASK)); if (locationManipulation.getOrientation() == Adjustable.HORIZONTAL) { performGesture(new MouseMoveAbsoluteGesture(Adjustable.HORIZONTAL, movement)); } else { performGesture(new MouseMoveAbsoluteGesture(Adjustable.HORIZONTAL, movement)); } performGesture(new MouseReleaseGesture(InputEvent.BUTTON1_MASK)); }