Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## sema
Class Box

    java.lang.Object
      sema.Box

Direct Known Subclasses:
  CoveringBox, ObstacleBox

public class Box
extends java.lang.Object

Square box. It's the pavement of the `Map`, used to draw the ground. But it is also used as a hashtable, to detect the presence of `Elements` in a given area of the map, without examining each element of the world. This is very useful for the computations linked to collisions, or to searche for elements in an area of the world. Is it typically used by the main application to refresh the drawing without unuseful computations (`ZGCarteSEMA.paintComponent(Graphics)`).

Field Summary
`protected Drawing` | `g`
`protected java.awt.Image` | `image`
`protected Map` | `map`
`int` | `x` the x-coordinate ( in the boxes' matrix 0 is at the left)
`int` | `y` the y-coordinate ( in the boxes' matrix 0 is at the top)

Constructor Summary
`Box(Map map, Drawing drawing, int x, int y, float height, java.lang.String kind, java.awt.Image image)` Constructs a `Box`.

Method Summary
`void` | `draw()` Draws the `Box`.
`void` | `drawBorder(java.awt.Color c)`
`void` | `fill(java.awt.Color c)`
`java.util.TreeSet` | `getContents()` Returns the registered `Elements` in the `Box`.
`float` | `getHeight()` Returns the height.
`javax.swing.Icon` | `getIcon()` Returns the associated icon.
`java.awt.Image` | `getImage()` Returns the associated image (main image used to create icon and to draw the default)
`java.lang.String` | `getKind()` Returns the kind.
`java.lang.String[][]` | `getProperties()` Returns the box's properties.
`void` | `highlight()` Highlight the `Box` (used when the box is selected) With the default blue color for a box.
`void` | `highlight(java.awt.Color c)` Highlight the `Box`.
`boolean` | `isFreeFor(Element el)` Determinate whether the `Box` can host the `Element`.
`void` | `register(Element element)` Register an `Element` in the `Box`.
`void` | `setProperties(java.lang.String property, java.lang.String value)` Try to sets the value to the property of the box.
`void` | `unregister(Element element)` Unregister an element from the `Box`.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### map

    protected Map map

### g

    protected Drawing g

### x

    public final int x

  the x-coordinate ( in the boxes' matrix 0 is at the left)

### y

    public final int y

  the y-coordinate ( in the boxes' matrix 0 is at the top)

### image

    protected java.awt.Image image

Constructor Detail

### Box

    public Box(Map map,
               Drawing drawing,
               int x,
               int y,
               float height,
               java.lang.String kind,
               java.awt.Image image)

  Constructs a `Box`. With his containing `Map`, his matrix coordinates, his height, his kind, and a main image.

Parameters:
  `map` - the map containing it.
  `drawing` - the drawing object of the simulation.
  `x` - the x-coordinate ( in the matrix of boxes, 0 is at the left)
  `y` - the x-coordinate ( in the matrix of boxes, 0 is at the top)
  `height` - the height.
  `kind` - the kind.
  `image` - The main image, used to draw itself and to create the icon.
See Also:
  `Map`, `Drawing`

Method Detail

### getHeight

    public float getHeight()

  Returns the height.

  Returns:
    the height.

### getKind

    public java.lang.String getKind()

  Returns the kind.

  Returns:
    the kind.

### getImage

    public java.awt.Image getImage()

  Returns the associated image (main image used to create icon and to draw the default)

  Returns:
    the associated main image.

### getContents

    public java.util.TreeSet getContents()

  Returns the registered `Elements` in the `Box`. It returns a copy of the treeSet so that no external modification could be made.

  Returns:
    the registered `Elements` in the `Box`.

### isFreeFor

    public boolean isFreeFor(Element el)

  Determinate whether the `Box` can host the `Element`. Very useful to design obstacles or restricted areas. However, some special agents could ignore the advice of the box.

  Parameters:
    `el` - the element to host.
  Returns:
    whether the `Box` can host the `Element`.

### register

    public void register(Element element)

  Register an `Element` in the `Box`. The call to this method should be made by : `Area.getIntersectedBoxes()`.

  Parameters:
    `element` - the element to register.

### unregister

    public void unregister(Element element)

  Unregister an element from the `Box`. The call to this method should be made by `Area.getIntersectedBoxes()` or `Element.death()`.

  Parameters:
    `element` - the element to unregister.

### getIcon

    public javax.swing.Icon getIcon()

  Returns the associated icon. It has to be an icon of dimension smaller than 100x100. It is used as the identity icon in the graphical interface. By default it is the main image resized and transformed into an icon.

  Returns:
    the associated icon.
  See Also:
    `Icon`

### draw

    public void draw()

  Draws the `Box`. if the image is set it draw the image.

### fill

    public void fill(java.awt.Color c)

### drawBorder

    public void drawBorder(java.awt.Color c)

### highlight

    public void highlight(java.awt.Color c)

  Highlight the `Box`.

### highlight

    public void highlight()

  Highlight the `Box` (used when the box is selected) With the default blue color for a box.

### getProperties

    public java.lang.String[][] getProperties()

  Returns the box's properties.

  Returns:
    the element's properties.
  See Also:
    `Engine.getProperties()`

### setProperties

    public void setProperties(java.lang.String property,
                              java.lang.String value)

  Try to sets the value to the property of the box. The new value is ignored if the property is read_only or if the value isn't valid.

  Parameters:
    `property` - the property to change.
    `value` - the new value for the property.
  See Also:
    `Engine.setProperties(java.lang.String, java.lang.String)`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD