tutorials:first-steps:save-load
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:first-steps:save-load [2025/05/25 11:04] – 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 '' |
{{: | {{: | ||
Line 75: | Line 75: | ||
**Note: | **Note: | ||
* The variable '' | * The variable '' | ||
- | * Any other serialization | + | * Any other serialization |
* To reset the three variables to their initial values, the project needs to be either '' | * To reset the three variables to their initial values, the project needs to be either '' | ||
You can run the '' | 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.1748163881.txt.gz · Last modified: 2025/05/25 11:04 by gaetan