Browse Source

Move MainFrame initialisation out of constructor.

Change-Id: If84baaa21a34335cd41e9b06bf4c693889cdfd76
Reviewed-on: http://gerrit.dmdirc.com/3320
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/20/3320/2
Greg Holmes 10 years ago
parent
commit
43f326cafd
1 changed files with 33 additions and 24 deletions
  1. 33
    24
      src/com/dmdirc/addons/ui_swing/MainFrame.java

+ 33
- 24
src/com/dmdirc/addons/ui_swing/MainFrame.java View File

@@ -120,7 +120,9 @@ public class MainFrame extends JFrame implements WindowListener,
120 120
     /** Main split pane. */
121 121
     private SplitPane mainSplitPane;
122 122
     /** Are we quitting or closing? */
123
-    private boolean quitting = false;
123
+    private boolean quitting;
124
+    /** Have we initialised our settings and listeners? */
125
+    private boolean initDone;
124 126
 
125 127
     /**
126 128
      * Creates new form MainFrame.
@@ -152,38 +154,45 @@ public class MainFrame extends JFrame implements WindowListener,
152 154
         this.iconManager = iconManager;
153 155
         this.frameManagerProvider = frameManagerProvider;
154 156
         this.eventBus = eventBus;
155
-
157
+        version = globalConfig.getOption("version", "version");
156 158
         focusOrder = new QueuedLinkedHashSet<>();
157
-        imageIcon = new ImageIcon(iconManager.getImage("icon"));
158
-        setIconImage(imageIcon.getImage());
159
+    }
159 160
 
160
-        CoreUIUtils.centreWindow(this);
161
+    @Override
162
+    public void setVisible(final boolean visible) {
163
+        if (!initDone) {
164
+            imageIcon = new ImageIcon(iconManager.getImage("icon"));
165
+            setIconImage(imageIcon.getImage());
161 166
 
162
-        addWindowListener(this);
167
+            CoreUIUtils.centreWindow(this);
163 168
 
164
-        showVersion = globalConfig.getOptionBool("ui", "showversion");
165
-        version = globalConfig.getOption("version", "version");
166
-        globalConfig.addChangeListener("ui", "showversion", this);
167
-        globalConfig.addChangeListener("ui", "framemanager", this);
168
-        globalConfig.addChangeListener("ui", "framemanagerPosition", this);
169
-        globalConfig.addChangeListener("icon", "icon", this);
169
+            addWindowListener(this);
170 170
 
171
-        addWindowFocusListener(new WindowFocusListener() {
171
+            showVersion = globalConfig.getOptionBool("ui", "showversion");
172
+            globalConfig.addChangeListener("ui", "showversion", this);
173
+            globalConfig.addChangeListener("ui", "framemanager", this);
174
+            globalConfig.addChangeListener("ui", "framemanagerPosition", this);
175
+            globalConfig.addChangeListener("icon", "icon", this);
172 176
 
173
-            @Override
174
-            public void windowGainedFocus(final WindowEvent e) {
175
-                eventBus.post(new ClientFocusGainedEvent());
176
-            }
177
+            addWindowFocusListener(new WindowFocusListener() {
177 178
 
178
-            @Override
179
-            public void windowLostFocus(final WindowEvent e) {
180
-                eventBus.post(new ClientFocusLostEvent());
181
-            }
182
-        });
179
+                @Override
180
+                public void windowGainedFocus(final WindowEvent e) {
181
+                    eventBus.post(new ClientFocusGainedEvent());
182
+                }
183 183
 
184
-        windowFactory.addWindowListener(this);
184
+                @Override
185
+                public void windowLostFocus(final WindowEvent e) {
186
+                    eventBus.post(new ClientFocusLostEvent());
187
+                }
188
+            });
185 189
 
186
-        setTitle(getTitlePrefix());
190
+            windowFactory.addWindowListener(this);
191
+
192
+            setTitle(getTitlePrefix());
193
+            initDone = true;
194
+        }
195
+        super.setVisible(visible);
187 196
     }
188 197
 
189 198
     public SwingStatusBar getStatusBar() {

Loading…
Cancel
Save