use of com.glitchcog.fontificator.gui.component.MenuComponent in project ChatGameFontificator by GlitchCog.
the class ControlWindow method initMenus.
/**
* Builds the menus from the static arrays
*/
private void initMenus() {
JMenuBar menuBar = new JMenuBar();
final String[] mainMenuText = { "File", "Presets", "View", "Message", "Help" };
final int[] mainMnomonics = { KeyEvent.VK_F, KeyEvent.VK_P, KeyEvent.VK_V, KeyEvent.VK_M, KeyEvent.VK_H };
JMenu[] menus = new JMenu[mainMenuText.length];
for (int i = 0; i < mainMenuText.length; i++) {
menus[i] = new JMenu(mainMenuText[i]);
menus[i].setMnemonic(mainMnomonics[i]);
}
/* File Menu Item Text */
final String strFileOpen = "Open Configuration";
final String strFileSave = "Save Configuration";
final String strFileRestore = "Restore Default Configuration";
final String strScreenshot = "Screenshot";
final String strFileExit = "Exit";
// @formatter:off
final MenuComponent[] fileComponents = new MenuComponent[] { new MenuComponent(strFileOpen, KeyEvent.VK_O, KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK)), new MenuComponent(strFileSave, KeyEvent.VK_S, KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK)), new MenuComponent(strFileRestore, KeyEvent.VK_R, null), new MenuComponent(strScreenshot, KeyEvent.VK_C, KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0)), new MenuComponent(strFileExit, KeyEvent.VK_X, KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.CTRL_MASK)) };
// @formatter:on
/* View Menu Item Text */
final String strAntiAlias = "Anti-Aliased";
final String strViewTop = "Always On Top";
final String strRememberPos = "Remember Chat Window Position";
final String strViewHide = "Hide Control Window";
final MenuComponent[] viewComponents = new MenuComponent[] { new MenuComponent(strAntiAlias, KeyEvent.VK_A, null, true), null, new MenuComponent(strViewTop, KeyEvent.VK_T, null, true), new MenuComponent(strRememberPos, KeyEvent.VK_P, null, true), new MenuComponent(strViewHide, KeyEvent.VK_H, KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK)) };
/* Message Menu Item Text */
final String strMsgMsg = "Message Management";
final MenuComponent[] messageComponents = new MenuComponent[] { new MenuComponent(strMsgMsg, KeyEvent.VK_M, KeyStroke.getKeyStroke(KeyEvent.VK_M, Event.CTRL_MASK)) };
/* Help Menu Item Text */
final String strHelpHelp = "Help";
final String strHelpDebug = "Debug Mode";
final String strHelpAbout = "About";
final MenuComponent[] helpComponents = new MenuComponent[] { new MenuComponent(strHelpHelp, KeyEvent.VK_R, null), new MenuComponent(strHelpDebug, KeyEvent.VK_D, null, true), null, new MenuComponent(strHelpAbout, KeyEvent.VK_A, null) };
/* All menu components, with a placeholder for the Presets menu */
final MenuComponent[][] allMenuComponents = new MenuComponent[][] { fileComponents, new MenuComponent[] {}, viewComponents, messageComponents, helpComponents };
ActionListener mal = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem mi = (JMenuItem) e.getSource();
if (strFileOpen.equals(mi.getText())) {
open();
} else if (strFileSave.equals(mi.getText())) {
saveConfig();
} else if (strFileRestore.equals(mi.getText())) {
restoreDefaults(true);
controlTabs.refreshUiFromConfig(fProps);
} else if (strScreenshot.equals(mi.getText())) {
saveScreenshot();
} else if (strFileExit.equals(mi.getText())) {
attemptToExit();
} else if (strAntiAlias.equals(mi.getText())) {
JCheckBoxMenuItem checkBox = (JCheckBoxMenuItem) e.getSource();
controlTabs.setAntiAlias(checkBox.isSelected());
chatWindow.getChatPanel().repaint();
} else if (strViewTop.equals(mi.getText())) {
JCheckBoxMenuItem checkBox = (JCheckBoxMenuItem) e.getSource();
((JFrame) getParent()).setAlwaysOnTop(checkBox.isSelected());
controlTabs.setAlwaysOnTopConfig(checkBox.isSelected());
} else if (strRememberPos.equals(mi.getText())) {
JCheckBoxMenuItem checkBox = (JCheckBoxMenuItem) e.getSource();
controlTabs.setRememberChatWindowPosition(checkBox.isSelected());
if (checkBox.isSelected()) {
final int sx = (int) chatWindow.getLocationOnScreen().getX();
final int sy = (int) chatWindow.getLocationOnScreen().getY();
fProps.getChatConfig().setChatWindowPositionX(sx);
fProps.getChatConfig().setChatWindowPositionY(sy);
}
} else if (strViewHide.equals(mi.getText())) {
setVisible(false);
} else if (strMsgMsg.equals(mi.getText())) {
messageDialog.showDialog();
} else if (strHelpHelp.equals(mi.getText())) {
help.setVisible(true);
} else if (strHelpDebug.equals(mi.getText())) {
toggleDebugTab();
} else if (strHelpAbout.equals(mi.getText())) {
showAboutPane();
}
}
};
/* Set all menu items but presets */
JMenuItem item = null;
for (int i = 0; i < allMenuComponents.length; i++) {
for (int j = 0; j < allMenuComponents[i].length; j++) {
MenuComponent mc = allMenuComponents[i][j];
if (mc == null) {
menus[i].add(new JSeparator());
} else {
item = mc.checkbox ? new JCheckBoxMenuItem(mc.label) : new JMenuItem(mc.label);
item.addActionListener(mal);
item.setMnemonic(mc.mnemonic);
if (mc.accelerator != null) {
item.setAccelerator(mc.accelerator);
}
menus[i].add(item);
}
}
menuBar.add(menus[i]);
}
/* Presets Breath of Fire */
final String[] strBof1 = new String[] { "Breath of Fire", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "bof1.cgf" };
final String[] strBof2 = new String[] { "Breath of Fire 2", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "bof2.cgf" };
/* Presets Chrono */
final String[] strChrono = new String[] { "Chrono Trigger", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "ct.cgf" };
final String[] strChronoCross = new String[] { "Chrono Cross", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "cc.cgf" };
/* Presets Dragon Warrior */
final String[] strDw1 = new String[] { "Dragon Warrior", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "dw1.cgf" };
final String[] strDw2 = new String[] { "Dragon Warrior II", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "dw2.cgf" };
final String[] strDq1_2 = new String[] { "Dragon Quest I.II (SFC)", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "dq1_2_sfc.cgf" };
final String[] strDw3 = new String[] { "Dragon Warrior III", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "dw3.cgf" };
final String[] strDw3Gbc = new String[] { "Dragon Warrior III (GBC)", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "dw3gbc.cgf" };
final String[] strDq3 = new String[] { "Dragon Quest III (SFC)", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "dq3_sfc.cgf" };
final String[] strDw4 = new String[] { "Dragon Warrior IV", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "dw4.cgf" };
final String[] strDqhrs = new String[] { "Dragon Quest Heroes: Rocket Slime", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "dqhrs.cgf" };
/* Presets EarthBound */
final String[] strEb0 = new String[] { "Earthbound Zero", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "eb0.cgf" };
final String[] strEbPlain = new String[] { "Earthbound Plain", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "eb_plain.cgf" };
final String[] strEbMint = new String[] { "Earthbound Mint", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "eb_mint.cgf" };
final String[] strEbStrawberry = new String[] { "Earthbound Strawberry", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "eb_strawberry.cgf" };
final String[] strEbBanana = new String[] { "Earthbound Banana", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "eb_banana.cgf" };
final String[] strEbPeanut = new String[] { "Earthbound Peanut", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "eb_peanut.cgf" };
final String[] strEbSaturn = new String[] { "Earthbound Mr. Saturn", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "eb_saturn.cgf" };
final String[] strM3 = new String[] { "Mother 3", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "m3.cgf" };
/* Presets Final Fantasy */
final String[] strFinalFantasy1 = new String[] { "Final Fantasy", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "ff1.cgf" };
final String[] strFinalFantasy4 = new String[] { "Final Fantasy IV", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "ff4.cgf" };
final String[] strFinalFantasy6 = new String[] { "Final Fantasy VI", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "ff6.cgf" };
final String[] strFinalFantasy7 = new String[] { "Final Fantasy VII", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "ff7.cgf" };
final String[] strFinalFantasy9 = new String[] { "Final Fantasy IX", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "ff9.cgf" };
/* Presets Mario */
final String[] strMario1 = new String[] { "Super Mario Bros.", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "smb1.cgf" };
final String[] strMario1Underworld = new String[] { "Super Mario Bros. Underworld", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "smb1_underworld.cgf" };
final String[] strMario2 = new String[] { "Super Mario Bros. 2", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "smb2.cgf" };
final String[] strMario3hud = new String[] { "Super Mario Bros. 3 HUD", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "smb3_hud.cgf" };
final String[] strMario3letter = new String[] { "Super Mario Bros. 3 Letter", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "smb3_letter.cgf" };
final String[] strMarioWorld = new String[] { "Super Mario World", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "smw.cgf" };
final String[] strYoshisIsland = new String[] { "Super Mario World 2: Yoshi's Island", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "yi.cgf" };
final String[] strMarioRpg = new String[] { "Super Mario RPG", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "smrpg.cgf" };
/* Presets Metroid */
final String[] strMetroid = new String[] { "Metroid", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "metroid.cgf" };
final String[] strMetroidBoss = new String[] { "Metroid Mother Brain", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "metroidboss.cgf" };
final String[] strMetroid2 = new String[] { "Metroid II", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "metroid2.cgf" };
final String[] strSuperMetroid = new String[] { "Super Metroid", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "smetroid.cgf" };
final String[] strMetroidFusion = new String[] { "Metroid Fusion", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "metroid_fusion.cgf" };
final String[] strMetroidZero = new String[] { "Metroid Zero Mission", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "metroid_zm.cgf" };
/* Presets Phantasy Star */
final String[] strPhanStar1 = new String[] { "Phantasy Star", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "ps1.cgf" };
final String[] strPhanStar2 = new String[] { "Phantasy Star II", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "ps2.cgf" };
/* Presets Pokemon */
final String[] strPkmnRb = new String[] { "Pokemon Red/Blue", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "pkmnrb.cgf" };
final String[] strPkmnFrlg = new String[] { "Pokemon Fire Red/Leaf Green", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "pkmnfrlg.cgf" };
/* Presets Ys */
final String[] strYs1fc = new String[] { "Ys (FC)", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "ys1_fc.cgf" };
final String[] strYs3fc = new String[] { "Ys III (FC)", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "ys3_fc.cgf" };
final String[] strYs3snes = new String[] { "Ys III (SNES)", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "ys3_snes.cgf" };
/* Presets Zelda */
final String[] strLozBush = new String[] { "The Legend of Zelda Bushes", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "zelda1_bush.cgf" };
final String[] strLozRock = new String[] { "The Legend of Zelda Moutains", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "zelda1_rock.cgf" };
final String[] strLozDungeon = new String[] { "The Legend of Zelda Dungeon", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "zelda1_dungeon.cgf" };
final String[] strZelda2 = new String[] { "Zelda II: The Adventures of Link", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "zelda2.cgf" };
final String[] strLozLa = new String[] { "The Legend of Zelda: Link's Awakening", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "zelda_la.cgf" };
final String[] strZelda3 = new String[] { "The Legend of Zelda: A Link to the Past", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "zelda3.cgf" };
final String[] strZeldaWw = new String[] { "The Legend of Zelda: The Wind Waker", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "zelda_ww.cgf" };
final String[] strZeldaMinish = new String[] { "The Legend of Zelda: The Minish Cap", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "zelda_minish.cgf" };
/* Ungrouped Presets */
final String[] strClash = new String[] { "Clash at Demonhead", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "cad.cgf" };
final String[] strCrystalis = new String[] { "Crystalis", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "crystalis.cgf" };
final String[] strFreedomPlanet = new String[] { "Freedom Planet", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "freep.cgf" };
final String[] strGoldenSun = new String[] { "Golden Sun", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "gsun.cgf" };
final String[] strHarvestMoonFmt = new String[] { "Harvest Moon: Friends of Mineral Town", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "hm_fmt.cgf" };
final String[] strRiverCityRansom = new String[] { "River City Ransom", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "rcr.cgf" };
final String[] strRygarNes = new String[] { "Rygar (NES)", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "rygar_nes.cgf" };
final String[] strSecretOfEvermore = new String[] { "Secret of Evermore", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "soe.cgf" };
final String[] strShantae = new String[] { "Shantae", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "shantae.cgf" };
final String[] strShiningForce = new String[] { "Shining Force", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "shiningforce.cgf" };
final String[] strShovel = new String[] { "Shovel Knight", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "sk.cgf" };
final String[] strStardew = new String[] { "Stardew Valley", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "sdv.cgf" };
final String[] strSuikoden = new String[] { "Suikoden", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "suiko.cgf" };
final String[] strTalesOfSymphonia = new String[] { "Tales of Symphonia", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "tos.cgf" };
final String[] strWarioLand4 = new String[] { "Wario Land 4", ConfigFont.INTERNAL_FILE_PREFIX + PRESET_DIRECTORY + "wl4.cgf" };
// @formatter:off
final String[][] allPresets = new String[][] { strBof1, strBof2, strChrono, strChronoCross, strDw1, strDw2, strDq1_2, strDw3, strDw3Gbc, strDq3, strDw4, strDqhrs, strEb0, strEbPlain, strEbMint, strEbStrawberry, strEbBanana, strEbPeanut, strEbSaturn, strM3, strFinalFantasy1, strFinalFantasy4, strFinalFantasy6, strFinalFantasy7, strFinalFantasy9, strMario1, strMario1Underworld, strMario2, strMario3hud, strMario3letter, strMarioWorld, strYoshisIsland, strMarioRpg, strMetroid, strMetroidBoss, strMetroid2, strSuperMetroid, strMetroidFusion, strMetroidZero, strPhanStar1, strPhanStar2, strPkmnRb, strPkmnFrlg, strYs1fc, strYs3fc, strYs3snes, strLozBush, strLozRock, strLozDungeon, strZelda2, strLozLa, strZelda3, strZeldaWw, strZeldaMinish, strClash, strCrystalis, strFreedomPlanet, strGoldenSun, strHarvestMoonFmt, strRiverCityRansom, strRygarNes, strSecretOfEvermore, strShantae, strShiningForce, strShovel, strStardew, strSuikoden, strTalesOfSymphonia, strWarioLand4 };
// @formatter:on
ActionListener presetListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String sourceText = ((JMenuItem) e.getSource()).getText();
for (int i = 0; i < allPresets.length; i++) {
if (allPresets[i][0].equals(sourceText)) {
loadPreset(allPresets[i][0], allPresets[i][1]);
break;
}
}
}
};
// Put all the presets into this map to convert them into the submenu items
final Map<String, String[]> presetMapSubmenuToItem = new LinkedHashMap<String, String[]>();
presetMapSubmenuToItem.put("Breath of Fire", new String[] { strBof1[0], strBof2[0] });
presetMapSubmenuToItem.put("Chrono", new String[] { strChrono[0], strChronoCross[0] });
presetMapSubmenuToItem.put("Dragon Warrior", new String[] { strDw1[0], strDw2[0], strDq1_2[0], strDw3[0], strDw3Gbc[0], strDq3[0], strDw4[0], strDqhrs[0] });
presetMapSubmenuToItem.put("Earthbound", new String[] { strEb0[0], strEbPlain[0], strEbMint[0], strEbStrawberry[0], strEbBanana[0], strEbPeanut[0], strEbSaturn[0], strM3[0] });
presetMapSubmenuToItem.put("Final Fantasy", new String[] { strFinalFantasy1[0], strFinalFantasy4[0], strFinalFantasy6[0], strFinalFantasy7[0], strFinalFantasy9[0] });
presetMapSubmenuToItem.put("Mario", new String[] { strMario1[0], strMario1Underworld[0], strMario2[0], strMario3hud[0], strMario3letter[0], strMarioWorld[0], strYoshisIsland[0], strMarioRpg[0] });
presetMapSubmenuToItem.put("Metroid", new String[] { strMetroid[0], strMetroidBoss[0], strMetroid2[0], strSuperMetroid[0], strMetroidFusion[0], strMetroidZero[0] });
presetMapSubmenuToItem.put("Phantasy Star", new String[] { strPhanStar1[0], strPhanStar2[0] });
presetMapSubmenuToItem.put("Pokemon", new String[] { strPkmnRb[0], strPkmnFrlg[0] });
presetMapSubmenuToItem.put("Ys", new String[] { strYs1fc[0], strYs3fc[0], strYs3snes[0] });
presetMapSubmenuToItem.put("Zelda", new String[] { strLozBush[0], strLozRock[0], strLozDungeon[0], strZelda2[0], strLozLa[0], strZelda3[0], strZeldaWw[0], strZeldaMinish[0] });
presetMapSubmenuToItem.put(null, new String[] { strClash[0], strCrystalis[0], strFreedomPlanet[0], strGoldenSun[0], strHarvestMoonFmt[0], strRiverCityRansom[0], strRygarNes[0], strSecretOfEvermore[0], strShantae[0], strShiningForce[0], strShovel[0], strStardew[0], strSuikoden[0], strTalesOfSymphonia[0], strWarioLand4[0] });
for (String submenuKey : presetMapSubmenuToItem.keySet()) {
String[] submenuItems = presetMapSubmenuToItem.get(submenuKey);
if (submenuKey != null) {
JMenu submenu = new JMenu(submenuKey);
for (String itemStr : submenuItems) {
JMenuItem submenuItem = new JMenuItem(itemStr);
submenuItem.addActionListener(presetListener);
submenu.add(submenuItem);
}
menus[1].add(submenu);
} else {
for (String submenuRootItemStr : submenuItems) {
JMenuItem submenuRootItem = new JMenuItem(submenuRootItemStr);
submenuRootItem.addActionListener(presetListener);
menus[1].add(submenuRootItem);
}
}
}
for (int i = 0; i < menus.length; i++) {
menuBar.add(menus[i]);
}
// add the whole menu bar
setJMenuBar(menuBar);
}
Aggregations