Created
August 29, 2010 14:09
-
-
Save aalmiray/556316 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package b; | |
import java.awt.GridLayout; | |
import java.awt.event.*; | |
import javax.swing.*; | |
import javax.swing.event.*; | |
import java.beans.*; | |
import java.util.Map; | |
import griffon.swing.SwingGriffonApplication; | |
import griffon.swing.WindowManager; | |
import org.codehaus.griffon.runtime.core.AbstractGriffonView; | |
public class BView extends AbstractGriffonView { | |
private BController controller; | |
private BModel model; | |
public void setController(BController controller) { | |
this.controller = controller; | |
} | |
public void setModel(BModel model) { | |
this.model = model; | |
} | |
private JComponent init() { | |
final JTextField input = new JTextField(20); | |
final JTextField output = new JTextField(20); | |
final JButton button = new JButton("Copy"); | |
input.getDocument().addDocumentListener(new DocumentListener() { | |
public void changedUpdate(DocumentEvent e) { model.setInput(input.getText()); } | |
public void insertUpdate(DocumentEvent e) { model.setInput(input.getText()); } | |
public void removeUpdate(DocumentEvent e) { model.setInput(input.getText()); } | |
}); | |
model.addPropertyChangeListener(new PropertyChangeListener() { | |
public void propertyChange(PropertyChangeEvent e) { | |
output.setText(model.getOutput()); | |
} | |
}); | |
button.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent e) { | |
controller.copy(e); | |
} | |
}); | |
JPanel panel = new JPanel(new GridLayout(3, 1)); | |
panel.add(input); | |
panel.add(button); | |
panel.add(output); | |
return panel; | |
} | |
public void mvcGroupInit(Map<String, ?> args) { | |
getApp().execSync(new Runnable() { | |
public void run() { | |
JFrame view = new JFrame("Griffon + Java"); | |
view.setLocationByPlatform(true); | |
view.getContentPane().add(init()); | |
view.pack(); | |
((SwingGriffonApplication) getApp()).getWindowManager().attach(view); | |
} | |
}); | |
} | |
} | |
/* | |
Groovy equivalent | |
package b | |
application(title: 'Griffon + Groovy', | |
pack: true, | |
locationByPlatform:true) { | |
gridLayout(cols: 1, rows: 3) | |
textField columns: 20, text: bind('input', target: model) | |
button('Copy', actionPerformed: controller.copy) | |
textField columns: 20, text: bind{ model.output } | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment