summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Conway <mikeconway@Mike-Conways-MacBook-Pro.local>2011-07-15 16:02:15 (GMT)
committer Mike Conway <mikeconway@Mike-Conways-MacBook-Pro.local>2011-07-15 16:02:15 (GMT)
commit2d0b28c33ce48df2fb706774d1d7a116b35332b9 (patch)
tree6fead95d65475ca687ce074320932c94501ca409
parent06ddf95b5269b08a89b0cb33bb2981500c948b02 (diff)
downloadQCG-Data-2d0b28c33ce48df2fb706774d1d7a116b35332b9.zip
QCG-Data-2d0b28c33ce48df2fb706774d1d7a116b35332b9.tar.gz
QCG-Data-2d0b28c33ce48df2fb706774d1d7a116b35332b9.tar.bz2
set look and feel at startup, now restart to avoid occ'l awt repaint errors
-rw-r--r--idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/StartupSequencer.java5
-rw-r--r--idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/iDrop.java139
-rw-r--r--idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImpl.java2
-rw-r--r--idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/utils/LookAndFeelManager.java105
-rw-r--r--idrop-swing/src/test/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImplTest.java1
5 files changed, 184 insertions, 68 deletions
diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/StartupSequencer.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/StartupSequencer.java
index 3766508..ebdc687 100644
--- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/StartupSequencer.java
+++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/StartupSequencer.java
@@ -17,6 +17,7 @@ import org.irods.jargon.idrop.desktop.systraygui.services.IdropConfigurationServ
import org.irods.jargon.idrop.desktop.systraygui.services.IdropConfigurationServiceImpl;
import org.irods.jargon.idrop.desktop.systraygui.services.QueueSchedulerTimerTask;
import org.irods.jargon.idrop.desktop.systraygui.utils.IdropConfig;
+import org.irods.jargon.idrop.desktop.systraygui.utils.LookAndFeelManager;
import org.irods.jargon.idrop.desktop.systraygui.viscomponents.SetupWizard;
import org.irods.jargon.idrop.exceptions.IdropAlreadyRunningException;
import org.irods.jargon.idrop.exceptions.IdropException;
@@ -129,6 +130,10 @@ public class StartupSequencer {
log.info("config properties derived...");
idropCore.setIdropConfig(new IdropConfig(derivedProperties));
idropCore.getIdropConfig().setUpLogging();
+
+ log.info("setting initial look and feel");
+ LookAndFeelManager laf = new LookAndFeelManager(idropCore);
+ laf.setLookAndFeel(idropCore.getIdropConfig().getPropertyForKey(IdropConfigurationService.LOOK_AND_FEEL));
log.info("logging in in splash background thread");
idropSplashWindow.setStatus("Logging in...", ++count);
diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/iDrop.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/iDrop.java
index 397626e..1edb1c4 100644
--- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/iDrop.java
+++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/iDrop.java
@@ -59,6 +59,7 @@ import org.irods.jargon.idrop.desktop.systraygui.services.IdropConfigurationServ
import org.irods.jargon.idrop.desktop.systraygui.utils.IDropUtils;
import org.irods.jargon.idrop.desktop.systraygui.utils.IconHelper;
import org.irods.jargon.idrop.desktop.systraygui.utils.LocalFileUtils;
+import org.irods.jargon.idrop.desktop.systraygui.utils.LookAndFeelManager;
import org.irods.jargon.idrop.desktop.systraygui.utils.TreeUtils;
import org.irods.jargon.idrop.desktop.systraygui.viscomponents.IRODSFileSystemModel;
import org.irods.jargon.idrop.desktop.systraygui.viscomponents.IRODSNode;
@@ -119,7 +120,7 @@ public class iDrop extends javax.swing.JFrame implements ActionListener,
}
this.iDropCore = idropCore;
-
+
}
/** Creates new form IDrop */
@@ -181,18 +182,18 @@ public class iDrop extends javax.swing.JFrame implements ActionListener,
protected void showIdropGui() {
+
if (fileTree == null) {
buildIdropGuiComponents();
}
+ initializeLookAndFeelSelected();
-
- //buildTargetTree();
+ if (irodsTree == null) {
+ buildTargetTree();
+ }
// setting look and feel will also trigger build of irods tree view
- setLookAndFeel(iDropCore.getIdropConfig().getPropertyForKey(IdropConfigurationService.LOOK_AND_FEEL));
- setUpLocalFileSelectTree();
-
-
-
+ //setLookAndFeel(iDropCore.getIdropConfig().getPropertyForKey(IdropConfigurationService.LOOK_AND_FEEL));
+ setUpLocalFileSelectTree();
togglePauseTransfer.setSelected(pausedItem.getState());
iDropCore.getIconManager().setRunningStatus(
iDropCore.getTransferManager().getRunningStatus());
@@ -210,8 +211,8 @@ public class iDrop extends javax.swing.JFrame implements ActionListener,
}
receivedStartupSignal = true;
-
-
+
+
iDropCore.getIconManager().setRunningStatus(
iDropCore.getTransferManager().getRunningStatus());
@@ -503,7 +504,7 @@ public class iDrop extends javax.swing.JFrame implements ActionListener,
Toolkit toolkit = getToolkit();
if (e.getActionCommand().equals("Exit")) {
- shutdown();
+ shutdownWithConfirmation();
} else if (e.getActionCommand().equals("Logout")) {
this.setIrodsAccount(null);
this.signalChangeInAccountSoCachedDataCanBeCleared();
@@ -2088,7 +2089,7 @@ public class iDrop extends javax.swing.JFrame implements ActionListener,
private void jMenuItemExitActionPerformed(
final java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItemExitActionPerformed
- shutdown();
+ shutdownWithConfirmation();
}// GEN-LAST:event_jMenuItemExitActionPerformed
/**
@@ -2591,13 +2592,18 @@ public class iDrop extends javax.swing.JFrame implements ActionListener,
});
}
- private void shutdown() {
+ private void shutdownWithConfirmation() {
int result = JOptionPane.showConfirmDialog(this,
"Shut down iDrop?",
"Do you want to shut down iDrop?",
JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
- try {
+ shutdown();
+ }
+ }
+
+ private void shutdown() {
+ try {
log.info("shut down queue timer");
iDropCore.getQueueTimer().cancel();
log.info("saving current configuration to idrop.properties");
@@ -2607,81 +2613,82 @@ public class iDrop extends javax.swing.JFrame implements ActionListener,
Exceptions.printStackTrace(ex);
}
System.exit(0);
+ }
+
+ private void initializeLookAndFeelSelected() {
+ String lookAndFeelChoice = iDropCore.getIdropConfig().getPropertyForKey(IdropConfigurationService.LOOK_AND_FEEL);
+ if (lookAndFeelChoice == null || lookAndFeelChoice.isEmpty()) {
+ lookAndFeelChoice = "System";
+ }
+ if (lookAndFeelChoice.equals("Metal")) {
+
+ this.jRadioButtonMenuItemMetal.setSelected(true);
+
+ } else if (lookAndFeelChoice.equals("System")) {
+
+ this.jRadioButtonLookAndFeelDefault.setSelected(true);
+ } else if (lookAndFeelChoice.equals("Motif")) {
+
+ this.jRadioButtonMenuItemMotif.setSelected(true);
+ } else if (lookAndFeelChoice.equals("GTK")) {
+
+ this.jRadioButtonMenuItemGTK.setSelected(true);
+ } else if (lookAndFeelChoice.equals("Nimbus")) {
+ this.jRadioButtonLookAndFeelNimbus.setSelected(true);
+
+ } else {
+ this.jRadioButtonLookAndFeelDefault.setSelected(true);
}
}
private void setLookAndFeel(String lookAndFeelChoice) {
+
+ int result = JOptionPane.showConfirmDialog(this,
+
+ "Changing the look and feel requires a restart, would you like to change the look and feel?",
+ "iDrop - Confirm change look and feel",
+ JOptionPane.OK_CANCEL_OPTION);
+ if (result == JOptionPane.CANCEL_OPTION) {
+ return;
+ }
+
String lookAndFeel = "";
if (lookAndFeelChoice == null) {
- lookAndFeelChoice="System";
+ lookAndFeelChoice = "System";
}
-
+
if (lookAndFeelChoice != null) {
- try {
- iDropCore.getIdropConfigurationService().updateConfig(IdropConfigurationService.LOOK_AND_FEEL, lookAndFeelChoice);
- } catch (IdropException ex) {
- log.error("unable to update configration for look and feel");
- throw new IdropRuntimeException("unable to set prop for look and feel", ex);
- }
+
if (lookAndFeelChoice.equals("Metal")) {
- lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
+ lookAndFeel = lookAndFeelChoice;
this.jRadioButtonMenuItemMetal.setSelected(true);
// an alternative way to set the Metal L&F is to replace the
// previous line with:
// lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel";
} else if (lookAndFeelChoice.equals("System")) {
- lookAndFeel = UIManager.getSystemLookAndFeelClassName();
+ lookAndFeel = lookAndFeelChoice;
this.jRadioButtonLookAndFeelDefault.setSelected(true);
} else if (lookAndFeelChoice.equals("Motif")) {
- lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
- this.jRadioButtonMenuItemMotif.setSelected(true);
+ lookAndFeel = lookAndFeelChoice;
+ this.jRadioButtonMenuItemMotif.setSelected(true);
} else if (lookAndFeelChoice.equals("GTK")) {
- lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
- this.jRadioButtonMenuItemGTK.setSelected(true);
+ lookAndFeel = lookAndFeelChoice;
+ this.jRadioButtonMenuItemGTK.setSelected(true);
} else if (lookAndFeelChoice.equals("Nimbus")) {
this.jRadioButtonLookAndFeelNimbus.setSelected(true);
- for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- lookAndFeel = info.getClassName();
- break;
- }
- }
+ lookAndFeel = lookAndFeelChoice;
} else {
- lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
- }
-
- if (lookAndFeel.equals("")) {
- lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
+ lookAndFeel = "System";
}
-
-
- final String finalLookAndFeel = lookAndFeel;
- final iDrop thisGui = this;
-
-
-
- java.awt.EventQueue.invokeLater(new Runnable() {
-
- @Override
- public void run() {
-
- try {
- UIManager.setLookAndFeel(finalLookAndFeel);
- //thisGui.getIrodsTree().updateUI();
- SwingUtilities.updateComponentTreeUI(thisGui);
- thisGui.irodsTree = null;
- thisGui.buildTargetTree();
- thisGui.pack();
-
- } catch (Exception e) {
- log.warn("unable to set look and feel to :{}", finalLookAndFeel);
- }
- }
- });
-
-
+ try {
+ LookAndFeelManager laf = new LookAndFeelManager(iDropCore);
+ laf.setLookAndFeel(lookAndFeel);
+ shutdown();
+ } catch (Exception e) {
+ log.warn("unable to set look and feel to :{}", lookAndFeel);
+ }
}
}
diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImpl.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImpl.java
index 7748637..afd5df0 100644
--- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImpl.java
+++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImpl.java
@@ -73,7 +73,7 @@ public class IdropConfigurationServiceImpl implements IdropConfigurationService
Properties databaseProperties;
Properties configFileProperties;
try {
- databaseProperties = configurationService.exportProperties();
+ databaseProperties = configurationService.exportProperties();
configFileProperties = this.importPropertiesFromDefaultFile();
} catch (Exception ex) {
diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/utils/LookAndFeelManager.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/utils/LookAndFeelManager.java
new file mode 100644
index 0000000..ccf3a74
--- /dev/null
+++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/utils/LookAndFeelManager.java
@@ -0,0 +1,105 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.irods.jargon.idrop.desktop.systraygui.utils;
+
+import javax.swing.UIManager;
+import javax.swing.UIManager.LookAndFeelInfo;
+import org.irods.jargon.idrop.desktop.systraygui.IDROPCore;
+import org.irods.jargon.idrop.desktop.systraygui.services.IdropConfigurationService;
+import org.irods.jargon.idrop.exceptions.IdropException;
+import org.irods.jargon.idrop.exceptions.IdropRuntimeException;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Mike Conway - DICE (www.irods.org)
+ */
+public class LookAndFeelManager {
+
+ private final IDROPCore idropCore;
+ private static final org.slf4j.Logger log = LoggerFactory.getLogger(LookAndFeelManager.class);
+
+ public LookAndFeelManager(final IDROPCore idropCore) {
+ if (idropCore == null) {
+ throw new IllegalArgumentException("null idropCore");
+ }
+ if (idropCore.getIdropConfig() == null) {
+ throw new IllegalArgumentException("idropConfig is null in idropCore");
+ }
+ if (idropCore.getIdropConfigurationService() == null) {
+ throw new IllegalArgumentException("idropConfigurationService in idropCore is null");
+ }
+ this.idropCore = idropCore;
+ }
+
+ public void setLookAndFeel(String lookAndFeelChoice) {
+ String lookAndFeel = "";
+ if (lookAndFeelChoice == null) {
+ lookAndFeelChoice = "System";
+ }
+
+ log.info("setLookAndFeel to:{}", lookAndFeelChoice);
+
+ if (lookAndFeelChoice != null) {
+ try {
+ idropCore.getIdropConfigurationService().updateConfig(IdropConfigurationService.LOOK_AND_FEEL, lookAndFeelChoice);
+ } catch (IdropException ex) {
+ log.error("unable to update configration for look and feel");
+ throw new IdropRuntimeException("unable to set prop for look and feel", ex);
+ }
+ if (lookAndFeelChoice.equals("Metal")) {
+ lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
+
+ // an alternative way to set the Metal L&F is to replace the
+ // previous line with:
+ // lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel";
+
+ } else if (lookAndFeelChoice.equals("System")) {
+ lookAndFeel = UIManager.getSystemLookAndFeelClassName();
+
+ } else if (lookAndFeelChoice.equals("Motif")) {
+ lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
+
+ } else if (lookAndFeelChoice.equals("GTK")) {
+ lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
+
+ } else if (lookAndFeelChoice.equals("Nimbus")) {
+
+ for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
+ if ("Nimbus".equals(info.getName())) {
+ lookAndFeel = info.getClassName();
+ break;
+ }
+ }
+ } else {
+ lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
+ }
+
+ if (lookAndFeel.equals("")) {
+ lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
+
+ }
+
+
+ final String finalLookAndFeel = lookAndFeel;
+
+
+
+ java.awt.EventQueue.invokeLater(new Runnable() {
+
+ @Override
+ public void run() {
+
+ try {
+ UIManager.setLookAndFeel(finalLookAndFeel);
+ } catch (Exception e) {
+ log.warn("unable to set look and feel to :{}", finalLookAndFeel);
+ }
+ }
+ });
+
+
+ }
+ }
+}
diff --git a/idrop-swing/src/test/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImplTest.java b/idrop-swing/src/test/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImplTest.java
index a017ae0..5ea8333 100644
--- a/idrop-swing/src/test/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImplTest.java
+++ b/idrop-swing/src/test/java/org/irods/jargon/idrop/desktop/systraygui/services/IdropConfigurationServiceImplTest.java
@@ -70,7 +70,6 @@ public class IdropConfigurationServiceImplTest {
configurationService.importProperties(testProps);
Properties myProps = idropConfigurationService.bootstrapConfiguration();
Assert.assertNotNull("null props returned", myProps);
- Assert.assertEquals(1, myProps.size());
Assert.assertEquals(testPropVal, myProps.get(testPropKey));
}