38 |
|
|
39 |
package javax.swing.plaf.basic; |
package javax.swing.plaf.basic; |
40 |
|
|
41 |
|
import java.awt.Component; |
42 |
import java.awt.Dimension; |
import java.awt.Dimension; |
43 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
44 |
import java.beans.PropertyChangeEvent; |
import java.beans.PropertyChangeEvent; |
47 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
48 |
import javax.swing.JMenu; |
import javax.swing.JMenu; |
49 |
import javax.swing.JMenuBar; |
import javax.swing.JMenuBar; |
|
import javax.swing.JMenuItem; |
|
50 |
import javax.swing.JPopupMenu; |
import javax.swing.JPopupMenu; |
51 |
|
import javax.swing.LookAndFeel; |
52 |
import javax.swing.MenuSelectionManager; |
import javax.swing.MenuSelectionManager; |
53 |
import javax.swing.UIDefaults; |
import javax.swing.UIDefaults; |
54 |
import javax.swing.UIManager; |
import javax.swing.UIManager; |
93 |
*/ |
*/ |
94 |
protected ChangeListener createChangeListener(JComponent c) |
protected ChangeListener createChangeListener(JComponent c) |
95 |
{ |
{ |
96 |
return new ChangeHandler(); |
return new ChangeHandler((JMenu) c, this); |
97 |
} |
} |
98 |
|
|
99 |
/** |
/** |
181 |
*/ |
*/ |
182 |
public Dimension getMaximumSize(JComponent c) |
public Dimension getMaximumSize(JComponent c) |
183 |
{ |
{ |
|
// If this menu is in a popup menu, treat it like a regular JMenuItem |
|
|
if (!((JMenu)c).isTopLevelMenu()) |
|
|
{ |
|
|
JMenuItem menuItem = new JMenuItem(((JMenu)c).getText(), ((JMenu)c).getIcon()); |
|
|
return menuItem.getMaximumSize(); |
|
|
} |
|
184 |
return c.getPreferredSize(); |
return c.getPreferredSize(); |
185 |
} |
} |
186 |
|
|
200 |
*/ |
*/ |
201 |
protected void installDefaults() |
protected void installDefaults() |
202 |
{ |
{ |
203 |
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
LookAndFeel.installBorder(menuItem, "Menu.border"); |
204 |
|
LookAndFeel.installColorsAndFont(menuItem, "Menu.background", |
205 |
menuItem.setBackground(defaults.getColor("Menu.background")); |
"Menu.foreground", "Menu.font"); |
206 |
menuItem.setBorder(defaults.getBorder("Menu.border")); |
menuItem.setMargin(UIManager.getInsets("Menu.margin")); |
207 |
menuItem.setFont(defaults.getFont("Menu.font")); |
acceleratorFont = UIManager.getFont("Menu.acceleratorFont"); |
208 |
menuItem.setForeground(defaults.getColor("Menu.foreground")); |
acceleratorForeground = UIManager.getColor("Menu.acceleratorForeground"); |
209 |
menuItem.setMargin(defaults.getInsets("Menu.margin")); |
acceleratorSelectionForeground = UIManager.getColor("Menu.acceleratorSelectionForeground"); |
210 |
acceleratorFont = defaults.getFont("Menu.acceleratorFont"); |
selectionBackground = UIManager.getColor("Menu.selectionBackground"); |
211 |
acceleratorForeground = defaults.getColor("Menu.acceleratorForeground"); |
selectionForeground = UIManager.getColor("Menu.selectionForeground"); |
212 |
acceleratorSelectionForeground = defaults.getColor("Menu.acceleratorSelectionForeground"); |
arrowIcon = UIManager.getIcon("Menu.arrowIcon"); |
213 |
selectionBackground = defaults.getColor("Menu.selectionBackground"); |
oldBorderPainted = UIManager.getBoolean("Menu.borderPainted"); |
|
selectionForeground = defaults.getColor("Menu.selectionForeground"); |
|
|
arrowIcon = defaults.getIcon("Menu.arrowIcon"); |
|
|
oldBorderPainted = defaults.getBoolean("Menu.borderPainted"); |
|
214 |
menuItem.setOpaque(true); |
menuItem.setOpaque(true); |
215 |
} |
} |
216 |
|
|
237 |
|
|
238 |
protected void setupPostTimer(JMenu menu) |
protected void setupPostTimer(JMenu menu) |
239 |
{ |
{ |
240 |
|
// TODO: Implement this properly. |
241 |
} |
} |
242 |
|
|
243 |
/** |
/** |
349 |
|
|
350 |
public void mouseMoved(MouseEvent e) |
public void mouseMoved(MouseEvent e) |
351 |
{ |
{ |
352 |
|
// TODO: What should be done here, if anything? |
353 |
} |
} |
354 |
|
|
355 |
public void mousePressed(MouseEvent e) |
public void mousePressed(MouseEvent e) |
415 |
public void menuDeselected(MenuEvent e) |
public void menuDeselected(MenuEvent e) |
416 |
{ |
{ |
417 |
JMenu menu = (JMenu) menuItem; |
JMenu menu = (JMenu) menuItem; |
418 |
if (menu.isTopLevelMenu()) |
if (menu.getParent() != null) |
419 |
((JMenuBar) menu.getParent()).getSelectionModel().clearSelection(); |
{ |
420 |
else |
if (menu.isTopLevelMenu()) |
421 |
((JPopupMenu) menu.getParent()).getSelectionModel().clearSelection(); |
((JMenuBar) menu.getParent()).getSelectionModel().clearSelection(); |
422 |
|
else |
423 |
|
((JPopupMenu) menu.getParent()).getSelectionModel().clearSelection(); |
424 |
|
} |
425 |
} |
} |
426 |
|
|
427 |
/** |
/** |
453 |
*/ |
*/ |
454 |
public void propertyChange(PropertyChangeEvent e) |
public void propertyChange(PropertyChangeEvent e) |
455 |
{ |
{ |
456 |
|
// TODO: Implement this properly. |
457 |
} |
} |
458 |
} |
} |
459 |
|
|
462 |
*/ |
*/ |
463 |
public class ChangeHandler implements ChangeListener |
public class ChangeHandler implements ChangeListener |
464 |
{ |
{ |
465 |
|
/** |
466 |
|
* Not used. |
467 |
|
*/ |
468 |
|
public boolean isSelected; |
469 |
|
|
470 |
|
/** |
471 |
|
* Not used. |
472 |
|
*/ |
473 |
|
public JMenu menu; |
474 |
|
|
475 |
|
/** |
476 |
|
* Not used. |
477 |
|
*/ |
478 |
|
public BasicMenuUI ui; |
479 |
|
|
480 |
|
/** |
481 |
|
* Not used. |
482 |
|
*/ |
483 |
|
public Component wasFocused; |
484 |
|
|
485 |
|
/** |
486 |
|
* Not used. |
487 |
|
*/ |
488 |
|
public ChangeHandler(JMenu m, BasicMenuUI ui) |
489 |
|
{ |
490 |
|
// Not used. |
491 |
|
} |
492 |
|
|
493 |
|
/** |
494 |
|
* Not used. |
495 |
|
*/ |
496 |
public void stateChanged(ChangeEvent e) |
public void stateChanged(ChangeEvent e) |
497 |
{ |
{ |
498 |
// FIXME: It seems that this class is not used anywhere |
// Not used. |
499 |
} |
} |
500 |
} |
} |
501 |
|
|
535 |
*/ |
*/ |
536 |
public void menuDragMouseExited(MenuDragMouseEvent e) |
public void menuDragMouseExited(MenuDragMouseEvent e) |
537 |
{ |
{ |
538 |
|
// TODO: What should be done here, if anything? |
539 |
} |
} |
540 |
|
|
541 |
/** |
/** |
546 |
*/ |
*/ |
547 |
public void menuDragMouseReleased(MenuDragMouseEvent e) |
public void menuDragMouseReleased(MenuDragMouseEvent e) |
548 |
{ |
{ |
549 |
|
// TODO: What should be done here, if anything? |
550 |
} |
} |
551 |
} |
} |
552 |
|
|
563 |
*/ |
*/ |
564 |
public void menuKeyPressed(MenuKeyEvent e) |
public void menuKeyPressed(MenuKeyEvent e) |
565 |
{ |
{ |
566 |
|
// TODO: What should be done here, if anything? |
567 |
} |
} |
568 |
|
|
569 |
/** |
/** |
573 |
*/ |
*/ |
574 |
public void menuKeyReleased(MenuKeyEvent e) |
public void menuKeyReleased(MenuKeyEvent e) |
575 |
{ |
{ |
576 |
|
// TODO: What should be done here, if anything? |
577 |
} |
} |
578 |
|
|
579 |
/** |
/** |
584 |
*/ |
*/ |
585 |
public void menuKeyTyped(MenuKeyEvent e) |
public void menuKeyTyped(MenuKeyEvent e) |
586 |
{ |
{ |
587 |
|
// TODO: What should be done here, if anything? |
588 |
} |
} |
589 |
} |
} |
590 |
} |
} |