@Override public boolean mouseMove(Component component, int x, int y) { boolean consumed = super.mouseMove(component, x, y); if (Mouse.getCapturer() == component) { ScrollBar scrollBar = (ScrollBar) TerraScrollBarSkin.this.getComponent(); Orientation orientation = scrollBar.getOrientation(); // Calculate the new scroll bar value int pixelValue; if (orientation == Orientation.HORIZONTAL) { pixelValue = component.getX() - scrollUpButton.getWidth() + x - dragOffset; } else { pixelValue = component.getY() - scrollUpButton.getHeight() + y - dragOffset; } int realValue = (int) (pixelValue / getValueScale()); // Bound the value int end = scrollBar.getEnd(); int extent = scrollBar.getExtent(); realValue = Math.min(Math.max(realValue, 0), end - extent); // Update the scroll bar scrollBar.setValue(realValue); } return consumed; }
@Override public void update() { graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity)); graphics.setColor(color); graphics.fillRect(0, 0, component.getWidth(), component.getHeight()); component = null; graphics = null; }
@Override public AffineTransform getTransform(Component componentArgument) { AffineTransform transform = AffineTransform.getScaleInstance(1.0, -1.0); transform.translate(0, -(componentArgument.getHeight() * 2)); return transform; }
/** * Propagates the scroll bar's enabled state to the scroll buttons. * * @param component The scroll bar. */ @Override public void enabledChanged(Component component) { boolean enabled = component.isEnabled(); scrollUpButton.setEnabled(enabled); scrollDownButton.setEnabled(enabled); invalidateComponent(); }
@Override public Graphics2D prepare(Component componentArgument, Graphics2D graphicsArgument) { this.component = componentArgument; this.graphics = graphicsArgument; int width = componentArgument.getWidth(); int height = componentArgument.getHeight(); componentImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); componentImageGraphics = componentImage.createGraphics(); // Clear the image background componentImageGraphics.setComposite(AlphaComposite.Clear); componentImageGraphics.fillRect(0, 0, componentImage.getWidth(), componentImage.getHeight()); componentImageGraphics.setComposite(AlphaComposite.SrcOver); return componentImageGraphics; }
private static void sendBubbleUp(Component container, Event event) { Container parent = container.getParent(); if (parent != null) { sendTo(parent, event); sendBubbleUp(parent, event); } if (container instanceof Display) { Application app = Applications.get((Display) container); sendTo(app, event); } }
@Override public Bounds getBounds(Component componentArgument) { return new Bounds(0, 0, componentArgument.getWidth(), componentArgument.getHeight()); }