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:
018: import javax.swing.*;
019: import java.awt.*;
020: import java.awt.geom.GeneralPath;
021:
022: /**
023: * User: Martin
024: * Date: 03.06.2006
025: * Time: 20:17:28
026: */
027: public class ColorIcon implements Icon {
028: @NotNull
029: private Shape shape;
030: @NotNull
031: private Color outline;
032: @NotNull
033: private Color fill;
034: private int w;
035: private int h;
036: private boolean fillBGWhite;
037:
038: @NotNull
039: private BasicStroke stroke;
040:
041: public ColorIcon(@NotNull
042: Color outline, @NotNull
043: Color fill, int w, int h, boolean fillBGWhite) {
044: this .outline = outline;
045: this .fill = fill;
046:
047: this .w = w;
048: this .h = h;
049: this .fillBGWhite = fillBGWhite;
050:
051: GeneralPath generalPath = new GeneralPath();
052: float r = (float) (2.);
053: float o = 0.0f;
054: generalPath.moveTo(r + o, 0 + o);
055: generalPath.lineTo(w - r + o, 0 + o);
056: generalPath.lineTo(w + o, r + o);
057: generalPath.lineTo(w + o, h - r + o);
058: generalPath.lineTo(w - r + o, h + o);
059:
060: generalPath.lineTo(r + o, h + o);
061: generalPath.lineTo(0 + o, h - r + o);
062: generalPath.lineTo(0 + o, r + o);
063: generalPath.closePath();
064:
065: shape = generalPath;
066:
067: stroke = new BasicStroke(1.0f);
068: }
069:
070: public void paintIcon(@NotNull
071: Component c, @NotNull
072: Graphics g, int x, int y) {
073: Graphics2D g2d = (Graphics2D) g;
074: Object hint = g2d
075: .getRenderingHint(RenderingHints.KEY_ANTIALIASING);
076: g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
077: RenderingHints.VALUE_ANTIALIAS_ON);
078: Stroke s = g2d.getStroke();
079: g2d.setStroke(stroke);
080: g2d.translate(x, y);
081:
082: Color col = g2d.getColor();
083: if (fillBGWhite) {
084: g2d.setColor(Color.WHITE);
085: g2d.fill(shape);
086: }
087:
088: g2d.setColor(fill);
089: g2d.fill(shape);
090: g2d.setColor(outline);
091: g2d.draw(shape);
092: g2d.setColor(col);
093:
094: g2d.translate(-x, -y);
095: g2d.setStroke(s);
096: g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, hint);
097: }
098:
099: public int getIconWidth() {
100: return w + 1;
101: }
102:
103: public int getIconHeight() {
104: return h + 1;
105: }
106: }
|