public static void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { g = g.create(x, y, width, height); // corners TL.paintIcon(c, g, x, y); BL.paintIcon(c, g, x, y + height - BL.getIconHeight()); TR.paintIcon(c, g, x + width - TR.getIconWidth(), y); BR.paintIcon(c, g, x + width - BR.getIconWidth(), y + height - BR.getIconHeight()); // top and bottom lines int xOffset = x + TL.getIconWidth(); int stop = x + width - TR.getIconWidth(); int top = y; int bottom = y + height - B.getIconHeight(); g.setClip(xOffset, y, width - L.getIconWidth() - R.getIconWidth(), height); while (xOffset < stop) { T.paintIcon(c, g, xOffset, top); B.paintIcon(c, g, xOffset, bottom); xOffset += T.getIconWidth(); } // left and right lines int left = x; int right = x + width - R.getIconWidth(); int yOffset = y + T.getIconHeight(); stop = y + height - B.getIconHeight(); g.setClip(x, yOffset, width, height - T.getIconHeight() - B.getIconHeight()); while (yOffset < stop) { L.paintIcon(c, g, left, yOffset); R.paintIcon(c, g, right, yOffset); yOffset += L.getIconHeight(); } g.dispose(); }
/** * Paint this window. This method should not generally be overridden by subclasses. This method * carefully stores the clip, translation, and color before calling into subclasses. The graphics * context should be translated such that it is in this window's coordinate space (0,0 is the top * left corner of this window). * * @param g The graphics object to use to paint this window. * @param refreshQ The custom queue which holds the set of refresh regions needing to be blitted * to the screen */ public void paint(Graphics g, CGraphicsQ refreshQ) { // We reset our dirty flag first. Any layers that become // dirty in the duration of this method will then cause it // to toggle back to true for the subsequent pass. // IMPL NOTE: when layers start to do complex animation, there will // likely need to be better atomic handling of the dirty state, // and layers becoming dirty and getting painted this.dirty = false; // Store the clip, translate, font, color cX = g.getClipX(); cY = g.getClipY(); cW = g.getClipWidth(); cH = g.getClipHeight(); tranX = g.getTranslateX(); tranY = g.getTranslateY(); font = g.getFont(); color = g.getColor(); // We set the basic clip to the size of this window g.setClip(bounds[X], bounds[Y], bounds[W], bounds[H]); synchronized (layers) { sweepAndMarkLayers(); copyAndCleanDirtyLayers(); } paintLayers(g, refreshQ); // We restore the original clip. The original font, color, etc. // have already been restored g.setClip(cX, cY, cW, cH); }
public static void paintComponentDecoration( final GuiEditor editor, final RadComponent component, final Graphics g) { // Collect selected components and paint decoration for non selected components final ArrayList<RadComponent> selection = new ArrayList<RadComponent>(); final Rectangle layeredPaneRect = editor.getLayeredPane().getVisibleRect(); FormEditingUtil.iterate( component, new FormEditingUtil.ComponentVisitor<RadComponent>() { public boolean visit(final RadComponent component) { if (!component.getDelegee().isShowing()) { // Skip invisible components return true; } final Shape oldClip = g.getClip(); final RadContainer parent = component.getParent(); if (parent != null) { final Point p = SwingUtilities.convertPoint( component.getDelegee(), 0, 0, editor.getLayeredPane()); final Rectangle visibleRect = layeredPaneRect.intersection( new Rectangle(p.x, p.y, parent.getWidth(), parent.getHeight())); g.setClip(visibleRect); } if (component.isSelected()) { // we will paint selection later selection.add(component); } else { paintComponentBoundsImpl(editor, component, g); } paintGridOutline(editor, component, g); if (parent != null) { g.setClip(oldClip); } return true; } }); // Let's paint decoration for selected components for (int i = selection.size() - 1; i >= 0; i--) { final Shape oldClip = g.getClip(); final RadComponent c = selection.get(i); final RadContainer parent = c.getParent(); if (parent != null) { final Point p = SwingUtilities.convertPoint(c.getDelegee(), 0, 0, editor.getLayeredPane()); final Rectangle visibleRect = layeredPaneRect.intersection( new Rectangle(p.x, p.y, parent.getWidth(), parent.getHeight())); g.setClip(visibleRect); } paintComponentBoundsImpl(editor, c, g); if (parent != null) { g.setClip(oldClip); } } }
public static Image createThumbnail(Image image, int width, int height) { int sourceWidth = image.getWidth(); int sourceHeight = image.getHeight(); if ((width > sourceWidth) && (height > sourceHeight)) { return image; } int thumbWidth = width; int thumbHeight = thumbWidth * sourceHeight / sourceWidth; if (thumbHeight > height) { thumbHeight = height; thumbWidth = thumbHeight * sourceWidth / sourceHeight; } // #sijapp cond.if modules_ANDROID is "true"# Image scaled = image.scale(thumbWidth, thumbHeight); if (null != scaled) return scaled; // #sijapp cond.end# Image thumb = Image.createImage(thumbWidth, thumbHeight); Graphics g = thumb.getGraphics(); for (int y = 0; y < thumbHeight; ++y) { for (int x = 0; x < thumbWidth; ++x) { g.setClip(x, y, 1, 1); int dx = x * sourceWidth / thumbWidth; int dy = y * sourceHeight / thumbHeight; g.drawImage(image, x - dx, y - dy, Graphics.LEFT | Graphics.TOP); } } return thumb; }
public void setClip(Graphics g) { if (g == null) return; int scaleHeight = mHeight; scaleHeight -= (mBottom + mTop); int scaleWidth = mWidth; scaleWidth -= (mLeft + mRight); g.setClip(mLeft, mTop, scaleWidth, scaleHeight); }
@Override public void print(Graphics g) { // We assume we print the whole frame, // so we expect no clip was set previously Shape shape = AWTAccessor.getWindowAccessor().getShape((Window) target); if (shape != null) { g.setClip(shape); } super.print(g); }
private void paintDragDivider(Graphics g, int x, int y, int w, int h) { SynthContext context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER); context.setComponentState(((context.getComponentState() | MOUSE_OVER) ^ MOUSE_OVER) | PRESSED); Shape oldClip = g.getClip(); g.clipRect(x, y, w, h); context .getPainter() .paintSplitPaneDragDivider(context, g, x, y, w, h, splitPane.getOrientation()); g.setClip(oldClip); context.dispose(); }
/** * Scale an image to the given width and height. * * <p><b>Be aware that resizing an image is very CPU intensive, therefore use this method with * care. </b> * * @param src the source image that needs to be resized * @return a new image object that contains the resized image */ public static final Image resizeImage(Image src, int width, int height) { // check if it is absolutely necessary to resize the image if (src.getWidth() != width && src.getHeight() != height) { int srcW = src.getWidth(); int srcH = src.getHeight(); // create temporary image object Image tmp = Image.createImage(width, srcH); Graphics g = tmp.getGraphics(); // calculate new width int delta = (srcW << 16) / width; int pos = delta / 2; // perform resize operation (horizontally) for (int x = 0; x < width; x++) { g.setClip(x, 0, 1, srcH); g.drawImage(src, x - (pos >> 16), 0, Graphics.LEFT | Graphics.TOP); pos += delta; } // create temporary image object Image dst = Image.createImage(width, height); g = dst.getGraphics(); // calculate new height delta = (srcH << 16) / height; pos = delta / 2; // perform resize operation (vertically) for (int y = 0; y < height; y++) { g.setClip(0, y, width, 1); g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT | Graphics.TOP); pos += delta; } return dst; } else { return src; } }
public void draw() { Graphics g = environment.getScreenHandler().getCurrentGraphics(); g.clearRect( 0, 0, environment.getScreenHandler().getWidth(), environment.getScreenHandler().getHeight()); fps.update(); fps.draw(g, Color.red, 10, 10); g.setColor(Color.white); g.drawString(model.getInfoString(), 50, 10); g.setColor(Color.white); if (cheatMode) { g.setColor(Color.white); g.drawString("CHEATMODE", 80, 10); } g.setClip(cont.getOffsetX(), cont.getOffsetY(), cont.getDrawingSizeX(), cont.getDrawingSizeY()); if (model.isInitialized()) { model.getMap().draw(g, 0); model.getMyCar().draw(g, 0); CarDrawInterface cars[] = model.getOpponentCars(); for (int i = 0; i < cars.length; i++) { cars[i].draw(g, 0); } if (!model.isStarted()) { g.setColor(Color.white); g.clearRect(50, 50, 400, 150); g.drawString("Accellerate to start game", 100, 100); if (model.isMultiplayer()) { if (model.getNoOfHumanCars() > 1) { g.drawString( "Currently " + (model.getNoOfHumanCars() - 1) + " other human player(s) connected", 100, 120); } else { g.drawString("Only you and computer contolled cars are connected", 100, 120); } g.drawString("You can wait for more human players to connect", 100, 140); } } } else { g.setColor(Color.white); g.clearRect(50, 50, 400, 150); g.drawString("Loading game data, please wait...", 100, 100); } }
/** * Second Pass: We sweep through the layers from the bottom to the top and paint each one that is * marked as dirty * * <p>Note, that the painting for copied layers is done here to not hold the layers lock during * the painting. * * @param g The graphics object to use to paint this window. * @param refreshQ The custom queue which holds the set of refresh regions needing to be blitted * to the screen */ private void paintLayers(Graphics g, CGraphicsQ refreshQ) { if (CGraphicsQ.DEBUG) { System.err.println("[Paint dirty layers]"); } for (int i = 0; i < dirtyCount; i++) { CLayer l = dirtyLayers[i]; // Prepare relative dirty region coordinates // of the current layer int dx = l.dirtyBoundsCopy[X]; int dy = l.dirtyBoundsCopy[Y]; int dw = l.dirtyBoundsCopy[W]; int dh = l.dirtyBoundsCopy[H]; // Before we call into the layer to paint, we // translate the graphics context into the layer's // coordinate space g.translate(l.boundsCopy[X], l.boundsCopy[Y]); if (CGraphicsQ.DEBUG) { System.err.println("Painting Layer: " + l); System.err.println("\tClip: " + dx + ", " + dy + ", " + dw + ", " + dh); } // Clip the graphics to only contain the dirty region of // the layer (if the dirty region isn't set, clip to the // whole layer contents). g.clipRect(dx, dy, dw, dh); refreshQ.queueRefresh(l.boundsCopy[X] + dx, l.boundsCopy[Y] + dy, dw, dh); l.paint(g); // We restore our graphics context to prepare // for the next layer g.translate(-g.getTranslateX(), -g.getTranslateY()); g.translate(tranX, tranY); // We reset our clip to this window's bounds again. g.setClip(bounds[X], bounds[Y], bounds[W], bounds[H]); g.setFont(font); g.setColor(color); } // for }
public void update(Graphics g) { Dimension size = getSize(); if (offscreen == null) offscreen = createImage((size.width < 1) ? 1 : size.width, (size.height < 1) ? 1 : size.height); Graphics og = offscreen.getGraphics(); if (og != null) try { og.setClip(g.getClip()); og.setColor(getBackground()); og.fillRect(0, 0, size.width, size.height); super.paint(og); } finally { og.dispose(); } paint(g); }
protected void paintComponent(Graphics g) { super.paintComponent(g); if (painter != null) { Shape shape = getShape(); if (shape != null) { Shape clip = g.getClip(); g.clipRect( shapedInsets.left, shapedInsets.top, getWidth() - shapedInsets.left - shapedInsets.right, getHeight() - shapedInsets.top - shapedInsets.bottom); ((Graphics2D) g).clip(shape); painter.paint( this, g, 0, 0, getWidth(), getHeight(), direction, horizontalFlip, verticalFlip); g.setClip(clip); } else painter.paint( this, g, 0, 0, getWidth(), getHeight(), direction, horizontalFlip, verticalFlip); } }
/** * Paint the glyphs for the given view. This is implemented to only render if the Graphics is of * type Graphics2D which is required by TextLayout (and this should be the case if running on the * JDK). */ public void paint(GlyphView v, Graphics g, Shape a, int p0, int p1) { if (g instanceof Graphics2D) { Rectangle2D alloc = a.getBounds2D(); Graphics2D g2d = (Graphics2D) g; float y = (float) alloc.getY() + layout.getAscent() + layout.getLeading(); float x = (float) alloc.getX(); if (p0 > v.getStartOffset() || p1 < v.getEndOffset()) { try { // TextLayout can't render only part of it's range, so if a // partial range is required, add a clip region. Shape s = v.modelToView(p0, Position.Bias.Forward, p1, Position.Bias.Backward, a); Shape savedClip = g.getClip(); g2d.clip(s); layout.draw(g2d, x, y); g.setClip(savedClip); } catch (BadLocationException e) { } } else { layout.draw(g2d, x, y); } } }
/** * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public final void render(GameContainer container, Graphics g) throws SlickException { int yoffset = 0; int xoffset = 0; if (targetHeight < container.getHeight()) { yoffset = (container.getHeight() - targetHeight) / 2; } if (targetWidth < container.getWidth()) { xoffset = (container.getWidth() - targetWidth) / 2; } SlickCallable.enterSafeBlock(); g.setClip(xoffset, yoffset, targetWidth, targetHeight); GL.glTranslatef(xoffset, yoffset, 0); g.scale(targetWidth / normalWidth, targetHeight / normalHeight); GL.glPushMatrix(); held.render(container, g); GL.glPopMatrix(); g.clearClip(); SlickCallable.leaveSafeBlock(); renderOverlay(container, g); }
public void paint(Graphics g) { mar.paintfill(g); fondomar.paintfull(g, 0, 108); fondomar.paintfull(g, 65, 108); // nube.paintfull(g,barco_x/2,0); radar.paintfull(g, 45, 0); // redspike.paintfull(g,20+(barco_x/4),5); // barco.paint(g,barco_x,barco_y,0); // barco.paintfull(g,barco_x,barco_y); // g.setColor(255,255,255); // g.drawString ("intro", // barco_x, barco_y, Graphics.TOP|Graphics.LEFT); // submarino.paintfull(g,submarino.x,submarino.y); // torpedo.paintfull(g,torpedo.x,torpedo.y); // barco2.draw(g); midlet.instancemanager.draw(g); // midlet.actormanager.draw(g); // midlet.bulletmanager.draw(g); g.setClip(0, 0, 100, 100); // g.drawString("Ready: " + cargaslistas,0,0, Graphics.TOP|Graphics.LEFT); g.drawString("" + (maxcargas - cargaslanzadas), 95, 0, Graphics.TOP | Graphics.LEFT); g.drawString("T:" + (gametime / 1000), 0, 10, Graphics.TOP | Graphics.LEFT); int i; int cx = 0; for (i = 0; i < cargaslistas; i++) { indicarga.paintfull(g, cx, 0); cx += 5; } drawradar(g); }
/** Overrides <code>Graphics.setClip</code>. */ public void setClip(int x, int y, int width, int height) { graphics.setClip(x, y, width, height); if (debugLog()) { info().log(toShortString() + " Setting new clipRect: " + graphics.getClip()); } }
/** Overrides <code>Graphics.setClip</code>. */ public void setClip(Shape clip) { graphics.setClip(clip); if (debugLog()) { info().log(toShortString() + " Setting new clipRect: " + graphics.getClip()); } }
private EditorFragmentComponent( EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) { Document doc = editor.getDocument(); final int endOffset = endLine < doc.getLineCount() ? doc.getLineEndOffset(endLine) : doc.getTextLength(); int textWidth = Math.min( editor.getMaxWidthInRange(doc.getLineStartOffset(startLine), endOffset), ScreenUtil.getScreenRectangle(1, 1).width); LOG.assertTrue( textWidth > 0, "TextWidth: " + textWidth + "; startLine:" + startLine + "; endLine:" + endLine + ";"); FoldingModelEx foldingModel = editor.getFoldingModel(); boolean isFoldingEnabled = foldingModel.isFoldingEnabled(); if (!showFolding) { foldingModel.setFoldingEnabled(false); } Point p1 = editor.logicalPositionToXY(new LogicalPosition(startLine, 0)); Point p2 = editor.logicalPositionToXY(new LogicalPosition(Math.max(endLine, startLine + 1), 0)); int y1 = p1.y; int y2 = p2.y; int height = y2 - y1 == 0 ? editor.getLineHeight() : y2 - y1; LOG.assertTrue( height > 0, "Height: " + height + "; startLine:" + startLine + "; endLine:" + endLine + "; p1:" + p1 + "; p2:" + p2); int savedScrollOffset = editor.getScrollingModel().getHorizontalScrollOffset(); if (savedScrollOffset > 0) { editor.stopOptimizedScrolling(); editor.getScrollingModel().scrollHorizontally(0); } final Image textImage = new BufferedImage(textWidth, height, BufferedImage.TYPE_INT_RGB); Graphics textGraphics = textImage.getGraphics(); final JComponent rowHeader; final Image markersImage; if (showGutter) { rowHeader = editor.getGutterComponentEx(); markersImage = new BufferedImage(Math.max(1, rowHeader.getWidth()), height, BufferedImage.TYPE_INT_RGB); Graphics markerGraphics = markersImage.getGraphics(); markerGraphics.translate(0, -y1); markerGraphics.setClip(0, y1, rowHeader.getWidth(), height); markerGraphics.setColor(getBackgroundColor(editor)); markerGraphics.fillRect(0, y1, rowHeader.getWidth(), height); rowHeader.paint(markerGraphics); } else { rowHeader = null; markersImage = null; } textGraphics.translate(0, -y1); textGraphics.setClip(0, y1, textWidth, height); final boolean wasVisible = editor.setCaretVisible(false); editor.setPurePaintingMode(true); try { editor.getContentComponent().paint(textGraphics); } finally { editor.setPurePaintingMode(false); } if (wasVisible) { editor.setCaretVisible(true); } if (!showFolding) { foldingModel.setFoldingEnabled(isFoldingEnabled); } if (savedScrollOffset > 0) { editor.stopOptimizedScrolling(); editor.getScrollingModel().scrollHorizontally(savedScrollOffset); } JComponent component = new JComponent() { public Dimension getPreferredSize() { return new Dimension( textImage.getWidth(null) + (markersImage == null ? 0 : markersImage.getWidth(null)), textImage.getHeight(null)); } protected void paintComponent(Graphics graphics) { if (markersImage != null) { graphics.drawImage(markersImage, 0, 0, null); graphics.drawImage(textImage, rowHeader.getWidth(), 0, null); } else { graphics.drawImage(textImage, 0, 0, null); } } }; setLayout(new BorderLayout()); add(component); final Color borderColor = editor.getColorsScheme().getColor(EditorColors.SELECTED_TEARLINE_COLOR); Border outsideBorder = BorderFactory.createLineBorder(borderColor, 1); Border insideBorder = BorderFactory.createEmptyBorder(2, 2, 2, 2); setBorder(BorderFactory.createCompoundBorder(outsideBorder, insideBorder)); }
public void paintIcon(Component c, Graphics g, int x, int y) { Shape old = g.getClip(); g.clipRect(x, y + myDelegate.getIconHeight() - 2 - myHeight, myWidth, myHeight + 2); myDelegate.paintIcon(c, g, x, y); g.setClip(old); }
@Override public void paint(Graphics g, JComponent c) { if (!(c.getBorder() instanceof MacIntelliJButtonBorder) && !isComboButton(c)) { super.paint(g, c); return; } int w = c.getWidth(); int h = c.getHeight(); if (isHelpButton(c)) { Icon icon = MacIntelliJIconCache.getIcon("helpButton", false, c.hasFocus()); int x = (w - icon.getIconWidth()) / 2; int y = (h - icon.getIconHeight()) / 2; icon.paintIcon(c, g, x, y); } else { AbstractButton b = (AbstractButton) c; String text = layout(b, SwingUtilities2.getFontMetrics(b, g), b.getWidth(), b.getHeight()); boolean isFocused = c.hasFocus(); if (isSquare(c)) { Icon icon = MacIntelliJIconCache.getIcon("browseButton"); int x = (c.getWidth() - icon.getIconWidth()) / 2; int y = (c.getHeight() - icon.getIconHeight()) / 2; icon.paintIcon(c, g, x, y); return; } else { int x = isFocused ? 0 : 2; int y = isFocused ? 0 : (h - viewRect.height) / 2; Icon icon; icon = getLeftIcon(b); icon.paintIcon(b, g, x, y); x += icon.getIconWidth(); int stop = w - (isFocused ? 0 : 2) - (getRightIcon(b).getIconWidth()); Graphics gg = g.create(0, 0, w, h); gg.setClip(x, y, stop - x, h); icon = getMiddleIcon(b); while (x < stop) { icon.paintIcon(b, gg, x, y); x += icon.getIconWidth(); } gg.dispose(); icon = getRightIcon(b); icon.paintIcon(b, g, stop, y); clearTextShiftOffset(); } // Paint the Icon if (b.getIcon() != null) { paintIcon(g, c, iconRect); } if (text != null && !text.isEmpty()) { View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, textRect); } else { UISettings.setupAntialiasing(g); paintText(g, b, textRect, text); } } } }
public static void cleanScreen(Graphics g) { g.setClip(0, 0, GameData.getGameData().screenWidth, GameData.getGameData().screenHeight); g.setColor(0); g.fillRect(0, 0, GameData.getGameData().screenWidth, GameData.getGameData().screenHeight); }
public void paintTabArea(TabbedPanel tp, Graphics g, int x, int y, int width, int height) { int heightTemp = height; int widthTemp = width; int xTemp = x; int yTemp = y; if (enabled && tp.isTabAreaVisible()) { tabData.initialize(tp); PanePainter pane = paneHandler.getPainter(tabData.getAreaOrientation()); initTabLocations(pane); Insets aInsets = getTabAreaInsets(tabData.getAreaOrientation()); if (tp.getTabCount() > 0) { // Adjust x, y if (tabData.getAreaOrientation() == Direction.DOWN) { yTemp += tabData.getTabbedPanelHeight() - heightTemp; } else if (tabData.getAreaOrientation() == Direction.RIGHT) { xTemp += tabData.getTabbedPanelWidth() - widthTemp; } widthTemp = xTemp < 0 ? widthTemp + xTemp : widthTemp; heightTemp = yTemp < 0 ? heightTemp + yTemp : heightTemp; xTemp = Math.max(0, xTemp); yTemp = Math.max(0, yTemp); if (tabData.isHorizontalLayout()) pane.setSize(tabData.getTabbedPanelSize().width, getTabbedPanelExtraSize()); else pane.setSize(getTabbedPanelExtraSize(), tabData.getTabbedPanelHeight()); if (PAINT_TAB_AREA && !(pane.getTabCount() == 0 && tabData.getTabCount() > 0)) { Shape originalClip = g.getClip(); int tx = -xTemp - (tabData.getAreaOrientation() == Direction.RIGHT ? -tabData.getTabbedPanelWidth() + getTabbedPanelExtraSize() : 0); int ty = -yTemp - (tabData.getAreaOrientation() == Direction.DOWN ? -tabData.getTabbedPanelHeight() + getTabbedPanelExtraSize() : 0); Rectangle firstVisibleRect = (Rectangle) tabData.getVisibleTabRects().get(0); Rectangle lastVisibleRect = (Rectangle) tabData.getVisibleTabRects().get(tabData.getTabCount() - 1); Tab lastTab = (Tab) tabData.getTabList().get(tabData.getTabCount() - 1); if (tabData.isHorizontalLayout()) { int extraWidth = lastTab.getWidth() == lastVisibleRect.width ? 0 : 2 * tabData.getTabbedPanelSize().width - tabData.getTabAreaWidth(); pane.setSize(pane.getWidth() + extraWidth, pane.getHeight()); pane.doValidation(); // Before tabs g.clipRect( 0, 0, aInsets.left + (firstVisibleRect.width > 0 && firstVisibleRect.x == 0 ? 1 : 0), heightTemp); pane.paint(g, tx, ty); g.setClip(originalClip); // After tabs tx -= extraWidth; int clipExtraWidth = extraWidth == 0 ? 1 : 0; g.clipRect( aInsets.left + tabData.getTabAreaWidth() - clipExtraWidth, 0, widthTemp - aInsets.left - tabData.getTabAreaWidth() + clipExtraWidth, heightTemp); pane.paint(g, tx, ty); g.setClip(originalClip); } else { int extraHeight = lastTab.getHeight() == lastVisibleRect.height ? 0 : 2 * tabData.getTabbedPanelSize().height - tabData.getTabAreaHeight(); pane.setSize(pane.getWidth(), pane.getHeight() + extraHeight); pane.doValidation(); // Before tabs g.clipRect( 0, 0, widthTemp, aInsets.top + (firstVisibleRect.height > 0 && firstVisibleRect.y == 0 ? 1 : 0)); pane.paint(g, tx, ty); g.setClip(originalClip); // After tabs ty -= extraHeight; int clipExtraHeight = extraHeight == 0 ? 1 : 0; g.clipRect( 0, aInsets.top + tabData.getTabAreaHeight() - clipExtraHeight, widthTemp, heightTemp - aInsets.top - tabData.getTabAreaHeight() + clipExtraHeight); pane.paint(g, tx, ty); g.setClip(originalClip); } } // First and last tab paintTabs(pane, tabData, g, xTemp, yTemp, widthTemp, heightTemp); tabData.reset(); reset(pane); } } }
public void paint(Graphics g) { g.setColor(255, 255, 255); g.fillRect(0, 0, maxX, maxY); g.setColor(0, 0, 0); // This vertical line start at x/2 position g.fillRect((this.maxX / 3) - 1, 0, 3, this.maxY); // This vertical line start at 2x/3 position g.fillRect(((2 * this.maxX) / 3) - 1, 0, 3, this.maxY); // This horizontal line start at this.maxY / 3 - 1 position g.fillRect(0, (this.maxY / 3) - 1, this.maxX, 3); // This horaizental line start at this.maxY / 3 - 1 position g.fillRect(0, ((2 * this.maxY) / 3) - 1, this.maxX, 3); // Drawing the selecting rectangle g.setColor(255, 0, 0); g.drawRect( ((this.colSelected * this.maxX) / 3) - 1, ((this.rowSelected * this.maxY) / 3) - 1, (this.maxX / 3) + 2, (this.maxY / 3) + 2); g.drawRect( (this.colSelected * this.maxX / 3), (this.rowSelected * this.maxY / 3), this.maxX / 3, this.maxY / 3); g.drawRect( (this.colSelected * this.maxX / 3) + 1, (this.rowSelected * this.maxY / 3) + 1, (this.maxX / 3) - 2, (this.maxY / 3) - 2); // Setting X variable for proper placement int refX = ((this.maxX / 3) - this.imgWidth) / 2; int refY = ((this.maxY / 3) - this.imgHeight) / 2; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (this.sq[i][j] == 0) { g.setClip( (i * this.maxX / 3) + refX, (j * this.maxY / 3) + refY, this.imgWidth, this.imgHeight); g.drawImage( this.zeroImage, ((i * this.maxX / 3) + refX) - this.frame * this.imgWidth, (j * this.maxY / 3) + refY, Graphics.TOP | Graphics.LEFT); } else if (this.sq[i][j] == 1) { g.setClip( (i * this.maxX / 3) + refX, (j * this.maxY / 3) + refY, this.imgWidth, this.imgHeight); g.drawImage( this.crossImage, ((i * this.maxX / 3) + refX) - this.frame * this.imgWidth, (j * this.maxY / 3) + refY, Graphics.TOP | Graphics.LEFT); } g.setClip(0, 0, this.maxX, this.maxY); } } }
/*@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); }
public void drawItem(Graphics g, int offset, boolean selected, boolean drawsec) { // g.setColor(0); boolean ralign = false; boolean underline = false; // #if NICK_COLORS // # boolean nick=false; // #endif int w = offset; int dw; int imageYOfs = ((getVHeight() - imgHeight()) >> 1); // #if ALCATEL_FONT // # int fontYOfs=(( getVHeight()-font.getHeight() )>>1) +1; // #else int fontYOfs = ((getVHeight() - font.getHeight()) >> 1); // #endif int imgWidth = imgWidth(); g.setFont(font); for (int index = 0; index < elementCount; index++) { Object ob = elementData[index]; if (ob != null) { if (ob instanceof String) { // string element String s = (String) ob; // #if NICK_COLORS // # if (nick) { // # int color=g.getColor(); // # dw=0; // # int p1=0; // # while (p1<s.length()) { // # int p2=p1; // # char c1=s.charAt(p1); // # //processing the same cp // # while (p2<s.length()) { // # char c2=s.charAt(p2); // # if ( (c1&0xff00) != (c2 &0xff00) ) break; // # p2++; // # } // # g.setColor( (c1>255) ? ColorScheme.strong(color) : // color); // # dw=font.substringWidth(s, p1, p2-p1); // # if (ralign) w-=dw; // # g.drawSubstring( s, p1, p2-p1, // # w,fontYOfs,Graphics.LEFT|Graphics.TOP); // # if (!ralign) w+=dw; // # p1=p2; // # } // # // # g.setColor(color); // # } else { // #endif dw = font.stringWidth(s); if (ralign) w -= dw; g.drawString(s, w, fontYOfs, Graphics.LEFT | Graphics.TOP); if (underline) { int y = getVHeight() - 1; g.drawLine(w, y, w + dw, y); underline = false; } if (!ralign) w += dw; // #if NICK_COLORS // # } // #endif } else if ((ob instanceof Integer)) { // image element or color int i = ((Integer) ob).intValue(); switch (i & 0xff000000) { case IMAGE: if (imageList == null) break; if (ralign) w -= imgWidth; imageList.drawImage(g, ((Integer) ob).intValue(), w, imageYOfs); if (!ralign) w += imgWidth; break; case COLOR: g.setColor(0xFFFFFF & i); break; case RALIGN: ralign = true; w = g.getClipWidth() - 1; break; case UNDERLINE: underline = true; break; // #if NICK_COLORS // # case NICK_ON: // # nick=true; // # break; // # case NICK_OFF: // # nick=false; // # break; // #endif } } /* Integer*/ else if (ob instanceof VirtualElement) { int clipw = g.getClipWidth(); int cliph = g.getClipHeight(); ((VirtualElement) ob).drawItem(g, 0, false, false); g.setClip(g.getTranslateX(), g.getTranslateY(), clipw, cliph); // TODO: рисование не с нулевой позиции и вычисление ширины } } // if ob!=null } // for }
private void paintTabs( PanePainter pane, TabData tabData, Graphics g, int x, int y, int width, int height) { if (enabled && PAINT_TAB) { Tab lastTab = (Tab) tabData.getTabList().get(tabData.getTabList().size() - 1); Rectangle lastVisibleRect = (Rectangle) tabData.getVisibleTabRects().get(tabData.getTabCount() - 1); // Fix post/pre tabs initPaintableTabLocations(pane); Insets aInsets = getTabAreaInsets(tabData.getAreaOrientation()); Point l = getLocationInTabbedPanel(lastTab, tabData.getTabbedPanel()); if (tabData.isHorizontalLayout()) { int w = aInsets.left + aInsets.right + Math.max(0, tabData.getTabAreaWidth() - l.x - lastVisibleRect.width) + EXTRA_SIZE; for (int i = 0; i < tabData.getTabList().size(); i++) w += ((Tab) tabData.getTabList().get(i)).getWidth(); pane.setSize(w, getTabbedPanelExtraSize()); } else { int h = aInsets.top + aInsets.bottom + Math.max(0, tabData.getTabAreaHeight() - l.y - lastVisibleRect.height) + EXTRA_SIZE; for (int i = 0; i < tabData.getTabList().size(); i++) h += ((Tab) tabData.getTabList().get(i)).getHeight(); pane.setSize(getTabbedPanelExtraSize(), h); } pane.doValidation(); int index = tabData.getPreTab() == null ? 0 : tabData.getTabCount() > 1 ? 1 : 0; Shape originalClip = g.getClip(); int tx = -x - (tabData.getAreaOrientation() == Direction.RIGHT ? -tabData.getTabbedPanelWidth() + getTabbedPanelExtraSize() : 0); int ty = -y - (tabData.getAreaOrientation() == Direction.DOWN ? -tabData.getTabbedPanelHeight() + getTabbedPanelExtraSize() : 0); Rectangle visibleRect = (Rectangle) tabData.getVisibleTabRects().get(index); Tab tab = (Tab) tabData.getTabList().get(index); if (tabData.isHorizontalLayout()) { tx -= (tabData.getPreTab() != null ? tab.getX() - tabData.getPreTab().getX() + visibleRect.x : visibleRect.x); g.clipRect(aInsets.left, 0, tabData.getTabAreaWidth(), height); } else { ty -= (tabData.getPreTab() != null ? tab.getY() - tabData.getPreTab().getY() + visibleRect.y : visibleRect.y); g.clipRect(0, aInsets.top, width, tabData.getTabAreaHeight()); } applyFocusAndHover(pane, true); pane.paint(g, tx, ty); applyFocusAndHover(pane, false); g.setClip(originalClip); } }
public final void paint(final Graphics g) { final Rectangle bounds = getBounds(); if (myAnchor == ToolWindowAnchor.LEFT) { if (myDirection == 1) { g.setClip(null); g.clipRect(myOffset, 0, bounds.width - myOffset, bounds.height); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, 0, myOffset, bounds.height); UIUtil.drawImage(g, myTopImage, myOffset - bounds.width, 0, null); } else { g.setClip(null); g.clipRect(bounds.width - myOffset, 0, myOffset, bounds.height); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, 0, bounds.width - myOffset, bounds.height); UIUtil.drawImage(g, myTopImage, -myOffset, 0, null); } myTopImage.flush(); } else if (myAnchor == ToolWindowAnchor.RIGHT) { if (myDirection == 1) { g.setClip(null); g.clipRect(0, 0, bounds.width - myOffset, bounds.height); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(bounds.width - myOffset, 0, myOffset, bounds.height); UIUtil.drawImage(g, myTopImage, bounds.width - myOffset, 0, null); } else { g.setClip(null); g.clipRect(0, 0, myOffset, bounds.height); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(myOffset, 0, bounds.width - myOffset, bounds.height); UIUtil.drawImage(g, myTopImage, myOffset, 0, null); } } else if (myAnchor == ToolWindowAnchor.TOP) { if (myDirection == 1) { g.setClip(null); g.clipRect(0, myOffset, bounds.width, bounds.height - myOffset); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, 0, bounds.width, myOffset); UIUtil.drawImage(g, myTopImage, 0, -bounds.height + myOffset, null); } else { g.setClip(null); g.clipRect(0, bounds.height - myOffset, bounds.width, myOffset); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, 0, bounds.width, bounds.height - myOffset); UIUtil.drawImage(g, myTopImage, 0, -myOffset, null); } } else if (myAnchor == ToolWindowAnchor.BOTTOM) { if (myDirection == 1) { g.setClip(null); g.clipRect(0, 0, bounds.width, bounds.height - myOffset); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, bounds.height - myOffset, bounds.width, myOffset); UIUtil.drawImage(g, myTopImage, 0, bounds.height - myOffset, null); } else { g.setClip(null); g.clipRect(0, 0, bounds.width, myOffset); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, myOffset, bounds.width, bounds.height - myOffset); UIUtil.drawImage(g, myTopImage, 0, myOffset, null); } } }
/** * Paints the border for the specified component with the specified position and size. * * @param c the component for which this border is being painted * @param g the paint graphics * @param x the x position of the painted border * @param y the y position of the painted border * @param width the width of the painted border * @param height the height of the painted border */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Border border = getBorder(); if (label == null) { if (border != null) { border.paintBorder(c, g, x, y, width, height); } return; } Rectangle grooveRect = new Rectangle( x + EDGE_SPACING, y + EDGE_SPACING, width - (EDGE_SPACING * 2), height - (EDGE_SPACING * 2)); Dimension labelDim = label.getPreferredSize(); int baseline = label.getBaseline(labelDim.width, labelDim.height); int ascent = Math.max(0, baseline); int descent = labelDim.height - ascent; int diff; Insets insets; if (border != null) { insets = border.getBorderInsets(c); } else { insets = new Insets(0, 0, 0, 0); } diff = Math.max(0, ascent / 2 + TEXT_SPACING - EDGE_SPACING); grooveRect.y += diff; grooveRect.height -= diff; compLoc.y = grooveRect.y + insets.top / 2 - (ascent + descent) / 2 - 1; int justification; if (c.getComponentOrientation().isLeftToRight()) { justification = LEFT; } else { justification = RIGHT; } switch (justification) { case LEFT: compLoc.x = grooveRect.x + TEXT_INSET_H + insets.left; break; case RIGHT: compLoc.x = (grooveRect.x + grooveRect.width - (labelDim.width + TEXT_INSET_H + insets.right)); break; } // If title is positioned in middle of border AND its fontsize // is greater than the border's thickness, we'll need to paint // the border in sections to leave space for the component's background // to show through the title. // if (border != null) { if (grooveRect.y > compLoc.y - ascent) { Rectangle clipRect = new Rectangle(); // save original clip Rectangle saveClip = g.getClipBounds(); // paint strip left of text clipRect.setBounds(saveClip); if (computeIntersection(clipRect, x, y, compLoc.x - 1 - x, height)) { g.setClip(clipRect); border.paintBorder( c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); } // paint strip right of text clipRect.setBounds(saveClip); if (computeIntersection( clipRect, compLoc.x + labelDim.width + 1, y, x + width - (compLoc.x + labelDim.width + 1), height)) { g.setClip(clipRect); border.paintBorder( c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); } // paint strip below text clipRect.setBounds(saveClip); if (computeIntersection( clipRect, compLoc.x - 1, compLoc.y + ascent + descent, labelDim.width + 2, y + height - compLoc.y - ascent - descent)) { g.setClip(clipRect); border.paintBorder( c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); } // restore clip g.setClip(saveClip); } else { border.paintBorder(c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); } label.setLocation(compLoc); label.setSize(labelDim); } }