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

Problems with font-size on the HTMLEditorKit (Regression for JDK 1.3RA)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.0
    • client-libs



      Name: skT88420 Date: 11/26/99


      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)

      try this :

      import java.awt.*;
      import java.util.*;
      import java.io.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.text.*;
      import javax.swing.text.html.*;

      public class Test extends JFrame {
        JTextPane theTextPane;
        Hashtable commands;

        public Test() {
          this.getContentPane().setLayout(new BorderLayout());
          this.setSize(new Dimension(640, 480));
          theTextPane = new JTextPane();
          theTextPane.setEditorKit(new HTMLEditorKit());
          theTextPane.setDocument(new HTMLDocument());
          this.getContentPane().add(new JScrollPane(theTextPane),
      BorderLayout.CENTER);

          Action[] theActions = theTextPane.getEditorKit().getActions();
          commands = new Hashtable();
          for (int i = 0; i < theActions.length; i++)
            commands.put(theActions[i].getValue(Action.NAME), theActions[i]);
          commands.put("export", new ExportAction());
          commands.put("import", new ImportAction());
          this.getContentPane().add(createToolbar(), BorderLayout.NORTH);
        }

        private Component createToolbar() {
      JToolBar toolbar = new JToolBar();
          toolbar.setFloatable(false);
          toolbar.add(createToolbarButton("font-size-8"));
          toolbar.add(createToolbarButton("font-size-10"));
          toolbar.add(createToolbarButton("font-size-36"));
          toolbar.add(createToolbarButton("export"));
          toolbar.add(createToolbarButton("import"));
      return toolbar;
        }

        private JButton createToolbarButton(String key) {
          JButton b = new JButton(key);
          b.setRequestFocusEnabled(false);
      Action a = getAction(key);
      if (a != null) {
      b.setActionCommand(a.getValue(Action.NAME).toString());
      b.addActionListener(a);
      }
          else
      b.setEnabled(false);
          return b;
        }

        protected Action getAction(String cmd) {
      return (Action) commands.get(cmd);
        }

        class ExportAction extends AbstractAction {
      ExportAction() {
      super("export");
      }

          public void actionPerformed(ActionEvent e) {
            try{
              FileWriter theWriter = new FileWriter(new File("test.html"));
              (new HTMLEditorKit()).write(theWriter, theTextPane.getDocument(), 0,
      theTextPane.getDocument().getLength());
              theWriter.flush();
            }
            catch(java.io.IOException ioe){
              System.out.println("ioException");}
            catch(javax.swing.text.BadLocationException ble){
              System.out.println("BadLocationException");}
          }
        }

        class ImportAction extends AbstractAction {
      ImportAction() {
      super("import");
      }

          public void actionPerformed(ActionEvent e) {
            try{
              FileReader theReader = new FileReader(new File("test.html"));
              theTextPane.setDocument(new HTMLDocument());
              (new HTMLEditorKit()).read(theReader, theTextPane.getDocument(), 0);
            }
            catch(java.io.IOException ioe){
              System.out.println(ioe.toString());}
            catch(javax.swing.text.BadLocationException ble){
              System.out.println(ble.toString());}
          }
        }

        public static void main(String[] args) {
          try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          }
          catch(Exception e) {
          }
          Test frame = new Test();
          frame.validate();
          frame.setVisible(true);
        }
      }

      type text, select it, and use font-size-8, font-size-10 buttons, you can see
      that font-size-8 set text to a font-size-12. Is it a bug?

      Export and Import the text by pressing 'export' and 'import' buttons. The font-
      size of the imported html text is not the same than the original text.
      The problem is when you use, for example, font-size-12, java encode the html
      file with a tag <font size="12"></font>, but that is not a valid html tag. A
      valid html tag should be <font size="x"> with x from 1 to 7.
      (Review ID: 98305)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: