public void showItem() {

    if (!this.editorPanel.getViewer().isLanguageFunctionAvailable()) {

      return;
    }

    this.highlight =
        this.editorPanel
            .getEditor()
            .addHighlight(this.position, this.position + this.word.length(), null, true);

    final FindSynonymsActionHandler _this = this;

    QTextEditor editor = this.editorPanel.getEditor();

    Rectangle r = null;

    try {

      r = editor.modelToView(this.position);

    } catch (Exception e) {

      // BadLocationException!
      Environment.logError("Location: " + this.position + " is not valid", e);

      UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

      return;
    }

    int y = r.y;

    // Show a panel of all the items.
    final QPopup p = this.popup;

    p.setOpaque(false);

    Synonyms syns = null;

    try {

      syns = this.projectViewer.getSynonymProvider().getSynonyms(this.word);

    } catch (Exception e) {

      UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

      Environment.logError("Unable to lookup synonyms for: " + word, e);

      return;
    }

    if ((syns.words.size() == 0) && (this.word.toLowerCase().endsWith("ed"))) {

      // Trim off the ed and try again.
      try {

        syns = this.projectViewer.getSynonyms(this.word.substring(0, this.word.length() - 2));

      } catch (Exception e) {

        UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

        Environment.logError("Unable to lookup synonyms for: " + word, e);

        return;
      }
    }

    if ((syns.words.size() == 0) && (this.word.toLowerCase().endsWith("s"))) {

      // Trim off the ed and try again.
      try {

        syns = this.projectViewer.getSynonyms(this.word.substring(0, this.word.length() - 1));

      } catch (Exception e) {

        UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

        Environment.logError("Unable to lookup synonyms for: " + word, e);

        return;
      }
    }

    StringBuilder sb = new StringBuilder();

    if (syns.words.size() > 0) {

      sb.append("6px");

      for (int i = 0; i < syns.words.size(); i++) {

        if (sb.length() > 0) {

          sb.append(", ");
        }

        sb.append("p, 3px, [p,90px], 5px");
      }
      /*
                if (syns.words.size () > 0)
                {

                    sb.append (",5px");

                }
      */
    } else {

      sb.append("6px, p, 6px");
    }

    FormLayout summOnly = new FormLayout("3px, fill:380px:grow, 3px", sb.toString());
    PanelBuilder pb = new PanelBuilder(summOnly);

    CellConstraints cc = new CellConstraints();

    int ind = 2;

    Map<String, String> names = new HashMap();
    names.put(Synonyms.ADJECTIVE + "", "Adjectives");
    names.put(Synonyms.NOUN + "", "Nouns");
    names.put(Synonyms.VERB + "", "Verbs");
    names.put(Synonyms.ADVERB + "", "Adverbs");
    names.put(Synonyms.OTHER + "", "Other");

    if (syns.words.size() == 0) {

      JLabel l = new JLabel("No synonyms found.");
      l.setFont(l.getFont().deriveFont(Font.ITALIC));

      pb.add(l, cc.xy(2, 2));
    }

    // Determine what type of word we are looking for.
    for (Synonyms.Part i : syns.words) {

      JLabel l = new JLabel(names.get(i.type + ""));

      l.setFont(l.getFont().deriveFont(Font.ITALIC));
      l.setFont(l.getFont().deriveFont((float) UIUtils.getEditorFontSize(10)));
      l.setBorder(
          new CompoundBorder(
              new MatteBorder(0, 0, 1, 0, Environment.getBorderColor()),
              new EmptyBorder(0, 0, 3, 0)));

      pb.add(l, cc.xy(2, ind));

      ind += 2;

      HTMLEditorKit kit = new HTMLEditorKit();
      HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();

      JTextPane t = new JTextPane(doc);
      t.setEditorKit(kit);
      t.setEditable(false);
      t.setOpaque(false);

      StringBuilder buf =
          new StringBuilder(
              "<style>a { text-decoration: none; } a:hover { text-decoration: underline; }</style><span style='color: #000000; font-size: "
                  + ((int) UIUtils.getEditorFontSize(10) /*t.getFont ().getSize () + 2*/)
                  + "pt; font-family: "
                  + t.getFont().getFontName()
                  + ";'>");

      for (int x = 0; x < i.words.size(); x++) {

        String w = (String) i.words.get(x);

        buf.append("<a class='x' href='http://" + w + "'>" + w + "</a>");

        if (x < (i.words.size() - 1)) {

          buf.append(", ");
        }
      }

      buf.append("</span>");

      t.setText(buf.toString());

      t.addHyperlinkListener(
          new HyperlinkAdapter() {

            public void hyperlinkUpdate(HyperlinkEvent ev) {

              if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {

                QTextEditor ed = _this.editorPanel.getEditor();

                ed.replaceText(
                    _this.position, _this.position + _this.word.length(), ev.getURL().getHost());

                ed.removeHighlight(_this.highlight);

                _this.popup.setVisible(false);

                _this.projectViewer.fireProjectEvent(
                    ProjectEvent.SYNONYM, ProjectEvent.REPLACE, ev.getURL().getHost());
              }
            }
          });

      // Annoying that we have to do this but it prevents the text from being too small.

      t.setSize(new Dimension(380, Short.MAX_VALUE));

      JScrollPane sp = new JScrollPane(t);

      t.setCaretPosition(0);

      sp.setOpaque(false);
      sp.getVerticalScrollBar().setValue(0);
      /*
                  sp.setPreferredSize (t.getPreferredSize ());
                  sp.setMaximumSize (new Dimension (380,
                                                    75));
      */
      sp.getViewport().setOpaque(false);
      sp.setOpaque(false);
      sp.setBorder(null);
      sp.getViewport().setBackground(Color.WHITE);
      sp.setAlignmentX(Component.LEFT_ALIGNMENT);

      pb.add(sp, cc.xy(2, ind));

      ind += 2;
    }

    JPanel pan = pb.getPanel();
    pan.setOpaque(true);
    pan.setBackground(Color.WHITE);

    this.popup.setContent(pan);

    // r.y -= this.editorPanel.getScrollPane ().getVerticalScrollBar ().getValue ();

    Point po = SwingUtilities.convertPoint(editor, r.x, r.y, this.editorPanel);

    r.x = po.x;
    r.y = po.y;

    // Subtract the insets of the editorPanel.
    Insets ins = this.editorPanel.getInsets();

    r.x -= ins.left;
    r.y -= ins.top;

    this.editorPanel.showPopupAt(this.popup, r, "above", true);
  }
 public void resetDocument() {
   if (document != null) document.removeUndoableEditListener(view.getUndoListener());
   HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
   document = (HTMLDocument) htmlEditorKit.createDefaultDocument();
   document.addUndoableEditListener(view.getUndoListener());
   view.update();
 }
 /**
  * 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;
 }
Example #4
0
    public void textual() {
      if (!isVisible()) return;
      // create jeditorpane
      JEditorPane jEditorPane = new JEditorPane();

      // make it read-only
      jEditorPane.setEditable(false);

      // create a scrollpane; modify its attributes as desired
      JScrollPane scrollPane = new JScrollPane(jEditorPane);

      // add an html editor kit
      HTMLEditorKit kit = new HTMLEditorKit();
      jEditorPane.setEditorKit(kit);
      Document doc = kit.createDefaultDocument();
      jEditorPane.setDocument(doc);
      jEditorPane.setText(floater.getText());

      // now add it all to a frame
      JFrame j = new JFrame("Read information");
      j.getContentPane().add(scrollPane, BorderLayout.CENTER);

      // make it easy to close the application
      j.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

      // display the frame
      j.setSize(new Dimension(300, 200));

      // pack it, if you prefer
      // j.pack();

      // center the jframe, then make it visible
      j.setLocationRelativeTo(null);
      j.setVisible(true);
    }
  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());
    }
  }
 private void appendMsg(String msg) {
   HTMLDocument doc = (HTMLDocument) textArea.getDocument();
   HTMLEditorKit kit = (HTMLEditorKit) textArea.getEditorKit();
   try {
     kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);
   } catch (Exception e) {
     Debug.error(me + "Problem appending text to message area!\n%s", e.getMessage());
   }
 }
 public void setPlainText(String text) {
   try {
     resetDocument();
     StringReader stringReader = new StringReader(text);
     HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
     htmlEditorKit.read(stringReader, document, 0);
   } catch (Exception e) {
     ExceptionHandler.log(e);
   }
 }
  private void initDebugTextPane() {
    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
    HTMLDocument htmlDocument = new HTMLDocument();

    debugTextPane.setEditable(false);
    debugTextPane.setBackground(Color.WHITE);
    debugTextPane.setEditorKit(htmlEditorKit);
    htmlEditorKit.install(debugTextPane);
    debugTextPane.setDocument(htmlDocument);
  }
 public static void clearAll(JEditorPane txt) {
   try {
     txt.setText("");
     HTMLEditorKit kit = (HTMLEditorKit) txt.getEditorKit();
     HTMLDocument doc = (HTMLDocument) txt.getDocument();
     kit.insertHTML(
         doc, 0, "<body style=\"font-family:'Courier New';font-size: 12pt;\">", 0, 0, null);
   } catch (Exception e) {
   }
 }
  public String getPlainText() {

    try {
      StringWriter stringWriter = new StringWriter();
      HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
      htmlEditorKit.write(stringWriter, document, 0, document.getLength());
      return stringWriter.toString();
    } catch (Exception e) {
      ExceptionHandler.log(e);
    }
    return null;
  }
Example #11
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;}");
    }
  }
Example #12
0
  public void updateCtx(List<RecognitionResult> results) {

    HTMLEditorKit kit = ((HTMLEditorKit) getResultPane().getEditorKit());
    //        StyleSheet styleSheet = kit.getStyleSheet();

    Document doc = kit.createDefaultDocument();
    getResultPane().setDocument(doc);
    getResultPane()
        .setText("<html><body>" + "<p>" + representResults(results) + "</p></body></html>");
    getResultPane().setCaretPosition(0);

    this.results = results;
  }
Example #13
0
 protected void insert(String s, int offset) {
   try {
     HTMLEditorKit edKit = (HTMLEditorKit) getEditorKit();
     //    ((HTMLDocument)getDocument()).insertString(offset,"\n",null);
     edKit.insertHTML((HTMLDocument) getDocument(), offset, "<BR>\n" + s, 0, 0, HTML.Tag.BR);
     //    HTMLEditorKit.InsertHTMLTextAction("similarity",s,HTML.Tag.BODY,HTML.Tag.P);
   } catch (BadLocationException ble) {
     System.out.println("Offset " + offset);
     ble.printStackTrace();
   } catch (Exception exp) {
     exp.printStackTrace();
   }
 }
 @Override
 protected void process(final List<String> chunks) {
   // Updates the messages text area
   try {
     HTMLEditorKit kit = (HTMLEditorKit) messagesTextArea.getEditorKit();
     HTMLDocument doc = (HTMLDocument) messagesTextArea.getDocument();
     for (final String string : chunks) {
       kit.insertHTML(doc, messagesTextArea.getCaretPosition(), string + "<br>", 0, 0, null);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #15
0
  private void initHtmlFromFile(String fileName) {
    try {
      FileInputStream fileS = new FileInputStream(fileName);
      HTMLEditorKit kit = new HTMLEditorKit();

      htmlDoc = (HTMLDocument) kit.createDefaultDocument();
      Reader HTMLReader = new InputStreamReader(fileS, "UTF-8");
      htmlDoc.putProperty("IgnoreCharsetDirective", new Boolean(true));
      kit.read(HTMLReader, htmlDoc, 0);

    } catch (Exception e) {
      logger.error("", e);
    }
  }
Example #16
0
    public void appendArchive(String s) {
      HTMLEditorKit editor = (HTMLEditorKit) archivePane.getEditorKit();
      StringReader reader = new StringReader(s);

      try {
        editor.read(reader, archivePane.getDocument(), archivePane.getDocument().getLength());
      } catch (BadLocationException ex) {
        // This happens if your offset is out of bounds.
        System.out.println(ex);
      } catch (IOException ex) {
        // I/O error
        System.out.println(ex);
      }
    }
 private static void appendHTML(JEditorPane editor, String html) {
   try {
     html = StringUtil.replaceAll(html, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
     html = StringUtil.replaceAll(html, "\r\n", "\n");
     html = StringUtil.replaceAll(html, "\r", "");
     Vector vt = StringUtil.toStringVector(html, "\n");
     HTMLEditorKit kit = (HTMLEditorKit) editor.getEditorKit();
     HTMLDocument doc = (HTMLDocument) editor.getDocument();
     for (int iIndex = 0; iIndex < vt.size(); iIndex++)
       kit.insertHTML(doc, doc.getLength(), (String) vt.elementAt(iIndex), 0, 0, null);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #18
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);
  }
Example #19
0
  public void toChatScreen(String toScreen, boolean selfSeen)
      throws IOException, BadLocationException {
    // Timestamp ts = new Timestamp();
    String toScreenFinal = "";
    Date now = Calendar.getInstance().getTime();
    SimpleDateFormat format = new SimpleDateFormat("hh:mm");
    String ts = format.format(now);

    // chatScreen.append(ts + " " + toScreen + "\n");
    toScreenFinal = "<font color=gray>" + ts + "</font> ";
    if (selfSeen) toScreenFinal = toScreenFinal + "<font color=red>" + toScreen + "</font>";
    else toScreenFinal = toScreenFinal + toScreen;

    // chatter.addTo(toScreen);

    // if(standardWindow) {
    //    chatScreen.setCaretPosition(chatScreen.getDocument().getLength());
    // }
    // else {
    JScrollBar vBar = scrollChat.getVerticalScrollBar();
    int vSize = vBar.getVisibleAmount();
    int maxVBar = vBar.getMaximum();
    int currVBar = vBar.getValue() + vSize;
    kit.insertHTML(doc, doc.getLength(), toScreenFinal, 0, 0, null);
    if (maxVBar == currVBar) {
      chatScreen.setCaretPosition(chatScreen.getDocument().getLength());
    }

    // }

    // kit.insertHTML(doc, doc.getLength(), toScreenFinal, 0, 0, null);

  }
  public void install(JEditorPane c) {
    MouseListener[] oldMouseListeners = c.getMouseListeners();
    MouseMotionListener[] oldMouseMotionListeners = c.getMouseMotionListeners();
    super.install(c);
    // the following code removes link handler added by original
    // HTMLEditorKit

    for (MouseListener l : c.getMouseListeners()) {
      c.removeMouseListener(l);
    }
    for (MouseListener l : oldMouseListeners) {
      c.addMouseListener(l);
    }

    for (MouseMotionListener l : c.getMouseMotionListeners()) {
      c.removeMouseMotionListener(l);
    }
    for (MouseMotionListener l : oldMouseMotionListeners) {
      c.addMouseMotionListener(l);
    }

    // add out link handler instead of removed one
    c.addMouseListener(handler);
    c.addMouseMotionListener(handler);
  }
Example #21
0
 @Override
 public void writeSource(String x) {
   try {
     htmlKit.insertHTML(htmlDoc, htmlDoc.getLength(), x, 0, 0, null);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #22
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);
  }
Example #23
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;
 }
Example #25
0
  private void initHtmlFromStringList(List<String> buff) {
    String htmlText = "";
    for (String str : buff) htmlText += str;

    try {
      InputStream is = new ByteArrayInputStream(htmlText.getBytes("UTF-8"));
      HTMLEditorKit kit = new HTMLEditorKit();
      htmlDoc = (HTMLDocument) kit.createDefaultDocument();
      Reader HTMLReader = new InputStreamReader(is, "UTF-8");
      htmlDoc.putProperty("IgnoreCharsetDirective", new Boolean(true));
      kit.read(HTMLReader, htmlDoc, 0);
      // printProps();

    } catch (UnsupportedEncodingException uee) {
      logger.error("", uee);
    } catch (Exception e) {
      logger.error("", e);
    }
  }
Example #26
0
 private void addHTML(String html) {
   synchronized (kit) {
     try {
       kit.insertHTML(doc, doc.getLength(), html, 0, 0, null);
     } catch (BadLocationException | IOException ignored) {
       Logger.logError(ignored.getMessage(), ignored);
     }
     displayArea.setCaretPosition(displayArea.getDocument().getLength());
   }
 }
Example #27
0
 @Override
 public void write(int b) throws IOException {
   try {
     htmlKit.insertHTML(
         htmlDoc, htmlDoc.getLength(), new String(new byte[] {(byte) b}), 0, 0, null);
   } catch (BadLocationException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Example #28
0
 public void ClearLog() {
   try {
     doc.replace(0, doc.getLength(), "", null);
     kit.insertHTML(doc, 0, "", 0, 0, null);
   } catch (BadLocationException e) {
     // TODO Auto-generated catch block
     // e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     // e.printStackTrace();
   }
 }
Example #29
0
 // appends a message to the log tab and system out.
 public void Log(String msg) {
   try {
     kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);
     int over_length = doc.getLength() - msg.length() - 5000;
     doc.remove(0, over_length);
   } catch (BadLocationException e) {
     // TODO Auto-generated catch block
     // e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     // e.printStackTrace();
   }
 }
 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());
 }