Example #1
0
  // draws the button, based on the type of button (ImageIcon, Image, or String)
  public void draw(Graphics g) {
    if (visible) {
      // if its image/imageicon, draw it
      g.setColor(new Color(50, 200, 50));
      g.fillRect(x - 1, y - 1, width + 2, height + 2);
      if (mode.equals("Image") || mode.equals("ImageIcon")) {
        if (enabled) {
          g.drawImage(image, x, y, null);
        } else {
          g.drawImage(BWimage, x, y, null);
        }
        // if its string, draw the string
      } else {

        g.setFont(new Font("Arial", Font.PLAIN, 20));
        if (enabled) {
          g.setColor(Color.black);
          g.drawString(message, x + 20, y + 20);
        } else {
          g.setColor(new Color(255, 255, 255));
          g.fillRect(x - 1, y - 1, width + 2, height + 2);
          g.setColor(Color.black);
          g.drawString(message, x + 20, y + 20);
        }
      }
    }
  }
Example #2
0
  /** Overrides <code>Graphics.drawString</code>. */
  public void drawString(AttributedCharacterIterator iterator, int x, int y) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info().log(toShortString() + " Drawing text: \"" + iterator + "\" at: " + new Point(x, y));
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawString(iterator, x, y);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.drawString(iterator, x, y);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawString(iterator, x, y);
  }
Example #3
0
 /**
  * Paint method for applet.
  *
  * @param g the Graphics object for this applet
  */
 public void paint(Graphics g) {
   // simple text displayed on applet
   g.setColor(c);
   g.fillRect(0, 0, 200, 100);
   g.setColor(Color.black);
   g.drawString("Sample Applet", 20, 20);
   g.setColor(Color.blue);
   g.drawString("created by BlueJ", 20, 40);
 }
Example #4
0
 private void reportStats(Graphics g)
       // Report the number of hits, and time spent playing
     {
   if (!gameOver) // stop incrementing the timer once the game is over
   timeSpentInGame = (int) ((System.nanoTime() - gameStartTime) / 1000000000L); // ns --> secs
   g.setColor(Color.red);
   g.setFont(msgsFont);
   g.drawString("Hits: " + numHits + "/" + MAX_HITS, 15, 25);
   g.drawString("Time: " + timeSpentInGame + " secs", 15, 50);
   g.setColor(Color.black);
 } // end of reportStats()
Example #5
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    height = this.getHeight();
    width = this.getWidth();

    drawPlayers(g);
    g.setColor(Color.WHITE);
    g.drawString("Score", width - 60, 25);
    g.drawString(String.valueOf(score), width - 60, 40);

    if (countdownF) {
      g.drawString(String.valueOf(counterN), width / 2 - 10, height / 2);
    } else {
      if ((spawnCircleB) && (spawnIncrease)) {
        spawnCircles();
      }
      if (spawnMonsterB) {
        spawnMonsters();
      }
      if (spawnRandomersB) {
        spawnRandomers();
      }
      if (spawnRainB) {
        spawnRain();
      }
      if (spawnBombB()) {
        spawnBomb();
      }

      try {
        Iterator i = enemies.iterator();
        while (i.hasNext()) {
          Enemy e = (Enemy) i.next();
          Iterator j = players.iterator();
          while (j.hasNext()) {
            Player p = (Player) j.next();
            e.move(players, programSpeedAdjust /*/players.size()*/);
            if ((e.collidesWith(p.getX(), p.getY())) && (!p.getImmunity())) {
              p.decLives(p.getX(), p.getY());
              p.setImmunity(true);
            }
          }
          e.paint(g);
        }
      } catch (Exception e) {
      }
    }
    drawLayout(g);
  }
Example #6
0
  public void paintFPS(int x, int y, Graphics g) {

    // Skip if not needed:
    if (usingMenu) {
      return;
    }

    if (showFPS) {

      // Update FPS count:
      if (--fpsCounter <= 0) {

        long ct = nes.getGui().getTimer().currentMicros();
        long frameT = (ct - prevFrameTime) / 45;
        if (frameT == 0) {
          fps = "FPS: -";
        } else {
          fps = "FPS: " + (1000000 / frameT);
        }
        fpsCounter = 45;
        prevFrameTime = ct;
      }

      // Draw FPS.
      gfx.setColor(Color.black);
      gfx.fillRect(
          x,
          y - gfx.getFontMetrics().getAscent(),
          gfx.getFontMetrics().stringWidth(fps) + 3,
          gfx.getFontMetrics().getHeight());
      gfx.setColor(Color.cyan);
      gfx.drawString(fps, x, y);
    }
  }
 // Show a message over frozen image in the display
 public void showMessage(String message) {
   Graphics g = getGraphics();
   g.setColor(Color.black);
   g.fillRect(30, (getHeight() / 2) - 16, message.length() * 10, 25);
   g.setColor(Color.white);
   g.drawString(message, 40, getHeight() / 2);
 }
Example #8
0
  /** Affichage du logo */
  protected void drawLogo(Graphics g) {

    int x = 5;
    int y = 2;

    g.setColor(getBackground());
    g.fillRect(0, 0, W, H);

    // Remplissage
    fillBG(g, x, y, Color.white);

    // Dessin
    drawGrid(
        g,
        x,
        y,
        !isAvailable()
            ? Aladin.MYGRAY
            : isActive() ? Aladin.GREEN : isMouseIn() ? Color.blue : Color.black);

    // Label
    g.setColor(isAvailable() ? Color.black : Aladin.MYGRAY);
    g.setFont(Aladin.SPLAIN);
    g.drawString(LABEL, W / 2 - g.getFontMetrics().stringWidth(LABEL) / 2, H - 2);
  }
 void drawRoiLabel(Graphics g, int index, Roi roi) {
   Rectangle r = roi.getBounds();
   int x = screenX(r.x);
   int y = screenY(r.y);
   double mag = getMagnification();
   int width = (int) (r.width * mag);
   int height = (int) (r.height * mag);
   int size = width > 40 && height > 40 ? 12 : 9;
   if (font != null) {
     g.setFont(font);
     size = font.getSize();
   } else if (size == 12) g.setFont(largeFont);
   else g.setFont(smallFont);
   boolean drawingList = index >= LIST_OFFSET;
   if (drawingList) index -= LIST_OFFSET;
   String label = "" + (index + 1);
   if (drawNames && roi.getName() != null) label = roi.getName();
   FontMetrics metrics = g.getFontMetrics();
   int w = metrics.stringWidth(label);
   x = x + width / 2 - w / 2;
   y = y + height / 2 + Math.max(size / 2, 6);
   int h = metrics.getAscent() + metrics.getDescent();
   if (bgColor != null) {
     g.setColor(bgColor);
     g.fillRoundRect(x - 1, y - h + 2, w + 1, h - 3, 5, 5);
   }
   if (!drawingList && labelRects != null && index < labelRects.length)
     labelRects[index] = new Rectangle(x - 1, y - h + 2, w + 1, h);
   g.setColor(labelColor);
   g.drawString(label, x, y - 2);
   g.setColor(defaultColor);
 }
Example #10
0
 public void paint(Graphics g) {
   String s = "Applet is open in a separate window.";
   if (!started) s = "Applet is starting.";
   else if (ogf == null) s = "Applet is finished.";
   else if (ogf.useFrame) ogf.triggerShow();
   g.drawString(s, 10, 30);
 }
Example #11
0
 void drawLabel(Graphics g, DrawObject L) {
   if ((sequencingOn) && (L.sequenceNum != currentSequenceNumDisplay)) {
     return;
   }
   int x = (int) ((L.x - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y = (int) ((L.y - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   g.drawString(L.str, inset + x, D.height - y - inset);
 }
Example #12
0
File: set.java Project: wcyuan/Set
  public void Message(String s1, String s2, int i) {
    Graphics g = getGraphics();

    if (s1 == null || s2 == null) {
      g.setColor(bgcolor);
      g.drawRect(400, 50 * i - 10, 200, 20);
      g.fillRect(400, 50 * i - 10, 200, 20);
      return;
    }
    /*
      g.setColor(Color.blue);
      g.drawRect(400,50 * i - 10,200,20);
      g.fillRect(400,50 * i - 10,200,20);
    */
    g.setColor(txtcolor);
    g.drawString(s1, 400, 50 * i);
    g.drawString(s2, 400, 50 * i + 10);
  }
Example #13
0
 public void paint(Graphics g) 
 {    	  
     if (iImage != null)
     {
     	g.clearRect(0, 0, 260, 350);        	
         g.drawImage(iImage, 5, 50, null);
         g.drawString("pic1", 120, 320);
     }
           
 }
 /**
  * Draw a string at a given point.
  *
  * <p>The method returns the point where the next string should be drawn to seamlessly continue
  * the current string.
  *
  * @param s the string
  * @param point the position where to draw the string
  * @param fontname the font's name, should preferably be a logical name
  * @param fontsize the font size
  * @param color the color
  * @return the point where outputting string text should continue
  */
 public Point drawString(String s, Point point, String fontname, int fontsize, Color color) {
   Graphics g = this.image.getGraphics();
   g.setColor(color);
   g.setFont(new Font(fontname, Font.PLAIN, fontsize));
   g.drawString(s, point.x, point.y);
   FontMetrics f = g.getFontMetrics();
   Point newPoint = new Point(point);
   newPoint.x += f.stringWidth(s);
   this.repaint();
   return (newPoint);
 }
Example #15
0
  private void gameOverMessage(Graphics g)
        // Center the game-over message in the panel.
      {
    String msg = "Game Over. Your score: " + score;

    int x = (PWIDTH - metrics.stringWidth(msg)) / 2;
    int y = (PHEIGHT - metrics.getHeight()) / 2;
    g.setColor(Color.black);
    g.setFont(msgsFont);
    g.drawString(msg, x, y);
  } // end of gameOverMessage()
Example #16
0
 void showFrameRate(Graphics g) {
   frames++;
   if (System.currentTimeMillis() > firstFrame + 1000) {
     firstFrame = System.currentTimeMillis();
     fps = frames;
     frames = 0;
   }
   g.setColor(Color.white);
   g.fillRect(10, 12, 50, 15);
   g.setColor(Color.black);
   g.drawString((int) (fps + 0.5) + " fps", 10, 25);
 }
Example #17
0
File: set.java Project: wcyuan/Set
  public void paint(Graphics g) {
    Message("Copyright Feb, 2000 Weicon Conan Yuan.", "All Rights Reserved", 7);
    for (int i = 0; i < NUM_LOCATIONS; i++) {
      locs[i].draw(g, this);
      g.setColor(txtcolor);
      if (locs[i].ToDraw()) {
        g.drawString("" + i, locs[i].GetX(), locs[i].GetY() + 10);
      }
    }

    g.setColor(Color.red);
    g.drawRect(400, 200, 30, 30);
    g.fillRect(400, 200, 30, 30);
    Message("Cheat", 4);
  }
Example #18
0
  void drawEngineAt(Graphics g, int x, int y, Integer walk, Integer run, Integer current) {

    // Move this to a buffered Image

    final int engineWidth = 128;
    final int engineHeight = 16;

    int walkLocation = walk * engineWidth / run;
    int currentLocation = current * engineWidth / run;

    if (current <= walk) {
      g.setColor(java.awt.Color.GREEN);
    } else {
      g.setColor(java.awt.Color.ORANGE);
    }

    g.fillRect(x, y - 12, currentLocation, 8);

    g.setColor(java.awt.Color.BLACK);

    for (int i = 0; i <= run; i++) {
      int l = i * engineWidth / run;
      g.drawLine(x + l, y, x + l, y - engineHeight / 2);
    }

    g.drawLine(x, y, x, y - engineHeight);
    g.drawLine(x, y, x + engineWidth, y);
    g.drawLine(x + engineWidth, y, x + engineWidth, y - engineHeight);
    g.drawLine(x + walkLocation, y, x + walkLocation, y - engineHeight);

    g.drawString(run.toString(), x + engineWidth - 4, y - engineHeight - 2);
    g.drawString(walk.toString(), x + walkLocation - 4, y - engineHeight - 2);

    g.setFont(new Font("Eurostile", 0, 12));
    g.drawString("Speed", x, y - engineHeight - 2);
  }
Example #19
0
File: set.java Project: wcyuan/Set
    public void centerText(String s1, String s2, Graphics g, Color c, int x, int y, int w, int h) {
      // locs[0].centerText(s1, s2, this.getGraphics(),
      // Color.white, 400,0,200,50);
      // g.setXORMode(unselected_color);
      // centerText("pic" + im, null, g, Color.black, x, y, w, h);

      Font f = g.getFont();
      FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(f);
      int ascent = fm.getAscent();
      int height = fm.getHeight();
      int width1 = 0, width2 = 0, x0 = 0, x1 = 0, y0 = 0, y1 = 0;
      width1 = fm.stringWidth(s1);
      if (s2 != null) width2 = fm.stringWidth(s2);
      x0 = x + (w - width1) / 2;
      x0 = x + (w - width2) / 2;
      if (s2 == null) y0 = y + (h - height) / 2 + ascent;
      else {
        y0 = y + (h - (int) (height * 2.2)) / 2 + ascent;
        y1 = y0 + (int) (height * 1.2);
      }
      g.setColor(c);
      g.drawString(s1, x0, y0);
      if (s2 != null) g.drawString(s2, x1, y1);
    }
Example #20
0
  private void createImage2() {
    java.awt.Image img2 = createImage(height, width);
    Graphics g = img2.getGraphics();

    g.setColor(Color.lightGray);
    g.fillRect(0, 0, height, width);

    g.setColor(Color.black);
    FontMetrics fm = g.getFontMetrics();
    String str = "Work Unit keyrate (kkeys/sec)";
    int length = fm.stringWidth(str);
    g.drawString(str, (height / 2) - length / 2, fm.getHeight());
    g.dispose();
    g.finalize();
    img2.flush();

    int[] pixels = new int[height * width];
    PixelGrabber pg = new PixelGrabber(img2, 0, 0, height, width, pixels, 0, height);
    try {
      pg.grabPixels();
    } catch (InterruptedException e) {
      System.err.println("interrupted waiting for pixels!");
      return;
    }

    /* Rotate the Image */
    int pixels2[] = new int[height * width];
    for (int x = 0; x < width; x++)
      for (int y = 0; y < height; y++) {
        int c = pixels[y + (x) * height];

        // Due a bug in the MS-JavaVM the Background for Images are not the same
        // as for Panel's  so. mark it as non-opaque ..
        if (c != 0xff000000) {
          c = 0;
        }
        pixels2[x + (height - y - 1) * width] = c;
      }

    img = createImage(new MemoryImageSource(width, height, pixels2, 0, width));
    repaint();
  }
Example #21
0
  /**
   * Parse the text then draw it without any rotation.
   *
   * @param g Graphics context
   * @param x pixel position of the text
   * @param y pixel position of the text
   */
  public void draw(Graphics g, int x, int y) {
    TextState ts;
    int xoffset = x;
    int yoffset = y;

    if (g == null || text == null) return;

    Graphics lg = g.create();

    parseText(g);

    if (justification == CENTER) {
      xoffset = x - width / 2;
    } else if (justification == RIGHT) {
      xoffset = x - width;
    }

    if (background != null) {
      lg.setColor(background);
      lg.fillRect(xoffset, yoffset - ascent, width, height);
      lg.setColor(g.getColor());
    }

    if (font != null) lg.setFont(font);
    if (color != null) lg.setColor(color);

    for (int i = 0; i < list.size(); i++) {
      ts = ((TextState) (list.elementAt(i)));
      if (ts.f != null) lg.setFont(ts.f);
      if (ts.s != null) lg.drawString(ts.toString(), ts.x + xoffset, ts.y + yoffset);
    }

    lg.dispose();

    lg = null;
  }
Example #22
0
  static void paintShadowTitle(
      Graphics g,
      String title,
      int x,
      int y,
      Color frente,
      Color shadow,
      int desp,
      int tipo,
      int orientation) {

    // Si hay que rotar la fuente, se rota
    Font f = g.getFont();
    if (orientation == SwingConstants.VERTICAL) {
      AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2);
      f = f.deriveFont(rotate);
    }

    // Si hay que pintar sombra, se hacen un monton de cosas
    if (shadow != null) {
      int matrix = (tipo == THIN ? MATRIX_THIN : MATRIX_FAT);

      Rectangle2D rect = g.getFontMetrics().getStringBounds(title, g);

      int w, h;
      if (orientation == SwingConstants.HORIZONTAL) {
        w = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde
        h = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP
      } else {
        h = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde
        w = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP
      }

      // La sombra del titulo
      BufferedImage iTitulo = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
      BufferedImage iSombra = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

      Graphics2D g2 = iTitulo.createGraphics();
      g2.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

      g2.setFont(f);
      g2.setColor(shadow);
      g2.drawString(title, 3 * matrix, 3 * matrix); // La pintamos en el centro

      ConvolveOp cop =
          new ConvolveOp((tipo == THIN ? kernelThin : kernelFat), ConvolveOp.EDGE_NO_OP, null);
      cop.filter(iTitulo, iSombra); // A ditorsionar

      // Por fin, pintamos el jodio titulo
      g.drawImage(
          iSombra,
          x - 3 * matrix + desp, // Lo llevamos a la posicion original y le sumamos 1
          y - 3 * matrix + desp, // para que la sombra quede pelin desplazada
          null);
    }

    // Si hay que pintar el frente, se pinta
    if (frente != null) {
      g.setFont(f);
      g.setColor(frente);
      g.drawString(title, x, y);
    }
  }
Example #23
0
  private void drawLayout(Graphics g) {
    g.setColor(Color.blue);
    g.drawRect(10, 10, width - 20, height - 20);

    g.setColor(Color.red.brighter());
    Iterator f = players.iterator();
    int lifeDisplayPosition = 0;
    while (f.hasNext()) {
      Player h = (Player) f.next();
      if (h.isActive()) {
        lifeDisplayPosition++;
        String lifeInformation = "Player " + lifeDisplayPosition + ": ";
        for (int i = 0; i < h.getLives(); i++) {
          lifeInformation += "\u2606";
        }
        g.drawString(lifeInformation, 20, lifeDisplayPosition * 40);
      }
    }

    borders[2] = width - 20;
    borders[3] = height - 20;

    Iterator i = players.iterator();
    Player p;
    while (i.hasNext()) {
      p = (Player) i.next();
      if (p.isActive()
          && !countdownF
          && (p.getX() < borders[0]
              || p.getY() < borders[1]
              || p.getX() > borders[2]
              || p.getY() > borders[3])
          && (!p.getImmunity())) {
        p.decLives(width / 2, height / 2);
        p.setImmunity(true);
      }
      if (p.getLives() <= 0) {
        if (p instanceof MouseControlledPlayer) {
          MouseControlledPlayer m = (MouseControlledPlayer) p;
          removeMouseListener(m);
          removeMouseMotionListener(m);
        } else if (p instanceof KeyboardControlledPlayer) {
          KeyboardFocusManager.getCurrentKeyboardFocusManager()
              .removeKeyEventDispatcher((KeyboardControlledPlayer) p);
        }
        i.remove();
        for (int h = 0; h < 4; h++) {
          if (deathLocation[h] == -1) {
            deathLocation[h] = p.getX();
            deathLocation[h + 1] = p.getY();
            break;
          }
        }
      }
    }

    if ((deathLocation[0] != -1) && (deathLocation[1] != -1)) {
      g.drawLine(
          deathLocation[0] - 15,
          deathLocation[1] - 15,
          deathLocation[0] + 15,
          deathLocation[1] + 15);
      g.drawLine(
          deathLocation[0] + 15,
          deathLocation[1] - 15,
          deathLocation[0] - 15,
          deathLocation[1] + 15);
    }
    if ((deathLocation[2] != -1) && (deathLocation[3] != -1)) {
      g.drawLine(
          deathLocation[2] - 15,
          deathLocation[3] - 15,
          deathLocation[2] + 15,
          deathLocation[3] + 15);
      g.drawLine(
          deathLocation[2] + 15,
          deathLocation[3] - 15,
          deathLocation[2] - 15,
          deathLocation[3] + 15);
    }

    if (!onePlayerAlive) {
      Font old = g.getFont();
      g.setFont(new Font("monospaced", Font.BOLD, 20));
      g.setColor(Color.red.darker());
      g.drawString("GAME OVER", width / 2 - 40, height / 2);
      g.setFont(old);
      g.setColor(Color.WHITE);
      g.drawString("Score", width - 60, 25);
      g.drawString(String.valueOf(score), width - 60, 40);
    }
  }
Example #24
0
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      response.setContentType("image/jpeg");
      pageContext =
          _jspxFactory.getPageContext(
              this, request, response, "/myhtml/errorpage/erroe.jsp", true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write('\r');
      out.write('\n');

      // 设置页面不缓存
      response.setHeader("Pragma", "No-cache");
      response.setHeader("Cache-Control", "no-cache");
      response.setDateHeader("Expires", 0);

      //   在内存中创建图象
      int width = 60, height = 20;
      BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

      //   获取图形上下文
      Graphics g = image.getGraphics();

      // 生成随机类
      Random random = new Random();

      //   设定背景色
      g.setColor(getRandColor(200, 250));
      g.fillRect(0, 0, width, height);

      // 设定字体
      g.setFont(new Font("Times   New   Roman", Font.PLAIN, 18));

      // 画边框
      // g.setColor(new   Color());
      // g.drawRect(0,0,width-1,height-1);

      //   随机产生155条干扰线,使图象中的认证码不易被其它程序探测到
      g.setColor(getRandColor(160, 200));
      for (int i = 0; i < 155; i++) {
        int x = random.nextInt(width);
        int y = random.nextInt(height);
        int xl = random.nextInt(12);
        int yl = random.nextInt(12);
        g.drawLine(x, y, x + xl, y + yl);
      }

      //   取随机产生的认证码(4位数字)
      String sRand = "";
      for (int i = 0; i < 4; i++) {
        String rand = String.valueOf(random.nextInt(10));
        sRand += rand;
        //   将认证码显示到图象中
        g.setColor(
            new Color(
                20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
        // 调用函数出来的颜色相同,可能是å›
        // ä¸ºç§å­å¤ªæŽ¥è¿‘,所以只能直接生成
        g.drawString(rand, 13 * i + 6, 16);
      }

      //   将认证码存入SESSION
      session.setAttribute("rand", sRand);

      //   图象生效
      g.dispose();

      //   输出图象到页面
      ImageIO.write(image, "JPEG", response.getOutputStream());
      out.clear();
      out = pageContext.pushBody();

    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try {
            out.clearBuffer();
          } catch (java.io.IOException e) {
          }
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else log(t.getMessage(), t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
  /*.................................................................................................................*/
  public Object doCommand(String commandName, String arguments, CommandChecker checker) {
    Tree trt = treeDisplay.getTree();
    MesquiteTree t = null;
    if (trt instanceof MesquiteTree) t = (MesquiteTree) trt;
    if (checker.compare(
        this.getClass(),
        "Adjust tool has touched branch",
        "[branch number][x coordinate touched][y coordinate touched][modifiers]",
        commandName,
        "touchedPositionAdjust")) {
      if (t == null) return null;
      MesquiteInteger io = new MesquiteInteger(0);
      int node = MesquiteInteger.fromString(arguments, io);
      int x = MesquiteInteger.fromString(arguments, io);
      int y = MesquiteInteger.fromString(arguments, io);
      String mod = ParseUtil.getRemaining(arguments, io);

      Point newOnLine = treeDisplay.getTreeDrawing().projectionOnLine(node, x, y);
      originalX = newOnLine.x;
      originalY = newOnLine.y;
      // lastX= newOnLine.x;
      // lastY = newOnLine.y;
      Graphics g = null;
      if (GraphicsUtil.useXORMode(null, false)) {
        g = treeDisplay.getGraphics();
        g.setXORMode(Color.white);
        g.setColor(Color.red);
      }
      // double bX = treeDisplay.getTreeDrawing().lineBaseX[node];
      // double bY = treeDisplay.getTreeDrawing().lineBaseY[node];
      // Math.sqrt((originalY-bY)*(originalY-bY) + (originalX-bX)*(originalX-bX));
      lastBL = tree.getBranchLength(node);
      double shortestAbove = MesquiteDouble.unassigned;
      for (int daughter = t.firstDaughterOfNode(node);
          t.nodeExists(daughter);
          daughter = t.nextSisterOfNode(daughter))
        shortestAbove = MesquiteDouble.minimum(shortestAbove, tree.getBranchLength(daughter));
      if (shortestAbove == MesquiteDouble.unassigned) upperLimit = MesquiteDouble.infinite;
      else if (MesquiteDouble.isCombinable(lastBL)) upperLimit = shortestAbove + lastBL;
      else upperLimit = shortestAbove + 1.0;
      int ibX = treeDisplay.getTreeDrawing().lineBaseX[node];
      int ibY = treeDisplay.getTreeDrawing().lineBaseY[node];
      lastX = treeDisplay.getTreeDrawing().lineTipX[node];
      lastY = treeDisplay.getTreeDrawing().lineTipY[node];
      if (GraphicsUtil.useXORMode(null, false)) {
        drawThickLine(g, ibX, ibY, lastX, lastY);
        for (int daughter = t.firstDaughterOfNode(node);
            t.nodeExists(daughter);
            daughter = t.nextSisterOfNode(daughter))
          drawThickLine(
              g,
              treeDisplay.getTreeDrawing().lineTipX[daughter],
              treeDisplay.getTreeDrawing().lineTipY[daughter],
              lastX,
              lastY);
        g.fillOval(
            lastX - ovalRadius,
            lastY - ovalRadius,
            ovalRadius + ovalRadius,
            ovalRadius + ovalRadius);
        try {
          g.drawString(MesquiteDouble.toString(lastBL), lastX + 10, lastY);
        } catch (InternalError e) { // workaround for bug on windows java 1.7.
        } catch (Throwable e) {
        }
        lineOn = true;
        g.dispose();
      }
    } else if (checker.compare(
        this.getClass(),
        "Adjust tool has been dropped",
        "[branch number][x coordinate dropped][y coordinate dropped]",
        commandName,
        "droppedPositionAdjust")) {
      if (t == null) return null;
      if (editorOn) return null;
      MesquiteInteger io = new MesquiteInteger(0);
      int node = MesquiteInteger.fromString(arguments, io);
      int x = MesquiteInteger.fromString(arguments, io);
      int y = MesquiteInteger.fromString(arguments, io);
      if (lineOn) {
        Point newOnLine = treeDisplay.getTreeDrawing().projectionOnLine(node, x, y);
        double bX = treeDisplay.getTreeDrawing().lineBaseX[node];
        double bY = treeDisplay.getTreeDrawing().lineBaseY[node];
        double tX = treeDisplay.getTreeDrawing().lineTipX[node];
        double tY = treeDisplay.getTreeDrawing().lineTipY[node];
        double lengthLine =
            Math.sqrt((originalY - bY) * (originalY - bY) + (originalX - bX) * (originalX - bX));
        double bL;
        if (lengthLine != 0) {
          double extension =
              Math.sqrt(
                      (newOnLine.y - bY) * (newOnLine.y - bY)
                          + (newOnLine.x - bX) * (newOnLine.x - bX))
                  / lengthLine;
          if (t.getBranchLength(node) == 0 || t.branchLengthUnassigned(node)) bL = extension;
          else bL = t.getBranchLength(node) * extension;
        } else bL = 1;

        if (bL > upperLimit) bL = upperLimit;
        else if (bL < lowerLimit) bL = lowerLimit;
        double oldBL = t.getBranchLength(node);
        if (!MesquiteDouble.isCombinable(oldBL)) oldBL = 1.0;
        t.setBranchLength(node, bL, false);
        double difference = oldBL - t.getBranchLength(node);
        for (int daughter = t.firstDaughterOfNode(node);
            t.nodeExists(daughter);
            daughter = t.nextSisterOfNode(daughter))
          if (MesquiteDouble.isCombinable(t.getBranchLength(daughter)))
            t.setBranchLength(daughter, t.getBranchLength(daughter) + difference, false);
        t.notifyListeners(this, new Notification(MesquiteListener.BRANCHLENGTHS_CHANGED));
        Graphics g = treeDisplay.getGraphics();
        g.setPaintMode();
        g.dispose();
        treeDisplay.pleaseUpdate(true);
        lineOn = false;
      }
    } else if (checker.compare(
        this.getClass(),
        "Adjust tool is being dragged",
        "[branch number][x coordinate][y coordinate]",
        commandName,
        "draggedPositionAdjust")) {
      if (t == null) return null;
      if (editorOn) return null;
      MesquiteInteger io = new MesquiteInteger(0);
      int node = MesquiteInteger.fromString(arguments, io);
      int x = MesquiteInteger.fromString(arguments, io);
      int y = MesquiteInteger.fromString(arguments, io);
      if (lineOn) {
        Point newOnLine = treeDisplay.getTreeDrawing().projectionOnLine(node, x, y);
        // WARNING":  This shouldn't result in length increase if simple click and release with no
        // drag; must subtract original X, Y
        Graphics g = null;
        if (GraphicsUtil.useXORMode(null, false)) {
          g = treeDisplay.getGraphics();
          g.setXORMode(Color.white);
          g.setColor(Color.red);
        }
        // g.fillOval(lastX-ovalRadius, lastY-ovalRadius, ovalRadius + ovalRadius, ovalRadius +
        // ovalRadius);
        // g.fillOval(newOnLine.x-ovalRadius, newOnLine.y -ovalRadius, ovalRadius + ovalRadius,
        // ovalRadius + ovalRadius);

        // g.drawLine(originalX, originalY, lastX, lastY);
        // g.drawLine(originalX, originalY, newOnLine.x, newOnLine.y);

        //				if decreasing, & unassigned involved: push unassigned down and assign values to
        // unassigned above; if increasing, push unassigne up
        int ibX = treeDisplay.getTreeDrawing().lineBaseX[node];
        int ibY = treeDisplay.getTreeDrawing().lineBaseY[node];
        int itX = treeDisplay.getTreeDrawing().lineTipX[node];
        int itY = treeDisplay.getTreeDrawing().lineTipY[node];

        double bX = ibX;
        double bY = ibY;
        double tX = itX;
        double tY = itY;
        double lengthLine =
            Math.sqrt((originalY - bY) * (originalY - bY) + (originalX - bX) * (originalX - bX));
        if (lengthLine != 0) {
          if (GraphicsUtil.useXORMode(null, false)) {
            if (MesquiteTrunk.isMacOSX()
                && MesquiteTrunk.getJavaVersionAsDouble() >= 1.5
                && MesquiteTrunk.getJavaVersionAsDouble() < 1.6) // due to a JVM bug
            g.fillRect(lastX, lastY - 20, 100, 20);
            g.drawString(MesquiteDouble.toString(lastBL), lastX + 10, lastY);
            if (MesquiteTrunk.isMacOSX()
                && MesquiteTrunk.getJavaVersionAsDouble() >= 1.5
                && MesquiteTrunk.getJavaVersionAsDouble() < 1.6) // due to a JVM bug
            g.fillRect(lastX, lastY - 20, 100, 20);
          }
          double extension =
              Math.sqrt(
                      (newOnLine.y - bY) * (newOnLine.y - bY)
                          + (newOnLine.x - bX) * (newOnLine.x - bX))
                  / lengthLine;
          double bL;
          if (t.getBranchLength(node) == 0 || t.branchLengthUnassigned(node)) bL = extension;
          else bL = t.getBranchLength(node) * extension;
          if (bL > upperLimit) {
            bL = upperLimit;
            if (t.getBranchLength(node) == 0 || t.branchLengthUnassigned(node))
              extension = upperLimit;
            else extension = upperLimit / t.getBranchLength(node);
          } else if (bL < lowerLimit) {
            bL = lowerLimit;
            if (t.getBranchLength(node) == 0 || t.branchLengthUnassigned(node))
              extension = lowerLimit;
            else extension = lowerLimit / t.getBranchLength(node);
          }
          lastBL = bL;
          if (GraphicsUtil.useXORMode(null, false)) {
            drawThickLine(g, ibX, ibY, lastX, lastY);
            for (int daughter = t.firstDaughterOfNode(node);
                t.nodeExists(daughter);
                daughter = t.nextSisterOfNode(daughter))
              drawThickLine(
                  g,
                  treeDisplay.getTreeDrawing().lineTipX[daughter],
                  treeDisplay.getTreeDrawing().lineTipY[daughter],
                  lastX,
                  lastY);
            g.fillOval(
                lastX - ovalRadius,
                lastY - ovalRadius,
                ovalRadius + ovalRadius,
                ovalRadius + ovalRadius);
          }
          int newX = ibX + (int) (extension * (tX - bX));
          int newY = ibY + (int) (extension * (tY - bY));
          if (GraphicsUtil.useXORMode(null, false)) {
            g.drawString(MesquiteDouble.toString(bL), newX + 10, newY);
            drawThickLine(g, ibX, ibY, newX, newY);
            for (int daughter = t.firstDaughterOfNode(node);
                t.nodeExists(daughter);
                daughter = t.nextSisterOfNode(daughter))
              drawThickLine(
                  g,
                  treeDisplay.getTreeDrawing().lineTipX[daughter],
                  treeDisplay.getTreeDrawing().lineTipY[daughter],
                  newX,
                  newY);
            g.fillOval(
                newX - ovalRadius,
                newY - ovalRadius,
                ovalRadius + ovalRadius,
                ovalRadius + ovalRadius);
          }
          lastX = newX;
          lastY = newY;
        }

        // lastX= newOnLine.x;
        // lastY = newOnLine.y;
      }
    }
    return null;
  }
Example #26
0
  public void paintComponent(Graphics g) {
    // We request keyboard focus out here so that we can catch events for locking zoom, etc.
    requestFocus();

    // 3 Images are painted each time. The reason we use images rather than directly drawing
    // onto the graphics context is that the drawings of one image can be taking place
    // concurrently with the other using threads into offscreen graphic contexts assoc.
    // with the respective images. While printing we do the opposite

    if (setupComplete && currImg != null) {
      int prevH = getPrev(currImg.imgIdH);
      int nextH = getNext(currImg.imgIdH);

      if (blFlag || !timer.isRunning()) {
        img[prevH].paintStuff1(0, g, this);
        currImg.paintStuff1(_xPix, g, this);
        img[nextH].paintStuff1(_xPix + _xPix, g, this);

        /*g.drawImage (img [prevH].img, 0, 0, this);
        g.drawImage (img [prevH].timeimg, 0, _yPix, this);

        g.drawImage (currImg.img, _xPix, 0, this);
        g.drawImage (currImg.timeimg, _xPix, _yPix, this);

        g.drawImage (img [nextH].img, _xPix + _xPix, 0, this);
        g.drawImage (img [nextH].timeimg, _xPix + _xPix, _yPix, this);*/
      } else {
        img[prevH].paintStuff2(0, g, this);
        currImg.paintStuff2(_xPix, g, this);
        img[nextH].paintStuff2(_xPix + _xPix, g, this);

        /*g.drawImage (img [prevH].img1, 0, 0, this);
        g.drawImage (img [prevH].timeimg, 0, _yPix, this);

        g.drawImage (currImg.img1, _xPix, 0, this);
        g.drawImage (currImg.timeimg, _xPix, _yPix, this);

        g.drawImage (img [nextH].img1, _xPix + _xPix, 0, this);
        g.drawImage (img [nextH].timeimg, _xPix + _xPix, _yPix, this);*/
      }
    }

    if (zoomLkLineDispStatus && zXTime >= begTime && zXTime <= endTime) {
      int xcord = panePosX + getEvtXCord(zXTime - begTime);
      g.setColor(Color.white);
      g.drawLine(xcord, 0, xcord, _yPix);
      g.fillRect(xcord, _yPix - lineSize, zLockStrW + 2, lineSize);
      g.setColor(Color.black);
      g.drawRect(xcord, _yPix - lineSize, zLockStrW + 1, lineSize - 1);
      g.setColor(Color.red);
      g.drawString("Zoom Lock", xcord + 1, _yPix - fDescent);
    }

    if (elTLineDispStatus && elapsedPoint >= begTime && elapsedPoint <= endTime) {
      int xcord = panePosX + getEvtXCord(elapsedPoint - begTime);
      g.setColor(Color.white);
      g.drawLine(xcord, 0, xcord, _yPix);
      g.fillRect(xcord, _yPix - lineSize, elTimeStrW + 2, lineSize);
      g.setColor(Color.black);
      g.drawRect(xcord, _yPix - lineSize, elTimeStrW + 1, lineSize - 1);
      g.setColor(Color.red);
      g.drawString("Elapsed Time", xcord + 1, _yPix - fDescent);
    }
  }
Example #27
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    RenderingHints rh = g2d.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHints(rh);

    // Background.
    D = this.getSize();
    g.setColor(backgroundColor);
    g.fillRect(0, 0, D.width, D.height);
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(lineStroke);

    // Axes, bounding box.
    g.setColor(Color.gray);
    g.drawLine(inset, D.height - inset, D.width - inset, D.height - inset);
    g.drawLine(D.width - inset, inset, D.width - inset, D.height - inset);
    g.drawLine(inset, inset, inset, D.height - inset);
    g.drawLine(inset, inset, D.width - inset, inset);

    double xDelta = (maxX - minX) / numIntervals;

    // X-ticks and labels.
    for (int i = 1; i <= numIntervals; i++) {
      double xTickd = i * xDelta;
      int xTick = (int) (xTickd / (maxX - minX) * (D.width - 2 * inset));
      g.drawLine(inset + xTick, D.height - inset - 5, inset + xTick, D.height - inset + 5);
      double x = minX + i * xDelta;
      g.drawString(df.format(x), xTick + inset - 5, D.height - inset + 20);
    }

    // Y-ticks
    double yDelta = (maxY - minY) / numIntervals;
    for (int i = 0; i < numIntervals; i++) {
      int yTick = (i + 1) * (int) ((D.height - 2 * inset) / (double) numIntervals);
      g.drawLine(inset - 5, D.height - yTick - inset, inset + 5, D.height - yTick - inset);
      double y = minY + (i + 1) * yDelta;
      g.drawString(df.format(y), 1, D.height - yTick - inset);
    }

    // Zoom+move
    Font savedFont = g.getFont();
    g.setFont(plusFont);
    g.drawString("+", D.width - 25, 20);
    g.setFont(minusFont);
    g.drawString("-", D.width - 25, 50);
    drawArrow(g2d, D.width - 70, 20, D.width - 70, 0, 1.0f, lineStroke); // Up
    drawArrow(g2d, D.width - 70, 30, D.width - 70, 50, 1.0f, lineStroke); // Down
    drawArrow(g2d, D.width - 65, 25, D.width - 45, 25, 1.0f, lineStroke); // Right
    drawArrow(g2d, D.width - 75, 25, D.width - 95, 25, 1.0f, lineStroke); // Left
    g.setFont(savedFont);

    // See if standard axes are in the middle.
    g.setColor(Color.gray);
    if ((minX < 0) && (maxX > 0) && (drawMiddleAxes)) {
      // Draw y-axis
      int x = (int) ((0 - minX) / (maxX - minX) * (D.width - 2 * inset));
      g.drawLine(inset + x, D.height - inset, inset + x, inset);
    }
    if ((minY < 0) && (maxY > 0) && (drawMiddleAxes)) {
      // Draw x-axis
      int y = (int) ((0 - minY) / (maxY - minY) * (D.height - 2.0 * inset));
      g.drawLine(inset, D.height - y - inset, D.width - inset, D.height - y - inset);
    }

    // Draw the objects.
    drawObjects(g, points, lines, ovals, rectangles, images, labels, eqnLines);
    if (animationMode) {
      drawObjects(g, animPoints, animLines, animOvals, animRectangles, null, labels, eqnLines);
      // No images in animation mode.
    }

    drawScribbles(g);
  }