@Override protected void draw(final Graphics g, final int x, final int y) { g.enterViewport(getX(), getY(), getWidth(), getHeight()); for (final Component c : components) { if (viewerBounds.intersects(c.getX(), c.getY(), c.getWidth(), c.getHeight())) { // draw component g.enterViewport(c.getX(), c.getY(), c.getWidth(), c.getHeight()); c.draw(g, x + getX() - viewerBounds.getX(), y + getY() - viewerBounds.getY()); g.exitViewport(); } } g.exitViewport(); }
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; }
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); }
@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 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; }
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()); } }
/** * 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 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; }
@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(); } }
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; }
/** {@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); } }
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; }
public void paint(Graphics g) { if (comp != null) { width = comp.getWidth() / 6; height = comp.getHeight() * 2 / 3; } g.setColor(bgColor); g.fillRect(x, y, width, height); g.setColor(fgColor); g.setFont(font); g.drawString(strTray, x / 2 + width / 2, y + height + 10); super.paint(g); }
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { if (image != null && showimage) { // TODO: add ability to scale maintaining aspect ratio fitting to size of parent // TODO: Need to add not zoom all the way, but zoom to a box of aspect ratio 4/3 Graphics2D g2 = (Graphics2D) g; AffineTransform tran = new AffineTransform(1f, 0f, 0f, 1f, 0, 0); float widthscale = (float) c.getWidth() / image.getWidth(); float heightscale = (float) c.getHeight() / image.getHeight(); switch (drawmode) { case DRAW_MODE_ASPECT: float scale; if (widthscale < heightscale) { scale = widthscale; } else { scale = heightscale; } tran.scale(scale, scale); g2.drawImage( image, new AffineTransformOp(tran, AffineTransformOp.TYPE_BILINEAR), (int) (c.getWidth() - image.getWidth() * scale) / 2, (int) (c.getHeight() - image.getHeight() * scale) / 2); break; case DRAW_MODE_WIDTH: tran.scale(widthscale, widthscale); g2.drawImage(image, tran, null); break; case DRAW_MODE_HEIGHT: tran.scale(heightscale, heightscale); g2.drawImage(image, tran, null); break; default: tran.scale(widthscale, heightscale); g2.drawImage(image, tran, null); break; } } }
public static BufferedImage componentToImage(Component component, Rectangle region) { BufferedImage img = new BufferedImage( component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE); Graphics g = img.getGraphics(); g.setColor(component.getForeground()); g.setFont(component.getFont()); component.paintAll(g); g.dispose(); if (region == null) { return img; } return img.getSubimage(region.x, region.y, region.width, region.height); }
/** * Returns the component in the currently selected path which contains sourcePoint. * * @param source The component in whose coordinate space sourcePoint is given * @param sourcePoint The point which is being tested * @return The component in the currently selected path which contains sourcePoint (relative to * the source component's coordinate space. If sourcePoint is not inside a component on the * currently selected path, null is returned. */ public Component componentForPoint(Component source, Point sourcePoint) { int screenX, screenY; Point p = sourcePoint; int i, c, j, d; Component mc; Rectangle r2; int cWidth, cHeight; MenuElement menuElement; MenuElement subElements[]; Vector<MenuElement> tmp; int selectionSize; SwingUtilities.convertPointToScreen(p, source); screenX = p.x; screenY = p.y; tmp = (Vector<MenuElement>) selection.clone(); selectionSize = tmp.size(); for (i = selectionSize - 1; i >= 0; i--) { menuElement = (MenuElement) tmp.elementAt(i); subElements = menuElement.getSubElements(); for (j = 0, d = subElements.length; j < d; j++) { if (subElements[j] == null) continue; mc = subElements[j].getComponent(); if (!mc.isShowing()) continue; if (mc instanceof JComponent) { cWidth = mc.getWidth(); cHeight = mc.getHeight(); } else { r2 = mc.getBounds(); cWidth = r2.width; cHeight = r2.height; } p.x = screenX; p.y = screenY; SwingUtilities.convertPointFromScreen(p, mc); /** * Return the deepest component on the selection path in whose bounds the event's point * occurs */ if (p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight) { return mc; } } } return null; }
public static void keepComponentInsideScreen(int x, int y, Component c) { Dimension screenDim = c.getToolkit().getScreenSize(); GraphicsConfiguration g = c.getGraphicsConfiguration(); if (g != null) { Insets insets = c.getToolkit().getScreenInsets(g); if (x + c.getWidth() > screenDim.width - insets.right) { x = (screenDim.width - insets.right) - c.getWidth(); } else if (x < insets.left) { x = insets.left; } if (y + c.getHeight() > screenDim.height - insets.bottom) { y = (screenDim.height - insets.bottom) - c.getHeight(); } else if (y < insets.top) { y = insets.top; } c.setLocation(x, y); } else { System.out.println("null"); } }
/** * Centers the given component on the user's screen. * * @param component a component (usually a frame.) */ public static void centerOnScreen(Component component) { Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit(); Dimension screenSize = toolkit.getScreenSize(); int screenWidth = (int) screenSize.getWidth(); int screenHeight = (int) screenSize.getHeight(); int componentWidth = component.getWidth(); int componentHeight = component.getHeight(); int top = (screenHeight - componentHeight) / 2; int left = (screenWidth - componentWidth) / 2; Utils.changeFrameLocation(component, left, top); }
private static void exportScreenshotEpsGraphics( Component target, File selectedFile, boolean paintOffscreen) throws IOException { if (!SnapshotUtilities.canExportScreenshotEps()) { String msg = "ERROR: EPS output requires EPSGraphics library. See https://www.broadinstitute.org/software/igv/third_party_tools#epsgraphics"; log.error(msg); return; } Graphics2D g = null; FileOutputStream fos = null; try { Class colorModeClass = RuntimeUtils.loadClassForName(EPSColorModeClassName, null); Class graphicsClass = RuntimeUtils.loadClassForName(EPSClassName, null); Constructor constructor = graphicsClass.getConstructor( String.class, OutputStream.class, int.class, int.class, int.class, int.class, colorModeClass); Object colorModeValue = Enum.valueOf(colorModeClass, "COLOR_RGB"); // EpsGraphics stores directly in a file fos = new FileOutputStream(selectedFile); g = (Graphics2D) constructor.newInstance( "eps", fos, 0, 0, target.getWidth(), target.getHeight(), colorModeValue); choosePaint(target, g, paintOffscreen); graphicsClass.getMethod("close").invoke(g); } catch (Exception e) { log.error(e.getMessage(), e); } finally { if (fos != null) { fos.flush(); fos.close(); } } }
public static final Component getChildAtLine( Container container, Point point, boolean horizontal) { if (horizontal) { for (int i = 0; i < container.getComponentCount(); i++) { Component component = container.getComponent(i); if (point.x >= component.getX() && point.x < component.getX() + component.getWidth()) return component; } } else { for (int i = 0; i < container.getComponentCount(); i++) { Component component = container.getComponent(i); if (point.y >= component.getY() && point.y < component.getY() + component.getHeight()) return component; } } return null; }
public static void fillComponent(Graphics g, Component c) { Graphics2D g2D = (Graphics2D) g; int w = c.getWidth(); int h = c.getHeight(); if (AbstractLookAndFeel.getTheme().isBackgroundPatternOn()) { // pattern Point p = JTattooUtilities.getRelLocation(c); Dimension d = JTattooUtilities.getFrameSize(c); int y = -p.y; while (y < h) { int x = -p.x; while (x < w) { BG_IMAGE.paintIcon(c, g, x, y); x += IMAGE_WIDTH; } y += IMAGE_HEIGHT; } if (JTattooUtilities.getJavaVersion() >= 1.6) { // higlight if (backgroundImage == null || backgroundImage.getWidth(null) != d.width || backgroundImage.getHeight(null) != d.height) { backgroundImage = c.createImage(d.width, d.height); Graphics2D ig2D = (Graphics2D) backgroundImage.getGraphics(); Point pt1 = new Point(0, 0); Point pt2 = new Point(d.width, 0); float fractions[] = {0.0f, 0.5f, 1.0f}; Color c1 = new Color(220, 220, 220); Color colors[] = {c1, Color.white, c1}; ig2D.setPaint(new LinearGradientPaint(pt1, pt2, fractions, colors)); ig2D.fillRect(0, 0, d.width, d.height); ig2D.dispose(); } Composite savedComposite = g2D.getComposite(); g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); g2D.drawImage(backgroundImage, -p.x, 0, null); g2D.setComposite(savedComposite); } } else { g.setColor(c.getBackground()); g.fillRect(0, 0, w, h); } }
public static void fillComponent(Graphics g, Component c, Icon texture) { int x = 0; int y = 0; int w = c.getWidth(); int h = c.getHeight(); if (texture != null) { int tw = texture.getIconWidth(); int th = texture.getIconHeight(); Point p = JTattooUtilities.getRelLocation(c); y = -p.y; while (y < h) { x = -p.x; while (x < w) { texture.paintIcon(c, g, x, y); x += tw; } y += th; } } else { g.setColor(c.getBackground()); g.fillRect(x, y, w, h); } }
static void fillRect(final Graphics g, final Component c) { fillRect(g, c, c.getBackground(), 0, 0, c.getWidth(), c.getHeight()); }
public static void paintInCenterOf(@NotNull Component c, Graphics g, Icon icon) { final int x = (c.getWidth() - icon.getIconWidth()) / 2; final int y = (c.getHeight() - icon.getIconHeight()) / 2; icon.paintIcon(c, g, x, y); }
private void findPaintableTabs() { Tab firstTab = null; Rectangle firstVisibleRect = null; Tab previousTab = null; int i = 0; boolean tabsFound = false; if (tabData.getTabbedPanel().isTabAreaVisible()) { while (i < tabData.getTabbedPanel().getTabCount()) { Tab tab = tabData.getTabbedPanel().getTabAt(i); Rectangle r = tab.getVisibleRect(); if (i == 0) { firstTab = tab; firstVisibleRect = r; } i++; if (r.width > 0 && r.height > 0) { tabsFound = true; tabData.getTabList().add(tab); tabData.getVisibleTabRects().add(r); if (tabData.getTabCount() == 1) tabData.setPreTab(previousTab); if (tab.isHighlighted()) { tabData.setSelectedTabPainterIndex(tabData.getTabCount() - 1); } } else if (!tabData.getTabList().isEmpty() && (r.width == 0 || r.height == 0)) tabData.setPostTab(tab); if (tabsFound && r.x == 0 && r.y == 0 && ((tabData.isHorizontalLayout() && r.width < tab.getWidth()) || (!tabData.isHorizontalLayout() && r.height < tab.getHeight()))) { break; } previousTab = tab; } if (firstTab != null) { // TODO: Ugly! Component box = findDraggableComponentBox(firstTab); if (box != null) { if (tabData.isHorizontalLayout()) { tabData.setTabAreaWidth(box.getWidth()); tabData.setTabAreaHeight(box.getParent().getHeight()); } else { tabData.setTabAreaWidth(box.getParent().getWidth()); tabData.setTabAreaHeight(box.getHeight()); } } if (tabData.getTabCount() == 0) { tabData.getTabList().add(firstTab); tabData.getVisibleTabRects().add(firstVisibleRect); } } } }
void doTest() throws Exception { ArrayList<Component> components = new ArrayList(); components.add(button); components.add(buttonLW); components.add(textField); components.add(textArea); components.add(list); components.add(listLW); int keys[]; String OS = System.getProperty("os.name").toLowerCase(); System.out.println(OS); if (OS.contains("os x") || OS.contains("sunos")) { keys = new int[] {KeyEvent.VK_SHIFT, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_META}; } else { keys = new int[] {KeyEvent.VK_SHIFT, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT}; } for (Component c : components) { System.out.print(c.getClass().getName() + ": "); Point origin = c.getLocationOnScreen(); int xc = origin.x + c.getWidth() / 2; int yc = origin.y + c.getHeight() / 2; Point center = new Point(xc, yc); robot.delay(robotDelay); robot.glide(origin, center); robot.click(); robot.delay(robotDelay); for (int k = 0; k < keys.length; ++k) { keyPressReceived = false; keyCode = keys[k]; robot.type(keyCode); robot.delay(robotDelay); if (!keyPressReceived) { synchronized (lock) { try { lock.wait(waitDelay); } catch (InterruptedException e) { } } } assertTrue(keyPressReceived, "key press event was not received"); } System.out.println("passed"); } robot.waitForIdle(); frame.dispose(); }
/*@Override*/ public void paintIcon(Component c, Graphics g, int x, int y) { final boolean expandToFit = (mWidth < 1); if (DEBUG.IMAGE && DEBUG.META) out( "paintIcon; onto=" + GUI.name(c) + " painter=" + GUI.name(mPainter) + "@" + Integer.toHexString((mPainter.hashCode()))); if (mPainter == null) { // note this means repaint updates would stop in a new parent, // tho assuming it's loaded by then, regular paints would work fine. mPainter = c; } if (DrawBorder && !expandToFit) { g.setColor(Color.gray); g.drawRect(x, y, mWidth - 1, mHeight - 1); } if (mImage == null) { if (!isLoading /*&& mPreviewData != null*/) { synchronized (this) { if (!isLoading /*&& mPreviewData != null*/) VUE.invokeAfterAWT(ResourceIcon.this); // load the preview } } g.setColor(Color.gray); g.drawRect(x, y, mWidth - 1, mHeight - 1); return; } int fitWidth, fitHeight; final Dimension maxImageSize; if (expandToFit) { // fill the given component fitWidth = c.getWidth(); fitHeight = c.getHeight(); maxImageSize = c.getSize(); } else { // paint at our fixed size fitWidth = mWidth; fitHeight = mHeight; if (DrawBorder) maxImageSize = new Dimension(fitWidth - BorderSpace * 2, fitHeight - BorderSpace * 2); else maxImageSize = new Dimension(fitWidth, fitHeight); if (DEBUG.IMAGE && DEBUG.META) out("paintIcon; into " + GUI.name(maxImageSize)); } double zoomFit; if (mImage == NoImage && expandToFit) { zoomFit = 1; } else { Rectangle2D imageBounds; if (CropToSquare) { // square off image, then fit in icon (todo: better; crop to icon) int smallestAxis = mImageWidth > mImageHeight ? mImageHeight : mImageWidth; imageBounds = new Rectangle2D.Float(0, 0, smallestAxis, smallestAxis); } else { // fit entire image in icon imageBounds = new Rectangle2D.Float(0, 0, mImageWidth, mImageHeight); } zoomFit = ZoomTool.computeZoomFit(maxImageSize, 0, imageBounds, null, false); if (zoomFit > MaxZoom) zoomFit = MaxZoom; } final int drawW = (int) (mImageWidth * zoomFit + 0.5); final int drawH = (int) (mImageHeight * zoomFit + 0.5); int xoff = x; int yoff = y; // center if drawable area is bigger than image if (drawW != fitWidth) xoff += (fitWidth - drawW) / 2; if (drawH != fitHeight) yoff += (fitHeight - drawH) / 2; Shape oldClip = null; if (CropToSquare && !expandToFit) { oldClip = g.getClip(); g.clipRect(x, y, mWidth, mHeight); } if (DEBUG.IMAGE && DEBUG.META) out("paintIcon; " + Util.tag(mImage) + " as " + drawW + "x" + drawH); g.drawImage(mImage, xoff, yoff, drawW, drawH, null); if (DEBUG.BOXES) { g.setColor(Color.green); ((Graphics2D) g) .setComposite( java.awt.AlphaComposite.getInstance(java.awt.AlphaComposite.SRC_OVER, 0.2f)); g.drawRect(x, y, mWidth - 1, mHeight - 1); ((Graphics2D) g).setComposite(java.awt.AlphaComposite.SrcOver); } if (CropToSquare && !expandToFit) g.setClip(oldClip); }