`

HTML rendering : Java Glossary

    博客分类:
  • Web
阅读更多

Source: http://mindprod.com/jgloss/htmlrendering.html

 

HTML rendering<!-- alias rendering HTML --> HTML rendering refers to analying the tags such as <b> and merging them with the text to produce a formatted display.

In Applets

If you writing Java source code for an Applet , you can persuade the browser you are running

<!-- macro JDisplay htmlrendering.example101.javafrag --><!-- generated -->
java
.
net
.
URL 
url 
= 
new 
java
.
net
.
URL 
(
 "http://mindprod.com"
 )
;

getAppletContext
(
)
.
showDocument
(
 url 
)
;
<!-- /generated by JDisplay -->

That code will fail with a NullPointerException if you attempt it in an application. You can catch all exceptions and just ignore the request in code that sometimes runs as an Applet and sometimes as an application.

There are some catches:

  • The URL must be absolute and must have a protocol e.g. http: or file: . Use getDocumentBase or getCodeBase and the URL context-constructor to make it absolute if you have a relative one. You must always have at least filename in your relative part.
  • Older versions of Opera did not work showDocument if there is a trailing #XXXX on your URL.
  • Netscape 4.79 does not work at all with JApplet s.
  • showDocument ignores the BASE TARGET of the current page. You must specify it explicitly as the second parameter to showDocument .

In Applications

  • Unfortunately showDocument does not allow you to take a hunk of HTML you have in a String, perhaps as the result of a POST, and display it. In that case you somehow have to persuade your server to put that html in a file where you can find it via URL. Alternatively you could use Sun’s not-free HTML rendering classes.
  • In <!-- macro Java 1.2 --><!-- generated -->Java version 1.2 <!-- /generated by Java --> there is javax.swing.text .HTMLEditorKit . which offers primitive HTML 3.2 rendering ability, inching toward HTML 4 compatibility. It also supports surprising amount of CSS. You use it like this: <!-- macro JDisplay htmlrendering.example1.javafrag --><!-- generated -->
    output 
    = 
    new 
    JEditorPane
    (
    )
    ;
    
    output
    .
    setContentType
    (
     "text/html"
     )
    ;
    
    output
    .
    setEditable
    (
     false 
    )
    ;
    
    <!-- /generated by JDisplay --> From then on text in the pane is rendered as HTML. You can also use <!-- macro JDisplay htmlrendering.example2.javafrag --><!-- generated -->
    output
    .
    setPage
    (
     "http://mindprod.com"
     )
    ;
    
    <!-- /generated by JDisplay --> to render a page.
  • Here is how you can render and URL pointing to an HTML page inside Java.
  • /*
     * @(#)TestHTMLRendering.java
     *
     * Summary: Eaxample use of Java HTML Rendering. Renders HTML 3.2 plus some CSS. Does not ignore comments properly. Does not.
     *
     * Copyright: (c) 2009-2010 Roedy Green, Canadian Mind Products, http://mindprod.com
     *
     * Licence: This software may be copied and used freely for any purpose but military.
     *          http://mindprod.com/contact/nonmil.html
     *
     * Requires: JDK 1.6+
     *
     * Created with: IntelliJ IDEA IDE.
     *
     * Version History:
     *  1.0 2009-01-01 - initial version
     */
    package com.mindprod.example;
    
    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.SwingUtilities;
    import java.awt.Color;
    import java.awt.Container;
    import java.io.IOException;
    
    import static java.lang.System.err;
    import static java.lang.System.out;
    
    /**
     * Eaxample use of Java HTML Rendering. Renders HTML 3.2 plus some CSS. Does not ignore comments properly. Does not.
     * <p/>
     * implement clickable links.
     *
     * @author Roedy Green, Canadian Mind Products
     * @version 1.0 2009-01-01 - initial version
     * @since 2009-01-01
     */
    @SuppressWarnings( { "UnusedDeclaration" } )
    final class TestHTMLRendering
        {
        // ------------------------------ CONSTANTS ------------------------------
    
        /**
         * height of frame in pixels
         */
        private static final int height = 1000;
    
        /**
         * width of frame in pixels
         */
        private static final int width = 1000;
    
        private static final String RELEASE_DATE = "2007-10-04";
    
        /**
         * title for frame
         */
        private static final String TITLE_STRING = "HTML Rendering";
    
        /**
         * URL of page we want to display
         */
        private static final String URL = "http://mindprod.com/index.html";
    
        /**
         * program version
         */
        private static final String VERSION_STRING = "1.0";
    
        // --------------------------- main() method ---------------------------
    
        /**
         * Debugging harness for a JFrame
         *
         * @param args command line arguments are ignored.
         */
        @SuppressWarnings( { "UnusedParameters" } )
        public static void main( String args[] )
            {
            // Invoke the run method on the Swing event dispatch thread
            // Sun now recommends you call ALL your GUI methods on the Swing
            // event thread, even the initial setup.
            // Could also use invokeAndWait and catch exceptions
            SwingUtilities.invokeLater( new Runnable()
            {
            /**
             * } fire up a JFrame on the Swing thread
             */
            public void run()
                {
                out.println( "Starting" );
                final JFrame jframe =
                        new JFrame( TITLE_STRING + " " + VERSION_STRING );
                Container contentPane = jframe.getContentPane();
                jframe.setSize( width, height );
    
                contentPane.setBackground( Color.YELLOW );
                contentPane.setForeground( Color.BLUE );
                jframe.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                try
                    {
                    out.println( "acquiring URL" );
                    JEditorPane jep = new JEditorPane( URL );
                    out.println( "URL acquired" );
                    JScrollPane jsp =
                            new JScrollPane( jep,
                                    JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
                    contentPane.add( jsp );
                    }
                catch ( IOException e )
                    {
                    err.println( "can't find URL" );
                    contentPane.add( new JLabel( "can't find URL" ) );
                    }
                jframe.validate();
                jframe.setVisible( true );
                // Shows page, with HTML comments erroneously displayed.
                // The links are not clickable.
                }
            } );
            }// end main
        }// end TestHTMLRendering
     
  • In older JVMs, if you are writing an application you are SOL. For applications, there is no standard HTML rendering class, though BISS-AWT has some primitive HTML rendering code.
  • Flying Saucer is very rigid about standards. It will not render the typical crap you find on the web, only your own carefully validated markup.
  • JDIC Browser is a means to embed Gecko into your Java app, giving pretty much all the rendering engine you might need.
分享到:
评论

相关推荐

    Physically Based Rendering: From Theory to Implementation源代码

    《Physically Based Rendering: From Theory to Implementation》是计算机图形学领域一本权威的著作,它深入探讨了物理渲染(PBR)的理论与实践。PBR是一种追求真实感的渲染技术,旨在模拟光线在物体表面的交互,...

    Physically Based Rendering. From Theory to Implementation

    [Morgan Kaufmann series in computer graphics and geometric modeling] Matt Pharr, Wenzel Jakob, Greg Humphreys - Physically Based Rendering. From Theory to Implementation (2017, Morgan Kaufmann)

    Production Rendering Design and Implementation

    This book on rendering considers REAL rendering systems,integrating complex geometry, procedural shading, and globalillumination. It is edited by Ian Stephenson, but each chapter has beenwritten by a ...

    differentiable_volumetric_rendering:该存储库包含CVPR 2020论文“可区分的体积渲染”的代码。

    title = {Differentiable Volumetric Rendering: Learning Implicit 3D Representations without 3D Supervision}, author = {Niemeyer, Michael and Mescheder, Lars and Oechsle, Michael and Geiger, Andreas},...

    Physically-Based.Rendering.-.From.Theory.To.Implementation.pdf

    ### 物理基础渲染:从理论到实现 #### 引言与系统方法 《物理基础渲染:从理论到实现》是一本深入探讨物理基础渲染技术的书籍,它不仅阐述了渲染的基本理论,还提供了实现这些理论的具体算法和方法。...

    Physically Based Rendering - From Theory to Implementation 3rd edition.part2.rar

    Physically Based Rendering - From Theory to Implementation 3rd edition.part2.rar

    amira_blender_rendering:Bosch BCAI AMIRA probject范围内基于物理的真实感渲染的代码库

    amira_blender_rendering关于AMIRA Blender Rendering:使用Blender进行真实感渲染的工具。 该项目旨在为基于物理的真实感渲染提供一个精益的程序框架,并使专家和初学者都可以使用它。 该项目基于渲染功能及其 ...

    Advanced Real Time Rendering in 3D Graphics and Games.pdf

    《Advanced Real Time Rendering in 3D Graphics and Games》是一本专为游戏开发和实时渲染技术设计的专业书籍。这本书深入探讨了3D图形学的核心概念,特别是如何在游戏环境中实现高效且高质量的实时渲染。实时渲染...

    Physically-Based Rendering - From Theory To Implementation .pdf

    在《物理基础渲染——从理论到实现》这本专著中,作者详细地介绍了渲染技术的基本原理及其实际应用,特别关注了体渲染(Volume Rendering)这一领域。书中通过深入浅出的方式讲解了构建渲染器所需的各个组成部分,...

    Conditional-Rendering:用CodeSandbox创建

    在"Conditional-Rendering:用CodeSandbox创建"中,我们可以推测这是一个关于如何在CodeSandbox上利用JavaScript条件语句(如if、else、三元运算符)和React的`{}`或Vue的`v-if/v-else`指令来实现条件渲染的教学项目...

    java3D (32位和64位)

    8. **渲染(Rendering)**:Java3D使用硬件加速的图形渲染,提供高效的图像生成。开发者可以调整渲染质量,平衡性能与图像效果。 9. **用户交互(User Interaction)**:Java3D支持键盘、鼠标等输入设备的事件处理...

    JAVA3D

    - **Rendering**:Java3D利用硬件加速进行高效渲染,提供高性能的3D图形显示。 10. **编程接口**: - **API**:Java3D提供了一套完整的API,包括基本类型、几何对象、变换、材质、光照等类,开发者可以通过调用...

    volume-rendering:用 C++ 实现的体积渲染(光线投射)

    Volume Rendering 纯 C++ 实现 Raycasting 实现的 Volume Rendering 算法。 数据下载 一份 CBCT 数据,在 下载并放入 文件夹下。 基本知识 看不了公式可以访问 HTML 页面: Raycasting is not the same as raytracing...

    tailwindcss-image-rendering:Tailwind CSS的图像渲染实用程序

    该插件添加了实用程序,可在Tailwind CSS中使用image-rendering 。 安装 将此插件添加到您的项目中: # Install using pnpm pnpm install --save-dev tailwindcss-image-rendering # Install using npm npm install...

    volume-rendering:WebGL客户端,用于3D天气场的体积渲染

    总结来说,"volume-rendering:WebGL客户端,用于3D天气场的体积渲染"是一个使用JavaScript和WebGL技术的项目,它实现了从Met Office的超级计算机提取3D气象数据并进行实时、交互式的体积渲染。通过射线行进算法,...

    transformers-rendering:计算机图形作业 2.2

    在本项目"transformers-rendering:计算机图形作业 2.2"中,主要涉及的是使用C++编程语言实现计算机图形学中的变压器渲染技术。变压器渲染是一种先进的图形处理方法,它通常用于复杂场景的可视化,特别是在游戏开发、...

    java3D-api

    7. **渲染(Rendering)**:Java3D使用硬件加速来提高渲染性能,通过OpenGL或Direct3D接口与图形硬件通信。渲染策略可以根据场景复杂性和系统资源动态调整。 8. **交互性(Interactivity)**:Java3D支持鼠标和键盘...

    spa-dynamic-pre-rendering:SPA动态预渲染

    **标题解析:** "spa-dynamic-pre-rendering:SPA动态预渲染" 这个标题指出我们讨论的主题是关于SPA(单页应用)的动态预渲染技术。预渲染是一种优化策略,它允许预先生成SPA的部分或全部HTML页面,以便在用户访问时...

    Physically Based Rendering From Theory To Implementation 基于物理的渲染,第八章

    ### 基于物理的渲染:第八章——胶片与成像管线 #### 章节概述 在《基于物理的渲染:从理论到实现》一书中,第八章主要介绍了“胶片与成像管线”(Film and the Imaging Pipeline)。这一章节深入探讨了模拟相机中...

    pybullet_rendering:PyBullet的外部渲染

    pybullet_rendering 模拟器的外部渲染。安装使用点 pip install pybullet_rendering从源代码安装NumPy pip install numpy从源代码安装PyBullet git clone ...

Global site tag (gtag.js) - Google Analytics