Package javax.swing.text.html

Examples of javax.swing.text.html.HTMLDocument


    Dimension preferredSize = tip.getPreferredSize();
    if (preferredSize.width < maximumWidth) {
      tip.setPreferredSize(preferredSize);
      return ;
    }
    final HTMLDocument document = (HTMLDocument) tip.getDocument();
    document.getStyleSheet().addRule("body { width: " + maximumWidth  + "}");
    // bad hack: call "setEditable" only to update view
    tip.setEditable(true);
    tip.setEditable(false);
    tip.setPreferredSize(tip.getPreferredSize());
  }
View Full Code Here


  @Override
  public Document createDefaultDocument() {
    StyleSheet styles = getStyleSheet();
    StyleSheet ss = new ScaledStyleSheet();
    ss.addStyleSheet(styles);
    HTMLDocument doc = new HTMLDocument(ss);
    doc.setParser(getParser());
    doc.setAsynchronousLoadPriority(4);
    doc.setTokenThreshold(100);
    return doc;
  }
View Full Code Here

   */
  Document createDefaultDocument(Font defaultFont, Color foreground) {
    StyleSheet styles = getStyleSheet();
    StyleSheet ss = new ScaledStyleSheet();
    ss.addStyleSheet(styles);
    HTMLDocument doc = new HTMLDocument(ss);
    doc.setPreservesUnknownTags(false);
    doc.getStyleSheet().addRule(displayPropertiesToCSS(defaultFont, foreground));
    doc.setParser(getParser());
    doc.setAsynchronousLoadPriority(Integer.MAX_VALUE);
    doc.setPreservesUnknownTags(false);
    return doc;
  }
View Full Code Here

  private void setLineWrap() {
    if(null != textfield.getClientProperty("EditNodeTextField.linewrap") || inputMethodInUseListener.isIMEInUse()){
      return;
    }
   
      final HTMLDocument document = (HTMLDocument) textfield.getDocument();
      document.getStyleSheet().addRule("body { width: " + (maxWidth - 1) + "}");
      // bad hack: call "setEditable" only to update view
      textfield.setEditable(false);
      textfield.setEditable(true);
      textfield.putClientProperty("EditNodeTextField.linewrap", true);
    }
View Full Code Here

    }
    ruleBuilder.append("color: ").append(ColorUtils.colorToString(nodeTextColor)).append(";");
      final Color bgColor = getBackground();
    ruleBuilder.append("background-color: ").append(ColorUtils.colorToString(bgColor)).append(";");
    ruleBuilder.append("}\n");
    final HTMLDocument document = (HTMLDocument) textfield.getDocument();
    final StyleSheet styleSheet = document.getStyleSheet();
    styleSheet.addRule(ruleBuilder.toString());
    textfield.setText(text);
    final MapView mapView = (MapView) viewController.getMapViewComponent();
    if(! mapView.isValid())
      mapView.validate();
    final NodeStyleController nsc = NodeStyleController.getController(modeController);
    maxWidth = nsc.getMaxWidth(node);
    final Icon icon = parent.getIcon();
    if(icon != null){
      maxWidth -= icon.getIconWidth();
      maxWidth -= parent.getIconTextGap();
    }
    maxWidth = mapView.getZoomed(maxWidth);
    extraWidth = ResourceController.getResourceController().getIntProperty("editor_extra_width", 80);
    extraWidth = mapView.getZoomed(extraWidth);
    final TextFieldListener textFieldListener = new TextFieldListener();
    this.textFieldListener = textFieldListener;
    textfield.addFocusListener(textFieldListener);
    textfield.addKeyListener(textFieldListener);
    textfield.addMouseListener(textFieldListener);
    mapViewChangeListener = new MapViewChangeListener();
    Controller.getCurrentController().getMapViewManager().addMapViewChangeListener(mapViewChangeListener);
    SpellCheckerController.getController().enableAutoSpell(textfield, true);
    mapView.scrollNodeToVisible(nodeView);
    assert( parent.isValid());
    final int nodeWidth = parent.getWidth();
    final int nodeHeight = parent.getHeight();
    final Dimension textFieldSize;
    textfield.setBorder(new MatteBorder(2, 2, 2, 2, nodeView.getSelectedColor()));
    textFieldSize = textfield.getPreferredSize();
    textFieldSize.width += 1;
        if(textFieldSize.width < extraWidth)
            textFieldSize.width = extraWidth;
        if(textFieldSize.width < 10)
            textFieldSize.width = 10;
    if (textFieldSize.width > maxWidth) {
      textFieldSize.width = maxWidth;
      setLineWrap();
      textFieldSize.height = textfield.getPreferredSize().height;
    }
    final Rectangle textR = ((ZoomableLabelUI)parent.getUI()).getTextR(parent);
    textFieldSize.width = Math.max(textFieldSize.width, textR.width);
    textFieldSize.height = Math.max(textFieldSize.height, textR.height);
    textfield.setSize(textFieldSize.width, textFieldSize.height);
    horizontalSpace = Math.max(nodeWidth - textFieldSize.width, textR.x);
    verticalSpace = Math.max(nodeHeight - textFieldSize.height, textR.y);
    final Dimension newParentSize = new Dimension(horizontalSpace + textFieldSize.width, verticalSpace + textFieldSize.height);
    parent.setPreferredSize(newParentSize);

    final Point location = new Point(textR.x - 2, textR.y);
    if(! layoutMapOnTextChange)
      UITools.convertPointToAncestor(parent, location, mapView);
    textfield.setBounds(location.x, location.y, textFieldSize.width, textFieldSize.height);
    parent.setText("");
        if(nodeView.isRoot() && parent instanceof MainView)
            parent.setHorizontalAlignment(JLabel.LEFT);
    if(layoutMapOnTextChange)
      parent.add(textfield, 0);
    else
      mapView.add(textfield, 0);
    final EventBuffer eventQueue = MTextController.getController().getEventQueue();
    KeyEvent firstEvent = eventQueue.getFirstEvent();
    redispatchKeyEvents(textfield, firstEvent);
    if (firstEvent == null) {
      MouseEvent currentEvent = eventQueue.getMouseEvent();
      int pos = document.getLength();
      if(currentEvent != null){
        MouseEvent mouseEvent = (MouseEvent) currentEvent;
        if(mouseEvent.getComponent().equals(parent)){
          final Point point = mouseEvent.getPoint();
          point.x -= textR.x;
          point.y -= textR.y;
          pos = textfield.viewToModel(point);
        }
      }
      textfield.setCaretPosition(pos);
    }
    document.addDocumentListener(documentListener);
    if(textController.isMinimized(node)){
      layout();
    }
    textfield.repaint();
    textfield.requestFocusInWindow();
View Full Code Here

            dot = getValidPosition(dot);
            super.setDot(fb, dot, bias);
        }

        private int getValidPosition(int position) {
          final HTMLDocument doc = (HTMLDocument) textfield.getDocument();
          if (doc.getDefaultRootElement().getElementCount() > 1) {
            final int startPos = doc.getDefaultRootElement().getElement(1).getStartOffset();
            final int validPosition = Math.max(position, startPos);
            return validPosition;
          }
          return position;
        }
View Full Code Here

    }
    final SHTMLPanel noteViewerComponent = noteController.getNoteViewerComponent();
    if (noteViewerComponent == null) {
      return;
    }
    final HTMLDocument document = noteViewerComponent.getDocument();
    document.removeDocumentListener(mNoteDocumentListener);
    try {
      final URL url = node.getMap().getURL();
      if (url != null) {
        document.setBase(url);
      }
      else {
        document.setBase(new URL("file: "));
      }
    }
    catch (final Exception e) {
    }
    noteController.setDefaultFont();
    final String note = node != null ? NoteModel.getNoteText(node) : null;
    if (note != null) {
      noteViewerComponent.setCurrentDocumentContent(note);
      noteController.setLastContentEmpty(false);
    }
    else if (!noteController.isLastContentEmpty()) {
      noteViewerComponent.setCurrentDocumentContent("");
      noteController.setLastContentEmpty(true);
    }
    document.addDocumentListener(mNoteDocumentListener);
  }
View Full Code Here

  private String[] splitNode(final String text) {
    if (text.startsWith("<html>")) {
      String[] parts = null;
      final HTMLEditorKit kit = new HTMLEditorKit();
      final HTMLDocument doc = new HTMLDocument();
      final StringReader buf = new StringReader(text);
      try {
        kit.read(buf, doc, 0);
        final Element parent = getParentElement(doc);
        if (parent == null) {
          return null;
        }
        final int elementCount = parent.getElementCount();
        int notEmptyElementCount = 0;
        parts = new String[elementCount];
        for (int i = 0; i < elementCount; i++) {
          final Element current = parent.getElement(i);
          final int start = current.getStartOffset();
          final int end = current.getEndOffset();
          final String paragraphText = doc.getText(start, end - start).trim();
          if (paragraphText.length() > 0) {
            final StringWriter out = new StringWriter();
            new FixedHTMLWriter(out, doc, start, end - start).write();
            final String string = out.toString();
            if (!string.equals("")) {
View Full Code Here

        ruleBuilder.append("color: ").append(ColorUtils.colorToString(textColor)).append(";");
        final Color bgColor = getBackground();
      ruleBuilder.append("background-color: ").append(ColorUtils.colorToString(bgColor)).append(";");
      ruleBuilder.append("}\n");
      ruleBuilder.append("p {margin-top:0;}\n");
      final HTMLDocument document = htmlEditorPanel.getDocument();
      final JEditorPane editorPane = htmlEditorPanel.getEditorPane();
      if(textColor != null){
        editorPane.setForeground(textColor);
        editorPane.setCaretColor(textColor);
      }
      final StyleSheet styleSheet = document.getStyleSheet();
      styleSheet.removeStyle("p");
      styleSheet.removeStyle("body");
      styleSheet.addRule(ruleBuilder.toString());
      final URL url = node.getMap().getURL();
      if (url != null) {
        document.setBase(url);
      }
      else {
        document.setBase(new URL("file: "));
      }
      htmlEditorPanel.setContentPanePreferredSize(preferredSize);
      htmlEditorWindow.getDialog().pack();
      if (ResourceController.getResourceController().getBooleanProperty("el__position_window_below_node")) {
        UITools.setDialogLocationUnder(htmlEditorWindow.getDialog(), node);
View Full Code Here

      return null;
    }
    final String[] strings = new String[2];
    if (text.startsWith("<html>")) {
      final HTMLEditorKit kit = new HTMLEditorKit();
      final HTMLDocument doc = new HTMLDocument();
      final StringReader buf = new StringReader(text);
      try {
        kit.read(buf, doc, 0);
        final char[] firstText = doc.getText(0, pos).toCharArray();
        int firstStart = 0;
        int firstLen = pos;
        while ((firstStart < firstLen) && (firstText[firstStart] <= ' ')) {
          firstStart++;
        }
        while ((firstStart < firstLen) && (firstText[firstLen - 1] <= ' ')) {
          firstLen--;
        }
        int secondStart = 0;
        int secondLen = doc.getLength() - pos;
        if(secondLen <= 0)
          return null;
        final char[] secondText = doc.getText(pos, secondLen).toCharArray();
        while ((secondStart < secondLen) && (secondText[secondStart] <= ' ')) {
          secondStart++;
        }
        while ((secondStart < secondLen) && (secondText[secondLen - 1] <= ' ')) {
          secondLen--;
View Full Code Here

TOP

Related Classes of javax.swing.text.html.HTMLDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.