KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > upgrade > Upgrade


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.upgrade;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.awt.FlowLayout JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.ActionListener JavaDoc;
27 import java.awt.event.WindowAdapter JavaDoc;
28 import java.awt.event.WindowEvent JavaDoc;
29
30 import javax.swing.ImageIcon JavaDoc;
31 import javax.swing.JButton JavaDoc;
32 import javax.swing.JFrame JavaDoc;
33 import javax.swing.JPanel JavaDoc;
34 import javax.swing.SwingConstants JavaDoc;
35
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
38
39 /**
40  * Update from version 0.1.16 to 0.2.5+
41  *
42  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
43  */

44 public class Upgrade {
45
46     static {
47         System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
48         System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "debug");
49     }
50
51     final static Log log = LogFactory.getLog(Upgrade.class);
52
53     /**
54      * @param args
55      * @throws Exception on any error
56      */

57     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
58
59         boolean gui = System.getProperty("os.name").toLowerCase().startsWith("windows") || System.getenv("DISPLAY") != null;
60
61         if (args.length == 2 || !gui) {
62             Upgrader upgrader = new CommandLineUpgrader(args);
63             upgrader.upgrade();
64         } else {
65             JFrame JavaDoc f = new JFrame JavaDoc("0.1.16 to 0.2.5+ Upgrader");
66             final Upgrader upgrader = new GUIUpgrader();
67             f.setIconImage(new ImageIcon JavaDoc(Upgrade.class.getResource("upgrader-32x32.png")).getImage());
68             f.getContentPane().setLayout(new BorderLayout JavaDoc());
69             f.getContentPane().add((JPanel JavaDoc)upgrader, BorderLayout.CENTER);
70             f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
71             JPanel JavaDoc bp = new JPanel JavaDoc(new FlowLayout JavaDoc(FlowLayout.RIGHT));
72             final JButton JavaDoc start = new JButton JavaDoc("Start");;
73             final JButton JavaDoc close = new JButton JavaDoc("Close");
74             start.addActionListener(new ActionListener JavaDoc() {
75                 public void actionPerformed(ActionEvent JavaDoc e) {
76                     try {
77                         start.setEnabled(false);
78                         close.setEnabled(false);
79                         upgrader.upgrade();
80                     }
81                     catch(Exception JavaDoc ex) {
82                         upgrader.error("Failed to upgrade.", ex);
83                     }
84                     finally {
85                         close.setEnabled(true);
86                     }
87                 }
88             });
89             close.addActionListener(new ActionListener JavaDoc() {
90                 public void actionPerformed(ActionEvent JavaDoc e) {
91                     if(close.isEnabled())
92                         System.exit(0);
93                 }
94             });
95             bp.add(start);
96             bp.add(close);
97             f.getContentPane().add(bp, BorderLayout.SOUTH);
98             f.addWindowListener(new WindowAdapter JavaDoc() {
99                 public void windowClosing(WindowEvent JavaDoc evt) {
100                     if(close.isEnabled())
101                         System.exit(0);
102                 }
103             });
104             f.setSize(new Dimension JavaDoc(480, 460));
105             UIUtil.positionComponent(SwingConstants.CENTER, f);
106             f.setVisible(true);
107         }
108     }
109
110 }
111
Popular Tags