Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4304521

Document with TabStop Attributes not written correctly into RTF File

XMLWordPrintable



      Name: tb29552 Date: 01/13/2000


      /*
      The Version didnþt matter. I tried the following:

      java version "1.2.2"
      HotSpot VM (1.0.1, mixed mode, build g)
          Or
      java version "1.2"
      Classic VM (build JDK-1.2-V, native threads)
          Or
      java version "1.3beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
      Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)

      The following Code produces a StyledDocument and writes it to a
      RTF-File. In the Document there are Tabs set. In the written
      RTF-File the definition of these Tabstops is missing. Only the
      Tab-Character is present.

      File <rtfoutput.rtf> contains:

      {\rtf1\ansi
      {\fonttbl\f0\fnil Monospaced;}

      \tab 1.Tab\tab 2.Tab\tab 3.Tab\par
      }

      As you can see there is no information about any Tabstop
      positions in the file.

      */

      import java.io.*;
      import javax.swing.*;
      import javax.swing.text.*;
      import javax.swing.text.rtf.*;
      class RTFTest {
          public static void main(String[] args) {

              RTFEditorKit myRTF = new RTFEditorKit();
              DefaultStyledDocument mySDoc = (DefaultStyledDocument)
              myRTF.createDefaultDocument();

              SimpleAttributeSet TabAttSet = new SimpleAttributeSet();

              TabStop first = new TabStop(50, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
              TabStop second = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
              TabStop third = new TabStop(250, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);

              TabSet tabs = new TabSet(new TabStop[] {first, second, third});
              SimpleAttributeSet Tabs = new SimpleAttributeSet();
              StyleConstants.setTabSet(Tabs, tabs);

              try {
                  mySDoc.insertString(mySDoc.getLength(),
                                      "\t1.Tab\t2.Tab\t3.Tab", null);
                  mySDoc.setParagraphAttributes(0, mySDoc.getLength(),
                                                Tabs, false);
              } catch(Exception Ex) {
                  Ex.printStackTrace();
              }
              try {
                  FileOutputStream ofs = new FileOutputStream("rtfoutput.rtf");
                  myRTF.write(ofs, mySDoc, 0, mySDoc.getLength());
                  ofs.close();
              } catch(Exception Ex) {
                  Ex.printStackTrace();
              }
          }
      }

      (Review ID: 99905)
      ======================================================================

            peterz Peter Zhelezniakov
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: