21ViewingHtml

Download Report

Transcript 21ViewingHtml

Viewing HTML in Swing
Homework
• Display a dialog box that warns the user if a
mnemonic is duplicated in a RunMenu
• Look in the gui.run.RunMenu
• Its just a warning
Midterm
• write an addressbook using the gui.run
components
• You will need
– RunButton, RunMenuItem, RunTextField,
RunTextArea, RunMenu
– Use Mnemonics and Keyboard accelerators
Look and feel
File Menu
•
•
•
•
Open
Save
Exit
Use xml.adbk.Address for your address
record. Use xml.adbk. AddressBook to store
your address.
HW For next week
• Just build the GUI for the addressbook, you
don’t have to make anything actually work.
• No event handling is needed for next week.
• You will need Run Method, but they will be
• empty
You will learn
•
•
•
•
How to build an HTML viewer
About MIME data types
How to synthesize HTML
How to generate HTML forms
Network Layers
•
•
•
•
•
•
•
physical – bits (sonet)
data link layer – PPP (ATM)
Network layer – IP - routing
transport layer - TCP
session layer – login, creating a connection
presentation layer – html /process data
application layer - browser
How do I know my data type?
• StreamSniffer!
• HTML – enables the decoding of data by
using a special string “MIME”
• Multi-purpose Internet Mail Extension…
•
RFC – 1521 “text/html” “image/gif”
“text/rtf” The mime string is in the header!
• Filename suffix….not reliable.
What is an HTML viewer?
• An application that renders HTML to the
screen
• Build a help file for my address book
program!
Why Render HTML?
• Process Data is decoded at the presentation
layer.
• Standard Markup language
• Enables creation of a browser
• Enables handy documentation viewer
• Debug of HTML generators
• Debug web servers
How Do I render HTML?
• gui.html.HtmlViewer
• renders some canned HTML
How does the HTML viewer
work?
•
•
•
•
•
•
The heart of the HTML viewer:
javax.swing.JEditorPane
Embed an instance of the JEP in a
javax.swing.JScrollPane
jep.setContentType("text/html");
jep.setText(s);/// then just display!
Using MIME
•
•
•
•
jep.setContentType("text/html");
sets the type of data in the JEP
"text" indicates there is text in the string
"html" indicates we have an HTML data
type.
What is MIME?
• Multipurpose Internet Mail Extensions
• It is a "string" with several predefined
values.
Why do we have MIME?
• In the beginning MAIL was only ASCII
text.
• Somebody wanted BINARY data too.
• MTA = Mail Transfer Agents.
• MTA is a program that moves mail from
one NODE to another.
• A node is just a computer than runs an
MTA.
MIME identifies Data Types
•
•
•
•
•
Word documents are of a specific type!
They present process data.
GIF represents process data “sound/aiff”
AU represents process data. “sound/au”
There is not limit to the number of different
data types.
• MIME is used to introduce the data types.
Examples of Mime
•
•
•
•
"text/html" = html document
"text/rtf" = word RTF
"sound/aiff" = audio interchange format
"sound/au" = 8 bit voice grade format
(SUN)
• ....Lots of others....All documented in an
RFC1521
MIME is used for
• Mail
• Browsers use MIME (mapping to plugins or
helper apps).
• JEditPanes
• "text/html", "text/plain", "text/rtf",
"image/gif".
How do we generate HTML?
• "<html> <body> sdlkfdslfkj</body>
</html>"
• Just type it in!
• Another way is to synthesize the HTML!
• Try to write a toolkit for HTML synthesis.
Using the HTML Synthesizer
•
•
•
•
•
public String getHtml(String s) {
return "<html>\n" + s + "\n</html>";
}
String s = getHtml("hello world");
s="<html>\n helloworld \n </html>";
Building a list
•
•
•
•
•
public String getListItem(String s) {
return "<li>\n" + s + "\n</li>";
}
s = getHtml(getListItem(li1));
<html>...<li> li1 <li> </html>....