From eeb95876576bed57f37262cbb7e1d7dd67a09e3c Mon Sep 17 00:00:00 2001 From: Vhati Date: Sat, 14 Sep 2013 22:08:35 -0400 Subject: [PATCH] Fixed perpetually-green Update button --- skel_common/readme_changelog.txt | 1 + .../java/net/vhati/modmanager/ui/ManagerFrame.java | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/skel_common/readme_changelog.txt b/skel_common/readme_changelog.txt index e8a11d4..42f5420 100644 --- a/skel_common/readme_changelog.txt +++ b/skel_common/readme_changelog.txt @@ -2,6 +2,7 @@ Changelog ???: - Added "Return FTL to an unmodded state before switching to a new version" +- Fixed perpetually green "Update" button 1.2: - Added a commandline interface diff --git a/src/main/java/net/vhati/modmanager/ui/ManagerFrame.java b/src/main/java/net/vhati/modmanager/ui/ManagerFrame.java index 14d346b..36568ad 100644 --- a/src/main/java/net/vhati/modmanager/ui/ManagerFrame.java +++ b/src/main/java/net/vhati/modmanager/ui/ManagerFrame.java @@ -56,6 +56,7 @@ import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; +import javax.swing.UIManager; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.table.DefaultTableModel; @@ -117,6 +118,8 @@ public class ManagerFrame extends JFrame implements ActionListener, HashObserver private ModDB modDB = new ModDB(); private AutoUpdateInfo appUpdateInfo = null; + private Color updateBtnDisabledColor = UIManager.getColor( "Button.foreground" ); + private Color updateBtnEnabledColor = new Color(0, 124, 0); private NerfListener nerfListener = new NerfListener( this ); @@ -209,9 +212,9 @@ public class ManagerFrame extends JFrame implements ActionListener, HashObserver updateBtn = new JButton("Update"); updateBtn.setMargin( actionInsets ); - updateBtn.setForeground( new Color(0, 124, 0) ); updateBtn.addMouseListener( new StatusbarMouseListener( this, String.format( "Show info about the latest version of %s.", appName ) ) ); updateBtn.addActionListener(this); + updateBtn.setForeground( updateBtnDisabledColor ); updateBtn.setEnabled( false ); modActionsPanel.add( updateBtn ); @@ -484,7 +487,9 @@ public class ManagerFrame extends JFrame implements ActionListener, HashObserver AutoUpdateInfo aui = JacksonAutoUpdateReader.parse( appUpdateFile ); if ( aui != null ) { appUpdateInfo = aui; - updateBtn.setEnabled( appVersion.compareTo(appUpdateInfo.getLatestVersion()) < 0 ); + boolean isUpdateAvailable = ( appVersion.compareTo(appUpdateInfo.getLatestVersion()) < 0 ); + updateBtn.setForeground( isUpdateAvailable ? updateBtnEnabledColor : updateBtnDisabledColor ); + updateBtn.setEnabled( isUpdateAvailable ); } if ( appUpdateInterval > 0 ) { @@ -549,7 +554,9 @@ public class ManagerFrame extends JFrame implements ActionListener, HashObserver AutoUpdateInfo aui = JacksonAutoUpdateReader.parse( appUpdateFile ); if ( aui != null ) { appUpdateInfo = aui; - updateBtn.setEnabled( appVersion.compareTo(appUpdateInfo.getLatestVersion()) < 0 ); + boolean isUpdateAvailable = ( appVersion.compareTo(appUpdateInfo.getLatestVersion()) < 0 ); + updateBtn.setForeground( isUpdateAvailable ? updateBtnEnabledColor : updateBtnDisabledColor ); + updateBtn.setEnabled( isUpdateAvailable ); } } }