becker.robots
Class RobotUIComponents

java.lang.Object
  extended by becker.robots.RobotUIComponents

public class RobotUIComponents
extends Object

A factory object that provides the major user interface components, making customized user interfaces easy to create.

For example, CityFrame has the controls on the left side rather than the right. Other, less trivial changes, are also possible.

import becker.robots.*;
import becker.robots.Robot;

import javax.swing.*;
import java.awt.*;

public class CityFrame {
        private JFrame frame;
        private RobotUIComponents ui;

        public CityFrame(City model, int firstVisibleStreet,
                        int firstVisibleAvenue, int numVisibleStreets, int numVisibleAvenues) {
                super();
                this.frame = new JFrame("Robots: Learning to program with Java");

                // this.frame.addWindowListener(new WindowCloser());

                this.ui = new RobotUIComponents(model, firstVisibleStreet,
                                firstVisibleAvenue, numVisibleStreets, numVisibleAvenues);

                this.frame.setJMenuBar(ui.getMenuBar());

                JPanel view = new JPanel(new BorderLayout());
                CityView sp = ui.getCityView();

                view.add(sp, BorderLayout.CENTER);
                view.add(ui.getControlPanel(), BorderLayout.WEST);

                this.frame.setContentPane(view);
                this.frame.pack();
                this.frame.repaint();
                this.frame.setVisible(true);
        }

        public static void main(String[] args) {
                City.showFrame(false);  // prevent City from showing its own frame
                City c = new City(-1, -2, 4, 5);
                Robot r = new Robot(c, 1, 1, Direction.EAST, 0);
                CityFrame cf = new CityFrame(c, -1, -2, 4, 5);

                r.move();
                r.move();
        }

}

 

Author:
Byron Weber Becker

Constructor Summary
RobotUIComponents(City model)
          Create the components for a default view of the city using the defaults in becker.robots.ini for the visible streets and avenues and intersection size.
RobotUIComponents(City model, int leftAve, int topStr, int width, int height)
          Create the components to view a specified section of the city.
RobotUIComponents(City model, int leftAve, int topStr, int width, int height, int simSize)
          Create the components to view a specified section of the city.
 
Method Summary
 CityView getCityView()
          Get a component that shows the city and the city's scrollbars.
 JPanel getControlPanel()
          Get a panel grouping the start/stop button and speed slider together
 JMenuBar getMenuBar()
          Get the menu bar for the user interface.
 JSlider getSpeedSlider()
          Get a slider to control the speed of the animation.
 JButton getStartStopButton()
          Get a button to start and stop the animation
 JPanel getUI()
          Get a panel grouping the city's view with the traditional control panel.
 JSlider getZoom()
          Get a component that causes the view to zoom in on the city
 void quitApp()
          Quit the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RobotUIComponents

public RobotUIComponents(City model)
Create the components for a default view of the city using the defaults in becker.robots.ini for the visible streets and avenues and intersection size.

Parameters:
model - the city to show

RobotUIComponents

public RobotUIComponents(City model,
                         int leftAve,
                         int topStr,
                         int width,
                         int height,
                         int simSize)
Create the components to view a specified section of the city.

Parameters:
model - the city to show
leftAve - the leftmost avenue to show
topStr - the topmost street to show
width - the number of avenues to show
height - the number of streets to show
simSize - the size, in pixels, of each sim (ie: the size of one intersection)

RobotUIComponents

public RobotUIComponents(City model,
                         int leftAve,
                         int topStr,
                         int width,
                         int height)
Create the components to view a specified section of the city.

Parameters:
model - the city to show
leftAve - the leftmost avenue to show
topStr - the topmost street to show
width - the number of avenues to show
height - the number of streets to show
Method Detail

getSpeedSlider

public JSlider getSpeedSlider()
Get a slider to control the speed of the animation.

Returns:
a slider to control the speed

getStartStopButton

public JButton getStartStopButton()
Get a button to start and stop the animation

Returns:
a start/stop button

getCityView

public CityView getCityView()
Get a component that shows the city and the city's scrollbars.

Returns:
a component showing the city

getZoom

public JSlider getZoom()
Get a component that causes the view to zoom in on the city

Returns:
a component controlling zoom

getControlPanel

public JPanel getControlPanel()
Get a panel grouping the start/stop button and speed slider together

Returns:
a control panel

getUI

public JPanel getUI()
Get a panel grouping the city's view with the traditional control panel.

Returns:
the traditional UI

getMenuBar

public JMenuBar getMenuBar()
Get the menu bar for the user interface.

Returns:
the application's menu bar.

quitApp

public void quitApp()
Quit the application.