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.Component;
024: import java.awt.Font;
025: import java.awt.FontMetrics;
026: import java.awt.Shape;
027: import java.awt.Toolkit;
028:
029: import javax.swing.event.DocumentEvent;
030:
031: public class LabelView extends GlyphView implements TabableView {
032: private boolean outOfSync = true;
033: private Font font;
034:
035: private Color background;
036: private Color foreground;
037:
038: private boolean strikeThrough;
039: private boolean subscript;
040: private boolean super script;
041: private boolean underline;
042:
043: public LabelView(final Element element) {
044: super (element);
045: }
046:
047: public void changedUpdate(final DocumentEvent event,
048: final Shape allocation, final ViewFactory factory) {
049: outOfSync = true;
050: super .changedUpdate(event, allocation, factory);
051: }
052:
053: public boolean isSuperscript() {
054: lazySync();
055: return super script;
056: }
057:
058: public boolean isSubscript() {
059: lazySync();
060: return subscript;
061: }
062:
063: public boolean isStrikeThrough() {
064: lazySync();
065: return strikeThrough;
066: }
067:
068: public boolean isUnderline() {
069: lazySync();
070: return underline;
071: }
072:
073: public Font getFont() {
074: lazySync();
075: return font;
076: }
077:
078: public Color getForeground() {
079: lazySync();
080: return foreground;
081: }
082:
083: public Color getBackground() {
084: lazySync();
085: return background;
086: }
087:
088: protected FontMetrics getFontMetrics() {
089: lazySync();
090: Component component = getComponent();
091: if (component == null) {
092: return Toolkit.getDefaultToolkit().getFontMetrics(font);
093: }
094: return component.getFontMetrics(font);
095: }
096:
097: protected void setPropertiesFromAttributes() {
098: outOfSync = false;
099:
100: font = super .getFont();
101: foreground = super .getForeground();
102: setBackground(super .getBackground());
103:
104: setStrikeThrough(super .isStrikeThrough());
105: setSubscript(super .isSubscript());
106: setSuperscript(super .isSuperscript());
107: setUnderline(super .isUnderline());
108: }
109:
110: protected void setBackground(final Color background) {
111: this .background = background;
112: }
113:
114: protected void setSubscript(final boolean subscript) {
115: this .subscript = subscript;
116: }
117:
118: protected void setSuperscript(final boolean super script) {
119: this .super script = super script;
120: }
121:
122: protected void setStrikeThrough(final boolean strikeThrough) {
123: this .strikeThrough = strikeThrough;
124: }
125:
126: protected void setUnderline(final boolean underline) {
127: this .underline = underline;
128: }
129:
130: private void lazySync() {
131: if (outOfSync) {
132: setPropertiesFromAttributes();
133: }
134: }
135: }
|