private void initialise() { Toolkit toolkit = Toolkit.getDefaultToolkit(); backBuffer = worldMap.getGraphics(); // Make the image buffer as large as could possibly be used (screensize) if (backBufferImage == null) { logger.debug( "Creating backBufferImage of dimensions " + toolkit.getScreenSize().width + "," + toolkit.getScreenSize().height + "."); backBufferImage = createImage(toolkit.getScreenSize().width, toolkit.getScreenSize().height); backBuffer = backBufferImage.getGraphics(); } else { backBufferImage.flush(); backBufferImage = createImage(toolkit.getScreenSize().width, toolkit.getScreenSize().height); backBuffer.dispose(); backBuffer = backBufferImage.getGraphics(); } setupWindow(worldMap.getWidth(), worldMap.getHeight()); initialise = false; logger.debug( "initialised backBufferImage with size " + worldMap.getWidth() + "," + worldMap.getHeight() + "."); }
@Override public void componentResized(ComponentEvent e) { Component c = e.getComponent(); if (c.getWidth() != widthSetting.getValue() || c.getHeight() != heightSetting.getValue()) { widthSetting.setValue(c.getWidth()); heightSetting.setValue(c.getHeight()); } }
@Override public void componentResized(ComponentEvent e) { int increment = ThemeSettings.FONT_SIZE_INCREMENT.getValue(); Component c = e.getComponent(); if (c.getWidth() != getWidthForFontIncrement(widthSetting, c, increment) || c.getHeight() != getHeightForFontIncrement(heightSetting, c, increment)) { widthSetting.setValue(c.getWidth()); heightSetting.setValue(c.getHeight()); } }
@Override public void componentResized(ComponentEvent e) { if ((frame.getExtendedState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH) return; if ((frame.getExtendedState() & Frame.ICONIFIED) == Frame.ICONIFIED) return; Component c = e.getComponent(); if (c.getHeight() != this.h || c.getWidth() != this.w) { this.h = c.getHeight(); this.w = c.getWidth(); // System.out.println(e.toString()); } }
public static void fillComponent(Graphics g, Component c) { if (!JTattooUtilities.isMac() && AbstractLookAndFeel.getTheme().isBackgroundPatternOn()) { Point offset = JTattooUtilities.getRelLocation(c); Dimension size = JTattooUtilities.getFrameSize(c); Graphics2D g2D = (Graphics2D) g; g2D.setPaint(new AluminiumGradientPaint(offset, size)); g2D.fillRect(0, 0, c.getWidth(), c.getHeight()); g2D.setPaint(null); } else { g.setColor(c.getBackground()); g.fillRect(0, 0, c.getWidth(), c.getHeight()); } }
public static Point keepComponentInsideParent( Point l, Point parentPoint, Component c, Component parent) { int dx = parentPoint.x + parent.getWidth() - DEFAULT_INSETS.right - COMPONENT_INSETS.right; if (l.x + c.getWidth() > dx) { l.x = dx - c.getWidth(); } int dy = parentPoint.y + parent.getHeight() - DEFAULT_INSETS.bottom - COMPONENT_INSETS.bottom; if (l.y + c.getHeight() > dy) { l.y = Math.max(10, dy - c.getHeight()); } return l; }
public GradientBackground(Component canvas) { super("Background"); this.canvas = canvas; canvas.addComponentListener( new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { super.componentResized(e); update(); } }); int width = Math.max(canvas.getWidth(), 10); int height = Math.max(canvas.getHeight(), 10); backgroundQuad = new Quad("BackgroundQuad", width, height); backgroundQuad.getSceneHints().setLightCombineMode(LightCombineMode.Off); backgroundQuad.getSceneHints().setOrthoOrder(1); update(); attachChild(backgroundQuad); final ZBufferState zstate = new ZBufferState(); zstate.setWritable(false); zstate.setEnabled(false); setRenderState(zstate); getSceneHints().setRenderBucketType(RenderBucketType.Skip); }
/** * Construct a Rotate effect for a given component with the number of degrees you wish to rotate * through during the transition. This constructor will result in an effect that rotates around * the center of the component */ public Rotate(Component component, int degrees) { this.degrees = degrees; // Rotate around the center of the component xCenter = component.getWidth() / 2; yCenter = component.getHeight() / 2; }
private static BufferedImage getScreenShot(Component component) { BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB); component.paint(image.getGraphics()); return image; }
public void componentMoved(ComponentEvent evt) { Component component = evt.getComponent(); Point point = component.getLocation(); if (point.y < 0) { component.setBounds(point.x, 0, component.getWidth(), component.getHeight()); } }
/** * Returns true if popup can fit the screen and the owner's top parent. It determines can popup * be lightweight or mediumweight. */ boolean fitsOnScreen() { boolean result = false; Component component = getComponent(); if (owner != null && component != null) { int popupWidth = component.getWidth(); int popupHeight = component.getHeight(); Container parent = (Container) SwingUtilities.getRoot(owner); if (parent instanceof JFrame || parent instanceof JDialog || parent instanceof JWindow) { Rectangle parentBounds = parent.getBounds(); Insets i = parent.getInsets(); parentBounds.x += i.left; parentBounds.y += i.top; parentBounds.width -= i.left + i.right; parentBounds.height -= i.top + i.bottom; if (JPopupMenu.canPopupOverlapTaskBar()) { GraphicsConfiguration gc = parent.getGraphicsConfiguration(); Rectangle popupArea = getContainerPopupArea(gc); result = parentBounds.intersection(popupArea).contains(x, y, popupWidth, popupHeight); } else { result = parentBounds.contains(x, y, popupWidth, popupHeight); } } else if (parent instanceof JApplet) { Rectangle parentBounds = parent.getBounds(); Point p = parent.getLocationOnScreen(); parentBounds.x = p.x; parentBounds.y = p.y; result = parentBounds.contains(x, y, popupWidth, popupHeight); } } return result; }
@Override public void paint(Graphics g) { if ((target instanceof Frame && !(target instanceof JFrame)) || (target instanceof Dialog && !(target instanceof JDialog))) { SwingBaseWindow<?, ?> sf = SwingBaseWindow.this; Window f = target; Color bg = f.getBackground(); if (bg == null) bg = UIManager.getColor("window"); if (bg == null) bg = UIManager.getColor("control"); if (bg == null) bg = Color.GRAY; g.setColor(bg); g.fillRect(0, 0, getWidth(), getHeight()); Point f_loc = sf.getLocationOnScreen(); Point p_loc = this.getLocationOnScreen(); int dx = p_loc.x - f_loc.x; int dy = p_loc.y - f_loc.y; for (Component c : f.getComponents()) { Graphics cg = g.create(c.getX() - dx, c.getY() - dy, c.getWidth(), c.getHeight()); c.paintAll(cg); cg.dispose(); } } }
private static Pair<Image, Point> createDragImage( final Tree tree, final Component c, Point dragOrigin, boolean adjustToPathUnderDragOrigin) { if (c instanceof JComponent) { ((JComponent) c).setOpaque(true); } c.setForeground(tree.getForeground()); c.setBackground(tree.getBackground()); c.setFont(tree.getFont()); c.setSize(c.getPreferredSize()); final BufferedImage image = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) image.getGraphics(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); c.paint(g2); g2.dispose(); Point point = new Point(-image.getWidth(null) / 2, -image.getHeight(null) / 2); if (adjustToPathUnderDragOrigin) { TreePath path = tree.getPathForLocation(dragOrigin.x, dragOrigin.y); if (path != null) { Rectangle bounds = tree.getPathBounds(path); point = new Point(bounds.x - dragOrigin.x, bounds.y - dragOrigin.y); } } return new Pair<Image, Point>(image, point); }
void paintStatus(Graphics2D g) { if (parts == null) { return; } g.setComposite(AlphaComposite.Src); synchronized (parts) { if (currWidth == 0 || currHeight == 0 || progressComponent == null) { return; } float scaleX = ((float) progressComponent.getWidth()) / currWidth; float scaleY = ((float) progressComponent.getHeight()) / currHeight; if (scaleX < scaleY) { scaleY = scaleX; } else { scaleX = scaleY; } g.setColor(Color.yellow); g.fillRect(0, 0, (int) (currWidth * scaleX), (int) (currHeight * scaleY)); Rectangle p = new Rectangle(); for (MosaicPart part : parts) { Rectangle r = part.getPlacement(); p.x = (int) (r.x * scaleX); p.y = (int) (r.y * scaleY); p.width = (int) (r.width * scaleX); p.height = (int) (r.height * scaleY); part.getImage().drawScaled(g, p, progressComponent); } } }
@Override public void mouseMoved(MouseEvent e) { Component source = e.getComponent(); Point location = e.getPoint(); direction = 0; if (location.x < dragInsets.left) direction += WEST; if (location.x > source.getWidth() - dragInsets.right - 1) direction += EAST; if (location.y < dragInsets.top) direction += NORTH; if (location.y > source.getHeight() - dragInsets.bottom - 1) direction += SOUTH; // Mouse is no longer over a resizable border if (direction == 0) { source.setCursor(sourceCursor); } else // use the appropriate resizable cursor { int cursorType = cursors.get(direction); Cursor cursor = Cursor.getPredefinedCursor(cursorType); source.setCursor(cursor); } }
public void componentResized(ComponentEvent arg0) { if (initialise) return; setupWindow(worldMap.getWidth(), worldMap.getHeight()); updateImageBuffer(); resize = true; execute(); }
private static int getScrollAmount(Component c, MouseWheelEvent me, JScrollBar scrollBar) { final int scrollBarWidth = scrollBar.getWidth(); final int ratio = Registry.is("ide.smart.horizontal.scrolling") && scrollBarWidth > 0 ? Math.max((int) Math.pow(c.getWidth() / scrollBarWidth, 2), 10) : 10; // do annoying scrolling faster if smart scrolling is on return me.getUnitsToScroll() * scrollBar.getUnitIncrement() * ratio; }
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { if (getComponentCount() > 0) { Component c = getComponent(0); if (orientation == SwingConstants.HORIZONTAL) return c.getWidth(); else return c.getHeight(); } return 50; }
/** * Centers the given component in relation to its owner. * * @param component the component to center * @param owner the parent frame */ public static void centerComponent(Component component, Component owner) { // find the difference in width to see the offsets int widthDifference = owner.getWidth() - component.getWidth(); int heightDifference = owner.getHeight() - component.getHeight(); // we can divide the differences by 2 and add that to the owner's top left // and then make that the top left of the component // to center the frame int leftOffset = widthDifference / 2; int topOffset = heightDifference / 2; // these are the new locations int left = owner.getX() + leftOffset; int top = owner.getY() + topOffset; Utils.changeFrameLocation(component, left, top); }
public synchronized void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(Color.white); g.fillRect(0, 0, c.getWidth(), c.getHeight()); if (getImageObserver() == null) { g.drawImage( getImage(), c.getWidth() / 2 - getIconWidth() / 2, c.getHeight() / 2 - getIconHeight() / 2, c); } else { g.drawImage( getImage(), c.getWidth() / 2 - getIconWidth() / 2, c.getHeight() / 2 - getIconHeight() / 2, getImageObserver()); } }
@Override public DriftFollowAnchor followLeft() { leftPad = self.getX() - followTo.getX() - followTo.getWidth(); if (leftPad < 0) { leftPad = 5; } return this; }
@Override public DriftFollowAnchor followRight() { rightPad = followTo.getX() - self.getX() - self.getWidth(); if (rightPad < 0) { rightPad = 5; } return this; }
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { final Graphics2D g2d = (Graphics2D) g; final Insets ins = getBorderInsets(c); final int yOff = (ins.top + ins.bottom) / 4; final boolean square = DarculaButtonUI.isSquare(c); int offset = square ? 1 : getOffset(); if (c.hasFocus()) { if (DarculaButtonUI.isHelpButton((JComponent) c)) { int w = c.getWidth(); int h = c.getHeight(); DarculaUIUtil.paintFocusOval(g2d, (w - 22) / 2, (h - 22) / 2, 22, 22); } else { DarculaUIUtil.paintFocusRing(g2d, offset, yOff, width - 2 * offset, height - 2 * yOff); } } else { final GraphicsConfig config = new GraphicsConfig(g); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT); g2d.setPaint( UIUtil.getGradientPaint( width / 2, y + yOff + 1, Gray._80.withAlpha(90), width / 2, height - 2 * yOff, Gray._90.withAlpha(90))); // g.drawRoundRect(x + offset + 1, y + yOff + 1, width - 2 * offset, height - 2*yOff, 5, 5); ((Graphics2D) g).setPaint(Gray._100.withAlpha(180)); if (DarculaButtonUI.isHelpButton((JComponent) c)) { int w = c.getWidth(); int h = c.getHeight(); g.drawOval((w - 22) / 2, (h - 22) / 2, 22, 22); } else { g.drawRoundRect( x + offset, y + yOff, width - 2 * offset, height - 2 * yOff, square ? 3 : 5, square ? 3 : 5); } config.restore(); } }
/** {@inheritDoc} */ @Override public void mouseDragged(final MouseEvent aEvent) { final MouseEvent event = convertEvent(aEvent); final Point point = event.getPoint(); // Update the selected channel while dragging... this.controller.setSelectedChannel(point); if (getModel().isCursorMode() && (this.movingCursor >= 0)) { this.controller.moveCursor(this.movingCursor, getCursorDropPoint(point)); aEvent.consume(); } else { if ((this.lastClickPosition == null) && ((aEvent.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0)) { this.lastClickPosition = new Point(point); } final JScrollPane scrollPane = getAncestorOfClass(JScrollPane.class, (Component) aEvent.getSource()); if ((scrollPane != null) && (this.lastClickPosition != null)) { final JViewport viewPort = scrollPane.getViewport(); final Component signalView = this.controller.getSignalDiagram().getSignalView(); boolean horizontalOnly = (aEvent.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0; boolean verticalOnly = horizontalOnly && ((aEvent.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0); int dx = aEvent.getX() - this.lastClickPosition.x; int dy = aEvent.getY() - this.lastClickPosition.y; Point scrollPosition = viewPort.getViewPosition(); int newX = scrollPosition.x; if (!verticalOnly) { newX -= dx; } int newY = scrollPosition.y; if (verticalOnly || !horizontalOnly) { newY -= dy; } int diagramWidth = signalView.getWidth(); int viewportWidth = viewPort.getWidth(); int maxX = diagramWidth - viewportWidth - 1; scrollPosition.x = Math.max(0, Math.min(maxX, newX)); int diagramHeight = signalView.getHeight(); int viewportHeight = viewPort.getHeight(); int maxY = diagramHeight - viewportHeight; scrollPosition.y = Math.max(0, Math.min(maxY, newY)); viewPort.setViewPosition(scrollPosition); } // Use UNCONVERTED/ORIGINAL mouse event! handleZoomRegion(aEvent, this.lastClickPosition); } }
/** * Uses the Robot class to try to postion the mouse in the center of the screen. * * <p>Note that use of the Robot class may not be available on all platforms. */ private synchronized void recenterMouse() { if (robot != null && comp.isShowing()) { centerLocation.x = comp.getWidth() / 2; centerLocation.y = comp.getHeight() / 2; SwingUtilities.convertPointToScreen(centerLocation, comp); isRecentering = true; robot.mouseMove(centerLocation.x, centerLocation.y); } }
public void paintIcon(Component c, Graphics g, int x, int y) { Color oldColor = g.getColor(); boolean enabled = c.isEnabled(); boolean pressed = false; if (c instanceof JButton) { pressed = ((JButton) c).getModel().isPressed(); } int i = 0; int j = 0; int w = Math.min(width, c.getWidth()); int h = c.getHeight(); if (h < 5 || w < 5) { // not enough space for the arrow g.setColor(oldColor); return; } int size = Math.min(h / 2, w / 2); size = Math.max(size, 2); int mid = size / 2; x = ((w - size) / 2); // center arrow y = (h - size) / 2; // center arrow if (pressed) { x++; y++; } g.translate(x, y); // move the x,y origin in the graphic if (enabled) g.setColor(UIManager.getColor("controlDkShadow")); // NOT // LOCALIZABLE else g.setColor(UIManager.getColor("controlShadow")); // NOT // LOCALIZABLE if (!enabled) { g.translate(1, 1); g.setColor(UIManager.getColor("controlLtHighlight")); // NOT // LOCALIZABLE for (i = size - 1; i >= 0; i--) { g.drawLine(mid - i, j, mid + i, j); j++; } g.translate(-1, -1); g.setColor(UIManager.getColor("controlShadow")); // NOT // LOCALIZABLE } j = 0; for (i = size - 1; i >= 0; i--) { g.drawLine(mid - i, j, mid + i, j); j++; } g.translate(-x, -y); g.setColor(oldColor); }
/** * Extracts the buffered image of some component * * @param myComponent the component for which the BufferedImage is required * @param region region to be captured * @return the BufferedImage which has the current condition of component * @throws IOException */ public static BufferedImage Get_Component_Image(Component myComponent, Rectangle region) throws IOException { BufferedImage img = new BufferedImage( myComponent.getWidth(), myComponent.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); myComponent.paint(g); g.dispose(); return img; }
/** * Create a new BusyPainterUI. * * @param view The view to create the painter to. */ public BusyPainterUI(Component view) { busyPainter = new SimpleBusyPainter(); busyPainter.setPointShape(new Ellipse2D.Double(0, 0, 20, 20)); busyPainter.setTrajectory( new Ellipse2D.Double( view.getWidth() / 4, view.getHeight() / 4, view.getWidth() / 2, view.getHeight() / 2)); timer = new Timer(200, this); }
private void showSpinner() { clearBuffer(); Image spinImage; try { spinImage = ImageIO.read(new File(IMAGE_PATH + SPIN)); backBuffer.drawImage( spinImage, worldMap.getWidth() / 2 - 15, worldMap.getHeight() / 2 - 15, null); } catch (Exception e) { logger.warn("Couldn't find the spinner image file '" + IMAGE_PATH + SPIN + "'."); } }
/** Turn the owned components. */ public final void turn() { // go through the list of contained components and change location // and e.g. call turn method of components. for (Component c : getComponents()) { c.setLocation(getWidth() - c.getX() - c.getWidth(), getHeight() - c.getY() - c.getHeight()); if (c instanceof Mega) { ((Mega) c).turn(); } } }