001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package apichanges;
042:
043: import framework.VisualTestCase;
044: import org.netbeans.api.visual.widget.LabelWidget;
045: import org.netbeans.api.visual.widget.LayerWidget;
046: import org.netbeans.api.visual.widget.Scene;
047: import org.netbeans.api.visual.widget.Widget;
048:
049: import java.awt.*;
050: import java.awt.image.BufferedImage;
051:
052: /**
053: * Test for #98641 - Missing vertical labels
054: * @author David Kaspar
055: */
056: public class LabelOrientationTest extends VisualTestCase {
057:
058: public LabelOrientationTest(String testName) {
059: super (testName);
060: }
061:
062: public void testLabelOrientations() {
063: Scene scene = new Scene();
064: LayerWidget layer = new LayerWidget(scene);
065: scene.addChild(layer);
066: layer.addChild(new Widget(scene));
067:
068: createLabel(layer, "N O R M A L", 100, 100,
069: LabelWidget.Orientation.NORMAL,
070: LabelWidget.Alignment.LEFT,
071: LabelWidget.VerticalAlignment.BASELINE)
072: .setPreferredBounds(null);
073: createLabel(layer, "R O T A T E 9 0", 100, 100,
074: LabelWidget.Orientation.ROTATE_90,
075: LabelWidget.Alignment.LEFT,
076: LabelWidget.VerticalAlignment.BASELINE)
077: .setPreferredBounds(null);
078:
079: createLabel(layer, "NORMAL BASELINE", 200, 100,
080: LabelWidget.Orientation.NORMAL,
081: LabelWidget.Alignment.BASELINE,
082: LabelWidget.VerticalAlignment.BASELINE);
083: createLabel(layer, "ROTATE90 BASELINE", 200, 300,
084: LabelWidget.Orientation.ROTATE_90,
085: LabelWidget.Alignment.BASELINE,
086: LabelWidget.VerticalAlignment.BASELINE);
087:
088: createLabel(layer, "NORMAL LEFT,TOP", 400, 100,
089: LabelWidget.Orientation.NORMAL,
090: LabelWidget.Alignment.LEFT,
091: LabelWidget.VerticalAlignment.TOP);
092: createLabel(layer, "ROTATE90 LEFT,TOP", 400, 300,
093: LabelWidget.Orientation.ROTATE_90,
094: LabelWidget.Alignment.LEFT,
095: LabelWidget.VerticalAlignment.TOP);
096:
097: createLabel(layer, "NORMAL CENTER", 600, 100,
098: LabelWidget.Orientation.NORMAL,
099: LabelWidget.Alignment.CENTER,
100: LabelWidget.VerticalAlignment.CENTER);
101: createLabel(layer, "ROTATE90 CENTER", 600, 300,
102: LabelWidget.Orientation.ROTATE_90,
103: LabelWidget.Alignment.CENTER,
104: LabelWidget.VerticalAlignment.CENTER);
105:
106: createLabel(layer, "NORMAL RIGHT,BOTTOM", 800, 100,
107: LabelWidget.Orientation.NORMAL,
108: LabelWidget.Alignment.RIGHT,
109: LabelWidget.VerticalAlignment.BOTTOM);
110: createLabel(layer, "ROTATE90 RIGHT,BOTTOM", 800, 300,
111: LabelWidget.Orientation.ROTATE_90,
112: LabelWidget.Alignment.RIGHT,
113: LabelWidget.VerticalAlignment.BOTTOM);
114:
115: BufferedImage snapshot = takeOneTimeSnapshot(scene);
116: BufferedImage clean = clearRegions(snapshot, Color.RED,
117: new Rectangle(100, 80, 100, 30), new Rectangle(80, 0,
118: 30, 110),
119:
120: new Rectangle(190, 90, 130, 30), new Rectangle(380, 70,
121: 110, 30), new Rectangle(610, 150, 120, 30),
122: new Rectangle(810, 230, 150, 30),
123:
124: new Rectangle(180, 270, 30, 130), new Rectangle(380,
125: 270, 30, 160),
126: new Rectangle(650, 290, 30, 150), new Rectangle(945,
127: 275, 30, 190)
128:
129: );
130: assertCleaness(testCleaness(clean, Color.WHITE, Color.YELLOW,
131: Color.RED), snapshot, clean);
132: }
133:
134: private static LabelWidget createLabel(LayerWidget layer,
135: String label, int x, int y,
136: LabelWidget.Orientation orientation,
137: LabelWidget.Alignment alignment,
138: LabelWidget.VerticalAlignment verticalAlignment) {
139: LabelWidget widget = new LabelWidget(layer.getScene(), label);
140: widget.setOpaque(true);
141: widget.setBackground(Color.YELLOW);
142: widget.setPreferredLocation(new Point(x, y));
143: widget.setPreferredBounds(new Rectangle(-20, -30, 180, 180));
144: widget.setOrientation(orientation);
145: widget.setAlignment(alignment);
146: widget.setVerticalAlignment(verticalAlignment);
147: layer.addChild(widget);
148: return widget;
149: }
150:
151: }
|