001: /*
002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Substance Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package org.jvnet.substance.shaperpack;
031:
032: import java.awt.Insets;
033: import java.awt.geom.GeneralPath;
034: import java.awt.geom.Point2D;
035: import java.util.ArrayList;
036:
037: public class CanonicalPath {
038: private ArrayList<Point2D> majorPoints;
039:
040: private ArrayList<Point2D> minorPoints;
041:
042: private double ratio;
043:
044: public CanonicalPath(ArrayList<Point2D> majorPoints,
045: ArrayList<Point2D> minorPoints, double ratio) {
046: if (majorPoints.size() != minorPoints.size())
047: throw new IllegalArgumentException(
048: "Sizes of major and minor must be equal");
049: this .majorPoints = majorPoints;
050: this .minorPoints = minorPoints;
051: this .ratio = ratio;
052: }
053:
054: public GeneralPath getPath(int width, int height, Insets insets) {
055: GeneralPath path = new GeneralPath();
056: if (this .majorPoints.size() < 2)
057: return path;
058:
059: int xs = (insets == null) ? 0 : insets.left;
060: int ys = (insets == null) ? 0 : insets.top;
061: if (insets != null) {
062: width -= (insets.left + insets.right);
063: height -= (insets.top + insets.bottom);
064: }
065:
066: path.moveTo((float) (xs + width
067: * this .majorPoints.get(0).getX()), (float) (ys + height
068: * this .majorPoints.get(0).getY()));
069: for (int i = 1; i < this .majorPoints.size(); i++) {
070: path.quadTo((float) (xs + width
071: * this .minorPoints.get(i - 1).getX()),
072: (float) (ys + height
073: * this .minorPoints.get(i - 1).getY()),
074: (float) (xs + width
075: * this .majorPoints.get(i).getX()),
076: (float) (ys + height
077: * this .majorPoints.get(i).getY()));
078: }
079: path.quadTo((float) (xs + width
080: * this .minorPoints.get(this .minorPoints.size() - 1)
081: .getX()), (float) (ys + height
082: * this .minorPoints.get(this .minorPoints.size() - 1)
083: .getY()), (float) (xs + width
084: * this .majorPoints.get(0).getX()), (float) (ys + height
085: * this .majorPoints.get(0).getY()));
086: return path;
087: }
088:
089: public ArrayList<Point2D> getMajorPoints() {
090: return majorPoints;
091: }
092:
093: public ArrayList<Point2D> getMinorPoints() {
094: return minorPoints;
095: }
096:
097: public double getRatio() {
098: return ratio;
099: }
100:
101: }
|