tutorials:first-steps:save-load
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
tutorials:first-steps:save-load [2025/03/25 11:53] – created gaetan | tutorials:first-steps:save-load [2025/05/26 23:56] (current) – barley1965 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Save/load static variables ====== | ====== Save/load static variables ====== | ||
- | This tutorial | + | This tutorial |
===== Create project ===== | ===== Create project ===== | ||
- | In a '' | + | In a '' |
+ | |||
+ | {{: | ||
In the '' | In the '' | ||
Line 70: | Line 72: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | **Note: | ||
+ | * The variable '' | ||
+ | * Any other serialization method can be used. Here we " | ||
+ | * To reset the three variables to their initial values, the project needs to be either '' | ||
+ | |||
+ | |||
+ | You can run the '' | ||
+ | |||
+ | |||
+ | ===== With the plugin PropFile ===== | ||
+ | |||
+ | The PropFile plugin includes some methods to: | ||
+ | * automatically create/ get a property file | ||
+ | * save/load variables by simply giving them a " | ||
+ | * save/load variables without casting their type | ||
+ | |||
+ | Example with the previous file: | ||
+ | |||
+ | |||
+ | <code java> | ||
+ | |||
+ | import de.grogra.pf.ui.registry.RunAfterSave; | ||
+ | import de.grogra.pf.ui.registry.RunAfterLoad; | ||
+ | import de.grogra.pf.registry.RegistryContext; | ||
+ | import de.grogra.propFile.TypedTextPropertyFile; | ||
+ | |||
+ | public static int myInt = 3; | ||
+ | public static String myString = " | ||
+ | |||
+ | static int myInt = 5; | ||
+ | static String myString = " "; | ||
+ | |||
+ | public class LoadParam implements RunAfterLoad{ | ||
+ | public void load(RegistryContext ctx){ | ||
+ | |||
+ | TypedTextPropertyFile props = TypedTextPropertyFile.fromProjectFile(" | ||
+ | props.load(); | ||
+ | myInt = props.get(" | ||
+ | myString = props.get(" | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | public class SaveParam implements RunAfterSave{ | ||
+ | public void save(RegistryContext ctx){ | ||
+ | |||
+ | TypedTextPropertyFile props = TypedTextPropertyFile.fromProjectFile(" | ||
+ | props.clear(); | ||
+ | |||
+ | props.set(" | ||
+ | props.set(" | ||
+ | |||
+ | props.save(); | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </ | ||
+ |
tutorials/first-steps/save-load.1742900017.txt.gz · Last modified: 2025/03/25 11:53 by gaetan