001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.design.decoration.components;
021:
022: import java.awt.BasicStroke;
023: import java.awt.Color;
024: import java.awt.Dimension;
025: import java.awt.Graphics;
026: import java.awt.Graphics2D;
027: import java.awt.RenderingHints;
028: import java.awt.Shape;
029: import java.awt.geom.RoundRectangle2D;
030: import javax.swing.ButtonModel;
031: import javax.swing.JButton;
032: import org.netbeans.modules.bpel.design.decoration.components.ZoomableDecorationComponent;
033:
034: /**
035: *
036: * @author aa160298
037: */
038: public class DiagramButton extends JButton implements
039: ZoomableDecorationComponent {
040:
041: private double zoom = 1;
042: private Icon2D icon2D;
043:
044: public DiagramButton(Icon2D icon2D) {
045: setContentAreaFilled(false);
046: setRolloverEnabled(true);
047: setBorder(null);
048: setFocusable(false);
049: this .icon2D = icon2D;
050: }
051:
052: public void paintComponent(Graphics g) {
053: Graphics2D g2 = (Graphics2D) g;
054:
055: g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
056: RenderingHints.VALUE_ANTIALIAS_ON);
057: g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
058: RenderingHints.VALUE_STROKE_PURE);
059:
060: double strokeWidth = STROKE.getLineWidth();
061:
062: Shape border = new RoundRectangle2D.Double(strokeWidth / 2,
063: strokeWidth / 2, getWidth() - strokeWidth, getHeight()
064: - strokeWidth, 6, 6);
065:
066: ButtonModel model = getModel();
067:
068: if (model.isArmed()) {
069: g2.setPaint(ARMED_FILL);
070: g2.fill(border);
071: } else if (model.isRollover()) {
072: g2.setPaint(DEFAULT_FILL);
073: g2.fill(border);
074: }
075:
076: if (model.isRollover()) {
077: g2.setPaint(ROLLOVER_STROKE);
078: g2.setStroke(STROKE);
079: g2.draw(border);
080: }
081:
082: int inset = 1 + (int) Math.round(zoom * (DEFAULT_INSET - 1));
083: int iconWidth = getWidth() - 2 * inset;
084: int iconHeight = getHeight() - 2 * inset;
085:
086: if ((iconWidth > 0) && (iconHeight > 0)) {
087: icon2D.paint(g, inset, inset, iconWidth, iconHeight);
088: }
089: }
090:
091: public void setZoom(double zoom) {
092: this .zoom = zoom;
093: }
094:
095: public Dimension getPreferredSize() {
096: int w = (int) Math.max(1, Math.round(zoom * DEFAULT_WIDTH));
097: int h = (int) Math.max(1, Math.round(zoom * DEFAULT_HEIGHT));
098: return new Dimension(w, h);
099: }
100:
101: private static final int DEFAULT_WIDTH = 14;
102: private static final int DEFAULT_HEIGHT = 14;
103: private static final int DEFAULT_INSET = 3;
104:
105: private static final BasicStroke STROKE = new BasicStroke(1.2f);
106: private static final Color DEFAULT_FILL = new Color(0xFFFFFF);
107: private static final Color ARMED_FILL = new Color(0xEEEEEE);
108: private static final Color ROLLOVER_STROKE = new Color(0xA9A9A9);
109: }
|