15.2 Dealing with Non-Groovy Artifacts - Reference Documentation
Authors: Andres Almiray
Version: 1.2.0
15.2 Dealing with Non-Groovy Artifacts
Since version 0.9.1 Griffon supports writing artifacts in JVM languages other than Groovy. The first of such languages is Java and it's supported in core by default. Additional languague support will be provided by plugins.Creating a Non-Groovy Artifact
Many of thecreate-*
scripts that come bundled with Griffon support an additional parameter that can be used to specify the language or filetype of the artifact. Non-Groovy artifacts must extend a particular class in order to receive all the benefits of a typical artifact. The default artifact templates can handle both Groovy and Java types. The following command will create an application that uses Java as the default language for the the initial MVC groupgriffon create-app simple -fileType=java
simple
MVC group we find the following code. First the Modelpackage simple;import org.codehaus.griffon.runtime.core.AbstractGriffonModel;public class SimpleModel extends AbstractGriffonModel { // an observable property // private String input; // public String getInput() { // return input; // } // public void setInput(String input) { // firePropertyChange("input", this.input, this.input = input); // } }
package simple;import java.awt.event.ActionEvent; import org.codehaus.griffon.runtime.core.AbstractGriffonController;public class SimpleController extends AbstractGriffonController { private SimpleModel model; public void setModel(SimpleModel model) { this.model = model; } /* public void action(ActionEvent e) { } */ }
package simple;import java.awt.*; import javax.swing.*; import java.util.Map;import griffon.swing.SwingGriffonApplication; import griffon.swing.WindowManager; import org.codehaus.griffon.runtime.core.AbstractGriffonView;public class SimpleView extends AbstractGriffonView { private SimpleController controller; private SimpleModel model; public void setController(SimpleController controller) { this.controller = controller; } public void setModel(SimpleModel model) { this.model = model; } // build the UI private JComponent init() { JPanel panel = new JPanel(new BorderLayout()); panel.add(new JLabel("Content Goes Here"), BorderLayout.CENTER); return panel; } @Override public void mvcGroupInit(Map<String, Object> args) { execInsideUISync(new Runnable() { public void run() { Container container = (Container) getApp().createApplicationContainer(); if(container instanceof Window) { containerPreInit((Window) container); } container.add(init()); if(container instanceof Window) { containerPostInit((Window) container); } } }); } private void containerPreInit(Window window) { if(window instanceof Frame) ((Frame) window).setTitle("simple"); window.setIconImage(getImage("/griffon-icon-48x48.png")); // uncomment the following lines if targeting +JDK6 // window.setIconImages(java.util.Arrays.asList( // getImage("/griffon-icon-48x48.png"), // getImage("/griffon-icon-32x32.png"), // getImage("/griffon-icon-16x16.png") // )); window.setLocationByPlatform(true); window.setPreferredSize(new Dimension(320, 240)); } private void containerPostInit(Window window) { window.pack(); ((SwingGriffonApplication) getApp()).getWindowManager().attach(window); } private Image getImage(String path) { return Toolkit.getDefaultToolkit() .getImage(SimpleView.class.getResource(path)); } }