SwingUI.java
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.gecode.explorer.swing;
00026
00027 import org.gecode.explorer.*;
00028 import org.gecode.Space;
00029
00030 import javax.swing.*;
00031 import java.io.File;
00032
00033 public class SwingUI implements ExplorerUIInterface {
00034 TreeCanvas canvas;
00035 Inspector inspector;
00036 private ExplorerController _ctrl;
00037
00038 public SwingUI(ExplorerController ctrl) {
00039 _ctrl = ctrl;
00040 ctrl.registerUI(this);
00041 }
00042
00043 public SpaceNode createRoot(Space rootSpace, boolean bab,
00044 Statistics stats) {
00045 return new UINode(rootSpace, bab, stats);
00046 }
00047
00048 public void update() {
00049 if (canvas != null) {
00050 canvas.updateTree((UINode)_ctrl.getRoot(),
00051 (UINode)_ctrl.getCurrentNode());
00052 }
00053 }
00054
00055 public void open() {
00056 System.setProperty("apple.laf.useScreenMenuBar", "true");
00057 try {
00058 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
00059 public void run() {
00060 canvas = new TreeCanvas(_ctrl);
00061 }
00062 });
00063 }
00064 catch(InterruptedException ex) {}
00065 catch(java.lang.reflect.InvocationTargetException ex) {}
00066 }
00067
00068 public void inspect(String s) {
00069 if (inspector==null) {
00070 inspector = new Inspector(s);
00071 }
00072 else inspector.addText(s);
00073 }
00074
00075 public File saveFilename() {
00076 JFileChooser fc = new JFileChooser();
00077 int ret = fc.showSaveDialog(canvas);
00078 if (ret == JFileChooser.APPROVE_OPTION) {
00079 return fc.getSelectedFile();
00080 } else {
00081 return null;
00082 }
00083 }
00084 public boolean overwriteDialog() {
00085 int n = JOptionPane.showConfirmDialog(canvas,
00086 "File exists.\n"+
00087 "Do you want to overwrite it?",
00088 "File exists",
00089 JOptionPane.YES_NO_OPTION);
00090 return (n == JOptionPane.YES_OPTION);
00091 }
00092
00093 public void reportError(String title, String msg) {
00094 JOptionPane.showMessageDialog(canvas, msg, title,
00095 JOptionPane.ERROR_MESSAGE);
00096 }
00097
00098 public void scaleToFit() {
00099 canvas.scaleToFit();
00100 }
00101
00102 public void centerCursor() {
00103 canvas.centerCursor();
00104 }
00105
00106 public void setCurrentNode(SpaceNode newNode) {
00107 canvas.setCurrentNode((UINode)newNode);
00108 }
00109
00110
00111 public void menuInspectActive(boolean active, boolean isRoot, boolean isLeaf) {
00112 canvas.menuBar.menuInspectActive(active, isRoot, isLeaf);
00113 }
00114 public void menuSearchActive(boolean active) {
00115 canvas.menuBar.menuSearchActive(active);
00116 }
00117 public void menuHideNodeActive(boolean active, boolean hidden) {
00118 canvas.menuBar.menuHideNodeActive(active, hidden);
00119 }
00120 public void menuUnhideAllActive(boolean active) {
00121 canvas.menuBar.menuUnhideAllActive(active);
00122 }
00123 public void menuHideFailedActive(boolean active) {
00124 canvas.menuBar.menuHideFailedActive(active);
00125 }
00126
00127
00128 public void updateEventListeners() {
00129 canvas.menuBar.updateEventListeners();
00130 }
00131
00132 }