1 /* 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.java.swing.plaf.motif; 27 28 import java.awt.*; 29 import java.awt.event.*; 30 import javax.swing.*; 31 import javax.swing.event.*; 32 33 import java.util.EventListener; 34 35 import javax.swing.plaf.basic.*; 36 import javax.swing.border.*; 37 import javax.swing.plaf.*; 38 39 40 /** 41 * A Motif {@literal L&F} implementation of InternalFrame. 42 * <p> 43 * <strong>Warning:</strong> 44 * Serialized objects of this class will not be compatible with 45 * future Swing releases. The current serialization support is appropriate 46 * for short term storage or RMI between applications running the same 47 * version of Swing. A future release of Swing will provide support for 48 * long term persistence. 49 * 50 * @author Tom Ball 51 */ 52 public class MotifInternalFrameUI extends BasicInternalFrameUI { 53 54 Color color; 55 Color highlight; 56 Color shadow; 57 MotifInternalFrameTitlePane titlePane; 58 59 /** 60 * As of Java 2 platform v1.3 this previously undocumented field is no 61 * longer used. 62 * Key bindings are now defined by the LookAndFeel, please refer to 63 * the key bindings specification for further details. 64 * 65 * @deprecated As of Java 2 platform v1.3. 66 */ 67 @Deprecated 68 protected KeyStroke closeMenuKey; 69 70 71 ///////////////////////////////////////////////////////////////////////////// 72 // ComponentUI Interface Implementation methods 73 ///////////////////////////////////////////////////////////////////////////// 74 public static ComponentUI createUI(JComponent w) { 75 return new MotifInternalFrameUI((JInternalFrame)w); 76 } 77 78 public MotifInternalFrameUI(JInternalFrame w) { 79 super(w); 80 } 81 82 public void installUI(JComponent c) { 83 super.installUI(c); 84 setColors((JInternalFrame)c); 85 } 86 87 protected void installDefaults() { 88 Border frameBorder = frame.getBorder(); 89 frame.setLayout(internalFrameLayout = createLayoutManager()); 90 if (frameBorder == null || frameBorder instanceof UIResource) { 91 frame.setBorder(new MotifBorders.InternalFrameBorder(frame)); 92 } 93 } 94 95 96 protected void installKeyboardActions(){ 97 super.installKeyboardActions(); 98 // We replace the 99 // we use JPopup in our TitlePane so need escape support 100 closeMenuKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); 101 } 102 103 104 protected void uninstallDefaults() { 105 LookAndFeel.uninstallBorder(frame); 106 frame.setLayout(null); 107 internalFrameLayout = null; 108 } 109 110 private JInternalFrame getFrame(){ 111 return frame; 112 } 113 114 public JComponent createNorthPane(JInternalFrame w) { 115 titlePane = new MotifInternalFrameTitlePane(w); 116 return titlePane; 117 } 118 119 public Dimension getMaximumSize(JComponent x) { 120 return Toolkit.getDefaultToolkit().getScreenSize(); 121 } 122 123 protected void uninstallKeyboardActions(){ 124 super.uninstallKeyboardActions(); 125 if (isKeyBindingRegistered()){ 126 JInternalFrame.JDesktopIcon di = frame.getDesktopIcon(); 127 SwingUtilities.replaceUIActionMap(di, null); 128 SwingUtilities.replaceUIInputMap(di, JComponent.WHEN_IN_FOCUSED_WINDOW, 129 null); 130 } 131 } 132 133 @SuppressWarnings("serial") // anonymous class 134 protected void setupMenuOpenKey(){ 135 super.setupMenuOpenKey(); 136 ActionMap map = SwingUtilities.getUIActionMap(frame); 137 if (map != null) { 138 // BasicInternalFrameUI creates an action with the same name, we override 139 // it as MotifInternalFrameTitlePane has a titlePane ivar that shadows the 140 // titlePane ivar in BasicInternalFrameUI, making supers action throw 141 // an NPE for us. 142 map.put("showSystemMenu", new AbstractAction(){ 143 public void actionPerformed(ActionEvent e){ 144 titlePane.showSystemMenu(); 145 } 146 public boolean isEnabled(){ 147 return isKeyBindingActive(); 148 } 149 }); 150 } 151 } 152 153 @SuppressWarnings("serial") // anonymous class 154 protected void setupMenuCloseKey(){ 155 ActionMap map = SwingUtilities.getUIActionMap(frame); 156 if (map != null) { 157 map.put("hideSystemMenu", new AbstractAction(){ 158 public void actionPerformed(ActionEvent e){ 159 titlePane.hideSystemMenu(); 160 } 161 public boolean isEnabled(){ 162 return isKeyBindingActive(); 163 } 164 }); 165 } 166 167 // Set up the bindings for the DesktopIcon, it is odd that 168 // we install them, and not the desktop icon. 169 JInternalFrame.JDesktopIcon di = frame.getDesktopIcon(); 170 InputMap diInputMap = SwingUtilities.getUIInputMap 171 (di, JComponent.WHEN_IN_FOCUSED_WINDOW); 172 if (diInputMap == null) { 173 Object[] bindings = (Object[])UIManager.get 174 ("DesktopIcon.windowBindings"); 175 if (bindings != null) { 176 diInputMap = LookAndFeel.makeComponentInputMap(di, bindings); 177 178 SwingUtilities.replaceUIInputMap(di, JComponent. 179 WHEN_IN_FOCUSED_WINDOW, 180 diInputMap); 181 } 182 } 183 ActionMap diActionMap = SwingUtilities.getUIActionMap(di); 184 if (diActionMap == null) { 185 diActionMap = new ActionMapUIResource(); 186 diActionMap.put("hideSystemMenu", new AbstractAction(){ 187 public void actionPerformed(ActionEvent e){ 188 JInternalFrame.JDesktopIcon icon = getFrame(). 189 getDesktopIcon(); 190 MotifDesktopIconUI micon = (MotifDesktopIconUI)icon. 191 getUI(); 192 micon.hideSystemMenu(); 193 } 194 public boolean isEnabled(){ 195 return isKeyBindingActive(); 196 } 197 }); 198 SwingUtilities.replaceUIActionMap(di, diActionMap); 199 } 200 } 201 202 /** This method is called when the frame becomes selected. 203 */ 204 protected void activateFrame(JInternalFrame f) { 205 super.activateFrame(f); 206 setColors(f); 207 } 208 /** This method is called when the frame is no longer selected. 209 */ 210 protected void deactivateFrame(JInternalFrame f) { 211 setColors(f); 212 super.deactivateFrame(f); 213 } 214 215 void setColors(JInternalFrame frame) { 216 if (frame.isSelected()) { 217 color = UIManager.getColor("InternalFrame.activeTitleBackground"); 218 } else { 219 color = UIManager.getColor("InternalFrame.inactiveTitleBackground"); 220 } 221 highlight = color.brighter(); 222 shadow = color.darker().darker(); 223 titlePane.setColors(color, highlight, shadow); 224 } 225 }