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: package javax.swing.plaf.basic;
018:
019: import java.awt.event.MouseEvent;
020:
021: import javax.swing.BoxLayout;
022: import javax.swing.JComponent;
023: import javax.swing.JPopupMenu;
024: import javax.swing.LookAndFeel;
025: import javax.swing.plaf.ComponentUI;
026: import javax.swing.plaf.PopupMenuUI;
027:
028: import org.apache.harmony.x.swing.Utilities;
029:
030: public class BasicPopupMenuUI extends PopupMenuUI {
031:
032: private static final String PROPERTY_PREFIX = "PopupMenu";
033:
034: protected JPopupMenu popupMenu;
035:
036: public static ComponentUI createUI(final JComponent c) {
037: return new BasicPopupMenuUI();
038: }
039:
040: public void installDefaults() {
041: LookAndFeel.installColorsAndFont(popupMenu, PROPERTY_PREFIX
042: + ".background", PROPERTY_PREFIX + ".foreground",
043: PROPERTY_PREFIX + ".font");
044: LookAndFeel.installBorder(popupMenu, PROPERTY_PREFIX
045: + ".border");
046: LookAndFeel.installProperty(popupMenu, "opaque", Boolean.TRUE);
047: }
048:
049: protected void uninstallDefaults() {
050: LookAndFeel.uninstallBorder(popupMenu);
051: Utilities.uninstallColorsAndFont(popupMenu);
052: }
053:
054: protected void installKeyboardActions() {
055: if (popupMenu == null) {
056: return;
057: }
058: Utilities
059: .installKeyboardActions(
060: popupMenu,
061: JComponent.WHEN_FOCUSED,
062: PROPERTY_PREFIX
063: + ".selectedWindowInputMapBindings",
064: PROPERTY_PREFIX
065: + ".selectedWindowInputMapBindings.RightToLeft");
066:
067: }
068:
069: protected void uninstallKeyboardActions() {
070: Utilities.uninstallKeyboardActions(popupMenu,
071: JComponent.WHEN_FOCUSED);
072: }
073:
074: protected void installListeners() {
075: RootPaneFocusHandler.attach();
076: }
077:
078: protected void uninstallListeners() {
079: RootPaneFocusHandler.detach();
080: }
081:
082: public void installUI(final JComponent c) {
083: popupMenu = (JPopupMenu) c;
084: if (Utilities.isUIResource(popupMenu.getLayout())) {
085: popupMenu.setLayout(new DefaultMenuLayout(popupMenu,
086: BoxLayout.Y_AXIS));
087: }
088: installDefaults();
089: installListeners();
090: installKeyboardActions();
091: }
092:
093: public void uninstallUI(final JComponent c) {
094: uninstallKeyboardActions();
095: uninstallListeners();
096: uninstallDefaults();
097: popupMenu = null;
098: }
099:
100: public boolean isPopupTrigger(final MouseEvent event) {
101: if (event == null) {
102: throw new NullPointerException();
103: }
104:
105: return false;
106: }
107: }
|