| Method from javax.swing.text.html.FrameView Detail: |
public void changedUpdate(DocumentEvent e,
Shape a,
ViewFactory f) {
Element elem = getElement();
AttributeSet attributes = elem.getAttributes();
URL oldPage = src;
String srcAtt = (String)attributes.getAttribute(HTML.Attribute.SRC);
URL base = ((HTMLDocument)elem.getDocument()).getBase();
try {
if (!createdComponent) {
return;
}
Object postData = movePostData(htmlPane, null);
src = new URL(base, srcAtt);
if (oldPage.equals(src) && (src.getRef() == null) && (postData == null)) {
return;
}
htmlPane.setPage(src);
Document newDoc = htmlPane.getDocument();
if (newDoc instanceof HTMLDocument) {
((HTMLDocument)newDoc).setFrameDocumentState(true);
}
} catch (MalformedURLException e1) {
// Need a way to handle exceptions
//e1.printStackTrace();
} catch (IOException e2) {
// Need a way to handle exceptions
//e2.printStackTrace();
}
}
Gives notification from the document that attributes were changed
in a location that this view is responsible for. Currently this view
handles changes to its SRC attribute. |
protected Component createComponent() {
Element elem = getElement();
AttributeSet attributes = elem.getAttributes();
String srcAtt = (String)attributes.getAttribute(HTML.Attribute.SRC);
if ((srcAtt != null) && (!srcAtt.equals(""))) {
try {
URL base = ((HTMLDocument)elem.getDocument()).getBase();
src = new URL(base, srcAtt);
htmlPane = new FrameEditorPane();
htmlPane.addHyperlinkListener(this);
JEditorPane host = getHostPane();
boolean isAutoFormSubmission = true;
if (host != null) {
htmlPane.setEditable(host.isEditable());
String charset = (String) host.getClientProperty("charset");
if (charset != null) {
htmlPane.putClientProperty("charset", charset);
}
HTMLEditorKit hostKit = (HTMLEditorKit)host.getEditorKit();
if (hostKit != null) {
isAutoFormSubmission = hostKit.isAutoFormSubmission();
}
}
htmlPane.setPage(src);
HTMLEditorKit kit = (HTMLEditorKit)htmlPane.getEditorKit();
if (kit != null) {
kit.setAutoFormSubmission(isAutoFormSubmission);
}
Document doc = htmlPane.getDocument();
if (doc instanceof HTMLDocument) {
((HTMLDocument)doc).setFrameDocumentState(true);
}
setMargin();
createScrollPane();
setBorder();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
createdComponent = true;
return scroller;
}
|
JEditorPane getHostPane() {
Container c = getContainer();
while ((c != null) && ! (c instanceof JEditorPane)) {
c = c.getParent();
}
return (JEditorPane) c;
}
|
public float getMaximumSpan(int axis) {
return Integer.MAX_VALUE;
}
Determines the maximum span for this view along an
axis. |
public float getMinimumSpan(int axis) {
return 5;
}
Determines the minimum span for this view along an
axis. |
JEditorPane getOutermostJEditorPane() {
View parent = getParent();
FrameSetView frameSetView = null;
while (parent != null) {
if (parent instanceof FrameSetView) {
frameSetView = (FrameSetView)parent;
}
parent = parent.getParent();
}
if (frameSetView != null) {
return (JEditorPane)frameSetView.getContainer();
}
return null;
}
Finds the outermost FrameSetView. It then
returns that FrameSetView's container. |
public void hyperlinkUpdate(HyperlinkEvent evt) {
JEditorPane c = getOutermostJEditorPane();
if (c == null) {
return;
}
if (!(evt instanceof HTMLFrameHyperlinkEvent)) {
c.fireHyperlinkUpdate(evt);
return;
}
HTMLFrameHyperlinkEvent e = (HTMLFrameHyperlinkEvent)evt;
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
String target = e.getTarget();
String postTarget = target;
if (target.equals("_parent") && !inNestedFrameSet()){
target = "_top";
}
if (evt instanceof FormSubmitEvent) {
HTMLEditorKit kit = (HTMLEditorKit)c.getEditorKit();
if (kit != null && kit.isAutoFormSubmission()) {
if (target.equals("_top")) {
try {
movePostData(c, postTarget);
c.setPage(e.getURL());
} catch (IOException ex) {
// Need a way to handle exceptions
}
} else {
HTMLDocument doc = (HTMLDocument)c.getDocument();
doc.processHTMLFrameHyperlinkEvent(e);
}
} else {
c.fireHyperlinkUpdate(evt);
}
return;
}
if (target.equals("_top")) {
try {
c.setPage(e.getURL());
} catch (IOException ex) {
// Need a way to handle exceptions
// ex.printStackTrace();
}
}
if (!c.isEditable()) {
c.fireHyperlinkUpdate(new HTMLFrameHyperlinkEvent(c,
e.getEventType(),
e.getURL(),
e.getDescription(),
getElement(),
e.getInputEvent(),
target));
}
}
}
Notification of a change relative to a
hyperlink. This method searches for the outermost
JEditorPane, and then fires an HTMLFrameHyperlinkEvent
to that frame. In addition, if the target is _parent,
and there is not nested framesets then the target is
reset to _top. If the target is _top, in addition to
firing the event to the outermost JEditorPane, this
method also invokes the setPage() method and explicitly
replaces the current document with the destination url. |
public void paint(Graphics g,
Shape allocation) {
Container host = getContainer();
if (host != null && htmlPane != null &&
htmlPane.isEditable() != ((JTextComponent)host).isEditable()) {
editable = ((JTextComponent)host).isEditable();
htmlPane.setEditable(editable);
}
super.paint(g, allocation);
}
Also determines if the FrameView should be editable
or not based on whether the JTextComponent that
contains it is editable. And then proceeds to call
the superclass to do the paint(). |
public void setParent(View parent) {
if (parent != null) {
JTextComponent t = (JTextComponent)parent.getContainer();
editable = t.isEditable();
}
super.setParent(parent);
}
Sets the parent view for the FrameView.
Also determines if the FrameView should be editable
or not based on whether the JTextComponent that
contains it is editable. |