Skip to content

Instantly share code, notes, and snippets.

@gditrick
Created October 24, 2011 18:45
Show Gist options
  • Save gditrick/1309785 to your computer and use it in GitHub Desktop.
Save gditrick/1309785 to your computer and use it in GitHub Desktop.
jruby Monkeybars rawr nested views locking up swing app
class LightBar
end
require "oc_module_controller"
class LightBarController < ApplicationController
set_model 'LightBar'
set_view 'LightBarView'
set_close_action :exit
def load
@controllers ||= []
@controllers << OcModuleController.create_instance
@controllers.last.open
add_nested_controller(:oc, @controllers.last)
end
end
class LightBarView < ApplicationView
set_java_class 'app.views.light_bar_views.LightBarFrame'
attr_accessor :current_x_pos, :current_y_pos, :current_width, :current_height
nest :sub_view => :oc, :using => [:add_oc, nil]
def load
lights_panel.remove_all
end
def add_oc(nested_view, nested_component, model, transfer)
lights_panel.add nested_component
nested_component.set_location(0, 0)
end
end
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* BayControllerFrame.java
*
* Created on Oct 19, 2011, 9:11:11 AM
*/
package app.views.light_bar_views;
/**
*
* @author gregd
*/
public class LightBarFrame extends javax.swing.JFrame {
/** Creates new form BayControllerFrame */
public LightBarFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
lights_pane = new javax.swing.JScrollPane();
lights_panel = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setEnabled(false);
setMinimumSize(new java.awt.Dimension(300, 115));
getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));
lights_pane.setOpaque(false);
lights_pane.setRequestFocusEnabled(false);
lights_panel.setAutoscrolls(true);
lights_panel.setDoubleBuffered(false);
lights_panel.setLayout(new javax.swing.BoxLayout(lights_panel, javax.swing.BoxLayout.LINE_AXIS));
lights_pane.setViewportView(lights_panel);
getContentPane().add(lights_pane);
pack();
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JScrollPane lights_pane;
private javax.swing.JPanel lights_panel;
// End of variables declaration
}
class OcModule
attr_accessor :address, :text, :ledState, :upState, :downState
def initialize(addr="01")
@address = addr
@text = 'Testing'
@ledState = :on
@upState = :off
@downState = :off
end
end
class OcModuleController < ApplicationController
set_model 'OcModule'
set_view 'OcModuleView'
def led_button_action_performed
model.text = ""
model.ledState = :off
model.upState = :off
model.downState = :off
update_view
end
end
class OcModuleView < ApplicationView
set_java_class 'app.views.oc_module_views.OcModulePanel'
BUTTON_STATES = {:off => false, :on => true}
map :model => :text, :view => "displayText.text"
map :model => :ledState, :view => "ledButton.enabled", :translate_using => BUTTON_STATES
map :model => :upState, :view => "upButton.enabled", :translate_using => BUTTON_STATES
map :model => :downState, :view => "downButton.enabled", :translate_using => BUTTON_STATES
end
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* D4Module.java
*
* Created on Oct 14, 2011, 9:39:33 AM
*/
package app.views.oc_module_views;
import app.views.d4_module_views.*;
/**
*
* @author gregd
*/
public class OcModulePanel extends javax.swing.JPanel {
/** Creates new form D4Module */
public OcModulePanel() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
upButton = new javax.swing.JButton();
downButton = new javax.swing.JButton();
displayText = new javax.swing.JTextField();
ledButton = new javax.swing.JButton();
setBackground(new java.awt.Color(235, 231, 45));
setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
setAutoscrolls(true);
setMaximumSize(new java.awt.Dimension(290, 80));
setMinimumSize(new java.awt.Dimension(290, 80));
setPreferredSize(new java.awt.Dimension(290, 80));
setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
upButton.setFont(new java.awt.Font("DejaVu Sans", 1, 14)); // NOI18N
upButton.setAlignmentY(0.0F);
upButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
upButton.setDoubleBuffered(true);
upButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
upButton.setLabel("+");
upButton.setMaximumSize(new java.awt.Dimension(25, 25));
upButton.setMinimumSize(new java.awt.Dimension(25, 25));
upButton.setPreferredSize(new java.awt.Dimension(25, 25));
add(upButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));
upButton.getAccessibleContext().setAccessibleName("");
downButton.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
downButton.setText("-");
downButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
downButton.setDoubleBuffered(true);
downButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
downButton.setMaximumSize(new java.awt.Dimension(25, 25));
downButton.setMinimumSize(new java.awt.Dimension(25, 25));
downButton.setPreferredSize(new java.awt.Dimension(25, 25));
add(downButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, -1, -1));
downButton.getAccessibleContext().setAccessibleName("");
displayText.setEditable(false);
displayText.setFont(new java.awt.Font("DejaVu Sans", 0, 24)); // NOI18N
displayText.setText("888888888888");
displayText.setDoubleBuffered(true);
displayText.setMaximumSize(new java.awt.Dimension(190, 40));
displayText.setMinimumSize(new java.awt.Dimension(190, 40));
displayText.setPreferredSize(new java.awt.Dimension(190, 40));
add(displayText, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 20, -1, -1));
ledButton.setDoubleBuffered(true);
ledButton.setMaximumSize(new java.awt.Dimension(30, 60));
ledButton.setMinimumSize(new java.awt.Dimension(30, 60));
ledButton.setPreferredSize(new java.awt.Dimension(30, 60));
ledButton.setRequestFocusEnabled(false);
ledButton.setRolloverEnabled(false);
add(ledButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 10, -1, -1));
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JTextField displayText;
private javax.swing.JButton downButton;
private javax.swing.JButton ledButton;
private javax.swing.JButton upButton;
// End of variables declaration
}
@gditrick
Copy link
Author

Need help to know why when I run this in Netbeans it locks up. The ledButton does nothing. I downloaded Nested-Simple example and it works and this is just as simple.
env: jruby-1.6.4
monkeybars-1.0.5
rawr-1.4.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment