00001 package dionarap;
00002
00003 import javax.swing.ButtonGroup;
00004 import javax.swing.JCheckBoxMenuItem;
00005 import javax.swing.JMenu;
00006 import javax.swing.JMenuBar;
00007 import javax.swing.JMenuItem;
00008 import javax.swing.JRadioButtonMenuItem;
00009 import javax.swing.UIManager;
00010 import javax.swing.UIManager.LookAndFeelInfo;
00011
00012
00025 public class MenuBar extends JMenuBar {
00029 private static final long serialVersionUID = 1634318767797551066L;
00030
00034 static public final String CMD_TOGGLENAVIGATOR = "toggleNavigator";
00035
00039 static public final String CMD_SHOWLEVELEDITOR = "showLevelEditor";
00040
00044 static public final String CMD_SHOWICONS = "showIcons";
00045
00049 static public final String CMD_SHOWHELP = "showHelp";
00050
00054 static public final String CMD_CLOSEWINDOW = "closeWindow";
00055
00059 static public final String CMD_THEMEPREFIX = "theme_";
00060
00067 private Hauptfenster parent;
00068
00075 private ListenerMenu listener;
00076
00086 public MenuBar(Hauptfenster parent, ListenerMenu listener)
00087 {
00088 this.parent = parent;
00089 this.listener = listener;
00090
00091
00092 JMenu menuConfiguration = new JMenu("Konfigurieren");
00093 menuConfiguration.setMnemonic('k');
00094 menuConfiguration.add(this.createMenuItemLookAndFeel());
00095 menuConfiguration.add(this.createMenuThemes());
00096 menuConfiguration.add(this.createCheckBoxMenuItem("Navigator", MenuBar.CMD_TOGGLENAVIGATOR, true));
00097 this.add(menuConfiguration);
00098
00099
00100 JMenu menuLevel = new JMenu("Level");
00101 menuLevel.setMnemonic('l');
00102 menuLevel.add(this.createMenuItem("Level erstellen", MenuBar.CMD_SHOWLEVELEDITOR) );
00103 menuLevel.add(this.createMenuLevels());
00104 this.add(menuLevel);
00105
00106
00107
00108 JMenu menuHelp = new JMenu("Hilfe");
00109 menuHelp.setMnemonic('h');
00110 menuHelp.add(this.createMenuItem("Spielfiguren anzeigen", MenuBar.CMD_SHOWICONS));
00111 menuHelp.add(this.createMenuItem("Spielbeschreibung", MenuBar.CMD_SHOWHELP));
00112 this.add(menuHelp);
00113 }
00114
00115
00126 private JMenuItem createMenuItemLookAndFeel()
00127 {
00128 LookAndFeelInfo[] lnf = UIManager.getInstalledLookAndFeels();
00129
00130 JMenuItem menuItemLookAndFeel = new JMenu("Look and Feel");
00131
00132 ButtonGroup groupLookAndFeel = new ButtonGroup();
00133 String lookandfeel = UIManager.getLookAndFeel().getName();
00134 for(int i = 0; i < lnf.length; i++) {
00135 menuItemLookAndFeel.add(this.createRadioMenuItem(lnf[i].getName(),
00136 lnf[i].getClassName(),
00137 groupLookAndFeel,
00138 lookandfeel.equals(lnf[i].getName())));
00139 }
00140
00141 return menuItemLookAndFeel;
00142 }
00143
00144
00155 private JMenuItem createMenuThemes()
00156 {
00157 String[] themes = Artwork.getTheme().getThemes();
00158 String currenttheme = Artwork.getTheme().getCurrentTheme();
00159
00160 JMenuItem menuItemThemes = new JMenu("Thema");
00161
00162 ButtonGroup groupThemes = new ButtonGroup();
00163 for (int i = 0; i < themes.length; i++) {
00164 menuItemThemes.add(this.createRadioMenuItem(themes[i],
00165 MenuBar.CMD_THEMEPREFIX + themes[i],
00166 groupThemes,
00167 themes[i].equals(currenttheme)));
00168 }
00169
00170 return menuItemThemes;
00171 }
00172
00173
00184 private JMenuItem createMenuLevels()
00185 {
00186 String[] levels = this.parent.getLevels();
00187 String currentLevel = this.parent.getCurrentLevel();
00188
00189 JMenuItem menuItemLevels = new JMenu("Level laden");
00190
00191 ButtonGroup groupLevels = new ButtonGroup();
00192 for (int i = 0; i < levels.length; i++) {
00193 menuItemLevels.add(this.createRadioMenuItem(levels[i],
00194 Hauptfenster.levelPrefix + levels[i],
00195 groupLevels,
00196 currentLevel.equals(levels[i])));
00197 }
00198
00199 return menuItemLevels;
00200 }
00201
00202
00212 private JMenuItem createMenuItem(String title, String command)
00213 {
00214 JMenuItem menuitem = new JMenuItem(title);
00215 menuitem.addActionListener(this.listener);
00216 menuitem.setActionCommand(command);
00217 return menuitem;
00218 }
00219
00220
00232 private JRadioButtonMenuItem createRadioMenuItem(String title, String command, ButtonGroup group, boolean selected)
00233 {
00234 JRadioButtonMenuItem menuitem = new JRadioButtonMenuItem(title);
00235 menuitem.setActionCommand(command);
00236 menuitem.setSelected(selected);
00237 menuitem.addActionListener(this.listener);
00238 group.add(menuitem);
00239 return menuitem;
00240 }
00241
00242
00253 private JCheckBoxMenuItem createCheckBoxMenuItem(String title, String command, boolean selected)
00254 {
00255 JCheckBoxMenuItem menuitem = new JCheckBoxMenuItem(title);
00256 menuitem.setActionCommand(command);
00257 menuitem.addActionListener(this.listener);
00258 menuitem.setState(selected);
00259 return menuitem;
00260 }
00261
00262 }