home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 5.1 KB | 201 lines |
- // Paper.java
- // 27.02.96
- //
- // Duh, paper.
-
- package cybcerone.utils;
-
- import java.awt.Color;
- import java.awt.Image;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.awt.Event;
- import java.util.Enumeration;
-
- /**
- * This is the SubPanel that looks like a sheet a paper. Draws itself in
- * the left-hand side of the screen.
- */
- public class Paper extends IdPanel {
- private static final String paperStatusText = "Click for more information";
-
- /** This is where I draw myself. */
- protected static final Rectangle placement = new Rectangle (0, 0, 734, 668);
-
- /** Where are my images? */
- protected static final String imagePath = "personnes/";
- private static final String bgFile = imagePath + "fond_text.gif";
-
- /* Some useful constants. */
-
- /** A dark shade of gray. */
- protected Color darkGray = new Color (160, 160, 160);
-
- /** A light shade of gray. */
- protected Color lightGray = new Color (192, 192, 192);
-
- /** Black. You know, opposite of white? */
- protected Color black = Color.black;
-
- /** Maximum # of lines on a page. */
- protected int maxLines = 16;
-
- /** Height, in pixels, of a line. */
- protected int lineHeight = scale (40);
-
- /** The border, in pixels, of the image. */
- protected int border = 7;
-
- /** Handy spacer. */
- protected int inset = scale (5);
-
- /** When we indent stuff, do it by this much. */
- protected int indentWidth = scale (20);
-
- /** What we're displaying at the moment. */
- protected Page currentPage;
-
- /** All the information at our disposal. */
- protected PaintableVector theData;
-
- /* for double buffering */
- private static Image offscreenImg;
- private static Graphics offscreenG;
-
-
- /**
- * I want to live!
- */
- public Paper (String id, String statusText, Appletlike app) {
- super (id, paperStatusText, app);
- reshape (placement);
-
- // setBackground (bgFile, 1);
- setFont (Fonts.bigFont);
- setBackground (Color.white);
- setForeground (Color.black);
- }
-
- /**
- * Clear out the current page. Don't repaint just yet, presumable
- * someone's about to add some lines.
- */
- protected void clearPage () {
- currentPage = new Page (maxLines);
- }
-
- /**
- * Returns true if this line was successfully added to the current
- * page. Can fail if there's already maxLines lines there, or if
- * the page was not constructed in a way so as to be updateable.
- */
- protected boolean addLine (Paintable newLine) {
- return currentPage.addLine (newLine);
- }
-
- /**
- * Set the data at our disposal.
- */
- public void setData (PaintableVector theData) {
- this.theData = theData;
- currentPage = new Page (theData);
- repaint ();
- }
-
- /**
- * Draw my background and, if it exists, the info on the current page.
- */
- public void paint (Graphics g) {
- super.paint (g);
-
- g.setColor (getBackground ());
- g.fillRect (0, 0, size().width, size().height);
-
- g.setColor (Color.black);
- g.drawRect (0, 0, size().width, size().height);
- g.drawRect (1, 1, size().width - 2, size().height - 2);
- g.drawRect (2, 2, size().width - 4, size().height - 4);
- g.drawRect (3, 3, size().width - 6, size().height - 6);
- g.drawRect (4, 4, size().width - 8, size().height - 8);
- g.drawRect (5, 5, size().width - 10, size().height - 10);
- g.drawRect (6, 6, size().width - 12, size().height - 12);
- g.drawRect (7, 7, size().width - 14, size().height - 14);
-
- g.setColor (getForeground ());
- g.setFont (Fonts.bigFont);
- if (currentPage != null)
- paintLines (g, currentPage.getLines());
- }
-
- /** to stop the flicker */
- public void update (Graphics g) {
- if (offscreenG == null) {
- offscreenImg = createImage (size().width, size().height);
- offscreenG = offscreenImg.getGraphics ();
- }
-
- paint (offscreenG);
- g.drawImage (offscreenImg, 0, 0, this);
- }
-
-
-
- /**
- * For each line on the current page, draw it. Draw a light gray line
- * underneath.
- */
- protected void paintLines (Graphics g, PaintableVector items) {
- int yPos = border + lineHeight;
-
- if (items != null) {
- for (Enumeration e = items.elements (); e.hasMoreElements ();) {
- ((Paintable)e.nextElement ()).paint (g, border + inset, yPos, this);
- drawLine (g, yPos);
- yPos += lineHeight;
- }
- }
- }
-
- /**
- * Here's how we draw that light gray line underneath each line
- * of information.
- */
- protected void drawLine (Graphics g, int yPos) {
- g.setColor (lightGray);
- g.drawLine (border + inset, yPos + inset,
- scale (placement.width) - border - inset, yPos + inset);
- g.setColor (black);
- }
-
- /**
- * The user clicked on something, update our parent with whatever
- * it was.
- */
- public boolean mouseDown (Event evt, int x, int y) {
- Object item = whichItem (x, y);
-
- if (item != null)
- app.update (item);
- return true;
- }
-
- /**
- * Which object is at this location?
- */
- protected Object whichItem (int x, int y) {
- int line = (y - border - 7) / lineHeight;
-
- if (currentPage != null) {
- PaintableVector lines = currentPage.getLines ();
-
- if (lines != null & lines.size () > line)
- return lines.elementAt (line);
- else
- return null;
- } else {
- return null;
- }
- }
-
- }
-