Package javax.swing.text

Examples of javax.swing.text.DefaultStyledDocument


   * Creates the annotation display.
   */
  private void displayAnnotations() {
    // for speed, detach document from text pane before updating
    StyledDocument doc = (StyledDocument) textPane.getDocument();
    Document blank = new DefaultStyledDocument();
    textPane.setDocument(blank);

    // make sure annotationCheckboxPanel is showing
    if (legendScrollPane.getViewport().getView() != annotationCheckboxPanel) {
      legendScrollPane.setViewportView(annotationCheckboxPanel);
View Full Code Here


   * Creates the entity display.
   */
  private void displayEntities() {
    // for speed, detach document from text pane before updating
    StyledDocument doc = (StyledDocument) textPane.getDocument();
    Document blank = new DefaultStyledDocument();
    textPane.setDocument(blank);

    // make sure entityCheckboxPanel is showing
    if (legendScrollPane.getViewport().getView() != entityCheckboxPanel) {
      legendScrollPane.setViewportView(entityCheckboxPanel);
View Full Code Here

        getVerticalScrollBar().setUnitIncrement(10);

        initActions();

        DefaultStyledDocument doc = new DefaultStyledDocument();
        doc.setDocumentFilter(new GroovyFilter(doc));
        textEditor.setDocument(doc);

        // add a document listener, to hint whether the line number gutter has to be repainted
        // when the number of lines changes
        doc.addDocumentListener(new DocumentListener() {
            public void insertUpdate(DocumentEvent documentEvent) {
                documentChangedSinceLastRepaint = true;
            }

            public void removeUpdate(DocumentEvent documentEvent) {
                documentChangedSinceLastRepaint = true;
            }

            public void changedUpdate(DocumentEvent documentEvent) {
                documentChangedSinceLastRepaint = true;
                int width = 3 * Preferences.userNodeForPackage(Console.class).getInt("fontSize", 12);
                numbersPanel.setPreferredSize(new Dimension(width, width));
            }
        });

        // create and add the undo/redo manager
        this.undoManager = new TextUndoManager();
        doc.addUndoableEditListener(undoManager);

        // add the undo actions
        undoManager.addPropertyChangeListener(undoAction);
        undoManager.addPropertyChangeListener(redoAction);

        doc.addDocumentListener(undoAction);
        doc.addDocumentListener(redoAction);

        InputMap im = textEditor.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK, false);
        im.put(ks, StructuredSyntaxResources.UNDO);
        ActionMap am = textEditor.getActionMap();
View Full Code Here

    String noHtmlTags = html.replaceAll("<i>", "").replaceAll("</i>", "").replaceAll("<b>", "").replaceAll("</b>", "");


    JTextPane m_monitor = new JTextPane();
    m_monitor.setText(noHtmlTags);
    DefaultStyledDocument rtf_doc = (DefaultStyledDocument) m_monitor.getDocument();

    boolean bold = false;
      boolean italics = false;
      int html_counter = 0;
      int count=0;
      MutableAttributeSet attr = new SimpleAttributeSet();
      StyleConstants.setItalic(attr,italics);
        StyleConstants.setBold(attr, bold);

        while(html_counter<html.length()){
          if(html_counter+3<=html.length() && "<b>".equals(html.substring(html_counter,html_counter+3))){
            StyleConstants.setBold(attr, true);
            html_counter+=3;
        } else if(html_counter+4<=html.length() && "</b>".equals(html.substring(html_counter,html_counter+4))){
          StyleConstants.setBold(attr, false);
          html_counter+=4;
        } else if(html_counter+3<=html.length() && "<i>".equals(html.substring(html_counter,html_counter+3))){
          StyleConstants.setItalic(attr, true);
          html_counter+=3;
        } else if(html_counter+4<=html.length() && "</i>".equals(html.substring(html_counter,html_counter+4))){
          StyleConstants.setItalic(attr, false);
          html_counter+=4;
        } else {
            rtf_doc.setCharacterAttributes(count++, 1 , attr, false);
            html_counter++;
        }
        }
      return rtf_doc;
  }
View Full Code Here

  public Chat(JChessBoard jcb) {
    super(new BorderLayout());
    this.jcb = jcb;
    setBorder(new javax.swing.border.EtchedBorder());
    //document = new DefaultStyledDocument();
    document = new DefaultStyledDocument();
    endPosition = document.getEndPosition();
    textPane = new JTextPane(document);
    textPane.setEditable(false);
    scrollPane = new JScrollPane();
    scrollPane.setVerticalScrollBarPolicy(
View Full Code Here

    public static TextEffigy newTextEffigy(CompositeEntity container,
            String text) throws Exception {
        // Create a new effigy.
        TextEffigy effigy = new TextEffigy(container, container
                .uniqueName("effigy"));
        Document doc = new DefaultStyledDocument();
        effigy.setDocument(doc);

        if (text != null) {
            doc.insertString(0, text, null);
        }

        return effigy;
    }
View Full Code Here

    public static TextEffigy newTextEffigy(CompositeEntity container, URL base,
            URL in) throws Exception {
        // Create a new effigy.
        TextEffigy effigy = new TextEffigy(container, container
                .uniqueName("effigy"));
        Document doc = new DefaultStyledDocument();
        effigy.setDocument(doc);

        if (in != null) {
            // A URL has been given.  Read it.
            BufferedReader reader = null;

            try {
                try {
                    InputStream inputStream = null;

                    try {
                        inputStream = in.openStream();
                    } catch (NullPointerException npe) {
                        throw new IOException("Failed to open '" + in
                                + "', base: '" + base
                                + "' : openStream() threw a "
                                + "NullPointerException");
                    }

                    reader = new BufferedReader(new InputStreamReader(
                            inputStream));

                    // openStream throws an IOException, not a
                    // FileNotFoundException
                } catch (IOException ex) {
                    try {
                        // If we are running under WebStart, and try
                        // view source on a .html file that is not in
                        // ptsupport.jar, then we may end up here,
                        // so we look for the file as a resource.
                        URL jarURL = ptolemy.util.ClassUtilities
                                .jarURLEntryResource(in.toString());
                        reader = new BufferedReader(new InputStreamReader(
                                jarURL.openStream()));

                        // We were able to open the URL, so update the
                        // original URL so that the title bar accurately
                        // reflects the location of the file.
                        in = jarURL;
                    } catch (Throwable throwable) {
                        // Looking for the file as a resource did not work,
                        // so we rethrow the original exception.
                        throw ex;
                    }
                }

                String line = reader.readLine();

                while (line != null) {
                    // Translate newlines to Java form.
                    doc.insertString(doc.getLength(), line + "\n", null);
                    line = reader.readLine();
                }
            } finally {
                if (reader != null) {
                    reader.close();
View Full Code Here

        boolean oldVisible = dialog.isVisible();
        JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
        int oldPosition = verticalScrollBar.getValue();
        int oldCaretPosition = textPane.getCaretPosition();

        StyledDocument document = new DefaultStyledDocument();
        SimpleAttributeSet attributeSet = new SimpleAttributeSet();
        StyleConstants.setBold(attributeSet, true);
        StyleConstants.setAlignment(attributeSet, StyleConstants.ALIGN_JUSTIFIED);
        try {
            document.insertString(document.getLength(), text, attributeSet);
        }
        catch (BadLocationException e) {
            // Normally cannot happen.
            textPane.setText(text);
            e.printStackTrace();
View Full Code Here

        boolean oldVisible = dialog.isVisible();
        JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
        int oldPosition = verticalScrollBar.getValue();
        int oldCaretPosition = textPane.getCaretPosition();

        StyledDocument document = new DefaultStyledDocument();
        SimpleAttributeSet attributeSet = new SimpleAttributeSet();
        StyleConstants.setBold(attributeSet, true);
        StyleConstants.setAlignment(attributeSet, StyleConstants.ALIGN_JUSTIFIED);
        try {
            document.insertString(document.getLength(), text, attributeSet);
        } catch (BadLocationException e) {
            // Normally cannot happen.
            textPane.setText(text);
            e.printStackTrace();
        }
View Full Code Here

        boolean oldVisible = dialog.isVisible();
        JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
        int oldPosition = verticalScrollBar.getValue();
        int oldCaretPosition = textPane.getCaretPosition();

        StyledDocument document = new DefaultStyledDocument();
        SimpleAttributeSet attributeSet = new SimpleAttributeSet();
        StyleConstants.setBold(attributeSet, true);
        StyleConstants.setAlignment(attributeSet, StyleConstants.ALIGN_JUSTIFIED);
        try {
            document.insertString(document.getLength(), text, attributeSet);
        }
        catch (BadLocationException e) {
            // Normally cannot happen.
            textPane.setText(text);
            e.printStackTrace();
View Full Code Here

TOP

Related Classes of javax.swing.text.DefaultStyledDocument

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.