|
1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.util.swing; |
|
27 |
|
28 import java.awt.*; |
|
29 import java.awt.event.MouseMotionListener; |
|
30 import javax.swing.*; |
|
31 import javax.swing.plaf.basic.BasicInternalFrameUI; |
|
32 |
|
33 /** |
|
34 * The {@code ExtInternalFrame} class is a {@code JInternalFrame} with the |
|
35 * following extras: |
|
36 * <ul> |
|
37 * <li> |
|
38 * the ability to {@link #setValidateRoot resize with its content} |
|
39 * </li> |
|
40 * <li> |
|
41 * the ability to {@link #disableMove disable user movement} of the frame |
|
42 * </li> |
|
43 * </ul> |
|
44 */ |
|
45 @SuppressWarnings({"serial"}) |
|
46 public class ExtInternalFrame extends JInternalFrame { |
|
47 // |
|
48 // Instance data |
|
49 // |
|
50 |
|
51 // Default behavior |
|
52 private boolean validateRoot = true; |
|
53 |
|
54 // |
|
55 // Constructors |
|
56 // |
|
57 |
|
58 public ExtInternalFrame() { |
|
59 init(); |
|
60 } |
|
61 |
|
62 public ExtInternalFrame(String title) { |
|
63 super(title); |
|
64 init(); |
|
65 } |
|
66 |
|
67 public ExtInternalFrame(String title, boolean resizable) { |
|
68 super(title, resizable); |
|
69 init(); |
|
70 } |
|
71 |
|
72 public ExtInternalFrame(String title, boolean resizable, |
|
73 boolean closable) { |
|
74 |
|
75 super(title, resizable, closable); |
|
76 init(); |
|
77 } |
|
78 |
|
79 public ExtInternalFrame(String title, boolean resizable, |
|
80 boolean closable, boolean maximizable) { |
|
81 |
|
82 super(title, resizable, closable, maximizable); |
|
83 init(); |
|
84 } |
|
85 |
|
86 public ExtInternalFrame(String title, boolean resizable, |
|
87 boolean closable, boolean maximizable, boolean iconifiable) { |
|
88 |
|
89 super(title, resizable, closable, maximizable, iconifiable); |
|
90 init(); |
|
91 } |
|
92 |
|
93 // |
|
94 // ExtInternalFrame methods |
|
95 // |
|
96 |
|
97 /** |
|
98 * Prevents the user from moving this {@code JInternalFrame}. |
|
99 */ |
|
100 public void disableMove() { |
|
101 BasicInternalFrameUI ui = (BasicInternalFrameUI)getUI(); |
|
102 Component north = ui.getNorthPane(); |
|
103 // Yes, this is a hack, but JInternalFrame forces our hand here |
|
104 removeMouseMotionListeners(north); |
|
105 } |
|
106 |
|
107 /** |
|
108 * Sets whether this {@code JInternalFrame}'s {@code JRootPane} is a root of |
|
109 * the validation hierarchy. Setting this to {@code true} (the default is |
|
110 * {@code false}) means that this {@code JInternalFrame}'s size can change |
|
111 * with its contents. |
|
112 */ |
|
113 public void setValidateRoot(boolean validateRoot) { |
|
114 this.validateRoot = validateRoot; |
|
115 } |
|
116 |
|
117 // |
|
118 // Private methods |
|
119 // |
|
120 |
|
121 private void init() { |
|
122 setRootPane(new JRootPane() { |
|
123 @Override |
|
124 public boolean isValidateRoot() { |
|
125 return validateRoot; |
|
126 } |
|
127 }); |
|
128 } |
|
129 |
|
130 private void removeMouseMotionListeners(Component comp) { |
|
131 for (MouseMotionListener listener : comp.getMouseMotionListeners()) { |
|
132 comp.removeMouseMotionListener(listener); |
|
133 } |
|
134 |
|
135 if (comp instanceof Container) { |
|
136 for (Component child : ((Container)comp).getComponents()) { |
|
137 removeMouseMotionListeners(child); |
|
138 } |
|
139 } |
|
140 } |
|
141 } |