List of usage examples for java.awt Graphics create
public abstract Graphics create();
From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java
private static void paintComponents(Container c, Graphics g) { if (!c.isShowing()) return;/* w w w. ja va2 s .c o m*/ final int ncomponents = c.getComponentCount(); final Rectangle clip = g.getClipBounds(); int i = ncomponents - 1; while (i >= 0) { final Component component[] = c.getComponents(); final Component comp = component[i]; if (comp == null || !comp.isVisible()) continue; final Rectangle bounds = comp.getBounds(); Rectangle cr; if (clip == null) cr = new Rectangle(bounds); else cr = bounds.intersection(clip); if (cr.isEmpty()) continue; final Graphics cg = g.create(); cg.setClip(cr); cg.translate(bounds.x, bounds.y); try { comp.paint(cg); } catch (Throwable e) { // } cg.dispose(); i--; } }
From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java
private void draw(Graphics g, Dimension size) { final int annotationHeight = 100; final int x = Math.max((int) (size.height * 0.05), 10); final int y = Math.max((int) (size.width * 0.05), 10); final int bottom = Math.max((int) (size.height * 0.1) + annotationHeight, 20); final int right = Math.max((int) (size.width * 0.1), 20); final Rectangle r = positionPlot(size, x, y, bottom, right); plotRadius = Math.min(r.width / 2, r.height / 2); final Dimension quadrantSize = new Dimension(plotRadius, plotRadius); g.translate(0, origin.y + r.height); if (data != null) { loadColorBar(data.getColorScale()); drawColorBar(g, colourAxis);//from www. j a va 2s . c o m } g.translate(0, -origin.y - r.height); origin.y += r.height / 2; origin.x += r.width / 2; final Graphics graphics = g.create(); graphics.translate(origin.x, origin.y); radialAxis.setSize(quadrantSize); if (data != null) data.draw(graphics); if (rings != null) { int ri = 0; for (double ring : rings) { final int rad = radialAxis.getScreenPoint(ring); final int rad2 = rad + rad; graphics.setColor(Color.lightGray); graphics.drawOval(-rad, -rad, rad2, rad2); if (ringText != null && ringText[ri] != null) { graphics.setColor(Color.black); graphics.drawString(ringText[ri], 0, -rad); } ++ri; } } else { radialAxis.draw(graphics); } // draw wind direction & speed if (showWindDirection) drawWindDirection(graphics, plotRadius, windDirection - 90); graphics.translate(-origin.x, -origin.y); drawAxisLabels(graphics); graphics.dispose(); }
From source file:org.openstreetmap.josm.tools.ImageProvider.java
/** * Creates a rotated version of the input image. * * @param c The component to get properties useful for painting, e.g. the foreground or * background color./*from w ww . j av a2 s . co m*/ * @param img the image to be rotated. * @param rotatedAngle the rotated angle, in degree, clockwise. It could be any double but we * will mod it with 360 before using it. * * @return the image after rotating. */ public static Image createRotatedImage(Component c, Image img, double rotatedAngle) { // convert rotatedAngle to a value from 0 to 360 double originalAngle = rotatedAngle % 360; if (rotatedAngle != 0 && originalAngle == 0) { originalAngle = 360.0; } // convert originalAngle to a value from 0 to 90 double angle = originalAngle % 90; if (originalAngle != 0.0 && angle == 0.0) { angle = 90.0; } double radian = Math.toRadians(angle); new ImageIcon(img); // load completely int iw = img.getWidth(null); int ih = img.getHeight(null); int w; int h; if ((originalAngle >= 0 && originalAngle <= 90) || (originalAngle > 180 && originalAngle <= 270)) { w = (int) (iw * Math.sin(DEGREE_90 - radian) + ih * Math.sin(radian)); h = (int) (iw * Math.sin(radian) + ih * Math.sin(DEGREE_90 - radian)); } else { w = (int) (ih * Math.sin(DEGREE_90 - radian) + iw * Math.sin(radian)); h = (int) (ih * Math.sin(radian) + iw * Math.sin(DEGREE_90 - radian)); } BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics g = image.getGraphics(); Graphics2D g2d = (Graphics2D) g.create(); // calculate the center of the icon. int cx = iw / 2; int cy = ih / 2; // move the graphics center point to the center of the icon. g2d.translate(w / 2, h / 2); // rotate the graphics about the center point of the icon g2d.rotate(Math.toRadians(originalAngle)); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.drawImage(img, -cx, -cy, c); g2d.dispose(); new ImageIcon(image); // load completely return image; }
From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
protected void paintComponent(final Graphics g) { if (fpsCalculator.isActive()) { fpsCalculator.tick();//from w w w .java 2 s . c om } final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(new Color(224, 224, 224)); g2.fillRect(0, 0, getWidth(), getHeight()); final int leftBorder = (int) getLeftBorder(); final int topBorder = (int) getTopBorder(); final float scaleFactor = getRenderContext().getZoomModel().getZoomAsPercentage(); // draw the page area .. final PageDefinition pageDefinition = getRenderContext().getContextRoot().getPageDefinition(); final Rectangle2D.Double area = new Rectangle2D.Double(0, 0, pageDefinition.getWidth() * scaleFactor, getHeight()); g2.translate(leftBorder * scaleFactor, topBorder * scaleFactor); g2.clip(area); g2.setColor(Color.WHITE); g2.fill(area); // draw the grid (unscaled, but translated) final Point2D offset = getOffset(); if (offset.getX() != 0) { // The blackout area is for inline sub-reports and is the area where the subreport is not interested in // (so we can clip out). The blackout area is only visible in the sub-report. final Rectangle2D.Double blackoutArea = new Rectangle2D.Double(0, 0, offset.getX() * scaleFactor, getHeight()); g2.setColor(Color.LIGHT_GRAY); g2.fill(blackoutArea); } paintGrid(g2); paintElementAlignment(g2); g2.dispose(); final Graphics2D logicalPageAreaG2 = (Graphics2D) g.create(); // draw the renderable content ... logicalPageAreaG2.translate(leftBorder * scaleFactor, topBorder * scaleFactor); logicalPageAreaG2.clip(area); logicalPageAreaG2.scale(scaleFactor, scaleFactor); try { final ElementRenderer rendererRoot = getElementRenderer(); if (rendererRoot != null) { if (rendererRoot.draw(logicalPageAreaG2) == false) { rendererRoot.handleError(designerContext, renderContext); logicalPageAreaG2.scale(1f / scaleFactor, 1f / scaleFactor); logicalPageAreaG2.setPaint(Color.WHITE); logicalPageAreaG2.fill(area); } } } catch (Exception e) { // ignore for now.. UncaughtExceptionsModel.getInstance().addException(e); } logicalPageAreaG2.dispose(); final OverlayRenderer[] renderers = new OverlayRenderer[4]; renderers[0] = new OverlappingElementOverlayRenderer(getDefaultElement()); // displays the red border for warning renderers[1] = new SelectionOverlayRenderer(getDefaultElement()); renderers[2] = new GuidelineOverlayRenderer(horizontalLinealModel, verticalLinealModel); renderers[3] = new SelectionRectangleOverlayRenderer(); // blue box when you shift and drag the region to select multiple // elements for (int i = 0; i < renderers.length; i++) { final OverlayRenderer renderer = renderers[i]; final Graphics2D selectionG2 = (Graphics2D) g.create(); renderer.validate(getRenderContext(), scaleFactor, offset); renderer.draw(selectionG2, new Rectangle2D.Double(getLeftBorder(), getTopBorder(), getWidth(), getHeight()), this); selectionG2.dispose(); } }
From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java
/** * paints this log item panel and all contained log items as specified. * /*ww w. j a v a2 s .c o m*/ * @param g * the graphics object used for painting */ public void paintComponent(Graphics grx) { Graphics gr = grx.create(); if (this.isOpaque()) { gr.setColor(colorBg); gr.fillRect(0, 0, getWidth(), getHeight()); } if ((int) gr.getClipBounds().getMinX() < coUtil.getClipL() || (int) gr.getClipBounds().getMaxX() > coUtil.getClipR() || (int) gr.getClipBounds().getMinY() < coUtil.getClipU() || (int) gr.getClipBounds().getMaxY() > coUtil.getClipB()) { modelBuffer = null; } if (modelBuffer == null) { this.setToolTipText(null); if (this.getWidth() <= SCREENLENGTH) { coUtil.setClipL(0); coUtil.setClipR(this.getWidth()); } else { int x1 = (SCREENLENGTH - gr.getClipBounds().width) / 2; int x2 = (int) gr.getClipBounds().getMinX() - x1; if (x2 <= 0) { coUtil.setClipL(0); coUtil.setClipR(SCREENLENGTH); } else if (x2 + SCREENLENGTH >= this.getWidth()) { coUtil.setClipR(this.getWidth()); coUtil.setClipL(this.getWidth() - SCREENLENGTH); } else { coUtil.setClipL(x2); coUtil.setClipR(x2 + SCREENLENGTH); } } if (this.getHeight() <= SCREENLENGTH) { coUtil.setClipU(0); coUtil.setClipB(this.getHeight()); } else { int y1 = (SCREENLENGTH - gr.getClipBounds().height) / 2; int y2 = (int) gr.getClipBounds().getMinY() - y1; if (y2 <= 0) { coUtil.setClipU(0); coUtil.setClipB(SCREENLENGTH); } else if (y2 + SCREENLENGTH >= this.getHeight()) { coUtil.setClipU(this.getHeight() - SCREENLENGTH); coUtil.setClipB(this.getHeight()); } else { coUtil.setClipU(y2); coUtil.setClipB(y2 + SCREENLENGTH); } } coUtil.updateMilli2pixelsRatio(getWidth(), BORDER); if (dcop.isSizeCheckBoxSelected()) { drawModelBuffer(getWidth(), getHeight(), true); } else { drawModelBuffer_NO_SIZE(getWidth(), getHeight(), true); } } grx.drawImage(modelBuffer, coUtil.getClipL(), coUtil.getClipU(), this); // to do box for zoom if (p1 != null && p2 != null) { int x1 = Math.min(p1.x, p2.x); int y1 = Math.min(p1.y, p2.y); int width = Math.abs(p1.x - p2.x); int height = Math.abs(p1.y - p2.y); grx.drawRect(x1, y1, width, height); } }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * paints this log item panel and all contained log items as specified. * /*from ww w. ja v a 2 s. c o m*/ * @param g * the graphics object used for painting */ public void paintComponent(Graphics grx) { selectedIDIndices.clear(); // for exporting bDrawLine = dca.getSettingPanel().isDrawLine(); // todo bBottleneck = dca.getSettingPanel().isBottleneck(); bBottleneckforInstances = dca.getSettingPanel().isBottleneckforInstance(); double percentileL = dcModel.getOverallStatistics().getPercentile(dca.getSettingPanel().getPercentileL()); double percentileU = dcModel.getOverallStatistics().getPercentile(dca.getSettingPanel().getPercentileU()); Graphics gr = grx.create(); if (this.isOpaque()) { gr.setColor(colorBg); gr.fillRect(0, 0, getWidth(), getHeight()); } // paint the time indicator equipped component lane paintComponentLane(gr); // calculate are to be painted int height = (int) ((double) (getHeight() - (2 * border))); int unitHeight = height / getHashMapSize(); int currentTop = 0; // paint items if (dcModel.getItemMap().size() > 0) { String key = null; AbstractLogUnit item = null; // iterate through sets int index = 0; for (Iterator itSets = dcModel.getSortedKeySetList().iterator(); itSets.hasNext();) { key = (String) itSets.next(); // if key is not in instanceIDs, skip.. if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(key)) continue; currentTop = unit2Cord(index) + unitHeight / 2; LogUnitList tempUnitList = new LogUnitList(); AbstractLogUnit olditem = null; // for bottleneck boolean bInstances = false; boolean flag = true; if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances) { LogUnitList tempUnitList2; tempUnitList2 = ((LogUnitList) dcModel.getItemMap().get(key)); double percentile2L = dcModel.getTimeStatistics().get(0) .getPercentile(dca.getSettingPanel().getPercentileforInstanceL()); double percentile2U = dcModel.getTimeStatistics().get(0) .getPercentile(dca.getSettingPanel().getPercentileforInstanceU()); long tempDuration = (tempUnitList2 .getRightBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep()) .getTime() - tempUnitList2.getLeftBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep()).getTime()); if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances && tempDuration >= percentile2L && tempDuration <= percentile2U) bInstances = true; } // end for bottleneck //////// // iterate through items for (Iterator itItm = ((LogUnitList) dcModel.getItemMap().get(key)).iterator(); itItm.hasNext();) { item = (AbstractLogUnit) itItm.next(); if (dcModel.getEventTypeToKeep() != null && (!dcModel.getEventTypeToKeep().contains(item.getType()) || !dcModel .getInstanceTypeToKeep().contains(item.getProcessInstance().getName()))) continue; if (bDrawLine && item.getType().equals(dca.getSettingPanel().getStartEvent())) tempUnitList.addEvent(item); assignColorByItem(item, gr); clipL = (int) gr.getClipBounds().getMinX() - 1; clipR = (int) gr.getClipBounds().getMaxX() + 1; long clipLeftTs2 = coord2timeMillis(clipL); long clipRightTs2 = coord2timeMillis(clipR); // if line is added if (bDrawLine && item.getType().equals(dca.getSettingPanel().getEndEvent())) { for (Iterator itr = tempUnitList.iterator(); itr.hasNext();) { AbstractLogUnit item2 = (AbstractLogUnit) itr.next(); if (item2.getElement().equals(item.getElement()) && item2.getProcessInstance().equals(item.getProcessInstance())) { paintItemLine(time2coord(item2.getCurrentTimeStamp()) + border, currentTop, time2coord(item.getCurrentTimeStamp()) + border, gr); tempUnitList.removeEvent(item2); break; } } } // if item is not shown on the screen, ship drawing if (item.getCurrentTimeStamp() == null || item.getCurrentTimeStamp().getTime() < clipLeftTs2 || item.getCurrentTimeStamp().getTime() > clipRightTs2) continue; // for botteleneck if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneck && olditem != null && (item.getCurrentTimeStamp().getTime() - olditem.getCurrentTimeStamp().getTime()) >= percentileL && (item.getCurrentTimeStamp().getTime() - olditem.getCurrentTimeStamp().getTime()) <= percentileU) { paintItemLineBottleneck(time2coord(olditem.getCurrentTimeStamp()) + border, currentTop, time2coord(item.getCurrentTimeStamp()) + border, gr); this.paintHighligtedItem(time2coord(olditem.getCurrentTimeStamp()) + border, currentTop, gr, assignShapeByItem(olditem)); this.paintHighligtedItem(time2coord(item.getCurrentTimeStamp()) + border, currentTop, gr, assignShapeByItem(item)); this.addExportingList(item); olditem = item; continue; } // paint an item if (bInstances) { this.paintHighligtedItem(time2coord(item.getCurrentTimeStamp()) + border, currentTop, gr, assignShapeByItem(item)); if (flag) { this.addExportingList(item); flag = false; } } else { this.paintItem(time2coord(item.getCurrentTimeStamp()) + border, currentTop, gr, assignShapeByItem(item)); } olditem = item; } // move y point index++; } } // to do box for zoom if (p1 != null && p2 != null) { int x1 = Math.min(p1.x, p2.x); int y1 = Math.min(p1.y, p2.y); int width = Math.abs(p1.x - p2.x); height = Math.abs(p1.y - p2.y); grx.drawRect(x1, y1, width, height); } // for exporting if (selectedIDIndices.size() > 0) { int tempArray[] = new int[selectedIDIndices.size()]; int i = 0; for (Iterator itr = selectedIDIndices.iterator(); itr.hasNext();) { tempArray[i++] = (int) ((Integer) itr.next()); } dca.setSelectedInstanceIndicesfromScreen(tempArray); } }
From source file:org.prom5.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * paints this log item panel and all contained log items as specified. * @param g the graphics object used for painting *//*from w ww. ja v a 2 s . co m*/ public void paintComponent(Graphics grx) { selectedIDIndices.clear(); // for exporting bDrawLine = dca.getSettingPanel().isDrawLine(); //todo bBottleneck = dca.getSettingPanel().isBottleneck(); bBottleneckforInstances = dca.getSettingPanel().isBottleneckforInstance(); double percentileL = dcModel.getOverallStatistics().getPercentile(dca.getSettingPanel().getPercentileL()); double percentileU = dcModel.getOverallStatistics().getPercentile(dca.getSettingPanel().getPercentileU()); Graphics gr = grx.create(); if (this.isOpaque()) { gr.setColor(colorBg); gr.fillRect(0, 0, getWidth(), getHeight()); } // paint the time indicator equipped component lane paintComponentLane(gr); // calculate are to be painted int height = (int) ((double) (getHeight() - (2 * border))); int unitHeight = height / getHashMapSize(); int currentTop = 0; // paint items if (dcModel.getItemMap().size() > 0) { String key = null; AbstractLogUnit item = null; // iterate through sets int index = 0; for (Iterator itSets = dcModel.getSortedKeySetList().iterator(); itSets.hasNext();) { key = (String) itSets.next(); // if key is not in instanceIDs, skip.. if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(key)) continue; currentTop = unit2Cord(index) + unitHeight / 2; LogUnitList tempUnitList = new LogUnitList(); AbstractLogUnit olditem = null; // for bottleneck boolean bInstances = false; boolean flag = true; if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances) { LogUnitList tempUnitList2; tempUnitList2 = ((LogUnitList) dcModel.getItemMap().get(key)); double percentile2L = dcModel.getTimeStatistics().get(0) .getPercentile(dca.getSettingPanel().getPercentileforInstanceL()); double percentile2U = dcModel.getTimeStatistics().get(0) .getPercentile(dca.getSettingPanel().getPercentileforInstanceU()); long tempDuration = (tempUnitList2 .getRightBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep()) .getTime() - tempUnitList2.getLeftBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep()).getTime()); if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances && tempDuration >= percentile2L && tempDuration <= percentile2U) bInstances = true; } // end for bottleneck //////// // iterate through items for (Iterator itItm = ((LogUnitList) dcModel.getItemMap().get(key)).iterator(); itItm.hasNext();) { item = (AbstractLogUnit) itItm.next(); if (dcModel.getEventTypeToKeep() != null && (!dcModel.getEventTypeToKeep().contains(item.getType()) || !dcModel .getInstanceTypeToKeep().contains(item.getProcessInstance().getName()))) continue; if (bDrawLine && item.getType().equals(dca.getSettingPanel().getStartEvent())) tempUnitList.addEvent(item); assignColorByItem(item, gr); clipL = (int) gr.getClipBounds().getMinX() - 1; clipR = (int) gr.getClipBounds().getMaxX() + 1; long clipLeftTs2 = coord2timeMillis(clipL); long clipRightTs2 = coord2timeMillis(clipR); // if line is added if (bDrawLine && item.getType().equals(dca.getSettingPanel().getEndEvent())) { for (Iterator itr = tempUnitList.iterator(); itr.hasNext();) { AbstractLogUnit item2 = (AbstractLogUnit) itr.next(); if (item2.getElement().equals(item.getElement()) && item2.getProcessInstance().equals(item.getProcessInstance())) { paintItemLine(time2coord(item2.getCurrentTimeStamp()) + border, currentTop, time2coord(item.getCurrentTimeStamp()) + border, gr); tempUnitList.removeEvent(item2); break; } } } // if item is not shown on the screen, ship drawing if (item.getCurrentTimeStamp() == null || item.getCurrentTimeStamp().getTime() < clipLeftTs2 || item.getCurrentTimeStamp().getTime() > clipRightTs2) continue; // for botteleneck if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneck && olditem != null && (item.getCurrentTimeStamp().getTime() - olditem.getCurrentTimeStamp().getTime()) >= percentileL && (item.getCurrentTimeStamp().getTime() - olditem.getCurrentTimeStamp().getTime()) <= percentileU) { paintItemLineBottleneck(time2coord(olditem.getCurrentTimeStamp()) + border, currentTop, time2coord(item.getCurrentTimeStamp()) + border, gr); this.paintHighligtedItem(time2coord(olditem.getCurrentTimeStamp()) + border, currentTop, gr, assignShapeByItem(olditem)); this.paintHighligtedItem(time2coord(item.getCurrentTimeStamp()) + border, currentTop, gr, assignShapeByItem(item)); this.addExportingList(item); olditem = item; continue; } // paint an item if (bInstances) { this.paintHighligtedItem(time2coord(item.getCurrentTimeStamp()) + border, currentTop, gr, assignShapeByItem(item)); if (flag) { this.addExportingList(item); flag = false; } } else { this.paintItem(time2coord(item.getCurrentTimeStamp()) + border, currentTop, gr, assignShapeByItem(item)); } olditem = item; } // move y point index++; } } // to do box for zoom if (p1 != null && p2 != null) { int x1 = Math.min(p1.x, p2.x); int y1 = Math.min(p1.y, p2.y); int width = Math.abs(p1.x - p2.x); height = Math.abs(p1.y - p2.y); grx.drawRect(x1, y1, width, height); } // for exporting if (selectedIDIndices.size() > 0) { int tempArray[] = new int[selectedIDIndices.size()]; int i = 0; for (Iterator itr = selectedIDIndices.iterator(); itr.hasNext();) { tempArray[i++] = (int) ((Integer) itr.next()); } dca.setSelectedInstanceIndicesfromScreen(tempArray); } }
From source file:org.tinymediamanager.ui.components.ImageLabel.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (scaledImage != null) { int originalWidth = scaledImage.getWidth(null); int originalHeight = scaledImage.getHeight(null); // calculate new height/width int newWidth = 0; int newHeight = 0; int offsetX = 0; int offsetY = 0; if (drawBorder && !drawFullWidth) { Point size = ImageCache.calculateSize(this.getWidth() - 8, this.getHeight() - 8, originalWidth, originalHeight, true); // calculate offsets if (position == Position.TOP_RIGHT || position == Position.BOTTOM_RIGHT) { offsetX = this.getWidth() - size.x - 8; }/*from ww w . j a va 2 s. c o m*/ if (position == Position.BOTTOM_LEFT || position == Position.BOTTOM_RIGHT) { offsetY = this.getHeight() - size.y - 8; } if (position == Position.CENTER) { offsetX = (this.getWidth() - size.x - 8) / 2; offsetY = (this.getHeight() - size.y - 8) / 2; } newWidth = size.x; newHeight = size.y; // when the image size differs too much - reload and rescale the original image recreateScaledImageIfNeeded(originalWidth, originalHeight, newWidth, newHeight); g.setColor(Color.BLACK); g.drawRect(offsetX, offsetY, size.x + 7, size.y + 7); g.setColor(Color.WHITE); g.fillRect(offsetX + 1, offsetY + 1, size.x + 6, size.y + 6); // g.drawImage(Scaling.scale(originalImage, newWidth, newHeight), offsetX + 4, offsetY + 4, newWidth, newHeight, this); g.drawImage(scaledImage, offsetX + 4, offsetY + 4, newWidth, newHeight, this); } else { Point size = null; if (drawFullWidth) { size = new Point(this.getWidth(), this.getWidth() * originalHeight / originalWidth); } else { size = ImageCache.calculateSize(this.getWidth(), this.getHeight(), originalWidth, originalHeight, true); } // calculate offsets if (position == Position.TOP_RIGHT || position == Position.BOTTOM_RIGHT) { offsetX = this.getWidth() - size.x; } if (position == Position.BOTTOM_LEFT || position == Position.BOTTOM_RIGHT) { offsetY = this.getHeight() - size.y; } if (position == Position.CENTER) { offsetX = (this.getWidth() - size.x) / 2; offsetY = (this.getHeight() - size.y) / 2; } newWidth = size.x; newHeight = size.y; // when the image size differs too much - reload and rescale the original image recreateScaledImageIfNeeded(originalWidth, originalHeight, newWidth, newHeight); // g.drawImage(Scaling.scale(originalImage, newWidth, newHeight), offsetX, offsetY, newWidth, newHeight, this); g.drawImage(scaledImage, offsetX, offsetY, newWidth, newHeight, this); } } else { // draw border and background if (drawBorder) { g.setColor(Color.BLACK); g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1); if (getParent().isOpaque()) { g.setColor(getParent().getBackground()); g.fillRect(1, 1, this.getWidth() - 2, this.getHeight() - 2); } } // calculate diagonal int diagonalSize = (int) Math .sqrt(this.getWidth() * this.getWidth() + this.getHeight() * this.getHeight()); // draw text String text = ""; if (alternativeText != null) { text = alternativeText; } else { text = BUNDLE.getString("image.nonefound"); //$NON-NLS-1$ } if (!getParent().isOpaque()) { text = ""; } Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); AffineTransform orig = g2.getTransform(); AffineTransform at = new AffineTransform(orig); at.translate(0, this.getHeight()); at.rotate(this.getWidth(), -this.getHeight()); g2.setTransform(at); g2.setColor(Color.BLACK); g2.setFont(FONT); FontMetrics fm = g2.getFontMetrics(); int x = (diagonalSize - fm.stringWidth(text)) / 2; int y = (fm.getAscent() - fm.getDescent()) / 2; g2.drawString(text, x, y); // g2.drawLine(0, 0, diagonalSize, 0); at.translate(0, -this.getHeight()); g2.setTransform(orig); } }