public void paint(Graphics g) {
    worldMap.getGraphics().drawImage(backBufferImage, 0, 0, this);
    // hideous hack
    statusTitle.repaint();
    fileTitle.repaint();
    fileProgress.repaint();
    iterationTitle.repaint();
    iterationProgress.repaint();
    cycleTitle.repaint();
    cycleProgress.repaint();

    currentTitle.repaint();
    commentTitle.repaint();
    commentLabel.repaint();
    phaseTitle.repaint();
    phaseLabel.repaint();
    turnTitle.repaint();
    turnProgress.repaint();

    inspectorTitle.repaint();
    showPaths.repaint();
    playButton.repaint();
    stepButton.repaint();
    endButton.repaint();
    inspectorScrollPane.repaint();
    seperator1.repaint();
    seperator2.repaint();
    seperator3.repaint();
    seperator4.repaint();
    cycleProgress.repaint();
  }
  private void initialise() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    backBuffer = worldMap.getGraphics();

    // Make the image buffer as large as could possibly be used (screensize)
    if (backBufferImage == null) {
      logger.debug(
          "Creating backBufferImage of dimensions "
              + toolkit.getScreenSize().width
              + ","
              + toolkit.getScreenSize().height
              + ".");
      backBufferImage = createImage(toolkit.getScreenSize().width, toolkit.getScreenSize().height);
      backBuffer = backBufferImage.getGraphics();
    } else {
      backBufferImage.flush();
      backBufferImage = createImage(toolkit.getScreenSize().width, toolkit.getScreenSize().height);
      backBuffer.dispose();
      backBuffer = backBufferImage.getGraphics();
    }

    setupWindow(worldMap.getWidth(), worldMap.getHeight());

    initialise = false;

    logger.debug(
        "initialised backBufferImage with size "
            + worldMap.getWidth()
            + ","
            + worldMap.getHeight()
            + ".");
  }
    private void paintFocusBorders(boolean clean) {
      if (myCurrent != null) {
        Graphics currentFocusGraphics = myCurrent.getGraphics();
        if (currentFocusGraphics != null) {
          if (clean) {
            if (myCurrent.isDisplayable()) {
              myCurrent.repaint();
            }
          } else {
            currentFocusGraphics.setColor(myTemporary ? JBColor.ORANGE : JBColor.GREEN);
            UIUtil.drawDottedRectangle(
                currentFocusGraphics,
                1,
                1,
                myCurrent.getSize().width - 2,
                myCurrent.getSize().height - 2);
          }
        }
      }

      if (myPrevious != null) {
        Graphics previousFocusGraphics = myPrevious.getGraphics();
        if (previousFocusGraphics != null) {
          if (clean) {
            if (myPrevious.isDisplayable()) {
              myPrevious.repaint();
            }
          } else {
            previousFocusGraphics.setColor(JBColor.RED);
            UIUtil.drawDottedRectangle(
                previousFocusGraphics,
                1,
                1,
                myPrevious.getSize().width - 2,
                myPrevious.getSize().height - 2);
          }
        }
      }
    }
 private void paintBorder() {
   final int row = FocusTracesDialog.this.myRequestsTable.getSelectedRow();
   if (row != -1) {
     final FocusRequestInfo info = FocusTracesDialog.this.myRequests.get(row);
     if (prev != null && prev != info.getComponent()) {
       prev.repaint();
     }
     prev = info.getComponent();
     if (prev != null && prev.isDisplayable()) {
       final Graphics g = prev.getGraphics();
       g.setColor(Color.RED);
       final Dimension sz = prev.getSize();
       UIUtil.drawDottedRectangle(g, 1, 1, sz.width - 2, sz.height - 2);
     }
   }
 }
Esempio n. 5
0
  /** Processes the data and renders it to a component */
  public synchronized int process(Buffer buffer) {
    if (component == null) return BUFFER_PROCESSED_FAILED;

    Format inf = buffer.getFormat();
    if (inf == null) return BUFFER_PROCESSED_FAILED;

    if (inf != inputFormat || !buffer.getFormat().equals(inputFormat)) {
      if (setInputFormat(inf) != null) return BUFFER_PROCESSED_FAILED;
    }

    Object data = buffer.getData();
    if (!(data instanceof int[])) return BUFFER_PROCESSED_FAILED;

    if (lastBuffer != buffer) {
      lastBuffer = buffer;
      newImage(buffer);
    }

    sourceImage.newPixels(0, 0, inWidth, inHeight);

    Graphics g = component.getGraphics();
    if (g != null) {
      if (reqBounds == null) {
        bounds = component.getBounds();
        bounds.x = 0;
        bounds.y = 0;
      } else bounds = reqBounds;
      g.drawImage(
          destImage,
          bounds.x,
          bounds.y,
          bounds.width,
          bounds.height,
          0,
          0,
          inWidth,
          inHeight,
          component);
    }

    return BUFFER_PROCESSED_OK;
  }
Esempio n. 6
0
 public void handleEvent(AWTEvent e) {
   // This can only happen when an application posts a PaintEvent for
   // a lightweight component directly. We still support painting for
   // this case.
   if (e instanceof PaintEvent) {
     PaintEvent pe = (PaintEvent) e;
     Component target = (Component) e.getSource();
     if (target != null && target.isShowing()) {
       Graphics g = target.getGraphics();
       if (g != null) {
         try {
           Rectangle clip = pe.getUpdateRect();
           g.setClip(clip);
           target.paint(g);
         } finally {
           g.dispose();
         }
       }
     }
   }
 }
  public synchronized void execute() {
    long start = System.currentTimeMillis(); // For calculating render time

    fileProgress.setStringPainted(true);
    fileProgress.setMinimum(0);
    fileProgress.setMaximum(((CTWorld) Simulator.pworld).getNumConfigs());
    fileProgress.setValue(((CTWorld) Simulator.pworld).getConfigNum());
    fileProgress.setString(
        ((CTWorld) Simulator.pworld).getConfigNum()
            + "/"
            + ((CTWorld) Simulator.pworld).getNumConfigs());

    iterationProgress.setStringPainted(true);
    iterationProgress.setMinimum(0);
    iterationProgress.setMaximum(((CTWorld) Simulator.pworld).getNumIterations());
    iterationProgress.setValue(((CTWorld) Simulator.pworld).getIterationNum());
    iterationProgress.setString(
        ((CTWorld) Simulator.pworld).getIterationNum()
            + "/"
            + ((CTWorld) Simulator.pworld).getNumIterations());

    cycleProgress.setStringPainted(true);
    cycleProgress.setMinimum(0);
    cycleProgress.setMaximum(Simulator.experimentLength);
    cycleProgress.setValue(Simulator.cycle);
    cycleProgress.setString(Simulator.cycle + "/" + Simulator.experimentLength);

    commentLabel.setText(((CTWorld) Simulator.pworld).getComment());

    phaseLabel.setText(getPhase());

    turnProgress.setStringPainted(true);
    turnProgress.setMinimum(0);
    turnProgress.setMaximum(((CTWorld) Simulator.pworld).getTimeout());
    turnProgress.setValue(((CTWorld) Simulator.pworld).getTurn());
    turnProgress.setString(
        ((CTWorld) Simulator.pworld).getTurn() + "/" + ((CTWorld) Simulator.pworld).getTimeout());

    if (initialise) initialise();

    // Draw the viewer components in background-foreground order
    // updating certain elements for different phases

    if (((CTWorld) Simulator.pworld).getCurrentPhase().equals(CTWorld.REG_PHASE)) {
      // Registration phase
      showSpinner();
    } else if (((CTWorld) Simulator.pworld).getCurrentPhase().equals(CTWorld.INIT_PHASE)) {

      if (Simulator.controlPanel.paused) {
        playButton.setText("Play");
      } else {
        playButton.setText("Pause");
      }

      updateInspectorTree();

      // Initiation phase
      getAgentIcons();
      updateImageBuffer();
      addAgentPaths();
      clearBuffer();
      drawHexagons();
      drawGoals();
      drawAgents();

    } else if (((CTWorld) Simulator.pworld).getCurrentPhase().equals(CTWorld.COMM_PHASE)) {
      // Communication phase
      if (resize) {
        // If a resize event has happened, we need to re-render
        resize = false;
        updateImageBuffer();
        clearBuffer();
        drawHexagons();
        drawPaths();
        drawGoals();
        drawAgents();
      }

    } else if (((CTWorld) Simulator.pworld).getCurrentPhase().equals(CTWorld.MOVE_PHASE)) {
      // Moving phase
      addAgentPaths();
      clearBuffer();
      drawHexagons();
      drawPaths();
      drawGoals();
      drawAgents();

    } else if (((CTWorld) Simulator.pworld).getCurrentPhase().equals(CTWorld.RESET_PHASE)) {
      agentPaths = new HashMap<String, ArrayList<Coord>>();
      initialise = true;
    } else {
      logger.debug("Perhaps I could use this unknown phase for something...");
    }

    // backBuffer ready for display
    worldMap.getGraphics().drawImage(backBufferImage, 0, 0, this);

    long finish = System.currentTimeMillis(); // For calculating render time
    String renderSpeed = dp.format(1000.0 / (finish - start));

    // TODO claim james wrote something that "renders" at 3k fps or more?
    if (finish == start) {
      logger.trace("Rendering speed: <1ms.");
    } else {
      logger.trace("Rendering speed: " + renderSpeed + "fps.");
    }
  }
Esempio n. 8
0
 /**
  * Fetch a <code>Graphics</code> for rendering. This can be used to determine font
  * characteristics, and will be different for a print view than a component view.
  *
  * @return a <code>Graphics</code> object for rendering
  * @since 1.3
  */
 public Graphics getGraphics() {
   // PENDING(prinz) this is a temporary implementation
   Component c = getContainer();
   return c.getGraphics();
 }
Esempio n. 9
0
 /**
  * Return bounds to draw specified string in the specified component.<br>
  * This function handle multi lines string ('\n' character used a line separator).
  */
 public static Rectangle2D getStringBounds(Component c, String text) {
   return getStringBounds(c.getGraphics(), text);
 }