Browse Source

synchronize on the dialog list not the method to get the dialogs

git-svn-id: http://svn.dmdirc.com/trunk@2292 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.1
Gregory Holmes 17 years ago
parent
commit
e3b4fbdb53

+ 63
- 65
src/com/dmdirc/ui/swing/dialogs/channelsetting/ChannelSettingsDialog.java View File

@@ -51,38 +51,39 @@ import javax.swing.WindowConstants;
51 51
  * Allows the user to modify channel settings (modes, topics, etc).
52 52
  */
53 53
 public final class ChannelSettingsDialog extends StandardDialog implements ActionListener {
54
-
54
+    
55 55
     /**
56 56
      * A version number for this class. It should be changed whenever the class
57 57
      * structure is changed (or anything else that would prevent serialized
58 58
      * objects being unserialized with the new class).
59 59
      */
60 60
     private static final long serialVersionUID = 7;
61
-
61
+    
62 62
     /** Channel settings dialogs, semi singleton use. */
63
-    private static Map<Channel, ChannelSettingsDialog> dialogs;
64
-
63
+    private static Map<Channel, ChannelSettingsDialog> dialogs =
64
+            new HashMap<Channel, ChannelSettingsDialog>();
65
+    
65 66
     /** The channel object that this dialog belongs to. */
66 67
     private final Channel channel;
67
-
68
+    
68 69
     /** Tabbed pane. */
69 70
     private JTabbedPane tabbedPane;
70
-
71
+    
71 72
     /** Client settings panel. */
72 73
     private SettingsPanel channelSettingsPane;
73
-
74
+    
74 75
     /** List modes panel. */
75 76
     private ChannelModesPane channelModesPane;
76
-
77
+    
77 78
     /** List modes panel. */
78 79
     private TopicModesPane topicModesPane;
79
-
80
+    
80 81
     /** List modes panel. */
81 82
     private ChannelListModesPane channelListModesPane;
82
-
83
+    
83 84
     /** Channel identity file. */
84 85
     private final Identity identity;
85
-
86
+    
86 87
     /**
87 88
      * Creates a new instance of ChannelSettingsDialog.
88 89
      *
@@ -90,19 +91,19 @@ public final class ChannelSettingsDialog extends StandardDialog implements Actio
90 91
      */
91 92
     private ChannelSettingsDialog(final Channel newChannel) {
92 93
         super((MainFrame) Main.getUI().getMainWindow(), false);
93
-
94
+        
94 95
         channel = newChannel;
95 96
         identity =
96 97
                 IdentityManager.getChannelConfig(channel.getServer().
97 98
                 getNetwork(), channel.getChannelInfo().getName());
98
-
99
+        
99 100
         initComponents();
100 101
         initListeners();
101
-
102
+        
102 103
         pack();
103 104
         setLocationRelativeTo((MainFrame) Main.getUI().getMainWindow());
104 105
     }
105
-
106
+    
106 107
     /**
107 108
      * Returns an instance of the CSD for the specified channel.
108 109
      *
@@ -110,36 +111,33 @@ public final class ChannelSettingsDialog extends StandardDialog implements Actio
110 111
      *
111 112
      * @return CSD instance for the specified channel
112 113
      */
113
-    public static synchronized ChannelSettingsDialog getChannelSettingDialog(final Channel channel) {
114
-        if (dialogs == null) {
115
-            dialogs =
116
-                    new HashMap<Channel, ChannelSettingsDialog>();
117
-        }
118
-
119
-        if (dialogs.containsKey(channel)) {
120
-            dialogs.get(channel).update();
121
-        } else {
122
-            dialogs.put(channel, new ChannelSettingsDialog(channel));
114
+    public static ChannelSettingsDialog getChannelSettingDialog(final Channel channel) {
115
+        synchronized (dialogs) {
116
+            if (dialogs.containsKey(channel)) {
117
+                dialogs.get(channel).update();
118
+            } else {
119
+                dialogs.put(channel, new ChannelSettingsDialog(channel));
120
+            }
121
+            
122
+            return dialogs.get(channel);
123 123
         }
124
-
125
-        return dialogs.get(channel);
126 124
     }
127
-
125
+    
128 126
     /** Initialises the main UI components. */
129 127
     private void initComponents() {
130 128
         final GridBagConstraints constraints = new GridBagConstraints();
131 129
         tabbedPane = new JTabbedPane();
132
-
130
+        
133 131
         setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
134 132
         getContentPane().setLayout(new GridBagLayout());
135 133
         setTitle("Channel settings for " + channel);
136 134
         setResizable(false);
137
-
135
+        
138 136
         final JButton button1 = new JButton();
139 137
         final JButton button2 = new JButton();
140
-
138
+        
141 139
         orderButtons(button1, button2);
142
-
140
+        
143 141
         constraints.gridx = 0;
144 142
         constraints.gridy = 0;
145 143
         constraints.gridwidth = 3;
@@ -150,13 +148,13 @@ public final class ChannelSettingsDialog extends StandardDialog implements Actio
150 148
                 new Insets(SMALL_BORDER, SMALL_BORDER, SMALL_BORDER,
151 149
                 SMALL_BORDER);
152 150
         getContentPane().add(tabbedPane, constraints);
153
-
151
+        
154 152
         constraints.weighty = 0.0;
155 153
         constraints.gridx = 0;
156 154
         constraints.gridy = 1;
157 155
         constraints.gridwidth = 1;
158 156
         getContentPane().add(Box.createHorizontalGlue(), constraints);
159
-
157
+        
160 158
         constraints.weightx = 0.0;
161 159
         constraints.insets.set(0, SMALL_BORDER, SMALL_BORDER, SMALL_BORDER);
162 160
         constraints.gridx = 1;
@@ -164,45 +162,45 @@ public final class ChannelSettingsDialog extends StandardDialog implements Actio
164 162
         constraints.anchor = GridBagConstraints.EAST;
165 163
         constraints.fill = GridBagConstraints.NONE;
166 164
         getContentPane().add(getLeftButton(), constraints);
167
-
165
+        
168 166
         constraints.gridx = 2;
169 167
         constraints.insets.set(0, 0, SMALL_BORDER, SMALL_BORDER);
170 168
         getContentPane().add(getRightButton(), constraints);
171
-
169
+        
172 170
         initIrcTab();
173
-
171
+        
174 172
         initListModesTab();
175
-
173
+        
176 174
         initSettingsTab();
177
-
175
+        
178 176
         tabbedPane.setSelectedIndex(channel.getConfigManager().
179 177
                 getOptionInt("dialogstate", "channelsettingsdialog", 0));
180 178
     }
181
-
179
+    
182 180
     /** Updates the dialogs content. */
183 181
     private void update() {
184 182
         channelListModesPane.update();
185 183
         channelModesPane.update();
186 184
         channelSettingsPane.update();
187 185
         topicModesPane.update();
188
-
186
+        
189 187
         tabbedPane.setSelectedIndex(channel.getConfigManager().
190 188
                 getOptionInt("dialogstate", "channelsettingsdialog", 0));
191 189
     }
192
-
190
+    
193 191
     /** Initialises the IRC Settings tab. */
194 192
     private void initIrcTab() {
195 193
         final GridBagConstraints constraints = new GridBagConstraints();
196 194
         final JPanel settingsPanel = new JPanel(new GridBagLayout());
197
-
195
+        
198 196
         tabbedPane.addTab("IRC Settings", settingsPanel);
199
-
197
+        
200 198
         settingsPanel.setBorder(BorderFactory.createEmptyBorder(SMALL_BORDER,
201 199
                 SMALL_BORDER, SMALL_BORDER, SMALL_BORDER));
202
-
200
+        
203 201
         channelModesPane = new ChannelModesPane(channel);
204 202
         topicModesPane = new TopicModesPane(channel, this);
205
-
203
+        
206 204
         constraints.gridx = 0;
207 205
         constraints.gridy = 0;
208 206
         constraints.fill = GridBagConstraints.BOTH;
@@ -212,37 +210,37 @@ public final class ChannelSettingsDialog extends StandardDialog implements Actio
212 210
         constraints.gridy = 1;
213 211
         settingsPanel.add(topicModesPane, constraints);
214 212
     }
215
-
213
+    
216 214
     /** Initialises the IRC Settings tab. */
217 215
     private void initListModesTab() {
218 216
         channelListModesPane = new ChannelListModesPane(channel);
219 217
         tabbedPane.addTab("List Modes", channelListModesPane);
220 218
     }
221
-
219
+    
222 220
     /** Initialises the channel Settings (identities) tab. */
223 221
     private void initSettingsTab() {
224
-
222
+        
225 223
         initSettingsPanel();
226
-
224
+        
227 225
         tabbedPane.addTab("Client Settings", channelSettingsPane);
228 226
     }
229
-
227
+    
230 228
     /** Initialises the channel settings. */
231 229
     private void initSettingsPanel() {
232 230
         channelSettingsPane =
233 231
                 new SettingsPanel(identity,
234
-                "These settings are specific to this channel on this network, " 
232
+                "These settings are specific to this channel on this network, "
235 233
                 + "any settings specified here will overwrite global settings");
236
-
234
+        
237 235
         channelSettingsPane.addOption("channel.splitusermodes",
238 236
                 "Split user modes", OptionType.CHECKBOX);
239 237
         channelSettingsPane.addOption("channel.sendwho", "Send channel WHOs",
240 238
                 OptionType.CHECKBOX);
241 239
         channelSettingsPane.addOption("channel.showmodeprefix", "Show mode prefixes",
242 240
                 OptionType.CHECKBOX);
243
-        channelSettingsPane.addOption("ui.shownickcoloursinnicklist", 
241
+        channelSettingsPane.addOption("ui.shownickcoloursinnicklist",
244 242
                 "Show colours in nicklist", OptionType.CHECKBOX);
245
-        channelSettingsPane.addOption("ui.shownickcoloursintext", 
243
+        channelSettingsPane.addOption("ui.shownickcoloursintext",
246 244
                 "Show colours in textpane", OptionType.CHECKBOX);
247 245
         channelSettingsPane.addOption("general.cyclemessage", "Cycle message",
248 246
                 OptionType.TEXTFIELD);
@@ -258,24 +256,24 @@ public final class ChannelSettingsDialog extends StandardDialog implements Actio
258 256
                 OptionType.SPINNER);
259 257
         channelSettingsPane.addOption("ui.inputbuffersize", "Input buffer size",
260 258
                 OptionType.SPINNER);
261
-        channelSettingsPane.addOption("ui.inputbackgroundcolour", 
259
+        channelSettingsPane.addOption("ui.inputbackgroundcolour",
262 260
                 "Inputfield background colour", OptionType.COLOUR);
263
-        channelSettingsPane.addOption("ui.inputforegroundcolour", 
261
+        channelSettingsPane.addOption("ui.inputforegroundcolour",
264 262
                 "Inputfield foreground colour", OptionType.COLOUR);
265
-        channelSettingsPane.addOption("ui.nicklistbackgroundcolour", 
263
+        channelSettingsPane.addOption("ui.nicklistbackgroundcolour",
266 264
                 "Nicklist background colour", OptionType.COLOUR);
267
-        channelSettingsPane.addOption("ui.nicklistforegroundcolour", 
265
+        channelSettingsPane.addOption("ui.nicklistforegroundcolour",
268 266
                 "Nicklist foreground colour", OptionType.COLOUR);
269
-        channelSettingsPane.addOption("channel.encoding", "Encoding", 
267
+        channelSettingsPane.addOption("channel.encoding", "Encoding",
270 268
                 OptionType.TEXTFIELD);
271 269
     }
272
-
270
+    
273 271
     /** Initialises listeners for this dialog. */
274 272
     private void initListeners() {
275 273
         getOkButton().addActionListener(this);
276 274
         getCancelButton().addActionListener(this);
277 275
     }
278
-
276
+    
279 277
     /**
280 278
      * Called whenever the user clicks on one of the two buttons.
281 279
      *
@@ -288,17 +286,17 @@ public final class ChannelSettingsDialog extends StandardDialog implements Actio
288 286
             setVisible(false);
289 287
         }
290 288
     }
291
-
289
+    
292 290
     /** Saves the settings. */
293 291
     protected void save() {
294 292
         channelModesPane.setChangedBooleanModes();
295 293
         topicModesPane.setChangedTopic();
296 294
         channelSettingsPane.save();
297 295
         channelListModesPane.save();
298
-
296
+        
299 297
         identity.setOption("dialogstate", "channelsettingsdialog",
300 298
                 String.valueOf(tabbedPane.getSelectedIndex()));
301
-
299
+        
302 300
         setVisible(false);
303 301
     }
304 302
 }

Loading…
Cancel
Save