@Override protected void paintBackground(Graphics g, JComponent component) { getGlassParameters(); Graphics2D g2d = (Graphics2D) g.create(); if (getOrientation().isHorizontal()) { paintBackground( g2d, 0, 0, component.getWidth(), component.getHeight(), getOrientation().isHorizontal(), component); } else { paintBackground( g2d, 0, 0, component.getHeight(), component.getWidth(), getOrientation().isHorizontal(), component); } g2d.dispose(); }
/** [Internal] */ public void paintComponent(Graphics g) { boolean opq = true; if (theOpaque != null) opq = theOpaque; super.setOpaque(opq); // if(theBackground!=null)super.setBackground(theBackground); super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Rectangle rt = getBounds(); rt.x = 0; rt.y = 0; doBuffer(g2, opq, rt); chkFPS(); }
/** Records a new size. Called by the AWT. */ public void setBounds(int x, int y, int width, int height) { Insets insets = getInsets(); int w; int h; if (source == null) { w = width; h = height; } else { w = source.getWidth(); h = source.getHeight(); if (width < w) { w = width; } if (height < h) { h = height; } } componentWidth = w + insets.left + insets.right; componentHeight = h + insets.top + insets.bottom; super.setBounds(x + shift_x, y + shift_y, componentWidth, componentHeight); }
@Override protected void paintForeground(Graphics g, JComponent component) { // paint icon (if there is any) paintIcon(g, component); Insets ins = getOutsideInsets(); int w = component.getWidth(); int h = component.getHeight(); // paint knob (if there is any) // TODO colors if (behavior.isShowKnob()) { Insets insets = getInnerInsets(); if (getOrientation().isHorizontal()) { int x = ins.left + insets.left - KNOB_SIZE + 3; int y1 = ins.top + insets.top + 3; int y2 = h - insets.bottom - ins.bottom - 4; g.setColor(Color.WHITE); g.drawLine(x, y1, x, y2); g.drawLine(x, y1, x + 1, y1); g.setColor(Color.DARK_GRAY); g.drawLine(x, y2, x + 1, y2); g.drawLine(x + 1, y1 + 1, x + 1, y2); } else { int y = ins.top + insets.top - KNOB_SIZE + 3; int x1 = ins.left + insets.left + 3; int x2 = w - insets.right - ins.right - 4; g.setColor(Color.WHITE); g.drawLine(x1, y, x2, y); g.drawLine(x1, y, x1, y + 1); g.setColor(Color.DARK_GRAY); g.drawLine(x1 + 1, y + 1, x2, y + 1); g.drawLine(x2, y, x2, y + 1); } } }
/** Draws the game */ @Override protected void paintComponent(Graphics g) { super.paintComponent(g); final Graphics2D g2 = (Graphics2D) g; /** Draw all the non-falling blocks on the board. Non-OUTSIDE blocks have rounded corners. */ for (int row = 0; row < board.getHeight(); row++) { for (int column = 0; column < board.getWidth(); column++) { if (board.getSquareType(row, column) != SquareType.OUTSIDE) { Shape tetrominoBlock = new RoundRectangle2D.Double( column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT, 5, 5); g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column))); g2.fill(tetrominoBlock); g2.draw(tetrominoBlock); } else { Shape tetrominoBlock = new Rectangle2D.Double( column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT); g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column))); g2.fill(tetrominoBlock); g2.draw(tetrominoBlock); } } } Poly tempPoly = board.getFalling(); if (tempPoly != null) { for (int row = 0; row < tempPoly.getSize(); row++) { for (int column = 0; column < tempPoly.getSize(); column++) { if (tempPoly.getSquareType(row, column) != SquareType.EMPTY) { Shape tetrominoBlock = new RoundRectangle2D.Double( (column + board.getFallingPosX()) * SQUARE_WIDTH, (row + board.getFallingPosY()) * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT, 5, 5); g2.setColor(SQUARE_COLOR.get(tempPoly.getSquareType(row, column))); g2.fill(tetrominoBlock); g2.draw(tetrominoBlock); } } } } }
@Override protected void doPaint( Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) { if (c != null && !c.isOpaque()) return; // populate componentColors array with colors calculated in getExtendedCacheKeys call componentColors = extendedCacheKeys; // generate this entire method. Each state/bg/fg/border combo that has // been painted gets its own KEY and paint method. switch (state) { case BACKGROUND_ENABLED: paintBackgroundEnabled(g); break; case BACKGROUND_ENABLED_FOCUSED: paintBackgroundEnabledAndFocused(g); break; } }
public void setLocation(int x, int y) { shift_x = x; shift_y = y; super.setLocation(x, y); }
/** * If the UI delegate is non-null, call its paint method. We pass the delegate a copy of the * Graphics object to protect the rest of the paint code from irrevocable changes (e.g. * Graphics.translate()). * * @see #paint * @see #defaultPaintComponent */ protected void paintComponent(Graphics g) { super.paintComponent(g); defaultPaintComponent((Graphics2D) g); }
/** * Reshape the receiver. The offscreen Image is destroyed, the component is laid out and * repainted. * * @see java.awt.Component * @see layoutComponent */ public void setBounds(int x, int y, int width, int height) { super.setBounds(x, y, width, height); layoutComponent(); repaint(); }
protected void paintBackground( Graphics g, int x, int y, int w, int h, boolean horizontal, JComponent component) { Graphics2D g2d = (Graphics2D) g.create(); CEclipseBorder ec = null; Insets ins = getOutsideInsets(); x = ins.left; y = ins.top; if (getOrientation().isHorizontal()) { w -= ins.left + ins.right; h -= ins.top + ins.bottom; } else { w -= ins.top + ins.bottom; h -= ins.left + ins.right; } if (component.getBorder() instanceof CompoundBorder) { CompoundBorder cb = (CompoundBorder) component.getBorder(); CompoundBorder bb = (CompoundBorder) cb.getInsideBorder(); ec = (CEclipseBorder) bb.getOutsideBorder(); } if (w > 0 && h > 0) { if (glassStrip != null) { BufferedImage im = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D gg = im.createGraphics(); gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gg.setColor(component.getBackground()); if (ec != null) { gg.fill(ec.createShape(0, 0, w, h, ec.getCornerRadius())); } else { gg.fillRect(0, 0, w, h); } if (!isSelected()) { gg.setComposite(AlphaComposite.SrcIn); } else { gg.setComposite(AlphaComposite.SrcAtop); } try { glass.Render2Graphics(new Dimension(w, h), gg, glassStrip, true); } catch (Exception e) { glass.Render2Graphics(new Dimension(w, h), gg, CGlassFactory.VALUE_STEEL, true); } gg.dispose(); if (!getOrientation().isHorizontal()) { AffineTransform atTrans = AffineTransform.getTranslateInstance(x /* + h */, y + w); atTrans.concatenate(COutlineHelper.tRot90CCW); g2d.drawImage(im, atTrans, null); } else { g2d.drawImage(im, x, y, null); } } g2d.dispose(); } }
// also clip, transform, composite, // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;} // --------------------------------------------------------- private void doPaint(Graphics2D g, int s, Object o) { // process an operation from the buffer // System.out.println(s); Object o1 = null, o2 = null, o3 = null, o4 = null, o5 = null, o6 = null, o7 = null, o8 = null, o9 = null, o10 = null, o11 = null; if (o instanceof Object[]) { Object[] a = (Object[]) o; if (a.length > 0) o1 = a[0]; if (a.length > 1) o2 = a[1]; if (a.length > 2) o3 = a[2]; if (a.length > 3) o4 = a[3]; if (a.length > 4) o5 = a[4]; if (a.length > 5) o6 = a[5]; if (a.length > 6) o7 = a[6]; if (a.length > 7) o8 = a[7]; if (a.length > 8) o9 = a[8]; if (a.length > 9) o10 = a[9]; if (a.length > 10) o11 = a[10]; } switch (s) { case clear: paintBackground(g, theBackground); break; // public void addRenderingHints(Map<?,?> hints) // {toBuffer("addRenderingHints",hints );} case addRenderingHints: g.addRenderingHints((Map<?, ?>) o); break; case clip1: g.clip((Shape) o); break; case draw1: g.draw((Shape) o); break; case draw3DRect: g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5); break; case drawGlyphVector: g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3); break; case drawImage1: g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4); break; case drawImage2: g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3); break; case drawRenderableImage: g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2); break; case drawRenderedImage: g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2); break; case drawString1: g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3); break; case drawString2: g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3); break; case drawString3: g.drawString((String) o1, (Float) o2, (Float) o3); break; case drawString4: g.drawString((String) o1, (Integer) o2, (Integer) o3); break; case fill: g.fill((Shape) o); break; case fill3DRect: g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5); break; case rotate1: g.rotate((Double) o); break; case rotate2: g.rotate((Double) o1, (Double) o2, (Double) o3); break; case scale1: g.scale((Double) o1, (Double) o2); break; case setBackground: g.setBackground( (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/ break; case setComposite: g.setComposite((Composite) o); break; case setPaint: g.setPaint((Paint) o); break; case setRenderingHint: g.setRenderingHint((RenderingHints.Key) o1, o2); break; case setRenderingHints: g.setRenderingHints((Map<?, ?>) o); break; case setStroke: g.setStroke((Stroke) o); break; case setTransform: g.setTransform(makeTransform(o)); break; case shear: g.shear((Double) o1, (Double) o2); break; case transform1: g.transform(makeTransform(o)); break; case translate1: g.translate((Double) o1, (Double) o2); break; case translate2: g.translate((Integer) o1, (Integer) o2); break; case clearRect: g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case copyArea: g.copyArea( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case drawArc: g.drawArc( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case drawBytes: g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5); break; case drawChars: g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5); break; case drawImage4: g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5); break; case drawImage5: g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4); break; case drawImage6: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Color) o6, (ImageObserver) o7); break; case drawImage7: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6); break; case drawImage8: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6, (Integer) o7, (Integer) o8, (Integer) o9, (Color) o10, (ImageObserver) o11); break; case drawImage9: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6, (Integer) o7, (Integer) o8, (Integer) o9, (ImageObserver) o10); break; case drawLine: g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawOval: g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawPolygon1: g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3); break; case drawPolygon2: g.drawPolygon((Polygon) o); break; case drawPolyline: g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3); break; case drawRect: g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawRoundRect: g.drawRoundRect( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case fillArc: g.fillArc( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case fillOval: g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; // {toBuffer("fillPolygon",mkArg(xPoints, yPoints, nPoints) );} case fillPolygon1: g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3); break; case fillPolygon2: g.fillPolygon((Polygon) o); break; case fillRect: g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case fillRoundRect: g.fillRoundRect( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case setClip1: g.setClip((Shape) o); break; case setColor: g.setColor((Color) o); break; case setFont: g.setFont((Font) o); break; case setPaintMode: g.setPaintMode(); break; case setXORMode: g.setXORMode((Color) o); break; case opaque: super.setOpaque((Boolean) o); break; case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break; { FontRenderContext frc = g.getFontRenderContext(); TextLayout tl = new TextLayout((String) o1, g.getFont(), frc); Shape s1 = tl.getOutline(null); AffineTransform af = g.getTransform(); g.translate((Integer) o2, (Integer) o3); g.draw(s1); g.setTransform(af); } ; break; default: System.out.println("Unknown image operation " + s); } }
public void setFont(Font font) { super.setFont(font); toBuffer(setFont, font); }
/** [Advanced] */ public void finalize() throws Throwable { super.finalize(); }