Commit a830d6a96d06da6ddd0dc0571e539ec7ca59b581

Added sample for nested controllers (drop in controllers).

Commit diff

examples/Nested-DropIn/README.TXT

 
1The Nested-DropIn sample shows off the nested controller feature using
2a payment form that has a billing address and a shipping address (the address
3pane is a re-used and nested controller).
4
5This also shows how to spawn and clean up controllers via the multiton methods
6on Monkeybars::Controller.
7
8Built against Monkeybars 6.2.
9
10Rawr is needed to build this project.
11
12If viewing this project as a Netbeans project, one can see how a design preview
13for fairly static nested views is done.
toggle raw diff

examples/Nested-DropIn/Rakefile

 
1require 'rawr'
2require 'rake'
3
4Dir.glob("tasks/**/*.rake").each do |rake_file|
5 load File.expand_path(File.dirname(__FILE__) + "/" + rake_file)
6end
toggle raw diff

examples/Nested-DropIn/build_configuration.yaml

 
1# Name of the created jar file
2project_name: change_me
3
4# Directory to create and place produced project files in
5output_dir: package
6
7# File to set as main-class in jar manifest
8main_java_file: org.rubyforge.rawr.Main
9
10# Ruby file to invoke when jar is started
11main_ruby_file: main
12
13# Location of Ruby source files
14ruby_source_dir: src
15
16# Location of Ruby library files
17ruby_library_dir: lib/ruby
18
19# Location of Java source files
20java_source_dir: src
21
22# Directories that should have ALL their .jar contents loaded on the classpath
23# If you wish to only include specific jars from a directory use classpath_files
24classpath_dirs:
25 - lib/java
26
27# Individual files that should be loaded on the classpath
28#classpath_files:
29# - lib/java/jruby-complete.jar
30# - lib/java/swing-layout-1.0.2.jar
31
32# Directory that should be loaded onto the java.library.path
33#native_library_dirs:
34# - lib/java/native
35
36# Directories which you want the coentents of to be copied to the output directory
37#package_data_dirs:
38# - lib
39
40# Directories to be added into the jar
41#jar_data_dirs:
42# - data
43
44# NOT YET IMPLEMENTED
45#pre_processing_task:
46#post_processing_task:
toggle raw diff

examples/Nested-DropIn/lib/java/jruby-complete.jar

 
toggle raw diff

examples/Nested-DropIn/lib/java/monkeybars-0.6.2.jar

 
toggle raw diff

examples/Nested-DropIn/manifest.mf

 
1Manifest-Version: 1.0
2X-COMMENT: Main-Class will be added automatically by build
3
toggle raw diff

examples/Nested-DropIn/src/address/AddressPanel.form

 
1<?xml version="1.0" encoding="UTF-8" ?>
2
3<Form version="1.3" maxVersion="1.6" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4 <AuxValues>
5 <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
6 <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7 <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
8 <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
9 <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
10 <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
11 <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
12 <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
13 </AuxValues>
14
15 <Layout>
16 <DimensionLayout dim="0">
17 <Group type="103" groupAlignment="0" attributes="0">
18 <Group type="102" alignment="0" attributes="0">
19 <EmptySpace max="-2" attributes="0"/>
20 <Group type="103" groupAlignment="1" attributes="0">
21 <Component id="jLabel5" alignment="1" min="-2" max="-2" attributes="0"/>
22 <Component id="jLabel4" alignment="1" min="-2" max="-2" attributes="0"/>
23 <Component id="jLabel3" alignment="1" min="-2" max="-2" attributes="0"/>
24 <Component id="jLabel2" alignment="1" min="-2" max="-2" attributes="0"/>
25 <Component id="jLabel1" alignment="1" min="-2" max="-2" attributes="0"/>
26 </Group>
27 <EmptySpace type="separate" max="-2" attributes="0"/>
28 <Group type="103" groupAlignment="0" attributes="0">
29 <Component id="state_combo_box" min="-2" max="-2" attributes="0"/>
30 <Component id="street_address1_text_field" alignment="0" pref="150" max="32767" attributes="0"/>
31 <Component id="street_address2_text_field" alignment="0" pref="150" max="32767" attributes="0"/>
32 <Component id="city_text_field" alignment="0" pref="150" max="32767" attributes="0"/>
33 <Component id="zip_code_text_field" alignment="0" pref="150" max="32767" attributes="0"/>
34 </Group>
35 <EmptySpace max="-2" attributes="0"/>
36 </Group>
37 </Group>
38 </DimensionLayout>
39 <DimensionLayout dim="1">
40 <Group type="103" groupAlignment="0" attributes="0">
41 <Group type="102" alignment="0" attributes="0">
42 <EmptySpace max="-2" attributes="0"/>
43 <Group type="103" groupAlignment="3" attributes="0">
44 <Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
45 <Component id="street_address1_text_field" alignment="3" min="-2" max="-2" attributes="0"/>
46 </Group>
47 <EmptySpace max="-2" attributes="0"/>
48 <Group type="103" groupAlignment="3" attributes="0">
49 <Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
50 <Component id="street_address2_text_field" alignment="3" min="-2" max="-2" attributes="0"/>
51 </Group>
52 <EmptySpace max="-2" attributes="0"/>
53 <Group type="103" groupAlignment="3" attributes="0">
54 <Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
55 <Component id="city_text_field" alignment="3" min="-2" max="-2" attributes="0"/>
56 </Group>
57 <EmptySpace max="-2" attributes="0"/>
58 <Group type="103" groupAlignment="3" attributes="0">
59 <Component id="jLabel4" alignment="3" min="-2" max="-2" attributes="0"/>
60 <Component id="state_combo_box" alignment="3" min="-2" max="-2" attributes="0"/>
61 </Group>
62 <EmptySpace max="-2" attributes="0"/>
63 <Group type="103" groupAlignment="3" attributes="0">
64 <Component id="jLabel5" alignment="3" min="-2" max="-2" attributes="0"/>
65 <Component id="zip_code_text_field" alignment="3" min="-2" max="-2" attributes="0"/>
66 </Group>
67 <EmptySpace max="32767" attributes="0"/>
68 </Group>
69 </Group>
70 </DimensionLayout>
71 </Layout>
72 <SubComponents>
73 <Component class="javax.swing.JLabel" name="jLabel1">
74 <Properties>
75 <Property name="text" type="java.lang.String" value="Street address 1"/>
76 </Properties>
77 </Component>
78 <Component class="javax.swing.JLabel" name="jLabel2">
79 <Properties>
80 <Property name="text" type="java.lang.String" value="Street address 2"/>
81 </Properties>
82 </Component>
83 <Component class="javax.swing.JLabel" name="jLabel3">
84 <Properties>
85 <Property name="text" type="java.lang.String" value="City"/>
86 </Properties>
87 </Component>
88 <Component class="javax.swing.JLabel" name="jLabel4">
89 <Properties>
90 <Property name="text" type="java.lang.String" value="State"/>
91 </Properties>
92 </Component>
93 <Component class="javax.swing.JLabel" name="jLabel5">
94 <Properties>
95 <Property name="text" type="java.lang.String" value="Zip code"/>
96 </Properties>
97 </Component>
98 <Component class="javax.swing.JTextField" name="street_address1_text_field">
99 <Properties>
100 <Property name="text" type="java.lang.String" value="4643 E. Thomas Rd."/>
101 </Properties>
102 </Component>
103 <Component class="javax.swing.JTextField" name="street_address2_text_field">
104 <Properties>
105 <Property name="text" type="java.lang.String" value="#3"/>
106 </Properties>
107 </Component>
108 <Component class="javax.swing.JTextField" name="city_text_field">
109 <Properties>
110 <Property name="text" type="java.lang.String" value="Phoenix"/>
111 </Properties>
112 </Component>
113 <Component class="javax.swing.JTextField" name="zip_code_text_field">
114 <Properties>
115 <Property name="text" type="java.lang.String" value="85018"/>
116 </Properties>
117 </Component>
118 <Component class="javax.swing.JComboBox" name="state_combo_box">
119 <Properties>
120 <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
121 <StringArray count="4">
122 <StringItem index="0" value="AK"/>
123 <StringItem index="1" value="AL"/>
124 <StringItem index="2" value="AZ"/>
125 <StringItem index="3" value="etc"/>
126 </StringArray>
127 </Property>
128 </Properties>
129 </Component>
130 </SubComponents>
131</Form>
toggle raw diff

examples/Nested-DropIn/src/address/AddressPanel.java

 
1/*
2 * AddressPanel.java
3 *
4 * Created on June 7, 2008, 10:04 PM
5 */
6
7package address;
8
9/**
10 *
11 * @author logan
12 */
13public class AddressPanel extends javax.swing.JPanel {
14
15 /** Creates new form AddressPanel */
16 public AddressPanel() {
17 initComponents();
18 }
19
20 /** This method is called from within the constructor to
21 * initialize the form.
22 * WARNING: Do NOT modify this code. The content of this method is
23 * always regenerated by the Form Editor.
24 */
25 @SuppressWarnings("unchecked")
26 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
27 private void initComponents() {
28
29 jLabel1 = new javax.swing.JLabel();
30 jLabel2 = new javax.swing.JLabel();
31 jLabel3 = new javax.swing.JLabel();
32 jLabel4 = new javax.swing.JLabel();
33 jLabel5 = new javax.swing.JLabel();
34 street_address1_text_field = new javax.swing.JTextField();
35 street_address2_text_field = new javax.swing.JTextField();
36 city_text_field = new javax.swing.JTextField();
37 zip_code_text_field = new javax.swing.JTextField();
38 state_combo_box = new javax.swing.JComboBox();
39
40 jLabel1.setText("Street address 1");
41
42 jLabel2.setText("Street address 2");
43
44 jLabel3.setText("City");
45
46 jLabel4.setText("State");
47
48 jLabel5.setText("Zip code");
49
50 street_address1_text_field.setText("4643 E. Thomas Rd.");
51
52 street_address2_text_field.setText("#3");
53
54 city_text_field.setText("Phoenix");
55
56 zip_code_text_field.setText("85018");
57
58 state_combo_box.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AK", "AL", "AZ", "etc" }));
59
60 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
61 this.setLayout(layout);
62 layout.setHorizontalGroup(
63 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
64 .add(layout.createSequentialGroup()
65 .addContainerGap()
66 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
67 .add(jLabel5)
68 .add(jLabel4)
69 .add(jLabel3)
70 .add(jLabel2)
71 .add(jLabel1))
72 .add(18, 18, 18)
73 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
74 .add(state_combo_box, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
75 .add(street_address1_text_field, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
76 .add(street_address2_text_field, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
77 .add(city_text_field, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
78 .add(zip_code_text_field, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE))
79 .addContainerGap())
80 );
81 layout.setVerticalGroup(
82 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
83 .add(layout.createSequentialGroup()
84 .addContainerGap()
85 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
86 .add(jLabel1)
87 .add(street_address1_text_field, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
88 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
89 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
90 .add(jLabel2)
91 .add(street_address2_text_field, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
92 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
93 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
94 .add(jLabel3)
95 .add(city_text_field, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
96 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
97 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
98 .add(jLabel4)
99 .add(state_combo_box, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
100 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
101 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
102 .add(jLabel5)
103 .add(zip_code_text_field, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
104 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
105 );
106 }// </editor-fold>//GEN-END:initComponents
107
108
109 // Variables declaration - do not modify//GEN-BEGIN:variables
110 private javax.swing.JTextField city_text_field;
111 private javax.swing.JLabel jLabel1;
112 private javax.swing.JLabel jLabel2;
113 private javax.swing.JLabel jLabel3;
114 private javax.swing.JLabel jLabel4;
115 private javax.swing.JLabel jLabel5;
116 private javax.swing.JComboBox state_combo_box;
117 private javax.swing.JTextField street_address1_text_field;
118 private javax.swing.JTextField street_address2_text_field;
119 private javax.swing.JTextField zip_code_text_field;
120 // End of variables declaration//GEN-END:variables
121
122}
toggle raw diff

examples/Nested-DropIn/src/address/address_controller.rb

 
1class AddressController < ApplicationController
2 set_model 'AddressModel'
3 set_view 'AddressView'
4 set_close_action :close
5
6 def load
7 signal :allow_editing
8 end
9
10 def set_editable(state)
11 signal_name = state ? :allow_editing : :deny_editing
12 signal signal_name
13 end
14
15 def use_address(foreign_address_model)
16 update_model(foreign_address_model, :street_address1, :street_address2, :city, :state, :zip_code)
17 update_view
18 end
19
20 def get_address
21 update_model(view_state.first, :street_address1, :street_address2, :city, :state, :zip_code)
22 model
23 end
24end
toggle raw diff

examples/Nested-DropIn/src/address/address_model.rb

 
1class AddressModel
2 attr_accessor :street_address1, :street_address2, :city, :state, :zip_code
3
4 def initialize
5 @street_address1 = ''
6 @street_address2 = ''
7 @city = ''
8 @state = ''
9 @zip_code = ''
10 end
11end
toggle raw diff

examples/Nested-DropIn/src/address/address_view.rb

 
1class AddressView < ApplicationView
2 set_java_class 'address.AddressPanel'
3
4 map :view => 'street_address1_text_field.text', :model => :street_address1
5 map :view => 'street_address2_text_field.text', :model => :street_address2
6 map :view => 'city_text_field.text', :model => :city
7 map :view => 'state_combo_box.selected_item', :model => :state
8 map :view => 'zip_code_text_field.text', :model => :zip_code
9
10 define_signal :name => :allow_editing, :handler => :enable_fields
11 define_signal :name => :deny_editing, :handler => :disable_fields
12
13 def enable_fields(model, transfer)
14 set_editable_fields(true)
15 end
16
17 def disable_fields(model, transfer)
18 set_editable_fields(false)
19 end
20
21 def set_editable_fields(state)
22 street_address1_text_field.enabled = state
23 street_address2_text_field.enabled = state
24 city_text_field.enabled = state
25 state_combo_box.enabled = state
26 zip_code_text_field.enabled = state
27 end
28end
toggle raw diff

examples/Nested-DropIn/src/application_controller.rb

 
1class ApplicationController < Monkeybars::Controller
2 # Add content here that you want to be available to all the controllers
3 # in your application
4end
toggle raw diff

examples/Nested-DropIn/src/application_view.rb

 
1class ApplicationView < Monkeybars::View
2 # Add content here that you want to be available to all the views in your application
3end
toggle raw diff

examples/Nested-DropIn/src/main.rb

 
1#===============================================================================
2# Much of the platform specific code should be called before Swing is touched.
3# The useScreenMenuBar is an example of this.
4require 'rbconfig'
5
6#===============================================================================
7# Platform specific operations, feel free to remove or override any of these
8# that don't work for your platform/application
9
10case Config::CONFIG["host_os"]
11when /darwin/i # OSX specific code
12 java.lang.System.set_property("apple.laf.useScreenMenuBar", "true")
13when /^win/i # Windows specific code
14when /linux/i # Linux specific code
15end
16
17# End of platform specific code
18#===============================================================================
19
20$LOAD_PATH.unshift File.dirname(__FILE__)
21Dir.glob(File.expand_path(File.dirname(__FILE__) + "/**")).each do |directory|
22 $LOAD_PATH << directory unless directory =~ /\.\w+$/ #File.directory? is broken in current JRuby for dirs inside jars
23end
24
25require 'manifest'
26
27
28require 'payment_controller'
29
30PaymentController.instance.open
toggle raw diff

examples/Nested-DropIn/src/manifest.rb

 
1#===============================================================================
2# Monkeybars requires, this pulls in the requisite libraries needed for
3# Monkeybars to operate.
4
5require 'java'
6require 'resolver'
7
8case Monkeybars::Resolver.run_location
9when Monkeybars::Resolver::IN_FILE_SYSTEM
10 $CLASSPATH << File.expand_path(File.dirname(__FILE__) + '/../lib/monkeybars-0.6.1.jar')
11end
12
13require 'monkeybars'
14require 'application_controller'
15require 'application_view'
16
17# End of Monkeybars requires
18#===============================================================================
19#
20# Add your own application-wide libraries below. To include jars, append to
21# $CLASSPATH, or use add_to_classpath, for example:
22#
23# $CLASSPATH << File.expand_path(File.dirname(__FILE__) + "/../lib/swing-layout-1.0.3.jar")
24#
25# is equivalent to
26#
27# add_to_classpath "../lib/swing-layout-1.0.3.jar"
28
29case Monkeybars::Resolver.run_location
30when Monkeybars::Resolver::IN_FILE_SYSTEM
31 # Files to be added only when running from the file system go here
32when Monkeybars::Resolver::IN_JAR_FILE
33 # Files to be added only when run from inside a jar file
34end
35
36$LOAD_PATH.unshift "src/address"
37$LOAD_PATH.unshift "src/payment"
toggle raw diff

examples/Nested-DropIn/src/org/rubyforge/rawr/Main.java

 
1package org.rubyforge.rawr;
2
3import java.io.BufferedReader;
4import java.io.InputStreamReader;
5import java.io.InputStream;
6import java.io.IOException;
7import java.net.URL;
8
9
10import java.util.ArrayList;
11import org.jruby.Ruby;
12import org.jruby.javasupport.JavaEmbedUtils;
13
14
15public class Main
16{
17 public static void main(String[] args) throws Exception
18 {
19 Ruby runtime = JavaEmbedUtils.initialize(new ArrayList(0));
20 String config_yaml = "";
21 try{
22 java.io.InputStream ins = Main.class.getClassLoader().getResourceAsStream("run_configuration");
23 if (ins == null ) {
24 System.err.println( "InputStream ins is null!");
25 }
26 else {
27 config_yaml = grabConfigFileContents(ins);
28 }
29 }
30 catch(IOException e)
31 {
32 System.err.println("Error loading run configuration file 'run_configuration', using configuration defaults: " + e);
33 config_yaml = "";
34 }
35 catch(java.lang.NullPointerException ee)
36 {
37 System.err.println("Error loading run configuration file 'run_configuration', using configuration defaults: " + ee );
38 config_yaml = "";
39 }
40
41 String bootRuby = "require 'java'\n" +
42 "require 'yaml'\n" +
43 "$: << 'src'\n" +
44 "yaml = '" + config_yaml + "' \n" +
45 "begin\n" +
46 " raise 'No YAML!' if yaml.strip.empty?\n" +
47 " config_hash = YAML.load( \"" + config_yaml + "\" )\n" +
48 " $:.unshift( config_hash['ruby_source_dir'] )\n" +
49 " require config_hash[ 'ruby_source_dir' ] + '/' + config_hash[ 'main_ruby_file' ]\n" +
50 "rescue Exception \n" +
51 " STDERR.puts \"Error loading config file: \" + $! + \"\nUsing default values.\"\n" +
52 " begin\n" +
53 " require 'src/main'\n" +
54 " rescue LoadError => e\n" +
55 " warn 'Error starting the application'\n" +
56 " warn \"#{e}\\n#{e.backtrace.join(\"\\n\")}\"\n" +
57 " end\n" +
58 "end\n";
59 runtime.evalScriptlet( bootRuby );
60 }
61