Package org.drools.examples.conway

Examples of org.drools.examples.conway.CellGrid


    private CellGrid grid = null;
    private static final int ROWS = 5;
    private static final int COLUMNS = 10;

    protected void setUp() throws Exception {
        grid = new CellGrid(ROWS, COLUMNS);
    }
View Full Code Here


        nextGenerationButton = new JButton( nextGenerationLabel );
        final String startLabel = ConwayApplicationProperties.getProperty( "start.label" );
        startStopButton = new JButton( startLabel );
        final String clearLabel = ConwayApplicationProperties.getProperty( "clear.label" );
        clearButton = new JButton( clearLabel );
        final CellGrid grid = new CellGrid( 30,
                                            30 );
        final CellGridCanvas canvas = new CellGridCanvas( grid );
        JPanel panel = new JPanel( new BorderLayout( ) );
        panel.add( BorderLayout.CENTER,
                   canvas );
        Border etchedBorder = BorderFactory.createEtchedBorder( EtchedBorder.LOWERED );
        Border outerBlankBorder = BorderFactory.createEmptyBorder( 5,
                                                                   5,
                                                                   5,
                                                                   5 );
        Border innerBlankBorder = BorderFactory.createEmptyBorder( 5,
                                                                   5,
                                                                   5,
                                                                   5 );
        Border border = BorderFactory.createCompoundBorder( BorderFactory.createCompoundBorder( outerBlankBorder,
                                                                                                etchedBorder ),
                                                            innerBlankBorder );
        panel.setBorder( border );
        add( BorderLayout.CENTER,
             panel );
        add( BorderLayout.EAST,
             createControlPanel( ) );
        nextGenerationButton.addActionListener( new ActionListener( ) {
            public void actionPerformed(ActionEvent e)
            {
                Worker.post( new Job( ) {
                    public Object run()
                    {
                        grid.nextGeneration( );
                        return null;
                    }
                } );
                canvas.repaint( );
            }
        } );
        clearButton.addActionListener( new ActionListener( ) {
            public void actionPerformed(ActionEvent e)
            {
                Worker.post( new Job( ) {
                    public Object run()
                    {
                        grid.killAll( );
                        return null;
                    }
                } );
                canvas.repaint( );
            }
        } );

        ActionListener timerAction = new ActionListener( ) {
            public void actionPerformed(ActionEvent ae)
            {
                Worker.post( new Job( ) {
                    public Object run()
                    {
                        if ( !grid.nextGeneration( ) )
                        {
                            stopTimer( );
                        }
                        return null;
                    }
                } );
                canvas.repaint( );
            }
        };
        timer = new Timer( 500,
                           timerAction );
        startStopButton.addActionListener( new ActionListener( ) {
            public void actionPerformed(ActionEvent e)
            {
                if ( timer.isRunning( ) )
                {
                    stopTimer( );
                }
                else
                {
                    startTimer( );
                }
            }
        } );

        populatePatternSelector( );

        patternSelector.addActionListener( new ActionListener( ) {
            public void actionPerformed(ActionEvent e)
            {
                ConwayPattern pattern = (ConwayPattern) patternSelector.getSelectedItem( );
                if ( pattern != null )
                {
                    grid.setPattern( pattern );
                    canvas.repaint( );
                }
            }
        } );
View Full Code Here

TOP

Related Classes of org.drools.examples.conway.CellGrid

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.