View Javadoc
1   /*
2    * Prometheus: Application Framework
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.prometheus.toolkit;
18  
19  import io.github.tonywasher.joceanus.gordianknot.api.factory.GordianFactoryType;
20  import io.github.tonywasher.joceanus.gordianknot.api.lock.GordianPasswordLockSpec;
21  import io.github.tonywasher.joceanus.metis.toolkit.MetisToolkit;
22  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
23  import io.github.tonywasher.joceanus.prometheus.preference.PrometheusPreferenceManager;
24  import io.github.tonywasher.joceanus.prometheus.preference.PrometheusPreferenceSecurity.PrometheusSecurityPreferences;
25  import io.github.tonywasher.joceanus.prometheus.preference.PrometheusPreferenceView;
26  import io.github.tonywasher.joceanus.prometheus.security.PrometheusSecurityGenerator;
27  import io.github.tonywasher.joceanus.prometheus.security.PrometheusSecurityPasswordManager;
28  import io.github.tonywasher.joceanus.tethys.api.base.TethysUIProgram;
29  import io.github.tonywasher.joceanus.tethys.api.factory.TethysUIFactory;
30  import io.github.tonywasher.joceanus.tethys.api.thread.TethysUIThreadManager;
31  
32  /**
33   * Prometheus Toolkit.
34   */
35  public class PrometheusToolkit {
36      /**
37       * Toolkit.
38       */
39      private final MetisToolkit theToolkit;
40  
41      /**
42       * Preference Manager.
43       */
44      private final PrometheusPreferenceManager thePreferenceManager;
45  
46      /**
47       * Password Manager.
48       */
49      private final PrometheusSecurityPasswordManager thePasswordMgr;
50  
51      /**
52       * Constructor.
53       *
54       * @param pFactory the GUI factory
55       * @throws OceanusException on error
56       */
57      public PrometheusToolkit(final TethysUIFactory<?> pFactory) throws OceanusException {
58          /* Store parameters */
59          theToolkit = new MetisToolkit(pFactory, false);
60  
61          /* Access components */
62          thePreferenceManager = new PrometheusPreferenceManager(theToolkit.getViewerManager());
63          theToolkit.setUpColors(thePreferenceManager);
64  
65          /* Create the passwordManager */
66          final PrometheusSecurityPreferences myPreferences = thePreferenceManager.getPreferenceSet(PrometheusSecurityPreferences.class);
67          thePasswordMgr = newPasswordManager(myPreferences.getFactoryType(), myPreferences.getPasswordLockSpec());
68  
69          /* Set this as the threadData */
70          final TethysUIThreadManager myThreadMgr = theToolkit.getThreadManager();
71          myThreadMgr.setThreadData(this);
72      }
73  
74      /**
75       * Obtain the preference manager.
76       *
77       * @return the preference manager
78       */
79      public PrometheusPreferenceManager getPreferenceManager() {
80          return thePreferenceManager;
81      }
82  
83      /**
84       * Obtain the password manager.
85       *
86       * @return the password manager
87       */
88      public PrometheusSecurityPasswordManager getPasswordManager() {
89          return thePasswordMgr;
90      }
91  
92      /**
93       * Obtain the Program Definitions.
94       *
95       * @return the definitions
96       */
97      public TethysUIProgram getProgramDefinitions() {
98          return theToolkit.getProgramDefinitions();
99      }
100 
101     /**
102      * Obtain the Toolkit.
103      *
104      * @return the toolkit
105      */
106     public MetisToolkit getToolkit() {
107         return theToolkit;
108     }
109 
110     /**
111      * Create a Password Manager.
112      *
113      * @param pFactoryType the factoryType
114      * @param pLockSpec    the lockSpec
115      * @return the manager
116      * @throws OceanusException on error
117      */
118     private PrometheusSecurityPasswordManager newPasswordManager(final GordianFactoryType pFactoryType,
119                                                                  final GordianPasswordLockSpec pLockSpec) throws OceanusException {
120         return PrometheusSecurityGenerator.newPasswordManager(getToolkit().getGuiFactory(), pFactoryType, pLockSpec);
121     }
122 
123     /**
124      * Create a new Preference View.
125      *
126      * @return the view
127      */
128     public PrometheusPreferenceView newPreferenceView() {
129         return new PrometheusPreferenceView(getToolkit().getGuiFactory(), thePreferenceManager);
130     }
131 }