Exemplo n.º 1
0
  public Browser(String currentHref) {
    super();

    this.currentHref = currentHref;

    try {
      if (Bither.getMainFrame() != null) {
        Bither.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      }
      addHyperlinkListener(new ActivatedHyperlinkListener(Bither.getMainFrame(), this));

      loadingMessage = LocaliserUtils.getString("browser.loadingMessage");

      setEditable(false);
      setBackground(Themes.currentTheme.detailPanelBackground());

      String fontName = null;
      if (fontName == null || "".equals(fontName)) {
        fontName = ColorAndFontConstants.BITHER_DEFAULT_FONT_NAME;
      }
      // Add in san-serif as a fallback.
      fontName = fontName + ", san-serif";

      int fontSize = ColorAndFontConstants.BITHER_DEFAULT_FONT_SIZE;
      boolean isItalic = false;
      boolean isBold = false;
      Font adjustedFont = FontSizer.INSTANCE.getAdjustedDefaultFont();
      if (adjustedFont != null) {
        setFont(adjustedFont);
        fontSize = adjustedFont.getSize();
        isItalic = adjustedFont.isItalic();
        isBold = adjustedFont.isBold();
      }

      String fontCSS = "font-size:" + fontSize + "pt; font-family:" + fontName + ";";
      if (isItalic) {
        fontCSS = fontCSS + "font-style:italic;";
      } else {
        fontCSS = fontCSS + "font-style:normal;";
      }
      if (isBold) {
        fontCSS = fontCSS + "font-weight:bold;";
      } else {
        fontCSS = fontCSS + "font-weight:normal;";
      }

      HTMLEditorKit kit = new HTMLEditorKit();
      setEditorKit(kit);
      javax.swing.text.html.StyleSheet styleSheet = kit.getStyleSheet();
      styleSheet.addRule("body {" + fontCSS + "}");
      Document doc = kit.createDefaultDocument();
      setDocument(doc);

      log.debug("Trying to load '" + currentHref + "'...");
    } catch (Exception ex) {
      showUnableToLoadMessage(ex.getClass().getCanonicalName() + " " + ex.getMessage());
    }
  }
Exemplo n.º 2
0
 /** @see Object#toString() */
 public String toString() {
   return "[Font Data face='"
       + getName()
       + "' size="
       + size
       + " bold="
       + javaFont.isBold()
       + " italic="
       + javaFont.isItalic()
       + "]";
 }
  protected void build() {
    jepMessage = new JEditorPane("text/html", "");
    jepMessage.setOpaque(false);
    jepMessage.setEditable(false);
    jepMessage.addHyperlinkListener(this);
    Font f = UIManager.getFont("Label.font");
    StyleSheet ss = new StyleSheet();
    String rule =
        MessageFormat.format(
            "font-family: ''{0}'';font-size: {1,number}pt; font-weight: {2}; font-style: {3}",
            f.getName(),
            f.getSize(),
            f.isBold() ? "bold" : "normal",
            f.isItalic() ? "italic" : "normal");
    rule = "body {" + rule + "}";
    rule =
        MessageFormat.format(
            "font-family: ''{0}'';font-size: {1,number}pt; font-weight: {2}; font-style: {3}",
            f.getName(), f.getSize(), "bold", f.isItalic() ? "italic" : "normal");
    rule = "strong {" + rule + "}";
    ss.addRule(rule);
    ss.addRule("a {text-decoration: underline; color: blue}");
    HTMLEditorKit kit = new HTMLEditorKit();
    kit.setStyleSheet(ss);
    jepMessage.setEditorKit(kit);

    setLayout(new BorderLayout());
    add(jepMessage, BorderLayout.CENTER);
    lblWarning = new JLabel("");
    lblWarning.setVisible(false);
    lblWarning.setIcon(ImageProvider.get("warning-small.png"));
    lblWarning.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JPanel pnl = new JPanel(new BorderLayout());
    pnl.add(lblWarning, BorderLayout.NORTH);
    add(pnl, BorderLayout.WEST);
  }
Exemplo n.º 4
0
  /**
   * Update the font in the default style of the document.
   *
   * @param font the new font to use or null to remove the font attribute from the document's style
   */
  private void updateFont(Font font) {
    StyledDocument doc = (StyledDocument) getComponent().getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);

    if (style == null) {
      return;
    }

    if (font == null) {
      style.removeAttribute(StyleConstants.FontFamily);
      style.removeAttribute(StyleConstants.FontSize);
      style.removeAttribute(StyleConstants.Bold);
      style.removeAttribute(StyleConstants.Italic);
    } else {
      StyleConstants.setFontFamily(style, font.getName());
      StyleConstants.setFontSize(style, font.getSize());
      StyleConstants.setBold(style, font.isBold());
      StyleConstants.setItalic(style, font.isItalic());
    }
  }
Exemplo n.º 5
0
 /**
  * Sets the font of the specified attribute.
  *
  * @param attr attribute to apply this font to
  * @param f the font to use
  */
 public static void setAttributeFont(MutableAttributeSet attr, Font f) {
   StyleConstants.setBold(attr, f.isBold());
   StyleConstants.setItalic(attr, f.isItalic());
   StyleConstants.setFontFamily(attr, f.getFamily());
   StyleConstants.setFontSize(attr, f.getSize());
 }