diff options
author | Alex Lockwood <alockwood@google.com> | 2014-10-10 15:46:40 +0000 |
---|---|---|
committer | Alex Lockwood <alockwood@google.com> | 2014-10-10 15:46:40 +0000 |
commit | 3e1eaf1cb5ec4cf913b785c5100a539ce4cf7df9 (patch) | |
tree | 29a67cbeed79d79e5206b30ce4be487db93d4e04 | |
parent | 499d46cc1fab25b684a69a2a0595c1f015159287 (diff) | |
download | login-3e1eaf1cb5ec4cf913b785c5100a539ce4cf7df9.tar.gz |
Revert "Fixed user login image flicker/glitch"
This reverts commit 499d46cc1fab25b684a69a2a0595c1f015159287.
Change-Id: Id40de7dabe4fb4e1176024f4a94f5bc695d67a04
-rw-r--r-- | src/com/google/gct/login/CredentialedUserRoster.java | 57 | ||||
-rw-r--r-- | src/com/google/gct/login/GoogleLogin.java | 76 | ||||
-rw-r--r-- | src/com/google/gct/login/GoogleLoginListener.java | 3 | ||||
-rw-r--r-- | src/com/google/gct/login/GoogleLoginPrefs.java | 7 | ||||
-rw-r--r-- | src/com/google/gct/login/GoogleLoginUtils.java | 3 | ||||
-rw-r--r-- | src/com/google/gct/login/OAuthScopeRegistry.java | 9 | ||||
-rw-r--r-- | src/com/google/gct/login/ui/UsersListCellRenderer.java | 96 |
7 files changed, 124 insertions, 127 deletions
diff --git a/src/com/google/gct/login/CredentialedUserRoster.java b/src/com/google/gct/login/CredentialedUserRoster.java index d8936fb..7d50c70 100644 --- a/src/com/google/gct/login/CredentialedUserRoster.java +++ b/src/com/google/gct/login/CredentialedUserRoster.java @@ -29,19 +29,22 @@ import java.util.Map; * {@link CredentialedUser} objects. */ public class CredentialedUserRoster { - private final LinkedHashMap<String, CredentialedUser> myAllUsers = new LinkedHashMap<String, CredentialedUser>(); - private final Collection<GoogleLoginListener> myListeners = Lists.newLinkedList(); - private CredentialedUser myActiveUser; + private final LinkedHashMap<String, CredentialedUser> allUsers = new LinkedHashMap<String, CredentialedUser>(); + private CredentialedUser activeUser; + private Collection<GoogleLoginListener> listeners; + + public CredentialedUserRoster() { + listeners = Lists.newLinkedList(); + } /** * Returns a copy of the map of the current logged in users. * @return Copy of current logged in users. */ - @NotNull public LinkedHashMap<String, CredentialedUser> getAllUsers() { synchronized (this) { LinkedHashMap<String, CredentialedUser> clone = new LinkedHashMap<String, CredentialedUser>(); - clone.putAll(myAllUsers); + clone.putAll(allUsers); return clone; } } @@ -52,8 +55,8 @@ public class CredentialedUserRoster { */ public void setAllUsers(Map<String, CredentialedUser> users) { synchronized (this) { - myAllUsers.clear(); - myAllUsers.putAll(users); + allUsers.clear(); + allUsers.putAll(users); } } @@ -63,7 +66,7 @@ public class CredentialedUserRoster { */ @Nullable public CredentialedUser getActiveUser() { - return myActiveUser; + return activeUser; } /** @@ -75,16 +78,16 @@ public class CredentialedUserRoster { */ public void setActiveUser(@NotNull String userEmail) throws IllegalArgumentException { synchronized (this) { - if (!myAllUsers.containsKey(userEmail)) { + if(!allUsers.containsKey(userEmail)) { throw new IllegalArgumentException(userEmail + " is not a logged in user."); } - if (myActiveUser != null) { - myActiveUser.setActive(false); + if(activeUser != null) { + activeUser.setActive(false); } - myActiveUser = myAllUsers.get(userEmail); - myActiveUser.setActive(true); + activeUser = allUsers.get(userEmail); + activeUser.setActive(true); GoogleLoginPrefs.saveActiveUser(userEmail); notifyLoginStatusChange(); } @@ -95,9 +98,9 @@ public class CredentialedUserRoster { */ public void removeActiveUser() { synchronized (this) { - if (myActiveUser != null) { - myActiveUser.setActive(false); - myActiveUser = null; + if(activeUser != null) { + activeUser.setActive(false); + activeUser = null; GoogleLoginPrefs.removeActiveUser(); notifyLoginStatusChange(); } @@ -110,7 +113,7 @@ public class CredentialedUserRoster { */ public int numberOfUsers() { synchronized (this) { - return myAllUsers.size(); + return allUsers.size(); } } @@ -119,7 +122,7 @@ public class CredentialedUserRoster { * @return True if there is an active user and false otherwise. */ public boolean isActiveUserAvailable() { - return myActiveUser != null; + return activeUser != null; } /** @@ -131,7 +134,7 @@ public class CredentialedUserRoster { */ public void addUser(CredentialedUser user) { synchronized (this) { - myAllUsers.put(user.getEmail(), user); + allUsers.put(user.getEmail(), user); setActiveUser(user.getEmail()); } } @@ -147,16 +150,16 @@ public class CredentialedUserRoster { */ public boolean removeUser(String userEmail) { synchronized (this) { - if (!myAllUsers.containsKey(userEmail)) { + if(!allUsers.containsKey(userEmail)) { return false; } - if (myActiveUser.getEmail().equals(userEmail)) { - myActiveUser = null; + if(activeUser.getEmail().equals(userEmail)) { + activeUser = null; GoogleLoginPrefs.removeActiveUser(); } - myAllUsers.remove(userEmail); + allUsers.remove(userEmail); notifyLoginStatusChange(); return true; } @@ -169,14 +172,14 @@ public class CredentialedUserRoster { * @param listener the specified {@code GoogleLoginListener} */ void addLoginListener(GoogleLoginListener listener) { - synchronized(myListeners) { - myListeners.add(listener); + synchronized(listeners) { + listeners.add(listener); } } private void notifyLoginStatusChange() { - synchronized(myListeners) { - for (GoogleLoginListener listener : myListeners) { + synchronized(listeners) { + for (GoogleLoginListener listener : listeners) { listener.statusChanged(); } } diff --git a/src/com/google/gct/login/GoogleLogin.java b/src/com/google/gct/login/GoogleLogin.java index 4676152..7ddf670 100644 --- a/src/com/google/gct/login/GoogleLogin.java +++ b/src/com/google/gct/login/GoogleLogin.java @@ -70,6 +70,9 @@ public class GoogleLogin { public static final Logger LOG = Logger.getInstance(GoogleLogin.class); + /** + * Constructor + */ private GoogleLogin() { this.clientInfo = getClientInfo(); this.uiFacade = new AndroidUiFacade(); @@ -82,9 +85,8 @@ public class GoogleLogin { * Gets the {@link GoogleLogin} object. * @return the {@link GoogleLogin} object. */ - @NotNull public static GoogleLogin getInstance() { - if (instance == null) { + if(instance == null) { instance = new GoogleLogin(); instance.dataStore.initializeUsers(); } @@ -108,10 +110,10 @@ public class GoogleLogin { * either succeeds or fails. * @throws InvalidThreadTypeException */ - public static void promptToLogIn(@Nullable final String message, @Nullable final IGoogleLoginCompletedCallback callback) + public static void promptToLogIn(final String message, @Nullable final IGoogleLoginCompletedCallback callback) throws InvalidThreadTypeException { if (!instance.isLoggedIn()) { - if (ApplicationManager.getApplication().isDispatchThread()) { + if(ApplicationManager.getApplication().isDispatchThread()) { getInstance().logIn(message, callback); } else { throw new InvalidThreadTypeException("promptToLogin"); @@ -133,7 +135,6 @@ public class GoogleLogin { * @return An HttpRequestFactory object that has been signed with the active user's * authentication headers or null if there is no active user. */ - @Nullable public HttpRequestFactory createRequestFactory() { return createRequestFactory(null); } @@ -155,10 +156,9 @@ public class GoogleLogin { * @return An HttpRequestFactory object that has been signed with the active user's * authentication headers or null if there is no active user. */ - @Nullable - public HttpRequestFactory createRequestFactory(@Nullable String message) { + public HttpRequestFactory createRequestFactory(String message) { CredentialedUser activeUser = users.getActiveUser(); - if (activeUser == null) { + if(activeUser == null) { // TODO: prompt user to select an existing user or sign in return null; } @@ -173,10 +173,9 @@ public class GoogleLogin { * @throws IOException if something goes wrong while fetching the token. * */ - @Nullable public String fetchAccessToken() throws IOException { CredentialedUser activeUser = users.getActiveUser(); - if (activeUser == null) { + if(activeUser == null) { return null; } return activeUser.getGoogleLoginState().fetchAccessToken(); @@ -186,10 +185,9 @@ public class GoogleLogin { * Returns the OAuth2 Client ID for the active user. * @return the OAuth2 Client ID for the active user. */ - @Nullable public String fetchOAuth2ClientId() { CredentialedUser activeUser = users.getActiveUser(); - if (activeUser == null) { + if(activeUser == null) { return null; } return activeUser.getGoogleLoginState().fetchOAuth2ClientId(); @@ -199,10 +197,9 @@ public class GoogleLogin { * Returns the OAuth2 Client Secret for the active user. * @return the OAuth2 Client Secret for the active user. */ - @Nullable public String fetchOAuth2ClientSecret() { CredentialedUser activeUser = users.getActiveUser(); - if (activeUser == null) { + if(activeUser == null) { return null; } return activeUser.getGoogleLoginState().fetchOAuth2ClientSecret(); @@ -215,10 +212,9 @@ public class GoogleLogin { * * @return the refresh token, or {@code null} if the user cancels out of a request to log in */ - @Nullable public String fetchOAuth2RefreshToken() { CredentialedUser activeUser = users.getActiveUser(); - if (activeUser == null) { + if(activeUser == null) { return null; } return activeUser.getGoogleLoginState().fetchOAuth2RefreshToken(); @@ -233,10 +229,9 @@ public class GoogleLogin { * @throws IOException if something goes wrong while fetching the token. * */ - @Nullable public String fetchOAuth2Token() throws IOException { CredentialedUser activeUser = users.getActiveUser(); - if (activeUser == null) { + if(activeUser == null) { return null; } return activeUser.getGoogleLoginState().fetchOAuth2Token(); @@ -247,10 +242,9 @@ public class GoogleLogin { * returns credentials with the access token and refresh token set to null. * @return the OAuth credentials. */ - @Nullable public Credential getCredential() { CredentialedUser activeUser = users.getActiveUser(); - if (activeUser == null) { + if(activeUser == null) { return null; } return activeUser.getGoogleLoginState().getCredential(); @@ -260,10 +254,9 @@ public class GoogleLogin { * Returns the active user's email address, or null if there is no active user, * @return the active user's email address, or null if there is no active user, */ - @Nullable public String getEmail() { CredentialedUser activeUser = users.getActiveUser(); - if (activeUser == null) { + if(activeUser == null) { return null; } return activeUser.getGoogleLoginState().getEmail(); @@ -338,7 +331,7 @@ public class GoogleLogin { } }); - loggedIn = state != null && state.logInWithLocalServer(message); + loggedIn = state.logInWithLocalServer(message); } @Override @@ -390,7 +383,7 @@ public class GoogleLogin { */ public boolean logOut() { CredentialedUser activeUser = users.getActiveUser(); - if (activeUser == null) { + if(activeUser == null) { return false; } @@ -412,7 +405,7 @@ public class GoogleLogin { */ public boolean logOut(boolean showPrompt) { CredentialedUser activeUser = users.getActiveUser(); - if (activeUser == null) { + if(activeUser == null) { return false; } return activeUser.getGoogleLoginState().logOut(showPrompt); @@ -424,13 +417,13 @@ public class GoogleLogin { * the access and refresh token will be set to null. * @return a new {@link Credential}. */ - @Nullable public Credential makeCredential() { CredentialedUser activeUser = users.getActiveUser(); - if (activeUser == null) { + if(activeUser == null) { return null; + } else { + return activeUser.getGoogleLoginState().makeCredential(); } - return activeUser.getGoogleLoginState().makeCredential(); } /** @@ -509,7 +502,7 @@ public class GoogleLogin { uiFacade, new AndroidLoggerFacade()); - if (initializingUsers && !state.isLoggedIn()) { + if(initializingUsers && !state.isLoggedIn()) { // Logs user out if oauth scope for active user's credentials // does not match the current scope return null; @@ -522,7 +515,7 @@ public class GoogleLogin { * Returns the Client Info for Android Studio in a {@link com.google.gct.login.GoogleLogin.ClientInfo}. * @return the Client Info for Android Studio in a {@link com.google.gct.login.GoogleLogin.ClientInfo}. */ - private static ClientInfo getClientInfo() { + private ClientInfo getClientInfo() { String id = LoginContext.getId(); String info = LoginContext.getInfo(); if (id != null && id.trim().length() > 0 @@ -534,7 +527,7 @@ public class GoogleLogin { } // TODO: update code to specify parent - private static void logErrorAndDisplayDialog(@NotNull final String title, @NotNull final Exception exception) { + private void logErrorAndDisplayDialog(@NotNull final String title, @NotNull final Exception exception) { LOG.error(exception.getMessage(), exception); GoogleLoginUtils.showErrorDialog(exception.getMessage(), title); } @@ -634,17 +627,13 @@ public class GoogleLogin { @Override public boolean askYesOrNo(String title, String message) { String updatedMessage = message; - if (message.equals("Are you sure you want to sign out?")) { - updatedMessage = "Are you sure you want to sign out"; + if(message.equals("Are you sure you want to sign out?")) { CredentialedUser activeUser = getActiveUser(); - if (activeUser != null && !Strings.isNullOrEmpty(activeUser.getName())) { - updatedMessage += (" " + activeUser.getName()); - } - if (activeUser != null && !Strings.isNullOrEmpty(activeUser.getEmail())) { - updatedMessage += (" (" + activeUser.getEmail() + ")"); - } - updatedMessage += "?"; + String name = activeUser.getName().isEmpty() ? "" : activeUser.getName() + " "; + updatedMessage = "Are you sure you want to sign out " + name + + "(" + activeUser.getEmail() + ")?"; } + Icon icon = IconLoader.getIcon(GOOGLE_IMG); return (Messages.showYesNoDialog(updatedMessage, title, icon) == Messages.YES); } @@ -696,7 +685,7 @@ public class GoogleLogin { List<String> allUsers = GoogleLoginPrefs.getStoredUsers(); String removedUsers = ""; - for (String aUser : allUsers) { + for(String aUser : allUsers) { // Add a new user, so that loadOAuth called from the GoogleLoginState constructor // will be able to create a customized key to get that user's OAuth data // This will be overwritten with new GoogleLoginState object @@ -739,8 +728,9 @@ public class GoogleLogin { } // Log removed users - if (!removedUsers.isEmpty()) { - String message = "The following user(s) had expired authentication scopes: " + removedUsers + "and have been logged out."; + if(!removedUsers.isEmpty()) { + String message = "The following user(s) had expired authentication scopes: " + removedUsers + + "and have been logged out."; GoogleLoginUtils.showErrorDialog(message, "Google Login"); } } diff --git a/src/com/google/gct/login/GoogleLoginListener.java b/src/com/google/gct/login/GoogleLoginListener.java index 84f1778..560f5f0 100644 --- a/src/com/google/gct/login/GoogleLoginListener.java +++ b/src/com/google/gct/login/GoogleLoginListener.java @@ -21,7 +21,8 @@ import com.intellij.openapi.extensions.ExtensionPointName; * Listener for changes in the login status. */ public interface GoogleLoginListener { - ExtensionPointName<GoogleLoginListener> EP_NAME = new ExtensionPointName<GoogleLoginListener>("com.google.gct.login.googleLoginListener"); + public static ExtensionPointName<GoogleLoginListener> EP_NAME = + new ExtensionPointName<GoogleLoginListener>("com.google.gct.login.googleLoginListener"); /** * Called when the login or active status of the user changes. diff --git a/src/com/google/gct/login/GoogleLoginPrefs.java b/src/com/google/gct/login/GoogleLoginPrefs.java index 0c9afd0..1872f4e 100644 --- a/src/com/google/gct/login/GoogleLoginPrefs.java +++ b/src/com/google/gct/login/GoogleLoginPrefs.java @@ -18,12 +18,10 @@ package com.google.gct.login; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; import com.google.common.base.Splitter; -import com.google.common.collect.Lists; import com.google.gdt.eclipse.login.common.OAuthData; import com.intellij.openapi.diagnostic.Logger; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -186,7 +184,6 @@ public class GoogleLoginPrefs { * Retrieves the persistently stored active user. * @return the stored active user. */ - @Nullable public static String getActiveUser() { Preferences prefs = getPrefs(); String activeUser = prefs.get(ACTIVE_USER, null); @@ -253,9 +250,9 @@ public class GoogleLoginPrefs { flushPrefs(prefs); } - private static void removeUser(Preferences prefs, String user) { + private static void removeUser(Preferences prefs, String user) {; String allUsersString = prefs.get(USERS, ""); - List<String> allUsers = Lists.newArrayList(); + List<String> allUsers = new ArrayList<String>(); for (String scope : allUsersString.split(DELIMITER)) { allUsers.add(scope); } diff --git a/src/com/google/gct/login/GoogleLoginUtils.java b/src/com/google/gct/login/GoogleLoginUtils.java index 11a29a9..adf1777 100644 --- a/src/com/google/gct/login/GoogleLoginUtils.java +++ b/src/com/google/gct/login/GoogleLoginUtils.java @@ -51,6 +51,7 @@ public class GoogleLoginUtils { * @param pictureCallback * @return the user's picture from <code>userInfo</code> */ + @Nullable public static void getUserPicture(Userinfoplus userInfo, final IUserPropertyCallback pictureCallback) { // set the size of the image before it is served String urlString = userInfo.getPicture() + "?sz=" + DEFAULT_PICTURE_SIZE; @@ -75,6 +76,7 @@ public class GoogleLoginUtils { }); } + @Nullable public static void getUserInfo(@NotNull final Credential credential, final IUserPropertyCallback callback) { final Oauth2 userInfoService = @@ -129,7 +131,6 @@ public class GoogleLoginUtils { * Used for testing. * @return a {@link Credential} object for the fake user. */ - @NotNull public static Credential makeFakeUserCredential() { String clientId = System.getenv().get("ANDROID_CLIENT_ID"); String clientSecret = System.getenv().get("ANDROID_CLIENT_SECRET"); diff --git a/src/com/google/gct/login/OAuthScopeRegistry.java b/src/com/google/gct/login/OAuthScopeRegistry.java index 31f96c7..a0c23b5 100644 --- a/src/com/google/gct/login/OAuthScopeRegistry.java +++ b/src/com/google/gct/login/OAuthScopeRegistry.java @@ -15,6 +15,8 @@ */ package com.google.gct.login; + +import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.NotNull; import java.util.Collections; @@ -25,18 +27,19 @@ import java.util.TreeSet; * Holds the list of OAuth2 scopes for Google Login. */ class OAuthScopeRegistry { - private static final SortedSet<String> SCOPES; + private static final SortedSet<String> sScopes; static { SortedSet<String> scopes = new TreeSet<String>(); scopes.add("https://www.googleapis.com/auth/userinfo#email"); scopes.add("https://www.googleapis.com/auth/appengine.admin"); scopes.add("https://www.googleapis.com/auth/cloud-platform"); - SCOPES = Collections.unmodifiableSortedSet(scopes); + + sScopes = Collections.unmodifiableSortedSet(scopes); } @NotNull public static SortedSet<String> getScopes() { - return SCOPES; + return sScopes; } } diff --git a/src/com/google/gct/login/ui/UsersListCellRenderer.java b/src/com/google/gct/login/ui/UsersListCellRenderer.java index 01e319a..928eeba 100644 --- a/src/com/google/gct/login/ui/UsersListCellRenderer.java +++ b/src/com/google/gct/login/ui/UsersListCellRenderer.java @@ -16,9 +16,6 @@ package com.google.gct.login.ui; import com.intellij.ui.ColorUtil; -import com.google.api.client.util.Maps; -import com.google.gct.login.CredentialedUser; -import com.google.gct.login.GoogleLogin; import com.intellij.ui.JBColor; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.Nullable; @@ -45,7 +42,7 @@ import java.awt.Image; import java.awt.Point; import java.awt.Toolkit; import java.net.URL; -import java.util.Map; + /** * A custom cell render for {@link GoogleLoginUsersPanel#list} that manages @@ -85,11 +82,6 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere private final Dimension myPlayLabelDimension; private final Dimension myLearnMoreLabelDimension; - /** Maps user emails to large user image icons. */ - private final Map<String, Image> myUserLargeImageCache = Maps.newHashMap(); - /** Maps user emails to small user image icons. */ - private final Map<String, Image> myUserSmallImageCache = Maps.newHashMap(); - public UsersListCellRenderer() { myNameFont = new Font("Helvetica", Font.BOLD, 13); myGeneralFont = new Font("Helvetica", Font.PLAIN, 13); @@ -109,58 +101,49 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere @Nullable @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - if (value instanceof NoUsersListItem) { + if(value instanceof NoUsersListItem) { return createNoUserDisplay(); } - if (!(value instanceof UsersListItem)) { + + if(!(value instanceof UsersListItem)) { return null; } + UsersListItem usersListItem = (UsersListItem)value; - final UsersListItem usersListItem = (UsersListItem)value; - final CredentialedUser activeUser = GoogleLogin.getInstance().getActiveUser(); - final boolean isActiveUserSelected = activeUser != null && usersListItem.getUserEmail().equals(activeUser.getEmail()); + boolean calcIsSelected; + if (list.getSelectedIndex() == index) { + calcIsSelected = true; + } else { + calcIsSelected = false; + } JPanel mainPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, HGAP, VGAP)); - mainPanel.setMinimumSize(isActiveUserSelected ? myActiveMainPanelDimension : myMainPanelDimension); + mainPanel.setMinimumSize(calcIsSelected ? myActiveMainPanelDimension : myMainPanelDimension); mainPanel.setAlignmentX(LEFT_ALIGNMENT); // Update colors - final Color bg = isActiveUserSelected ? myActiveColor : myInactiveColor; - final Color fg = isActiveUserSelected ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground(); + final Color bg = calcIsSelected ? myActiveColor : myInactiveColor; + final Color fg = calcIsSelected ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground(); mainPanel.setBackground(bg); mainPanel.setForeground(fg); + // TODO: add step to cache scaled image Image image = usersListItem.getUserPicture(); - if (image == null){ - // Use default profile image. - image = Toolkit.getDefaultToolkit().getImage(UsersListCellRenderer.class.getResource(DEFAULT_AVATAR)); + if(image == null){ + // use default image + URL url = UsersListCellRenderer.class.getResource(DEFAULT_AVATAR); + image = Toolkit.getDefaultToolkit().getImage(url); } - final int imageWidth, imageHeight; - final Map<String, Image> userImageCache; - if (isActiveUserSelected) { - imageWidth = ACTIVE_USER_IMAGE_WIDTH; - imageHeight = ACTIVE_USER_IMAGE_HEIGHT; - userImageCache = myUserLargeImageCache; - } else { - imageWidth = PLAIN_USER_IMAGE_WIDTH; - imageHeight = PLAIN_USER_IMAGE_HEIGHT; - userImageCache = myUserSmallImageCache; - } - - final Image scaledImage; - if (!userImageCache.containsKey(usersListItem.getUserEmail())) { - scaledImage = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_SMOOTH); - userImageCache.put(usersListItem.getUserEmail(), scaledImage); - } else { - scaledImage = userImageCache.get(usersListItem.getUserEmail()); - } + int imageWidth = calcIsSelected ? ACTIVE_USER_IMAGE_WIDTH : PLAIN_USER_IMAGE_WIDTH; + int imageHeight = calcIsSelected ? ACTIVE_USER_IMAGE_HEIGHT : PLAIN_USER_IMAGE_HEIGHT; + Image scaledImage = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_SMOOTH); - final JComponent textPanel; - if (isActiveUserSelected) { - textPanel = createActiveTextDisplay(usersListItem); + JComponent textPanel; + if (calcIsSelected) { + textPanel = createActiveTextDisplay(usersListItem); } else { - textPanel = createTextDisplay(false, usersListItem); + textPanel = createTextDisplay(calcIsSelected, usersListItem); } mainPanel.add(new JLabel(new ImageIcon(scaledImage))); @@ -178,7 +161,13 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere double playYEnd = playYStart + myPlayLabelDimension.getHeight(); double playXStart = ACTIVE_USER_IMAGE_WIDTH + HGAP + VGAP; double playXEnd = playXStart + myPlayLabelDimension.getWidth(); - return (point.getX() > playXStart) && (point.getX() < playXEnd) && (point.getY() > playYStart) && (point.getY() < playYEnd); + + if((point.getX() > playXStart) && (point.getX() < playXEnd) + && (point.getY() > playYStart) && (point.getY() < playYEnd)) { + return true; + } + + return false; } public boolean inCloudConsoleUrl(Point point, int activeIndex) { @@ -188,7 +177,13 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere double playYEnd = playYStart + myCloudLabelDimension.getHeight(); double playXStart = ACTIVE_USER_IMAGE_WIDTH + HGAP + VGAP; double playXEnd = playXStart + myCloudLabelDimension.getWidth(); - return (point.getX() > playXStart) && (point.getX() < playXEnd) && (point.getY() > playYStart) && (point.getY() < playYEnd); + + if((point.getX() > playXStart) && (point.getX() < playXEnd) + && (point.getY() > playYStart) && (point.getY() < playYEnd)) { + return true; + } + + return false; } public boolean inLearnMoreUrl(Point point) { @@ -198,7 +193,13 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere double urlYEnd = urlYStart + myLearnMoreLabelDimension.getHeight(); double urlXStart = GOOGLE_IMAGE_WEST; double urlXEnd = urlXStart + myLearnMoreLabelDimension.getWidth(); - return (point.getX() > urlXStart) && (point.getX() < urlXEnd) && (point.getY() > urlYStart) && (point.getY() < urlYEnd); + + if((point.getX() > urlXStart) && (point.getX() < urlXEnd) + && (point.getY() > urlYStart) && (point.getY() < urlYEnd)) { + return true; + } + + return false; } public int getMainPanelHeight() { @@ -285,7 +286,8 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere String googleIcon = UIUtil.isUnderDarcula() ? GOOGLE_IMG_WHITE : GOOGLE_IMG_COL; URL url = UsersListCellRenderer.class.getResource(googleIcon); Image image = Toolkit.getDefaultToolkit().getImage(url); - Image scaledImage = image.getScaledInstance(GOOGLE_IMAGE_WIDTH, GOOGLE_IMAGE_HEIGHT, Image.SCALE_SMOOTH); + Image scaledImage = image.getScaledInstance( + GOOGLE_IMAGE_WIDTH, GOOGLE_IMAGE_HEIGHT, Image.SCALE_SMOOTH); JLabel imageLabel = new JLabel(new ImageIcon(scaledImage)); JLabel signInLabel = new JLabel(SIGN_IN_TEXT); |