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 javax.swing.plaf.multi;
019:
020: import java.awt.Dimension;
021: import java.awt.Graphics;
022: import java.awt.Point;
023: import java.awt.Rectangle;
024: import java.util.Vector;
025:
026: import javax.accessibility.Accessible;
027: import javax.swing.JComponent;
028: import javax.swing.plaf.ComponentUI;
029: import javax.swing.plaf.TextUI;
030: import javax.swing.text.BadLocationException;
031: import javax.swing.text.EditorKit;
032: import javax.swing.text.JTextComponent;
033: import javax.swing.text.View;
034: import javax.swing.text.Position.Bias;
035:
036: /**
037: * All the methods described in public api
038: */
039: public class MultiTextUI extends TextUI {
040:
041: protected Vector uis = new Vector();
042:
043: /**
044: * Used in cycles. numberOfUIs = Correct number of UIs + 1, but the variable
045: * used in that sence
046: */
047: private int numberOfUIs;
048:
049: public static ComponentUI createUI(JComponent a) {
050: MultiTextUI mui = new MultiTextUI();
051: ComponentUI result = MultiLookAndFeel
052: .createUIs(mui, mui.uis, a);
053: mui.numberOfUIs = mui.uis.size();
054: return result;
055: }
056:
057: @Override
058: public boolean contains(JComponent a, int b, int c) {
059: for (int i = 1; i < numberOfUIs; i++) {
060: ((ComponentUI) uis.get(i)).contains(a, b, c);
061: }
062: return ((ComponentUI) uis.firstElement()).contains(a, b, c);
063: }
064:
065: @Override
066: public Accessible getAccessibleChild(JComponent a, int b) {
067: for (int i = 1; i < numberOfUIs; i++) {
068: ((ComponentUI) uis.get(i)).getAccessibleChild(a, b);
069: }
070: return ((ComponentUI) uis.firstElement()).getAccessibleChild(a,
071: b);
072: }
073:
074: @Override
075: public int getAccessibleChildrenCount(JComponent a) {
076: for (int i = 1; i < numberOfUIs; i++) {
077: ((ComponentUI) uis.get(i)).getAccessibleChildrenCount(a);
078: }
079: return ((ComponentUI) uis.firstElement())
080: .getAccessibleChildrenCount(a);
081: }
082:
083: @Override
084: public Dimension getMaximumSize(JComponent a) {
085: for (int i = 1; i < numberOfUIs; i++) {
086: ((ComponentUI) uis.get(i)).getMaximumSize(a);
087: }
088: return ((ComponentUI) uis.firstElement()).getMaximumSize(a);
089: }
090:
091: @Override
092: public Dimension getMinimumSize(JComponent a) {
093: for (int i = 1; i < numberOfUIs; i++) {
094: ((ComponentUI) uis.get(i)).getMinimumSize(a);
095: }
096: return ((ComponentUI) uis.firstElement()).getMinimumSize(a);
097: }
098:
099: @Override
100: public Dimension getPreferredSize(JComponent a) {
101: for (int i = 1; i < numberOfUIs; i++) {
102: ((ComponentUI) uis.get(i)).getPreferredSize(a);
103: }
104: return ((ComponentUI) uis.firstElement()).getPreferredSize(a);
105: }
106:
107: public ComponentUI[] getUIs() {
108: return MultiLookAndFeel.uisToArray(uis);
109: }
110:
111: @Override
112: public void installUI(JComponent a) {
113: for (Object ui : uis) {
114: ((ComponentUI) ui).installUI(a);
115: }
116: }
117:
118: @Override
119: public void paint(Graphics a, JComponent b) {
120: for (Object ui : uis) {
121: ((ComponentUI) ui).paint(a, b);
122: }
123: }
124:
125: @Override
126: public void uninstallUI(JComponent a) {
127: for (Object ui : uis) {
128: ((ComponentUI) ui).uninstallUI(a);
129: }
130: }
131:
132: @Override
133: public void update(Graphics a, JComponent b) {
134: for (Object ui : uis) {
135: ((ComponentUI) ui).update(a, b);
136: }
137: }
138:
139: @Override
140: public Rectangle modelToView(JTextComponent a0, int a1)
141: throws BadLocationException {
142: for (int i = 1; i < numberOfUIs; i++) {
143: ((TextUI) uis.get(i)).modelToView(a0, a1);
144: }
145: return ((TextUI) uis.firstElement()).modelToView(a0, a1);
146: }
147:
148: @Override
149: public Rectangle modelToView(JTextComponent a0, int a1, Bias a2)
150: throws BadLocationException {
151: for (int i = 1; i < numberOfUIs; i++) {
152: ((TextUI) uis.get(i)).modelToView(a0, a1, a2);
153: }
154: return ((TextUI) uis.firstElement()).modelToView(a0, a1, a2);
155: }
156:
157: @Override
158: public int viewToModel(JTextComponent a0, Point a1) {
159: for (int i = 1; i < numberOfUIs; i++) {
160: ((TextUI) uis.get(i)).viewToModel(a0, a1);
161: }
162: return ((TextUI) uis.firstElement()).viewToModel(a0, a1);
163: }
164:
165: @Override
166: public int viewToModel(JTextComponent a0, Point a1, Bias[] a2) {
167: for (int i = 1; i < numberOfUIs; i++) {
168: ((TextUI) uis.get(i)).viewToModel(a0, a1, a2);
169: }
170: return ((TextUI) uis.firstElement()).viewToModel(a0, a1, a2);
171: }
172:
173: @Override
174: public int getNextVisualPositionFrom(JTextComponent a0, int a1,
175: Bias a2, int a3, Bias[] a4) throws BadLocationException {
176: for (int i = 1; i < numberOfUIs; i++) {
177: ((TextUI) uis.get(i)).getNextVisualPositionFrom(a0, a1, a2,
178: a3, a4);
179: }
180: return ((TextUI) uis.firstElement()).getNextVisualPositionFrom(
181: a0, a1, a2, a3, a4);
182: }
183:
184: @Override
185: public void damageRange(JTextComponent a0, int a1, int a2) {
186: for (Object ui : uis) {
187: ((TextUI) ui).damageRange(a0, a1, a2);
188: }
189: }
190:
191: @Override
192: public void damageRange(JTextComponent a0, int a1, int a2, Bias a3,
193: Bias a4) {
194: for (Object ui : uis) {
195: ((TextUI) ui).damageRange(a0, a1, a2, a3, a4);
196: }
197: }
198:
199: @Override
200: public EditorKit getEditorKit(JTextComponent a0) {
201: for (int i = 1; i < numberOfUIs; i++) {
202: ((TextUI) uis.get(i)).getEditorKit(a0);
203: }
204: return ((TextUI) uis.firstElement()).getEditorKit(a0);
205: }
206:
207: @Override
208: public View getRootView(JTextComponent a0) {
209: for (int i = 1; i < numberOfUIs; i++) {
210: ((TextUI) uis.get(i)).getRootView(a0);
211: }
212: return ((TextUI) uis.firstElement()).getRootView(a0);
213: }
214:
215: @Override
216: public String getToolTipText(JTextComponent a0, Point a1) {
217: for (int i = 1; i < numberOfUIs; i++) {
218: ((TextUI) uis.get(i)).getToolTipText(a0, a1);
219: }
220: return ((TextUI) uis.firstElement()).getToolTipText(a0, a1);
221: }
222: }
|