コード例 #1
0
ファイル: SkiPanel.java プロジェクト: kruchy/SlopeModel
  /** {@inheritDoc} */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setBackground(Color.white);
    int xDim = (int) (getWidth() / 56);
    int yDim = (int) (getHeight() / 66);
    g2d.drawLine(0, (agent[0].length) * yDim, Slope.getWidth() * xDim, (agent[0].length) * yDim);
    g2d.drawRect((Slope.getWidth() - 3) * xDim, 0, 15, Slope.getHeight() * yDim);

    for (int k = 0; k < Slope.getHeight(); k++)
      for (int l = 0; l < Slope.getWidth(); l++) {

        g2d.setColor(new Color(0, 0, 0, 1));
        g2d.drawRect(k * getWidth() / 56, l * getHeight() / 66, 30, 30);
      }

    for (int i = 0; i < agent.length; i++) {
      for (int j = 0; j < agent[0].length; j++) {
        g2d.setColor(Color.blue);
        if (agent[i][j]) {
          //					 g2d.drawString("*", i*getWidth()/56, j*getHeight()/66);
          g2d.drawImage(image, i * getWidth() / 56, j * getHeight() / 66, null);
        }
      }
    }
  }
コード例 #2
0
  @Override
  protected void paintTabBorder(
      Graphics graphics,
      int tabPlacement,
      int tabIndex,
      int x,
      int y,
      int w,
      int h,
      boolean isSelected) {
    if (null == graphics) {
      return;
    }
    Graphics2D g = (Graphics2D) graphics;
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    if (isSelected) {
      g.setColor(TabColors.SELECTED_OUTTER_BORDER);
      g.drawRect(x, y, w, h);
      g.setColor(TabColors.SELECTED_INNER_BORDER);
      g.drawRect(x + 1, y + 1, w - 1, h - 1);
    } else {
      g.setColor(TabColors.BORDER);
      g.drawRect(x, y, w, h);
    }
  }
コード例 #3
0
ファイル: OpFooter.java プロジェクト: RobertoQ/LightZone
  private static Icon getThemeIcon(ColorScheme colorScheme, boolean square) {
    int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
    BufferedImage result = SubstanceCoreUtilities.getBlankImage(iSize, iSize);
    Graphics2D graphics = (Graphics2D) result.getGraphics().create();
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Color color1 = (colorScheme == null) ? Color.red : colorScheme.getUltraDarkColor();
    Color color2 = (colorScheme == null) ? Color.green : colorScheme.getMidColor();
    Color color3 = (colorScheme == null) ? Color.blue : colorScheme.getExtraLightColor();

    graphics.setColor(color1);
    if (square) graphics.fillRect(5, 2, 6, 6);
    else graphics.fillOval(5, 2, 6, 6);
    graphics.setColor(color1.darker());
    if (square) graphics.drawRect(5, 2, 6, 6);
    else graphics.drawOval(5, 2, 6, 6);

    graphics.setColor(color2);
    if (square) graphics.fillRect(1, 9, 6, 6);
    else graphics.fillOval(1, 9, 6, 6);
    graphics.setColor(color2.darker());
    if (square) graphics.drawRect(1, 9, 6, 6);
    else graphics.drawOval(1, 9, 6, 6);

    graphics.setColor(color3);
    if (square) graphics.fillRect(9, 9, 6, 6);
    else graphics.fillOval(9, 9, 6, 6);
    graphics.setColor(color3.darker());
    if (square) graphics.drawRect(9, 9, 6, 6);
    else graphics.drawOval(9, 9, 6, 6);

    graphics.dispose();
    return new ImageIcon(result);
  }
コード例 #4
0
  @Override
  public void drawShape() {
    Graphics2D graphics = (Graphics2D) getGraphics();
    Color oldFg = graphics.getColor();
    Table table = getDbModel();
    if (null != table) {
      Point location = getLocation();
      Dimension size = getSize();
      // draw the border
      graphics.setColor(DbexColorConstants.TABLE_BORDER_COLOR);
      graphics.drawRect(location.x, location.y, size.width, size.height);
      graphics.setColor(DbexColorConstants.COLUMN_NAMES_BG_COLOR);
      graphics.fillRect(location.x + 1, location.y + 1, size.width - 1, size.height - 1);
      // draw the header
      graphics.setColor(DbexColorConstants.TABLE_BORDER_COLOR);
      graphics.drawRect(
          location.x, location.y, size.width, DesignUtil.calculateCellHeight(graphics));
      graphics.setColor(DbexColorConstants.TABLE_HEADER_BG_COLOR);
      graphics.fillRect(
          location.x + 1,
          location.y + 1,
          size.width - 1,
          DesignUtil.calculateCellHeight(graphics) - 1);
      graphics.setColor(DbexColorConstants.TABLE_HEADER_FG_COLOR);
      graphics.drawString(
          table.getModelName(),
          location.x + 2,
          location.y + DesignUtil.calculateCellHeight(graphics) - 4);
      // draw the left margin
      graphics.setColor(DbexColorConstants.TABLE_BORDER_COLOR);
      graphics.drawRect(
          location.x,
          location.y + DesignUtil.calculateCellHeight(graphics),
          DbexDesignConstants.TABLE_LEFT_MARGIN_WIDTH,
          size.height - DesignUtil.calculateCellHeight(graphics));
      graphics.setColor(DbexColorConstants.TABLE_LEFT_MARGIN_BG_COLOR);
      graphics.fillRect(
          location.x + 1,
          location.y + DesignUtil.calculateCellHeight(graphics) + 1,
          DbexDesignConstants.TABLE_LEFT_MARGIN_WIDTH - 1,
          size.height - 1 - DesignUtil.calculateCellHeight(graphics));

      // draw columns
      if (null != columnDbShapes) {
        for (int i = 0; i < columnDbShapes.size(); i++) {
          ColumnDbShape columnDbShape = columnDbShapes.get(i);
          columnDbShape.drawShape();
          if (i < columnDbShapes.size() - 1) {
            graphics.setColor(DbexColorConstants.TABLE_BORDER_COLOR);
            graphics.drawLine(
                columnDbShape.getX() + DbexDesignConstants.TABLE_LEFT_MARGIN_WIDTH + 2,
                columnDbShape.getY() + columnDbShape.getHeight() + 2,
                location.x + size.width,
                columnDbShape.getY() + columnDbShape.getHeight() + 2);
          }
        }
      }
    }
    graphics.setColor(oldFg);
  }
コード例 #5
0
ファイル: ClassEntityView.java プロジェクト: As2piK/slyuml
  /**
   * Draw a border representing a selection.
   *
   * @param g2 the graphic context
   */
  public void drawSelectedStyle(Graphics2D g2) {
    final int PADDING = 2;
    final Color selectColor = new Color(100, 100, 100);

    final BasicStroke dashed =
        new BasicStroke(
            1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] {2f}, 0.0f);

    final Rectangle inRectangle =
        new Rectangle(
            bounds.x + PADDING,
            bounds.y + PADDING,
            bounds.width - 2 * PADDING,
            bounds.height - 2 * PADDING);

    final Rectangle outRectangle =
        new Rectangle(
            bounds.x - PADDING,
            bounds.y - PADDING,
            bounds.width + 2 * PADDING,
            bounds.height + 2 * PADDING);

    g2.setStroke(dashed);
    g2.setColor(selectColor);

    g2.drawRect(inRectangle.x, inRectangle.y, inRectangle.width, inRectangle.height);
    g2.drawRect(outRectangle.x, outRectangle.y, outRectangle.width, outRectangle.height);
  }
コード例 #6
0
ファイル: SpritesPanel.java プロジェクト: Cazra/Pwnee2D
  public void paint(Graphics g) {
    // set the background color to white.
    this.setBackground(new Color(0xFFFFFF));

    // clear the panel with the background color.
    super.paint(g);

    // cast our Graphics as a Graphics2D, since it has more features and g is actually a Graphics2D
    // anyways.
    Graphics2D g2D = (Graphics2D) g;

    // render the blittered Strings.
    monoSprite.render(g2D);
    fittedSprite.render(g2D);
    dimsSprite.render(g2D);

    // Draw borders around the text sprites to demonstrate that they
    // are obeying their line-wrapping.
    Dimension monoDim = monoSprite.getDimensions();
    Dimension fittedDim = fittedSprite.getDimensions();

    g2D.drawRect((int) monoSprite.x, (int) monoSprite.y, monoSprite.maxWidth, monoDim.height);
    g2D.drawRect(
        (int) fittedSprite.x, (int) fittedSprite.y, fittedSprite.maxWidth, fittedDim.height);

    // Set our drawing color to black
    g2D.setColor(new Color(0x000000));

    // display the current frame rate.
    g2D.drawString("" + timer.fpsCounter, 400, 32);
  }
コード例 #7
0
 static void printInsets(PrintWriter html, Insets insets) {
   html.println(
       "<td>Insets ("
           + insets.top
           + ","
           + insets.left
           + ","
           + insets.bottom
           + ","
           + insets.right
           + ")</pre></td>");
   int w = 50 + insets.left + insets.right;
   int h = 20 + insets.top + insets.bottom;
   BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
   Graphics2D g2 = img.createGraphics();
   Composite old = g2.getComposite();
   g2.setComposite(AlphaComposite.Clear);
   g2.fillRect(0, 0, w, h);
   g2.setComposite(old);
   g2.setColor(Color.BLACK);
   g2.drawRect(insets.left, insets.top, 49, 19);
   g2.setColor(Color.RED);
   g2.drawRect(0, 0, w - 1, h - 1);
   g2.dispose();
   html.println("<td>" + saveImage(img) + "</td>");
 }
コード例 #8
0
ファイル: BlockWorld.java プロジェクト: nlemon/RetroCrane
  public void drawStuff(Graphics2D g2) {

    g2.setColor(Color.BLACK);
    g2.fillRect(0, 0, 650, 450);
    g2.setColor(Color.BLACK);
    g2.drawRect(0, 0, 650, 450);

    for (int i = 0; i < blocks.size(); i++) {

      if (blocks.get(i).isOnMagnet()) continue;
      Shape curShape = blocks.get(i).getFrame();
      Rectangle2D boundingBox = (Rectangle2D) curShape;

      g2.setColor(Color.WHITE);
      g2.fillRect(
          (int) boundingBox.getX(), (int) boundingBox.getY(),
          (int) boundingBox.getWidth(), (int) boundingBox.getHeight());

      g2.setColor(Color.BLUE);
      g2.drawRect(
          (int) boundingBox.getX(), (int) boundingBox.getY(),
          (int) boundingBox.getWidth(), (int) boundingBox.getHeight());
    }

    g2.setColor(Color.GRAY);
    g2.fillRect(0, 380, 650, 70);
    g2.setColor(Color.BLACK);
    g2.drawRect(0, 380, 650, 70);
  }
コード例 #9
0
  @Override
  public void onPaint(Graphics2D graphics2D) {
    this.runtimeMillis = System.currentTimeMillis() - this.startTimeMillis;
    graphics2D.setColor(new Color(0, 0, 100, 120));
    graphics2D.fillRect(25, 240, 350, 82);

    graphics2D.setColor(Color.GREEN);
    graphics2D.fillRect(25, 240, 3 * this.expTracker.getPercentageToNextLevel(Skill.HERBLORE), 9);

    graphics2D.setColor(Color.WHITE);
    graphics2D.drawRect(25, 240, 350, 9);
    graphics2D.drawRect(25, 240, 350, 82);

    int cleanedPerHour =
        (int)
            (3600000.0
                / (double) (System.currentTimeMillis() - this.startTimeMillis)
                * (double) this.herbsCleaned);
    String profitsPerHour =
        String.valueOf(cleanedPerHour * this.profitPerClean)
            .replaceAll("(\\d)(?=(\\d{3})+$)", "$1,");

    graphics2D.setFont(new Font("Monospaced", 0, 12));
    graphics2D.drawString(
        "Herbs cleaned: " + this.herbsCleaned + " | (" + cleanedPerHour + ")", 28, 260);
    graphics2D.drawString("Current State: " + this.textualState, 28, 270);
    graphics2D.drawString("Time running: " + Core.formatElapsedTime(this.runtimeMillis), 28, 280);
    graphics2D.drawString(
        "XP Gained: "
            + this.expTracker.getExperienceGained(Skill.HERBLORE)
            + (" | (" + this.expTracker.getLevelsGained(Skill.HERBLORE) + ")"),
        28,
        290);
    graphics2D.drawString(
        "XP/hr: "
            + this.expTracker.gainedPerHour(Skill.HERBLORE)
            + " | Profit/hr: "
            + profitsPerHour,
        28,
        300);
    graphics2D.drawString(
        "Time till next level: "
            + Core.formatElapsedTime(this.expTracker.timeUntilNextLevel(Skill.HERBLORE)),
        28,
        310);

    graphics2D.drawLine(
        (int) this.getMouse().getPosition().getX(),
        (int) this.getMouse().getPosition().getY() + 10,
        (int) this.getMouse().getPosition().getX(),
        (int) this.getMouse().getPosition().getY() - 10);
    graphics2D.drawLine(
        (int) this.getMouse().getPosition().getX() + 10,
        (int) this.getMouse().getPosition().getY(),
        (int) this.getMouse().getPosition().getX() - 10,
        (int) this.getMouse().getPosition().getY());

    graphics2D.setColor(Color.RED);
    graphics2D.drawString("by Chicken Wing      v1.0", 70, 320);
  }
コード例 #10
0
ファイル: Element.java プロジェクト: Aidy121/Gravity
  public void render(Graphics2D g) {

    trueText = interpretText(text);

    if (parent.style == Gui.STYLE_B) {
      g.setColor(new Color(200, 200, 0, 90));
    } else if (action == BUTTON) {
      if (mode == DEFAULT) {
        g.setColor(new Color(181, 89, 49, 90));
      } else if (mode == MOUSE_OVER) {
        g.setColor(new Color(211, 119, 79, 90));
      } else if (mode == PRESSED) {
        g.setColor(new Color(151, 59, 19, 90));
      }
    } else {
      g.setColor(new Color(181, 89, 49, 90));
    }

    g.fillRect(parent.x + x, parent.y + y, width, height);
    g.setColor(new Color(0, 0, 0));
    g.drawRect(parent.x + x, parent.y + y, width, height);

    if (action == LABEL || action == BUTTON) {

      g.setColor(color); // Text color

      int height = this.height - 6;

      g.setFont(new Font("Impact", Font.PLAIN, height)); // Maximum size (y)

      int width = g.getFontMetrics().stringWidth(trueText);

      if (width > this.width - 10) {
        height = (int) ((double) height * (this.width - 10.0) / width);
        g.setFont(new Font("Impact", Font.PLAIN, height)); // Maximum size (x)
        width = g.getFontMetrics().stringWidth(trueText);
      }

      int x = this.x + (this.width / 2) - width / 2 + 1;

      g.drawString(trueText, parent.x + x, parent.y + y + height + (this.height - height) / 2 - 1);
    } else if (action == SLIDER) {

      g.setStroke(new BasicStroke(3));
      g.setColor(new Color(0, 0, 0, 190));

      g.drawLine(
          parent.x + x + (int) (SLIDER_WIDTH * 1.5),
          parent.y + y + height / 2,
          parent.x + x + width - (int) (SLIDER_WIDTH * 1.5),
          parent.y + y + height / 2);

      g.setColor(new Color(181, 89, 49));

      g.fillRect(parent.x + x + getScrollValue(), parent.y + y + 5, SLIDER_WIDTH, height - 10);
      g.setColor(new Color(0, 0, 0));
      g.drawRect(parent.x + x + getScrollValue(), parent.y + y + 5, SLIDER_WIDTH, height - 10);
    }
  }
コード例 #11
0
ファイル: GMap.java プロジェクト: joshuasm/gmap-viewer
 // initialize default image
 private BufferedImage getDefaultImage(int w, int h) {
   BufferedImage defaultImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
   Graphics2D graphics2D = defaultImage.createGraphics();
   graphics2D.setColor(new Color(200, 200, 200));
   graphics2D.fillRect(0, 0, w, h);
   graphics2D.setColor(new Color(130, 130, 130));
   graphics2D.drawRect(0, 0, w - 1, h - 1);
   return defaultImage;
 }
コード例 #12
0
ファイル: SudokuCV.java プロジェクト: kasrasadeghi/Sudoku
  /**
   * Paints the 3x3 outer grid.
   *
   * @param g
   * @param w
   * @param h
   */
  public void paintGrid(Graphics g, int w, int h) {
    g.setColor(Color.BLACK);

    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke(3));
    g2.drawRect(0, 0, w, h);
    g2.drawRect(0, h / 3, w, h / 3);
    g2.drawRect(w / 3, 0, w / 3, h);
    g2.setStroke(new BasicStroke(1));
  }
コード例 #13
0
ファイル: Paint.java プロジェクト: Kirinsoul/Monk_Slayer
  public static void evokeTabs(Graphics g1, boolean hide) {
    final Color color1 = new Color(255, 51, 0);
    final Color color2 = new Color(0, 0, 0);
    final BasicStroke stroke1 = new BasicStroke(1);
    final Font font1 = new Font("Century", 0, 15);
    Graphics2D g = (Graphics2D) g1;
    g.translate(0, 50);

    if (!hide) {
      g.setColor(color1);
      g.fillRect(445, 173, 70, 26);
      g.setColor(color2);
      g.setStroke(stroke1);
      g.drawRect(445, 173, 70, 26);
      g.fillRect(445, 145, 70, 26);
      g.drawRect(445, 145, 70, 26);
      g.fillRect(445, 201, 70, 26);
      g.drawRect(445, 201, 70, 26);
      g.setColor(color1);
      g.fillRect(445, 117, 70, 26);
      g.setColor(color2);
      g.drawRect(445, 117, 70, 26);
      g.fillRect(445, 88, 70, 26);
      g.drawRect(445, 88, 70, 26);
      g.setColor(color1);
      g.fillRect(445, 60, 70, 26);
      g.setColor(color2);
      g.drawRect(445, 60, 70, 26);
      g.fillRect(445, 32, 70, 26);
      g.drawRect(445, 32, 70, 26);
      g.setColor(color1);
      g.fillRect(445, 4, 70, 26);
      g.setColor(color2);
      g.drawRect(445, 4, 70, 26);
      g.setFont(font1);
      g.drawString("Magic", 460, 194);
      g.setColor(color1);
      g.drawString("Range", 459, 166);
      g.drawString("Prayer", 457, 222);
      g.setColor(color2);
      g.drawString("Defense", 452, 138);
      g.setColor(color1);
      g.drawString("Const", 457, 110);
      g.setColor(color2);
      g.drawString("Strength", 451, 82);
      g.setColor(color1);
      g.drawString("Attack", 458, 54);
      g.setColor(color2);
      g.drawString("Hide", 465, 25);

    } else {
      g.setColor(color1);
      g.fillRect(445, 4, 70, 26);
      g.setColor(color2);
      g.drawRect(445, 4, 70, 26);
      g.setFont(font1);
      g.setColor(color2);
      g.drawString("Show", 465, 25);
    }
  }
コード例 #14
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      AbstractButton button = (AbstractButton) c;
      Graphics2D g2D = (Graphics2D) g;
      Color frameColor = AbstractLookAndFeel.getTheme().getFrameColor();
      if (!JTattooUtilities.isFrameActive(button)) {
        frameColor = ColorHelper.brighter(frameColor, 40);
      }

      if (AbstractLookAndFeel.getTheme().doDrawSquareButtons()) {
        g2D.setColor(Color.white);
        g2D.drawRect(x, y, w - 1, h - 1);

        if (button.getRootPane() != null
            && button.equals(button.getRootPane().getDefaultButton())
            && !button.hasFocus()) {
          g2D.setColor(ColorHelper.darker(frameColor, 20));
          g2D.drawRect(x, y, w - 1, h - 2);
          if (!button.getModel().isRollover()) {
            g2D.setColor(defaultColorHi);
            g2D.drawRect(x + 1, y + 1, w - 3, h - 4);
            g2D.setColor(defaultColorLo);
            g2D.drawRect(x + 2, y + 2, w - 5, h - 6);
          }
        } else {
          g2D.setColor(frameColor);
          g2D.drawRect(x, y, w - 2, h - 2);
        }
      } else {
        Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
        g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        if (button.getRootPane() != null
            && button.equals(button.getRootPane().getDefaultButton())) {
          if (!button.getModel().isRollover()) {
            g2D.setColor(defaultColorHi);
            g2D.drawRoundRect(x + 1, y + 1, w - 4, h - 2, 6, 6);
            g2D.setColor(defaultColorLo);
            g2D.drawRoundRect(x + 2, y + 2, w - 6, h - 6, 6, 6);
          }
        }

        g2D.setColor(Color.white);
        g2D.drawRoundRect(x, y, w - 1, h - 1, 6, 6);

        g2D.setColor(frameColor);
        g2D.drawRoundRect(x, y, w - 2, h - 2, 6, 6);

        g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint);
      }
    }
コード例 #15
0
 /**
  * Draws a progress bar using the co-ordinates, dimensions and skill provided. This also displays
  * current level in the skill, percent till the next level & exp needed to reach the next level
  *
  * @param g An instance of Graphics to paintType to.
  * @param skill The number of the skill wanting to display. E.g Skills.MAGIC
  * @param x The "x" co-ordinate.
  * @param y The "y" co-ordinate.
  * @param w The width of the progress bar.
  * @param h The height of the progress bar.
  * @param hover If you want extra info to be displayed (Usually for when the skill is "Hovered")
  * @author Rudday, UberMouse
  */
 public void drawProgressBar(Graphics g, int skill, int x, int y, int w, int h, boolean hover) {
   Graphics2D g2 = (Graphics2D) g;
   Paint p = g2.getPaint();
   GradientPaint grad1 =
       new GradientPaint(x, y, scheme.firstGradient1, x, y + h + 3, scheme.firstGradient2);
   GradientPaint grad2 =
       new GradientPaint(x, y, scheme.secondGradient1, x, y + h + 3, scheme.secondGradient2);
   g2.setPaint(grad1);
   g2.fillRect(x, y, w, h);
   g2.setPaint(grad2);
   g2.fillRect(x, y, (int) (w * (UberSkills.getPercentToNextLevel(skill) / 100.0)), h);
   g2.setColor(scheme.text);
   g2.drawRect(x, y, w, h);
   g2.setFont(new Font("Arial", 0, 9));
   String progress =
       UberSkills.getPercentToNextLevel(skill)
           + "% to "
           + ((UberSkills.getRealLevel(skill) + 1 <= 120)
               ? UberSkills.getRealLevel(skill) + 1
               : 120)
           + " "
           + name
           + " | "
           + UberSkills.getExpToNextLevel(skill)
           + " XPTL";
   g2.drawString(
       progress,
       x + ((w - (g.getFontMetrics().stringWidth(progress))) / 2),
       (int) (y + ((g.getFontMetrics().getHeight() / 2) + (h / 4) * 1.75)));
   g2.setPaint(p);
   if (hover) {
     g2.setColor(scheme.hover);
     g2.fillRect(x, y - (height + 2), width, height);
     g2.setColor(scheme.text);
     g2.drawRect(x, y - (height + 2), width, height);
     progress =
         "TTL: "
             + skillInfo.timeToLevel()
             + " XPG: "
             + skillInfo.xpGained()
             + " XPPH: "
             + skillInfo.xpPH()
             + " LG: "
             + skillInfo.levelsGained();
     g2.drawString(
         progress,
         x + ((w - (g.getFontMetrics().stringWidth(progress))) / 2),
         (int) ((y - (height + 2)) + ((g.getFontMetrics().getHeight() / 2) + (h / 4) * 1.75)));
   }
 }
コード例 #16
0
  public void drawPoolOrLane(String name, int x, int y, int width, int height) {
    g.drawRect(x, y, width, height);

    // Add the name as text, vertical
    if (name != null && name.length() > 0) {
      // Include some padding
      int availableTextSpace = height - 6;

      // Create rotation for derived font
      AffineTransform transformation = new AffineTransform();
      transformation.setToIdentity();
      transformation.rotate(270 * Math.PI / 180);

      Font currentFont = g.getFont();
      Font theDerivedFont = currentFont.deriveFont(transformation);
      g.setFont(theDerivedFont);

      String truncated = fitTextToWidth(name, availableTextSpace);
      int realWidth = fontMetrics.stringWidth(truncated);

      g.drawString(
          truncated,
          x + 2 + fontMetrics.getHeight(),
          3 + y + availableTextSpace - (availableTextSpace - realWidth) / 2);
      g.setFont(currentFont);
    }
  }
コード例 #17
0
  public BufferedImage[] createUI(TComponent component, int w, int h) {
    BufferedImage[] ui = GraphicsUtil.createImage(3, w, h, Transparency.OPAQUE);

    String[] color =
        new String[] {
          "Background Color", "Background Disabled Color", "Background Uneditable Color"
        };
    String[] border =
        new String[] {
          "Background Border Color",
          "Background Border Disabled Color",
          "Background Border Uneditable Color"
        };

    for (int i = 0; i < ui.length; i++) {
      Graphics2D g = ui[i].createGraphics();

      g.setColor((Color) get(color[i], component));
      g.fillRect(0, 0, w, h);

      g.setColor((Color) get(border[i], component));
      g.drawRect(0, 0, w - 1, h - 1);

      g.dispose();
    }

    return ui;
  }
コード例 #18
0
  public void paintShadow(Component c, Graphics2D g, int x, int y, int width, int height) {
    final int leftSize = myLeft.getIconWidth();
    final int rightSize = myRight.getIconWidth();
    final int bottomSize = myBottom.getIconHeight();
    final int topSize = myTop.getIconHeight();

    myTopLeft.paintIcon(c, g, x, y);
    myTopRight.paintIcon(c, g, x + width - myTopRight.getIconWidth(), y);
    myBottomRight.paintIcon(
        c, g, x + width - myBottomRight.getIconWidth(), y + height - myBottomRight.getIconHeight());
    myBottomLeft.paintIcon(c, g, x, y + height - myBottomLeft.getIconHeight());

    for (int _x = myTopLeft.getIconWidth(); _x < width - myTopRight.getIconWidth(); _x++) {
      myTop.paintIcon(c, g, _x + x, y);
    }
    for (int _x = myBottomLeft.getIconWidth(); _x < width - myBottomLeft.getIconWidth(); _x++) {
      myBottom.paintIcon(c, g, _x + x, y + height - bottomSize);
    }
    for (int _y = myTopLeft.getIconHeight(); _y < height - myBottomLeft.getIconHeight(); _y++) {
      myLeft.paintIcon(c, g, x, _y + y);
    }
    for (int _y = myTopRight.getIconHeight(); _y < height - myBottomRight.getIconHeight(); _y++) {
      myRight.paintIcon(c, g, x + width - rightSize, _y + y);
    }

    if (myBorderColor != null) {
      g.setColor(myBorderColor);
      g.drawRect(
          x + leftSize - 1,
          y + topSize - 1,
          width - leftSize - rightSize + 1,
          height - topSize - bottomSize + 1);
    }
  }
コード例 #19
0
ファイル: GameState.java プロジェクト: mgriley/hive-wars
  private void drawSelectionBox(Graphics2D g2d) {

    // Draw the rectangular selection box
    if (leftMousePressed && !startedInMiniMap && !startedInHiveCreation) {

      Pt topLeft = new Pt();
      topLeft.setX(Math.min(mouseGlobal.x(), startSelect.x()));
      topLeft.setY(Math.min(mouseGlobal.y(), startSelect.y()));

      int width = (int) Math.abs(mouseGlobal.x() - startSelect.x());
      int height = (int) Math.abs(mouseGlobal.y() - startSelect.y());

      g2d.setColor(Color.GREEN);
      Stroke original = g2d.getStroke();
      int dashOneLength = 3;
      int dashInterval = 5;
      int dashTwoLength = dashOneLength * 5;
      g2d.setStroke(
          new BasicStroke(
              1,
              BasicStroke.CAP_BUTT,
              BasicStroke.JOIN_BEVEL,
              0,
              new float[] {dashOneLength, dashInterval, dashTwoLength, dashInterval},
              0));
      g2d.drawRect(topLeft.intX(), topLeft.intY(), width, height);
      g2d.setStroke(original);
    }
  }
コード例 #20
0
  /**
   * Paint the marker.
   *
   * @param g the graphics device
   * @param context the painting context
   * @param converter the pixel converter
   * @param zoom the zoom level
   * @param minX the bounding box minimum x pixel coordinate
   * @param minY the bounding box minimum y pixel coordinate
   * @param maxX the bounding box maximum x pixel coordinate
   * @param maxY the bounding box maximum y pixel coordinate
   * @param gBounds the graphics bounds
   * @param calculateArea if the area representing the marker should be calculated, if <code>false
   *     </code> is given here the return value is ignored and should be <code>null</code>
   * @return the area that represents the marker
   */
  protected Area doPaintMarker(
      Graphics2D g,
      T context,
      PixelConverter converter,
      int zoom,
      int minX,
      int minY,
      int maxX,
      int maxY,
      Rectangle gBounds,
      boolean calculateArea) {
    if (applyFill(g, context)) {
      g.fillRect(minX, minY, maxX - minX + 1, maxY - minY + 1);
    }

    if (applyStroke(g, context)) {
      g.drawRect(minX, minY, maxX - minX + 1, maxY - minY + 1);
    }

    if (calculateArea) {
      return new BoxArea(minX, minY, maxX, maxY);
    } else {
      return null;
    }
  }
コード例 #21
0
  /**
   * Code to paint the WhiteboardShapeRect.
   *
   * @param g graphics context
   * @param t 2D affine transformation
   */
  public void paintShape(Graphics2D g, AffineTransform t) {
    double x = point.getX();
    double y = point.getY();

    g.setStroke(new BasicStroke(this.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND));

    Point2D w0 = new Point2D.Double(x, y);
    Point2D v0 = t.transform(w0, null);

    int x0 = (int) v0.getX();
    int y0 = (int) v0.getY();

    Point2D w1 = new Point2D.Double(x + width, y + height);
    Point2D v1 = t.transform(w1, null);

    int xWidth = (int) v1.getX() - x0;
    int yHeight = (int) v1.getY() - y0;

    g.setColor(Color.getColor("", this.getColor()));
    if (fill) {
      g.fillRect(x0, y0, xWidth, yHeight);
    } else {
      g.drawRect(x0, y0, xWidth, yHeight);
    }
  }
コード例 #22
0
ファイル: DrawPanel.java プロジェクト: lq100d/Makelangelo
 private void paintLimits(Graphics2D g2d, MachineConfiguration mc) {
   if (!connected) {
     g2d.setColor(new Color(194.0f / 255.0f, 133.0f / 255.0f, 71.0f / 255.0f));
     g2d.drawRect(
         (int) TX(mc.limit_left),
         (int) TY(mc.limit_top),
         (int) ((mc.limit_right - mc.limit_left) * extraScale),
         (int) ((mc.limit_top - mc.limit_bottom) * extraScale));
     g2d.setColor(Color.WHITE);
     g2d.fillRect(
         (int) TX(mc.paper_left),
         (int) TY(mc.paper_top),
         (int) ((mc.paper_right - mc.paper_left) * extraScale),
         (int) ((mc.paper_top - mc.paper_bottom) * extraScale));
   } else {
     g2d.setColor(new Color(194.0f / 255.0f, 133.0f / 255.0f, 71.0f / 255.0f));
     g2d.fillRect(
         (int) TX(mc.limit_left),
         (int) TY(mc.limit_top),
         (int) ((mc.limit_right - mc.limit_left) * extraScale),
         (int) ((mc.limit_top - mc.limit_bottom) * extraScale));
     g2d.setColor(Color.WHITE);
     g2d.fillRect(
         (int) TX(mc.paper_left),
         (int) TY(mc.paper_top),
         (int) ((mc.paper_right - mc.paper_left) * extraScale),
         (int) ((mc.paper_top - mc.paper_bottom) * extraScale));
   }
 }
コード例 #23
0
ファイル: Paint.java プロジェクト: xPropel/LonelehMining
  private void percentBar(
      boolean vertical,
      int x,
      int y,
      int width,
      int height,
      double percentage,
      Color percentColor,
      Color color,
      Stroke stroke,
      Graphics2D g) {
    g.setRenderingHints(
        new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
    int drawPercentage = (int) (((percentage > 100 ? 100 : percentage) / 100) * width);
    g.setColor(percentColor);

    if (!vertical)
      g.fillRect(
          x,
          y,
          (width > height ? drawPercentage : width),
          (height >= width ? drawPercentage : height));
    else {
      int x1 = (width > height ? width - drawPercentage : 0);
      int y2 = (height >= width ? height - drawPercentage : 0);
      g.fillRect(x + x1, y + y2, width - x1, height - y2);
    }

    g.setColor(color);
    g.setStroke(stroke);
    g.drawRect(x, y, width, height);
  }
コード例 #24
0
  @Override
  protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    Rectangle b = getBounds();

    // dessiner un fond de couleur
    Color bgColor = color != null ? color : Color.white;
    g2d.setColor(bgColor);
    g2d.fillRect(0, 0, b.width, b.height);

    // si la couleur est nulle, dessiner une diagonale
    if (color == null) {
      g2d.setColor(borderColor);
      g2d.setStroke(new BasicStroke(borderThickness + 1));
      g2d.drawLine(0, 0, b.width, b.height);
    }

    // bordure
    g2d.setStroke(new BasicStroke(borderThickness));
    g2d.setColor(borderColor);
    g2d.drawRect(
        borderThickness / 2,
        borderThickness / 2,
        b.width - borderThickness,
        b.height - borderThickness);
  }
コード例 #25
0
ファイル: ToolBarCode.java プロジェクト: zhiyang4cn/JfinalUIB
  /**
   * 将照片logo添加到二维码中间
   *
   * @param image 生成的二维码照片对象
   * @param imagePath 照片保存路径
   * @param logoPath logo照片路径
   * @param formate 照片格式
   */
  public static void overlapImage(
      BufferedImage image,
      String formate,
      String imagePath,
      String logoPath,
      MatrixToLogoImageConfig logoConfig) {
    try {
      BufferedImage logo = ImageIO.read(new File(logoPath));
      Graphics2D g = image.createGraphics();
      // 考虑到logo照片贴到二维码中,建议大小不要超过二维码的1/5;
      int width = image.getWidth() / logoConfig.getLogoPart();
      int height = image.getHeight() / logoConfig.getLogoPart();
      // logo起始位置,此目的是为logo居中显示
      int x = (image.getWidth() - width) / 2;
      int y = (image.getHeight() - height) / 2;
      // 绘制图
      g.drawImage(logo, x, y, width, height, null);

      // 给logo画边框
      // 构造一个具有指定线条宽度以及 cap 和 join 风格的默认值的实心 BasicStroke
      g.setStroke(new BasicStroke(logoConfig.getBorder()));
      g.setColor(logoConfig.getBorderColor());
      g.drawRect(x, y, width, height);

      g.dispose();
      // 写入logo照片到二维码
      ImageIO.write(image, formate, new File(imagePath));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #26
0
ファイル: DButton.java プロジェクト: bo198214/4dbb
  public void paint(Graphics g) {
    Graphics2D gc = (Graphics2D) g;
    // for antialiasing text
    gc.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    gc.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    Dimension d = getSize();
    // System.out.println(d.width + "x" + d.height);
    // System.out.println(d.width + "," + d.height);
    int w = d.width - 1;
    int h = d.height - 1;
    float brightness = (float) Settings.brightness.getDouble();
    gc.setColor(Color.black);
    gc.fillRect(0, 0, getWidth(), getHeight());

    gc.setColor(new Color(brightness, brightness, brightness));

    if (mouseInside) gc.drawRoundRect(0, 0, w, h, 8, 8);
    else gc.drawRect(0, 0, w, h);
    FontMetrics fm = gc.getFontMetrics();
    Rectangle2D sb = fm.getStringBounds(text, gc);
    double x = (d.width - sb.getWidth()) / 2;
    double y = (d.height + sb.getHeight()) / 2 - fm.getDescent();
    gc.drawString(text, (int) Math.round(x), (int) Math.round(y));
  }
コード例 #27
0
  @Override
  public void onRepaint(Graphics g1) {
    Graphics2D g = (Graphics2D) g1;

    final Color color1 = new Color(213, 214, 175);
    final Color color2 = new Color(0, 0, 0);
    final Color color3 = new Color(1, 1, 1);

    final BasicStroke stroke1 = new BasicStroke(1);

    final Font font1 = new Font("Verdana", 3, 18);
    final Font font2 = new Font("Verdana", 1, 12);

    if (Game.isLoggedIn()) {
      currentWcExp = Skills.getExperience(Skills.WOODCUTTING);
      woodcuttingExpGained = currentWcExp - startWoodcuttingExp;
      int xpHour = (int) (3600000.0 / (runTime.getElapsed()) * woodcuttingExpGained);

      g.setColor(color1);
      g.fillRect(8, 394, 487, 114);
      g.setColor(color2);
      g.setStroke(stroke1);
      g.drawRect(8, 394, 487, 114);
      g.setFont(font1);
      g.setColor(color3);
      g.drawString("AnDraynorWillowChopper v0.3", 219, 421);
      g.setFont(font2);
      g.drawString("Status: " + Status, 18, 433);
      g.drawString("Run Time: " + runTime.toElapsedString(), 18, 452);
      g.drawString("Xp gained: " + woodcuttingExpGained + "(" + xpHour + ")/hr", 19, 472);
      g.drawString("WoodCutting Level: " + Skills.getLevel(Skills.WOODCUTTING), 18, 491);
    }
  }
コード例 #28
0
ファイル: Panel.java プロジェクト: aajjbb/Pixelator
 @Override
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D copy = (Graphics2D) g.create();
   if (dragging) {
     copy.drawImage(imageBuffer, 0, 0, null);
     if (objectDragging == SelectedForm.LINE) {
       Line l = (Line) objectDragged;
       copy.setColor(l.getColor());
       copy.drawLine(l.getP1().x, l.getP1().y, l.getP2().x, l.getP2().y);
     } else if (objectDragging == SelectedForm.SQUARE) {
       Square sq = (Square) objectDragged;
       copy.setColor(sq.getColor());
       copy.drawRect(
           sq.adjustRendering().x, sq.adjustRendering().y, sq.getWidth(), sq.getHeight());
     } else if (objectDragging == SelectedForm.CIRCLE) {
       Circle c = (Circle) objectDragged;
       copy.setColor(c.getColor());
       copy.drawOval(c.adjustRendering().x, c.adjustRendering().y, c.getWidth(), c.getHeight());
     } else if (objectDragging == SelectedForm.POLYLINE) {
       Polyline poly = (Polyline) objectDragged;
       copy.setColor(poly.getColor());
       poly.fill();
       int[] XIS = poly.getX();
       int[] YSP = poly.getY();
       copy.drawPolyline(XIS, YSP, poly.getN());
       copy.drawLine(
           XIS[poly.getN() - 1], YSP[poly.getN() - 1], poly.getActualX(), poly.getActualY());
     }
   } else {
     copy.drawImage(imageBuffer, 0, 0, null);
   }
   copy.dispose();
 }
コード例 #29
0
  /**
   * Draw the icon at the specified location. Icon implementations may use the Component argument to
   * get properties useful for painting, e.g. the foreground or background color.
   *
   * @param c the component which the icon belongs to
   * @param gorg the graphic object to draw on
   * @param x the upper left point of the icon in the x direction
   * @param y the upper left point of the icon in the y direction
   */
  public void paintIcon(final Component c, final Graphics gorg, final int x, final int y) {
    final Graphics2D g = (Graphics2D) gorg.create();
    if (!mousepressed) {
      g.translate(-1, -1);
    }

    if (mousepressed && mouseover) {
      g.setColor(Color.WHITE);
      g.fillRect(x + 1, y + 1, 14, 14);
    }

    g.setColor(Color.black);
    g.drawRect(x + 1, y + 1, 14, 14);
    if (mouseover) {
      g.setColor(Color.GRAY);
    }

    g.setStroke(new BasicStroke(2));
    // from top left to bottom right
    g.drawLine(x + 5, y + 5, x + 12, y + 12);
    // from bottom left to top right
    g.drawLine(x + 12, y + 5, x + 5, y + 12);

    g.dispose();
  }
コード例 #30
0
ファイル: Paint.java プロジェクト: Kirinsoul/Monk_Slayer
  public static void evokeCombat(Graphics g1, boolean hide, int skill) {

    final Color color1 = new Color(0, 0, 0);
    final Color color2 = new Color(255, 0, 0);

    final BasicStroke stroke1 = new BasicStroke(1);

    final Font font1 = new Font("Arial", 0, 10);
    final Font font2 = new Font("Arial", 0, 18);

    if (!hide) {
      Graphics2D g = (Graphics2D) g1;
      g.setColor(color1);
      g.fillRect(1, 1, 162, 180);
      g.setStroke(stroke1);
      g.drawRect(1, 1, 162, 180);
      g.setFont(font1);
      g.setColor(color2);
      g.drawString("Current Level: " + Skills.getLevel(skill), 5, 48);
      g.drawString("Levels Gained: " + sd.level(skill), 5, 65);
      g.drawString("Experiance / hour: " + getXpHr(skill), 5, 82);
      g.drawString("TTL: " + getTtl(skill), 6, 100);
      g.setFont(font2);
      g.drawString("Monk Killer", 6, 26);
      g.setFont(font1);
      g.drawString("Run Time: " + runTime.toElapsedString(), 6, 116);
      g.drawString("Monks Killed: " + monksKilled, 6, 133);
      g.drawString("Bones looted: " + bonesLooted, 6, 150);
      g.setFont(font2);
      g.drawString("By: Kirinsoul!", 5, 176);
    }
  }