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.event.MouseEvent;
023: import java.util.Vector;
024:
025: import javax.accessibility.Accessible;
026: import javax.swing.JComponent;
027: import javax.swing.JPopupMenu;
028: import javax.swing.Popup;
029: import javax.swing.plaf.ComponentUI;
030: import javax.swing.plaf.PopupMenuUI;
031:
032: /**
033: * All the methods described in public api
034: */
035: public class MultiPopupMenuUI extends PopupMenuUI {
036:
037: protected Vector uis = new Vector();
038:
039: /**
040: * Used in cycles. numberOfUIs = Correct number of UIs + 1, but the variable
041: * used in that sence
042: */
043: private int numberOfUIs;
044:
045: public static ComponentUI createUI(JComponent a) {
046: MultiPopupMenuUI mui = new MultiPopupMenuUI();
047: ComponentUI result = MultiLookAndFeel
048: .createUIs(mui, mui.uis, a);
049: mui.numberOfUIs = mui.uis.size();
050: return result;
051: }
052:
053: @Override
054: public boolean contains(JComponent a, int b, int c) {
055: for (int i = 1; i < numberOfUIs; i++) {
056: ((ComponentUI) uis.get(i)).contains(a, b, c);
057: }
058: return ((ComponentUI) uis.firstElement()).contains(a, b, c);
059: }
060:
061: @Override
062: public Accessible getAccessibleChild(JComponent a, int b) {
063: for (int i = 1; i < numberOfUIs; i++) {
064: ((ComponentUI) uis.get(i)).getAccessibleChild(a, b);
065: }
066: return ((ComponentUI) uis.firstElement()).getAccessibleChild(a,
067: b);
068: }
069:
070: @Override
071: public int getAccessibleChildrenCount(JComponent a) {
072: for (int i = 1; i < numberOfUIs; i++) {
073: ((ComponentUI) uis.get(i)).getAccessibleChildrenCount(a);
074: }
075: return ((ComponentUI) uis.firstElement())
076: .getAccessibleChildrenCount(a);
077: }
078:
079: @Override
080: public Dimension getMaximumSize(JComponent a) {
081: for (int i = 1; i < numberOfUIs; i++) {
082: ((ComponentUI) uis.get(i)).getMaximumSize(a);
083: }
084: return ((ComponentUI) uis.firstElement()).getMaximumSize(a);
085: }
086:
087: @Override
088: public Dimension getMinimumSize(JComponent a) {
089: for (int i = 1; i < numberOfUIs; i++) {
090: ((ComponentUI) uis.get(i)).getMinimumSize(a);
091: }
092: return ((ComponentUI) uis.firstElement()).getMinimumSize(a);
093: }
094:
095: @Override
096: public Dimension getPreferredSize(JComponent a) {
097: for (int i = 1; i < numberOfUIs; i++) {
098: ((ComponentUI) uis.get(i)).getPreferredSize(a);
099: }
100: return ((ComponentUI) uis.firstElement()).getPreferredSize(a);
101: }
102:
103: public ComponentUI[] getUIs() {
104: return MultiLookAndFeel.uisToArray(uis);
105: }
106:
107: @Override
108: public void installUI(JComponent a) {
109: for (Object ui : uis) {
110: ((ComponentUI) ui).installUI(a);
111: }
112: }
113:
114: @Override
115: public void paint(Graphics a, JComponent b) {
116: for (Object ui : uis) {
117: ((ComponentUI) ui).paint(a, b);
118: }
119: }
120:
121: @Override
122: public void uninstallUI(JComponent a) {
123: for (Object ui : uis) {
124: ((ComponentUI) ui).uninstallUI(a);
125: }
126: }
127:
128: @Override
129: public void update(Graphics a, JComponent b) {
130: for (Object ui : uis) {
131: ((ComponentUI) ui).update(a, b);
132: }
133: }
134:
135: @Override
136: public Popup getPopup(JPopupMenu popup, int x, int y) {
137: for (int i = 1; i < numberOfUIs; i++) {
138: ((PopupMenuUI) uis.get(i)).getPopup(popup, x, y);
139: }
140: return ((PopupMenuUI) uis.firstElement()).getPopup(popup, x, y);
141: }
142:
143: @Override
144: public boolean isPopupTrigger(MouseEvent event) {
145: for (int i = 1; i < numberOfUIs; i++) {
146: ((PopupMenuUI) uis.get(i)).isPopupTrigger(event);
147: }
148: return ((PopupMenuUI) uis.firstElement()).isPopupTrigger(event);
149: }
150: }
|