public void drawImage(Image img, float alpha, double[] _xyzSW, double[] _xyzSE, double[] _xyzNW) { Composite cs = comp2D.getComposite(); comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); AffineTransform t = getAffineTransform(img.getWidth(canvas), img.getHeight(canvas), _xyzSW, _xyzSE, _xyzNW); if (t != null) { comp2D.drawImage(img, t, canvas); } comp2D.setComposite(cs); }
public void paintComponent(Graphics screen) { if (inactive == null) { inactive = new Image[BUTTON_COUNT]; rollover = new Image[BUTTON_COUNT]; active = new Image[BUTTON_COUNT]; int IMAGE_SIZE = 33; for (int i = 0; i < BUTTON_COUNT; i++) { inactive[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT); Graphics g = inactive[i].getGraphics(); g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -2 * IMAGE_SIZE, null); rollover[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT); g = rollover[i].getGraphics(); g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -1 * IMAGE_SIZE, null); active[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT); g = active[i].getGraphics(); g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -0 * IMAGE_SIZE, null); } state = new int[buttonCount]; stateImage = new Image[buttonCount]; for (int i = 0; i < buttonCount; i++) { setState(i, INACTIVE, false); } } Dimension size = getSize(); if ((offscreen == null) || (size.width != width) || (size.height != height)) { offscreen = createImage(size.width, size.height); width = size.width; height = size.height; y1 = 0; y2 = BUTTON_HEIGHT; x1 = new int[buttonCount]; x2 = new int[buttonCount]; int offsetX = 3; for (int i = 0; i < buttonCount; i++) { x1[i] = offsetX; if (i == 2) x1[i] += BUTTON_GAP; x2[i] = x1[i] + BUTTON_WIDTH; offsetX = x2[i]; } } Graphics g = offscreen.getGraphics(); g.setColor(bgcolor); // getBackground()); g.fillRect(0, 0, width, height); for (int i = 0; i < buttonCount; i++) { g.drawImage(stateImage[i], x1[i], y1, null); } g.setColor(statusColor); g.setFont(statusFont); /* // if i ever find the guy who wrote the java2d api, i will hurt him. Graphics2D g2 = (Graphics2D) g; FontRenderContext frc = g2.getFontRenderContext(); float statusW = (float) statusFont.getStringBounds(status, frc).getWidth(); float statusX = (getSize().width - statusW) / 2; g2.drawString(status, statusX, statusY); */ // int statusY = (BUTTON_HEIGHT + statusFont.getAscent()) / 2; int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2; g.drawString(status, buttonCount * BUTTON_WIDTH + 2 * BUTTON_GAP, statusY); screen.drawImage(offscreen, 0, 0, null); }
/** * calls drawImage(Image,int,int,int,int,Color,ImageObserver) * * @see #drawImage(Image,int,int,int,int,Color,ImageObserver) */ public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { return drawImage(img, x, y, img.getWidth(observer), img.getHeight(observer), bgcolor, observer); }