Skip to content

Commit f9aad48

Browse files
committed
Remove LoginPanel singleton to separate class to allow other implementations
Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent c613d97 commit f9aad48

File tree

5 files changed

+51
-19
lines changed

5 files changed

+51
-19
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.mirth.connect.client.ui;
2+
3+
/**
4+
* Public interface for the login panel so alternative implementations can be provided.
5+
*/
6+
public abstract class AbstractLoginPanel extends javax.swing.JFrame {
7+
8+
/**
9+
* Initialize and show the login UI.
10+
*/
11+
public abstract void initialize(String mirthServer, String version, String user, String pass);
12+
13+
/**
14+
* Update the status text shown on the login UI.
15+
*/
16+
public abstract void setStatus(String status);
17+
}

client/src/com/mirth/connect/client/ui/Frame.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ public void eventDispatched(AWTEvent e)
543543
*/
544544
public void setupFrame(Client mirthClient) throws ClientException {
545545

546-
LoginPanel login = LoginPanel.getInstance();
546+
AbstractLoginPanel login = LoginPanelFactory.getInstance();
547547

548548
// Initialize the send message dialog
549549
editMessageDialog = new EditMessageDialog();
@@ -1524,7 +1524,7 @@ public void alertThrowable(Component parentComponent, Throwable t, String custom
15241524
}
15251525
mirthClient.close();
15261526
this.dispose();
1527-
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
1527+
LoginPanelFactory.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
15281528
return;
15291529
} else if (t.getCause() != null && t.getCause() instanceof HttpHostConnectException && (StringUtils.contains(t.getCause().getMessage(), "Connection refused") || StringUtils.contains(t.getCause().getMessage(), "Host is down"))) {
15301530
connectionError = true;
@@ -1542,7 +1542,7 @@ public void alertThrowable(Component parentComponent, Throwable t, String custom
15421542
}
15431543
mirthClient.close();
15441544
this.dispose();
1545-
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
1545+
LoginPanelFactory.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
15461546
return;
15471547
}
15481548
}
@@ -2292,7 +2292,7 @@ public boolean logout(boolean quit, boolean confirmFirst) {
22922292
this.dispose();
22932293

22942294
if (!quit) {
2295-
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
2295+
LoginPanelFactory.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
22962296
}
22972297

22982298
return true;

client/src/com/mirth/connect/client/ui/LoginPanel.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131
import com.mirth.connect.model.LoginStatus;
3232
import com.mirth.connect.plugins.MultiFactorAuthenticationClientPlugin;
3333

34-
public class LoginPanel extends javax.swing.JFrame {
34+
public class LoginPanel extends AbstractLoginPanel {
3535

3636
private static final String ERROR_MESSAGE = "There was an error connecting to the server at the specified address. Please verify that the server is up and running.";
37-
private static LoginPanel instance = null;
3837

39-
private LoginPanel() {
38+
public LoginPanel() {
4039
initComponents();
4140
DisplayUtil.setResizable(this, false);
4241
jLabel2.setForeground(UIConstants.HEADER_TITLE_TEXT_COLOR);
@@ -74,15 +73,7 @@ public void mouseClicked(java.awt.event.MouseEvent evt) {
7473
errorTextArea.setDisabledTextColor(Color.RED);
7574
}
7675

77-
public static LoginPanel getInstance() {
78-
synchronized (LoginPanel.class) {
79-
if (instance == null) {
80-
instance = new LoginPanel();
81-
}
82-
return instance;
83-
}
84-
}
85-
76+
@Override
8677
public void initialize(String mirthServer, String version, String user, String pass) {
8778
synchronized (this) {
8879
// Do not initialize another login window if one is already visible
@@ -501,6 +492,7 @@ private void closeButtonActionPerformed(java.awt.event.ActionEvent evt)// GEN-FI
501492
System.exit(0);
502493
}// GEN-LAST:event_closeButtonActionPerformed
503494

495+
@Override
504496
public void setStatus(String status) {
505497
this.status.setText("Please wait: " + status);
506498
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.mirth.connect.client.ui;
2+
3+
/**
4+
* Factory for obtaining the application's LoginPanel implementation.
5+
*/
6+
public class LoginPanelFactory {
7+
8+
private static AbstractLoginPanel provider = null;
9+
10+
public static synchronized AbstractLoginPanel getInstance() {
11+
if (provider == null) {
12+
provider = new LoginPanel();
13+
}
14+
return provider;
15+
}
16+
17+
/**
18+
* Replace the current provider. This is used to switch between login implementations at runtime.
19+
*/
20+
public static synchronized void setProvider(AbstractLoginPanel newProvider) {
21+
provider = newProvider;
22+
}
23+
}

client/src/com/mirth/connect/client/ui/Mirth.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public Mirth(Client mirthClient) throws ClientException {
7575
UIManager.put("Tree.closedIcon", UIConstants.CLOSED_ICON);
7676

7777
userPreferences = Preferences.userNodeForPackage(Mirth.class);
78-
LoginPanel.getInstance().setStatus("Loading components...");
78+
LoginPanelFactory.getInstance().setStatus("Loading components...");
7979
PlatformUI.MIRTH_FRAME.setupFrame(mirthClient);
8080

8181
boolean maximized;
@@ -135,7 +135,7 @@ public static void aboutMac() {
135135
* @return quit
136136
*/
137137
public static boolean quitMac() {
138-
return (LoginPanel.getInstance().isVisible() || (PlatformUI.MIRTH_FRAME != null && PlatformUI.MIRTH_FRAME.logout(true)));
138+
return PlatformUI.MIRTH_FRAME == null || PlatformUI.MIRTH_FRAME.logout(true);
139139
}
140140

141141
/**
@@ -297,7 +297,7 @@ private static void start(final String server, final String version, final Strin
297297
public void run() {
298298
initUIManager();
299299
PlatformUI.BACKGROUND_IMAGE = new ImageIcon(com.mirth.connect.client.ui.Frame.class.getResource("images/header_nologo.png"));
300-
LoginPanel.getInstance().initialize(server, version, username, password);
300+
LoginPanelFactory.getInstance().initialize(server, version, username, password);
301301
}
302302
});
303303
}

0 commit comments

Comments
 (0)