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.geometry;
021:
022: import java.awt.BasicStroke;
023: import java.awt.Graphics2D;
024: import java.awt.Shape;
025: import java.awt.Stroke;
026: import java.awt.geom.AffineTransform;
027:
028: public final class FStroke {
029:
030: public final double width;
031: public final double dash;
032: public final double space;
033:
034: public final boolean isSolid;
035:
036: public FStroke(double width) {
037: this (width, 0.0, 0.0);
038: }
039:
040: public FStroke(double width, double dash) {
041: this (width, dash, 0.0);
042: }
043:
044: public FStroke(double width, double dash, double space) {
045: this .width = (width < 0.0) ? -width : width;
046:
047: if (dash <= 0.0) {
048: this .isSolid = true;
049: this .dash = 0.0;
050: this .space = 0.0;
051: } else {
052: // this.isSolid = false;
053: // this.dash = dash;
054: // this.space = (space <= 0.0) ? (dash + width) : space;
055: this .isSolid = true;
056: this .dash = 0.0;
057: this .space = 0.0;
058: }
059: }
060:
061: public final Stroke createSolidStroke(Graphics2D g2) {
062: return createSolidStroke(g2.getTransform());
063: }
064:
065: public final Stroke createStroke(Graphics2D g2) {
066: return createStroke(g2.getTransform());
067: }
068:
069: public final Stroke createSolidStroke(AffineTransform at) {
070: double scale;
071:
072: if (at == null) {
073: scale = 1.0;
074: } else {
075: double a = at.getScaleX();
076: double b = at.getShearY();
077: scale = Math.sqrt(a * a + b * b);
078: if (scale <= 0.0)
079: scale = 1.0;
080: }
081:
082: double k = scale * width;
083:
084: if (k < 1.0) {
085: return new BasicStroke((float) (width / k),
086: BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
087: }
088:
089: return new BasicStroke((float) width, BasicStroke.CAP_BUTT,
090: BasicStroke.JOIN_BEVEL);
091: }
092:
093: public final Stroke createStroke(AffineTransform at) {
094: double scale;
095:
096: if (at == null) {
097: scale = 1.0;
098: } else {
099: double a = at.getScaleX();
100: double b = at.getShearY();
101: scale = Math.sqrt(a * a + b * b);
102: if (scale <= 0.0)
103: scale = 1.0;
104: }
105:
106: double k = scale * width;
107:
108: if (k < 1.0) {
109: return (isSolid) ? new BasicStroke((float) (width / k),
110: BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)
111: : new BasicStroke((float) (width / k),
112: BasicStroke.CAP_BUTT,
113: BasicStroke.JOIN_BEVEL, 0, new float[] {
114: (float) (dash / k),
115: (float) (space / k) }, 0);
116: }
117:
118: return (isSolid) ? new BasicStroke((float) width,
119: BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)
120: : new BasicStroke((float) width, BasicStroke.CAP_BUTT,
121: BasicStroke.JOIN_BEVEL, 0, new float[] {
122: (float) dash, (float) space }, 0);
123: }
124: }
|