logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject svn commit: r568858 - in /logging/chainsaw/trunk/src: changes/changes.xml main/java/org/apache/log4j/chainsaw/ChainsawTabbedPane.java main/java/org/apache/log4j/chainsaw/LogUI.java main/java/org/apache/log4j/chainsaw/SavableTabSetting.java
Date Thu, 23 Aug 2007 07:14:16 GMT
Author: psmith
Date: Thu Aug 23 00:14:15 2007
New Revision: 568858

URL: http://svn.apache.org/viewvc?rev=568858&view=rev
Log:
Bug 42883 Applied patch provided by Isuru to remember hidden log panels.

Added:
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/SavableTabSetting.java
Modified:
    logging/chainsaw/trunk/src/changes/changes.xml
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawTabbedPane.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java

Modified: logging/chainsaw/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/changes/changes.xml?rev=568858&r1=568857&r2=568858&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/changes/changes.xml (original)
+++ logging/chainsaw/trunk/src/changes/changes.xml Thu Aug 23 00:14:15 2007
@@ -33,6 +33,9 @@
 	<action dev="psmith" issue="43158" type="add due-to="Isuru Suriarachchi" due-to-email="">
 		Added ability to remember last created receivers in an xml file, and load them at startup.
 	</action>
+	<action dev="psmith" issue="ASF Bugzilla Bug 42883" type="add due-to="Isuru Suriarachchi"
due-to-email="">
+		Added ability to remember hidden log panels.
+	</action>
     </release>
   </body>
 </document>

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawTabbedPane.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawTabbedPane.java?rev=568858&r1=568857&r2=568858&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawTabbedPane.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawTabbedPane.java
Thu Aug 23 00:14:15 2007
@@ -21,12 +21,23 @@
 */
 package org.apache.log4j.chainsaw;
 
+import org.apache.log4j.chainsaw.prefs.SettingsManager;
+import org.apache.log4j.chainsaw.prefs.SettingsListener;
+import org.apache.log4j.chainsaw.prefs.LoadSettingsEvent;
+import org.apache.log4j.chainsaw.prefs.SaveSettingsEvent;
+
 import java.awt.Component;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.FileReader;
 
 import javax.swing.Icon;
 import javax.swing.JComponent;
 import javax.swing.JTabbedPane;
 
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
+
 
 /**
  * The only reason this class is needed is because
@@ -47,7 +58,11 @@
  * @author Scott Deboy <sdeboy@apache.org>
  *
  */
-class ChainsawTabbedPane extends JTabbedPane {
+
+class ChainsawTabbedPane extends JTabbedPane implements SettingsListener {
+  public SavableTabSetting tabSetting;
+  public static final String WELCOME_TAB = "Welcome";
+  public static final String DRAG_DROP_TAB = "Drag & Drop XML log files here";
   /**
    *
    * Create the tabbed pane.  
@@ -103,5 +118,64 @@
   public void remove(Component component) {
     super.remove(component);
     super.fireStateChanged();
+  }
+
+  /**
+   * Saves the state of the currently active tabs to an XML file.
+   * Only considers the Welcome, Drag and Drop and chainsaw-log
+   * panels as they are the panel which are always running. Saves
+   * whether they are hidden or not....
+   */
+
+  public void saveSettings(SaveSettingsEvent event){
+   File file = new File(SettingsManager.getInstance().getSettingsDirectory(), "tab-settings.xml");
+   XStream stream = new XStream(new DomDriver());
+   try {
+     FileWriter writer = new FileWriter(file);
+     int count = super.getTabCount();
+     String title;
+     SavableTabSetting setting = new SavableTabSetting();
+     for(int i = 0 ; i < count ; i++){
+       title = super.getTitleAt(i);
+       if(title.equals("Welcome")){
+         setting.setWelcome(true);
+       } else if (title.equals("Drag & Drop XML log files here")){
+         setting.setDragdrop(true);
+       } else if (title.equals("chainsaw-log")){
+         setting.setChainsawLog(true);
+       }
+     }
+
+     stream.toXML(setting, writer);
+     writer.close();
+
+   } catch (Exception e) {
+     e.printStackTrace();
+   }
+  }
+
+  /**
+   * Loads the saved tab setting by reading the XML file.
+   * If the file doesn't exist, all three panels should be
+   * shown as the default setting....
+   */
+
+  public void loadSettings(LoadSettingsEvent event){
+    File file = new File(SettingsManager.getInstance().getSettingsDirectory(), "tab-settings.xml");
+    XStream stream = new XStream(new DomDriver());
+    try {
+      if (file.exists()) {
+        FileReader reader = new FileReader(file);
+        tabSetting = (SavableTabSetting) stream.fromXML(reader);
+        reader.close();
+      } else {
+        tabSetting = new SavableTabSetting();
+        tabSetting.setWelcome(true);
+        tabSetting.setDragdrop(true);
+        tabSetting.setChainsawLog(true);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
   }
 }

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java?rev=568858&r1=568857&r2=568858&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java Thu Aug 23 00:14:15
2007
@@ -436,6 +436,8 @@
     setJMenuBar(getToolBarAndMenus().getMenubar());
     
     setTabbedPane(new ChainsawTabbedPane());
+    getSettingsManager().addSettingsListener(getTabbedPane());
+    getSettingsManager().configure(getTabbedPane());
     
     /**
      * This adds Drag & Drop capability to Chainsaw
@@ -487,7 +489,7 @@
   private void addDragDropPanel(){
     final JLabel lbl  = new JLabel();
     lbl.setEnabled(false);
-    final String dndTitle = "Drag & Drop XML log files here";
+    final String dndTitle = ChainsawTabbedPane.DRAG_DROP_TAB;
     SwingUtilities.invokeLater(new Runnable() {
     	public void run() {
     	    ensureWelcomePanelVisible();
@@ -849,9 +851,9 @@
           if (selectedComp instanceof LogPanel) {
             currentName = getCurrentLogPanel().getIdentifier();
           } else if (selectedComp instanceof WelcomePanel) {
-            currentName = "Welcome";
+            currentName = ChainsawTabbedPane.WELCOME_TAB;
           } else {
-            currentName = "Drag & Drop XML log files here";
+            currentName = ChainsawTabbedPane.DRAG_DROP_TAB;
           }
 
           int count = getTabbedPane().getTabCount();
@@ -1075,6 +1077,20 @@
           }
         }
       });
+
+    /**
+     * loads the saved tab settings and if there are hidden tabs,
+     * hide those tabs out of currently loaded tabs..
+     */
+
+    if (!getTabbedPane().tabSetting.isWelcome()){
+      displayPanel(ChainsawTabbedPane.WELCOME_TAB, false);
+    }
+    if (!getTabbedPane().tabSetting.isDragdrop()){
+      displayPanel(ChainsawTabbedPane.DRAG_DROP_TAB, false);
+    }
+    tbms.stateChange();
+
   }
 
   /**
@@ -1439,16 +1455,16 @@
 
   void addWelcomePanel() {
     getTabbedPane().insertTab(
-      "Welcome",  new ImageIcon(ChainsawIcons.ABOUT),welcomePanel,
+      ChainsawTabbedPane.WELCOME_TAB,  new ImageIcon(ChainsawIcons.ABOUT),welcomePanel,
       "Welcome/Help", 0);
     getTabbedPane().setSelectedComponent(welcomePanel);
-    getPanelMap().put("Welcome", welcomePanel);
+    getPanelMap().put(ChainsawTabbedPane.WELCOME_TAB, welcomePanel);
   }
 
   void removeWelcomePanel() {
     if (getTabbedPane().containsWelcomePanel()) {
       getTabbedPane().remove(
-        getTabbedPane().getComponentAt(getTabbedPane().indexOfTab("Welcome")));
+        getTabbedPane().getComponentAt(getTabbedPane().indexOfTab(ChainsawTabbedPane.WELCOME_TAB)));
     }
   }
 
@@ -1504,7 +1520,7 @@
       int index = getTabbedPane().indexOfTab(panelName);
 
       if ((index == -1) && display) {
-        if (panelName.equals("Drag & Drop XML log files here")){
+        if (panelName.equals(ChainsawTabbedPane.DRAG_DROP_TAB)){
           addDragDropPanel();
         } else {
           getTabbedPane().addTab(panelName, p);
@@ -1922,6 +1938,9 @@
             getTabbedPane().addANewTab(
               ident, thisPanel, new ImageIcon(ChainsawIcons.ANIM_RADIO_TOWER));
             thisPanel.receiveEventBatch(ident, events);
+            if(!getTabbedPane().tabSetting.isChainsawLog()){
+              displayPanel("chainsaw-log", false);
+            }
           }
         });
 

Added: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/SavableTabSetting.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/SavableTabSetting.java?rev=568858&view=auto
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/SavableTabSetting.java
(added)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/SavableTabSetting.java
Thu Aug 23 00:14:15 2007
@@ -0,0 +1,36 @@
+package org.apache.log4j.chainsaw;
+
+/**
+ * This class is used to in saving and loading the tab settings
+ * of Chainsaw....
+ */
+
+public class SavableTabSetting {
+    private boolean welcome = false;
+    private boolean dragdrop = false;
+    private boolean chainsawLog = false;
+
+    public void setDragdrop(boolean dragdrop) {
+        this.dragdrop = dragdrop;
+    }
+
+    public void setWelcome(boolean welcome) {
+        this.welcome = welcome;
+    }
+
+    public void setChainsawLog(boolean chainsawLog) {
+        this.chainsawLog = chainsawLog;
+    }
+
+    public boolean isWelcome() {
+        return welcome;
+    }
+
+    public boolean isDragdrop() {
+        return dragdrop;
+    }
+
+    public boolean isChainsawLog() {
+        return chainsawLog;
+    }
+}



Mime
View raw message