Subversion Repositories svn.mios

Compare Revisions

Ignore whitespace Rev 740 → Rev 741

/trunk/java/MIOSStudioSID.java
26,29 → 26,21
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.prefs.Preferences;
 
import javax.swing.JApplet;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenuItem;
import javax.swing.UIManager;
 
import org.midibox.apps.miosstudio.gui.MIOSStudioGUI.ExternalCommandButton;
import org.midibox.apps.miosstudio.xml.MIOSStudioXML;
import org.midibox.apps.miosstudio.gui.MIOSStudioGUI;
import org.midibox.apps.miosstudiosid.gui.MIOSStudioSIDGUI;
import org.midibox.midi.gui.MidiFilterGUI;
import org.midibox.mios.gui.HexFileUploadGUI;
import org.midibox.apps.miosstudiosid.gui.xml.MIOSStudioSIDGUIXML;
import org.midibox.utils.gui.DialogOwner;
import org.midibox.utils.gui.ImageLoader;
import org.midibox.utils.gui.SplashScreen;
 
/**
* Driver class for launching MIOS Studio + SID V2 application. MIOS Studio can
* be launched as an application or embedded in a a web page as an applet. When
* Driver class for launching MIOS Studio application. MIOS Studio can be
* launched as an application or embedded in a a web page as an applet. When
* launched as an application, the app shows a splash screen and is launched
* within its own frame. Preferences are saved and restored from this class.
*
57,205 → 49,67
 
public class MIOSStudioSID extends JApplet {
 
protected static Preferences preferences = Preferences.userRoot().node(
"org/midibox/miostudiosid/gui");
 
protected static String configFileName = ".miosstudiosid";
 
protected static String frameTitle = "MIOS Studio + SID V2 Editor";
 
protected static String splashTitle = "MIOS Studio beta 9 + SID V2 Editor";
protected static String splashTitle = "MIOS Studio beta 9.1 + SID V2 Editor";
 
protected static String splashImage = "splash.jpg";
 
protected static String frameComment = "MIOS Studio beta 9 + SID V2 Editor";
protected static String frameComment = "MIOS Studio beta 9.1";
 
protected org.midibox.apps.miosstudiosid.MIOSStudioSID miosStudioSID;
 
protected MIOSStudioSIDGUI miosStudioSIDGUI;
 
protected Hashtable windows;
 
public MIOSStudioSID() {
 
this.miosStudioSID = new org.midibox.apps.miosstudiosid.MIOSStudioSID();
File configFile = new File(System.getProperty("user.home"),
configFileName);
 
loadConfigFile();
if (configFile.exists()) {
 
try {
UIManager.setLookAndFeel(preferences.get("lookAndFeel", UIManager
.getCrossPlatformLookAndFeelClassName()));
} catch (Exception e) {
System.out.println(e.toString());
}
MIOSStudioSIDGUIXML miosStudioSIDGUIXML = new MIOSStudioSIDGUIXML(
miosStudioSID, MIOSStudioSIDGUIXML.TAG_ROOT_ELEMENT, true, true);
 
JDialog.setDefaultLookAndFeelDecorated(preferences.getBoolean(
"defaultDecoratedFrames", false));
miosStudioSIDGUIXML.loadXML(configFile);
 
this.miosStudioSIDGUI = new MIOSStudioSIDGUI(miosStudioSID);
miosStudioSIDGUI.setCommentLabel(frameComment);
this.miosStudioSIDGUI = (MIOSStudioSIDGUI) miosStudioSIDGUIXML.getMiosStudioGUI();
}
if (miosStudioSIDGUI == null) {
 
this.windows = new Hashtable();
this.miosStudioSIDGUI = new MIOSStudioSIDGUI(miosStudioSID);
}
 
setContentPane(miosStudioSIDGUI);
 
setJMenuBar(miosStudioSIDGUI.createMenuBar());
miosStudioSIDGUI.setCommentLabel(frameComment);
}
 
public void init() {
 
HexFileUploadGUI.setCurrentDirectory(preferences.get(
"uploadCurrentDirectory", HexFileUploadGUI
.getCurrentDirectory()));
 
MIOSStudioSIDGUI.setCurrentDirectory(preferences.get(
"workspaceCurrentDirectory", MIOSStudioSIDGUI
.getCurrentDirectory()));
 
MidiFilterGUI.setCurrentDirectory(preferences.get(
"filterCurrentDirectory", MidiFilterGUI.getCurrentDirectory()));
 
String[] frames = preferences.get("visibleFrames", "").split(",");
String[] ec = preferences.get("externalCommands", "").split("\n");
 
createWindowsHashtable();
 
Enumeration keys = windows.keys();
 
int windowNo = 0;
 
while (keys.hasMoreElements()) {
String keyName = (String) keys.nextElement();
 
JInternalFrame window = (JInternalFrame) windows.get(keyName);
 
int x = preferences.getInt(keyName + "X", 20 * windowNo);
int y = preferences.getInt(keyName + "Y", 20 * windowNo);
int width = preferences.getInt(keyName + "Width", window
.getPreferredSize().width);
int height = preferences.getInt(keyName + "Height", window
.getPreferredSize().height);
 
Dimension d = window.getPreferredSize();
 
if (window.isResizable()) {
window.setBounds(x, y, Math.max(width, d.width), Math.max(
height, d.height));
} else {
window.setBounds(x, y, d.width, d.height);
}
 
if (preferences.getBoolean(keyName + "Visible", false)) {
miosStudioSIDGUI.showFrame(window);
try {
window.setMaximum(preferences.getBoolean(keyName
+ "Maximized", false));
window.setIcon(preferences.getBoolean(
keyName + "Iconified", false));
} catch (Exception e) {
System.out.println(e.toString());
}
}
 
windowNo++;
}
 
for (int i = frames.length - 1; i >= 0; i--) {
if (windows.containsKey(frames[i])) {
((JInternalFrame) windows.get(frames[i])).toFront();
}
}
 
for (int i = 0; i < ec.length; i++) {
String[] temp = ec[i].split("\t");
if (temp.length == 2) {
miosStudioSIDGUI.addExternalCommandButton(temp[0], temp[1]);
}
}
}
 
public void destroy() {
 
saveConfigFile();
 
preferences.put("lookAndFeel", miosStudioSIDGUI.getLookAndFeel());
preferences.putBoolean("defaultDecoratedFrames", miosStudioSIDGUI
.isDefaultDecoratedFrames());
 
preferences.put("uploadCurrentDirectory", HexFileUploadGUI
.getCurrentDirectory());
 
preferences.put("workspaceCurrentDirectory", MIOSStudioSIDGUI
.getCurrentDirectory());
 
preferences.put("filterCurrentDirectory", MidiFilterGUI
.getCurrentDirectory());
 
JInternalFrame[] frames = miosStudioSIDGUI.getDesktop().getAllFrames();
String visibleFrames = "";
 
for (int i = 0; i < frames.length; i++) {
Enumeration keys = windows.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
if (windows.get(key) == frames[i]) {
visibleFrames += (key + ",");
}
}
}
 
preferences.put("visibleFrames", visibleFrames);
 
Enumeration keys = windows.keys();
while (keys.hasMoreElements()) {
String keyName = (String) keys.nextElement();
JInternalFrame window = (JInternalFrame) windows.get(keyName);
 
boolean visible = window.isVisible();
try {
preferences.putBoolean(keyName + "Iconified", window.isIcon());
preferences.putBoolean(keyName + "Maximized", window
.isMaximum());
window.setIcon(false);
window.setMaximum(false);
} catch (Exception e) {
System.out.println(e);
}
preferences.putInt(keyName + "X", window.getX());
preferences.putInt(keyName + "Y", window.getY());
preferences.putInt(keyName + "Width", window.getWidth());
preferences.putInt(keyName + "Height", window.getHeight());
preferences.putBoolean(keyName + "Visible", visible);
}
 
String externalCommandsString = "";
 
for (int i = 0; i < miosStudioSIDGUI.getExternalCommands().size(); i++) {
ExternalCommandButton ecb = (ExternalCommandButton) miosStudioSIDGUI
.getExternalCommands().elementAt(i);
externalCommandsString += ecb.commandName + "\t"
+ ecb.externalCommand + "\n";
}
preferences.put("externalCommands", externalCommandsString);
}
 
public void exit(JFrame frame) {
 
preferences.putInt("mainWindowX", frame.getX());
preferences.putInt("mainWindowY", frame.getY());
preferences.putInt("mainWindowWidth", frame.getWidth());
preferences.putInt("mainWindowHeight", frame.getHeight());
 
System.exit(0);
}
 
protected void saveConfigFile() {
 
File configFile = new File(System.getProperty("user.home"),
configFileName);
 
if (!configFile.exists()) {
 
try {
 
configFile.createNewFile();
 
} catch (Exception e) {
 
e.printStackTrace();
}
}
262,62 → 116,14
 
if (configFile.exists()) {
 
MIOSStudioXML miosStudioXML = new MIOSStudioXML(miosStudioSID,
MIOSStudioXML.TAG_ROOT_ELEMENT);
MIOSStudioSIDGUIXML miosStudioSIDGUIXML = new MIOSStudioSIDGUIXML(
miosStudioSIDGUI, MIOSStudioSIDGUIXML.TAG_ROOT_ELEMENT, true,
true);
 
miosStudioXML.saveXML(configFile);
miosStudioSIDGUIXML.saveXML(configFile);
}
}
 
protected void loadConfigFile() {
 
File configFile = new File(System.getProperty("user.home"),
configFileName);
 
if (configFile.exists()) {
 
MIOSStudioXML miosStudioXML = new MIOSStudioXML(miosStudioSID,
MIOSStudioXML.TAG_ROOT_ELEMENT);
 
miosStudioXML.loadXML(configFile);
 
} else {
 
miosStudioSID.getHexFileUploadDeviceManager()
.newHexFileUploadDevice();
}
}
 
protected void createWindowsHashtable() {
 
windows.put("midiDevicesWindow", miosStudioSIDGUI
.getMidiDeviceRoutingWindow());
windows.put("midiOutPortMonitorWindow", miosStudioSIDGUI
.getMidiOutPortMonitorWindow());
windows.put("midiInPortMonitorWindow", miosStudioSIDGUI
.getMidiInPortMonitorWindow());
windows.put("virtualKeyboardWindow", miosStudioSIDGUI
.getMidiKeyboardControllerWindow());
/*
* windows.put("sysexWindow", miosStudioGUI
* .getSysexSendReceiveDeviceManagerWindow());
*/
 
windows.put("uploadWindow", miosStudioSIDGUI
.getHexFileUploadDeviceManagerWindow());
windows.put("lcdWindow", miosStudioSIDGUI.getLcdMessageWindow());
windows.put("debugWindow", miosStudioSIDGUI.getDebugFunctionWindow());
windows.put("miosTerminalWindow", miosStudioSIDGUI
.getMIOSTerminalWindow());
windows
.put("sidv2librarianWindow",
((MIOSStudioSIDGUI) miosStudioSIDGUI)
.getSidv2librarianWindow());
 
windows.put("helpWindow", miosStudioSIDGUI.getHelpWindow());
 
}
 
public static void main(String[] args) {
 
SplashScreen splashScreen = new SplashScreen(splashImage, splashTitle);
330,16 → 136,6
 
splashScreen.setVisible(true);
 
try {
UIManager.setLookAndFeel(preferences.get("lookAndFeel", UIManager
.getCrossPlatformLookAndFeelClassName()));
} catch (Exception e) {
System.out.println(e.toString());
}
 
JFrame.setDefaultLookAndFeelDecorated(preferences.getBoolean(
"defaultDecoratedFrames", false));
 
final JFrame frame = new JFrame(frameTitle);
 
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
346,17 → 142,16
 
DialogOwner.setFrame(frame);
 
frame.setIconImage(ImageLoader.getImageIcon("ucIcon.png").getImage());
 
frame.setBounds(50, 50, (screenSize.width - 100), (screenSize.height - 100));
final MIOSStudioSID miosStudioSID = new MIOSStudioSID();
 
miosStudioSID.init();
 
frame.setContentPane(miosStudioSID);
frame.setIconImage(ImageLoader.getImageIcon("ucIcon.png").getImage());
 
frame.setBounds(preferences.getInt("mainWindowX", 50), preferences
.getInt("mainWindowY", 50), preferences.getInt(
"mainWindowWidth", (screenSize.width - 100)), preferences
.getInt("mainWindowHeight", (screenSize.height - 100)));
 
JMenuItem exitMenuItem = new JMenuItem("Exit");
exitMenuItem.setMnemonic(KeyEvent.VK_X);
exitMenuItem.setActionCommand("exit");
363,8 → 158,10
 
exitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
miosStudioSID.destroy();
miosStudioSID.exit(frame);
 
System.exit(0);
}
});
 
372,8 → 169,10
 
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
miosStudioSID.destroy();
miosStudioSID.exit(frame);
 
System.exit(0);
}
});