home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 3.3 KB | 162 lines |
- // ManifPaper.java
- // 01.03.96
- //
- // the paper on the manifestions screen
-
- package cybcerone.manif;
-
- import java.util.Enumeration;
-
- import cybcerone.utils.Appletlike;
- import cybcerone.utils.ScrollingPaper;
- import cybcerone.utils.Manif;
- import cybcerone.utils.ManifVector;
-
-
- /**
- * The list of events.
- */
- class ManifPaper extends ScrollingPaper implements Runnable {
- private static final String id = "manifPaper";
- private static final String statusText = "Here are the events";
-
- private Thread updater;
- private Interval currentInterval = new Interval (Interval.ALL);
- private Fac currentFac = new Fac (Fac.ALL);
-
- ManifPaper (Appletlike app) {
- super (id, statusText, app);
- }
-
- void update (Interval theInterval) {
- currentInterval = theInterval;
- update ();
- }
-
- void update (Fac theFac) {
- currentFac = theFac;
- update ();
- }
-
- void update () {
- if (updater != null)
- updater.stop ();
-
- updater = new Thread (this);
- updater.start ();
- }
-
- public void stop () {
- if (updater != null)
- updater.stop ();
- updater = null;
- }
-
- public void run () {
- int first, last;
- Manif oneManif;
-
- while (theData == null) {
- try {
- updater.sleep (1000);
- } catch (InterruptedException e) {
- }
- }
-
- ManifVector theManifs = new ManifVector (theData.toVector ());
-
- if (currentInterval.getInterval () == Interval.ALL) {
- first = 0;
- last = theManifs.size () - 1;
- } else {
- first = searchFirst (currentInterval, theManifs);
- last = searchLast (currentInterval, theManifs, first);
- }
-
- if (currentFac.getFac () == Fac.ALL) {
- setDataRange (theData, first, last);
- } else {
- clearPages ();
- for (int i = first; i <= last; i++) {
- oneManif = theManifs.elementAt (i);
-
- if (currentFac.includes (oneManif)) {
- addLine (oneManif);
- }
- }
- }
-
- repaint ();
- }
-
- /**
- * Find the first event in this interval.
- */
- private int searchFirst (Interval theInterval, ManifVector events) {
- int first = 0;
- int last = events.size () - 1;
- int current = 0;
- Manif oneManif = null;
-
- while (last > first) {
- current = (first + last) / 2;
- oneManif = events.elementAt (current);
- if (theInterval.includes (oneManif)) {
- last = current;
- } else {
- if (theInterval.after (oneManif))
- first = current + 1;
- else
- last = current - 1;
- }
- }
-
- if (last == first) {
- current = first;
- oneManif = events.elementAt (current);
- }
-
- if (theInterval.includes (oneManif)) {
- return current;
- } else {
- return -1;
- }
- }
-
-
- /**
- * Find the last event in this interval.
- */
- private int searchLast (Interval theInterval, ManifVector events, int first) {
- int last = events.size () - 1;
- Manif oneManif;
- int current = 0;
-
- if (first >= 0) {
-
- while (last > first) {
- current = (first + last + 1) / 2;
- oneManif = events.elementAt (current);
- if (theInterval.includes (oneManif)) {
- first = current;
- } else {
- if (theInterval.after (oneManif)) {
- first = current + 1;
- } else {
- last = current - 1;
- }
- }
- }
- if (first == last) current = first;
-
- return current;
-
- } else {
-
- return (first - 1);
-
- }
- }
- }
-
-