Ejemplo 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());
    }
  }
Ejemplo n.º 2
0
  /** @see javax.swing.JPanel#updateUI() */
  @Override
  public void updateUI() {
    super.updateUI();

    if (feedItemDetail != null) {
      Font font = UIManager.getFont("Label.font");

      HTMLEditorKit kit = (HTMLEditorKit) feedItemDetail.getEditorKit();
      StyleSheet sheet = kit.getStyleSheet();
      sheet.addRule(
          "body {font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt;}");
    }
  }
Ejemplo n.º 3
0
 public Commentary(VisPanel panel, JScrollPane sp) {
   super();
   this.panel = panel;
   setContentType("text/html; charset=iso-8859-2");
   setEditable(false);
   final Font font = UIManager.getFont("Label.font");
   final StyleSheet css = ((HTMLDocument) getDocument()).getStyleSheet();
   css.addRule(
       "body { font-family: "
           + font.getFamily()
           + "; "
           + "font-size: 12pt; margin: 10pt; margin-top: 0pt; "
           + "}");
   css.addRule(".step { margin-bottom: 5pt; }");
   css.addRule("ol { padding-left: 14px; margin: 0px; }");
   css.addRule("a { color: black; text-decoration:none; }");
   css.addRule("p.note { font-style: italic; margin: 0pt; margin-bottom: 5pt; }");
   this.sp = sp;
   Languages.addListener(this);
   addHyperlinkListener(this);
   setText("<html><body></body></html>");
 }
Ejemplo n.º 4
0
  /**
   * Apply a new font for the label.
   *
   * @param font new font to use.
   */
  public void setFont(Font font) {
    getLabel().setFont(font); // Set font so that getFont can be used direclty

    // Set the properties to the text (only for text label not for HTML or MATHML)
    if ((labelText != null)
        && !(labelText.startsWith(DOLLAR) && labelText.endsWith(DOLLAR))
        && !(labelText.startsWith("<") && labelText.endsWith(">"))) {
      // Now set the stylesheet because of text/html contents
      StyleSheet styleSheet = ((HTMLDocument) getLabel().getDocument()).getStyleSheet();
      styleSheet.addRule("body {font-family:" + font.getName() + ";}");
      styleSheet.addRule("body {font-size:" + font.getSize() + "pt;}");
      if (font.isBold()) {
        styleSheet.addRule("body {font-weight:bold;}");
      } else {
        styleSheet.addRule("body {font-weight:normal;}");
      }
      if (font.isItalic()) {
        styleSheet.addRule("body {font-style:italic;}");
      } else {
        styleSheet.addRule("body {font-style:normal;}");
      }
    }
  }
Ejemplo n.º 5
0
  public Details(EventBus bus, Explorer controller) {
    super();

    this.controller = controller;

    setEditable(false);
    setContentType(HTML_MIME_TYPE);
    setText(INITIAL_CONTENT_HTML);
    HTMLEditorKit kit = (HTMLEditorKit) getEditorKitForContentType(HTML_MIME_TYPE);
    StyleSheet css = kit.getStyleSheet();
    for (String rule : CSS_RULES) {
      css.addRule(rule);
    }

    bus.register(this);
  }
Ejemplo n.º 6
0
  public TableFeedBody() {
    this.setOrientation(JSplitPane.VERTICAL_SPLIT);
    this.setOneTouchExpandable(false);
    this.setContinuousLayout(true);
    // the top component (the list) takes the extra space
    this.setResizeWeight(1);

    JScrollPane scroll = new JScrollPane();
    feedTable = new JTable();
    feedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    feedTable.setRowSelectionAllowed(true);
    feedTable.changeSelection(0, 0, false, false);
    feedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    feedTable.addMouseListener(this);
    feedTable.setRowHeight(25);
    feedTable.addKeyListener(this);
    scroll.setViewportView(feedTable);

    this.setTopComponent(scroll);

    feedItemDetail = new JEditorPane();
    feedItemDetail.setContentType("text/html");
    feedItemDetail.addHyperlinkListener(this);
    feedItemDetail.setBackground(Color.WHITE);
    feedItemDetail.setEditable(false);
    HTMLEditorKit kit = (HTMLEditorKit) feedItemDetail.getEditorKit();
    StyleSheet sheet = kit.getStyleSheet();
    Font font = UIManager.getFont("Label.font");
    sheet.addRule(
        "body {font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt;}");

    JScrollPane detailScroll = new JScrollPane();
    Dimension minDetailSize = detailScroll.getMinimumSize();
    minDetailSize.height = 100;
    detailScroll.setMinimumSize(minDetailSize);
    Dimension prefDetailSize = detailScroll.getPreferredSize();
    prefDetailSize.height = 200;
    detailScroll.setPreferredSize(prefDetailSize);
    detailScroll.setViewportView(feedItemDetail);

    this.setBottomComponent(detailScroll);

    this.setDividerSize(2);
    this.setDividerLocation(-1);
  }
Ejemplo n.º 7
0
  private MainPanel() {
    super(new GridLayout(3, 1));
    add(makePanel("Default", HREF));

    // [Customize detault html link color in java swing - Stack Overflow]
    // http://stackoverflow.com/questions/26749495/customize-detault-html-link-color-in-java-swing
    HTMLEditorKit kit = new HTMLEditorKit();
    StyleSheet styleSheet = kit.getStyleSheet();
    styleSheet.addRule("a{color:#FF0000;}");
    add(makePanel("styleSheet.addRule(\"a{color:#FF0000;}\")", HREF));

    add(
        makePanel(
            "<a style='color:#00FF00'...",
            "<html><a style='color:#00FF00' href='" + MYSITE + "'>" + MYSITE + "</a>"));

    setPreferredSize(new Dimension(320, 240));
  }
Ejemplo n.º 8
0
 private void updateStyle(@NotNull JEditorPane pane) {
   EditorKit kit = pane.getEditorKit();
   if (kit instanceof HTMLEditorKit) {
     StyleSheet css = ((HTMLEditorKit) kit).getStyleSheet();
     css.addRule(
         "body, p {"
             + "color:#"
             + ColorUtil.toHex(getForeground())
             + ";"
             + "font-family:"
             + getFont().getFamily()
             + ";"
             + "font-size:"
             + getFont().getSize()
             + "pt;"
             + "white-space:nowrap;}");
   }
 }
Ejemplo n.º 9
0
 /**
  * Builds the style sheet used in the internal help browser
  *
  * @return the style sheet
  */
 protected StyleSheet buildStyleSheet() {
   StyleSheet ss = new StyleSheet();
   BufferedReader reader =
       new BufferedReader(
           new InputStreamReader(getClass().getResourceAsStream("/data/help-browser.css")));
   StringBuffer css = new StringBuffer();
   try {
     String line = null;
     while ((line = reader.readLine()) != null) {
       css.append(line);
       css.append("\n");
     }
   } catch (Exception e) {
     Main.error(
         tr("Failed to read CSS file ''help-browser.css''. Exception is: {0}", e.toString()));
     e.printStackTrace();
     return ss;
   } finally {
     Utils.close(reader);
   }
   ss.addRule(css.toString());
   return ss;
 }
 private static void adjustFontSize(StyleSheet styleSheet) {
   int size = (int) UIUtil.getFontSize(UIUtil.FontSize.MINI);
   styleSheet.addRule(TIP_HTML_TEXT_TAGS + " {font-size: " + size + "px;}");
 }
Ejemplo n.º 11
0
 /**
  * This method initializes jEditorPane
  *
  * @return javax.swing.JEditorPane
  */
 protected JEditorPane getResultPane() {
   if (resultPane == null) {
     HTMLEditorKit kit = new HTMLEditorKit();
     resultPane = new JEditorPane();
     resultPane.setEditable(false);
     resultPane.setContentType("text/html");
     resultPane.addHyperlinkListener(new RecognitionHyperlinkListener());
     resultPane.setCaretPosition(0);
     resultPane.setEditorKit(kit);
     StyleSheet styleSheet = kit.getStyleSheet();
     styleSheet.addRule("table{border-width: 1px;}");
     styleSheet.addRule("table{border-style: solid;}");
     styleSheet.addRule("table{border-color: gray;}");
     styleSheet.addRule("table{border-spacing: 0x;}");
     styleSheet.addRule("table{width: 100%;}");
     styleSheet.addRule("th {border-width: 1px;}");
     styleSheet.addRule("th {border-style: solid;}");
     styleSheet.addRule("th {border-color: gray;}");
     styleSheet.addRule("th {padding: 5px;}");
     styleSheet.addRule("td {border-width: 1px;}");
     styleSheet.addRule("td.selected {background-color: gray;color: black;}");
     styleSheet.addRule("td {border-style: solid;}");
     styleSheet.addRule("td {color: gray;}");
     styleSheet.addRule("td {padding: 5px;}");
     styleSheet.addRule("div {width: 100%;}");
     styleSheet.addRule("div {position: absolute;}");
     styleSheet.addRule("div {text-align: center;}");
     styleSheet.addRule("div {padding: 5px;}");
   }
   return resultPane;
 }