psmith      2003/06/17 19:07:54

  Modified:    src/java/org/apache/log4j/chainsaw FileSaveAction.java
                        FileLoadAction.java
  Log:
  Fixed bug where background thread could prevent proper L&F change.
  
  Fixed this by REMOVING the background thread, and the chooser
  is just created the first time it is accessed.  Makes the startup
  of Chainsaw quicker, but defers the cost of creation till the first
  usage, so there's noticable lag the first time.  This seems acceptable
  given the complexities involved in a whole bunch of synchronization
  /rendevousing.   Much easier to understand.
  
  Revision  Changes    Path
  1.9       +8 -30     
jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/FileSaveAction.java
  
  Index: FileSaveAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/FileSaveAction.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FileSaveAction.java       18 Jun 2003 01:55:41 -0000      1.8
  +++ FileSaveAction.java       18 Jun 2003 02:07:54 -0000      1.9
  @@ -72,6 +72,7 @@
   import javax.swing.JFileChooser;
   import javax.swing.KeyStroke;
   import javax.swing.SwingUtilities;
  +import javax.swing.plaf.FileChooserUI;
   
   
   /**
  @@ -83,7 +84,6 @@
    */
   class FileSaveAction extends AbstractAction {
     private LogUI parent;
  -  private final Object guard = new Object();
     private JFileChooser chooser = null;
   
     /**
  @@ -92,24 +92,7 @@
      *
      */
     public FileSaveAction(LogUI parent) {
  -    super("Save...");
  -
  -    Thread chooserConstructionThread =
  -      new Thread(
  -        new Runnable() {
  -          public void run() {
  -            chooser = new JFileChooser();
  -
  -            synchronized (guard) {
  -              guard.notifyAll();
  -            }
  -
  -            //      System.out.println("Constructed chooser");
  -          }
  -        });
  -
  -    chooserConstructionThread.setPriority(Thread.NORM_PRIORITY - 1);
  -    chooserConstructionThread.start();
  +    super("Save as...");
   
       putValue(
         Action.ACCELERATOR_KEY,
  @@ -122,7 +105,9 @@
     }
     
     void lookAndFeelUpdated() {
  -    SwingUtilities.updateComponentTreeUI(chooser);
  +    if (chooser !=null) {
  +      SwingUtilities.updateComponentTreeUI(chooser);
  +    }
     }
     
     /*
  @@ -133,18 +118,11 @@
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
      */
     public void actionPerformed(ActionEvent e) {
  -    synchronized (guard) {
  -      while (chooser == null) {
  -        System.out.println("Waiting on chooser construction");
   
  -        try {
  -          guard.wait();
  -        } catch (InterruptedException e1) {
  -          e1.printStackTrace();
  -        }
  -      }
  +    if( chooser == null ){
  +      chooser = new JFileChooser();
       }
  -
  +    
       chooser.setAcceptAllFileFilterUsed(true);
       chooser.setDialogTitle("Save Events to XML file...");
       chooser.showSaveDialog(parent);
  
  
  
  1.11      +5 -28     
jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/FileLoadAction.java
  
  Index: FileLoadAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/FileLoadAction.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- FileLoadAction.java       18 Jun 2003 01:55:41 -0000      1.10
  +++ FileLoadAction.java       18 Jun 2003 02:07:54 -0000      1.11
  @@ -89,27 +89,10 @@
     Decoder decoder = null;
     private LogUI parent;
     private JFileChooser chooser = null;
  -  private final Object guard = new Object();
   
     public FileLoadAction(LogUI parent, String decoder, String title) {
       super(title);
   
  -    Thread chooserConstructionThread =
  -      new Thread(
  -        new Runnable() {
  -          public void run() {
  -            chooser = new JFileChooser();
  -
  -            synchronized (guard) {
  -              guard.notifyAll();
  -            }
  -
  -            //      System.out.println("Constructed chooser");
  -          }
  -        });
  -
  -    chooserConstructionThread.setPriority(Thread.NORM_PRIORITY - 1);
  -    chooserConstructionThread.start();
   
       try {
         Class c = Class.forName(decoder);
  @@ -142,16 +125,8 @@
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
      */
     public void actionPerformed(ActionEvent e) {
  -    synchronized (guard) {
  -      while (chooser == null) {
  -        System.out.println("Waiting on chooser construction");
  -
  -        try {
  -          guard.wait();
  -        } catch (InterruptedException e1) {
  -          e1.printStackTrace();
  -        }
  -      }
  +    if( chooser == null ){
  +      chooser = new JFileChooser();
       }
   
       chooser.setDialogTitle("Load Events from XML file...");
  @@ -190,6 +165,8 @@
       }
     }
     void lookAndFeelUpdated() {
  -    SwingUtilities.updateComponentTreeUI(chooser);
  +    if (chooser!=null) {
  +      SwingUtilities.updateComponentTreeUI(chooser);
  +    }
     }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to