home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 201 / DPCS1104.ISO / data1.cab / Internet_Extensions / Java / SerifMarquee / Misc.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-08-11  |  2.3 KB  |  70 lines

  1. import java.awt.Color;
  2. import java.awt.Point;
  3. import java.awt.Rectangle;
  4. import java.util.StringTokenizer;
  5.  
  6. public final class Misc {
  7.    public static final Color InterpolateColour(Color start, Color end, long mul, long div) {
  8.       if (mul < 0L) {
  9.          return start;
  10.       } else if (mul >= div) {
  11.          return end;
  12.       } else {
  13.          int red = (int)((long)start.getRed() + (long)(end.getRed() - start.getRed()) * mul / div);
  14.          int green = (int)((long)start.getGreen() + (long)(end.getGreen() - start.getGreen()) * mul / div);
  15.          int blue = (int)((long)start.getBlue() + (long)(end.getBlue() - start.getBlue()) * mul / div);
  16.          return new Color(red, green, blue);
  17.       }
  18.    }
  19.  
  20.    public static final int InterpolateInt(int start, int end, long mul, long div) {
  21.       if (mul < 0L) {
  22.          return start;
  23.       } else {
  24.          return mul >= div ? end : (int)((long)start + (long)(end - start) * mul / div);
  25.       }
  26.    }
  27.  
  28.    public static final Point InterpolatePoint(Point start, Point end, long mul, long div) {
  29.       if (mul < 0L) {
  30.          return start;
  31.       } else if (mul >= div) {
  32.          return end;
  33.       } else {
  34.          int x = (int)((long)start.x + (long)(end.x - start.x) * mul / div);
  35.          int y = (int)((long)start.y + (long)(end.y - start.y) * mul / div);
  36.          return new Point(x, y);
  37.       }
  38.    }
  39.  
  40.    public static final Color initColour(String param) {
  41.       StringTokenizer st = new StringTokenizer(param, ",");
  42.       int r = 0;
  43.       int g = 0;
  44.       int b = 0;
  45.  
  46.       try {
  47.          r = Integer.valueOf(st.nextToken());
  48.          g = Integer.valueOf(st.nextToken());
  49.          b = Integer.valueOf(st.nextToken());
  50.       } catch (Exception var7) {
  51.       }
  52.  
  53.       return new Color(r, g, b);
  54.    }
  55.  
  56.    public static final Rectangle InterpolateRectangle(Rectangle start, Rectangle end, long mul, long div) {
  57.       if (mul < 0L) {
  58.          return start;
  59.       } else if (mul >= div) {
  60.          return end;
  61.       } else {
  62.          int x = (int)((long)start.x + (long)(end.x - start.x) * mul / div);
  63.          int y = (int)((long)start.y + (long)(end.y - start.y) * mul / div);
  64.          int width = (int)((long)start.width + (long)(end.width - start.width) * mul / div);
  65.          int height = (int)((long)start.height + (long)(end.height - start.height) * mul / div);
  66.          return new Rectangle(x, y, width, height);
  67.       }
  68.    }
  69. }
  70.