예제 #1
0
  public static void main(String[] args) throws Exception {
    BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setPaint(Color.WHITE);
    g.fill(new Rectangle(image.getWidth(), image.getHeight()));
    g.scale(.9, .9);
    g.setPaint(Color.BLACK);
    g.setStroke(new BasicStroke(0.5f));
    g.draw(new Ellipse2D.Double(25, 25, 150, 150));

    // To visually check it
    // ImageIO.write(image, "PNG", new File(args[0]));

    boolean nonWhitePixelFound = false;
    for (int x = 100; x < 200; ++x) {
      if (image.getRGB(x, 90) != Color.WHITE.getRGB()) {
        nonWhitePixelFound = true;
        break;
      }
    }
    if (!nonWhitePixelFound) {
      throw new RuntimeException("A circle is rendered like a 'C' shape.");
    }
  }
/**
 * Class to store mouse start location when dragging, and to deselect any selected components when
 * the mouse is pressed
 *
 * @author Alex Billingsley
 */
public class MseSelectListener extends MouseAdapter {

  private Point xy1;
  public static final Color DESELECT = new Color(Color.WHITE.getRGB());
  public static final Color SELECT = new Color(Color.LIGHT_GRAY.getRGB());

  /** Creates a new instance of MouseSelectionListener */
  public MseSelectListener() {}

  public void mousePressed(MouseEvent e) {
    xy1 = new Point(e.getX(), e.getY());
    JPanel layer = (JPanel) e.getComponent();
    deSelect(layer);
  }

  public static void deSelect(JPanel layer) {

    Component[] components = layer.getComponents();
    int i = 0;
    while (i < components.length) {

      if (components[i].getClass().getName().equals("javax.swing.JLabel")) {
        if (components[i].getBackground().equals(SELECT)) {
          JLabel temp = (JLabel) components[i];
          temp.setOpaque(false);
          components[i].setBackground(DESELECT);
        }
      }

      if (components[i].getClass().getName().equals("Display.TextBox")) {
        if (components[i].getBackground().equals(SELECT)) {
          components[i].setBackground(DESELECT);
        }
      }

      // If panel is selected, de-select all components nested on panel
      if (components[i].getClass().getName().equals("javax.swing.JPanel")) {
        if (components[i].getBackground().equals(SELECT)) {
          components[i].setBackground(DESELECT);
        }
        deSelect((JPanel) components[i]);
      }

      i++;
    }
  }

  /**
   * Getter for property xy1.
   *
   * @return Value of property xy1.
   */
  public Point getXy1() {
    return this.xy1;
  }
}
예제 #3
0
  public static void renderTooltip(
      int x,
      int y,
      List<String> tooltipData,
      Color color,
      Color colorFade,
      FontRenderer fontRenderer) {
    TextureHelper.setActiveTextureToAtlasSprite();
    boolean lighting = GL11.glGetBoolean(GL11.GL_LIGHTING);
    if (lighting) RenderHelper.disableStandardItemLighting();

    if (!tooltipData.isEmpty()) {
      int esWidth = 0;
      for (String toolTip : tooltipData) {
        int width = fontRenderer.getStringWidth(toolTip);
        if (width > esWidth) esWidth = width;
      }
      int pX = x + 12;
      int pY = y - 12;
      int sumLineHeight = 8;
      if (tooltipData.size() > 1) sumLineHeight += 2 + (tooltipData.size() - 1) * 10;
      float z = 300F;

      drawGradientRect(pX - 3, pY - 4, z, pX + esWidth + 3, pY - 3, color, colorFade);
      drawGradientRect(
          pX - 3,
          pY + sumLineHeight + 3,
          z,
          pX + esWidth + 3,
          pY + sumLineHeight + 4,
          color,
          colorFade);
      drawGradientRect(
          pX - 3, pY - 3, z, pX + esWidth + 3, pY + sumLineHeight + 3, color, colorFade);
      drawGradientRect(pX - 4, pY - 3, z, pX - 3, pY + sumLineHeight + 3, color, colorFade);
      drawGradientRect(
          pX + esWidth + 3, pY - 3, z, pX + esWidth + 4, pY + sumLineHeight + 3, color, colorFade);

      int rgb = color.getRGB();
      int col = (rgb & 0x00FFFFFF) | rgb & 0xFF000000;
      Color colOp = new Color(col);
      drawGradientRect(pX - 3, pY - 3 + 1, z, pX - 3 + 1, pY + sumLineHeight + 3 - 1, color, colOp);
      drawGradientRect(
          pX + esWidth + 2,
          pY - 3 + 1,
          z,
          pX + esWidth + 3,
          pY + sumLineHeight + 3 - 1,
          color,
          colOp);
      drawGradientRect(pX - 3, pY - 3, z, pX + esWidth + 3, pY - 3 + 1, colOp, colOp);
      drawGradientRect(
          pX - 3,
          pY + sumLineHeight + 2,
          z,
          pX + esWidth + 3,
          pY + sumLineHeight + 3,
          color,
          color);

      GL11.glDisable(GL11.GL_DEPTH_TEST);
      for (int i = 0; i < tooltipData.size(); ++i) {
        String var14 = tooltipData.get(i);
        fontRenderer.drawString(var14, pX, pY, Color.WHITE.getRGB());
        if (i == 0) pY += 2;
        pY += 10;
      }
      GL11.glEnable(GL11.GL_DEPTH_TEST);
    }

    if (lighting) RenderHelper.enableStandardItemLighting();
    GL11.glColor4f(1F, 1F, 1F, 1F);
  }