001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.crm.report.util;
015:
016: import org.jetbrains.annotations.NotNull;
017: import org.jetbrains.annotations.Nullable;
018: import org.pentaho.reportdesigner.crm.report.GraphicsContext;
019:
020: import javax.swing.*;
021: import java.awt.*;
022: import java.awt.geom.GeneralPath;
023: import java.awt.geom.Rectangle2D;
024: import java.awt.image.BufferedImage;
025:
026: /**
027: * User: Martin
028: * Date: 25.01.2006
029: * Time: 07:58:51
030: */
031: public class GraphicUtils {
032: private GraphicUtils() {
033: }
034:
035: @NotNull
036: public static Rectangle2D.Double getScaledRectangle(@NotNull
037: GraphicsContext graphicsContext, @NotNull
038: Rectangle2D.Double orig) {
039: double sf = graphicsContext.getScaleFactor();
040: return new Rectangle2D.Double(orig.x * sf, orig.y * sf,
041: orig.width * sf, orig.height * sf);
042: }
043:
044: @Nullable
045: public static float[] getArrayCopy(@Nullable
046: double[] doubles) {
047: if (doubles == null) {
048: return null;
049: }
050:
051: float[] floats = new float[doubles.length];
052: for (int i = 0; i < floats.length; i++) {
053: floats[i] = (float) doubles[i];
054: }
055: return floats;
056: }
057:
058: @NotNull
059: public static ImageIcon createColorImageIcon(@NotNull
060: Color outline, @NotNull
061: Color fill, int w, int h, boolean fillBGWhite) {
062: BufferedImage bi = new BufferedImage(w + 1, h + 1,
063: BufferedImage.TYPE_INT_ARGB);
064: Graphics2D g2d = bi.createGraphics();
065:
066: Object hint = g2d
067: .getRenderingHint(RenderingHints.KEY_ANTIALIASING);
068: g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
069: RenderingHints.VALUE_ANTIALIAS_ON);
070:
071: GeneralPath generalPath = new GeneralPath();
072: float r = (float) (2.);
073: float o = 0.0f;
074: generalPath.moveTo(r + o, 0 + o);
075: generalPath.lineTo(w - r + o, 0 + o);
076: generalPath.lineTo(w + o, r + o);
077: generalPath.lineTo(w + o, h - r + o);
078: generalPath.lineTo(w - r + o, h + o);
079:
080: generalPath.lineTo(r + o, h + o);
081: generalPath.lineTo(0 + o, h - r + o);
082: generalPath.lineTo(0 + o, r + o);
083: generalPath.closePath();
084:
085: Color col = g2d.getColor();
086: if (fillBGWhite) {
087: g2d.setColor(Color.WHITE);
088: g2d.fill(generalPath);
089: }
090:
091: g2d.setColor(fill);
092: g2d.fill(generalPath);
093: g2d.setColor(outline);
094: g2d.draw(generalPath);
095: g2d.setColor(col);
096:
097: g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, hint);
098:
099: g2d.dispose();
100:
101: return new ImageIcon(bi);
102: }
103: }
|