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.model.elements;
21:
22: import java.awt.Color;
23: import java.awt.Font;
24: import java.awt.GradientPaint;
25: import java.awt.Graphics2D;
26: import java.awt.Paint;
27: import java.awt.Shape;
28: import java.awt.geom.Rectangle2D;
29:
30: public class Renderers {
31:
32: public static void renderGradient(Graphics2D g, Shape s) {
33: Shape oldClip = g.getClip();
34: Paint oldPaint = g.getPaint();
35:
36: Rectangle2D bounds = s.getBounds2D();
37:
38: Rectangle2D oldClipBounds = oldClip.getBounds2D();
39:
40: double x = bounds.getX();
41: double y = bounds.getY();
42: double h = bounds.getHeight();
43: double w = bounds.getWidth();
44:
45: Rectangle2D newClip = new Rectangle2D.Double();
46:
47: Rectangle2D gradientClip = new Rectangle2D.Double();
48:
49: for (int i = 1; i < GRADIENT_Y.length; i++) {
50: double y1 = y + h * GRADIENT_Y[i - 1];
51: double y2 = y + h * GRADIENT_Y[i];
52:
53: gradientClip.setRect(x, y1, w, y2 - y1);
54: Rectangle2D.intersect(oldClipBounds, gradientClip, newClip);
55:
56: g.setClip(newClip);
57: g.setPaint(new GradientPaint((float) x, (float) y1,
58: GRADIENT_COLOR[i - 1], (float) x, (float) y2,
59: GRADIENT_COLOR[i]));
60: g.fill(s);
61: }
62:
63: g.setClip(oldClip);
64: g.setPaint(oldPaint);
65: }
66:
67: public static void renderString(Graphics2D g, String text,
68: float cx, float cy, float height, float maxWidth) {
69: // g.setFont(FONT);
70: // FontMetrics fm = g.getFontMetrics();
71: //
72: // Rectangle2D stringBounds = fm.getStringBounds(text, g);
73: //
74: // double scale = height / stringBounds.getHeight();
75: //
76: // double scaledMaxWidth = maxWidth / scale;
77: // if (scaledMaxWidth > maxWidth) {
78: // }
79: // String end = "...";
80: //
81: //
82: }
83:
84: private static final double[] GRADIENT_Y = { 0, 0.0843, 0.1798,
85: 0.7416, 0.9045, 1.0674 };
86:
87: private static final Color[] GRADIENT_COLOR = {
88: new Color(0xA9CDE8), new Color(0xDDEBF6),
89: new Color(0xFFFFFF), new Color(0xDCE3EF),
90: new Color(0xE7F1F9), new Color(0xDCE3EF) };
91:
92: private static final Font FONT = new Font("sans-serif", Font.PLAIN,
93: 20);
94: }
|