Generated on Fri Oct 6 16:26:43 2006 for Gecode/J by doxygen 1.4.7

SwingUI.java

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *
00005  *  Contributing authors:
00006  *     Mikael Lagerkvist <lagerkvist@gecode.org> 
00007  *
00008  *  Copyright:
00009  *     Guido Tack, 2006
00010  *
00011  *  Last modified:
00012  *     $Date: 2006-02-20 10:43:09 +0100 (Mon, 20 Feb 2006) $ by $Author: tack $
00013  *     $Revision: 2982 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  See the file "LICENSE" for information on usage and
00020  *  redistribution of this file, and for a
00021  *     DISCLAIMER OF ALL WARRANTIES.
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     // Methods for controlling disabling and enabling of menu entries
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     // Handling event listeners
00128     public void updateEventListeners() {
00129         canvas.menuBar.updateEventListeners();
00130     }
00131 
00132 }