diff options
| author | Simon Rettberg | 2015-07-09 12:15:54 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2015-07-09 12:15:54 +0200 |
| commit | 0c7260e879a2514203719146e20dd243b5493095 (patch) | |
| tree | 82473c459df08d4c27f00adb64e41391baf7c29b /dozentenmodul/src/main/java | |
| parent | [server] Implement OS list fetching, caching, and fallback to local DB (diff) | |
| download | tutor-module-0c7260e879a2514203719146e20dd243b5493095.tar.gz tutor-module-0c7260e879a2514203719146e20dd243b5493095.tar.xz tutor-module-0c7260e879a2514203719146e20dd243b5493095.zip | |
[client] Clean up login, implement showMessageBox, fix formatting
Diffstat (limited to 'dozentenmodul/src/main/java')
8 files changed, 152 insertions, 156 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BaseAuthenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/Authenticator.java index 60602a3f..78c1528a 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BaseAuthenticator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/Authenticator.java @@ -2,15 +2,15 @@ package org.openslx.dozmod.authentication; import org.openslx.bwlp.thrift.iface.TAuthenticationException; import org.openslx.bwlp.thrift.iface.UserInfo; -import org.openslx.dozmod.authentication.ShibbolethECP.ReturnCode; +import org.openslx.dozmod.authentication.ShibbolethEcp.ReturnCode; import edu.kit.scc.dei.ecplean.ECPAuthenticationException; /** * @author Jonathan Bauer - * + * */ -public interface BaseAuthenticator { +public interface Authenticator { /** * Callback interface to the login to be called after a login @@ -21,13 +21,15 @@ public interface BaseAuthenticator { interface AuthenticatorCallback { void postLogin(ReturnCode returnCode, UserInfo user); } + /** - * Definition of the generic login method. + * Definition of the generic login method. * * @param username The username as String. * @param password The password as String. * @param callback The callback function to be called after the login - * @throws ECPAuthenticationException + * @throws ECPAuthenticationException */ - void login(String username, String password, AuthenticatorCallback callback) throws TAuthenticationException; + void login(String username, String password, AuthenticatorCallback callback) + throws TAuthenticationException; }
\ No newline at end of file diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWIDMAuthenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/EcpAuthenticator.java index ece74088..2494914a 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWIDMAuthenticator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/EcpAuthenticator.java @@ -11,7 +11,7 @@ import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.TAuthenticationException; import org.openslx.bwlp.thrift.iface.TInvalidTokenException; import org.openslx.bwlp.thrift.iface.UserInfo; -import org.openslx.dozmod.authentication.ShibbolethECP.ReturnCode; +import org.openslx.dozmod.authentication.ShibbolethEcp.ReturnCode; import org.openslx.thrifthelper.ThriftManager; import com.google.gson.JsonSyntaxException; @@ -20,16 +20,16 @@ import com.google.gson.JsonSyntaxException; * @author Jonathan Bauer * */ -public class BWIDMAuthenticator implements BaseAuthenticator { +public class EcpAuthenticator implements Authenticator { /** * Logger instance for this class */ - private final static Logger LOGGER = Logger.getLogger(BWIDMAuthenticator.class); + private final static Logger LOGGER = Logger.getLogger(EcpAuthenticator.class); private final String ecpUrl; - public BWIDMAuthenticator(String ecpUrl) { + public EcpAuthenticator(String ecpUrl) { // first lets check the given ecpUrl if (!ecpUrl.isEmpty()) this.ecpUrl = ecpUrl; @@ -45,7 +45,7 @@ public class BWIDMAuthenticator implements BaseAuthenticator { // try to login ReturnCode ret = null; try { - ret = ShibbolethECP.doLogin(this.ecpUrl, username, password); + ret = ShibbolethEcp.doLogin(this.ecpUrl, username, password); } catch (JsonSyntaxException e) { LOGGER.error("Could not parse JSON response from the service provider: ", e); } catch (ClientProtocolException e) { @@ -69,7 +69,7 @@ public class BWIDMAuthenticator implements BaseAuthenticator { if (ret == ReturnCode.NO_ERROR) { UserInfo userInfo; try { - userInfo = ThriftManager.getMasterClient().getUserFromToken(ShibbolethECP.getResponse().token); + userInfo = ThriftManager.getMasterClient().getUserFromToken(ShibbolethEcp.getResponse().token); } catch (TInvalidTokenException e) { LOGGER.error("Masterserver does not accepts the token received from the Service Provider. See trace: ", e); return; diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethECP.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethEcp.java index 0998c8af..22638b52 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethECP.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethEcp.java @@ -22,12 +22,12 @@ import com.google.gson.JsonSyntaxException; import edu.kit.scc.dei.ecplean.ECPAuthenticationException; import edu.kit.scc.dei.ecplean.ECPAuthenticator; -public class ShibbolethECP { +public class ShibbolethEcp { /** * Logger instance for this class */ - private final static Logger LOGGER = Logger.getLogger(ShibbolethECP.class); + private final static Logger LOGGER = Logger.getLogger(ShibbolethEcp.class); /** * Static gson object for (de)serialization diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWLPAuthenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/TestAccountAuthenticator.java index 7a9e718d..9ca67609 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWLPAuthenticator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/TestAccountAuthenticator.java @@ -4,25 +4,24 @@ import org.apache.log4j.Logger; import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.SessionData; import org.openslx.bwlp.thrift.iface.TAuthenticationException; -import org.openslx.bwlp.thrift.iface.TAuthorizationException; import org.openslx.bwlp.thrift.iface.UserInfo; -import org.openslx.dozmod.authentication.ShibbolethECP.ReturnCode; +import org.openslx.dozmod.authentication.ShibbolethEcp.ReturnCode; import org.openslx.thrifthelper.ThriftManager; /** * @author Jonathan Bauer - * + * */ -public class BWLPAuthenticator implements BaseAuthenticator { +public class TestAccountAuthenticator implements Authenticator { /** * Logger instance for this class */ - private final static Logger LOGGER = Logger.getLogger(BWLPAuthenticator.class); - + private final static Logger LOGGER = Logger.getLogger(TestAccountAuthenticator.class); + @Override - public void login(String username, String password, - AuthenticatorCallback callback) throws TAuthenticationException { + public void login(String username, String password, AuthenticatorCallback callback) + throws TAuthenticationException { SessionData authResult = null; // try to login user @@ -34,7 +33,7 @@ public class BWLPAuthenticator implements BaseAuthenticator { callback.postLogin(ReturnCode.ERROR_OTHER, null); return; } - + // handle answer from server if (authResult != null && authResult.authToken != null) { UserInfo userInfo = null; diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java index b79f306d..5fc53d5c 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java @@ -28,13 +28,14 @@ public abstract class GuiManager { static final int THRIFT_ERROR_RETRY_COUNT = 3; static final String THRIFT_ERROR = "Lost connection to the masterserver. Click OK to retry."; static final String THRIFT_FINAL_ERROR = "Could not re-establish connection to the masterserver after " - + THRIFT_ERROR_RETRY_COUNT + " tries. Contact an administrator/developer. Exiting application."; + + THRIFT_ERROR_RETRY_COUNT + " tries. Contact an administrator/developer. Exiting application."; /** * Add a new composite with content to the main Shell + * * @param The composite to add, should be a GUI */ - public static void addContent( Composite contentComposite ){ + public static void addContent(Composite contentComposite) { removeContent(); GuiManager.contentComposite = contentComposite; @@ -53,23 +54,14 @@ public abstract class GuiManager { * Remove the current content of the main shell */ private static void removeContent() { - if(contentComposite != null) { + if (contentComposite != null) { GuiManager.contentComposite.dispose(); } } - // TODO use showMessageBox - public static void showMessage(final String message, final int style) { - MessageBox msgBox = new MessageBox(mainShell, style); - msgBox.setText("Information"); - msgBox.setMessage(message); - int ret = msgBox.open(); - LOGGER.info("Message box return value: " + ret); - } - - public static Display getDisplay(){ - return display; + public static Display getDisplay() { + return display; } public static void initGui() { @@ -78,7 +70,7 @@ public abstract class GuiManager { // setup global thrift connection error handler before anything else // Set master server to use (TODO: make configurable via command line) - ThriftManager.setMasterServerAddress( "bwlp-masterserver.ruf.uni-freiburg.de" ); + ThriftManager.setMasterServerAddress("bwlp-masterserver.ruf.uni-freiburg.de"); // Set up thrift error message displaying ThriftManager.setErrorCallback(new ErrorCallback() { @@ -144,4 +136,27 @@ public abstract class GuiManager { display.sleep(); } } + + /** + * Generic helper to show a message box to the user, and optionally log the + * message to the log file. + * + * @param parent parent shell this message box belongs to + * @param message Message to display. Can be multiline. + * @param messageType Type of message (warning, information) + * @param logger Logger instance to log to. Can be null. + * @param exception Exception related to this message. Can be null. + */ + public static void showMessageBox(Shell parent, String message, MessageType messageType, Logger logger, + Throwable exception) { + if (logger != null) + logger.log(messageType.logPriority, message, exception); + if (exception != null) + message += "\n\n" + exception.getClass().getSimpleName() + " (Siehe Logdatei)"; + MessageBox box = new MessageBox(parent, messageType.style); + box.setMessage(message); + box.setText(messageType.title); + box.open(); + } + } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java index b0f55a5d..a5dc8b7b 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java @@ -1,23 +1,22 @@ package org.openslx.dozmod.gui.helper; -import javax.swing.JOptionPane; - import org.apache.log4j.Priority; +import org.eclipse.swt.SWT; @SuppressWarnings("deprecation") public enum MessageType { - DEBUG(JOptionPane.INFORMATION_MESSAGE, "Debug", Priority.DEBUG), - INFO(JOptionPane.INFORMATION_MESSAGE, "Hinweis", Priority.INFO), - WARNING(JOptionPane.WARNING_MESSAGE, "Warnung", Priority.WARN), - ERROR(JOptionPane.ERROR_MESSAGE, "Fehler", Priority.ERROR); + DEBUG(SWT.ICON_INFORMATION, "Debug", Priority.DEBUG), + INFO(SWT.ICON_INFORMATION, "Hinweis", Priority.INFO), + WARNING(SWT.ICON_WARNING, "Warnung", Priority.WARN), + ERROR(SWT.ICON_ERROR, "Fehler", Priority.ERROR); public final String title; - public final int optionPaneId; + public final int style; public final Priority logPriority; - private MessageType(int paneId, String title, Priority prio) { + private MessageType(int style, String title, Priority prio) { this.title = title; - this.optionPaneId = paneId; + this.style = style; this.logPriority = prio; } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java index 62860fb5..f3c47dd7 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java @@ -15,13 +15,14 @@ import org.openslx.bwlp.thrift.iface.Organization; import org.openslx.bwlp.thrift.iface.TAuthenticationException; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.dozmod.Config; -import org.openslx.dozmod.authentication.BWIDMAuthenticator; -import org.openslx.dozmod.authentication.BWLPAuthenticator; -import org.openslx.dozmod.authentication.BaseAuthenticator.AuthenticatorCallback; -import org.openslx.dozmod.authentication.ShibbolethECP.ReturnCode; +import org.openslx.dozmod.authentication.Authenticator; +import org.openslx.dozmod.authentication.Authenticator.AuthenticatorCallback; +import org.openslx.dozmod.authentication.EcpAuthenticator; +import org.openslx.dozmod.authentication.ShibbolethEcp.ReturnCode; +import org.openslx.dozmod.authentication.TestAccountAuthenticator; import org.openslx.dozmod.gui.helper.GuiManager; +import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.window.layout.LoginWindowLayout; -import org.openslx.dozmod.gui.window.layout.MainWindowLayout; import org.openslx.dozmod.thrift.OrganizationCache; import org.openslx.thrifthelper.ThriftManager; @@ -29,7 +30,7 @@ import edu.kit.scc.dei.ecplean.ECPAuthenticationException; /** * @author Jonathan Bauer - * + * */ public class LoginWindow extends LoginWindowLayout { @@ -39,15 +40,10 @@ public class LoginWindow extends LoginWindowLayout { private final String NO_USERNAME = "Kein Benutzername angegeben!"; private final String NO_PASSWORD = "Kein Passwort angegeben!"; - // user input variables - private String username = null; - private String password = null; - - /** * Constructor doing the setup of the logical GUI functions * Fetches the organization list for BWIDM logins and - * adds mouse/keyboard event listeners to various widgets. + * adds mouse/keyboard event listeners to various widgets. * * @param mainShell */ @@ -61,28 +57,28 @@ public class LoginWindow extends LoginWindowLayout { LOGGER.error("No organizations received from the cache."); idpCombo.add("No entries"); } - + // all fine, lets sort it Collections.sort(orgs, new Comparator<Organization>() { public int compare(Organization o1, Organization o2) { return o1.getDisplayName().compareTo(o2.getDisplayName()); } }); - + // now check if we had a saved identity provider String savedOrganizationId = Config.getIdentityProvider(); // add only organizations which have an ECP URL to the combobox for (Organization o : orgs) { - if (o.getEcpUrl() == null | o.getEcpUrl().isEmpty()) continue; + if (o.getEcpUrl() == null | o.getEcpUrl().isEmpty()) + continue; LOGGER.debug("Adding: " + o.toString()); idpCombo.add(o.displayName); idpCombo.setData(o.displayName, o); - if (savedOrganizationId != null && - !savedOrganizationId.isEmpty() && - savedOrganizationId.equals(o.getOrganizationId())) + if (savedOrganizationId != null && !savedOrganizationId.isEmpty() + && savedOrganizationId.equals(o.getOrganizationId())) // select the organization we just added, this seems kinda bad - is there a better way? idpCombo.select(idpCombo.getItemCount() - 1); - //idpCombo.select(idpCombo.indexOf(savedOrganizationId)); this is probably not optimal... but safer + //idpCombo.select(idpCombo.indexOf(savedOrganizationId)); this is probably not optimal... but safer } // if no organization was saved, none is selected, so select the first one in the combobox if (idpCombo.getSelectionIndex() == -1) @@ -104,10 +100,9 @@ public class LoginWindow extends LoginWindowLayout { } else { // default value for LOGIN_TYPE is BWIDM authButtons[LOGIN_TYPE.BWIDM.getId()].setSelection(true); - loginType = LOGIN_TYPE.BWIDM; + loginType = LOGIN_TYPE.BWIDM; } - - + // finally check if we had a saved username String savedUsername = Config.getUsername(); if (savedUsername != null && !savedUsername.isEmpty()) { @@ -164,11 +159,11 @@ public class LoginWindow extends LoginWindowLayout { loginType = LOGIN_TYPE.SAT; } }); - + // add a key listener to the password field to trigger login // when the user presses the ENTER key. passwordText.addKeyListener(new KeyListener() { - + @Override public void keyReleased(KeyEvent e) { if (e.keyCode == SWT.CR) { @@ -176,14 +171,16 @@ public class LoginWindow extends LoginWindowLayout { doLogin(); } } + @Override - public void keyPressed(KeyEvent e) {} + public void keyPressed(KeyEvent e) { + } }); } /** * Saves various user choices to the config file. - * This gets triggered when the login button is activated. + * This gets triggered when the login button is activated. */ private void doSaveConfig() { // first we need to check if the "Remember me" button is active @@ -198,7 +195,8 @@ public class LoginWindow extends LoginWindowLayout { } // always save the authentication method and potentially the identity provider if (!Config.setAuthenticationMethod(loginType.getTag())) - LOGGER.error("Could not save authentication method '" + loginType.getTag() + "' to '" + Config.getPath() + "'."); + LOGGER.error("Could not save authentication method '" + loginType.getTag() + "' to '" + + Config.getPath() + "'."); // check if we are doing bwIDM authentication if (loginType == LOGIN_TYPE.BWIDM) { // save the selected identity provider @@ -210,106 +208,98 @@ public class LoginWindow extends LoginWindowLayout { if (!Config.store()) LOGGER.error("Could not save '" + Config.getPath() + "'!"); } + /** * Actually do the login using the username/password in the field using the * authentication mechanism corresponding to the selected authButton - * @throws ECPAuthenticationException + * + * @throws ECPAuthenticationException */ private void doLogin() { // sanity check on loginType. if (loginType == null) { - LOGGER.error("No login type set, a default should be set! Ignoring..."); + GuiManager.showMessageBox(this.getShell(), + "No login type set, a default should be set! Ignoring...", MessageType.ERROR, LOGGER, + null); return; } // here we only check for the fields - username = usernameText.getText(); - password = passwordText.getText(); + String username = usernameText.getText(); + String password = passwordText.getText(); // login clicked, lets first read the fields - if (username == null) { - // tell the GUIManager to show an error to the user - // TODO either popup or in the bottom status bar - GuiManager.showMessage(NO_USERNAME, SWT.ICON_ERROR); + if (username.isEmpty()) { + GuiManager.showMessageBox(this.getShell(), NO_USERNAME, MessageType.ERROR, null, null); return; } - if (password == null) { - // tell the GUIManager to show an error to the user - // TODO either popup or in the bottom status bar - GuiManager.showMessage(NO_PASSWORD, SWT.ICON_ERROR); + if (password.isEmpty()) { + GuiManager.showMessageBox(this.getShell(), NO_PASSWORD, MessageType.ERROR, null, null); return; } // determine which organization was selected by the user. + // TODO: Needed for test accounts? Organization selectedOrg = getSelectedOrganization(); + // Setup login callback + final LoginWindow me = this; + AuthenticatorCallback authenticatorCallback = new AuthenticatorCallback() { + @Override + public void postLogin(ReturnCode returnCode, UserInfo user) { + // TODO finish this + // handle errors first + if (returnCode != ReturnCode.NO_ERROR && user == null) { + switch (returnCode) { + case IDP_ERROR: + GuiManager.showMessageBox(me.getShell(), "IdP Error", MessageType.ERROR, null, null); + break; + default: + GuiManager.showMessageBox(me.getShell(), "Internal error!", MessageType.ERROR, null, + null); + break; + } + } else { + postSuccessfulLogin(); + } + } + }; + // now switch over the login types. + Authenticator authenticator; switch (loginType) { case BWIDM: - BWIDMAuthenticator bwidmAuth = new BWIDMAuthenticator( - selectedOrg.getEcpUrl()); - try { - bwidmAuth.login(username, password, new AuthenticatorCallback() { - @Override - public void postLogin(ReturnCode returnCode, UserInfo user) { - // TODO finish this - // handle errors first - if (returnCode != ReturnCode.NO_ERROR && user == null) { - switch(returnCode) { - case IDP_ERROR: - GuiManager.showMessage("IdP Error", SWT.ICON_ERROR); - break; - default: - GuiManager.showMessage("Internal error!", SWT.ICON_ERROR); - break; - } - } else - postSuccessfulLogin(); - } - }); - } catch (TAuthenticationException e) { - //LOGGER.error("Authentication error, see trace: ", e); - GuiManager.showMessage(e.getMessage(), SWT.ICON_ERROR); - return; - } + authenticator = new EcpAuthenticator(selectedOrg.getEcpUrl()); break; case BWLP: - LOGGER.info("bwlp"); - BWLPAuthenticator bwlpAuth = new BWLPAuthenticator(); - try { - bwlpAuth.login(username, password, new AuthenticatorCallback() { - @Override - public void postLogin(ReturnCode returnCode, UserInfo user) { - // handle errors first - if (returnCode != ReturnCode.NO_ERROR && user == null) { - LOGGER.error("BWLP login failed."); - GuiManager.showMessage("Login failed!", SWT.ICON_ERROR); - } - if (returnCode == ReturnCode.NO_ERROR && user != null) - postSuccessfulLogin(); - } - }); - } catch (TAuthenticationException e) { - GuiManager.showMessage(e.getMessage(), SWT.ICON_ERROR); - } + authenticator = new TestAccountAuthenticator(); break; case SAT: - LOGGER.warn("Direct satellite login is not yet supported."); - break; + GuiManager.showMessageBox(this.getShell(), "Not yet implemented", MessageType.ERROR, null, null); + return; default: - LOGGER.error("Unknown login type! Ignoring..."); - break; + GuiManager.showMessageBox(this.getShell(), "No login type selected!", MessageType.ERROR, null, + null); + return; + } + + // Excute login + try { + authenticator.login(username, password, authenticatorCallback); + } catch (TAuthenticationException e) { + GuiManager.showMessageBox(me.getShell(), "Authentication failed: " + e.getMessage(), + MessageType.ERROR, LOGGER, null); + return; } - return; } - + /** * Functions called by doLogin is the login process succeeded. */ private void postSuccessfulLogin() { LOGGER.info(loginType.getTag() + " succeeded."); - + // TODO HACK HACK - ThriftManager.setSatelliteAddress( "132.230.8.113" ); - + ThriftManager.setSatelliteAddress("132.230.8.113"); + // now read the config to see if the user already agreed to the disclaimer if (!Config.getDisclaimerAgreement()) GuiManager.addContent(new DisclaimerWindow(getShell())); @@ -317,9 +307,10 @@ public class LoginWindow extends LoginWindowLayout { GuiManager.addContent(new VirtualizerNoticeWindow(getShell())); // TODO: See MainWindowLayout comments } - + /** - * @return the organization currently selected in the combobox for identity providers + * @return the organization currently selected in the combobox for identity + * providers */ private final Organization getSelectedOrganization() { // get the index of the selected item in the combobox diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java index 89b7e6ba..ad429085 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java @@ -1,24 +1,14 @@ package org.openslx.dozmod.util; -import java.awt.Graphics2D; -import java.awt.SystemColor; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; import java.net.URL; -import javax.swing.ImageIcon; - import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontMetrics; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Text; import org.openslx.dozmod.gui.helper.GuiManager; /** @@ -35,19 +25,19 @@ public class ResourceLoader { public static ImageData getImageData(String path) { - ImageData _imgData = null; - URL _url = ResourceLoader.class.getResource(path); - if (_url == null) { + ImageData imgData = null; + URL url = ResourceLoader.class.getResource(path); + if (url == null) { LOGGER.error("Resource not found: " + path); return errorIcon("nope").getImageData(); } else { try { - _imgData = new ImageData(_url.openStream()); + imgData = new ImageData(url.openStream()); } catch (Exception e) { LOGGER.error("Resource not loadable: " + path + ". See trace: ", e); return errorIcon("nope").getImageData(); } - return _imgData; + return imgData; } } |
