Example #1
0
    private void paintToImage(
        final BufferedImage img, final int x, final int y, final int width, final int height) {
      // clear the prior image
      Graphics2D imgG = (Graphics2D) img.getGraphics();
      imgG.setComposite(AlphaComposite.Clear);
      imgG.setColor(Color.black);
      imgG.fillRect(0, 0, width + blur * 2, height + blur * 2);

      final int adjX = (int) (x + blur + offsetX + (insets.left * distance));
      final int adjY = (int) (y + blur + offsetY + (insets.top * distance));
      final int adjW = (int) (width - (insets.left + insets.right) * distance);
      final int adjH = (int) (height - (insets.top + insets.bottom) * distance);

      // let the delegate paint whatever they want to be blurred
      imgG.setComposite(AlphaComposite.DstAtop);
      if (prePainter != null) prePainter.paint(imgG, adjX, adjY, adjW, adjH);
      imgG.dispose();

      // blur the prior image back into the same pixels
      imgG = (Graphics2D) img.getGraphics();
      imgG.setComposite(AlphaComposite.DstAtop);
      imgG.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
      imgG.setRenderingHint(
          RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
      imgG.drawImage(img, blurOp, 0, 0);

      if (postPainter != null) postPainter.paint(imgG, adjX, adjY, adjW, adjH);
      imgG.dispose();
    }
Example #2
0
 @Override
 protected void paintComponent(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   if (image == null) {
     painter.paintPanel(this, g2);
   } else {
     painter.paintImage(this, image, g2);
   }
 }
  @Override
  protected void paintComponent(Graphics g) {

    super.paintComponent(g);

    if (image == null) {
      painter.paintPanel(this, (Graphics2D) g);
    } else {
      painter.paintImage(this, image, (Graphics2D) g);
    }
  }
  @Test
  public void test() throws Exception {
    final Orange orange = new Orange();
    beanManager.fireEvent(orange);

    final Green green = new Green();
    beanManager.fireEvent(green);

    Assert.assertEquals(2, painter.getObserved().size());
    Assert.assertSame(orange, painter.getObserved().get(0));
    Assert.assertSame(green, painter.getObserved().get(1));
  }
Example #5
0
 @Override
 public void onFinish() {
   log.info("Runtime: " + Timer.format(painter.getRunTime()));
   log.info(
       "Money made: "
           + (moneyHandler.getTotalMoneyMade() / 1000)
           + "."
           + (moneyHandler.getTotalMoneyMade() % 1000)
           + "k");
   log.info("XP gained: " + painter.xPGained());
   log.info("XP/hr: " + painter.xPPerHour());
 }
Example #6
0
  /** {@inheritDoc} */
  @Override
  protected void doPaint(Graphics2D g, T component, int width, int height) {
    for (Painter<T> p : getPainters()) {
      Graphics2D temp = (Graphics2D) g.create();

      try {
        p.paint(temp, component, width, height);
        if (isClipPreserved()) {
          g.setClip(temp.getClip());
        }
      } finally {
        temp.dispose();
      }
    }
  }
  /** Override the paint method to do custom painting. */
  public synchronized void paint(Graphics g) {

    // Draw the background
    if (image != null) {
      int x = (getWidth() - image.getWidth()) / 2;
      int y = (getHeight() - image.getHeight()) / 2;
      g.drawImage(image, x, y, this);
    }

    // Paint any other painters
    for (Painter p : painters) {
      // System.out.println(p);
      p.paint(g);
    }
  }
  @Override
  public void paint(Graphics g) {
    float width = getWidth();
    float height = getHeight();

    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setColor(Color.black);
    g2.fill(new Rectangle2D.Float(0, 0, width, height));

    g2.setFont(getFont().deriveFont(FONT_SIZE));
    g2.setColor(Color.green);
    FontMetrics fm = g2.getFontMetrics();
    g2.drawString("Input", width / 4f - fm.stringWidth("Input") / 2f, 30);
    g2.setColor(Color.red);
    g2.drawString("Output", width - width / 4f - fm.stringWidth("Output") / 2f, 30);

    g2.setFont(getFont().deriveFont(FONT_SIZE / 2));
    fm = g2.getFontMetrics();
    g2.setColor(new Color(0, 255, 0));
    g2.drawString("response", width / 4f - fm.stringWidth("response") / 2f, 48);
    g2.setColor(new Color(0, 255, 255));
    g2.drawString("request", width / 4f - fm.stringWidth("request") / 2f, 60);

    g2.setColor(new Color(255, 0, 0));
    g2.drawString("request", width - width / 4f - fm.stringWidth("request") / 2f, 48);
    g2.setColor(new Color(255, 0, 255));
    g2.drawString("response", width - width / 4f - fm.stringWidth("response") / 2f, 60);

    synchronized (lock) {
      painter.paint(this, g2);
    }
  }
Example #9
0
  private void drawYGrid(GC gc, double lineStart, double lineStep) {
    Color color_light_blue = new Color(display, 220, 220, 255);

    // double line = minValue;
    double line = lineStart;

    while (line <= maxValue) {
      int y = valueToGraph(line);
      gc.setForeground(color_light_blue);
      gc.drawLine(xStart, y, xEnd, y);
      gc.setForeground(color_black);

      String valueText;
      if (lineStep >= 1d) {
        valueText = Util.doubleToString0(line);
      } else if (lineStep >= 0.1d) {
        valueText = Util.doubleToString1(line);
      } else if (lineStep >= 0.01d) {
        valueText = Util.doubleToString2(line);
      } else {
        valueText = Util.doubleToStringFull(line);
      }

      Painter.drawText(valueText, gc, xStart, y, PosHorizontal.RIGHT, PosVerical.CENTER);
      line += lineStep;
    }
  }
Example #10
0
 @Test
 public void mapCellPositionToBufferPosition() throws TicTacToeInputException {
   board.add(Cell.TOP_LEFT.setPlayer(board.getCurrentPlayer()));
   board.add(Cell.MIDDLE_CENTER.setPlayer(board.getCurrentPlayer()));
   board.add(Cell.BOTTOM_RIGHT.setPlayer(board.getCurrentPlayer()));
   assertThat(
       cut.drow(board),
       allOf(containsString("|X| | |"), containsString("| |X| |"), containsString("| | |X|")));
 }
Example #11
0
 @Override
 public int loop() {
   for (Strategy currentStrategy : strategies) {
     if (currentStrategy.isValid()) {
       painter.setTotalMoneyMade(moneyHandler.getTotalMoneyMade());
       currentStrategy.execute();
     }
   }
   return Random.nextInt(300, 600);
 }
    /*
     * Completely erases the current state of the Simulation
     */
    public void reset() {
      e.purgeAgents();
      paint.clearHistory();
      children.clear();
      fillWithAgents();

      Agent a = new Agent();
      a.setName("My Agent");
      a.setChrome("000 000 000 000 000 000 000 011 011 011 011 011 100 101 101 101");
      children.add(a);

      cur_gen = 0;
      current_elite = null;
      prev_elite_total = 0;
      running = true;
    }
Example #13
0
 @Override
 public void paint(Graphics g, JComponent c) {
   Gripper gripper = (Gripper) c;
   paintBackground(g, gripper);
   int state = gripper.isSelected() ? ThemePainter.STATE_SELECTED : ThemePainter.STATE_DEFAULT;
   if (_gripperPainter == null) {
     getPainter()
         .paintGripper(
             c,
             g,
             new Rectangle(0, 0, c.getWidth(), c.getHeight()),
             gripper.getOrientation(),
             state);
   } else {
     _gripperPainter.paint(
         c, g, new Rectangle(0, 0, c.getWidth(), c.getHeight()), gripper.getOrientation(), state);
   }
 }
    public ProcessSimulator(
        ArrayList<Agent> agents, int generations, int id, Environment e, ActionListener l) {

      // store parameters as instance variables
      this.e = e;
      this.id = id;
      this.listener = l;
      this.generations = generations;
      children = agents;

      // setup all other data
      total_agents = agents.size();
      cur_gen = 0;
      day_count = 100;
      elite_percent = .05;
      parent_percent = .8;
      current_elite = null;
      prev_elite_total = 0;

      // Create a Tabbed panel for the different graphs
      JTabbedPane graphs = new JTabbedPane();
      graphs.addTab(
          "Species Average",
          null,
          paint,
          "Graphical " + "Representation of All Species' Average Performance");
      graphs.addTab(
          "Elite Performance", null, ep, "A 100-day Graph of the Elite Agent's Business Model");
      window.getContentPane().add(graphs);

      // give our paint class a copy of the Generational History
      paint.setHistory(history);

      // construct our window
      // TODO: consolidate each thread's results into a single window for
      // TODO: ease of human comparison
      window.setTitle("Optimal Division of Tasks in a Business");
      window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      // window.getContentPane().add(paint);
      running = true;
      window.pack();
      window.setVisible(true);
    }
  /*
   * (non-Javadoc)
   * @see org.limewire.mojito.io.MessageDispatcher.MessageDispatcherListener#handleMessageDispatcherEvent(org.limewire.mojito.io.MessageDispatcher.MessageDispatcherEvent)
   */
  public void handleMessageDispatcherEvent(MessageDispatcherEvent evt) {
    EventType type = evt.getEventType();
    KUID nodeId = null;
    SocketAddress addr = null;

    if (type.equals(EventType.MESSAGE_RECEIVED)) {
      nodeId = evt.getMessage().getContact().getNodeID();
      addr = evt.getMessage().getContact().getContactAddress();
    } else if (type.equals(EventType.MESSAGE_SENT)) {
      nodeId = evt.getNodeID();
      addr = evt.getSocketAddress();
    } else {
      return;
    }

    OpCode opcode = evt.getMessage().getOpCode();
    boolean request = (evt.getMessage() instanceof RequestMessage);
    synchronized (lock) {
      painter.handle(type, nodeId, addr, opcode, request);
    }
  }
Example #16
0
  public void paintCanvas(GC gc, Point point) {
    if (timeSeries != null) {

      Font old = gc.getFont();
      FontData fd = old.getFontData()[0];
      fd.setHeight(20);
      gc.setFont(new Font(display, fd));
      gc.setForeground(new Color(display, 200, 200, 200));
      Painter.drawText(title, gc, 50, 20, PosHorizontal.LEFT, PosVerical.TOP);
      gc.setFont(old);

      if (point != null) {
        updateRangeOfOutputWindow(point.x, point.y);
      }

      updateDataWindowConversionValues();

      Color color_bluegreen = new Color(display, 190, 240, 190);
      int avg = valueToGraph(dataSum / dataCount);
      gc.setForeground(color_bluegreen);
      gc.drawLine(xStart, avg, xEnd, avg);

      drawGrid(gc);

      drawXYAxis(gc);

      if (compare_timeSeries != null) {

        Color color_red = new Color(display, 240, 0, 0);
        Color color_redgrey = new Color(display, 240, 190, 190);

        drawTimeSeries(gc, compare_timeSeries, color_red, color_redgrey);
      }

      drawTimeSeries(gc, timeSeries, color_black, color_grey);
    }
  }
Example #17
0
 protected void paintChild(Graphics2D g2, Component child) {
   Painter painter = PainterFactory.getPainter(child.getClass());
   painter.paint(g2, child);
 }
Example #18
0
 public void mouseClicked(MouseEvent e) {
   painter.mouseClicked(e);
 }
Example #19
0
 public void onRepaint(Graphics graphics) {
   painter.onRepaint(graphics);
 }
Example #20
0
  /**
   * This method will only throw exceptions if some aspect of the test's internal operation fails.
   */
  public TestReport runImpl() throws Exception {
    DefaultTestReport report = new DefaultTestReport(this);

    SVGGraphics2D g2d = buildSVGGraphics2D();
    g2d.setSVGCanvasSize(CANVAS_SIZE);

    //
    // Generate SVG content
    //
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    OutputStreamWriter osw = new OutputStreamWriter(bos, "UTF-8");
    try {
      painter.paint(g2d);
      configureSVGGraphics2D(g2d);
      g2d.stream(osw);
      osw.flush();
      bos.flush();
      bos.close();
    } catch (Exception e) {
      StringWriter trace = new StringWriter();
      e.printStackTrace(new PrintWriter(trace));
      report.setErrorCode(ERROR_CANNOT_GENERATE_SVG);
      report.setDescription(
          new TestReport.Entry[] {
            new TestReport.Entry(
                Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                Messages.formatMessage(
                    ERROR_CANNOT_GENERATE_SVG,
                    new String[] {
                      painter == null ? "null" : painter.getClass().getName(),
                      e.getClass().getName(),
                      e.getMessage(),
                      trace.toString()
                    }))
          });
      report.setPassed(false);
      return report;
    }

    //
    // Compare with reference SVG
    //
    InputStream refStream = null;
    try {
      refStream = new BufferedInputStream(refURL.openStream());
    } catch (Exception e) {
      report.setErrorCode(ERROR_CANNOT_OPEN_REFERENCE_SVG_FILE);
      report.setDescription(
          new TestReport.Entry[] {
            new TestReport.Entry(
                Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                Messages.formatMessage(
                    ERROR_CANNOT_OPEN_REFERENCE_SVG_FILE,
                    new Object[] {
                      refURL != null ? refURL.toExternalForm() : "null", e.getMessage()
                    }))
          });
      report.setPassed(false);
      save(bos.toByteArray());
      return report;
    }

    InputStream newStream = new ByteArrayInputStream(bos.toByteArray());

    boolean accurate = true;
    String refLine = null;
    String newLine = null;
    int ln = 1;

    try {
      // accurate = compare(refStream, newStream);
      BufferedReader refReader = new BufferedReader(new InputStreamReader(refStream));
      BufferedReader newReader = new BufferedReader(new InputStreamReader(newStream));
      while ((refLine = refReader.readLine()) != null) {
        newLine = newReader.readLine();
        if (newLine == null || !refLine.equals(newLine)) {
          accurate = false;
          break;
        }
        ln++;
      }

      if (accurate) {
        // need to make sure newLine is null as well
        newLine = newReader.readLine();
        if (newLine != null) {
          accurate = false;
        }
      }

    } catch (IOException e) {
      report.setErrorCode(ERROR_ERROR_WHILE_COMPARING_FILES);
      report.setDescription(
          new TestReport.Entry[] {
            new TestReport.Entry(
                Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                Messages.formatMessage(
                    ERROR_ERROR_WHILE_COMPARING_FILES,
                    new Object[] {refURL.toExternalForm(), e.getMessage()}))
          });
      report.setPassed(false);
      save(bos.toByteArray());
      return report;
    }

    if (!accurate) {
      save(bos.toByteArray());
      int cn = computeColumnNumber(refLine, newLine);
      String expectedChar = "eol";
      if (cn >= 0 && refLine != null && refLine.length() > cn) {
        expectedChar = (new Character(refLine.charAt(cn))).toString();
      }
      String foundChar = "null";
      if (cn >= 0 && newLine != null && newLine.length() > cn) {
        foundChar = (new Character(newLine.charAt(cn))).toString();
      }

      if (expectedChar.equals(" ")) {
        expectedChar = "' '";
      }
      if (foundChar.equals(" ")) {
        foundChar = "' '";
      }

      report.setErrorCode(ERROR_GENERATED_SVG_INACCURATE);
      report.addDescriptionEntry(
          Messages.formatMessage(ENTRY_KEY_LINE_NUMBER, null), new Integer(ln));
      report.addDescriptionEntry(
          Messages.formatMessage(ENTRY_KEY_COLUMN_NUMBER, null), new Integer(cn));
      report.addDescriptionEntry(
          Messages.formatMessage(ENTRY_KEY_COLUMN_EXPECTED_VALUE, null), expectedChar);
      report.addDescriptionEntry(
          Messages.formatMessage(ENTRY_KEY_COLUMN_FOUND_VALUE, null), foundChar);
      report.addDescriptionEntry(Messages.formatMessage(ENTRY_KEY_REFERENCE_LINE, null), refLine);
      report.addDescriptionEntry(Messages.formatMessage(ENTRY_KEY_NEW_LINE, null), newLine);
      report.setPassed(false);
    } else {
      report.setPassed(true);
    }

    return report;
  }
  /**
   * Fills the Canvas in the Painter with circles in a grid
   *
   * @param painter Paint the generated shape in this object
   * @param contact Data from this Contact object will be used to generate the shapes and colors
   */
  public static void generate(Painter painter, Contact contact) {
    if (painter == null || contact == null) return;

    // Prepare painting values based on image size and contact data.
    final String md5String = contact.getMD5EncryptedString();

    // Use the length of the first name to determine the number of shapes per row and column.
    final int firstNameLength = contact.getNameWord(0).length();
    //        int shapesPerRow = (md5String.charAt(20) % 2 == 0) ? firstNameLength : firstNameLength
    // / 2;
    //        if (shapesPerRow < 3) shapesPerRow = contact.getNumberOfLetters();
    //        if (shapesPerRow < 3) shapesPerRow += 2;

    final int shapesPerRow;
    if (firstNameLength < 3) {
      shapesPerRow = 3;
    } else if (firstNameLength > 8) {
      shapesPerRow = 8;
    } else {
      shapesPerRow = firstNameLength;
    }

    final int imageSize = painter.getImageSize();
    final float strokeWidth = md5String.charAt(12) * 3f;
    float circleDistance;
    //        circleDistance = (imageSize / shapesPerRow) + (imageSize / (shapesPerRow * 2f));
    circleDistance = (imageSize / shapesPerRow);

    int md5Pos = 0;
    int index;
    float radius;
    int color;
    char md5Char;
    for (int y = 0; y < shapesPerRow; y++) {
      for (int x = 0; x < shapesPerRow; x++) {

        md5Pos++;
        if (md5Pos >= md5String.length()) md5Pos = 0;
        md5Char = md5String.charAt(md5Pos);

        //                final int color = ColorCollection.getColor(md5Char);
        color = ColorCollection.generateColor(md5Char, firstNameLength, shapesPerRow);

        index = y * shapesPerRow + x;
        if ((index & 1) == 0) radius = md5Char * 6f;
        else radius = md5Char * 5f;

        painter.paintShape(
            Painter.MODE_CIRCLE_FILLED,
            color,
            //                        255,
            255 - md5String.charAt(md5Pos),
            0,
            0,
            x * circleDistance,
            y * circleDistance,
            radius);
        circleDistance *= 1.1f;
      }
    }
  }