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,8 +22,8 @@
22 22
 
23 23
 package com.dmdirc.ui.themes;
24 24
 
25
-import com.dmdirc.config.IdentityManager;
26 25
 import com.dmdirc.config.InvalidIdentityFileException;
26
+import com.dmdirc.interfaces.IdentityController;
27 27
 import com.dmdirc.logger.ErrorLevel;
28 28
 import com.dmdirc.logger.Logger;
29 29
 import com.dmdirc.util.io.ConfigFile;
@@ -34,11 +34,17 @@ import java.io.File;
34 34
 import java.io.IOException;
35 35
 import java.io.InputStream;
36 36
 
37
+import lombok.RequiredArgsConstructor;
38
+
37 39
 /**
38 40
  * Represents one theme file.
39 41
  */
42
+@RequiredArgsConstructor
40 43
 public class Theme implements Comparable<Theme> {
41 44
 
45
+    /** The controller to add theme identities to. */
46
+    private final IdentityController identityController;
47
+
42 48
     /** The file to load the theme from. */
43 49
     private final File file;
44 50
 
@@ -54,15 +60,6 @@ public class Theme implements Comparable<Theme> {
54 60
     /** The Identity we've registered. */
55 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 64
      * Determines if this theme is valid or not (i.e., it is a valid zip file,
68 65
      * and it contains one file).
@@ -85,9 +82,7 @@ public class Theme implements Comparable<Theme> {
85 82
 
86 83
                 try {
87 84
                     metadata.read();
88
-                } catch (IOException ex) {
89
-                    metadata = null;
90
-                } catch (InvalidConfigFileException ex) {
85
+                } catch (IOException | InvalidConfigFileException ex) {
91 86
                     metadata = null;
92 87
                 }
93 88
             }
@@ -111,11 +106,8 @@ public class Theme implements Comparable<Theme> {
111 106
         if (stream != null) {
112 107
             try {
113 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 111
                 Logger.userError(ErrorLevel.MEDIUM, "Error loading theme identity file: "
120 112
                         + ex.getMessage());
121 113
             }
@@ -131,8 +123,7 @@ public class Theme implements Comparable<Theme> {
131 123
         }
132 124
 
133 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,7 +110,7 @@ public final class ThemeManager {
110 110
         if (themes.containsKey(file.getName())) {
111 111
             theme = themes.get(file.getName());
112 112
         } else {
113
-            theme = new Theme(file);
113
+            theme = new Theme(identityController, file);
114 114
 
115 115
             if (theme.isValidTheme()) {
116 116
                 themes.put(file.getName(), theme);

Loading…
Cancel
Save