001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package java.awt;
019:
020: import java.awt.geom.AffineTransform;
021: import java.awt.geom.Point2D;
022: import java.awt.geom.Rectangle2D;
023: import java.awt.image.ColorModel;
024:
025: import org.apache.harmony.awt.internal.nls.Messages;
026:
027: public class GradientPaint implements Paint {
028: /**
029: * The start point color
030: */
031: Color color1;
032:
033: /**
034: * The end color point
035: */
036: Color color2;
037:
038: /**
039: * The location of the start point
040: */
041: Point2D point1;
042:
043: /**
044: * The location of the end point
045: */
046: Point2D point2;
047:
048: /**
049: * The indicator of cycle filling. If TRUE filling repeated outside points
050: * stripe, if FALSE solid color filling outside.
051: */
052: boolean cyclic;
053:
054: public GradientPaint(Point2D point1, Color color1, Point2D point2,
055: Color color2, boolean cyclic) {
056: if (point1 == null || point2 == null) {
057: // awt.6D=Point is null
058: throw new NullPointerException(Messages.getString("awt.6D")); //$NON-NLS-1$
059: }
060: if (color1 == null || color2 == null) {
061: // awt.6E=Color is null
062: throw new NullPointerException(Messages.getString("awt.6E")); //$NON-NLS-1$
063: }
064:
065: this .point1 = point1;
066: this .point2 = point2;
067: this .color1 = color1;
068: this .color2 = color2;
069: this .cyclic = cyclic;
070: }
071:
072: public GradientPaint(float x1, float y1, Color color1, float x2,
073: float y2, Color color2, boolean cyclic) {
074: this (new Point2D.Float(x1, y1), color1, new Point2D.Float(x2,
075: y2), color2, cyclic);
076: }
077:
078: public GradientPaint(float x1, float y1, Color color1, float x2,
079: float y2, Color color2) {
080: this (x1, y1, color1, x2, y2, color2, false);
081: }
082:
083: public GradientPaint(Point2D point1, Color color1, Point2D point2,
084: Color color2) {
085: this (point1, color1, point2, color2, false);
086: }
087:
088: public PaintContext createContext(ColorModel cm,
089: Rectangle deviceBounds, Rectangle2D userBounds,
090: AffineTransform t, RenderingHints hints) {
091: return new GradientPaintContext(cm, t, point1, color1, point2,
092: color2, cyclic);
093: }
094:
095: public Color getColor1() {
096: return color1;
097: }
098:
099: public Color getColor2() {
100: return color2;
101: }
102:
103: public Point2D getPoint1() {
104: return point1;
105: }
106:
107: public Point2D getPoint2() {
108: return point2;
109: }
110:
111: public int getTransparency() {
112: int a1 = color1.getAlpha();
113: int a2 = color2.getAlpha();
114: return (a1 == 0xFF && a2 == 0xFF) ? OPAQUE : TRANSLUCENT;
115: }
116:
117: public boolean isCyclic() {
118: return cyclic;
119: }
120: }
|