Browse Source

Tidy up Theme a bit.

Remove singleton IdentityManager references.

Change-Id: I6b3214d54d8d0c7848d445efce94f389f9c2a7d4
Reviewed-on: http://gerrit.dmdirc.com/2750
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8rc1
Chris Smith 10 years ago
parent
commit
32730d3557
2 changed files with 12 additions and 21 deletions
  1. 11
    20
      src/com/dmdirc/ui/themes/Theme.java
  2. 1
    1
      src/com/dmdirc/ui/themes/ThemeManager.java

+ 11
- 20
src/com/dmdirc/ui/themes/Theme.java View File

22
 
22
 
23
 package com.dmdirc.ui.themes;
23
 package com.dmdirc.ui.themes;
24
 
24
 
25
-import com.dmdirc.config.IdentityManager;
26
 import com.dmdirc.config.InvalidIdentityFileException;
25
 import com.dmdirc.config.InvalidIdentityFileException;
26
+import com.dmdirc.interfaces.IdentityController;
27
 import com.dmdirc.logger.ErrorLevel;
27
 import com.dmdirc.logger.ErrorLevel;
28
 import com.dmdirc.logger.Logger;
28
 import com.dmdirc.logger.Logger;
29
 import com.dmdirc.util.io.ConfigFile;
29
 import com.dmdirc.util.io.ConfigFile;
34
 import java.io.IOException;
34
 import java.io.IOException;
35
 import java.io.InputStream;
35
 import java.io.InputStream;
36
 
36
 
37
+import lombok.RequiredArgsConstructor;
38
+
37
 /**
39
 /**
38
  * Represents one theme file.
40
  * Represents one theme file.
39
  */
41
  */
42
+@RequiredArgsConstructor
40
 public class Theme implements Comparable<Theme> {
43
 public class Theme implements Comparable<Theme> {
41
 
44
 
45
+    /** The controller to add theme identities to. */
46
+    private final IdentityController identityController;
47
+
42
     /** The file to load the theme from. */
48
     /** The file to load the theme from. */
43
     private final File file;
49
     private final File file;
44
 
50
 
54
     /** The Identity we've registered. */
60
     /** The Identity we've registered. */
55
     private ThemeIdentity identity;
61
     private ThemeIdentity identity;
56
 
62
 
57
-    /**
58
-     * Creates a new instance of Theme.
59
-     *
60
-     * @param file The file to load the theme from
61
-     */
62
-    public Theme(final File file) {
63
-        this.file = file;
64
-    }
65
-
66
     /**
63
     /**
67
      * Determines if this theme is valid or not (i.e., it is a valid zip file,
64
      * Determines if this theme is valid or not (i.e., it is a valid zip file,
68
      * and it contains one file).
65
      * and it contains one file).
85
 
82
 
86
                 try {
83
                 try {
87
                     metadata.read();
84
                     metadata.read();
88
-                } catch (IOException ex) {
89
-                    metadata = null;
90
-                } catch (InvalidConfigFileException ex) {
85
+                } catch (IOException | InvalidConfigFileException ex) {
91
                     metadata = null;
86
                     metadata = null;
92
                 }
87
                 }
93
             }
88
             }
111
         if (stream != null) {
106
         if (stream != null) {
112
             try {
107
             try {
113
                 identity = new ThemeIdentity(stream, this);
108
                 identity = new ThemeIdentity(stream, this);
114
-                IdentityManager.getIdentityManager().registerIdentity(identity);
115
-            } catch (InvalidIdentityFileException ex) {
116
-                Logger.userError(ErrorLevel.MEDIUM, "Error loading theme identity file: "
117
-                        + ex.getMessage());
118
-            } catch (IOException ex) {
109
+                identityController.registerIdentity(identity);
110
+            } catch (InvalidIdentityFileException | IOException ex) {
119
                 Logger.userError(ErrorLevel.MEDIUM, "Error loading theme identity file: "
111
                 Logger.userError(ErrorLevel.MEDIUM, "Error loading theme identity file: "
120
                         + ex.getMessage());
112
                         + ex.getMessage());
121
             }
113
             }
131
         }
123
         }
132
 
124
 
133
         enabled = false;
125
         enabled = false;
134
-
135
-        IdentityManager.getIdentityManager().unregisterIdentity(identity);
126
+        identityController.unregisterIdentity(identity);
136
     }
127
     }
137
 
128
 
138
     /**
129
     /**

+ 1
- 1
src/com/dmdirc/ui/themes/ThemeManager.java View File

110
         if (themes.containsKey(file.getName())) {
110
         if (themes.containsKey(file.getName())) {
111
             theme = themes.get(file.getName());
111
             theme = themes.get(file.getName());
112
         } else {
112
         } else {
113
-            theme = new Theme(file);
113
+            theme = new Theme(identityController, file);
114
 
114
 
115
             if (theme.isValidTheme()) {
115
             if (theme.isValidTheme()) {
116
                 themes.put(file.getName(), theme);
116
                 themes.put(file.getName(), theme);

Loading…
Cancel
Save