Example #1
0
  /**
   * Set the scroll position.
   *
   * @param x coordinate of upper left corner.
   * @param y coordinate of upper left corner.
   */
  public void setScrollPosition(int x, int y) {
    final DjVuImage image = getImage();
    if ((image != null) && ((x != scrollPosition.x) || (y != scrollPosition.y))) {
      final Dimension imageSize = image.getSize();
      final Dimension viewportSize = getViewportSize();
      x = Math.max(0, Math.min(imageSize.width - viewportSize.width, x));
      y = Math.max(0, Math.min(imageSize.height - viewportSize.height, y));

      if ((x != scrollPosition.x) || (y != scrollPosition.y)) {
        scrollPosition.setLocation(x, y);
        updateScrollbars();
        repaint(50L);
      }
    }
  }
Example #2
0
 /*Creates the equipment in all states to initiate the game */
 private void fillStates(int sAvail, int sRent, int sShop) {
   int[] statesSizes = {sAvail, sRent, sShop};
   int s = 1;
   for (int stateSize : statesSizes) {
     for (int t = 1; t <= TYPES; t++) {
       for (int i = 1; i <= stateSize; i++) {
         Equipment e = new Equipment();
         e.state = s;
         e.type = t;
         int sMax =
             Math.max(
                 s - 2, 0); /*formula to make sure identifiers resume counting and stay unique */
         int sMin =
             Math.min(
                 s - 1, 1); /*formula to make sure identifiers resume counting and stay unique */
         e.ident = i + (sMin) * sAvail + (sMax) * sRent;
         e.c = equipColor(e.type);
         switch (s) {
           case 1:
             availEquipment.add(e);
             break;
           case 2:
             rentEquipment.add(e);
             break;
           case 3:
             shopEquipment.add(e);
             break;
         }
       }
     }
     s++;
   }
   computeInitialTimes();
   assignShapes();
 }
Example #3
0
  /**
   * Get the Maximum Y value of all attached DataSets.
   *
   * @return The maximum value
   */
  public double getYmax() {
    DataSet d;
    double max = 0.0;

    if (dataset == null | dataset.isEmpty()) return max;
    for (int i = 0; i < dataset.size(); i++) {
      d = ((DataSet) dataset.elementAt(i));
      if (i == 0) max = d.getYmax();
      else max = Math.max(max, d.getYmax());
    }

    return max;
  }
Example #4
0
 public void sizeToText() {
   Dimension d = new Dimension(0, 0);
   Dimension di;
   for (int i = 0; i < nLists; i++) {
     fm = getFontMetrics(list[i].getFont());
     di = list[i].preferredSize();
     d.height += di.height;
     for (int j = 0; j < list[i].countItems(); j++) {
       d.width = Math.max(d.width, fm.stringWidth(list[i].getItem(j) + "  "));
     }
   }
   for (int i = 0; i < nLists; i++) {
     list[i].resize(d.width + hSpace / 3, list[i].preferredSize().height);
   }
   panel.resize(d.width + hSpace / 3, list[1].preferredSize().height);
   this.resize(d.width + hSpace, d.height + vSpace);
   panel.invalidate();
   validate();
 }
 double trim(double x, double min_value, double max_value) {
   return Math.min(Math.max(x, min_value), max_value);
 }
Example #6
0
  /**
   * Force the plot to have an aspect ratio of 1 by forcing the axes to have the same range. If the
   * range of the axes are very different some extremely odd things can occur. All axes are forced
   * to have the same range, so more than 2 axis is pointless.
   */
  protected Rectangle ForceSquare(Graphics g, Rectangle r) {
    Axis a;
    Rectangle dr;
    int x = r.x;
    int y = r.y;
    int width = r.width;
    int height = r.height;

    double xmin;
    double xmax;
    double ymin;
    double ymax;

    double xrange = 0.0;
    double yrange = 0.0;
    double range;

    double aspect;

    if (dataset == null | dataset.isEmpty()) return r;

    /*
     **          Force all the axis to have the same range. This of course
     **          means that anything other than one xaxis and one yaxis
     **          is a bit pointless.
     */
    for (int i = 0; i < axis.size(); i++) {
      a = (Axis) axis.elementAt(i);
      range = a.maximum - a.minimum;
      if (a.isVertical()) {
        yrange = Math.max(range, yrange);
      } else {
        xrange = Math.max(range, xrange);
      }
    }

    if (xrange <= 0 | yrange <= 0) return r;

    if (xrange > yrange) range = xrange;
    else range = yrange;

    for (int i = 0; i < axis.size(); i++) {
      a = (Axis) axis.elementAt(i);
      a.maximum = a.minimum + range;
    }
    /*
     **          Get the new data rectangle
     */
    dr = getDataRectangle(g, r);
    /*
     **          Modify the data rectangle so that it is square.
     */
    if (dr.width > dr.height) {
      x += (dr.width - dr.height) / 2.0;
      width -= dr.width - dr.height;
    } else {
      y += (dr.height - dr.width) / 2.0;
      height -= dr.height - dr.width;
    }

    return new Rectangle(x, y, width, height);
  }