home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 4.5 KB | 187 lines |
- // FacultePaper.java
- // 01.03.96
- //
- // the paper on the faculte screen
-
- package cybcerone.faculte;
-
- import java.awt.Image;
- import java.awt.Graphics;
- import java.awt.Event;
- import java.util.Vector;
- import java.util.Enumeration;
-
- import cybcerone.utils.Appletlike;
- import cybcerone.utils.Paper;
- import cybcerone.utils.FaculteVector;
- import cybcerone.utils.Faculte;
- import cybcerone.utils.Paintable;
- import cybcerone.utils.PaintableVector;
-
- /**
- * The paper on the facultes screen.
- */
- class FacultePaper extends Paper implements Runnable {
- private static final String id = "facultePaper";
- private static final String statusText = "These are our faculties";
-
- private Thread updater;
- private String updateName;
-
- protected Faculte currentFaculte;
-
- /** The number of items to show with a dark gray background. */
- protected int darkLines;
-
- /**
- * The number of lines (not information, actual lines) that we've
- * been asked to draw so far. Used to make sure that we don't draw
- * lines when writing information in the dark gray area.
- */
- protected int drawLinesCount;
-
- FacultePaper (Appletlike app) {
- super (id, statusText, app);
- }
-
- /**
- * Search for the faculte with this name.
- */
- void update (String name) {
- if (updater != null)
- updater.stop ();
-
- updateName = name;
- updater = new Thread (this);
- updater.start ();
- }
-
- public void stop () {
- if (updater != null)
- updater.stop ();
- updater = null;
- }
-
- public void run () {
- boolean done = false;
- Faculte oneFac = null;
-
- while (theData == null) {
- try {
- updater.sleep (1000);
- } catch (InterruptedException e) {
- }
- }
-
- FaculteVector theFacs = new FaculteVector (theData.toVector ());
-
- for (Enumeration e = theFacs.elements ();
- e.hasMoreElements () && !done;) {
- oneFac = (Faculte)e.nextElement ();
-
- if (oneFac.getName().equals (updateName)) {
- done = true;
- update (oneFac);
- }
- }
- }
-
- /** Here's my data. */
- public void setData (PaintableVector theData) {
- this.theData = theData;
- if (theData != null && theData.size () > 0)
- update ((Faculte)theData.elementAt (0));
- }
-
- /**
- * Show this new and exciting faculte.
- */
- void update (Faculte newFaculte) {
- FaculteVector children = newFaculte.getChildren ();
-
- if (children != null) {
-
- currentFaculte = newFaculte;
- clearPage ();
- darkLines = newFaculte.getLevel ();
-
- addAncestors (newFaculte);
-
- if (newFaculte.getLevel () != 0)
- addLine (newFaculte);
-
- if (children != null) {
- for (Enumeration e = children.elements (); e.hasMoreElements ();)
- addLine ((Paintable)e.nextElement ());
- }
- repaint ();
-
- } else if (newFaculte.getLevel () == 0) {
- clearPage ();
- repaint ();
- } else {
- app.update (newFaculte);
- }
- }
-
- private void addAncestors (Faculte fac) {
- Faculte ancestor = fac.getParent ();
-
- if (ancestor != null && ancestor.getLevel () > 0) {
- addAncestors (ancestor);
- addLine (ancestor);
- }
- }
-
- /**
- * We draw things a bit differently on this page. There are light and
- * dark gray backgrounds, and lines may be indented.
- */
- protected void paintLines (Graphics g, PaintableVector items) {
- int yPos = border + (lineHeight * (darkLines + 1));
- drawLinesCount = 0;
-
- g.clipRect (border, border,
- placement.width - (border * 2),
- placement.height - (border * 2));
-
- if (darkLines > 0) {
- g.setColor (darkGray);
- g.fillRect (0, 0, placement.width, placement.height);
- }
-
- g.setColor (lightGray);
- g.fillRect (border + darkLines * indentWidth + (darkLines == 0 ? 0 : 5),
- border + darkLines * lineHeight + (darkLines == 0 ? 0 : 5),
- placement.width, placement.height);
-
- g.setColor (black);
- super.paintLines (g, items);
- }
-
- /**
- * Draw a line (not a piece of information, an actual line).
- */
- protected void drawLine (Graphics g, int yPos) {
- if (++drawLinesCount > darkLines)
- g.drawLine (border + (darkLines * indentWidth) + inset, yPos + inset,
- placement.width, yPos + inset);
- }
-
- /**
- * If the user clicks on the current Faculte, show its parent,
- * otherwise show the faculte that was clicked on.
- */
- public boolean mouseDown (Event evt, int x, int y) {
- Faculte theFac = (Faculte)whichItem (x, y);
-
- if (theFac != null) {
- if (theFac.equals (currentFaculte))
- update (theFac.getParent ());
- else
- update (theFac);
- }
- return true;
- }
- }
-