コード例 #1
0
ファイル: SevenSegment.java プロジェクト: pi0/AP2014
  @Override
  public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int v = value;
    boolean is_ng = false;
    if (v > 999) v = 999;
    if (v < 0) {
      v *= -1;
      is_ng = true;
      if (v > 99) v = 99;
    }
    for (int i = 2, p = 1; i >= 0; i--, v /= 10) {
      BufferedImage r = GameResource.sevenSegmentDigits[v % 10];
      g2.drawImage(r, i * 15 + 5, 5, 15, 30, this);
    }
    if (is_ng) {
      BufferedImage r = GameResource.sevenSegmentDigits[10];
      g2.drawImage(r, 0 * 15 + 5, 5, 15, 30, this);
    }
  }
コード例 #2
0
 public void paint(Graphics g) {
   if (g instanceof Graphics2D) {
     Graphics2D g2 = (Graphics2D) g;
     g2.setRenderingHint(
         RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
     g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   }
   super.paint(g);
 }
コード例 #3
0
ファイル: LoginBox.java プロジェクト: timburrow/ovj3
 public void paint(Graphics g) {
   if (comp != null) {
     width = comp.getWidth() / 6;
     height = comp.getHeight() * 2 / 3;
   }
   g.setColor(bgColor);
   g.fillRect(x, y, width, height);
   g.setColor(fgColor);
   g.setFont(font);
   g.drawString(strTray, x / 2 + width / 2, y + height + 10);
   super.paint(g);
 }
コード例 #4
0
ファイル: ScreenCapture.java プロジェクト: geovas01/mathpiper
 /*
  *  Create a BufferedImage for Swing components.
  *  All or part of the component can be captured to an image.
  *
  *  @param	 component Swing component to create image from
  *  @param	 region The region of the component to be captured to an image
  *  @param	 fileName name of file to be created or null
  *  @return	image the image for the given region
  *  @exception IOException if an error occurs during writing
  */
 public static BufferedImage createImage(JComponent component, Rectangle region, String fileName)
     throws IOException {
   boolean opaqueValue = component.isOpaque();
   component.setOpaque(true);
   BufferedImage image =
       new BufferedImage(region.width, region.height, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2d = image.createGraphics();
   g2d.setClip(region);
   component.paint(g2d);
   g2d.dispose();
   component.setOpaque(opaqueValue);
   ScreenCapture.writeImage(image, fileName);
   return image;
 }
コード例 #5
0
  public void paint(Graphics g) {
    super.paint(g);
    if (thumbnail != null) {
      int x = getWidth() / 2 - thumbnail.getIconWidth() / 2;
      int y = getHeight() / 2 - thumbnail.getIconHeight() / 2;
      if (y < 0) {
        y = 0;
      }

      if (x < 5) {
        x = 5;
      }
      thumbnail.paintIcon(this, g, x, y);
    }
  }
コード例 #6
0
  public void paint(Graphics g) {
    Graphics2D gr = (Graphics2D) g;
    super.paint(g);
    Rectangle bounds = scene.getBounds();
    Dimension size = getSize();

    double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
    double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
    double scale = Math.min(sx, sy);

    int vw = (int) (scale * bounds.width);
    int vh = (int) (scale * bounds.height);
    int vx = (size.width - vw) / 2;
    int vy = (size.height - vh) / 2;

    if (image == null || vw != imageWidth || vh != imageHeight) {

      imageWidth = vw;
      imageHeight = vh;
      image = this.createImage(imageWidth, imageHeight);
      Graphics2D ig = (Graphics2D) image.getGraphics();
      ig.scale(scale, scale);
      scene.setRealZoomFactor(scale);
      scene.paint(ig);
      scene.setRealZoomFactor(0.0);
    }

    gr.drawImage(image, vx, vy, this);

    JComponent component = scene.getView();
    double zoomFactor = scene.getZoomFactor();
    Rectangle viewRectangle = component != null ? component.getVisibleRect() : null;
    if (viewRectangle != null) {
      Rectangle window =
          new Rectangle(
              (int) ((double) viewRectangle.x * scale / zoomFactor),
              (int) ((double) viewRectangle.y * scale / zoomFactor),
              (int) ((double) viewRectangle.width * scale / zoomFactor),
              (int) ((double) viewRectangle.height * scale / zoomFactor));
      window.translate(vx, vy);
      gr.setColor(new Color(200, 200, 200, 128));
      gr.fill(window);
      gr.setColor(Color.BLACK);
      gr.drawRect(window.x, window.y, window.width - 1, window.height - 1);
    }
  }
コード例 #7
0
  @Override
  public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int textWidth = g2.getFontMetrics().stringWidth("00:00.00");
    int fontSize = getFont().getSize() * getWidth() / textWidth;
    g2.setFont(getFont().deriveFont((float) Math.min(fontSize, getHeight())));

    Rectangle2D bounds = g2.getFontMetrics().getStringBounds(this.text, g2);
    g2.drawString(
        this.text,
        (int) ((getWidth() - bounds.getWidth()) / 2 - bounds.getX()),
        (int) ((getHeight() - bounds.getHeight()) / 2 - bounds.getY()));
  }
コード例 #8
0
ファイル: Test4783068.java プロジェクト: jjjunior/jdk7u-jdk
  void test(JComponent c) {
    c.setEnabled(false);
    c.setOpaque(true);
    c.setBackground(TEST_COLOR);
    c.setBorder(null);
    Dimension size = c.getPreferredSize();
    c.setBounds(0, 0, size.width, size.height);

    BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
    c.paint(image.getGraphics());

    int rgb = TEST_COLOR.getRGB();
    for (int i = 0; i < size.height; i++) {
      for (int j = 0; j < size.width; j++) {
        if (image.getRGB(j, i) != rgb) {
          throw new RuntimeException(String.format("Color mismatch at [%d, %d]", j, i));
        }
      }
    }
  }
コード例 #9
0
  private void checkResult(@TestDataFile String expectedResultFileName) throws IOException {
    myEditor.getSettings().setAdditionalLinesCount(0);
    myEditor.getSettings().setAdditionalColumnsCount(1);
    JComponent editorComponent = myEditor.getContentComponent();
    Dimension size = editorComponent.getPreferredSize();
    editorComponent.setSize(size);
    //noinspection UndesirableClassUsage
    BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
    BitmapFont bitmapFont = BitmapFont.loadFromFile(getFontFile());
    MyGraphics graphics = new MyGraphics(image.createGraphics(), bitmapFont);
    try {
      editorComponent.paint(graphics);
    } finally {
      graphics.dispose();
    }

    File fileWithExpectedResult = getTestDataFile(expectedResultFileName);
    if (OVERWRITE_TESTDATA) {
      ImageIO.write(image, "png", fileWithExpectedResult);
      System.out.println("File " + fileWithExpectedResult.getPath() + " created.");
    }
    if (fileWithExpectedResult.exists()) {
      BufferedImage expectedResult = ImageIO.read(fileWithExpectedResult);
      if (expectedResult.getWidth() != image.getWidth()) {
        fail("Unexpected image width", fileWithExpectedResult, image);
      }
      if (expectedResult.getHeight() != image.getHeight()) {
        fail("Unexpected image height", fileWithExpectedResult, image);
      }
      for (int i = 0; i < expectedResult.getWidth(); i++) {
        for (int j = 0; j < expectedResult.getHeight(); j++) {
          if (expectedResult.getRGB(i, j) != image.getRGB(i, j)) {
            fail("Unexpected image contents", fileWithExpectedResult, image);
          }
        }
      }
    } else {
      ImageIO.write(image, "png", fileWithExpectedResult);
      fail("Missing test data created: " + fileWithExpectedResult.getPath());
    }
  }
コード例 #10
0
  private EditorFragmentComponent(
      EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) {
    Document doc = editor.getDocument();
    final int endOffset =
        endLine < doc.getLineCount() ? doc.getLineEndOffset(endLine) : doc.getTextLength();
    int textWidth =
        Math.min(
            editor.getMaxWidthInRange(doc.getLineStartOffset(startLine), endOffset),
            ScreenUtil.getScreenRectangle(1, 1).width);
    LOG.assertTrue(
        textWidth > 0,
        "TextWidth: " + textWidth + "; startLine:" + startLine + "; endLine:" + endLine + ";");

    FoldingModelEx foldingModel = editor.getFoldingModel();
    boolean isFoldingEnabled = foldingModel.isFoldingEnabled();
    if (!showFolding) {
      foldingModel.setFoldingEnabled(false);
    }

    Point p1 = editor.logicalPositionToXY(new LogicalPosition(startLine, 0));
    Point p2 = editor.logicalPositionToXY(new LogicalPosition(Math.max(endLine, startLine + 1), 0));
    int y1 = p1.y;
    int y2 = p2.y;
    int height = y2 - y1 == 0 ? editor.getLineHeight() : y2 - y1;
    LOG.assertTrue(
        height > 0,
        "Height: "
            + height
            + "; startLine:"
            + startLine
            + "; endLine:"
            + endLine
            + "; p1:"
            + p1
            + "; p2:"
            + p2);

    int savedScrollOffset = editor.getScrollingModel().getHorizontalScrollOffset();
    if (savedScrollOffset > 0) {
      editor.stopOptimizedScrolling();
      editor.getScrollingModel().scrollHorizontally(0);
    }

    final Image textImage = new BufferedImage(textWidth, height, BufferedImage.TYPE_INT_RGB);
    Graphics textGraphics = textImage.getGraphics();

    final JComponent rowHeader;
    final Image markersImage;
    if (showGutter) {
      rowHeader = editor.getGutterComponentEx();
      markersImage =
          new BufferedImage(Math.max(1, rowHeader.getWidth()), height, BufferedImage.TYPE_INT_RGB);
      Graphics markerGraphics = markersImage.getGraphics();

      markerGraphics.translate(0, -y1);
      markerGraphics.setClip(0, y1, rowHeader.getWidth(), height);
      markerGraphics.setColor(getBackgroundColor(editor));
      markerGraphics.fillRect(0, y1, rowHeader.getWidth(), height);
      rowHeader.paint(markerGraphics);
    } else {
      rowHeader = null;
      markersImage = null;
    }

    textGraphics.translate(0, -y1);
    textGraphics.setClip(0, y1, textWidth, height);
    final boolean wasVisible = editor.setCaretVisible(false);
    editor.setPurePaintingMode(true);
    try {
      editor.getContentComponent().paint(textGraphics);
    } finally {
      editor.setPurePaintingMode(false);
    }
    if (wasVisible) {
      editor.setCaretVisible(true);
    }

    if (!showFolding) {
      foldingModel.setFoldingEnabled(isFoldingEnabled);
    }

    if (savedScrollOffset > 0) {
      editor.stopOptimizedScrolling();
      editor.getScrollingModel().scrollHorizontally(savedScrollOffset);
    }

    JComponent component =
        new JComponent() {
          public Dimension getPreferredSize() {
            return new Dimension(
                textImage.getWidth(null) + (markersImage == null ? 0 : markersImage.getWidth(null)),
                textImage.getHeight(null));
          }

          protected void paintComponent(Graphics graphics) {
            if (markersImage != null) {
              graphics.drawImage(markersImage, 0, 0, null);
              graphics.drawImage(textImage, rowHeader.getWidth(), 0, null);
            } else {
              graphics.drawImage(textImage, 0, 0, null);
            }
          }
        };

    setLayout(new BorderLayout());
    add(component);

    final Color borderColor =
        editor.getColorsScheme().getColor(EditorColors.SELECTED_TEARLINE_COLOR);

    Border outsideBorder = BorderFactory.createLineBorder(borderColor, 1);
    Border insideBorder = BorderFactory.createEmptyBorder(2, 2, 2, 2);
    setBorder(BorderFactory.createCompoundBorder(outsideBorder, insideBorder));
  }
コード例 #11
0
 public void paint(Graphics g) {
   super.paint(g);
   // LineMetrics _metrics = _font.
 }
コード例 #12
0
ファイル: Notepad.java プロジェクト: ArcherSys/ArcherSysRuby
 @Override
 public void paint(Graphics g) {
   super.paint(g);
 }