KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > config > MainFrameOptionsXmlConfig


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.config;
17
18 import java.io.File JavaDoc;
19 import java.util.logging.Logger JavaDoc;
20
21 import org.columba.core.config.DefaultXmlConfig;
22 import org.columba.core.config.GuiItem;
23 import org.columba.core.config.ViewItem;
24 import org.columba.core.xml.XmlElement;
25
26
27 public class MainFrameOptionsXmlConfig extends DefaultXmlConfig {
28
29     /** JDK 1.4+ logging framework logger, used for logging. */
30     private static final Logger JavaDoc LOG = Logger.getLogger("org.columba.mail.config");
31
32     
33     GuiItem guiItem;
34    
35     ViewItem viewItem;
36     boolean initialVersionWasApplied = false;
37
38     public MainFrameOptionsXmlConfig(File JavaDoc file) {
39         super(file);
40     }
41
42     public boolean load() {
43         boolean result = super.load();
44
45         //apply initial version information
46
XmlElement root = getRoot().getElement(0);
47         String JavaDoc version = root.getAttribute("version");
48
49         if (version == null) {
50             initialVersionWasApplied = true;
51             root.addAttribute("version", "1.0");
52         }
53
54         convert();
55
56         return result;
57     }
58
59     protected void convert() {
60         // add initial messageframe treenode
61
XmlElement root = getRoot();
62         if (initialVersionWasApplied) {
63             LOG.fine("converting configuration to new version...");
64
65             XmlElement gui = root.getElement("/options/gui");
66             XmlElement messageframe = new XmlElement("messageframe");
67             gui.addElement(messageframe);
68
69             XmlElement view = new XmlElement("view");
70             messageframe.addElement(view);
71             view.addAttribute("id", "messageframe");
72
73             XmlElement window = new XmlElement("window");
74             window.addAttribute("width", "640");
75             window.addAttribute("height", "480");
76             window.addAttribute("maximized", "true");
77             view.addElement(window);
78
79             XmlElement toolbars = new XmlElement("toolbars");
80             toolbars.addAttribute("main", "true");
81             view.addElement(toolbars);
82
83             XmlElement splitpanes = new XmlElement("splitpanes");
84             splitpanes.addAttribute("main", "200");
85             splitpanes.addAttribute("header", "200");
86             splitpanes.addAttribute("attachment", "100");
87             view.addElement(splitpanes);
88         }
89     }
90
91     public ViewItem getViewItem() {
92         if (viewItem == null) {
93             viewItem = new ViewItem(getRoot().getElement("/options/gui/viewlist/view"));
94         }
95
96         return viewItem;
97     }
98
99     public GuiItem getGuiItem() {
100         if (guiItem == null) {
101             guiItem = new GuiItem(getRoot().getElement("/options/gui"));
102         }
103
104         return guiItem;
105     }
106
107 }
108
Popular Tags