Example #1
0
  private void computeWorkersSizes(Dimension panelDimensions) {

    // check when the column of of workers start
    double startWorkerColumn = 8d * panelDimensions.getWidth() / 9d;

    double workerColumnWidth = panelDimensions.getWidth() - startWorkerColumn;
    workerXStart = startWorkerColumn + workerColumnWidth / 5d;
    workerXEnd = panelDimensions.getWidth() - workerColumnWidth / 5d;
    workerFirstY = panelDimensions.getHeight() / 9d;
    workerLastY = 8d * panelDimensions.getHeight() / 9d;
    workerHeight = (workerLastY - workerFirstY) / new Double(Market.numberOfWorkers);
    assert workerXStart > 0;
    assert workerXEnd > 0;
    assert workerFirstY > 0;
    assert workerLastY > 0;
    assert workerHeight > 0;

    int index = 0;
    for (Consumer x : SleepStoneTest.market.getLabor().workers) {
      Rectangle rectangle =
          new Rectangle(
              (int) workerXStart,
              (int) (workerFirstY + index * workerHeight),
              (int) (workerXEnd - workerXStart),
              (int) workerHeight);
      tradersPlace.put(x, new Point((int) rectangle.getCenterX(), (int) rectangle.getCenterY()));
      consumerPlace.put(x, rectangle);
      index++;
    }
  }
Example #2
0
  private void computeFirmSizes(Dimension panelDimensions) {

    ArrayList<Firm> firms = SleepStoneTest.firms;

    double rowMaxLenght = 8d * panelDimensions.getWidth() / 9d;

    // check when the column of of workers start
    double halfheight = panelDimensions.getHeight() / 2d;
    firmYStart = halfheight / 3d;
    firmYEnd = 2d * halfheight / 3d;

    firmFirstX = rowMaxLenght / 11d;
    firmLastX = 10d * rowMaxLenght / 11d;
    double rowRealLenght = firmLastX - firmFirstX;
    firmLenght = (rowRealLenght * 3d) / (4d * new Double(firms.size()));
    firmSpacing = firmLenght / 3d;

    // compute the rectangles
    for (int i = 0; i < firms.size(); i++) {

      Rectangle location =
          new Rectangle(
              (int) Math.round(firmFirstX + i * (firmLenght + firmSpacing)),
              (int) Math.round(firmYStart),
              (int) Math.round(firmLenght),
              (int) Math.round(firmYEnd - firmYStart));
      System.out.println(location);
      firmsPlace.put(firms.get(i), location);
      tradersPlace.put(
          firms.get(i), new Point((int) location.getCenterX(), (int) location.getCenterY()));
    }
  }
  public void paint(Graphics g) {
    // repaint the whole transformer in case the view component was repainted
    Rectangle clipBounds = g.getClipBounds();
    if (clipBounds != null && !clipBounds.equals(visibleRect)) {
      repaint();
    }
    // clear the background
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());

    if (view != null && at.getDeterminant() != 0) {
      Graphics2D g2 = (Graphics2D) g.create();
      Insets insets = getInsets();
      Rectangle bounds = getBounds();

      // don't forget about insets
      bounds.x += insets.left;
      bounds.y += insets.top;
      bounds.width -= insets.left + insets.right;
      bounds.height -= insets.top + insets.bottom;
      double centerX1 = bounds.getCenterX();
      double centerY1 = bounds.getCenterY();

      Rectangle tb = getTransformedSize();
      double centerX2 = tb.getCenterX();
      double centerY2 = tb.getCenterY();

      // set antialiasing by default
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      if (renderingHints != null) {
        g2.addRenderingHints(renderingHints);
      }
      // translate it to the center of the view component again
      double tx = centerX1 - centerX2 - getX();
      double ty = centerY1 - centerY2 - getY();
      g2.translate((int) tx, (int) ty);
      g2.transform(at);
      view.paint(g2);
      g2.dispose();
    }
    // paint the border
    paintBorder(g);
  }
  public static void paintButtonGroupLines(
      RadRootContainer rootContainer, RadButtonGroup group, Graphics g) {
    List<RadComponent> components = rootContainer.getGroupContents(group);
    if (components.size() < 2) return;
    Rectangle[] allBounds = new Rectangle[components.size()];
    int lastTop = -1;
    int minLeft = Integer.MAX_VALUE;
    for (int i = 0; i < components.size(); i++) {
      final Rectangle rc =
          SwingUtilities.convertRectangle(
              components.get(i).getParent().getDelegee(),
              components.get(i).getBounds(),
              rootContainer.getDelegee());
      allBounds[i] = rc;

      minLeft = Math.min(minLeft, rc.x);
      if (i == 0) {
        lastTop = rc.y;
      } else if (lastTop != rc.y) {
        lastTop = Integer.MIN_VALUE;
      }
    }

    Graphics2D g2d = (Graphics2D) g;
    Stroke oldStroke = g2d.getStroke();
    g2d.setStroke(new BasicStroke(2.0f));
    g2d.setColor(new Color(104, 107, 130));
    if (lastTop != Integer.MIN_VALUE) {
      // all items in group have same Y
      int left = Integer.MAX_VALUE;
      int right = Integer.MIN_VALUE;
      for (Rectangle rc : allBounds) {
        final int midX = (int) rc.getCenterX();
        left = Math.min(left, midX);
        right = Math.max(right, midX);
        g2d.drawLine(midX, lastTop - 8, midX, lastTop);
      }
      g2d.drawLine(left, lastTop - 8, right, lastTop - 8);
    } else {
      int top = Integer.MAX_VALUE;
      int bottom = Integer.MIN_VALUE;
      for (Rectangle rc : allBounds) {
        final int midY = (int) rc.getCenterY();
        top = Math.min(top, midY);
        bottom = Math.max(bottom, midY);
        g2d.drawLine(minLeft - 8, midY, rc.x, midY);
      }
      g2d.drawLine(minLeft - 8, top, minLeft - 8, bottom);
    }
    g2d.setStroke(oldStroke);
  }