01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19:
20: package org.netbeans.modules.bpel.design.decoration.components;
21:
22: import java.awt.Color;
23: import java.awt.Component;
24: import java.awt.Graphics;
25: import java.awt.Graphics2D;
26: import java.awt.GridLayout;
27: import java.awt.Insets;
28: import java.awt.Paint;
29: import java.awt.RenderingHints;
30: import java.awt.Shape;
31: import java.awt.event.MouseAdapter;
32: import java.awt.event.MouseEvent;
33: import java.awt.geom.RoundRectangle2D;
34: import javax.swing.JPanel;
35: import javax.swing.border.Border;
36:
37: public class ContextToolBar extends JPanel implements
38: DecorationComponent {
39:
40: public ContextToolBar() {
41: super (new GridLayout(1, 0, 2, 0));
42: setBorder(new MyBorder());
43: setBackground(null);
44: setOpaque(false);
45:
46: super .toString();
47: }
48:
49: private class MyBorder implements Border {
50: public void paintBorder(Component c, Graphics g, int x, int y,
51: int w, int h) {
52: Graphics2D g2 = (Graphics2D) g.create();
53: g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
54: RenderingHints.VALUE_ANTIALIAS_ON);
55: g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
56: RenderingHints.VALUE_STROKE_PURE);
57:
58: float arcSize = Math.max(0, ARC_SIZE - STROKE_WIDTH);
59: float strokeHalf = STROKE_WIDTH / 2;
60:
61: Shape shape = new RoundRectangle2D.Float(x + strokeHalf, y
62: + strokeHalf, w - STROKE_WIDTH, h - STROKE_WIDTH,
63: arcSize, arcSize);
64:
65: if (FILL_PAINT != null) {
66: g2.setPaint(FILL_PAINT);
67: g2.fill(shape);
68: }
69:
70: if (STROKE_PAINT != null) {
71: g2.setPaint(STROKE_PAINT);
72: g2.draw(shape);
73: }
74:
75: g2.dispose();
76: }
77:
78: public Insets getBorderInsets(Component c) {
79: return new Insets(2, 3, 2, 3);
80: }
81:
82: public boolean isBorderOpaque() {
83: return false;
84: }
85:
86: }
87:
88: private static final float ARC_SIZE = 8;
89: private static final float STROKE_WIDTH = 1;
90: private static final Paint STROKE_PAINT = new Color(0xCCCCCC);
91: private static final Paint FILL_PAINT = new Color(0xCCFFFFFF, true);
92: }
|