KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > archive > wizard > ArchiveWizard


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  * Paul Mahar
22  *
23  */

24 package org.enhydra.tool.archive.wizard;
25
26 // ToolBox
27
import org.enhydra.tool.ToolBoxInfo;
28 import org.enhydra.tool.archive.ArchiveException;
29 import org.enhydra.tool.archive.Main;
30 import org.enhydra.tool.archive.JarPlan;
31 import org.enhydra.tool.common.PathHandle;
32 import org.enhydra.tool.common.SwingUtil;
33 import org.enhydra.tool.common.wizard.TBWizard;
34
35 // JDK
36
import javax.swing.*;
37 import javax.swing.border.*;
38 import java.awt.*;
39 import java.awt.event.ActionEvent JavaDoc;
40 import java.awt.event.ActionListener JavaDoc;
41 import java.io.File JavaDoc;
42 import java.beans.*;
43 import java.util.ResourceBundle JavaDoc;
44
45 /**
46  * The ArchiveDialog defines a dialog for presenting
47  * archive wizards.
48  */

49 public class ArchiveWizard extends TBWizard {
50
51     //
52
private final static String JavaDoc ARCHIVE_TITLE = "Kelp Archive Wizard";
53
54     //
55
transient private Icon largeIcon = null;
56     transient private ArchiveSelectionPanel selectionPanel = null;
57     transient private JarPlan plan = null;
58     transient private String JavaDoc workRoot = null;
59     transient private boolean mru = true;
60
61     public ArchiveWizard() {
62         super();
63         archiveInit();
64     }
65
66     /**
67      * Get archive
68      *
69      * @return
70      * File object for archive.
71      *
72      */

73     public String JavaDoc getNewArchive() {
74         String JavaDoc newArchive = new String JavaDoc();
75
76         if (getPlan() != null) {
77             newArchive =
78                 PathHandle.createPathString(getPlan().getArchivePath());
79         }
80         return newArchive;
81     }
82
83     public JarPlan getPlan() {
84         return plan;
85     }
86
87     public void setMostRecentlyUsed(boolean b) {
88       mru = b;
89     }
90     public boolean isMostRecentlyUsed() {
91       return mru;
92     }
93
94     public void setPlan(JarPlan p) throws ArchiveException {
95         plan = p;
96         ArchiveType type = null;
97         type = ArchiveType.createType(plan);
98         type.setMostRecentlyUsed(isMostRecentlyUsed());
99         getArchiveDeck().setSelection(type);
100         getArchiveDeck().setSelectionPageHidden(true);
101     }
102
103     /**
104      * Set archive
105      *
106      * @param archive
107      * File object for archive.
108      *
109      */

110     public void readArchive(String JavaDoc archive) throws ArchiveException {
111         if (getArchiveDeck().getSelection() != null) {
112             getArchiveDeck().getSelection().readArchive(archive);
113             getArchiveDeck().readPlan();
114         }
115     }
116
117     public void setWorkingRoot(String JavaDoc r) {
118         workRoot = PathHandle.createPathString(r);
119         System.setProperty("user.dir", getWorkingRoot());
120     }
121
122     public String JavaDoc getWorkingRoot() {
123         if (workRoot == null) {
124             setWorkingRoot(System.getProperty("user.dir"));
125         }
126         return workRoot;
127     }
128
129     // overrides TBWizard
130
public void back() {
131         if (getArchiveDeck().getPageIndex() == 1) {
132             setLargeIcon(largeIcon);
133         }
134         super.back();
135     }
136
137     // overrides TBWizard
138
public void next() {
139         ArchiveType type = null;
140         if (getArchiveDeck().isSelectionPageShowing()) {
141             type = selectionPanel.getSelection();
142             try {
143                 type.setMostRecentlyUsed(isMostRecentlyUsed());
144                 getArchiveDeck().setSelection(type);
145                 setLargeIcon(null);
146                 getArchiveDeck().next();
147             } catch (ArchiveException e) {
148                 JOptionPane.showMessageDialog(getInnerPanel(),
149                                               e.getMessage(),
150                                               "Archive Wizard Error",
151                                               JOptionPane.ERROR_MESSAGE);
152                 if (Main.debug) {
153                     e.printStackTrace();
154                 }
155             }
156             refreshButtons();
157         } else {
158             super.next();
159         }
160     }
161
162     // override TBWizard
163
public void finish() {
164         try {
165             ArchiveType type = null;
166
167             getArchiveDeck().writePlan();
168             type = getArchiveDeck().getSelection();
169             type.getPlan().setClassFiltering(true);
170             type.build();
171             setPlan(type.getPlan());
172             JOptionPane.showMessageDialog(getInnerPanel(),
173                                           "Created archive:\n"
174                                           + getNewArchive(),
175                                           "Archive Complete",
176                                           JOptionPane.INFORMATION_MESSAGE);
177             type.saveDefaults();
178             super.finish();
179         } catch (ArchiveException e) {
180             if (Main.debug) {
181                 e.printStackTrace();
182             }
183             JOptionPane.showMessageDialog(getInnerPanel(), e.getMessage(),
184                                           "Archive Error",
185                                           JOptionPane.ERROR_MESSAGE);
186         }
187     }
188
189     // implements TBWizard
190
public String JavaDoc getTitle() {
191         return ARCHIVE_TITLE;
192     }
193
194     // implements TBWizard
195
protected String JavaDoc getProgressTitle() {
196         return "Archive Progress";
197     }
198
199
200     /**
201      * Add listeners and other items that are not generated by
202      * the JBuilder designer.
203      */

204     private void archiveInit() {
205         ArchiveDeck newDeck = null;
206         ArchivePage page = null;
207
208         largeIcon = getLargeIcon();
209         newDeck = new ArchiveDeck(this);
210         selectionPanel = new ArchiveSelectionPanel();
211         selectionPanel.setWizard(this);
212         setDeck(newDeck);
213         page = new ArchivePage();
214         page.setPageTitle(selectionPanel.getPageTitle());
215         page.setInstructions(selectionPanel.getInstructions());
216         page.add(selectionPanel);
217         addWizardPage(page);
218     }
219
220     private ArchiveDeck getArchiveDeck() {
221         return (ArchiveDeck) getDeck();
222     }
223
224 }
225
Popular Tags