home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 4.7 KB | 181 lines |
- // IdPanel.java
- // 27.02.96
- //
- // your basic panel
-
- package cybcerone.utils;
-
- import java.awt.Panel;
- import java.awt.Image;
- import java.awt.Graphics;
- import java.awt.Event;
- import java.awt.Rectangle;
- import java.awt.Point;
- import java.awt.Dimension;
- import java.awt.Color;
-
- /**
- * The IdPanel is just a regular panel with a few features tacked on. It
- * has an id, displays text when the mouse passes over it, and can be set
- * so that, if clicked on, it updates its parent with a string (used in
- * this case to jump to another page). Also, an image can be set to be
- * used as the background.
- */
- public class IdPanel extends Panel {
- private String id;
- private String statusText;
-
- /**
- * When the user clicks on an IdPanel, if this value is not null it is
- * used as the ID of a panel to switch to. If it's a Mapable object,
- * the mapping module will be activated and this object will be displayed.
- */
- protected Object next;
-
- /**
- * The parent of this IdPanel or, if it's at the top level, a link to
- * the Appletlike object that's running it.
- */
- protected Appletlike app;
-
- /**
- * The background image.
- */
- private Image background;
-
- /**
- * @parameter id The id for this panel.
- * @parameter statusText The text to display on the status bar.
- * @parameter app The parent of this IdPanel.
- */
- public IdPanel (String id, String statusText, Appletlike app) {
- setLayout (null);
- this.id = id;
- this.statusText = statusText;
- this.app = app;
- setBackground (Color.black);
- }
-
- /** What was that id again? */
- public String getId () { return id; }
-
- /** The text for the status bar. */
- public String getStatusText () { return statusText; }
-
- /**
- * Change the text to display on the status bar.
- */
- public void setStatusText (String statusText) {
- this.statusText = statusText;
- }
-
- /** The id of the panel to switch to. */
- public Object getNext () { return next; }
-
- /** Set the background image to this image */
- public void setBackground (Image background) {
- this.background = background;
- }
-
- /**
- * Set the background image to the image with this filename, and
- * assign it this priority while loading.
- */
- public void setBackground (String bgFile, int priority) {
- setBackground (app.getImage (bgFile, priority));
- }
-
- /** If I'm clicked on, where do I go? */
- public void setNext (Object next) {
- this.next = next;
- }
-
- /** Just draws the background. */
- public void paint (Graphics g) {
- if (background != null)
- g.drawImage (background, 0, 0, Color.black, this);
- }
-
- /** Overridden to prevent flickering. */
- public void update (Graphics g) {
- paint (g);
- }
-
- /** Display this panel's status bar text. */
- public boolean mouseEnter (Event evt, int x, int y) {
- app.showStatus (statusText);
- return true;
- }
-
- /** Clear the status bar. */
- public boolean mouseExit (Event evt, int x, int y) {
- app.showStatus ("");
- return true;
- }
-
- /**
- * When the user clicks, update app with the id of the panel to go to.
- */
- public boolean mouseDown (Event evt, int x, int y) {
- if (next != null)
- app.update (next);
- return true;
- }
-
- /**
- * Put yourself in the right place, according to this Rectangle.
- * Scaling is done automatically.
- */
- public void reshape (Rectangle placement) {
- reshape (scale (placement.x), scale (placement.y),
- scale (placement.width), scale (placement.height));
- }
-
- /**
- * Put yourself in the right place, starting at the Point and with
- * the given Dimension. Scaling is done automatically.
- */
- public void reshape (Point place, Dimension dimensions) {
- reshape (scale (place.x), scale (place.y),
- scale (dimensions.width), scale (dimensions.height));
- }
-
- /**
- * Scale this number using the current scaling factor. This method
- * makes it easier for panels to scale things.
- */
- public static final int scale (int num) {
- return Scaler.scale (num);
- }
-
- /**
- * Same as above, but make a scaled rectangle out of these parameters.
- */
- public static final Rectangle scale (int x, int y, int width, int height) {
- return Scaler.scale (x, y, width, height);
- }
-
- /**
- * Return a scaled version of this rectangle.
- */
- public static final Rectangle scale (Rectangle rec) {
- return Scaler.scale (rec);
- }
-
- /** Start any subpanels. */
- public void start () {
- for (int i = 0; i < countComponents (); i++) {
- if (getComponent (i) instanceof IdPanel) {
- ((IdPanel)getComponent(i)).start ();
- }
- }
- }
-
- /** Stop any subpanels. */
- public void stop () {
- for (int i = 0; i < countComponents (); i++)
- if (getComponent (i) instanceof IdPanel)
- ((IdPanel)getComponent(i)).stop ();
- }
- }
-