/[classpath]/classpath/javax/swing/text/html/HTMLEditorKit.java
ViewVC logotype

Diff of /classpath/javax/swing/text/html/HTMLEditorKit.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by andreast, Wed Oct 19 20:31:15 2005 UTC revision 1.9 by langel, Thu Dec 8 21:43:22 2005 UTC
# Line 41  package javax.swing.text.html; Line 41  package javax.swing.text.html;
41  import java.io.IOException;  import java.io.IOException;
42  import java.io.Reader;  import java.io.Reader;
43  import java.io.Serializable;  import java.io.Serializable;
44    import java.io.Writer;
45    
46    import javax.swing.text.AbstractDocument;
47  import javax.swing.text.BadLocationException;  import javax.swing.text.BadLocationException;
48    import javax.swing.text.BoxView;
49    import javax.swing.text.ComponentView;
50  import javax.swing.text.Document;  import javax.swing.text.Document;
51    import javax.swing.text.Element;
52    import javax.swing.text.IconView;
53    import javax.swing.text.LabelView;
54  import javax.swing.text.MutableAttributeSet;  import javax.swing.text.MutableAttributeSet;
55    import javax.swing.text.ParagraphView;
56    import javax.swing.text.StyleConstants;
57  import javax.swing.text.StyledEditorKit;  import javax.swing.text.StyledEditorKit;
58    import javax.swing.text.View;
59    import javax.swing.text.ViewFactory;
60  import javax.swing.text.html.parser.ParserDelegator;  import javax.swing.text.html.parser.ParserDelegator;
61    
62  /**  /**
# Line 257  public class HTMLEditorKit Line 268  public class HTMLEditorKit
268    public static final String PARA_INDENT_RIGHT = "html-para-indent-right";    public static final String PARA_INDENT_RIGHT = "html-para-indent-right";
269    
270    /**    /**
271       * The ViewFactory for HTMLViewFactory.
272       */
273      HTMLViewFactory viewFactory;
274      
275      /**
276     * Create a text storage model for this type of editor.     * Create a text storage model for this type of editor.
277     *     *
278     * @return the model     * @return the model
# Line 277  public class HTMLEditorKit Line 293  public class HTMLEditorKit
293    {    {
294      return new ParserDelegator();      return new ParserDelegator();
295    }    }
296      
297      /**
298       * Inserts HTML into an existing document.
299       *
300       * @param doc - the Document to insert the HTML into.
301       * @param offset - where to begin inserting the HTML.
302       * @param html - the String to insert
303       * @param popDepth - the number of ElementSpec.EndTagTypes
304       * to generate before inserting
305       * @param pushDepth - the number of ElementSpec.StartTagTypes
306       * with a direction of ElementSpec.JoinNextDirection that
307       * should be generated before
308       * @param insertTag - the first tag to start inserting into document
309       * @throws IOException - on any I/O error
310       * @throws BadLocationException - if pos represents an invalid location
311       * within the document
312       */
313      public void insertHTML(HTMLDocument doc, int offset, String html,
314                             int popDepth, int pushDepth, HTML.Tag insertTag)
315          throws BadLocationException, IOException
316      {
317        // FIXME: Not implemented.
318      }
319      
320      /**
321       * Inserts content from the given stream. Inserting HTML into a non-empty
322       * document must be inside the body Element, if you do not insert into
323       * the body an exception will be thrown. When inserting into a non-empty
324       * document all tags outside of the body (head, title) will be dropped.
325       *
326       * @param in - the stream to read from
327       * @param doc - the destination for the insertion
328       * @param pos - the location in the document to place the content
329       * @throws IOException - on any I/O error
330       * @throws BadLocationException - if pos represents an invalid location
331       * within the document
332       */
333      public void read(Reader in, Document doc, int pos) throws IOException,
334          BadLocationException
335      {
336        // FIXME: Not implemented.
337      }
338      
339      /**
340       * Writes content from a document to the given stream in
341       * an appropriate format.
342       *
343       * @param out - the stream to write to
344       * @param doc - the source for the write
345       * @param pos - the location in the document to get the content.
346       * @param len - the amount to write out
347       * @throws IOException - on any I/O error
348       * @throws BadLocationException - if pos represents an invalid location
349       * within the document
350       */
351      public void write(Writer out, Document doc, int pos, int len)
352          throws IOException, BadLocationException
353      {
354        // FIXME: Not implemented.
355      }
356      
357      /**
358       * Gets the content type that the kit supports.
359       * This kit supports the type text/html.
360       *
361       * @returns the content type supported.
362       */
363      public String getContentType()
364      {
365        return "text/html";
366      }
367      
368      /**
369       * Gets a factory suitable for producing views of any
370       * models that are produced by this kit.
371       *
372       * @return the view factory suitable for producing views.
373       */
374      public ViewFactory getViewFactory()
375      {
376        if (viewFactory == null)
377          viewFactory = new HTMLViewFactory();
378        return viewFactory;
379      }
380      
381      /**
382       * A {@link ViewFactory} that is able to create {@link View}s for
383       * the <code>Element</code>s that are supported.
384       */
385      static class HTMLViewFactory
386        implements ViewFactory
387      {
388        /**
389         * Creates a {@link View} for the specified <code>Element</code>.
390         *
391         * @param element the <code>Element</code> to create a <code>View</code>
392         *        for
393         * @return the <code>View</code> for the specified <code>Element</code>
394         *         or <code>null</code> if the type of <code>element</code> is
395         *         not supported
396         */
397        public View create(Element element)
398        {
399          View view = null;
400          Object attr = element.getAttributes().getAttribute(
401                                    StyleConstants.NameAttribute);
402          if (attr instanceof HTML.Tag)
403            {
404              HTML.Tag tag = (HTML.Tag) attr;
405    
406              if (tag.equals(HTML.Tag.IMPLIED) || tag.equals(HTML.Tag.P)
407                  || tag.equals(HTML.Tag.H1) || tag.equals(HTML.Tag.H2)
408                  || tag.equals(HTML.Tag.H3) || tag.equals(HTML.Tag.H4)
409                  || tag.equals(HTML.Tag.H5) || tag.equals(HTML.Tag.H6)
410                  || tag.equals(HTML.Tag.DT))
411                view = new ParagraphView(element);
412              else if (tag.equals(HTML.Tag.LI) || tag.equals(HTML.Tag.DL)
413                       || tag.equals(HTML.Tag.DD) || tag.equals(HTML.Tag.BODY)
414                       || tag.equals(HTML.Tag.HTML) || tag.equals(HTML.Tag.CENTER)
415                       || tag.equals(HTML.Tag.DIV)
416                       || tag.equals(HTML.Tag.BLOCKQUOTE)
417                       || tag.equals(HTML.Tag.PRE))
418                view = new BlockView(element, View.Y_AXIS);
419              
420              // FIXME: Uncomment when the views have been implemented
421             /* else if (tag.equals(HTML.Tag.CONTENT))
422                view = new InlineView(element);
423              else if (tag.equals(HTML.Tag.MENU) || tag.equals(HTML.Tag.DIR)
424                       || tag.equals(HTML.Tag.UL) || tag.equals(HTML.Tag.OL))
425                view = new ListView(element);
426              else if (tag.equals(HTML.Tag.IMG))
427                view = new ImageView(element);
428              else if (tag.equals(HTML.Tag.HR))
429                view = new HRuleView(element);
430              else if (tag.equals(HTML.Tag.BR))
431                view = new BRView(element);
432              else if (tag.equals(HTML.Tag.TABLE))
433                view = new TableView(element);
434              else if (tag.equals(HTML.Tag.INPUT) || tag.equals(HTML.Tag.SELECT)
435                       || tag.equals(HTML.Tag.TEXTAREA))
436                view = new FormView(element);
437              else if (tag.equals(HTML.Tag.OBJECT))
438                view = new ObjectView(element);
439              else if (tag.equals(HTML.Tag.FRAMESET))
440                view = new FrameSetView(element);
441              else if (tag.equals(HTML.Tag.FRAME))
442                view = new FrameView(element); */
443            }      
444          
445          if (view == null)
446            {
447              String name = element.getName();
448              if (name.equals(AbstractDocument.ContentElementName))
449                view = new LabelView(element);
450              else if (name.equals(AbstractDocument.ParagraphElementName))
451                view = new ParagraphView(element);
452              else if (name.equals(AbstractDocument.SectionElementName))
453                view = new BoxView(element, View.Y_AXIS);
454              else if (name.equals(StyleConstants.ComponentElementName))
455                view = new ComponentView(element);
456              else if (name.equals(StyleConstants.IconElementName))
457                view = new IconView(element);
458            }
459          return view;
460        }
461      }
462  }  }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26