Esempio n. 1
1
  /**
   * Draws as much as possible of a given string into a 2d square region in a graphical space.
   *
   * @param g component onto which to draw
   * @param f font to use in drawing the string
   * @param s string to be drawn
   * @param xPos
   * @param yPos
   * @param width
   * @param height
   */
  public static void drawStringMultiline(
      Graphics2D g, Font f, String s, double xPos, double yPos, double width, double height) {
    FontMetrics fm = g.getFontMetrics(f);
    int w = fm.stringWidth(s);
    int h = fm.getAscent();
    // g.setColor(Color.LIGHT_GRAY);
    g.setColor(Color.BLACK);
    g.setFont(f);

    Scanner lineSplitter = new Scanner(s);
    // draw as much as can fit in each item
    // read all content from scanner, storing in string lists (where each string == 1 line), each
    // string should be as long as possible without overflowing the space
    int maxRows = (int) height / h;
    List<String> textRows = new ArrayList<>();
    while (lineSplitter.hasNextLine() && textRows.size() < maxRows) {
      String line = lineSplitter.nextLine();
      // if line is blank, insert to maintain paragraph seps
      if (line.trim().equals("")) {
        textRows.add("");
      }
      // else, pass to inner loop
      StringBuilder currentBuilder = new StringBuilder();
      int currentStrWidth = 0;
      Scanner splitter = new Scanner(line);
      while (splitter.hasNext() && textRows.size() < maxRows) {
        String token = splitter.next() + " ";
        // TODO incorporate weight detection, formatting for token?
        currentStrWidth += fm.stringWidth(token);
        if (currentStrWidth >= width) {
          // if string length >= glyph width, build row
          textRows.add(currentBuilder.toString());
          currentBuilder = new StringBuilder();
          currentBuilder.append(token);
          currentStrWidth = fm.stringWidth(token);
        } else {
          // if not yet at end of row, append to builder
          currentBuilder.append(token);
        }
      }

      // if we've still space and still have things to write, add them here
      if (textRows.size() < maxRows) {
        textRows.add(currentBuilder.toString());
        currentBuilder = new StringBuilder();
        currentStrWidth = 0;
      }
    }

    // write each line to object
    for (int t = 0; t < textRows.size(); t++) {
      String line = textRows.get(t);
      if (fm.stringWidth(line) <= width) {
        // ensure that string doesn't overflow the box
        //                g.drawString(line, (float) (xPos-(width/2.)), (float) (yPos-(height/2.) +
        // h * (t+1)));
        g.drawString(line, (float) xPos, (float) (yPos + h * (t + 1)));
      }
    }
  }
Esempio n. 2
0
  public void paint(Graphics g) {
    gRef = (Graphics2D) g;

    // change size of font
    gRef.setFont(gRef.getFont().deriveFont(9.0f));

    fmRef = g.getFontMetrics();

    // Clear background

    if (Preferences.monochrome) {
      gRef.setColor(Preferences.whiteColor);
    } else {
      gRef.setColor(Preferences.backgroundColor);
    }
    gRef.fillRect(0, 0, getWidth(), getHeight());

    // set colour to correct drawing colour
    if (Preferences.monochrome) {
      gRef.setColor(Preferences.blackColor);
    } else {
      gRef.setColor(Preferences.penColor);
    }

    gRef.translate(0, margin);

    // Call c code to draw tree
    gRef.scale(scale, scale);
    nativeDrawTree();
  }
Esempio n. 3
0
  public void paint(java.awt.Graphics g) {
    if (element != null) {
      Rectangle bounds = element.jGetBounds();
      Graphics2D g2 = (Graphics2D) g;

      g2.setFont(font);

      int mitteX = bounds.x + (bounds.width) / 2;
      int mitteY = bounds.y + (bounds.height) / 2;

      int distanceY = 10;

      g2.setColor(new Color(204, 204, 255));
      g2.fillRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY);
      g2.setColor(Color.BLACK);
      g2.drawRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY);

      String caption = "dec(" + variable.getValue() + ")";

      FontMetrics fm = g2.getFontMetrics();
      Rectangle2D r = fm.getStringBounds(caption, g2);

      g2.setColor(Color.BLACK);
      g.drawString(
          caption, mitteX - (int) (r.getWidth() / 2), (int) (mitteY + fm.getHeight() / 2) - 3);
    }
    super.paint(g);
  }
Esempio n. 4
0
  private void drawTile(Graphics g2, Tile tile, int x, int y) {
    Graphics2D g = ((Graphics2D) g2);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    int value = tile.value;
    int xOffset = offsetCoors(x);
    int yOffset = offsetCoors(y);
    g.setColor(tile.getBackground());
    g.fillRoundRect(xOffset, yOffset, TILE_SIZE, TILE_SIZE, 14, 14);
    g.setColor(tile.getForeground());
    final int size = value < 100 ? 36 : value < 1000 ? 32 : 24;
    final Font font = new Font(FONT_NAME, Font.BOLD, size);
    g.setFont(font);

    String s = String.valueOf(value);
    final FontMetrics fm = getFontMetrics(font);

    final int w = fm.stringWidth(s);
    final int h = -(int) fm.getLineMetrics(s, g).getBaselineOffsets()[2];

    if (value != 0)
      g.drawString(s, xOffset + (TILE_SIZE - w) / 2, yOffset + TILE_SIZE - (TILE_SIZE - h) / 2 - 2);

    if (myWin || myLose) {
      g.setColor(new Color(255, 255, 255, 30));
      g.fillRect(0, 0, getWidth(), getHeight());
      g.setColor(new Color(78, 139, 202));
      g.setFont(new Font(FONT_NAME, Font.BOLD, 48));
      if (myWin) {
        g.drawString("You won!", 68, 150);
      }
      if (myLose) {
        g.drawString("Game over!", 50, 130);
        g.drawString("You lose!", 64, 200);
      }
      if (myWin || myLose) {
        g.setFont(new Font(FONT_NAME, Font.PLAIN, 16));
        g.setColor(new Color(128, 128, 128, 128));
        g.drawString("Press ESC to play again", 80, getHeight() - 40);
      }
    }
    g.setFont(new Font(FONT_NAME, Font.PLAIN, 18));
    g.drawString("Score: " + myScore, 200, 365);
  }
Esempio n. 5
0
  /** Draw vertices on top of the edge structure */
  public void drawNodes(Graphics2D gg) {
    Enumeration nodeList = argument.getBreadthFirstTraversal().elements();
    // Run through the traversal and draw each vertex
    // using an Ellipse2D
    // The draw point has been determined previously in
    // calcNodeCoords()
    while (nodeList.hasMoreElements()) {
      TreeVertex vertex = (TreeVertex) nodeList.nextElement();
      // Don't draw virtual nodes
      if (vertex.isVirtual()) continue;

      // If tree is incomplete and we're on the top layer, skip it
      if (argument.isMultiRoots() && vertex.getLayer() == 0) continue;

      Point corner = vertex.getDrawPoint();
      Shape node = new Ellipse2D.Float(corner.x, corner.y, NODE_DIAM, NODE_DIAM);
      vertex.setShape(node, this);

      // Fill the interior of the node with vertex's fillPaint
      gg.setPaint(vertex.fillPaint);
      gg.fill(node);

      // Draw the outline with vertex's outlinePaint; bold if selected
      gg.setPaint(vertex.outlinePaint);
      if (vertex.isSelected()) {
        gg.setStroke(selectStroke);
      } else {
        gg.setStroke(solidStroke);
      }
      gg.draw(node);

      // Draw the short label on top of the vertex
      gg.setPaint(vertex.textPaint);
      String shortLabelString = new String(vertex.getShortLabel());
      if (shortLabelString.length() == 1) {
        gg.setFont(labelFont1);
        gg.drawString(shortLabelString, corner.x + NODE_DIAM / 4, corner.y + 3 * NODE_DIAM / 4);
      } else if (shortLabelString.length() == 2) {
        gg.setFont(labelFont2);
        gg.drawString(shortLabelString, corner.x + NODE_DIAM / 5, corner.y + 3 * NODE_DIAM / 4);
      }
    }
  }
 public void draw(Graphics2D g) {
   g.setColor(fillColor);
   g.fill(gp);
   g.setColor(Color.black);
   g.draw(gp);
   for (int i = 0; i < points.size(); i++) {
     GlyphPoint p = points.get(i);
     g.setColor(Color.red);
     g.draw(p.gp);
     g.setColor(Color.blue);
     g.setFont(gfont);
     g.drawString(String.valueOf(i), p.x + 3, p.y + 3);
   }
   g.setColor(Color.black);
   //	    System.out.println("Advance: "+advance);
   g.draw(advp);
   if (name != null) {
     g.setFont(gfont);
     g.drawString(name, 0, -40);
   }
 }
Esempio n. 7
0
 /**
  * Overrides Step draw method.
  *
  * @param panel the drawing panel requesting the drawing
  * @param _g the graphics context on which to draw
  */
 public void draw(DrawingPanel panel, Graphics _g) {
   if (track.trackerPanel == panel) {
     AutoTracker autoTracker = track.trackerPanel.getAutoTracker();
     if (autoTracker.isInteracting(track)) return;
   }
   if (panel instanceof TrackerPanel) {
     TrackerPanel trackerPanel = (TrackerPanel) panel;
     super.draw(trackerPanel, _g);
     Graphics2D g = (Graphics2D) _g;
     if (isLabelVisible()) {
       TextLayout layout = textLayouts.get(trackerPanel);
       if (layout == null) return;
       Point p = getLayoutPosition(trackerPanel);
       Paint gpaint = g.getPaint();
       Font gfont = g.getFont();
       g.setPaint(footprint.getColor());
       g.setFont(textLayoutFont);
       layout.draw(g, p.x, p.y);
       g.setPaint(gpaint);
       g.setFont(gfont);
     }
   }
 }
Esempio n. 8
0
 private synchronized void doBuffer(Graphics2D g2, boolean opq, Rectangle rt) {
   origTransform = g2.getTransform();
   if (opq && rt != null) g2.clearRect(rt.x, rt.y, rt.width, rt.height);
   g2.setPaint(origPaint);
   g2.setFont(origFont);
   g2.setStroke(origStroke);
   if (inBuffer) { // System.out.println("upps");
     for (int i = 0; i < a1x.size(); i++) doPaint(g2, a1x.get(i), a2x.get(i));
     origTransform = null;
     return;
   }
   for (int i = 0; i < a1.size(); i++) doPaint(g2, a1.get(i), a2.get(i));
   origTransform = null;
 }
Esempio n. 9
0
  /**
   * paintComponent schreibt alle Laendernamen an die entsprechende Stelle der Landkarte
   * (Hintergrundgrafik) und zeichnet die Laendergrenzen auf der Landkarte nach.
   *
   * @param g Zeichenflaeche der Landkarte
   */
  public void paintComponent(Graphics g) {
    Shape shape;

    Graphics2D g2d = (Graphics2D) g;
    g2d.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
    Font myFont = new Font("Times New Roman", Font.BOLD, 12);
    g2d.setFont(myFont);

    g2d.setStroke(new BasicStroke(2.0f));

    Territory territory;
    Color color;

    ListIterator territories = worldMap.getTerritories().listIterator();

    while (territories.hasNext()) {
      territory = (Territory) territories.next();

      if (territory.getOwner() != null) {
        color = territory.getOwner().getPlayerColor();
      } else {
        color = Color.WHITE;
      }

      g2d.setColor(color);
      g2d.drawString(
          territory.getName(),
          (int) territory.getMidpoint().getX() - 15,
          (int) territory.getMidpoint().getY() - 10);

      g2d.drawString(
          new Integer(territory.getArmySize()).toString(),
          (int) territory.getMidpoint().getX(),
          (int) territory.getMidpoint().getY());
    }

    if (territoryBattle.size() != 0) {
      for (int j = 0; j < territoryBattle.size(); j++) {
        g2d.setColor(territoryBattle.get(j).getOwner().getPlayerColor());
        // g2d.fillPolygon(territoryTmp.getFrontiers());   Sieht bei unseren Grenzen nicht huebsch
        // aus
        g2d.drawPolygon(territoryBattle.get(j).getFrontiers());
      }
    }

    repaint();
  }
Esempio n. 10
0
    /** @see prefuse.render.Renderer#render(java.awt.Graphics2D, prefuse.visual.VisualItem) */
    @Override
    public void render(Graphics2D g, VisualItem item) {
      Shape s = getShape(item);
      GraphicsLib.paint(g, item, m_line, getStroke(item), getRenderType(item));

      // check if we have a text label, if so, render it
      String str;
      if (item.canGetString(VisualItem.LABEL)) {
        str = (String) item.getString(VisualItem.LABEL);
        if (str != null && !str.equals("")) {
          float x = (float) m_box.getMinX();
          float y = (float) m_box.getMinY() + m_ascent;

          // draw label background
          GraphicsLib.paint(g, item, s, null, RENDER_TYPE_FILL);

          AffineTransform origTransform = g.getTransform();
          AffineTransform transform = this.getTransform(item);
          if (transform != null) {
            g.setTransform(transform);
          }

          g.setFont(item.getFont());
          g.setColor(ColorLib.getColor(item.getTextColor()));

          if (!(str.length() > 5
              && str.substring(str.length() - 5, str.length()).equals("_last"))) {

            g.setColor(Color.WHITE);
            // TODO properly hunt down source of null str! for now, triage
            if (str != null) {
              // bump y down by appropriate amount
              FontMetrics fm = g.getFontMetrics(item.getFont());
              int strHeight = fm.getAscent();
              //                        g.drawString(str, x, y);
              g.drawString(str, x, y + strHeight);
            }

            if (transform != null) {
              g.setTransform(origTransform);
            }
          }
        }
      }
    }
Esempio n. 11
0
 public void paint(Graphics screen) {
   Graphics2D screen2D = (Graphics2D) screen;
   Font type = new Font("Monospaced", Font.BOLD, 20);
   screen2D.setFont(type);
   GregorianCalendar day = new GregorianCalendar();
   String time = day.getTime().toString();
   screen2D.setColor(back);
   screen2D.drawString(lastTime, 5, 25);
   screen2D.setColor(butterscotch);
   screen2D.drawString(time, 5, 25);
   try {
     Thread.sleep(1000);
   } catch (InterruptedException e) {
     // do nothing
   }
   lastTime = time;
   repaint();
 }
Esempio n. 12
0
 void renderUI(Graphics2D g2d) {
   g2d.setFont(new Font("Courier New", Font.PLAIN, 12));
   g2d.setColor(Color.white);
   if (removeMode) g2d.setColor(Color.black);
   if (player.health < 0) player.health = 0;
   g2d.drawString(String.format("Helath: %s", player.health), 10, 20);
   g2d.drawString(String.format("Kills: %s", player.score), 10, 40);
   int WLevel = (Integer) player.weapon[player.currentWeapon][10];
   if (WLevel == 5)
     g2d.drawString(String.format("Current Weapon: %s:Max", player.currentWeapon), 10, 60);
   else
     g2d.drawString(String.format("Current Weapon: %s:%s", player.currentWeapon, WLevel), 10, 60);
   g2d.setColor(Color.gray);
   g2d.drawString(String.format("Level: %s", difficulty), 10, 80);
   g2d.setColor(Color.black);
   if (showDebug) g2d.drawString(String.format("FPS: %s", fps), 10, 100);
   if (cheated) g2d.drawString("You cheated, no highscore will be saved", 200, height - 15);
 }
Esempio n. 13
0
  /**
   * A rendering method to draw this label to the given Graphics2D object, with the additional
   * option of allowing the "long" lines to be drawn. Due to the fact that the relative drawing
   * point of a state is its x and y co-ordinates and for a Transition there is a workOutMiddle()
   * method, the relative x and y values must be supplied to this method. Usually this method will
   * be called from inside a Transition render method or a State render method.
   *
   * @param g2 the Graphics2D component upon which to draw this label.
   * @param x the x position upon which to make relative co-ordinates exact.
   * @param y the y position upon which to make relative co-ordinates exact.
   * @param longLines flag to determine whether the long version of this label should be drawn.
   */
  public void render(Graphics2D g2, double x, double y, boolean longLines) {
    intersects(new Rectangle2D.Double(0, 0, 1, 1));
    StringTokenizer tokens = new StringTokenizer(getRenderString(), "\n");
    if (selected) {
      g2.setColor(Color.green);
    } else {
      g2.setColor(theColour);
    }
    g2.setFont(theFont);
    int i = 0;
    boolean doneLong = false;
    while (tokens.hasMoreTokens()) {
      if (doneLong)
        g2.drawString(
            tokens.nextToken(),
            (float) (x + offsetX),
            (float) (y + offsetY + ((i * (theFont.getSize() + 2)))));
      else {
        if (!longLines)
          g2.drawString(
              tokens.nextToken().trim(),
              (float) (x + offsetX),
              (float) (y + offsetY + ((i * (theFont.getSize()))) + 2));
        else
          g2.drawString(
              getName() + ": " + tokens.nextToken().trim(),
              (float) (x + offsetX),
              (float) (y + offsetY + ((i * (theFont.getSize()))) + 2));
      }
      i++;
      doneLong = true;
    }

    /*if(intersects != null)
    {
        g2.setColor(Color.magenta);
        for(int j = 0; j < intersects.size(); j++)
        {
            Rectangle2D rect = (Rectangle2D)intersects.get(j);
            g2.draw(rect);
        }
    }*/

  }
Esempio n. 14
0
 private synchronized void toBuffer(int s, Object a) {
   a1.add(s);
   a2.add(a);
   if (s == clear) {
     clearBuffer();
   }
   if (s == opaque) theOpaque = (Boolean) a;
   if (s == setBackground) theBackground = (Color) a;
   if (inBuffer) return;
   if (isSetter(s)) return;
   Graphics g = getGraphics();
   if (g == null) return;
   Graphics2D g2 = (Graphics2D) g;
   g2.setPaint(origPaint);
   g2.setFont(origFont);
   g2.setStroke(origStroke);
   for (int i = 0; i < a1.size() - 1; i++) {
     int s1 = a1.get(i);
     Object s2 = a2.get(i);
     if (isSetter(s1)) doPaint(g2, s1, s2);
   }
   doPaint((Graphics2D) g, s, a);
 }
 /** Paints the text of the <tt>VisualEdge</tt>. */
 public void paintText(Graphics2D g2d, Font font, Color fontColor, String text, float x, float y) {
   g2d.setFont(font);
   g2d.setColor(fontColor);
   g2d.drawString(text, x, y);
 }
Esempio n. 16
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    // g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);

    Graphics2D canvas = (Graphics2D) g;

    if (panelBackground != null) {
      canvas.drawImage(panelBackground, 0, 0, getPanelWidth(), getPanelHeight(), null);
    }

    if (dalekDamageImage != null) {
      // int w = 100;
      // int h = (int)  (dalekImage.getHeight(null) * w / dalekImage.getWidth(null)  );

      int h = 200;
      // int w = dalekDamageImage.scaleWidth(h);

      int w = h * dalekDamageImage.getWidth(null) / dalekDamageImage.getHeight(null);

      BufferedImage thumbImage = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
      Graphics2D graphics2D = thumbImage.createGraphics();
      graphics2D.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      graphics2D.drawImage(dalekDamageImage, 0, 0, w, h, null);

      canvas.drawImage(thumbImage, getPanelWidth() / 2 - (w / 2), getPanelHeight() - h - 16, null);

      //	g.drawImage(thumbImage,getPanelWidth()/2 - (w/2), 32 ,null);

    }
    if (dalekTacticalImage != null) {

      // int h = 400;
      // int w = dalekTacticalImage.scaleWidth(h);

      BufferedImage thumbImage =
          new BufferedImage(
              dalekTacticalImage.getWidth(),
              dalekTacticalImage.getHeight(),
              BufferedImage.TYPE_4BYTE_ABGR);
      Graphics2D graphics2D = thumbImage.createGraphics();
      graphics2D.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      graphics2D.drawImage(dalekTacticalImage, 0, 0, null);

      // g.drawImage(thumbImage,getPanelWidth()/2 - (w/2), getPanelHeight() - h - 16 ,null);

      canvas.drawImage(thumbImage, 0, 32, null);

      /*
      Iterator<WeaponUI> it = dalekTacticalImage.iterator();
      int y = 32;
      while (it.hasNext()) {
      	g.drawImage(it.next(),0, y ,null);
      	y += 40; // really want height of WeaponUI.
      }
       */

    }

    // Move to Buffered Image
    if (this.getEngineRun() > 0) {
      this.drawEngineAt(
          canvas, 16, 256, this.getEngineWalk(), this.getEngineRun(), this.getEngineCurrent());
    }
    if (this.name != null) {
      canvas.setFont(techFont);
      canvas.drawString(this.name, 16, 24);
    }
  }
Esempio n. 17
0
 // also clip, transform, composite,
 // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;}
 // ---------------------------------------------------------
 private void doPaint(Graphics2D g, int s, Object o) {
   // process an operation from the buffer
   // System.out.println(s);
   Object o1 = null,
       o2 = null,
       o3 = null,
       o4 = null,
       o5 = null,
       o6 = null,
       o7 = null,
       o8 = null,
       o9 = null,
       o10 = null,
       o11 = null;
   if (o instanceof Object[]) {
     Object[] a = (Object[]) o;
     if (a.length > 0) o1 = a[0];
     if (a.length > 1) o2 = a[1];
     if (a.length > 2) o3 = a[2];
     if (a.length > 3) o4 = a[3];
     if (a.length > 4) o5 = a[4];
     if (a.length > 5) o6 = a[5];
     if (a.length > 6) o7 = a[6];
     if (a.length > 7) o8 = a[7];
     if (a.length > 8) o9 = a[8];
     if (a.length > 9) o10 = a[9];
     if (a.length > 10) o11 = a[10];
   }
   switch (s) {
     case clear:
       paintBackground(g, theBackground);
       break;
       // public void addRenderingHints(Map<?,?> hints)
       // {toBuffer("addRenderingHints",hints );}
     case addRenderingHints:
       g.addRenderingHints((Map<?, ?>) o);
       break;
     case clip1:
       g.clip((Shape) o);
       break;
     case draw1:
       g.draw((Shape) o);
       break;
     case draw3DRect:
       g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case drawGlyphVector:
       g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3);
       break;
     case drawImage1:
       g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4);
       break;
     case drawImage2:
       g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3);
       break;
     case drawRenderableImage:
       g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2);
       break;
     case drawRenderedImage:
       g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2);
       break;
     case drawString1:
       g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3);
       break;
     case drawString2:
       g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3);
       break;
     case drawString3:
       g.drawString((String) o1, (Float) o2, (Float) o3);
       break;
     case drawString4:
       g.drawString((String) o1, (Integer) o2, (Integer) o3);
       break;
     case fill:
       g.fill((Shape) o);
       break;
     case fill3DRect:
       g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case rotate1:
       g.rotate((Double) o);
       break;
     case rotate2:
       g.rotate((Double) o1, (Double) o2, (Double) o3);
       break;
     case scale1:
       g.scale((Double) o1, (Double) o2);
       break;
     case setBackground:
       g.setBackground(
           (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/
       break;
     case setComposite:
       g.setComposite((Composite) o);
       break;
     case setPaint:
       g.setPaint((Paint) o);
       break;
     case setRenderingHint:
       g.setRenderingHint((RenderingHints.Key) o1, o2);
       break;
     case setRenderingHints:
       g.setRenderingHints((Map<?, ?>) o);
       break;
     case setStroke:
       g.setStroke((Stroke) o);
       break;
     case setTransform:
       g.setTransform(makeTransform(o));
       break;
     case shear:
       g.shear((Double) o1, (Double) o2);
       break;
     case transform1:
       g.transform(makeTransform(o));
       break;
     case translate1:
       g.translate((Double) o1, (Double) o2);
       break;
     case translate2:
       g.translate((Integer) o1, (Integer) o2);
       break;
     case clearRect:
       g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case copyArea:
       g.copyArea(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawArc:
       g.drawArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawBytes:
       g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawChars:
       g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawImage4:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5);
       break;
     case drawImage5:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4);
       break;
     case drawImage6:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Color) o6,
           (ImageObserver) o7);
       break;
     case drawImage7:
       g.drawImage(
           (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6);
       break;
     case drawImage8:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (Color) o10,
           (ImageObserver) o11);
       break;
     case drawImage9:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (ImageObserver) o10);
       break;
     case drawLine:
       g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawOval:
       g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawPolygon1:
       g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawPolygon2:
       g.drawPolygon((Polygon) o);
       break;
     case drawPolyline:
       g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawRect:
       g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawRoundRect:
       g.drawRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillArc:
       g.fillArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillOval:
       g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
       // {toBuffer("fillPolygon",mkArg(xPoints,  yPoints, nPoints) );}
     case fillPolygon1:
       g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case fillPolygon2:
       g.fillPolygon((Polygon) o);
       break;
     case fillRect:
       g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case fillRoundRect:
       g.fillRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case setClip1:
       g.setClip((Shape) o);
       break;
     case setColor:
       g.setColor((Color) o);
       break;
     case setFont:
       g.setFont((Font) o);
       break;
     case setPaintMode:
       g.setPaintMode();
       break;
     case setXORMode:
       g.setXORMode((Color) o);
       break;
     case opaque:
       super.setOpaque((Boolean) o);
       break;
     case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break;
       {
         FontRenderContext frc = g.getFontRenderContext();
         TextLayout tl = new TextLayout((String) o1, g.getFont(), frc);
         Shape s1 = tl.getOutline(null);
         AffineTransform af = g.getTransform();
         g.translate((Integer) o2, (Integer) o3);
         g.draw(s1);
         g.setTransform(af);
       }
       ;
       break;
     default:
       System.out.println("Unknown image operation " + s);
   }
 }
Esempio n. 18
0
  boolean eventHandeler(Graphics2D g2d) {

    if (keyboard.keyDownOnce(KeyEvent.VK_Q)) {
      window.setState(Frame.ICONIFIED);
      paused = true;
    }

    if (firstStartup) {
      g2d.setColor(Color.white);
      g2d.fill(new Rectangle(0, 0, width, height));

      g2d.setFont(new Font("Courier New", Font.PLAIN, 20));
      g2d.setColor(Color.black);
      switch (startupPage) {
        case 1:
          if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) startupPage = 2;

          g2d.drawString("The goal of this game is to kill as", 100, 170);
          g2d.drawString("many *zombies* as possible. You are", 100, 200);
          g2d.drawString("given weapons and power-ups to help", 100, 230);
          g2d.drawString("you succeed. Good luck.", 100, 260);

          g2d.setColor(Color.gray);
          g2d.drawString("Press SPACE to continue", 150, 330);
          g2d.drawString("Ø O O", 280, 290);

          g2d.setColor(Color.black);
          g2d.setFont(new Font("Courier New", Font.PLAIN, 34));
          g2d.drawString("Story", 265, 110);
          break;
        case 2:
          if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) startupPage = 3;

          g2d.drawString("Use A,S,D,W to stear", 100, 170);
          g2d.drawString("Use 1,2,3,4 to change weapon", 100, 200);
          g2d.drawString("Use the MOUSE to aim", 100, 230);
          g2d.drawString("Use the LEFT MOUSE BUTTON to fire", 100, 260);

          g2d.setColor(Color.gray);
          g2d.drawString("Press SPACE to continue", 150, 330);
          g2d.drawString("O Ø O", 280, 290);

          g2d.setColor(Color.black);
          g2d.setFont(new Font("Courier New", Font.PLAIN, 34));
          g2d.drawString("Controlls", 230, 110);
          break;
        case 3:
          if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) firstStartup = false;

          g2d.setColor(Color.black);
          g2d.draw(new Ellipse2D.Double(100, 170 - 15, 20, 20));
          g2d.setColor(Color.red);
          g2d.draw(new Ellipse2D.Double(100, 200 - 15, 20, 20));
          g2d.setColor(Color.blue);
          g2d.draw(new Ellipse2D.Double(100, 230 - 15, 20, 20));
          g2d.setColor(Color.green);
          g2d.draw(new Ellipse2D.Double(100, 260 - 15, 20, 20));

          g2d.setColor(Color.black);
          g2d.drawString("Is you", 130, 170);
          g2d.drawString("Heals you", 130, 200);
          g2d.drawString("Unlocks / upgrades a weapon", 130, 230);
          g2d.drawString("Causes an explosion around you", 130, 260);

          g2d.setColor(Color.gray);
          g2d.drawString("Press SPACE to start", 150, 330);
          g2d.drawString("O O Ø", 280, 290);

          g2d.setColor(Color.black);
          g2d.setFont(new Font("Courier New", Font.PLAIN, 34));
          g2d.drawString("Power-ups", 230, 110);
          break;
      }
      return true;
    }

    if (player.isDead) {
      g2d.setColor(Color.white);
      g2d.fill(new Rectangle(0, 0, width, height));
      if (keyboard.keyDownOnce(KeyEvent.VK_R)) restart();

      if (newHighscore) {
        int x = 20;
        int y = 130;
        g2d.rotate(-.4, x, y);
        g2d.setFont(new Font("Comic Sans MS", Font.PLAIN, 40));
        g2d.setColor(Color.black);
        Stroke oldStroke = g2d.getStroke();
        float dash[] = {40.0f};
        g2d.setStroke(
            new BasicStroke(
                4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.0f, dash, 40.0f));
        g2d.drawRoundRect(x, y, 320, 75, 20, 20);
        g2d.setColor(Color.red);
        g2d.drawString(String.format("New Highscore"), x + 20, y + 50);
        g2d.rotate(.4, x, y);
        g2d.setStroke(oldStroke);

        g2d.setColor(Color.lightGray);
        g2d.setFont(new Font("Courier", Font.PLAIN, 20));
        g2d.drawString("Your record was " + oldHighScore + " kills", 210, 260);
      } else if (cheated) {
        int x = 20;
        int y = 130;
        g2d.rotate(-.4, x, y);
        g2d.setFont(new Font("Comic Sans MS", Font.PLAIN, 40));
        g2d.setColor(Color.black);
        Stroke oldStroke = g2d.getStroke();
        float dash[] = {40.0f};
        g2d.setStroke(
            new BasicStroke(
                4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.0f, dash, 40.0f));
        g2d.drawRoundRect(x, y, 270, 75, 20, 20);
        g2d.setColor(Color.red);
        g2d.drawString(String.format("You cheated"), x + 20, y + 50);
        g2d.rotate(.4, x, y);
        g2d.setStroke(oldStroke);

        g2d.setColor(Color.lightGray);
        g2d.setFont(new Font("Courier", Font.PLAIN, 20));
        g2d.drawString("Highscore not saved", 210, 260);
      } else {
        g2d.setColor(Color.lightGray);
        g2d.setFont(new Font("Courier", Font.PLAIN, 20));
        g2d.drawString("Your record is " + oldHighScore + " kills", 210, 260);
      }

      g2d.setColor(Color.black);
      g2d.setFont(new Font("Courier", Font.PLAIN, 50));

      if (player.score == 1) g2d.drawString(String.format(player.score + " kill"), 200, 230);
      else g2d.drawString(String.format(player.score + " kills"), 200, 230);
      g2d.setFont(new Font("Courier New", Font.PLAIN, 30));
      g2d.setColor(Color.gray);
      g2d.drawString(String.format("Press R to restart"), 150, 330);
      return true;
    }

    if (window.isFocused() == false) paused = true;

    if (paused) {
      g2d.setColor(Color.white);
      g2d.fill(new Rectangle(0, 0, width, height));
      if (keyboard.keyDownOnce(KeyEvent.VK_ESCAPE)) paused = false;
      g2d.setColor(Color.black);
      g2d.setFont(new Font("Courier", Font.PLAIN, 50));
      g2d.drawString("Paused", 200, 230);
      g2d.setFont(new Font("Courier New", Font.PLAIN, 30));
      g2d.setColor(Color.gray);
      g2d.drawString(String.format("Press ESC to resume"), 150, 330);
      return true;
    }

    return false;
  }
  public void paintRegion(Graphics2D g, int x1, int y1, int w, int h) {
    int h2 = h / 2;
    int rad = 3;
    int diam = rad * 2;

    Color lg = Color.cyan;
    Color dg = Color.orange;

    lg = new Color(lg.getRed(), lg.getGreen(), lg.getBlue(), 75);
    dg = new Color(dg.getRed(), dg.getGreen(), dg.getBlue(), 75);

    /*
     * Draw the Baseline
     */
    g.setColor(Color.black);
    g.drawLine(x1, y1 + h, x1 + w, y1 + h);

    Stroke oldStroke = g.getStroke();
    g.setStroke(new BasicStroke((float) 2.0));

    /*
     * Draw the datapoints
     */
    for (ExprPoint ep : points) {
      if (ep.strand == '+') {
        g.setColor(lg);
      } else {
        g.setColor(dg);
      }

      g.drawOval(x1 + ep.x - rad, y1 + ep.y - rad, diam, diam);
    }

    g.setStroke(oldStroke);

    /*
     * Paint the hash marks...
     */
    if (!displayOppositeChannel) {
      g.setColor(Color.black);
      boolean flipper = true;
      for (int value = 100;
          value <= scale.getMax();
          value *= (flipper ? 5 : 2), flipper = !flipper) {
        int yoff = getYOffset((double) value);
        String line = String.format("%d", value);
        int uy = y1 + h2 - yoff, ly = y1 + h2 + yoff;

        g.drawLine(x1, uy, x1 + 10, uy);
        g.drawString(line, x1 + 12, uy + 5);

        g.drawLine(x1, ly, x1 + 10, ly);
        g.drawString(line, x1 + 12, ly + 5);
      }
    }

    /*
     * Draw any selections.
     */

    g.setColor(Color.black);
    for (Point p : selections.keySet()) {
      ExprPoint ep = selections.get(p);
      g.drawLine(p.x, p.y, ep.x, ep.y);
      g.drawString(ep.getLabel(), p.x, p.y);
    }

    /*
     * Draw the label in the upper-right hand corner.
     */
    g.setColor(Color.black);
    Font oldFont = g.getFont();
    Font newFont = new Font("Arial", Font.BOLD, 24);
    g.setFont(newFont);
    FontMetrics fm = g.getFontMetrics();
    int lblHeight = fm.getAscent() + fm.getDescent();
    int lblWidth = fm.charsWidth(label.toCharArray(), 0, label.length());

    int padding = 5;
    int lblx = x1 + w - lblWidth - padding;
    int lbly = y1 + lblHeight + padding;

    g.drawString(label, lblx, lbly);

    g.setFont(oldFont);
  }