home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 2.8 KB | 135 lines |
- // UnitePaper.java
- // 18.03.96
- //
- // the paper on the unite screen
-
- package cybcerone.unite;
-
- import cybcerone.utils.Appletlike;
- import cybcerone.utils.ScrollingPaper;
- import cybcerone.utils.UniteVector;
-
- /**
- * The paper on the unite screen.
- */
- class UnitePaper extends ScrollingPaper implements Runnable {
- private static final String id = "UnitePaper";
- private static final String statusText = "Click for a room";
-
- private Thread updater;
- private String updateName;
-
- UnitePaper (Appletlike app) {
- super (id, statusText, app);
- }
-
- /**
- * Search for 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 () {
- int first, last;
-
- while (theData == null) {
- try {
- updater.sleep (1000);
- } catch (InterruptedException e) {
- }
- }
-
- UniteVector thePeople = new UniteVector (theData.toVector ());
-
- if (updateName.equals ("")) {
- first = 0;
- last = thePeople.size () - 1;
- } else {
- first = searchFirst (updateName, thePeople);
- last = searchLast (updateName, thePeople, first);
- }
- setDataRange (theData, first, last);
- }
-
- /**
- * Find the first occurance of this name.
- */
- private int searchFirst (String name, UniteVector rooms) {
- int first = 0;
- int last = rooms.size () - 1;
- int current = 0;
- String UniteName = null;
-
- while (last > first) {
- current = (first + last) / 2;
- UniteName = rooms.elementAt(current).getName();
- if (UniteName.startsWith (name)) {
- last = current;
- } else {
- if (UniteName.compareTo (name) < 0)
- first = current + 1;
- else
- last = current - 1;
- }
- }
-
- if (last == first) {
- current = first;
- UniteName = rooms.elementAt(current).getName();
- }
-
- if (UniteName.startsWith (name)) {
- return current;
- } else {
- return -1;
- }
- }
-
- /**
- * Find the last occurance of this name.
- */
- private int searchLast (String name, UniteVector rooms, int first) {
- int last = rooms.size () - 1;
- String UniteName = null;
- int current = 0;
-
- if (first >= 0) {
-
- while (last > first) {
- current = (first + last + 1) / 2;
- UniteName = rooms.elementAt(current).getName();
- if (UniteName.startsWith (name)) {
- first = current;
- } else {
- if (UniteName.compareTo (name) < 0) {
- first = current + 1;
- } else {
- last = current - 1;
- }
- }
- }
- if (first == last) current = first;
-
- return current;
-
- } else {
-
- return (first - 1);
-
- }
- }
- }
-
-