ExplorerDocument.java
Go to the documentation of this file.00001 package org.gecode.explorer.cocoa;
00002
00003 import com.apple.cocoa.application.*;
00004 import com.apple.cocoa.foundation.*;
00005 import java.util.*;
00006
00007 import org.gecode.*;
00008 import org.gecode.explorer.*;
00009
00010
00011 public class ExplorerDocument extends NSDocument {
00012
00013 public NSScrollView graphicScrollView;
00014 public TreeView treeView;
00015 public NSSlider slider;
00016
00017 private ExplorerNode rootNode;
00018
00019 public ExplorerDocument() {
00020 super();
00021
00022 NSMutableDictionary applicationDefaults = new NSMutableDictionary();
00023
00024 applicationDefaults.setObjectForKey("Blueberry", "NodeColorChoiceInside");
00025 applicationDefaults.setObjectForKey("Licorice", "NodeColorChoiceBorder");
00026 applicationDefaults.setObjectForKey("Fern", "NodeColorSolutionInside");
00027 applicationDefaults.setObjectForKey("Licorice", "NodeColorSolutionBorder");
00028 applicationDefaults.setObjectForKey("Maraschino", "NodeColorFailureInside");
00029 applicationDefaults.setObjectForKey("Licorice", "NodeColorFailureBorder");
00030 applicationDefaults.setObjectForKey("Silver", "NodeColorUnknownInside");
00031 applicationDefaults.setObjectForKey("Licorice", "NodeColorUnknownBorder");
00032
00033 NSUserDefaults defaults = NSUserDefaults.standardUserDefaults();
00034 defaults.registerDefaults(applicationDefaults);
00035 }
00036
00037 public ExplorerDocument(String fileName, String fileType) {
00038 super(fileName, fileType);
00039 }
00040
00041 public String windowNibName() {
00042 return "ExplorerDocument";
00043 }
00044
00045 public void windowControllerDidLoadNib(NSWindowController aController) {
00046
00047
00048 super.windowControllerDidLoadNib(aController);
00049 NSView documentView = graphicScrollView.documentView();
00050 CenteringClipView newClipView =
00051 new CenteringClipView(graphicScrollView.contentView().frame());
00052 newClipView.setDocumentView(documentView);
00053 newClipView.setBackgroundColor(NSColor.whiteColor());
00054 graphicScrollView.setContentView((NSClipView) newClipView);
00055
00056 setScale(slider);
00057
00058 Queens queens = new Queens(8);
00059 this.rootNode = new ExplorerNode(queens);
00060 treeView.setRootNode(rootNode);
00061 }
00062
00063 public NSData dataRepresentationOfType(String aType) {
00064 NSRect rectangle = this.treeView.frame();
00065 NSData data = this.treeView.dataWithPDFInsideRect(rectangle);
00066 return data;
00067 }
00068
00069 public boolean loadDataRepresentation(NSData data, String aType) {
00070 return true;
00071 }
00072
00073 public void setScale(Object sender) {
00074 NSSlider slider = (NSSlider) sender;
00075 treeView.setScale(slider.floatValue());
00076 treeView.setNeedsDisplay(true);
00077 }
00078
00079 public void exploreAll(Object sender) {
00080 DFS dfs = new DFS();
00081 dfs.setup(rootNode);
00082 while (! dfs.step());
00083 treeView.layout();
00084 }
00085 }