示例#1
0
 /**
  * Create the name label if needed.
  *
  * @return The component that holds the name label.
  */
 protected JComponent getLabelComponent() {
   if (nameLabel == null) {
     nameLabel = new JLabel();
     Font font = nameLabel.getFont();
     nameLabel.setFont(font.deriveFont(Font.ITALIC | Font.BOLD));
     labelComponent = GuiUtils.hflow(Misc.newList(new JLabel("Layout Model: "), nameLabel));
   }
   return labelComponent;
 }
  /**
   * Same as parent, but override for native version of the font.
   *
   * <p>Also gets called by textFont, so the metrics will get recorded properly.
   */
  public void textSize(float size) {
    if (textFont == null) {
      defaultFontOrDeath("textAscent", size);
    }

    // if a native version available, derive this font
    //    if (textFontNative != null) {
    //      textFontNative = textFontNative.deriveFont(size);
    //      g2.setFont(textFontNative);
    //      textFontNativeMetrics = g2.getFontMetrics(textFontNative);
    //    }
    Font font = textFont.getFont();
    if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) {
      Font dfont = font.deriveFont(size);
      g2.setFont(dfont);
      textFont.setFont(dfont);
    }

    // take care of setting the textSize and textLeading vars
    // this has to happen second, because it calls textAscent()
    // (which requires the native font metrics to be set)
    super.textSize(size);
  }
示例#3
0
  static void paintShadowTitle(
      Graphics g,
      String title,
      int x,
      int y,
      Color frente,
      Color shadow,
      int desp,
      int tipo,
      int orientation) {

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

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

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

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

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

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

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

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

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

    // Si hay que pintar el frente, se pinta
    if (frente != null) {
      g.setFont(f);
      g.setColor(frente);
      g.drawString(title, x, y);
    }
  }