From: <mg...@us...> - 2007-03-23 14:21:27
|
Revision: 414 http://svn.sourceforge.net/obo/?rev=414&view=rev Author: mgibson Date: 2007-03-23 07:21:24 -0700 (Fri, 23 Mar 2007) Log Message: ----------- There is now a menu option to change your configuration - its a little crude at this point as you then have to restart phenote - eventually will redo the configuration on the fly - but this is at least a start. all it actually does is change the file name in my-phenote.cfg. it took me a while to realize i needed to just set the modal flag on the dialog as i couldnt get the dialog to stay up and i was doing ridiculous tricks with threads til i finally realize - gee whiz its like ive never put up a dialog before Modified Paths: -------------- phenote/trunk/src/java/phenote/config/Config.java phenote/trunk/src/java/phenote/config/ConfigFileQueryGui.java phenote/trunk/src/java/phenote/gui/FileMenu.java phenote/trunk/src/java/phenote/main/Phenote.java Modified: phenote/trunk/src/java/phenote/config/Config.java =================================================================== --- phenote/trunk/src/java/phenote/config/Config.java 2007-03-22 16:52:28 UTC (rev 413) +++ phenote/trunk/src/java/phenote/config/Config.java 2007-03-23 14:21:24 UTC (rev 414) @@ -88,7 +88,7 @@ /** if all else fails revert to flybase which should be there */ public void loadDefaultFlybaseConfigFile() throws ConfigException { - setConfigFile(FLYBASE_DEFAULT_CONFIG_FILE,true,false,false); + setConfigFile(FLYBASE_DEFAULT_CONFIG_FILE,true,false,false); // merge true? } /** default file should be in .phenote/conf/my-phenote.cfg. if not set yet then just @@ -186,13 +186,14 @@ //File conf = new File(dotPhenote,"conf");conf.mkdir();return conf; } - private File getMyPhenoteFile() { + private static File getMyPhenoteFile() { return new File(getDotPhenoteConfDir(),"my-phenote.cfg"); } /** Write name of config file loaded out to .phenote/conf/my-phenote.cfg for use - by future startups with no config specified */ - private void writeMyPhenoteDefaultFile(String newDefaultFileString) + by future startups with no config specified + Throws ConfigException if fails to find file */ + public static void writeMyPhenoteDefaultFile(String newDefaultFileString) throws ConfigException { try { File myPhenote = getMyPhenoteFile(); Modified: phenote/trunk/src/java/phenote/config/ConfigFileQueryGui.java =================================================================== --- phenote/trunk/src/java/phenote/config/ConfigFileQueryGui.java 2007-03-22 16:52:28 UTC (rev 413) +++ phenote/trunk/src/java/phenote/config/ConfigFileQueryGui.java 2007-03-23 14:21:24 UTC (rev 414) @@ -39,7 +39,7 @@ import phenote.gui.GridBagUtil; import phenote.util.FileUtil; -class ConfigFileQueryGui { +public class ConfigFileQueryGui { //private String selection; private String selectedFile; @@ -47,20 +47,24 @@ private boolean okPressed = false; private ButtonGroup buttonGroup; - static String queryUserForConfigFile() { + public static String queryUserForConfigFile() { ConfigFileQueryGui c = new ConfigFileQueryGui(); return c.queryUser(); } + private String queryUser() { - dialog = new JDialog(); //"Choose Configuration",true); - //dialog.setPreferredSize(new Dimension(300,400)); - //dialog.setLayout(new BoxLayout(dialog,BoxLayout.Y_AXIS)); - //dialog.setLayout(new GridLayout(0,1)); - //dialog.setLayout(new BorderLayout()); + makeQueryDialog(); + return selectedFile; + } + + + private void makeQueryDialog() { + java.awt.Frame f = phenote.main.Phenote.getPhenote().getFrame(); + // true -> modal -> this is crucial! + dialog = new JDialog(f,true); //"Choose Configuration",true); dialog.setLayout(new GridBagLayout()); dialog.setTitle("Phenote Configuration"); - // set layout? JLabel text = new JLabel("Please pick a configuration for Phenote: "); int center = GridBagConstraints.CENTER; GridBagConstraints gbc = GridBagUtil.makeAnchorConstraint(0,0,center); @@ -89,12 +93,6 @@ dialog.pack(); centerOnScreen(dialog); dialog.setVisible(true); - //return selection; // ???? - while (!okPressed) { - //System.out.println("ok pressed? "+okPressed); - try { Thread.sleep(10); } catch (InterruptedException e) {} - } // sleep?? - return selectedFile; } private class OkActionListener implements ActionListener { @@ -191,19 +189,66 @@ c.setLocation(p); } - private class PhenoteClassLoader extends ClassLoader { +} - private PhenoteClassLoader() { - super(ClassLoader.getSystemClassLoader()); - } - - protected String findLibrary(String lib) { - return super.findLibrary(lib); - //return this.getParent().findLibrary(lib); - } +// silly me - all i needed to do was make the dialog modal! silly silly +// WaitSwingWorkerThread waitSwingWorkerThread; + // doesnt work - still spins + //Thread dt = new DialogThread(); +// try { +// // this says cant do from EventDispatcherThread +// //javax.swing.SwingUtilities.invokeAndWait(new DialogThread()); +// // this literally makes the computer blow up +// //javax.swing.SwingUtilities.invokeLater(new DialogThread()); +// } //catch (InterruptedException e) { System.out.println("interrupted "+e); } +// catch (Exception e) { System.out.println("Exception: "+e); } + //dt.start(); + //DialogSwingWorkerThread dt = new DialogSwingWorkerThread(); + //dt.start(); +// while (!okPressed) { +// System.out.println("ok pressed? "+okPressed+" cur thread "+Thread.currentThread()+" dlg thread "+dt); +// try { Thread.sleep(300); } catch (InterruptedException e) {} +// } // sleep?? +// return selectedFile; //(String) dt.get(); //selectedFile; +// waitSwingWorkerThread = new WaitSwingWorkerThread(); +// waitSwingWorkerThread.start(); +// return (String)waitSwingWorkerThread.get(); +// private class DialogThread extends Thread { +// public void run() { +// makeQueryDialog(); +// } +// } - //protected ClassLoader getParent() { return super.getParent(); } +// private class WaitSwingWorkerThread extends phenote.gui.SwingWorker { +// public Object construct() { +// while (!okPressed) { +// System.out.println("ok pressed? "+okPressed+" cur thread "+Thread.currentThread()+" this "+this+" sel "+selectedFile); +// // try { +// waitSwingWorkerThread.sleep(300);// } catch (InterruptedException e) {} +// } // sleep?? +// return selectedFile; +// } +// } + - } +// private class DialogSwingWorkerThread extends phenote.gui.SwingWorker { +// public Object construct() { +// makeQueryDialog(); +// // while (!okPressed) { +// // System.out.println("ok pressed? "+okPressed+" cur thread "+Thread.currentThread()+" this "+this); +// // try { Thread.sleep(300); } catch (InterruptedException e) {} +// // } // sleep?? +// return selectedFile; +// } +// } -} +// private class PhenoteClassLoader extends ClassLoader { +// private PhenoteClassLoader() { +// super(ClassLoader.getSystemClassLoader()); +// } +// protected String findLibrary(String lib) { +// return super.findLibrary(lib); +// //return this.getParent().findLibrary(lib); +// } +// //protected ClassLoader getParent() { return super.getParent(); } +// } Modified: phenote/trunk/src/java/phenote/gui/FileMenu.java =================================================================== --- phenote/trunk/src/java/phenote/gui/FileMenu.java 2007-03-22 16:52:28 UTC (rev 413) +++ phenote/trunk/src/java/phenote/gui/FileMenu.java 2007-03-23 14:21:24 UTC (rev 414) @@ -4,12 +4,15 @@ import java.awt.event.ActionListener; import javax.swing.JMenu; import javax.swing.JMenuItem; +import javax.swing.JOptionPane; import phenote.dataadapter.CharacterListManager; import phenote.dataadapter.DataAdapterI; import phenote.dataadapter.LoadSaveManager; import phenote.config.Config; -//import phenote.gui.prefswindow.PrefsWindowController; +import phenote.config.ConfigFileQueryGui; +import phenote.config.ConfigException; +//import phenote.gui.prefswindow.PrefsWindowController; ??? class FileMenu extends JMenu { @@ -34,12 +37,16 @@ save.setActionCommand("save"); save.addActionListener(actionListener); add(save); + + JMenuItem loadConfig = new JMenuItem("Load Configuration"); + loadConfig.addActionListener(new ConfigActionListener()); + add(loadConfig); } private class LoadSaveActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (!Config.inst().hasDataAdapters()) { - System.out.println("no data adapter to load with"); + System.out.println("no file data adapter to load/save with"); return; } if (e.getActionCommand().equals("load")) @@ -50,6 +57,26 @@ } } + private class ConfigActionListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + // 1st step just set my-phenote.cfg & user restart phenote + // eventually reconfigure phenote in same session, cfg,obo,gui + String cfg = ConfigFileQueryGui.queryUserForConfigFile(); + try { + if (cfg != null && !cfg.equals("")) + Config.writeMyPhenoteDefaultFile(cfg); + String m = "You must restart phenote for new config to take effect"; + JOptionPane.showMessageDialog(null,m,"Please restart", + JOptionPane.INFORMATION_MESSAGE); + } + catch (ConfigException x) { + String m = "Failed to change configuration "+x.getMessage(); + JOptionPane.showMessageDialog(null,m,"Config error", + JOptionPane.ERROR_MESSAGE); + } + } + } + // for testing public void clickLoad() { loadMenuItem.doClick(); Modified: phenote/trunk/src/java/phenote/main/Phenote.java =================================================================== --- phenote/trunk/src/java/phenote/main/Phenote.java 2007-03-22 16:52:28 UTC (rev 413) +++ phenote/trunk/src/java/phenote/main/Phenote.java 2007-03-23 14:21:24 UTC (rev 414) @@ -49,7 +49,7 @@ public static void main(String[] args) { standalone = true; // i think this is ok System.out.println("This is Phenote version "+PhenoteVersion.versionString()); - // default mac lok & feel is "Mac OS X", but the JComboBox is buggy + // default mac look & feel is "Mac OS X", but the JComboBox is buggy try { UIManager.setLookAndFeel(new MetalLookAndFeel()); } @@ -156,16 +156,14 @@ private JPanel makeMainPanel() { JPanel mainPanel = new JPanel(new GridBagLayout()); // ?? - //JPanel termAndTablePanel = new JPanel(); JPanel upperPanel = new JPanel(); - //BoxLayout bl = new BoxLayout(termAndTablePanel,BoxLayout.Y_AXIS); BoxLayout bl = new BoxLayout(upperPanel,BoxLayout.X_AXIS); upperPanel.setLayout(bl); fieldPanel = new FieldPanel(); // field panel contains search params upperPanel.add(fieldPanel); - termInfo = new TermInfo(); //fieldPanel); + termInfo = new TermInfo(); upperPanel.add(termInfo.getComponent()); selectionHistory = new SelectionHistory(); @@ -204,59 +202,3 @@ } -// /** for now just looking for '-c configFile.cfg', use command line package -// if we need to get more sophisticated -// so if user has personal config file should override this - however maybe -// there should be a distinction between initial config file and user made configs -// well really the initials are db/species specific - so could be -// --initialConfig zf|fb|obd - actually da heck with that with entity chooser just -// put all 3 ontologies in one which is then the default (unspecified on cmd line) -// and -c file.cfg will load/overwrite that cfg into .phenote/my-phenote.cfg -// (if it exists) - we can always add --init later if we need it -// -c overwrites, -i doesnt -i is for initial startup of phenote */ -// private void doCommandLineOld(String[] args) { -// String configFile = getConfigFileFromCommandLine(args); -// // if no config file specified then set default initial config file. this will be -// // overridden by a personal config file if it exists -// //if (configFile == null) configFile = Config.DEFAULT_CONFIG_FILE; stored in file -// try { -// if (isOverwriteConfigFile(args)) //causes wipeout move of app file to .phenote -// Config.inst().setOverwriteConfigFile(configFile); -// else if (isInitialConfigFile(args)) -// Config.inst().setInitialConfigFile(configFile); -// //else if update... -// else // no command line config file specified - use last one specified (cache) -// Config.inst().loadDefaultConfigFile(); -// } catch (ConfigException e) { -// //LOG.fatal("EXITING! Fatal error in config file: "+e.getMessage()); -// LOG.error("Error in config file! "+e.getMessage()); -// e.printStackTrace(); // log? -// //System.exit(1); // isnt this a bit extreme? -// System.out.println("Yikes! config exception "+e+" gonna try loading default" -// +" config"); -// try { Config.inst().loadDefaultConfigFile(); } -// catch (ConfigException ce) { -// System.out.println("bummer - even default config fails. we're hosed! "+ce); -// } -// } -// } - -// // change to -m for merge?? - move to CommandLine! -// private boolean isInitialConfigFile(String args[]) { -// if (args == null || args.length < 2) return false; -// return args[0].equals("-i"); -// } -// private boolean isOverwriteConfigFile(String args[]) { -// if (args == null || args.length < 2) return false; -// return args[0].equals("-c"); -// } - -// private String getConfigFileFromCommandLine(String args[]) { -// // need 2 args -// if (args == null || args.length < 2) return null; -// //String firstArg = args[0]; -// if (!isInitialConfigFile(args) && !isOverwriteConfigFile(args)) return null; -// String configFile = args[1]; -// return configFile; -// } - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |