Add nascent Swing GUI

This commit is contained in:
2008-06-07 16:20:20 +00:00
parent 6714f12ca3
commit f722c07ee2
2 changed files with 143 additions and 1 deletions

View File

@ -49,6 +49,8 @@ public class AppleCommander {
if (args.length == 0) {
if (isSwtAvailable()) {
launchSwtAppleCommander(args);
} else if (isSwingAvailable()) {
launchSwingAppleCommander(args);
} else {
showHelp();
}
@ -59,6 +61,7 @@ public class AppleCommander {
launchSwtAppleCommander(args);
} else if ("-swing".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
System.err.println(textBundle.get("SwingVersionNotAvailable")); //$NON-NLS-1$
launchSwingAppleCommander(args);
} else if ("-command".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
System.err.println(textBundle.get("CommandLineNotAvailable")); //$NON-NLS-1$
} else if ("-help".equalsIgnoreCase(args[0]) //$NON-NLS-1$
@ -112,6 +115,48 @@ public class AppleCommander {
return false;
}
}
/**
* Test to see if Swing is available.
*/
protected static boolean isSwingAvailable() {
try {
Class.forName("com.webcodepro.applecommander.ui.swing.SwingAppleCommander"); //$NON-NLS-1$
return true;
} catch (ClassNotFoundException ex) {
return false;
}
}
/**
* Launch the Swing version of AppleCommander. This method
* uses reflection to load SwingAppleCommander to minimize which
* classes get loaded. This is particularly important for the
* command-line version.
*/
protected static void launchSwingAppleCommander(String[] args) {
Class swtAppleCommander;
try {
swtAppleCommander = Class.forName(
"com.webcodepro.applecommander.ui.swing.SwingAppleCommander"); //$NON-NLS-1$
Object object = swtAppleCommander.newInstance();
Method launchMethod = swtAppleCommander.
getMethod("launch", null); //$NON-NLS-1$
launchMethod.invoke(object, null);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
}
/**
* Display help message(s) for AppleCommander.
*/

View File

@ -0,0 +1,97 @@
/*
* AppleCommander - An Apple ][ image utility.
* Copyright (C) 2008 by Robert Greene
* robgreene at users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.webcodepro.applecommander.ui.swing;
import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JToolBar;
import com.webcodepro.applecommander.ui.UiBundle;
import com.webcodepro.applecommander.ui.UserPreferences;
import com.webcodepro.applecommander.util.TextBundle;
public class SwingAppleCommander extends JFrame implements ActionListener {
private UserPreferences userPreferences = UserPreferences.getInstance();
private TextBundle textBundle = UiBundle.getInstance();
/**
* Launch SwingAppleCommander.
*/
public static void main(String[] args) {
new SwingAppleCommander().launch();
}
/**
* Launch SwingAppleCommander.
*/
public void launch() {
JToolBar toolBar = new JToolBar();
JButton aButton = new JButton(textBundle.get("OpenButton"), new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/opendisk.gif")))); //$NON-NLS-1$
aButton.setToolTipText(textBundle.get("SwtAppleCommander.OpenDiskImageTooltip")); //$NON-NLS-1$
aButton.setHorizontalTextPosition(JLabel.CENTER);
aButton.setVerticalTextPosition(JLabel.BOTTOM);
toolBar.add(aButton);
JButton aButton2 = new JButton(textBundle.get("CreateButton"), new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/newdisk.gif")))); //$NON-NLS-1$
aButton2.setToolTipText(textBundle.get("SwtAppleCommander.CreateDiskImageTooltip")); //$NON-NLS-1$
aButton2.setHorizontalTextPosition(JLabel.CENTER);
aButton2.setVerticalTextPosition(JLabel.BOTTOM);
toolBar.add(aButton2);
JButton aButton3 = new JButton(textBundle.get("CompareButton"), new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/comparedisks.gif")))); //$NON-NLS-1$
aButton3.setToolTipText(textBundle.get("SwtAppleCommander.CompareDiskImageTooltip")); //$NON-NLS-1$
aButton3.setHorizontalTextPosition(JLabel.CENTER);
aButton3.setVerticalTextPosition(JLabel.BOTTOM);
toolBar.add(aButton3);
JButton aButton4 = new JButton(textBundle.get("AboutButton"), new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/about.gif")))); //$NON-NLS-1$
aButton4.setToolTipText(textBundle.get("SwtAppleCommander.AboutTooltip")); //$NON-NLS-1$
aButton4.setHorizontalTextPosition(JLabel.CENTER);
aButton4.setVerticalTextPosition(JLabel.BOTTOM);
toolBar.add(aButton4);
SwingAppleCommander application = new SwingAppleCommander();
application.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/diskicon.gif"))); //$NON-NLS-1$
application.setTitle(textBundle.get("SwtAppleCommander.AppleCommander"));
JLabel label = new JLabel(new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/AppleCommanderLogo.gif"))));
application.getContentPane().add(label, BorderLayout.CENTER);
application.getContentPane().add(toolBar, BorderLayout.NORTH);
application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
application.pack();
application.setVisible(true);
UserPreferences.getInstance().save();
}
/**
* Constructor for SwingAppleCommander.
*/
public SwingAppleCommander() {
super();
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}