Skip to contentPackage: PreferencesHandler
PreferencesHandler
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2024 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
23: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.util;
28:
29: import javax.annotation.Nonnull;
30: import java.util.Optional;
31: import java.nio.file.Path;
32: import static it.tidalwave.role.impl.ServiceLoaderLocator.lazySupplierOf;
33:
34: /***********************************************************************************************************************
35: *
36: * @author Fabrizio Giudici
37: * @since 3.2-ALPHA-17
38: *
39: **********************************************************************************************************************/
40: public interface PreferencesHandler
41: {
42: static class Inner
43: {
44: private static final LazySupplier<PreferencesHandler> REF = lazySupplierOf(PreferencesHandler.class);
45: }
46:
47: public static final String PROPS_BASE_NAME = PreferencesHandler.class.getPackage().getName();
48:
49: public static final String PROP_APP_NAME = PROPS_BASE_NAME + ".appName";
50:
51: /** Suppress any console output. @since 3.2-ALPHA-21 */
52: public static final String PROP_SUPPRESS_CONSOLE = PROPS_BASE_NAME + ".suppressConsoleOutput";
53:
54: // FIXME: make private as soon as the right Java version is required
55: public static final String __BASE_NAME = "it.tidalwave.javafx";
56:
57: /** A property representing the initial main window size as a percentual of the screen size. */
58: public static final Key<Double> KEY_INITIAL_SIZE = Key.of(__BASE_NAME + ".initialSize", Double.class);
59:
60: /** Whether the application should start at full screen. */
61: public static final Key<Boolean> KEY_FULL_SCREEN = Key.of(__BASE_NAME + ".fullScreen", Boolean.class);
62:
63: /*******************************************************************************************************************
64: *
65: ******************************************************************************************************************/
66: @Nonnull
67: public static PreferencesHandler getInstance()
68: {
69: return Inner.REF.get();
70: }
71:
72: /*******************************************************************************************************************
73: *
74: ******************************************************************************************************************/
75: @Nonnull
76: public Path getAppFolder();
77:
78: /*******************************************************************************************************************
79: *
80: ******************************************************************************************************************/
81: @Nonnull
82: public Path getLogFolder();
83:
84: /*******************************************************************************************************************
85: *
86: * Sets the application name. This method must be called at boot from the {@code main} method before doing
87: * anything else.
88: *
89: * @param name the property name
90: *
91: ******************************************************************************************************************/
92: public static void setAppName (@Nonnull final String name)
93: {
94: System.setProperty(PROP_APP_NAME, name);
95: }
96:
97: /*******************************************************************************************************************
98: *
99: * Gets a property.
100: *
101: * @param <T> the property type
102: * @param name the property name
103: * @return the property value
104: *
105: ******************************************************************************************************************/
106: @Nonnull
107: public <T> Optional<T> getProperty (@Nonnull Key<T> name);
108:
109: /*******************************************************************************************************************
110: *
111: * Sets a property, overriding the current value.
112: *
113: * @param <T> the property type
114: * @param name the property name
115: * @param value the property value
116: *
117: ******************************************************************************************************************/
118: public <T> void setProperty (@Nonnull final Key<T> name, @Nonnull final T value);
119:
120: /**
121: *
122: * Sets a property, unless it has been already set.
123: *
124: * @param <T> the property type
125: * @param name the property name
126: * @param value the property value
127: *
128: ******************************************************************************************************************/
129: public <T> void setDefaultProperty (@Nonnull final Key<T> name, @Nonnull final T value);
130: }