📄 annotationframe.java
字号:
if (event.getActionCommand().equals("exitApplication")) {
exitApplication();
} else if (event.getActionCommand().equals("openFile")) {
debug("open file operation initiated");
openFile();
debug("open file operation ended");
} else if (event.getActionCommand().equals("showAbout")) {
AboutDialog adialog = new AboutDialog(this);
adialog.pack();
Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
adialog.setLocation((ss.width - adialog.getWidth()) / 2, (ss.height - adialog.getHeight()) / 2);
adialog.setVisible(true);
} else if (event.getActionCommand().equals("showHelp")) {
HelpDialog adialog = new HelpDialog(this);
// adialog.pack();
Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
adialog.setLocation((ss.width - adialog.getWidth()) / 2, (ss.height - adialog.getHeight()) / 2);
adialog.setVisible(true);
} else if (event.getActionCommand().equals("saveFileAs")) {
JOptionPane.showMessageDialog(this, "not implemented yet");
} else if (event.getActionCommand().equals("gc")) {
debug("Mem: "
+ df.format(Runtime.getRuntime().freeMemory() / (1024.0 * 1024.0)) + "MB of "
+ df.format(Runtime.getRuntime().totalMemory() / (1024.0 * 1024.0)) + "MB free");
debug("starting garbage collector ...");
System.gc();
debug("finished collecting garbage!");
debug("Mem: "
+ df.format(Runtime.getRuntime().freeMemory() / (1024.0 * 1024.0)) + "MB of "
+ df.format(Runtime.getRuntime().totalMemory() / (1024.0 * 1024.0)) + "MB free");
status.setText("Garbage collection finished: "
+ df.format(Runtime.getRuntime().freeMemory() / (1024.0 * 1024.0)) + "MB of "
+ df.format(Runtime.getRuntime().totalMemory() / (1024.0 * 1024.0)) + "MB free");
// gtracker.start();
} else if (event.getActionCommand().equals("viewXML")) {
TextPreviewDialog preview = new TextPreviewDialog(this, createDocument());
preview.setSize(properties.getTextViewWidth(), properties.getTextViewHeight());
Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
preview.setLocation((ss.width - preview.getWidth()) / 2, (ss.height - preview.getHeight()) / 2);
preview.setVisible(true);
properties.setTextViewHeight(preview.getHeight());
properties.setTextViewWidth(preview.getWidth());
} else if (event.getActionCommand().equals("saveFile")) {
if (currentFile != null) {
saveFile();
} else {
JOptionPane.showMessageDialog(this, "No image selected!");
}
} else if (event.getActionCommand().equals("viewExternal")) {
if (currentFile != null && properties.getExternalViewer() != null) {
try {
debug("Run: " + properties.getExternalViewer() + " \"" + currentFile.getCanonicalPath() + "\"");
Runtime.getRuntime().exec(properties.getExternalViewer() + " \"" + currentFile.getCanonicalPath() + "\"");
} catch (IOException e) {
debug("Error with external viewer - " + e.toString() + ": " + e.getMessage());
}
}
} else if (event.getActionCommand().equals("setExternal")) {
ExternalViewerSelectDialog d = new ExternalViewerSelectDialog(this, properties.getExternalViewer());
d.pack();
Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
d.setLocation((ss.width - d.getWidth()) / 2, (ss.height - d.getHeight()) / 2);
d.setVisible(true);
properties.setExternalViewer(d.getExternalViewer());
} else if (event.getActionCommand().equals("autoPilot")) {
if (currentFile != null) {
startAutoPilot();
}
} else if (event.getActionCommand().equals("delAgent")) {
DeleteAgentDialog d = new DeleteAgentDialog(this);
d.pack();
Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
d.setLocation((ss.width - d.getWidth()) / 2, (ss.height - d.getHeight()) / 2);
d.setVisible(true);
} else {
JOptionPane.showMessageDialog(this, "Not Implemented!");
}
}
/**
* is called when applikation is exited ...
* saving properties and closing app.
* todo: save file? dialog
*/
private void exitApplication() {
properties.setFrameHeigth(this.getHeight());
properties.setFrameWidth(this.getWidth());
properties.setFrameLocationX(this.getLocation().x);
properties.setFrameLocationY(this.getLocation().y);
properties.setTbSplit(tbSplit.getDividerLocation());
properties.setLrSplit(lrSplit.getDividerLocation());
debug("saving configuration ...");
properties.saveConfiguration();
debug("finished saving configuration");
debug("saving semantic objects ...");
beePanel.saveCatalog();
debug("semantic objects saved");
if (DIRTY) {
if (askIfSave()) {
System.exit(0);
}
} else {
System.exit(0);
}
}
private boolean askIfSave() {
int returnVal = JOptionPane.showConfirmDialog(this, "Would you like to save your changes? Otherwise your changes will be lost.", "Save description?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (returnVal == JOptionPane.YES_OPTION) {
debug("Save file ...");
saveFile();
return true;
} else if (returnVal == JOptionPane.NO_OPTION) {
debug("Quit without saving ...");
return true;
} else {
debug("no quitting, no saving :)");
return false;
}
}
private void startAutoPilot() {
AutoPilotThread t = new AutoPilotThread(this, currentFile);
t.start();
}
/**
* is called when a file is explicitely openend, meanwhile not used :)
*/
private void openFile() {
JFileChooser jfc = new JFileChooser(properties.getLastDir());
// jfc.setCurrentDirectory(new File(properties.getLastDir()));
if (JFileChooser.APPROVE_OPTION == jfc.showOpenDialog(this)) {
debug("opening file: " + jfc.getSelectedFile().toString());
properties.setLastDir(jfc.getCurrentDirectory().toString());
debug("saving path: " + jfc.getCurrentDirectory().toString());
try {
setCurrentFile(jfc.getSelectedFile());
} catch (IOException e) {
debug("Error reading File: " + e.toString());
}
}
// System.gc();
}
/**
* Set the "dirty" trag if information has changed :) needed for
* bugging the user with questions like: Do you want to save the
* file? or Unsaved changes will be lost :)
*
* @param isDirty
*/
public static void setDirty(boolean isDirty) {
DIRTY = isDirty;
}
/**
* set a new Image to edit ... thread-based ...
*/
public void setCurrentFile(File f) throws IOException {
boolean loadIt = true;
if (DIRTY) {
loadIt = askIfSave();
}
if (loadIt) {
ImageLoader t = new ImageLoader(status, this, f, imagePanel, creationPanel, textPanel, mdPanel, qualityPanel,
beePanel, colorPanel);
t.start();
currentFile = f;
}
}
/**
* loadCurrentFile is the not thread based method to load a file, it's used
* by the autopilot
*
* @param f defines the file to open
* @throws IOException
*/
public void loadCurrentFile(File f) throws IOException {
ImageLoader t = new ImageLoader(status, this, f, imagePanel, creationPanel, textPanel, mdPanel, qualityPanel,
beePanel, colorPanel);
t.run();
currentFile = f;
}
public void saveFile() {
if (currentFile != null) {
try {
XMLOutputter op = new XMLOutputter(Format.getPrettyFormat());
String imgName = currentFile.getCanonicalPath();
String fname = imgName.substring(0, imgName.lastIndexOf("."));
fname = fname + ".mp7.xml";
File saveFile = new File(fname);
// check if file is arleady in existence and ask if we should overwrite:
// boolean write = false;
// if (saveFile.exists()) {
// if (JOptionPane.showConfirmDialog(this,
// "Overwrite existing file?", "Overwrite?",
// JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// write = true;
// }
// } else {
// write = true;
// }
if (true) {
FileOutputStream fos = new FileOutputStream(saveFile);
OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
op.output(createDocument(), osw);
osw.close();
fos.close();
debug("File written to " + saveFile.toString());
status.setText("File written to " + saveFile.toString());
setDirty(false);
if (getTitle().indexOf('*') > -1)
setTitle(getTitle().substring(2));
}
} catch (IOException e) {
debug("Exception while saving " + e.toString());
}
}
}
/**
* This is the method where all the information is collected and put together. The result is valid
* MPEG-7 Description
*/
public Document createDocument() {
Element mediaFormat, creation, tmp, semantics;
tmp = creationPanel.createXML();
mediaFormat = (Element) tmp.getChild("MediaFormat", tmp.getNamespace()).detach();
creation = (Element) tmp.getChild("CreationInformation", tmp.getNamespace()).detach();
tmp = beePanel.getSemanticsDocument().getRootElement();
semantics = ((Element) tmp.getChild("Description", tmp.getNamespace()).getChild("Semantics",
tmp.getNamespace()).clone());
semantics.setName("Semantic");
File thumbFile = AnnotationToolkit.generateThumbnail(currentFile);
Element thumbNailProfile = null;
Mpeg7ThumbnailMediaProfile thumbnail = null;
thumbnail = new Mpeg7ThumbnailMediaProfile(thumbFile, 120, 120);
thumbNailProfile = thumbnail.createDocument();
Mpeg7ImageDescription m7id = new Mpeg7ImageDescription(creation, mdPanel.createXML(), mediaFormat,
AnnotationToolkit.getMpeg7MediaInstance(currentFile),
qualityPanel.createXML(), thumbNailProfile, semantics, textPanel.createXML(), colorPanel.createXML());
return m7id.createDocument();
}
private void debug(String message) {
if (DEBUG) System.out.println("[at.lux.fotoannotation.AnnotationFrame] " + message);
}
public void setStatus(String message) {
status.setText(message);
}
public String getSemanticAgentsNames() {
String[] names = beePanel.getSemanticAgentsNames();
return createStringFromArray(names);
}
private String createStringFromArray(String[] names) {
StringWriter sw = new StringWriter(names.length * 32);
for (int i = 0; i < names.length; i++) {
sw.append(names[i]);
if (i < names.length - 1) sw.append(", ");
}
return sw.toString();
}
public String getSemanticEventsNames() {
String[] names = beePanel.getSemanticEventsNames();
return createStringFromArray(names);
}
public String getSemanticTimesNames() {
String[] names = beePanel.getSemanticTimesNames();
return createStringFromArray(names);
}
public String getSemanticPlacesNames() {
String[] names = beePanel.getSemanticPlacesNames();
return createStringFromArray(names);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -