GUIMediator.java

Index Score
com.limegroup.gnutella.gui
FrostWire

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
DECL_COMMENTSComments in declarations
DOC_COMMENTNumber of javadoc comment lines
JAVA0034JAVA0034 Missing braces in if statement
EXITSProcedure exits
COMMENTSComment lines
SIZESize of the file in bytes
FUNCTIONSNumber of function declarations
CYCLOMATICCyclomatic complexity
LINESNumber of lines in the source file
RETURNSNumber of return points from functions
LINE_COMMENTNumber of line comments
INTERFACE_COMPLEXITYInterface complexity
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
JAVA0065JAVA0065 Unnecessary final modifier for method in final class
BLOCKSNumber of blocks
PARAMSNumber of formal parameter declarations
ELOCEffective lines of code
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
LOCLines of code
OPERANDSNumber of operands
LOGICAL_LINESNumber of statements
EXEC_COMMENTSComments in executable code
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0144JAVA0144 Line exceeds maximum M characters
WHITESPACENumber of whitespace lines
COMPARISONSNumber of comparison operators
JAVA0109JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0128JAVA0128 Public constructor in non-public class
JAVA0170JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0166JAVA0166 Generic exception caught
UNIQUE_OPERATORSNumber of unique operators
JAVA0031JAVA0031 Case statement not properly closed
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
NEST_DEPTHMaximum nesting depth
JAVA0150JAVA0150 java.lang.Error (or subclass) thrown
JAVA0130JAVA0130 Non-static method does not use instance fields
JAVA0237JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0008JAVA0008 Empty catch block
JAVA0143JAVA0143 Synchronized method
JAVA0076JAVA0076 Use of magic number
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0032JAVA0032 Switch statement missing default
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0264JAVA0264 Integer math in long context - check for overflow
JAVA0087JAVA0087 Use of Thread.sleep()
JAVA0029JAVA0029 Private method not used
JAVA0145JAVA0145 Tab character used in source file
LOOPSNumber of loops
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
package com.limegroup.gnutella.gui; import java.awt.Component; import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Frame; import java.awt.Point; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; import javax.swing.Action; import javax.swing.Box; import javax.swing.ImageIcon; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPopupMenu; import javax.swing.ListCellRenderer; import javax.swing.SwingUtilities; import org.limewire.concurrent.AbstractLazySingletonProvider; import org.limewire.concurrent.ThreadExecutor; import org.limewire.i18n.I18nMarker; import org.limewire.io.Connectable; import org.limewire.lws.server.LWSConnectionListener; import org.limewire.service.ErrorService; import org.limewire.service.Switch; import org.limewire.setting.BooleanSetting; import org.limewire.setting.IntSetting; import org.limewire.setting.StringSetting; import org.limewire.setting.evt.SettingEvent; import org.limewire.setting.evt.SettingListener; import org.limewire.util.OSUtils; import org.limewire.util.StringUtils; import org.limewire.util.VersionUtils; import com.google.inject.Provider; import com.limegroup.bittorrent.gui.TorrentUploadCanceller; import com.limegroup.gnutella.bugs.FatalBugManager; import com.limegroup.gnutella.chat.InstantMessenger; import com.limegroup.gnutella.gui.actions.AbstractAction; import com.limegroup.gnutella.gui.chat.ChatFrame; import com.limegroup.gnutella.gui.chat.ChatUIManager; import com.limegroup.gnutella.gui.connection.ConnectionMediator; import com.limegroup.gnutella.gui.download.DownloadMediator; import com.limegroup.gnutella.gui.library.LibraryMediator; import com.limegroup.gnutella.gui.mp3.MediaPlayerComponent; import com.limegroup.gnutella.gui.mp3.PlayListItem; import com.limegroup.gnutella.gui.notify.NotifyUserProxy; import com.limegroup.gnutella.gui.options.OptionsMediator; import com.limegroup.gnutella.gui.playlist.PlaylistMediator; import com.limegroup.gnutella.gui.search.SearchMediator; import com.limegroup.gnutella.gui.shell.LimeAssociations; import com.limegroup.gnutella.gui.shell.ShellAssociationManager; import com.limegroup.gnutella.gui.tabs.LibraryPlayListTab; import com.limegroup.gnutella.gui.themes.ThemeMediator; import com.limegroup.gnutella.gui.themes.ThemeSettings; import com.limegroup.gnutella.gui.upload.UploadMediator; import com.frostwire.gnutella.gui.chat.ChatMediator; import com.limegroup.gnutella.settings.ApplicationSettings; import com.limegroup.gnutella.settings.PlayerSettings; import com.limegroup.gnutella.settings.QuestionsHandler; import com.limegroup.gnutella.settings.SWTBrowserSettings; import com.limegroup.gnutella.settings.StartupSettings; import com.limegroup.gnutella.util.LaunchException; import com.limegroup.gnutella.util.Launcher; import com.limegroup.gnutella.util.LimeWireUtils; import com.limegroup.gnutella.util.LogUtils; import com.limegroup.gnutella.version.UpdateInformation; import com.frostwire.gnutella.connectiondoctor.ConnectionDoctor; /** * This class acts as a central point of access for all gui components, a sort * of "hub" for the frontend. This should be the only common class that all * frontend components have access to, reducing the overall dependencies and * therefore increasing the modularity of the code. * * <p>Any functions or services that should be accessible to multiple classes * should be added to this class. These currently include such functions as * easily displaying standardly-formatted messages to the user, obtaining * locale-specific strings, and obtaining image resources, among others. * * <p>All of the methods in this class should be called from the event- * dispatch (Swing) thread. */ //2345678|012345678|012345678|012345678|012345678|012345678|012345678|012345678| public final class GUIMediator { /** * The number of messages a connection must have sent before we consider * it stable for the UI. */ private static final int STABLE_THRESHOLD = 5; /** * Flag for whether or not a message has been displayed to the user -- * useful in deciding whether or not to display other dialogues. */ private static boolean _displayedMessage; /** * Message key for the disconnected message */ private static final String DISCONNECTED_MESSAGE = I18nMarker .marktr("Your machine does not appear to have an active Internet connection or a firewall is blocking FrostWire from accessing the internet. FrostWire will automatically keep trying to connect you to the network unless you select \"Disconnect\" from the File menu."); /** * Singleton for easy access to the mediator. */ private static GUIMediator _instance = null; public static enum Tabs { SEARCH(I18n.tr("&Search")), MONITOR(I18n.tr("&Monitor"), ApplicationSettings.MONITOR_VIEW_ENABLED), CONNECTION(I18n.tr("&Connections"), ApplicationSettings.CONNECTION_VIEW_ENABLED), LIBRARY(I18n.tr("&Library"), ApplicationSettings.LIBRARY_VIEW_ENABLED), CHAT(I18n.tr("Community C&hat"), ApplicationSettings.CHAT_VIEW_ENABLED), CONSOLE(I18n.tr("C&onsole"), ApplicationSettings.CONSOLE_VIEW_ENABLED), LOGGING(I18n.tr("Lo&gging"), ApplicationSettings.LOGGING_VIEW_ENABLED), FROSTCLICK(I18n.tr("FrostClick.com"), ApplicationSettings.SWT_BROWSER_VIEW_ENABLED, "http://www.frostclick.com/?from=frostwire&"); private Action navAction; private String name; private final BooleanSetting visibleSetting; private final PropertyChangeSupport propertyChangeSupport; private Tabs(String name) { this(name, null); } private Tabs(String nameWithAmpers, BooleanSetting visibleSetting) { this.name = GUIUtils.stripAmpersand(nameWithAmpers); navAction = new NavigationAction(nameWithAmpers, I18n.tr("Display the {0} Screen", name)); this.visibleSetting = visibleSetting; this.propertyChangeSupport = new PropertyChangeSupport(this); } private Tabs(StringSetting nameSetting, BooleanSetting visibleSetting) { this(nameSetting.getValue(), visibleSetting); nameSetting.addSettingListener(new SettingListener() { public void settingChanged(final SettingEvent evt) { if(evt.getEventType() == SettingEvent.EventType.VALUE_CHANGED) { SwingUtilities.invokeLater(new Runnable() { public void run() { setName(evt.getSetting().getValueAsString()); } }); } } }); } private Tabs(String nameWithAmpers, BooleanSetting visibleSetting, String url) { this(nameWithAmpers, visibleSetting); this.navAction=new BrowseAction(nameWithAmpers, url); } void setName(String newName) { String oldName = name; this.name = GUIUtils.stripAmpersand(newName); navAction.putValue(Action.NAME, newName); navAction.putValue(Action.LONG_DESCRIPTION, I18n.tr("Display the {0} Screen", name)); propertyChangeSupport.firePropertyChange("name", oldName, name); } void setEnabled(boolean enabled) { navAction.setEnabled(enabled); } public Action getNavigationAction() { return navAction; } public boolean isViewEnabled() { if (visibleSetting == null) { throw new IllegalStateException("Should not be called on " + getName() + " which is a non-optional tab"); } return visibleSetting.getValue(); } public String getName() { return name; } private class NavigationAction extends AbstractAction { public NavigationAction(String name, String description) { super(name); putValue(Action.LONG_DESCRIPTION, description); } public void actionPerformed(ActionEvent e) { instance().setWindow(Tabs.this); } } /** The tabs are also used on the View Menu, sometimes, you don't need to add a tab, but instead point to a website when the user wants to view the action shown on the menu, in this case, we use a BrowseAction. A BrowseAction will be used with the Third Tab enum constructor, which takes an url as the third parameter. */ private class BrowseAction extends AbstractAction { private String url; public BrowseAction (String name, String url) { super(name); this.url = url; } public void actionPerformed(ActionEvent e) { byte[] guid = GuiCoreMediator.getApplicationServices().getMyGUID(); GUIMediator.openURL(LimeWireUtils.addLWInfoToUrl(this.url,guid)); } } /** * Returns the */ public static Tabs[] getOptionalTabs() { if (LogUtils.isLog4JAvailable()) { if( isBrowserCapable()) return new Tabs[] { MONITOR, CONNECTION, LIBRARY, CONSOLE, LOGGING, CHAT, FROSTCLICK }; else return new Tabs[] { MONITOR, CONNECTION, LIBRARY, CONSOLE, LOGGING, CHAT }; } else { if( isBrowserCapable()) return new Tabs[] { MONITOR, CONNECTION, LIBRARY, LOGGING, CHAT, FROSTCLICK }; else return new Tabs[] { MONITOR, CONNECTION, LIBRARY, LOGGING, CHAT }; } } public void addPropertyChangeListener(PropertyChangeListener listener) { propertyChangeSupport.addPropertyChangeListener(listener); } } /** * Return true if the web browser can safely launch on the OS */ public static boolean isBrowserCapable() { return OSUtils.isWindows(); } /** * Constant specifying whether or not the user has donated to the Frosty * project. */ private static boolean HAS_DONATED = true; /** * The main <tt>JFrame</tt> for the application. */ private static final JFrame FRAME = new LimeJFrame(); /** * The popup menu on the icon in the sytem tray. */ private static final JPopupMenu TRAY_MENU = new TrayPopupMenu(); /** * <tt>List</tt> of <tt>RefreshListener</tt> classes to notify of UI * refresh events. */ private static final List<RefreshListener> REFRESH_LIST = new ArrayList<RefreshListener>(); /** * String to be displayed in title bar of LW client. */ private final String APP_TITLE = I18n.tr("FrostWire: Share it with your friends"); /** * Handle to the <tt>OptionsMediator</tt> class that is responsible for * displaying customizable options to the user. */ private static OptionsMediator _optionsMediator; /** * The shell association manager. */ private static final Provider<ShellAssociationManager> ASSOCIATION_MANAGER = new AbstractLazySingletonProvider<ShellAssociationManager>() { @Override protected ShellAssociationManager createObject() { return new ShellAssociationManager(LimeAssociations.getSupportedAssociations()); } }; /** * Constant handle to the <tt>MainFrame</tt> instance that handles * constructing all of the primary gui components. */ private final MainFrame MAIN_FRAME = new MainFrame(FRAME); /** * Constant handle to the <tt>DownloadMediator</tt> class that is * responsible for displaying active downloads to the user. */ private final DownloadMediator DOWNLOAD_MEDIATOR = MAIN_FRAME.getDownloadMediator(); /** * Constant handle to the <tt>UploadMediator</tt> class that is * responsible for displaying active uploads to the user. */ private final UploadMediator UPLOAD_MEDIATOR = MAIN_FRAME.getUploadMediator(); /** * Constant handle to the <tt>ConnectionMediator</tt> class that is * responsible for displaying current connections to the user. */ private final ConnectionMediator CONNECTION_MEDIATOR = MAIN_FRAME.getConnectionMediator(); /** * Constant handle to the <tt>LibraryMediator</tt> class that is * responsible for displaying files in the user's repository. */ private final LibraryMediator LIBRARY_MEDIATOR = MAIN_FRAME.getLibraryMediator(); /** * Constant handle to the <tt>ChatMediator</tt> class that is * responsible for displaying the user chat. */ private final ChatMediator CHAT_MEDIATOR = MAIN_FRAME.getChatMediator(); /** * Constant handle to the <tt>DownloadView</tt> class that is responsible * for displaying the status of the network and connectivity to the user. */ private final StatusLine STATUS_LINE = MAIN_FRAME.getStatusLine(); /** * Flag for whether or not the app has ever been made visible during this * session. */ private static boolean _visibleOnce = false; /** * Flag for whether or not the app is allowed to become visible. */ private static boolean _allowVisible = false; /** * The last recorded idle time. */ private long lastIdleTime = 0; /** * Private constructor to ensure that this class cannot be constructed * from another class. */ private GUIMediator() { FRAME.setTitle(APP_TITLE); _optionsMediator = MAIN_FRAME.getOptionsMediator(); } /** * Singleton accessor for this class. * * @return the <tt>GUIMediator</tt> instance */ public static synchronized GUIMediator instance() { if (_instance == null) _instance = new GUIMediator(); return _instance; } /** * Accessor for whether or not the GUIMediator has been constructed yet. */ public static boolean isConstructed() { return _instance != null; } /** * Notification that the the core has been initialized. */ public void coreInitialized() { startTimer(); createEventListeners(); new ConnectionDoctor().initialize(); // Initialize the Connection Doctor timer } private final void startTimer() { RefreshTimer timer = new RefreshTimer(); timer.startTimer(); } private void createEventListeners() { GuiCoreMediator.getLWSManager().addConnectionListener(new LWSConnectionListener() { public void connectionChanged(boolean isConnected) { GUIMediator.instance().getStatusLine().updateLWSLabel(!isConnected); } }); TorrentUploadCanceller.createAndRegister(GuiCoreMediator.getTorrentManager()); } /** * Returns a boolean specifying whether or not the wrapped * <tt>JFrame</tt> is visible or not. * * @return <tt>true</tt> if the <tt>JFrame</tt> is visible, * <tt>false</tt> otherwise */ public static final boolean isAppVisible() { return FRAME.isShowing(); } /** * Specifies whether or not the main application window should be visible * or not. * * @param visible specifies whether or not the application should be * made visible or not */ public static final void setAppVisible(final boolean visible) { safeInvokeLater(new Runnable() { public void run() { try { if (visible) FRAME.toFront(); FRAME.setVisible(visible); } catch (NullPointerException npe) { // NPE being thrown on WinXP sometimes. First try // reverting to the limewire theme. If NPE still // thrown, tell user to change LimeWire's Windows // compatibility mode to Win2k. // null pointer found // Update: no idea if the NPE also happens on vista, use the workaround // just in case. if (OSUtils.isNativeThemeWindows()) { try { if (ThemeSettings.isWindowsTheme()) { ThemeMediator.changeTheme(ThemeSettings.FROSTWIRE_THEME_FILE); try { if (visible) FRAME.toFront(); FRAME.setVisible(visible); } catch (NullPointerException npe2) { GUIMediator.showError(I18n.tr("FrostWire has encountered a problem during startup and cannot proceed. You may be able to fix this problem by changing FrostWire\'s Windows Compatibility. Right-click on the FrostWire icon on your Desktop and select \'Properties\' from the popup menu. Click the \'Compatibility\' tab at the top, then click the \'Run this program in compatibility mode for\' check box, and then select \'Windows 2000\' in the box below the check box. Then click the \'OK\' button at the bottom and restart FrostWire.")); System.exit(0); } } else { GUIMediator.showError(I18n.tr("FrostWire has encountered a problem during startup and cannot proceed. You may be able to fix this problem by changing FrostWire\'s Windows Compatibility. Right-click on the FrostWire icon on your Desktop and select \'Properties\' from the popup menu. Click the \'Compatibility\' tab at the top, then click the \'Run this program in compatibility mode for\' check box, and then select \'Windows 2000\' in the box below the check box. Then click the \'OK\' button at the bottom and restart FrostWire.")); System.exit(0); } } catch (Throwable t) { if (visible) FatalBugManager.handleFatalBug(npe); else ErrorService.error(npe); } } else { if (visible) FatalBugManager.handleFatalBug(npe); else ErrorService.error(npe); } } catch(Throwable t) { if (visible) FatalBugManager.handleFatalBug(t); else ErrorService.error(t); } if (visible) { SearchMediator.requestSearchFocus(); // forcibily revalidate the FRAME // after making it visible. // on Java 1.5, it does not validate correctly. SwingUtilities.invokeLater(new Runnable() { public void run() { FRAME.getContentPane().invalidate(); FRAME.getContentPane().validate(); } }); } // If the app has already been made visible, don't display extra // dialogs. We could display the pro dialog here, but it causes // some odd issues when LimeWire is brought back up from the tray if (visible && !_visibleOnce) { // Show the startup dialogs in the swing thread. showDialogsForFirstVisibility(); _visibleOnce = true; } } }); } /** * Displays various dialog boxes that should only be shown the first * time the application is made visible. */ private static final void showDialogsForFirstVisibility() { if (_displayedMessage) return; _displayedMessage = true; getAssociationManager().checkAndGrab(true); if (!hasDonated()) UpgradeWindow.showProDialog(); if (TipOfTheDayMessages.hasLocalizedMessages() && StartupSettings.SHOW_TOTD.getValue()) { // Construct it first... TipOfTheDayMediator.instance(); ThreadExecutor.startThread(new Runnable() { public void run() { try { Thread.sleep(500); } catch (InterruptedException ignored) { } SwingUtilities.invokeLater(new Runnable() { public void run() { TipOfTheDayMediator.instance().displayTipWindow(); } }); } }, "TOTD"); } JDialog dialog = JavaVersionNotice.getUpgradeRecommendedDialog(VersionUtils.getJavaVersion()); if (dialog != null) { dialog.setVisible(true); } } /** * Displays a dialog the first time a user performs a download. * Returns true iff the user selects 'Yes'; returns false otherwise. */ /* public static boolean showFirstDownloadDialog() { if (DialogOption.YES == showYesNoCancelMessage(I18n.tr("FrostWire is unable to find a license for this file. Download the file anyway?\n\nPlease note: FrostWire cannot monitor or control the content of the Gnutella network. Please respect your local copyright laws."), QuestionsHandler.SKIP_FIRST_DOWNLOAD_WARNING)) return true; return false; } */ /** * Closes any dialogues that are displayed at startup and sets the flag to * indicate that we've displayed a message. */ public static void closeStartupDialogs() { if(SplashWindow.instance().isShowing()) SplashWindow.instance().toBack(); if(TipOfTheDayMediator.isConstructed()) TipOfTheDayMediator.instance().hide(); } /** * Returns a <tt>Dimension</tt> instance containing the dimensions of the * wrapped JFrame. * * @return a <tt>Dimension</tt> instance containing the width and height * of the wrapped JFrame */ public static final Dimension getAppSize() { return FRAME.getSize(); } /** * Returns a <tt>Point</tt> instance containing the x, y position of the * wrapped <ttJFrame</tt> on the screen. * * @return a <tt>Point</tt> instance containting the x, y position of the * wrapped JFrame */ public static final Point getAppLocation() { return FRAME.getLocation(); } /** * Returns the <tt>MainFrame</tt> instance. <tt>MainFrame</tt> maintains * handles to all of the major gui classes. * * @return the <tt>MainFrame</tt> instance */ public final MainFrame getMainFrame() { return MAIN_FRAME; } /** * Returns the main application <tt>JFrame</tt> instance. * * @return the main application <tt>JFrame</tt> instance */ public static final JFrame getAppFrame() { return FRAME; } /** * Returns the popup menu on the icon in the system tray. * * @return The tray popup menu */ public static final JPopupMenu getTrayMenu() { return TRAY_MENU; } /** * Returns the status line instance for other classes to access */ public StatusLine getStatusLine() { return STATUS_LINE; } /** * Refreshes the various gui components that require refreshing. */ public final void refreshGUI() { for (int i = 0; i < REFRESH_LIST.size(); i++) { try { REFRESH_LIST.get(i).refresh(); } catch(Throwable t) { // Show the error for each RefreshListener individually // so that we continue refreshing the other items. ErrorService.error(t); } } // update the status panel int sharedFiles = GuiCoreMediator.getFileManager().getNumFiles(); int pendingShare = GuiCoreMediator.getFileManager().getNumPendingFiles(); int quality = getConnectionQuality(); STATUS_LINE.setStatistics(sharedFiles, pendingShare); if(quality != StatusLine.STATUS_DISCONNECTED && quality != StatusLine.STATUS_CONNECTING) { hideDisposableMessage(DISCONNECTED_MESSAGE); } updateConnectionUI(quality); } /** * Returns the connectiong quality. */ public int getConnectionQuality() { int stable = GuiCoreMediator.getConnectionServices().countConnectionsWithNMessages(STABLE_THRESHOLD); int status; if(stable == 0) { int initializing = CONNECTION_MEDIATOR.getConnectingCount(); int connections = GuiCoreMediator.getConnectionServices().getNumInitializedConnections(); // No initializing or stable connections if(initializing == 0 && connections == 0) { //Not attempting to connect at all... if(!GuiCoreMediator.getConnectionServices().isConnecting()) status = StatusLine.STATUS_DISCONNECTED; //Attempting to connect... else status = StatusLine.STATUS_CONNECTING; } // No initialized, all initializing - connecting else if(connections == 0) status = StatusLine.STATUS_CONNECTING; // Some initialized - poor connection. else status = StatusLine.STATUS_POOR; } else if(GuiCoreMediator.getConnectionManager().isConnectionIdle()) { lastIdleTime = System.currentTimeMillis(); status = StatusLine.STATUS_IDLE; } else { int preferred = GuiCoreMediator.getConnectionManager(). getPreferredConnectionCount(); // pro will have more. if(LimeWireUtils.isPro()) preferred -= 2; // ultrapeers don't need as many... if(GuiCoreMediator.getConnectionServices().isSupernode()) preferred -= 5; preferred = Math.max(1, preferred); // prevent div by 0 double percent = (double)stable / (double)preferred; if(percent <= 0.25) status = StatusLine.STATUS_POOR; else if(percent <= 0.5) status = StatusLine.STATUS_FAIR; else if(percent <= 0.75) status = StatusLine.STATUS_GOOD; else if(percent <= 1) status = StatusLine.STATUS_EXCELLENT; else /* if(percent > 1) */ status = StatusLine.STATUS_TURBOCHARGED; } switch(status) { case StatusLine.STATUS_CONNECTING: case StatusLine.STATUS_POOR: case StatusLine.STATUS_FAIR: case StatusLine.STATUS_GOOD: // if one of these four, see if we recently woke up from // idle, and if so, report as 'waking up' instead. long now = System.currentTimeMillis(); if(now < lastIdleTime + 15 * 1000) status = StatusLine.STATUS_WAKING_UP; } return status; } /** * Sets the visibility state of the options window. * * @param visible the visibility state to set the window to */ public void setOptionsVisible(boolean visible) { if (_optionsMediator == null) return; _optionsMediator.setOptionsVisible(visible); } /** * Sets the visibility state of the options window, and sets * the selection to a option pane associated with a given key. * * @param visible the visibility state to set the window to * @param key the unique identifying key of the panel to show */ public void setOptionsVisible(boolean visible, final String key) { if (_optionsMediator == null) return; _optionsMediator.setOptionsVisible(visible, key); } /** * Returns whether or not the options window is visible * * @return <tt>true</tt> if the options window is visible, * <tt>false</tt> otherwise */ public static boolean isOptionsVisible() { if (_optionsMediator == null) return false; return _optionsMediator.isOptionsVisible(); } /** * Gets a handle to the options window main <tt>JComponent</tt> instance. * * @return the options window main <tt>JComponent</tt>, or <tt>null</tt> * if the options window has not yet been constructed (the window is * guaranteed to be constructed if it is visible) */ public static Component getMainOptionsComponent() { if (_optionsMediator == null) return null; return _optionsMediator.getMainOptionsComponent(); } /** * @return the <tt>ShellAssociationManager</tt> instance. */ public static ShellAssociationManager getAssociationManager() { return ASSOCIATION_MANAGER.get(); } /** * Sets the tab pane to display the given tab. * * @param index the index of the tab to display */ public void setWindow(GUIMediator.Tabs tab) { MAIN_FRAME.setSelectedTab(tab); } /** * Updates the icon at the specified tab index. * * @param index the fixed index of the tab to update */ public void updateTabIcon(GUIMediator.Tabs tab) { MAIN_FRAME.updateTabIcon(tab); } /** * Clear the connections in the connection view. */ public void clearConnections() { CONNECTION_MEDIATOR.clearConnections(); } /** * Sets the connected/disconnected visual status of the client. * * @param connected the connected/disconnected status of the client */ private void updateConnectionUI(int quality) { STATUS_LINE.setConnectionQuality(quality); boolean connected = quality != StatusLine.STATUS_DISCONNECTED; if (!connected) this.setSearching(false); } /** * Returns the total number of uploads for this session. * * @return the total number of uploads for this session */ public int getTotalUploads() { return UPLOAD_MEDIATOR.getTotalUploads(); } /** * Returns the total number of currently active uploads. * * @return the total number of currently active uploads */ public int getCurrentUploads() { return UPLOAD_MEDIATOR.getCurrentUploads(); } /** * Returns the total number of downloads for this session. * * @return the total number of downloads for this session */ public final int getTotalDownloads() { return DOWNLOAD_MEDIATOR.getTotalDownloads(); } /** * Returns the total number of currently active downloads. * * @return the total number of currently active downloads */ public final int getCurrentDownloads() { return DOWNLOAD_MEDIATOR.getCurrentDownloads(); } public final void openTorrent(File torrentFile) { DOWNLOAD_MEDIATOR.openTorrent(torrentFile); setWindow(GUIMediator.Tabs.SEARCH); } public final void openTorrentURI(URI torrentURI) { DOWNLOAD_MEDIATOR.openTorrentURI(torrentURI); setWindow(GUIMediator.Tabs.SEARCH); } /** * Tells the library to add a new top-level (shared) folder. */ public final void addSharedLibraryFolder() { LIBRARY_MEDIATOR.addSharedLibraryFolder(); } /** * Returns the active playlist or <code>null</code> if the playlist * is not enabled. */ public static PlaylistMediator getPlayList() { return MainFrame.getPlaylistMediator(); } /** * Determines whether or not the PlaylistMediator is being used this session. */ public static boolean isPlaylistVisible() { // If we are not constructed yet, then make our best guess as // to visibility. It is actually VERY VERY important that this // returns the same thing throughout the entire course of the program, // otherwise exceptions can pop up. if(!isConstructed()) return PlayerSettings.PLAYER_ENABLED.getValue(); else return getPlayList() != null && PlayerSettings.PLAYER_ENABLED.getValue(); } /** * Runs the appropriate methods to start LimeWire up * hidden. */ public static void startupHidden() { // sends us to the system tray on windows, ignored otherwise. GUIMediator.showTrayIcon(); // If on OSX, we must set the framestate appropriately. if(OSUtils.isMacOSX()) GUIMediator.hideView(); } /** * Notification that visibility is now allowed. */ public static void allowVisibility() { if(!_allowVisible && OSUtils.isAnyMac()) MacEventHandler.instance().enablePreferences(); _allowVisible = true; } /** * Notification that loading is finished. Updates the status line and * bumps the AWT thread priority. */ public void loadFinished() { SwingUtilities.invokeLater(new Runnable() { public void run() { Thread awt = Thread.currentThread(); awt.setPriority(awt.getPriority() + 1); STATUS_LINE.loadFinished(); } }); } /** * Handles a 'reopen' event appropriately. * Used primarily for allowing LimeWire to be made * visible after it was started from system startup * on OSX. */ public static void handleReopen() { // Do not do anything // if visibility is not allowed yet, as initialization // is not yet finished. if(_allowVisible) { if(!_visibleOnce) restoreView(); // First make sure it's not minimized setAppVisible(true); // Then make it visible // Otherwise (if the above operations were reversed), a tiny // LimeWire icon would appear in the 'minimized' area of the dock // for a split second, and the Console would report strange errors } } /** * Hides the GUI by either sending it to the System Tray or * minimizing the window. Mimimize behavior occurs on platforms * which do not support the System Tray. * @see restoreView */ public static void hideView() { FRAME.setState(Frame.ICONIFIED); if (OSUtils.supportsTray() && ResourceManager.instance().isTrayIconAvailable()) GUIMediator.setAppVisible(false); } /** * Makes the GUI visible by either restoring it from the System Tray or * the task bar. * @see hideView */ public static void restoreView() { // Frame must be visible for setState to work. Make visible // before restoring. if (OSUtils.supportsTray() && ResourceManager.instance().isTrayIconAvailable()) { // below is a little hack to get around odd windowing // behavior with the system tray on windows. This enables // us to get LimeWire to the foreground after it's run from // the startup folder with all the nice little animations // that we want // cache whether or not to use our little hack, since setAppVisible // changes the value of _visibleOnce boolean doHack = false; if (!_visibleOnce) doHack = true; GUIMediator.setAppVisible(true); if (ApplicationSettings.DISPLAY_TRAY_ICON.getValue()) GUIMediator.showTrayIcon(); else GUIMediator.hideTrayIcon(); if (doHack) restoreView(); } // If shutdown sequence was initiated, cancel it. Auto shutdown is // disabled when the GUI is visible. Finalizer.cancelShutdown(); FRAME.setState(Frame.NORMAL); } /** * Determines the appropriate shutdown behavior based on user settings. * This implementation decides between exiting the application immediately, * or exiting after all file transfers in progress are complete. */ public static void close(boolean fromFrame) { if (ApplicationSettings.MINIMIZE_TO_TRAY.getValue()) { // if we want to minimize to the tray, but LimeWire wasn't // able to load the tray library, then shutdown after transfers. if(OSUtils.supportsTray() && !ResourceManager.instance().isTrayIconAvailable()) shutdownAfterTransfers(); else { applyWindowSettings(); GUIMediator.showTrayIcon(); hideView(); } } else if (OSUtils.isMacOSX() && fromFrame) { //If on OSX, don't close in response to clicking on the 'X' //as that's not normal behaviour. This can only be done on Java14 //though, because we need access to the //com.apple.eawt.ApplicationListener.handleReOpenApplication event //in order to restore the GUI. GUIMediator.setAppVisible(false); } else if (ApplicationSettings.SHUTDOWN_AFTER_TRANSFERS.getValue()) { GUIMediator.shutdownAfterTransfers(); } else { shutdown(); } } /** * Shutdown the program cleanly. */ public static void shutdown() { Finalizer.shutdown(); } /** * Shutdown the program cleanly after all transfers in progress are * complete. Calling this method causes the GUI to be hidden while the * application waits to shutdown. * @see hideView */ public static void shutdownAfterTransfers() { Finalizer.shutdownAfterTransfers(); GUIMediator.hideView(); } public static void flagUpdate(String toExecute) { Finalizer.flagUpdate(toExecute); } /** * Shows the "About" menu with more information about the program. */ public static final void showAboutWindow() { new AboutWindow().showDialog(); } /** * Shows the user notification area. The user notification icon and * tooltip created by the NotifyUser object are not modified. */ public static void showTrayIcon() { NotifyUserProxy.instance().showTrayIcon(); } /** * Hides the user notification area. */ public static void hideTrayIcon() { // Do not use hideNotify() here, since that will // create multiple tray icons. NotifyUserProxy.instance().hideTrayIcon(); } /** * Sets the window height, width and location properties to remember the * next time the program is started. */ public static void applyWindowSettings() { ApplicationSettings.RUN_ONCE.setValue(true); if (GUIMediator.isAppVisible()) { if((GUIMediator.getAppFrame().getExtendedState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH) { ApplicationSettings.MAXIMIZE_WINDOW.setValue(true); } else { // set the screen size and location for the // next time the application is run. Dimension dim = GUIMediator.getAppSize(); // only save reasonable sizes to get around a bug on // OS X that could make the window permanently // invisible if((dim.height > 100) && (dim.width > 100)) { Point loc = GUIMediator.getAppLocation(); ApplicationSettings.APP_WIDTH.setValue(dim.width); ApplicationSettings.APP_HEIGHT.setValue(dim.height); ApplicationSettings.WINDOW_X.setValue(loc.x); ApplicationSettings.WINDOW_Y.setValue(loc.y); } } } } /** * Serves as a single point of access for any icons used in the program. * * @param imageName the name of the icon to return without path * information, as in "plug" * @return the <tt>ImageIcon</tt> object specified in the param string */ public static final ImageIcon getThemeImage(final String name) { return ResourceManager.getThemeImage(name); } /** * Returns an ImageIcon for the specified resource. */ public static final ImageIcon getImageFromResourcePath(final String loc) { return ResourceManager.getImageFromResourcePath(loc); } /** * Returns a new <tt>URL</tt> instance for the specified file name. * The file must be located in the org/limewire/gui/resources * directory, or this will return <tt>null</tt>. * * @param FILE_NAME the name of the file to return a url for without path * information, as in "about.html" * @return the <tt>URL</tt> instance for the specified file, or * <tt>null</tt> if the <tt>URL</tt> could not be loaded */ public static URL getURLResource(final String FILE_NAME) { return ResourceManager.getURLResource(FILE_NAME); } /** * Resets locale options. */ public static void resetLocale() { ResourceManager.resetLocaleOptions(); GUIUtils.resetLocale(); } /** * Return ResourceBundle for use with specific xml schema * * @param schemaname the name of schema * (not the URI but name returned by LimeXMLSchema.getDisplayString) * @return a ResourceBundle matching the passed in param */ public static final ResourceBundle getXMLResourceBundle(final String schemaname) { return ResourceManager.getXMLResourceBundle(schemaname); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific question message to the user with an input field<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the locale-specific message to display * @param initialValue the initial input value * @return a String containing the user input */ public static final String showInputMessage( final String message, String initialValue) { return MessageService.instance().showInputMessage( message, initialValue); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific message to the user in the form of a yes or no * question.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the locale-specific message to display * @return an integer indicating a yes or a no response from the user */ public static final DialogOption showYesNoMessage( final String message, final DialogOption defaultOption) { return MessageService.instance().showYesNoMessage( message, defaultOption); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific message to the user in the form of a yes or no * question.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the locale-specific message to display * @param defaultValue the IntSetting to store/retrieve the default value * @return an integer indicating a yes or a no response from the user */ public static final DialogOption showYesNoMessage( final String message, final IntSetting defaultValue, final DialogOption defaultOption) { return MessageService.instance().showYesNoMessage( message, defaultValue, defaultOption); } public static final DialogOption showYesNoTitledMessage( final String message, final String title, final DialogOption defaultOption) { return MessageService.instance().showYesNoMessage( message, title, defaultOption); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific message to the user. Below a non-selectable list is * shown. This is in the form of a yes or no or cancel question.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the locale-specific message to display * @param listModel the array of object to be displayed in the list * @param messageType either {@link JOptionPane#YES_NO_OPTION}, * {@link JOptionPane#YES_NO_CANCEL_OPTION} or {@link JOptionPane#OK_CANCEL_OPTION}. * @param listRenderer optional list cell rendere, can be <code>null</code> * * @return an integer indicating a yes or a no or cancel response * from the user, see {@link JOptionPane#showConfirmDialog(Component, Object, String, int)} */ public static final int showConfirmListMessage(final String message, final Object[] listModel, int messageType, final ListCellRenderer listRenderer) { return MessageService.instance().showConfirmListMessage( message, listModel, messageType, listRenderer); } /** * Displays a locale-specific message to the user in the form of a * yes/no/{other} question.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the locale-specific message to display * @param defaultValue the IntSetting to store/retrieve the default value * @param otherOptions the name of the other option * @return an integer indicating a yes or a no response from the user */ public static final DialogOption showYesNoOtherMessage( final String message, final IntSetting defaultValue, String otherOptions) { return MessageService.instance().showYesNoOtherMessage( message, defaultValue, otherOptions); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific message to the user in the form of a yes or no or cancel * question.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the locale-specific message to display * @return an integer indicating a yes or a no response from the user */ public static final DialogOption showYesNoCancelMessage( final String message) { return MessageService.instance().showYesNoCancelMessage( message); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific message to the user in the form of a yes or no or cancel * question.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message for the locale-specific message to display * @param defaultValue the IntSetting to store/retrieve the default value * @return an integer indicating a yes or a no response from the user */ public static final DialogOption showYesNoCancelMessage( final String message, final IntSetting defaultValue) { return MessageService.instance().showYesNoCancelMessage( message, defaultValue); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific message to the user.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param messageKey the key for the locale-specific message to display */ public static final void showMessage( final String messageKey) { MessageService.instance().showMessage(messageKey); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific message to the user.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the locale-specific message to display * @param ignore the BooleanSetting that stores/retrieves whether or * not to display this message. */ public static final void showMessage( final String message, final Switch ignore) { MessageService.instance().showMessage(message, ignore); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific disposable message to the user.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param messageKey the key for the locale-specific message to display * @param ignore the BooleanSetting that stores/retrieves whether or * not to display this message. * @param msgType The <tt>JOptionPane</tt> message type. @see javax.swing.JOptionPane. * @param msgTitle The title of the message window. */ public static final void showDisposableMessage( final String messageKey, final String message, final Switch ignore, int msgType) { MessageService.instance().showDisposableMessage( messageKey, message, ignore, msgType); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Hides a * locale-specific disposable message.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param messageKey the key for the locale-specific message to display */ public static final void hideDisposableMessage( final String messageKey) { MessageService.instance().hideDisposableMessage( messageKey); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * confirmation message to the user.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the locale-specific message to display */ public static final void showConfirmMessage( final String message) { MessageService.instance().showConfirmMessage( message); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * confirmation message to the user.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the locale-specific message to display * @param ignore the BooleanSetting for that stores/retrieves whether * or not to display this message. */ public static final void showConfirmMessage( final String message, final Switch ignore) { MessageService.instance().showConfirmMessage( message, ignore); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific message to the user.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the locale-specific message to display. */ public static final void showError( final String message) { closeStartupDialogs(); MessageService.instance().showError(message); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific message to the user.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the key for the locale-specific message to display. * @param ignore the BooleanSetting for that stores/retrieves whether * or not to display this message. */ public static final void showError( final String message, final Switch ignore) { closeStartupDialogs(); MessageService.instance().showError( message, ignore); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific warning message to the user.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the locale-specific message to display. * @param ignore the BooleanSetting for that stores/retrieves whether * or not to display this message. */ public static final void showWarning( final String message, final Switch ignore) { closeStartupDialogs(); MessageService.instance().showWarning( message, ignore); } /** * Acts as a proxy for the <tt>MessageService</tt> class. Displays a * locale-specific warning message to the user.<p> * * The <tt>messageKey</tt> parameter must be the key for a locale- * specific message <tt>String</tt> and not a hard-coded value. * * @param message the locale-specific message to display. */ public static final void showWarning(final String message) { closeStartupDialogs(); MessageService.instance().showWarning(message); } /** * Acts as a proxy for the Launcher class so that other classes only need * to know about this mediator class. * * <p>Opens the specified url in a browser. * * @param url the url to open * @return an int indicating the success of the browser launch */ public static final int openURL(String url) { try { return Launcher.openURL(url); } catch(IOException ioe) { GUIMediator.showError(I18n.tr("FrostWire could not locate your web browser to display the following webpage: {0}.", url)); return -1; } } /** * Acts as a proxy for the Launcher class so that other classes only need * to know about this mediator class. * * <p>Launches the file specified in its associated application. * * @param file a <tt>File</tt> instance denoting the abstract pathname * of the file to launch * @throws IOException if the file cannot be launched do to an IO problem */ public static final void launchFile(File file) { try { Launcher.launchFile(file); } catch (SecurityException se) { showError(I18n.tr("FrostWire will not launch the specified file for security reasons.")); } catch (LaunchException e) { GUIMediator.showError(I18n.tr("FrostWire could not launch the specified file.\n\nExecuted command: {0}.", StringUtils.explode(e.getCommand(), " "))); } catch (IOException e) { showError(I18n.tr("FrostWire could not launch the specified file.")); } } /** * Acts as a proxy for the Launcher class so that other classes only need * to know about this mediator class. * * <p>Opens <tt>file</tt> in a platform specific file manager. * * @param file a <tt>File</tt> instance denoting the abstract pathname * of the file to launch * @throws IOException if the file cannot be launched do to an IO problem */ public static final void launchExplorer(File file) { try { Launcher.launchExplorer(file); } catch (SecurityException e) { showError(I18n.tr("FrostWire will not launch the specified file for security reasons.")); } catch (LaunchException e) { GUIMediator.showError(I18n.tr("FrostWire could not launch the specified file.\n\nExecuted command: {0}.", StringUtils.explode(e.getCommand(), " "))); } catch (IOException e) { showError(I18n.tr("FrostWire could not launch the specified file.")); } } /** * Returns a <tt>Component</tt> standardly sized for horizontal separators. * * @return the constant <tt>Component</tt> used as a standard horizontal * separator */ public static final Component getHorizontalSeparator() { return Box.createRigidArea(new Dimension(6,0)); } /** * Returns a <tt>Component</tt> standardly sized for vertical separators. * * @return the constant <tt>Component</tt> used as a standard vertical * separator */ public static final Component getVerticalSeparator() { return Box.createRigidArea(new Dimension(0,6)); } /** * Connects the user from the network. */ public void connect() { GuiCoreMediator.getConnectionServices().connect(); GuiCoreMediator.getDHTManager().setEnabled(true); } /** * Disconnects the user to the network. */ public void disconnect() { GuiCoreMediator.getConnectionServices().disconnect(); GuiCoreMediator.getDHTManager().setEnabled(false); } /** * Notifies the user that LimeWire is disconnected */ public static void disconnected() { showDisposableMessage( DISCONNECTED_MESSAGE, I18n.tr("Your machine does not appear to have an active Internet connection or a firewall is blocking FrostWire from accessing the internet. FrostWire will automatically keep trying to connect you to the network unless you select \"Disconnect\" from the File menu."), QuestionsHandler.NO_INTERNET_RETRYING, JOptionPane.ERROR_MESSAGE); } /** * Returns a <tt>boolean</tt> specifying whether or not the user has * donated to the LimeWire project. * * @return <tt>true</tt> if the user has donated, <tt>false</tt> otherwise */ public static boolean hasDonated() { return HAS_DONATED; } /** * Sets the visible/invisible state of the tab. * * @param tab the tab to make visible or invisible * @param visible the visible/invisible state to set the tab to */ public void setTabVisible(GUIMediator.Tabs tab, boolean visible) { MAIN_FRAME.setTabVisible(tab, visible); } /** * Modifies the text displayed to the user in the splash screen to * provide application loading information. * * @param text the text to display */ public static void setSplashScreenString(String text) { if(!_allowVisible) SplashWindow.instance().setStatusText(text); else if(isConstructed()) instance().STATUS_LINE.setStatusText(text); } /** * Returns the point for the placing the specified component on the * center of the screen. * * @param comp the <tt>Component</tt> to use for getting the relative * center point * @return the <tt>Point</tt> for centering the specified * <tt>Component</tt> on the screen */ public static Point getScreenCenterPoint(Component comp) { final Dimension COMPONENT_DIMENSION = comp.getSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int appWidth = Math.min(screenSize.width, COMPONENT_DIMENSION.width); // compare against a little bit less than the screen size, // as the screen size includes the taskbar int appHeight = Math.min(screenSize.height - 40, COMPONENT_DIMENSION.height); return new Point((screenSize.width - appWidth) / 2, (screenSize.height - appHeight) / 2); } /** * Adds the <tt>FinalizeListener</tt> class to the list of classes that * should be notified of finalize events. * * @param fin the <tt>FinalizeListener</tt> class that should be notified */ public static void addFinalizeListener(FinalizeListener fin) { Finalizer.addFinalizeListener(fin); } /** * Sets the searching or not searching status of the application. * * @param searching the searching status of the application */ public void setSearching(boolean searching) { MAIN_FRAME.setSearching(searching); } /** * Adds the specified <tt>RefreshListener</tt> instance to the list of * listeners to be notified when a UI refresh event occurs. * * @param the new <tt>RefreshListener</tt> to add */ public static void addRefreshListener(RefreshListener listener) { if (!REFRESH_LIST.contains(listener)) REFRESH_LIST.add(listener); } /** * Removes the specified <tt>RefreshListener</tt> instance from the list * of listeners to be notified when a UI refresh event occurs. * * @param the <tt>RefreshListener</tt> to remove */ public static void removeRefreshListener(RefreshListener listener) { REFRESH_LIST.remove(listener); } /** * Returns the <tt>Locale</tt> instance currently in use. * * @return the <tt>Locale</tt> instance currently in use */ public static Locale getLocale() { return ResourceManager.getLocale(); } /** * Returns true if the current locale is English. */ public static boolean isEnglishLocale() { return LanguageUtils.isEnglishLocale(getLocale()); } /** * Launches the specified audio song in the player. Adds this song * to the play list and begins playing it. * * @param song the <tt>PlayListItem</tt> instance to launch */ public void launchAudio(PlayListItem song) { launchAudio(song, true); } /** * Launches the specified audio song in the player. * @param song - song to play now * @param enqueueSong - if true, also add this song to the playlist, otherwise just * */ public void launchAudio(PlayListItem song, boolean addSongToPlaylist) { if( addSongToPlaylist ) { PlaylistMediator playList = PlaylistMediator.getInstance(); playList.add(song, playList.getSize()); playList.setSelectedIndex(song); } MediaPlayerComponent mediaPlayer = MediaPlayerComponent.getInstance(); mediaPlayer.loadSong(song, !addSongToPlaylist); } /** Attempts to stop a song if playing on the frost player. * */ public boolean attemptStopAudio() { MediaPlayerComponent mediaPlayer = MediaPlayerComponent.getInstance(); mediaPlayer.stopSong(); return true; } /** * Makes the update message show up in the status panel */ public void showUpdateNotification(final UpdateInformation info) { safeInvokeAndWait(new Runnable() { public void run() { STATUS_LINE.showUpdatePanel(true, info); } }); } /** * Trigger a search based on a string. * * @param query the query <tt>String</tt> * @return the GUID of the query sent to the network. * Used mainly for testing */ public byte[] triggerSearch(String query) { MAIN_FRAME.setSelectedTab(GUIMediator.Tabs.SEARCH); return SearchMediator.triggerSearch(query); } /** * Notification that the button state has changed. */ public void buttonViewChanged() { IconManager.instance().wipeButtonIconCache(); updateButtonView(FRAME); } /** * Notification that the smileys state has been changed. */ public void smileysChanged(boolean newstatus) { ChatMediator.instance().changesmileys(newstatus); updateButtonView(FRAME); } private void updateButtonView(Component c) { if (c instanceof IconButton) { ((IconButton) c).updateUI(); } Component[] children = null; if (c instanceof Container) { children = ((Container)c).getComponents(); } if (children != null) { for(int i = 0; i < children.length; i++) { updateButtonView(children[i]); } } } /** * trigger a browse host based on address and port */ public void doBrowseHost(Connectable host) { MAIN_FRAME.setSelectedTab(GUIMediator.Tabs.SEARCH); SearchMediator.doBrowseHost(host, null); } /** * safely run code synchronously in the event dispatching thread. */ public static void safeInvokeAndWait(Runnable runnable) { if (EventQueue.isDispatchThread()) runnable.run(); else { try { SwingUtilities.invokeAndWait(runnable); } catch (InvocationTargetException ite) { Throwable t = ite.getTargetException(); if(t instanceof Error) throw (Error)t; else if(t instanceof RuntimeException) throw (RuntimeException)t; else ErrorService.error(t); } catch(InterruptedException ignored) {} } } /** * InvokesLater if not already in the dispatch thread. */ public static void safeInvokeLater(Runnable runnable) { if (EventQueue.isDispatchThread()) runnable.run(); else SwingUtilities.invokeLater(runnable); } /** * Changes whether the media player is enabled and updates the GUI accordingly. */ public void setPlayerEnabled(boolean value) { if (value == PlayerSettings.PLAYER_ENABLED.getValue()) return; PlayerSettings.PLAYER_ENABLED.setValue(value); getStatusLine().refresh(); LIBRARY_MEDIATOR.setPlayerEnabled(value); LibraryPlayListTab.setPlayerEnabled(value); } /** Tells CHAT_MEDIATOR to try to start the IRC Chat */ public void tryToStartAndAddChat() { CHAT_MEDIATOR.tryToStartAndAddChat(); } /** Changes the nick on the Chat */ public void setIRCNick(String newNick) { CHAT_MEDIATOR.nick(newNick); } /** * Sets the cursor on limewire's frame. * @param cursor the cursor that should be shown on the frame and all its * child components that don't have their own cursor set */ public void setFrameCursor(Cursor cursor) { FRAME.setCursor(cursor); } public static ChatFrame createChat(String host, int port) { InstantMessenger chatter = GuiCoreMediator.getChatManager().createConnection(host, port); ChatFrame frame = ChatUIManager.instance().acceptChat(chatter); chatter.start(); return frame; } }

The table below shows all metrics for GUIMediator.java.

MetricValueDescription
BLOCKS192.00Number of blocks
BLOCK_COMMENT 9.00Number of block comment lines
COMMENTS768.00Comment lines
COMMENT_DENSITY 1.05Comment density
COMPARISONS65.00Number of comparison operators
CYCLOMATIC233.00Cyclomatic complexity
DECL_COMMENTS127.00Comments in declarations
DOC_COMMENT692.00Number of javadoc comment lines
ELOC734.00Effective lines of code
EXEC_COMMENTS30.00Comments in executable code
EXITS242.00Procedure exits
FUNCTIONS133.00Number of function declarations
HALSTEAD_DIFFICULTY74.25Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY245.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 2.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 1.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 1.00JAVA0031 Case statement not properly closed
JAVA0032 1.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003455.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 2.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 1.00JAVA0064 N variations of identifier name (maximum: M)
JAVA006542.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 4.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 1.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 1.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA010819.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 8.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA011010.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 2.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA011711.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 2.00JAVA0128 Public constructor in non-public class
JAVA0130 2.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 1.00JAVA0143 Synchronized method
JAVA0144 7.00JAVA0144 Line exceeds maximum M characters
JAVA01451205.00JAVA0145 Tab character used in source file
JAVA0150 1.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 3.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 3.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 1.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 2.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 2.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 1.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 1.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1857.00Number of lines in the source file
LINE_COMMENT67.00Number of line comments
LOC906.00Lines of code
LOGICAL_LINES404.00Number of statements
LOOPS 2.00Number of loops
NEST_DEPTH 7.00Maximum nesting depth
OPERANDS1938.00Number of operands
OPERATORS3923.00Number of operators
PARAMS97.00Number of formal parameter declarations
PROGRAM_LENGTH5861.00Halstead program length
PROGRAM_VOCAB829.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS148.00Number of return points from functions
SIZE65273.00Size of the file in bytes
UNIQUE_OPERANDS770.00Number of unique operands
UNIQUE_OPERATORS59.00Number of unique operators
WHITESPACE183.00Number of whitespace lines