Пример #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();
    }
 /** Paint the component using the Nimbus Table Header Background Painter */
 @Override
 protected void paintComponent(Graphics g) {
   Painter painter =
       (Painter) UIManager.get("TableHeader:\"TableHeader.renderer\"[Enabled].backgroundPainter");
   if (painter != null) {
     if (g instanceof Graphics2D) {
       painter.paint((Graphics2D) g, this, getWidth() + 1, getHeight());
     } else {
       // paint using image to not Graphics2D to support
       // Java 1.1 printing API
       BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
       Graphics2D g2 = (Graphics2D) img.getGraphics();
       painter.paint(g2, this, getWidth() + 1, getHeight());
       g2.dispose();
       g.drawImage(img, 0, 0, null);
       img = null;
     }
   }
 }
    /*
     * 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;
    }
Пример #4
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);
    }