Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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));
  }
 @Override
 public Component getPreferencesDecorationPanel() {
   HtmlPanel pnlMessage = new HtmlPanel();
   HTMLEditorKit kit = (HTMLEditorKit) pnlMessage.getEditorPane().getEditorKit();
   kit.getStyleSheet()
       .addRule(
           ".warning-body {background-color:rgb(253,255,221);padding: 10pt; border-color:rgb(128,128,128);border-style: solid;border-width: 1px;}");
   pnlMessage.setText(
       tr(
           "<html><body>"
               + "<p class=\"warning-body\">"
               + "<strong>Warning:</strong> The password is stored in plain text in the JOSM preferences file. "
               + "Furthermore, it is transferred <strong>unencrypted</strong> in every request sent to the OSM server. "
               + "<strong>Do not use a valuable password.</strong>"
               + "</p>"
               + "</body></html>"));
   return pnlMessage;
 }
Ejemplo n.º 8
0
 void loadHTMLContent(String shortUrl) {
   try {
     StyleSheet style = htmlKit.getStyleSheet();
     BufferedReader r =
         new BufferedReader(
             new InputStreamReader(
                 peer.getFileInputStream("assets/ExhibitContents/exhibits.css")));
     style.loadRules(r, null);
   } catch (Exception e) {
     // TODO do the try block differently if css has been modified.
   }
   InputStream r =
       peer.getFileInputStream("assets/" + shortUrl); // TODO do differently if modified
   StringBuffer sb = new StringBuffer(128);
   try {
     byte[] buffer = new byte[128];
     for (int result = r.read(buffer); result != -1; result = r.read(buffer)) {
       sb.append(new String(buffer, 0, result));
     }
   } catch (IOException e) {
   }
   htmlContentViewer.setText(sb.toString());
 }
Ejemplo n.º 9
0
 public void addCSSEntry(String entry) {
   // For example: addCSSEntry("body {color:#000; font-family:times; margin: 4px; }")
   htmlKit.getStyleSheet().addRule(entry);
 }
Ejemplo n.º 10
0
  HtmlPanel(final Map<String, Action> actions, HtmlPage page) throws IOException {
    super(new BorderLayout());

    this.actions = actions;
    textPane = new JTextPane();
    find = new JTextField();
    matches = new JLabel();
    this.page = null;

    final Dimension d = matches.getPreferredSize();
    matches.setPreferredSize(new Dimension(100, d.height));

    textPane.setEditable(false);
    textPane.setFocusable(false);
    textPane.addHyperlinkListener(
        new HyperlinkListener() {

          public final void hyperlinkUpdate(HyperlinkEvent ev) {
            if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              final JEditorPane pane = (JEditorPane) ev.getSource();
              if (ev instanceof HTMLFrameHyperlinkEvent) {
                final HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) ev;
                final HTMLDocument doc = (HTMLDocument) pane.getDocument();
                doc.processHTMLFrameHyperlinkEvent(evt);
              } else if (Desktop.isDesktopSupported())
                try {
                  Desktop.getDesktop().browse(ev.getURL().toURI());
                } catch (final Exception e) {
                  e.printStackTrace();
                }
            }
          }
        });

    final HTMLEditorKit kit =
        new HTMLEditorKit() {
          private static final long serialVersionUID = 1L;

          @Override
          public final Document createDefaultDocument() {
            final HTMLDocument doc = (HTMLDocument) super.createDefaultDocument();
            // Load synchronously.
            doc.setAsynchronousLoadPriority(-1);
            return doc;
          }
        };

    final StyleSheet styleSheet = kit.getStyleSheet();
    final InputStream is = getClass().getResourceAsStream("/doogal.css");
    try {
      styleSheet.loadRules(newBufferedReader(is), null);
    } finally {
      is.close();
    }

    textPane.setEditorKit(kit);

    final Document doc = kit.createDefaultDocument();
    textPane.setDocument(doc);
    textPane.addMouseListener(
        new MouseAdapter() {

          private final void showPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
              final JPopupMenu menu = newPopupMenu(TableType.DOCUMENT, actions);
              if (null != menu) menu.show(e.getComponent(), e.getX(), e.getY());
            }
          }

          @Override
          public final void mousePressed(MouseEvent e) {
            showPopup(e);
          }

          @Override
          public final void mouseReleased(MouseEvent e) {
            showPopup(e);
          }
        });
    find.setColumns(16);
    find.setFont(new Font("Dialog", Font.PLAIN, TINY_FONT));
    find.setMargin(new Insets(2, 2, 2, 2));
    find.addActionListener(
        new ActionListener() {
          public final void actionPerformed(ActionEvent ev) {
            find(find.getText());
          }
        });

    final JLabel label = new JLabel("Quick Find: ");
    label.setLabelFor(find);

    final JButton clear = new JButton("Clear");
    clear.setMargin(new Insets(1, 5, 0, 5));
    clear.setFont(new Font("Dialog", Font.PLAIN, TINY_FONT));
    clear.addActionListener(
        new ActionListener() {
          public final void actionPerformed(ActionEvent e) {
            find.setText("");
            find("");
          }
        });

    final JPanel findPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    findPanel.add(label);
    findPanel.add(find);
    findPanel.add(clear);
    findPanel.add(matches);

    scrollPane =
        new JScrollPane(
            textPane,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setFocusable(false);
    final JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
    scrollBar.setBlockIncrement(scrollBar.getBlockIncrement() * 20);
    scrollBar.setUnitIncrement(scrollBar.getUnitIncrement() * 20);

    add(scrollPane, BorderLayout.CENTER);
    add(findPanel, BorderLayout.SOUTH);

    setPage(page);
  }