author | ant |
Fri, 22 Feb 2013 15:13:13 +0400 | |
changeset 15983 | 26a673dec5b2 |
parent 13604 | 31089af1a447 |
child 16839 | d0f2e97b7359 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
package sun.awt.X11; |
|
26 |
||
27 |
import java.awt.*; |
|
28 |
import java.awt.peer.*; |
|
29 |
||
30 |
import java.util.Vector; |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
31 |
import sun.util.logging.PlatformLogger; |
13604 | 32 |
import sun.awt.AWTAccessor; |
2 | 33 |
|
34 |
public class XMenuPeer extends XMenuItemPeer implements MenuPeer { |
|
35 |
||
36 |
/************************************************ |
|
37 |
* |
|
38 |
* Data members |
|
39 |
* |
|
40 |
************************************************/ |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
41 |
private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XMenuPeer"); |
2 | 42 |
|
43 |
/** |
|
44 |
* Window that correspond to this menu |
|
45 |
*/ |
|
46 |
XMenuWindow menuWindow; |
|
47 |
||
48 |
/************************************************ |
|
49 |
* |
|
50 |
* Construction |
|
51 |
* |
|
52 |
************************************************/ |
|
53 |
XMenuPeer(Menu target) { |
|
54 |
super(target); |
|
55 |
} |
|
56 |
||
57 |
/** |
|
58 |
* This function is called when menu is bound |
|
59 |
* to its container window. Creates submenu window |
|
60 |
* that fills its items vector while construction |
|
61 |
*/ |
|
62 |
void setContainer(XBaseMenuWindow container) { |
|
63 |
super.setContainer(container); |
|
64 |
menuWindow = new XMenuWindow(this); |
|
65 |
} |
|
66 |
||
67 |
||
68 |
/************************************************ |
|
69 |
* |
|
70 |
* Implementaion of interface methods |
|
71 |
* |
|
72 |
************************************************/ |
|
73 |
||
74 |
/* |
|
75 |
* From MenuComponentPeer |
|
76 |
*/ |
|
77 |
||
78 |
/** |
|
79 |
* Disposes menu window if needed |
|
80 |
*/ |
|
81 |
public void dispose() { |
|
82 |
if (menuWindow != null) { |
|
83 |
menuWindow.dispose(); |
|
84 |
} |
|
85 |
super.dispose(); |
|
86 |
} |
|
87 |
||
88 |
/** |
|
89 |
* Resets text metrics for this item, for its menu window |
|
90 |
* and for all descendant menu windows |
|
91 |
*/ |
|
92 |
public void setFont(Font font) { |
|
93 |
//TODO:We can decrease count of repaints here |
|
94 |
//and get rid of recursion |
|
95 |
resetTextMetrics(); |
|
96 |
||
97 |
XMenuWindow menuWindow = getMenuWindow(); |
|
98 |
if (menuWindow != null) { |
|
99 |
menuWindow.setItemsFont(font); |
|
100 |
} |
|
101 |
||
102 |
repaintIfShowing(); |
|
103 |
} |
|
104 |
||
105 |
/* |
|
106 |
* From MenuPeer |
|
107 |
*/ |
|
108 |
/** |
|
109 |
* addSeparator routines are not used |
|
110 |
* in peers. Shared code invokes addItem("-") |
|
111 |
* for adding separators |
|
112 |
*/ |
|
113 |
public void addSeparator() { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
114 |
if (log.isLoggable(PlatformLogger.FINER)) log.finer("addSeparator is not implemented"); |
2 | 115 |
} |
116 |
||
117 |
public void addItem(MenuItem item) { |
|
118 |
XMenuWindow menuWindow = getMenuWindow(); |
|
119 |
if (menuWindow != null) { |
|
120 |
menuWindow.addItem(item); |
|
121 |
} else { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
122 |
if (log.isLoggable(PlatformLogger.FINE)) { |
2 | 123 |
log.fine("Attempt to use XMenuWindowPeer without window"); |
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
||
128 |
public void delItem(int index) { |
|
129 |
XMenuWindow menuWindow = getMenuWindow(); |
|
130 |
if (menuWindow != null) { |
|
131 |
menuWindow.delItem(index); |
|
132 |
} else { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
133 |
if (log.isLoggable(PlatformLogger.FINE)) { |
2 | 134 |
log.fine("Attempt to use XMenuWindowPeer without window"); |
135 |
} |
|
136 |
} |
|
137 |
} |
|
138 |
||
139 |
/************************************************ |
|
140 |
* |
|
141 |
* Access to target's fields |
|
142 |
* |
|
143 |
************************************************/ |
|
144 |
Vector getTargetItems() { |
|
13604 | 145 |
return AWTAccessor.getMenuAccessor().getItems((Menu)getTarget()); |
2 | 146 |
} |
147 |
||
148 |
/************************************************ |
|
149 |
* |
|
150 |
* Overriden behaviour |
|
151 |
* |
|
152 |
************************************************/ |
|
153 |
boolean isSeparator() { |
|
154 |
return false; |
|
155 |
} |
|
156 |
||
157 |
//Fix for 6180416: Shortcut keys are displayed against Menus on XToolkit |
|
158 |
//Menu should always return null as shortcutText |
|
159 |
String getShortcutText() { |
|
160 |
return null; |
|
161 |
} |
|
162 |
||
163 |
/************************************************ |
|
164 |
* |
|
165 |
* Utility functions |
|
166 |
* |
|
167 |
************************************************/ |
|
168 |
||
169 |
/** |
|
170 |
* Returns menu window of this menu or null |
|
171 |
* it this menu has no container and so its |
|
172 |
* window can't be created. |
|
173 |
*/ |
|
174 |
XMenuWindow getMenuWindow() { |
|
175 |
return menuWindow; |
|
176 |
} |
|
177 |
||
178 |
} |