/** Save the current station model under a new name */ private void doSaveAs() { StationModel nl = getStationModel(); String newName = smm.doSaveAs(nl, this); if (newName == null) { return; } nl = new StationModel(newName, new ArrayList(nl.getList())); setStationModel(nl, false); smm.addUsers(nl); }
/** Create a new station model */ protected void doNew() { if (!okToChange()) { return; } String newName = smm.doNew(this, "New", "model", "Provide a name for the model"); if (newName == null) { return; } setStationModel(new StationModel(newName, new ArrayList()), true); smm.addUsers(getStationModel()); }
/** Use the default station model */ private void initFromDefault() { stationModel = smm.getDefaultStationModel(); if (stationModel == null) { stationModel = new StationModel("Default model", new ArrayList()); } setStationModel(stationModel, true); }
/** * Save the current station model * * @param fireChangeEvent Do we also fire the change event */ private void doSave(boolean fireChangeEvent) { StationModel sm = getStationModel(); smm.addUsers(sm); if (fireChangeEvent) { // sm.firePropertyChangeEvent(); } setHaveChanged(false); }
/** * _more_ * * @param symbols _more_ * @param listener _more_ * @param smm _more_ * @return _more_ */ public static List makeStationModelMenuItems( List symbols, final ObjectListener listener, StationModelManager smm) { List items = new ArrayList(); List subMenus = new ArrayList(); Hashtable categories = new Hashtable(); for (int i = 0; i < symbols.size(); i++) { StationModel sm = (StationModel) symbols.get(i); boolean isUsers = smm.isUsers(sm); String name = sm.getName(); if (name.equals("")) continue; List toks = StringUtil.split(name, ">", true, true); if (toks.size() > 0) { name = (String) toks.get(toks.size() - 1); } JMenuItem item = new JMenuItem(GuiUtils.getLocalName(name, isUsers)); item.addActionListener( new ObjectListener(sm) { public void actionPerformed(ActionEvent ae) { listener.setObject(this.theObject); listener.actionPerformed(ae); } }); toks.remove(toks.size() - 1); if (toks.size() == 0) { items.add(item); continue; } JMenu categoryMenu = null; String catSoFar = ""; String menuCategory = ""; for (int catIdx = 0; catIdx < toks.size(); catIdx++) { String subCat = (String) toks.get(catIdx); catSoFar = catSoFar + "/" + subCat; JMenu m = (JMenu) categories.get(catSoFar); if (m == null) { m = new JMenu(subCat); menuCategory = catSoFar; categories.put(catSoFar, m); if (categoryMenu != null) { categoryMenu.add(m, 0); } else { subMenus.add(m); } } categoryMenu = m; } if (categoryMenu == null) { categoryMenu = new JMenu(""); categories.put(toks.toString(), categoryMenu); subMenus.add(categoryMenu); menuCategory = toks.toString(); } categoryMenu.add(item); } items.addAll(subMenus); return items; }
/** Import a station model */ private void doImport() { if (!okToChange()) { return; } StationModel nl = (StationModel) smm.doImport(true); if (nl == null) { return; } setStationModel(nl, true); }
/** Remove the current station model */ protected void doRemove() { if (!GuiUtils.showYesNoDialog( null, "Are you sure you want to remove the station model: " + stationModel.getName() + "?", "Confirm")) { return; } smm.removeUsers(stationModel); initFromDefault(); }
/** Rename the current station model */ protected void doRename() { if (!okToChange()) { return; } String newName = smm.doNew(this, "Rename", stationModel.getName(), "Use '>' to add categories"); if (newName == null) { return; } doSave(false); StationModel sm = getStationModel(); sm.setName(newName); setStationModel(sm, false); doSave(true); }
/** Make the view menu */ private void makeStationModelMenu() { stationModelMenu.removeAll(); List symbols = smm.getResources(); List items = new ArrayList(); ObjectListener listener = new ObjectListener(null) { public void actionPerformed(ActionEvent ae) { if (!okToChange()) { return; } setStationModel((StationModel) theObject, true); } }; GuiUtils.makeMenu(stationModelMenu, makeStationModelMenuItems(symbols, listener, smm)); }
/** * Set the current station model * * @param newModel The station model * @param closeDialogs If true then close any dialog windows */ public void setStationModel(StationModel newModel, boolean closeDialogs) { if (closeDialogs) { closeDialogs(); } if (!smm.isUsers(newModel)) { List newGlyphs = cloneGlyphs(newModel.getList()); newModel = new StationModel(newModel.getName(), newGlyphs); // new ArrayList(newModel.getList())); } stationModel = newModel; setGlyphs(cloneGlyphs(newModel.getList())); setName(stationModel.getDisplayName()); setHaveChanged(false); frame.setTitle( GuiUtils.getApplicationTitle() + "Layout Model Editor -- " + stationModel.getName()); }
/** Make the file menu */ private void makeFileMenu() { fileMenu.removeAll(); fileMenu.add(makeMenuItem("New", 'n', GuiUtils.CMD_NEW)); fileMenu.addSeparator(); fileMenu.add(makeMenuItem("Save", 's', GuiUtils.CMD_SAVE)); fileMenu.add(makeMenuItem("Save As...", GuiUtils.CMD_SAVEAS)); fileMenu.add(makeMenuItem("Rename...", GuiUtils.CMD_RENAME)); fileMenu.addSeparator(); JMenuItem removeMenuItem = makeMenuItem("Remove", GuiUtils.CMD_REMOVE); removeMenuItem.setEnabled(smm.isUsers(stationModel)); fileMenu.add(removeMenuItem); fileMenu.addSeparator(); fileMenu.add(makeMenuItem("Import...", GuiUtils.CMD_IMPORT)); fileMenu.add(makeMenuItem("Export...", GuiUtils.CMD_EXPORT)); fileMenu.addSeparator(); fileMenu.add(makeMenuItem("Close", GuiUtils.CMD_CLOSE)); }
/** Export the current station model */ private void doExport() { smm.doExport(getStationModel()); }