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: * @author Roman I. Chernyatchik
019: * @version $Revision$
020: */package javax.swing.text;
021:
022: import java.awt.Color;
023: import java.awt.Rectangle;
024: import java.awt.Shape;
025: import javax.swing.BasicSwingTestCase;
026: import javax.swing.event.DocumentEvent;
027:
028: public class LabelViewRTest extends BasicSwingTestCase {
029: private DefaultStyledDocument styledDoc;
030:
031: private LabelView labelView;
032:
033: public LabelViewRTest() {
034: super ();
035: }
036:
037: @Override
038: protected void setUp() throws Exception {
039: super .setUp();
040: styledDoc = new DefaultStyledDocument();
041: styledDoc.insertString(0, "Hello world", null);
042: labelView = new LabelView(styledDoc.getDefaultRootElement()
043: .getElement(0).getElement(0));
044: }
045:
046: public void testSetPropertiesFromAttributes() {
047: final Marker backgroundColorSetterMarker = new Marker();
048: labelView = new LabelView(styledDoc.getDefaultRootElement()
049: .getElement(0).getElement(0)) {
050: @Override
051: protected void setBackground(Color bg) {
052: super .setBackground(bg);
053: backgroundColorSetterMarker.setOccurred();
054: }
055: };
056: labelView.setPropertiesFromAttributes();
057: if (isHarmony()) {
058: assertTrue(backgroundColorSetterMarker.isOccurred());
059: } else {
060: assertFalse(backgroundColorSetterMarker.isOccurred());
061: }
062: }
063:
064: public void testChangedUpdate() {
065: final Marker preferenceChangeMarker = new Marker();
066: labelView = new LabelView(styledDoc.getDefaultRootElement()
067: .getElement(0).getElement(0)) {
068: @Override
069: public void preferenceChanged(View child, boolean width,
070: boolean height) {
071: preferenceChangeMarker.setOccurred();
072: super .preferenceChanged(child, width, height);
073: }
074:
075: @Override
076: public void changedUpdate(DocumentEvent event,
077: Shape allocation, ViewFactory factory) {
078: // Do nothing.
079: }
080: };
081: DocumentEvent event = new DocumentEvent() {
082: public int getOffset() {
083: return labelView.getStartOffset();
084: }
085:
086: public int getLength() {
087: return labelView.getEndOffset()
088: - labelView.getStartOffset();
089: }
090:
091: public Document getDocument() {
092: return null;
093: }
094:
095: public EventType getType() {
096: return EventType.CHANGE;
097: }
098:
099: public ElementChange getChange(Element elem) {
100: return null;
101: }
102: };
103: Rectangle rectangle = new Rectangle();
104: labelView.changedUpdate(event, rectangle, null);
105: assertFalse(preferenceChangeMarker.isOccurred());
106: }
107: }
|