241 }
242 }
243 }
244
245 protected void assembleSystemMenu() {
246 systemPopupMenu = new JPopupMenu();
247 addSystemMenuItems(systemPopupMenu);
248 enableActions();
249 systemLabel = new JLabel(frame.getFrameIcon()) {
250 protected void paintComponent(Graphics g) {
251 int x = 0;
252 int y = 0;
253 int w = getWidth();
254 int h = getHeight();
255 g = g.create(); // Create scratch graphics
256 if (isOpaque()) {
257 g.setColor(getBackground());
258 g.fillRect(0, 0, w, h);
259 }
260 Icon icon = getIcon();
261 int iconWidth = 0;
262 int iconHeight = 0;
263 if (icon != null &&
264 (iconWidth = icon.getIconWidth()) > 0 &&
265 (iconHeight = icon.getIconHeight()) > 0) {
266
267 // Set drawing scale to make icon scale to our desired size
268 double drawScale;
269 if (iconWidth > iconHeight) {
270 // Center icon vertically
271 y = (h - w*iconHeight/iconWidth) / 2;
272 drawScale = w / (double)iconWidth;
273 } else {
274 // Center icon horizontally
275 x = (w - h*iconWidth/iconHeight) / 2;
276 drawScale = h / (double)iconHeight;
277 }
278 ((Graphics2D)g).translate(x, y);
279 ((Graphics2D)g).scale(drawScale, drawScale);
280 icon.paintIcon(this, g, 0, 0);
281 }
282 g.dispose();
287 if (e.getClickCount() == 2 && frame.isClosable() &&
288 !frame.isIcon()) {
289 systemPopupMenu.setVisible(false);
290 frame.doDefaultCloseAction();
291 }
292 else {
293 super.mouseClicked(e);
294 }
295 }
296 public void mousePressed(MouseEvent e) {
297 try {
298 frame.setSelected(true);
299 } catch(PropertyVetoException pve) {
300 }
301 showSystemPopupMenu(e.getComponent());
302 }
303 });
304 }
305
306 protected void addSystemMenuItems(JPopupMenu menu) {
307 JMenuItem mi = (JMenuItem)menu.add(restoreAction);
308 mi.setMnemonic('R');
309 mi = (JMenuItem)menu.add(moveAction);
310 mi.setMnemonic('M');
311 mi = (JMenuItem)menu.add(sizeAction);
312 mi.setMnemonic('S');
313 mi = (JMenuItem)menu.add(iconifyAction);
314 mi.setMnemonic('n');
315 mi = (JMenuItem)menu.add(maximizeAction);
316 mi.setMnemonic('x');
317 systemPopupMenu.add(new JSeparator());
318 mi = (JMenuItem)menu.add(closeAction);
319 mi.setMnemonic('C');
320 }
321
322 protected void showSystemMenu(){
323 showSystemPopupMenu(systemLabel);
324 }
325
326 private void showSystemPopupMenu(Component invoker){
327 Dimension dim = new Dimension();
328 Border border = frame.getBorder();
329 if (border != null) {
330 dim.width += border.getBorderInsets(frame).left +
331 border.getBorderInsets(frame).right;
332 dim.height += border.getBorderInsets(frame).bottom +
333 border.getBorderInsets(frame).top;
334 }
335 if (!frame.isIcon()) {
336 systemPopupMenu.show(invoker,
337 getX() - dim.width,
338 getY() + getHeight() - dim.height);
339 } else {
424 x, y, buttonWidth, buttonHeight, 2,
425 !leftToRight);
426 }
427
428 if(frame.isMaximizable()) {
429 x = layoutButton(maxButton, Part.WP_MAXBUTTON,
430 x, y, buttonWidth, buttonHeight, (xp != null) ? 2 : 0,
431 !leftToRight);
432 }
433
434 if(frame.isIconifiable()) {
435 layoutButton(iconButton, Part.WP_MINBUTTON,
436 x, y, buttonWidth, buttonHeight, 0,
437 !leftToRight);
438 }
439 }
440 } // end WindowsTitlePaneLayout
441
442 public class WindowsPropertyChangeHandler extends PropertyChangeHandler {
443 public void propertyChange(PropertyChangeEvent evt) {
444 String prop = (String)evt.getPropertyName();
445
446 // Update the internal frame icon for the system menu.
447 if (JInternalFrame.FRAME_ICON_PROPERTY.equals(prop) &&
448 systemLabel != null) {
449 systemLabel.setIcon(frame.getFrameIcon());
450 }
451
452 super.propertyChange(evt);
453 }
454 }
455
456 /**
457 * A versatile Icon implementation which can take an array of Icon
458 * instances (typically <code>ImageIcon</code>s) and choose one that gives the best
459 * quality for a given Graphics2D scale factor when painting.
460 * <p>
461 * The class is public so it can be instantiated by UIDefaults.ProxyLazyValue.
462 * <p>
463 * Note: We assume here that icons are square.
464 */
|
241 }
242 }
243 }
244
245 protected void assembleSystemMenu() {
246 systemPopupMenu = new JPopupMenu();
247 addSystemMenuItems(systemPopupMenu);
248 enableActions();
249 systemLabel = new JLabel(frame.getFrameIcon()) {
250 protected void paintComponent(Graphics g) {
251 int x = 0;
252 int y = 0;
253 int w = getWidth();
254 int h = getHeight();
255 g = g.create(); // Create scratch graphics
256 if (isOpaque()) {
257 g.setColor(getBackground());
258 g.fillRect(0, 0, w, h);
259 }
260 Icon icon = getIcon();
261 int iconWidth;
262 int iconHeight;
263 if (icon != null &&
264 (iconWidth = icon.getIconWidth()) > 0 &&
265 (iconHeight = icon.getIconHeight()) > 0) {
266
267 // Set drawing scale to make icon scale to our desired size
268 double drawScale;
269 if (iconWidth > iconHeight) {
270 // Center icon vertically
271 y = (h - w*iconHeight/iconWidth) / 2;
272 drawScale = w / (double)iconWidth;
273 } else {
274 // Center icon horizontally
275 x = (w - h*iconWidth/iconHeight) / 2;
276 drawScale = h / (double)iconHeight;
277 }
278 ((Graphics2D)g).translate(x, y);
279 ((Graphics2D)g).scale(drawScale, drawScale);
280 icon.paintIcon(this, g, 0, 0);
281 }
282 g.dispose();
287 if (e.getClickCount() == 2 && frame.isClosable() &&
288 !frame.isIcon()) {
289 systemPopupMenu.setVisible(false);
290 frame.doDefaultCloseAction();
291 }
292 else {
293 super.mouseClicked(e);
294 }
295 }
296 public void mousePressed(MouseEvent e) {
297 try {
298 frame.setSelected(true);
299 } catch(PropertyVetoException pve) {
300 }
301 showSystemPopupMenu(e.getComponent());
302 }
303 });
304 }
305
306 protected void addSystemMenuItems(JPopupMenu menu) {
307 JMenuItem mi = menu.add(restoreAction);
308 mi.setMnemonic(getButtonMnemonic("restore"));
309 mi = menu.add(moveAction);
310 mi.setMnemonic(getButtonMnemonic("move"));
311 mi = menu.add(sizeAction);
312 mi.setMnemonic(getButtonMnemonic("size"));
313 mi = menu.add(iconifyAction);
314 mi.setMnemonic(getButtonMnemonic("minimize"));
315 mi = menu.add(maximizeAction);
316 mi.setMnemonic(getButtonMnemonic("maximize"));
317 menu.add(new JSeparator());
318 mi = menu.add(closeAction);
319 mi.setMnemonic(getButtonMnemonic("close"));
320 }
321
322 private static int getButtonMnemonic(String button) {
323 try {
324 return Integer.parseInt(UIManager.getString(
325 "InternalFrameTitlePane." + button + "Button.mnemonic"));
326 } catch (NumberFormatException e) {
327 return -1;
328 }
329 }
330
331 protected void showSystemMenu(){
332 showSystemPopupMenu(systemLabel);
333 }
334
335 private void showSystemPopupMenu(Component invoker){
336 Dimension dim = new Dimension();
337 Border border = frame.getBorder();
338 if (border != null) {
339 dim.width += border.getBorderInsets(frame).left +
340 border.getBorderInsets(frame).right;
341 dim.height += border.getBorderInsets(frame).bottom +
342 border.getBorderInsets(frame).top;
343 }
344 if (!frame.isIcon()) {
345 systemPopupMenu.show(invoker,
346 getX() - dim.width,
347 getY() + getHeight() - dim.height);
348 } else {
433 x, y, buttonWidth, buttonHeight, 2,
434 !leftToRight);
435 }
436
437 if(frame.isMaximizable()) {
438 x = layoutButton(maxButton, Part.WP_MAXBUTTON,
439 x, y, buttonWidth, buttonHeight, (xp != null) ? 2 : 0,
440 !leftToRight);
441 }
442
443 if(frame.isIconifiable()) {
444 layoutButton(iconButton, Part.WP_MINBUTTON,
445 x, y, buttonWidth, buttonHeight, 0,
446 !leftToRight);
447 }
448 }
449 } // end WindowsTitlePaneLayout
450
451 public class WindowsPropertyChangeHandler extends PropertyChangeHandler {
452 public void propertyChange(PropertyChangeEvent evt) {
453 String prop = evt.getPropertyName();
454
455 // Update the internal frame icon for the system menu.
456 if (JInternalFrame.FRAME_ICON_PROPERTY.equals(prop) &&
457 systemLabel != null) {
458 systemLabel.setIcon(frame.getFrameIcon());
459 }
460
461 super.propertyChange(evt);
462 }
463 }
464
465 /**
466 * A versatile Icon implementation which can take an array of Icon
467 * instances (typically <code>ImageIcon</code>s) and choose one that gives the best
468 * quality for a given Graphics2D scale factor when painting.
469 * <p>
470 * The class is public so it can be instantiated by UIDefaults.ProxyLazyValue.
471 * <p>
472 * Note: We assume here that icons are square.
473 */
|