From: <dan...@us...> - 2012-03-27 23:13:02
|
Revision: 20253 http://jmri.svn.sourceforge.net/jmri/?rev=20253&view=rev Author: dan_boudreau Date: 2012-03-27 23:12:55 +0000 (Tue, 27 Mar 2012) Log Message: ----------- New operations feature, auto save. Now the user can have the program automatically save the operations files. Modified Paths: -------------- trunk/jmri/java/src/jmri/jmrit/operations/OperationsXml.java trunk/jmri/java/src/jmri/jmrit/operations/setup/JmritOperationsSetupBundle.properties trunk/jmri/java/src/jmri/jmrit/operations/setup/OperationsSetupFrame.java trunk/jmri/java/src/jmri/jmrit/operations/setup/Setup.java trunk/jmri/java/src/jmri/jmrit/operations/trains/TrainsTableFrame.java trunk/jmri/xml/DTD/operations-config.dtd Added Paths: ----------- trunk/jmri/java/src/jmri/jmrit/operations/setup/AutoSave.java Modified: trunk/jmri/java/src/jmri/jmrit/operations/OperationsXml.java =================================================================== --- trunk/jmri/java/src/jmri/jmrit/operations/OperationsXml.java 2012-03-27 13:23:12 UTC (rev 20252) +++ trunk/jmri/java/src/jmri/jmrit/operations/OperationsXml.java 2012-03-27 23:12:55 UTC (rev 20253) @@ -102,7 +102,7 @@ } private String operationsFileName = "DefaultOperations.xml"; // should be overridden - + /** * Absolute path to location of Operations files. * <P> @@ -155,6 +155,9 @@ return buf.toString(); } + /** + * Saves operation files that have been modified. + */ public static void save(){ OperationsSetupXml.instance().writeFileIfDirty(); LocationManagerXml.instance().writeFileIfDirty(); //Need to save "moves" for track location Added: trunk/jmri/java/src/jmri/jmrit/operations/setup/AutoSave.java =================================================================== --- trunk/jmri/java/src/jmri/jmrit/operations/setup/AutoSave.java (rev 0) +++ trunk/jmri/java/src/jmri/jmrit/operations/setup/AutoSave.java 2012-03-27 23:12:55 UTC (rev 20253) @@ -0,0 +1,50 @@ +// AutoSave.java + +package jmri.jmrit.operations.setup; + +import jmri.jmrit.operations.OperationsXml; + +/** + * Auto Save. When enabled will automatically save operation files. + * + * @author Daniel Boudreau Copyright (C) 2012 + * @version $Revision: 17977 $ + */ + +public class AutoSave { + + static Thread autoSave = null; + + public AutoSave(){ + if (Setup.isAutoSaveEnabled() && autoSave == null){ + autoSave = new Thread(new Runnable() { + public void run() { + saveFiles(); + } + }); + autoSave.setName("Auto Save"); + autoSave.start(); + } + } + + private synchronized void saveFiles(){ + while (true){ + try { + wait(60000); // check every minute + } catch (InterruptedException e) {} + if (!Setup.isAutoSaveEnabled()) + break; + if (OperationsXml.areFilesDirty()){ + log.debug("Detected dirty files"); + try { + wait(60000); // wait another minute before saving + } catch (InterruptedException e) {} + OperationsXml.save(); + log.info("Operations files automatically saved"); + } + } + autoSave = null; // done + } + + static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(AutoSave.class.getName()); +} Property changes on: trunk/jmri/java/src/jmri/jmrit/operations/setup/AutoSave.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/jmri/java/src/jmri/jmrit/operations/setup/JmritOperationsSetupBundle.properties =================================================================== --- trunk/jmri/java/src/jmri/jmrit/operations/setup/JmritOperationsSetupBundle.properties 2012-03-27 13:23:12 UTC (rev 20252) +++ trunk/jmri/java/src/jmri/jmrit/operations/setup/JmritOperationsSetupBundle.properties 2012-03-27 23:12:55 UTC (rev 20253) @@ -156,6 +156,7 @@ MainMenu = Add Operations Menu to Main Menu CloseOnSave = Close Windows on Save +AutoSave = Auto Save Font = Font FontSize = Font Size BuildReport = Detail Level Modified: trunk/jmri/java/src/jmri/jmrit/operations/setup/OperationsSetupFrame.java =================================================================== --- trunk/jmri/java/src/jmri/jmrit/operations/setup/OperationsSetupFrame.java 2012-03-27 13:23:12 UTC (rev 20252) +++ trunk/jmri/java/src/jmri/jmrit/operations/setup/OperationsSetupFrame.java 2012-03-27 23:12:55 UTC (rev 20253) @@ -83,6 +83,7 @@ JCheckBox northCheckBox = new JCheckBox(rb.getString("northsouth")); JCheckBox mainMenuCheckBox = new JCheckBox(rb.getString("MainMenu")); JCheckBox closeOnSaveCheckBox = new JCheckBox(rb.getString("CloseOnSave")); + JCheckBox autoSaveCheckBox = new JCheckBox(rb.getString("AutoSave")); JCheckBox iconCheckBox = new JCheckBox(rb.getString("trainIcon")); JCheckBox appendCheckBox = new JCheckBox(rb.getString("trainIconAppend")); //JCheckBox rfidCheckBox = new JCheckBox(rb.getString("EnableRfid")); @@ -132,7 +133,7 @@ // load checkboxes mainMenuCheckBox.setSelected(Setup.isMainMenuEnabled()); closeOnSaveCheckBox.setSelected(Setup.isCloseWindowOnSaveEnabled()); - //rfidCheckBox.setSelected(Setup.isRfidEnabled()); + autoSaveCheckBox.setSelected(Setup.isAutoSaveEnabled()); iconCheckBox.setSelected(Setup.isTrainIconCordEnabled()); appendCheckBox.setSelected(Setup.isTrainIconAppendEnabled()); @@ -266,8 +267,9 @@ JPanel options = new JPanel(); options.setLayout(new GridBagLayout()); options.setBorder(BorderFactory.createTitledBorder(rb.getString("BorderLayoutOptions"))); - addItem (options, mainMenuCheckBox, 1,7); - addItem (options, closeOnSaveCheckBox, 1,8); + addItem (options, mainMenuCheckBox, 0,0); + addItem (options, closeOnSaveCheckBox, 1,0); + addItem (options, autoSaveCheckBox, 2,0); //p9.add(options); @@ -476,6 +478,7 @@ // main menu enabled? Setup.setMainMenuEnabled(mainMenuCheckBox.isSelected()); Setup.setCloseWindowOnSaveEnabled(closeOnSaveCheckBox.isSelected()); + Setup.setAutoSaveEnabled(autoSaveCheckBox.isSelected()); // RFID enabled? // Setup.setRfidEnabled(rfidCheckBox.isSelected()); // add panel name to setup Modified: trunk/jmri/java/src/jmri/jmrit/operations/setup/Setup.java =================================================================== --- trunk/jmri/java/src/jmri/jmrit/operations/setup/Setup.java 2012-03-27 13:23:12 UTC (rev 20252) +++ trunk/jmri/java/src/jmri/jmrit/operations/setup/Setup.java 2012-03-27 23:12:55 UTC (rev 20253) @@ -219,6 +219,7 @@ private static boolean mainMenuEnabled = false; //when true add operations menu to main menu bar private static boolean closeWindowOnSave = false; //when true, close window when save button is activated + private static boolean autoSave = true; //when true, automatically save files if modified private static boolean enableValue = false; //when true show value fields for rolling stock private static String labelValue = rb.getString("Value"); private static boolean enableRfid = false; //when true show RFID fields for rolling stock @@ -244,7 +245,6 @@ private static boolean generateCsvManifest = false; // when true generate csv manifest private static boolean generateCsvSwitchList = false; // when true generate csv switch list private static boolean enableVsdPhysicalLocations = false; - //private static boolean enableReporters = false; // when true create a reporter for each train private static boolean printLocationComments = false; // when true print location comments on the manifest private static boolean printRouteComments = false; // when true print route comments on the manifest @@ -253,28 +253,6 @@ private static boolean use12hrFormat = false; // when true use 12hr rather than 24hr format private static boolean printValid = true; // when true print out the valid time and date - /* all JMRI window position and size are now saved - // Setup frame attributes - private static OperationsSetupFrame _operationsSetupFrame = null; - private static Dimension _operationsSetupFrameDimension = null; - private static Point _operationsSetupFramePosition = null; - - @Deprecated - public static void setOperationsSetupFrame(OperationsSetupFrame frame){ - _operationsSetupFrame = frame; - } - - @Deprecated - public static Dimension getOperationsSetupFrameSize(){ - return _operationsSetupFrameDimension; - } - - @Deprecated - public static Point getOperationsSetupFramePosition(){ - return _operationsSetupFramePosition; - } - */ - public static boolean isMainMenuEnabled(){ OperationsSetupXml.instance(); // load file return mainMenuEnabled; @@ -292,6 +270,17 @@ closeWindowOnSave = enabled; } + public static boolean isAutoSaveEnabled(){ + return autoSave; + } + + public static void setAutoSaveEnabled(boolean enabled){ + boolean old = autoSave; + autoSave = enabled; + if (!old && enabled) + new AutoSave(); + } + public static boolean isValueEnabled(){ return enableValue; } @@ -1339,6 +1328,7 @@ e.addContent(values = new Element("settings")); values.setAttribute("mainMenu", isMainMenuEnabled()?"true":"false"); values.setAttribute("closeOnSave", isCloseWindowOnSaveEnabled()?"true":"false"); + values.setAttribute("autoSave", isAutoSaveEnabled()?"true":"false"); values.setAttribute("trainDirection", Integer.toString(getTrainDirection())); values.setAttribute("trainLength", Integer.toString(getTrainLength())); values.setAttribute("maxEngines", Integer.toString(getEngineSize())); @@ -1546,6 +1536,11 @@ if (log.isDebugEnabled()) log.debug("closeOnSave: "+enabled); setCloseWindowOnSaveEnabled(enabled.equals("true")); } + if ((a = operations.getChild("settings").getAttribute("autoSave"))!= null){ + String enabled = a.getValue(); + if (log.isDebugEnabled()) log.debug("autoSave: "+enabled); + setAutoSaveEnabled(enabled.equals("true")); + } if ((a = operations.getChild("settings").getAttribute("trainDirection"))!= null){ String dir = a.getValue(); if (log.isDebugEnabled()) log.debug("direction: "+dir); Modified: trunk/jmri/java/src/jmri/jmrit/operations/trains/TrainsTableFrame.java =================================================================== --- trunk/jmri/java/src/jmri/jmrit/operations/trains/TrainsTableFrame.java 2012-03-27 13:23:12 UTC (rev 20252) +++ trunk/jmri/java/src/jmri/jmrit/operations/trains/TrainsTableFrame.java 2012-03-27 23:12:55 UTC (rev 20253) @@ -31,6 +31,7 @@ import jmri.jmrit.operations.locations.LocationManager; import jmri.jmrit.operations.rollingstock.cars.CarManagerXml; import jmri.jmrit.operations.rollingstock.engines.EngineManagerXml; +import jmri.jmrit.operations.setup.AutoSave; import jmri.jmrit.operations.setup.Control; import jmri.jmrit.operations.setup.OptionAction; import jmri.jmrit.operations.setup.PrintOptionAction; @@ -105,6 +106,8 @@ // create ShutDownTasks createShutDownTask(); + // always check for dirty operations files + setModifiedFlag(true); // general GUI configuration getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS)); @@ -253,11 +256,12 @@ // listen for location switch list changes addPropertyChangeLocations(); + // auto save + new AutoSave(); } public void radioButtonActionPerformed(java.awt.event.ActionEvent ae) { log.debug("radio button actived"); - setModifiedFlag(true); trainManagerXml.setDirty(true); if (ae.getSource() == showId){ trainsModel.setSort(trainsModel.SORTBYID); @@ -425,7 +429,6 @@ } public void checkBoxActionPerformed(java.awt.event.ActionEvent ae) { - setModifiedFlag(true); trainManagerXml.setDirty(true); if (ae.getSource() == buildMsgBox){ trainManager.setBuildMessagesEnabled(buildMsgBox.isSelected()); @@ -442,8 +445,13 @@ } } + protected void storeValues(){ + OperationsXml.save(); + saveTableDetails(trainsTable); + } + protected void handleModified() { - if (getModifiedFlag()) { + if (OperationsXml.areFilesDirty()) { ResourceBundle rbu = ResourceBundle.getBundle("jmri.util.UtilBundle"); int result = javax.swing.JOptionPane.showOptionDialog(this, rb.getString("PromptQuitWindowNotWritten"), @@ -462,19 +470,13 @@ } } - protected void storeValues(){ - OperationsXml.save(); - saveTableDetails(trainsTable); - setModifiedFlag(false); - } - private synchronized void createShutDownTask(){ if (jmri.InstanceManager.shutDownManagerInstance() != null && trainDirtyTask == null) { trainDirtyTask = new SwingShutDownTask( "Operations Train Window Check", rb.getString("PromptQuitWindowNotWritten"), rb.getString("PromptSaveQuit"), this) { public boolean checkPromptNeeded() { - return !trainManagerXml.isDirty(); + return !OperationsXml.areFilesDirty(); } public boolean doPrompt() { @@ -553,6 +555,5 @@ updateSwitchListButton(); } - static org.apache.log4j.Logger log = org.apache.log4j.Logger - .getLogger(TrainsTableFrame.class.getName()); + static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(TrainsTableFrame.class.getName()); } Modified: trunk/jmri/xml/DTD/operations-config.dtd =================================================================== --- trunk/jmri/xml/DTD/operations-config.dtd 2012-03-27 13:23:12 UTC (rev 20252) +++ trunk/jmri/xml/DTD/operations-config.dtd 2012-03-27 23:12:55 UTC (rev 20253) @@ -53,7 +53,8 @@ <!ATTLIST railRoad name CDATA #IMPLIED> <!ATTLIST settings mainMenu (true | false ) "false"> -<!ATTLIST settings closeOnSave (true | false ) "false"> +<!ATTLIST settings closeOnSave (true | false ) "false"> +<!ATTLIST settings autoSave (true | false ) "true"> <!ATTLIST settings trainDirection CDATA #IMPLIED> <!ATTLIST settings trainLength CDATA #IMPLIED> <!ATTLIST settings maxEngines CDATA #IMPLIED> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |