package de.onyxbits.giftedmotion;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.net.*;
/**
* Core class
*/
public class Core extends JFrame implements WindowListener, ActionListener,
ComponentListener, MouseMotionListener, MouseListener {
/**
* Program version as shown in the title
*/
public static final String VERSION="GiftedMotion "+Package.getPackage("de.onyxbits.giftedmotion").getImplementationVersion();
/**
* Back reference to the running program
*/
public static Core app;
/**
* Quit program
*/
private JMenuItem quit = new JMenuItem(Dict.get("core.quit"),KeyEvent.VK_Q);
/**
* Load files
*/
private JMenuItem load = new JMenuItem(Dict.get("core.load"),KeyEvent.VK_L);
/**
* Export as animated GIF
*/
private JMenuItem export = new JMenuItem(Dict.get("core.export"),KeyEvent.VK_S);
/**
* Save the sequence as individual files
*/
private JMenuItem extract = new JMenuItem(Dict.get("core.extract"),KeyEvent.VK_E);
/**
* Display license
*/
private JMenuItem license = new JMenuItem(Dict.get("core.license"));
/**
* Go to homepage
*/
private JMenuItem handbook = new JMenuItem(Dict.get("core.handbook"));
/**
* Go to FAQ
*/
private JMenuItem faq = new JMenuItem(Dict.get("core.faq"));
/**
* Play animation
*/
private JButton play = new JButton(IO.createIcon("Tango/22x22/actions/media-playback-start.png",Dict.get("core.play")));
/**
* Pause animation
*/
private JButton pause = new JButton(IO.createIcon("Tango/22x22/actions/media-playback-pause.png",Dict.get("core.pause")));
/**
* Record (same as export)
*/
private JButton record = new JButton(IO.createIcon("Tango/22x22/actions/media-record.png",Dict.get("core.record")));
/**
* Import (same as load)
*/
private JButton open = new JButton(IO.createIcon("Tango/22x22/actions/document-open.png",Dict.get("core.open")));
/**
* Toggle displaying of the settings window
*/
private JButton togglesettings = new JButton(IO.createIcon("Tango/22x22/categories/preferences-desktop.png",Dict.get("core.togglesettings")));
/**
* Sequence Editor
*/
private SequenceEditor seqedit;
/**
* Frame Display
*/
private FrameDisplay display;
/**
* Settings editor
*/
private SettingsEditor setedit = new SettingsEditor();
/**
* The main workspace
*/
private JDesktopPane workspace = new JDesktopPane();
/**
* The framesequence being worked upon
*/
private FrameSequence seq;
/**
* Directory, to open filedialogs with
*/
private File directory = new File(System.getProperty("user.dir"));
/**
* Used for doing an animation preview
*/
private Player player;
/**
* For displaying status messages
*/
private JLabel status = new JLabel();
/**
* Construct a new instance of the program. There may only be one object
* of this class present.
*/
public Core() {
// Wire listeners up
load.addActionListener(this);
extract.addActionListener(this);
export.addActionListener(this);
quit.addActionListener(this);
faq.addActionListener(this);
handbook.addActionListener(this);
license.addActionListener(this);
open.addActionListener(this);
play.addActionListener(this);
pause.addActionListener(this);
record.addActionListener(this);
togglesettings.addActionListener(this);
// Fancy stuff
quit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,ActionEvent.CTRL_MASK));
load.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,ActionEvent.CTRL_MASK));
export.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.CTRL_MASK));
handbook.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1,0));
open.setToolTipText(((ImageIcon)open.getIcon()).getDescription());
play.setToolTipText(((ImageIcon)play.getIcon()).getDescription());
pause.setToolTipText(((ImageIcon)pause.getIcon()).getDescription());
togglesettings.setToolTipText(((ImageIcon)togglesettings.getIcon()).getDescription());
record.setToolTipText(((ImageIcon)record.getIcon()).getDescription());
pause.setEnabled(false);
status.setBorder(new BevelBorder(BevelBorder.LOWERED));
// Build menus
JMenu file = new JMenu(Dict.get("core.core.file"));
file.add(load);
file.add(extract);
file.add(export);
file.add(new JSeparator());
file.add(quit);
JMenu help = new JMenu(Dict.get("core.core.help"));
help.add(handbook);
help.add(faq);
help.add(new JSeparator());
help.add(license);
JMenuBar mbar = new JMenuBar();
mbar.add(file);
mbar.add(Box.createHorizontalGlue());
mbar.add(help);
mbar.setBorder(new BevelBorder(BevelBorder.RAISED));
setJMenuBar(mbar);
// Build toolbar
JToolBar tbar = new JToolBar();
tbar.setRollover(true);
tbar.setFloatable(true);
tbar.add(open);
tbar.add(togglesettings);
tbar.addSeparator();
tbar.add(play);
tbar.add(pause);
tbar.add(record);
tbar.addSeparator();
// Put all together and display
JPanel content = new JPanel();
content.setLayout(new BorderLayout());
content.add(tbar,BorderLayout.NORTH);
content.add(workspace,BorderLayout.CENTER);
content.add(status,BorderLayout.SOUTH);
setContentPane(content);
workspace.add(setedit);
postStatus("");
}
/**
** Various event listeners interface implementations
**/
public void windowClosing(WindowEvent e) { handleQuit(); }
public void focusLost(FocusEvent e) {}
public void windowOpened(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == quit) handleQuit();
if (src == load || src == open ) handleLoad();
if (src == extract) handleExtract();
if (src == export || src == record) handleExport();
if (src == handbook) handleHandbook();
if (src == faq) handleFAQ();
if (src == license) handleLicense();
if (src == play || src == pause ) handlePlayPause();
if (src == togglesettings ) handleTogglesettings();
}
public void componentHidden(ComponentEvent e) {}
public void componentMoved(ComponentEvent e) {}
public void componentShown(ComponentEvent e) {}
public void componentResized(ComponentEvent e) {
Component c = (Component)e.getSource();
Integer size[] = {
new Integer(c.getWidth()),
new Integer(c.getHeight())
};
postStatus(Dict.get("core.componentresized",size));
}
public void mouseMoved(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {
if (seq.selected==null) return;
Integer pos[] = {
new Integer(seq.selected.position.x),
new Integer(seq.selected.position.y)
};
postStatus(Dict.get("core.mousedragged",pos));
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
if (seq.selected==null) return;
Integer pos[] = {
new Integer(seq.selected.position.x),
new Integer(seq.selected.position.y)
};
postStatus(Dict.get("core.mousepressed",pos));
}
public void mouseReleased(MouseEvent e) {
postStatus("");
}
/**
** Handlers for events created by GUI elements
**/
public void handleQuit() {
System.exit(0);
}
public void handleLoad() {
try {
postStatus(Dict.get("core.handleload.hint"));
LoadAccessory loadAccessory = new LoadAccessory();
JFileChooser jfc = new JFi