1.1 --- a/minesweeper/src/main/java/org/apidesign/demo/minesweeper/MinesModel.java Sat Jul 26 08:28:59 2014 +0200
1.2 +++ b/minesweeper/src/main/java/org/apidesign/demo/minesweeper/MinesModel.java Mon Sep 08 17:15:18 2014 +0200
1.3 @@ -23,15 +23,28 @@
1.4 */
1.5 package org.apidesign.demo.minesweeper;
1.6
1.7 +import java.awt.event.ActionEvent;
1.8 +import java.net.MalformedURLException;
1.9 +import java.net.URL;
1.10 import java.util.ArrayList;
1.11 import java.util.List;
1.12 import java.util.Random;
1.13 +import java.util.logging.Level;
1.14 +import java.util.logging.Logger;
1.15 +import javax.swing.Action;
1.16 import net.java.html.json.ComputedProperty;
1.17 import net.java.html.json.Function;
1.18 import net.java.html.json.Model;
1.19 import net.java.html.json.ModelOperation;
1.20 import net.java.html.json.Property;
1.21 import net.java.html.sound.AudioClip;
1.22 +import org.openide.awt.HtmlBrowser;
1.23 +import org.openide.filesystems.FileObject;
1.24 +import org.openide.filesystems.FileUtil;
1.25 +import org.openide.util.ContextAwareAction;
1.26 +import org.openide.util.Exceptions;
1.27 +import org.openide.util.Lookup;
1.28 +import org.openide.util.Utilities;
1.29
1.30 /** Model of the mine field.
1.31 */
1.32 @@ -114,6 +127,42 @@
1.33 }
1.34 }
1.35
1.36 + private static final Logger LOG = Logger.getLogger(MinesModel.class.getName());
1.37 + @Function static void develop(Mines model) {
1.38 + Action a = null;
1.39 + try {
1.40 + ClassLoader l = Lookup.getDefault().lookup(ClassLoader.class);
1.41 + if (l == null) {
1.42 + l = Thread.currentThread().getContextClassLoader();
1.43 + }
1.44 + if (l == null) {
1.45 + l = MinesModel.class.getClassLoader();
1.46 + }
1.47 + Class<?> newPrj = Class.forName("org.netbeans.spi.project.ui.support.CommonProjectActions", true, l); // NOI18N
1.48 + a = (Action) newPrj.getMethod("newProjectAction").invoke(null); // NOI18N
1.49 + } catch (Exception ex) {
1.50 + LOG.log(Level.FINE, "Cannot find New project action!", ex);
1.51 + }
1.52 + if (a != null) {
1.53 + FileObject fo = FileUtil.getConfigFile("Templates/Project/ClientSide"); // NOI18N
1.54 + if (fo != null) {
1.55 + a.putValue("PRESELECT_CATEGORY", "ClientSide"); // NOI18N
1.56 + for (FileObject template : fo.getChildren()) {
1.57 + if (template.getName().contains("htmljava")) { // NOI18N
1.58 + a.putValue("PRESELECT_TEMPLATE", template.getName()); // NOI18N
1.59 + a.actionPerformed(new ActionEvent(model, 0, null));
1.60 + return;
1.61 + }
1.62 + }
1.63 + }
1.64 + }
1.65 + try {
1.66 + HtmlBrowser.URLDisplayer.getDefault().showURL(new URL("http://wiki.apidesign.org/wiki/DukeScriptInNetBeans")); // NO18N
1.67 + } catch (MalformedURLException ex) {
1.68 + Exceptions.printStackTrace(ex);
1.69 + }
1.70 + }
1.71 +
1.72 @ModelOperation static void init(Mines model, int width, int height, int mines) {
1.73 List<Row> rows = model.getRows();
1.74 if (rows.size() != height || rows.get(0).getColumns().size() != width) {