home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 3.1 KB | 120 lines |
- // TsolTime.java
- // 22.03.96
- //
- // one of the times at which the metro comes
-
- package cybcerone.main;
-
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.awt.Graphics;
- import java.awt.image.ImageObserver;
-
- import cybcerone.utils.Date;
- import cybcerone.utils.Literate;
- import cybcerone.utils.Scaler;
-
- /**
- * My own little time class to make keeping track of the Tsol easier.
- */
- class TsolTime implements Literate {
- private int hour;
- private int minute;
- private int second;
-
- /* value entirely in seconds */
- private int value;
-
- /* to speed up painting */
- private int min1, min2, sec1, sec2;
-
- private int xIncr1 = Scaler.scale (15);
- private int xIncr2 = Scaler.scale (30);
- private int xIncr3 = Scaler.scale (40);
- private int xIncr4 = Scaler.scale (55);
- private int xIncr5 = Scaler.scale (73);
-
- private String line; /* for reading */
-
- private TsolTime (int hour, int minute, int second, int value) {
- this.hour = hour;
- this.minute = minute;
- this.second = second;
- this.value = value;
-
- min1 = minute / 10;
- min2 = minute % 10;
- sec1 = second / 10;
- sec2 = second % 10;
- }
-
- public TsolTime (int hour, int minute, int second) {
- this (hour, minute, second, secondValue (hour, minute, second));
- }
-
- private static int secondValue (int hour, int minute, int second) {
- return (hour * 3600 + minute * 60 + second);
- }
-
- public TsolTime (int hour, int minute) {
- this (hour, minute, 0);
- }
-
- /* in seconds, from midnight */
- public TsolTime (int value) {
- this (value / 3600, (value % 3600) / 60, (value % 3600) % 60, value);
- }
-
- public TsolTime (Date theDate) {
- this (theDate.getHours (), theDate.getMinutes (), theDate.getSeconds ());
- }
-
- /* for reading */
- public TsolTime () {
- }
-
- /* return true if this is before other */
- public boolean before (TsolTime other) {
- return (this.value < other.value);
- }
-
- /* returns true if this is after other */
- public boolean after (TsolTime other) {
- return (this.value > other.value);
- }
-
- /* this minus other, the difference in time */
- public TsolTime minus (TsolTime other) {
- return new TsolTime (this.value - other.value);
- }
-
- public TsolTime minus (Date other) {
- return this.minus (new TsolTime (other));
- }
-
- public Object read (DataInputStream inStream) throws IOException {
- line = inStream.readLine ();
-
- if (line != null)
- return (new TsolTime (Integer.parseInt (line.substring (0, 2)),
- Integer.parseInt (line.substring (3))));
- else
- return null;
- }
-
- public String toString () {
- return ("TsolTime[" + hour + ":" + minute + ":" + second + "]");
- }
-
- public void paint (Graphics g, int x, int y,
- TsolNumImages images, ImageObserver parent) {
- g.drawImage (images.getDigit (min1), x, y, parent);
- g.drawImage (images.getDigit (min2), x + xIncr1, y, parent);
- g.drawImage (images.getMinutes (), x + xIncr2, y, parent);
- g.drawImage (images.getDigit (sec1), x + xIncr3, y, parent);
- g.drawImage (images.getDigit (sec2), x + xIncr4, y, parent);
- g.drawImage (images.getSeconds (), x + xIncr5, y, parent);
- }
-
- }
-