[jboss-svn-commits] JBL Code SVN: r11559 - in labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway: ui and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue May 1 11:38:20 EDT 2007
Author: mark.proctor at jboss.com
Date: 2007-05-01 11:38:20 -0400 (Tue, 01 May 2007)
New Revision: 11559
Modified:
labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellGrid.java
labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ConwayGUI.java
Log:
-migrate to new statefulsession
Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellGrid.java
===================================================================
--- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellGrid.java 2007-05-01 15:26:01 UTC (rev 11558)
+++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellGrid.java 2007-05-01 15:38:20 UTC (rev 11559)
@@ -1,6 +1,7 @@
package org.drools.examples.conway;
import org.drools.RuleBase;
+import org.drools.StatefulSession;
import org.drools.WorkingMemory;
import org.drools.event.AgendaGroupPoppedEvent;
import org.drools.event.DefaultAgendaEventListener;
@@ -17,7 +18,7 @@
private final Cell[][] cells;
- private WorkingMemory workingMemory;
+ private StatefulSession session;
/**
* Constructs a CellGrid
@@ -32,7 +33,7 @@
this.cells = new Cell[rows][columns];
final RuleBase ruleBase = ConwayRuleBaseFactory.getRuleBase();
- this.workingMemory = ruleBase.newWorkingMemory();
+ this.session = ruleBase.newStatefulSession();
DefaultAgendaEventListener listener = new DefaultAgendaEventListener() {
public void agendaGroupPopped(AgendaGroupPoppedEvent event,
@@ -43,9 +44,9 @@
}
};
- this.workingMemory.addEventListener( listener );
+ this.session.addEventListener( listener );
- this.workingMemory.assertObject( this );
+ this.session.assertObject( this );
// populate the array of Cells and hook each
// cell up with its neighbors...
@@ -54,11 +55,11 @@
final Cell newCell = new Cell( column,
row );
this.cells[row][column] = newCell;
- this.workingMemory.assertObject( newCell );
+ this.session.assertObject( newCell );
}
}
- this.workingMemory.setFocus( "register neighbor" );
- this.workingMemory.fireAllRules();
+ this.session.setFocus( "register neighbor" );
+ this.session.fireAllRules();
}
/**
@@ -98,24 +99,24 @@
*/
public boolean nextGeneration() {
System.out.println( "next generation" );
- workingMemory.setFocus( "calculate" );
- workingMemory.setFocus( "kill" );
- workingMemory.setFocus( "birth" );
- workingMemory.setFocus( "reset calculate" );
- workingMemory.setFocus( "rest" );
- workingMemory.setFocus( "evaluate" );
- workingMemory.fireAllRules();
- return workingMemory.getAgenda().getAgendaGroup( "evaluate" ).size() != 0;
+ session.setFocus( "calculate" );
+ session.setFocus( "kill" );
+ session.setFocus( "birth" );
+ session.setFocus( "reset calculate" );
+ session.setFocus( "rest" );
+ session.setFocus( "evaluate" );
+ session.fireAllRules();
+ return session.getAgenda().getAgendaGroup( "evaluate" ).size() != 0;
}
/**
* kills all cells in the grid
*/
public void killAll() {
- this.workingMemory.setFocus( "calculate" );
- this.workingMemory.setFocus( "kill all" );
- this.workingMemory.setFocus( "reset calculate" );
- this.workingMemory.fireAllRules();
+ this.session.setFocus( "calculate" );
+ this.session.setFocus( "kill all" );
+ this.session.setFocus( "reset calculate" );
+ this.session.fireAllRules();
}
/**
@@ -153,16 +154,19 @@
final Cell cell = getCellAt( row + rowOffset,
column + columnOffset );
cell.setCellState( CellState.LIVE );
- this.workingMemory.modifyObject( this.workingMemory.getFactHandle( cell ),
+ this.session.modifyObject( this.session.getFactHandle( cell ),
cell );
}
}
}
- workingMemory.setFocus( "calculate" );
- workingMemory.fireAllRules();
- System.out.println( "" );
+ session.setFocus( "calculate" );
+ session.fireAllRules();
}
+ public void dispose() {
+ this.session.dispose();
+ }
+
public String toString() {
StringBuffer buf = new StringBuffer();
Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ConwayGUI.java
===================================================================
--- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ConwayGUI.java 2007-05-01 15:26:01 UTC (rev 11558)
+++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ConwayGUI.java 2007-05-01 15:38:20 UTC (rev 11559)
@@ -3,6 +3,8 @@
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
import java.util.StringTokenizer;
import javax.swing.BorderFactory;
@@ -35,6 +37,7 @@
private final JButton clearButton;
private final JComboBox patternSelector = new JComboBox();
private final Timer timer;
+ private final CellGrid grid;
public ConwayGUI() {
super( new BorderLayout() );
@@ -44,8 +47,8 @@
this.startStopButton = new JButton( startLabel );
final String clearLabel = ConwayApplicationProperties.getProperty( "clear.label" );
this.clearButton = new JButton( clearLabel );
- final CellGrid grid = new CellGrid( 30,
- 30 );
+ this.grid = new CellGrid( 30,
+ 30 );
final CellGridCanvas canvas = new CellGridCanvas( grid );
final JPanel panel = new JPanel( new BorderLayout() );
panel.add( BorderLayout.CENTER,
@@ -130,6 +133,9 @@
this.patternSelector.setSelectedIndex( -1 );
}
+ public void dispose() {
+ this.grid.dispose();
+ }
private void populatePatternSelector() {
final String patternClassNames = ConwayApplicationProperties.getProperty( "conway.pattern.classnames" );
final StringTokenizer tokenizer = new StringTokenizer( patternClassNames );
@@ -233,12 +239,19 @@
// System.setProperty( "conway.drl.file",
// args[0] );
+ final ConwayGUI gui = new ConwayGUI();
final String appTitle = ConwayApplicationProperties.getProperty( "app.title" );
final JFrame f = new JFrame( appTitle );
f.setResizable( false );
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.getContentPane().add( BorderLayout.CENTER,
- new ConwayGUI() );
+ gui );
+
+ f.addWindowListener( new WindowAdapter() {
+ public void windowClosing(WindowEvent we) {
+ gui.dispose();
+ }
+ } );
f.pack();
f.setVisible( true );
}
More information about the jboss-svn-commits
mailing list