2008-06-07 16:20:20 +00:00
|
|
|
/*
|
|
|
|
* AppleCommander - An Apple ][ image utility.
|
2022-01-19 03:55:20 +00:00
|
|
|
* Copyright (C) 2008-2022 by Robert Greene
|
2008-06-07 16:20:20 +00:00
|
|
|
* 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;
|
2008-06-08 03:02:53 +00:00
|
|
|
import java.io.File;
|
2008-06-07 16:20:20 +00:00
|
|
|
|
|
|
|
import javax.swing.ImageIcon;
|
|
|
|
import javax.swing.JButton;
|
2008-06-08 03:02:53 +00:00
|
|
|
import javax.swing.JFileChooser;
|
2008-06-07 16:20:20 +00:00
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JLabel;
|
2008-06-08 18:59:41 +00:00
|
|
|
import javax.swing.JMenu;
|
|
|
|
import javax.swing.JMenuBar;
|
|
|
|
import javax.swing.JMenuItem;
|
2008-06-08 03:02:53 +00:00
|
|
|
import javax.swing.JOptionPane;
|
2008-06-08 18:59:41 +00:00
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.JTabbedPane;
|
2008-06-07 16:20:20 +00:00
|
|
|
import javax.swing.JToolBar;
|
|
|
|
|
2008-06-08 03:02:53 +00:00
|
|
|
import com.webcodepro.applecommander.ui.AppleCommander;
|
2008-06-07 16:20:20 +00:00
|
|
|
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 {
|
2008-06-08 03:02:53 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private static final long serialVersionUID = -3302293994498495537L;
|
2008-06-07 16:20:20 +00:00
|
|
|
private UserPreferences userPreferences = UserPreferences.getInstance();
|
|
|
|
private TextBundle textBundle = UiBundle.getInstance();
|
2008-06-08 18:59:41 +00:00
|
|
|
private JTabbedPane tabPane;
|
|
|
|
private JLabel titleLabel;
|
2008-06-07 16:20:20 +00:00
|
|
|
/**
|
|
|
|
* Launch SwingAppleCommander.
|
|
|
|
*/
|
|
|
|
public static void main(String[] args) {
|
|
|
|
new SwingAppleCommander().launch();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Launch SwingAppleCommander.
|
|
|
|
*/
|
|
|
|
public void launch() {
|
2008-06-08 18:59:41 +00:00
|
|
|
JMenuBar menuBar = createMenuBar();
|
2008-06-07 16:20:20 +00:00
|
|
|
JToolBar toolBar = new JToolBar();
|
2008-06-08 18:59:41 +00:00
|
|
|
JPanel topPanel = new JPanel(new BorderLayout());
|
|
|
|
tabPane = new JTabbedPane(JTabbedPane.TOP);
|
|
|
|
topPanel.add(menuBar,BorderLayout.NORTH);
|
|
|
|
topPanel.add(toolBar,BorderLayout.SOUTH);
|
2008-06-07 16:20:20 +00:00
|
|
|
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);
|
2008-06-08 03:02:53 +00:00
|
|
|
aButton.addActionListener(this);
|
2008-06-07 16:20:20 +00:00
|
|
|
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);
|
2008-06-08 03:02:53 +00:00
|
|
|
aButton2.addActionListener(this);
|
2008-06-07 16:20:20 +00:00
|
|
|
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);
|
2008-06-08 03:02:53 +00:00
|
|
|
aButton3.addActionListener(this);
|
2008-06-07 16:20:20 +00:00
|
|
|
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);
|
2008-06-08 03:02:53 +00:00
|
|
|
aButton4.addActionListener(this);
|
2008-06-07 16:20:20 +00:00
|
|
|
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"));
|
2018-03-29 02:10:08 +00:00
|
|
|
|
|
|
|
titleLabel = new JLabel(new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/AppleCommanderLogo.jpg"))));
|
|
|
|
|
2008-06-08 18:59:41 +00:00
|
|
|
addTitleTabPane();
|
|
|
|
application.getContentPane().add(topPanel, BorderLayout.NORTH);
|
|
|
|
application.getContentPane().add(tabPane, BorderLayout.CENTER);
|
2008-06-07 16:20:20 +00:00
|
|
|
application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
|
|
application.pack();
|
|
|
|
application.setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for SwingAppleCommander.
|
|
|
|
*/
|
|
|
|
public SwingAppleCommander() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2008-06-08 03:02:53 +00:00
|
|
|
if (e.getActionCommand().equals(textBundle.get("AboutButton"))) { //$NON-NLS-1$
|
|
|
|
showAboutAppleCommander();
|
2008-06-08 18:59:41 +00:00
|
|
|
} else if ((e.getActionCommand().equals(textBundle.get("OpenButton"))) || //$NON-NLS-1$
|
|
|
|
(e.getActionCommand().equals(textBundle.get("SwingAppleCommander.MenuFileOpen")))) {
|
2008-06-08 03:02:53 +00:00
|
|
|
openFile();
|
2008-06-08 18:59:41 +00:00
|
|
|
} else if (e.getActionCommand().equals(textBundle.get("SwingAppleCommander.MenuFileClose"))) {
|
|
|
|
closeFile();
|
|
|
|
} else if (e.getActionCommand().equals(textBundle.get("SwingAppleCommander.MenuFileQuit"))) { //$NON-NLS-1$
|
|
|
|
UserPreferences.getInstance().save();
|
|
|
|
setVisible(false);
|
|
|
|
dispose();
|
|
|
|
System.exit(0);
|
|
|
|
} else {
|
|
|
|
System.out.println("Unhandled action: "+e.getActionCommand());
|
2008-06-08 03:02:53 +00:00
|
|
|
}
|
2008-06-07 16:20:20 +00:00
|
|
|
}
|
|
|
|
|
2008-06-08 18:59:41 +00:00
|
|
|
/**
|
|
|
|
* Set up the menu bar
|
|
|
|
*/
|
|
|
|
JMenuBar createMenuBar() {
|
|
|
|
JMenuBar menuBar = new JMenuBar();
|
|
|
|
// File
|
|
|
|
JMenu menuFile = new JMenu(textBundle.get("SwingAppleCommander.MenuFile")); //$NON-NLS-1$
|
|
|
|
// File->Open
|
|
|
|
JMenuItem openItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileOpen")); //$NON-NLS-1$
|
|
|
|
openItem.addActionListener(this);
|
|
|
|
menuFile.add(openItem);
|
|
|
|
// File->Close
|
|
|
|
JMenuItem closeItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileClose")); //$NON-NLS-1$
|
|
|
|
closeItem.addActionListener(this);
|
|
|
|
menuFile.add(closeItem);
|
|
|
|
// File->New
|
|
|
|
JMenuItem newItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileNew")); //$NON-NLS-1$
|
|
|
|
newItem.addActionListener(this);
|
|
|
|
menuFile.add(newItem);
|
|
|
|
// File->Exit
|
|
|
|
JMenuItem quitItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileQuit")); //$NON-NLS-1$
|
|
|
|
quitItem.addActionListener(this);
|
|
|
|
menuFile.add(quitItem);
|
|
|
|
menuBar.add(menuFile);
|
|
|
|
return menuBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the title tab.
|
|
|
|
*/
|
|
|
|
void addTitleTabPane() {
|
|
|
|
tabPane.add(textBundle.get("SwtAppleCommander.AppleCommander"),titleLabel);
|
|
|
|
}
|
|
|
|
|
2008-06-08 03:02:53 +00:00
|
|
|
/**
|
|
|
|
* Open a file.
|
|
|
|
*/
|
|
|
|
protected void openFile() {
|
|
|
|
JFileChooser jc = new JFileChooser();
|
2009-06-01 16:04:13 +00:00
|
|
|
String pathName = userPreferences.getDiskImageDirectory();
|
|
|
|
if (null == pathName) {
|
|
|
|
pathName = ""; //$NON-NLS-1$
|
|
|
|
}
|
|
|
|
jc.setCurrentDirectory(new File(pathName));
|
2008-06-08 03:02:53 +00:00
|
|
|
EmulatorFileFilter ff = new EmulatorFileFilter();
|
|
|
|
jc.setFileFilter(ff);
|
|
|
|
int rc = jc.showDialog(this, textBundle.get("Open")); //$NON-NLS-1$
|
|
|
|
if (rc == 0) {
|
|
|
|
userPreferences.setDiskImageDirectory(jc.getSelectedFile().getParent());
|
|
|
|
UserPreferences.getInstance().save();
|
2008-08-13 20:33:55 +00:00
|
|
|
addDiskExplorerTab(jc.getSelectedFile());
|
2008-06-08 18:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-13 20:33:55 +00:00
|
|
|
protected void addDiskExplorerTab(File file) {
|
|
|
|
if (tabPane.getTitleAt(0).equals(textBundle.get("SwtAppleCommander.AppleCommander"))) {
|
|
|
|
tabPane.remove(0);
|
|
|
|
}
|
|
|
|
tabPane.add(file.getName(),new DiskExplorer());
|
|
|
|
tabPane.setSelectedIndex(tabPane.getTabCount()-1);
|
|
|
|
}
|
2008-06-08 18:59:41 +00:00
|
|
|
/**
|
|
|
|
* Close a file.
|
|
|
|
*/
|
|
|
|
protected void closeFile() {
|
|
|
|
if (!tabPane.getTitleAt(0).equals(textBundle.get("SwtAppleCommander.AppleCommander"))) {
|
|
|
|
tabPane.remove(tabPane.getSelectedIndex());
|
|
|
|
}
|
|
|
|
if (tabPane.getTabCount() == 0) {
|
|
|
|
addTitleTabPane();
|
2008-06-08 03:02:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showAboutAppleCommander() {
|
|
|
|
JOptionPane.showMessageDialog(null,
|
|
|
|
textBundle.format("SwtAppleCommander.AboutMessage", //$NON-NLS-1$
|
2019-10-06 18:17:46 +00:00
|
|
|
AppleCommander.VERSION, textBundle.get("Copyright")),
|
|
|
|
textBundle.get("SwtAppleCommander.AboutTitle"), //$NON-NLS-1$
|
2008-06-08 03:02:53 +00:00
|
|
|
JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
}
|
2008-06-07 16:20:20 +00:00
|
|
|
}
|