JDK-4321103 : Right text margins changed by wide objects on page
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.2,1.3.0,1.3.1
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_7,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 2000-03-13
  • Updated: 2002-06-24
  • Resolved: 2002-03-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.1 hopperFixed
Related Reports
Duplicate :  
Relates :  
Description
Objects (images, <pre> formatted text) wider than the viewer window change
the right text margin.  The web browsers maintain the text margins at the
width of the browser window even when large images or <pre> formatted text
forces the addition of a horizontal scroll bar.  This requires the user to
scroll back and forth to see all of the text in the window.

==========================
Here are the steps to reproduce the bug.

1. start SwingSet2 demo
2. Goto Text test (JEditorPane HTML Demo)
3. Change the width of the window. Make it smaller than the image width.
4. Check the text at the bottom
You see that the text is formatted using the image width not the visible widht.

###@###.### 2002-03-06

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: hopper FIXED IN: hopper INTEGRATED IN: hopper VERIFIED IN: hopper-beta
14-06-2004

SUGGESTED FIX javax/swing/text/html/HTMLEditorKit.java *************** *** 22,27 **** --- 22,28 ---- import javax.swing.plaf.TextUI; import java.util.*; import javax.accessibility.*; + import java.lang.ref.*; /** * The Swing JEditorPane text component supports different kinds *************** *** 1062,1077 **** (kind == HTML.Tag.OL)) { return new ListView(elem); } else if (kind == HTML.Tag.BODY) { ! // reimplement major axis requirements to indicate that the ! // block is flexible for the body element... so that it can ! // be stretched to fill the background properly. ! return new BlockView(elem, View.Y_AXIS) { ! protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) { ! r = super.calculateMajorAxisRequirements(axis, r); ! r.maximum = Integer.MAX_VALUE; ! return r; ! } ! }; } else if (kind == HTML.Tag.HTML) { return new BlockView(elem, View.Y_AXIS); } else if ((kind == HTML.Tag.LI) || --- 1063,1069 ---- (kind == HTML.Tag.OL)) { return new ListView(elem); } else if (kind == HTML.Tag.BODY) { ! return new BodyBlockView(elem); } else if (kind == HTML.Tag.HTML) { return new BlockView(elem, View.Y_AXIS); } else if ((kind == HTML.Tag.LI) || *************** *** 1176,1183 **** return new LabelView(elem); } ! } // --- Action implementations ------------------------------ /** The bold action identifier --- 1168,1300 ---- return new LabelView(elem); } ! private static class BodyBlockView extends BlockView implements ComponentListener { ! public BodyBlockView(Element elem) { ! super(elem,View.Y_AXIS); ! } ! // reimplement major axis requirements to indicate that the ! // block is flexible for the body element... so that it can ! // be stretched to fill the background properly. ! protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) { ! r = super.calculateMajorAxisRequirements(axis, r); ! r.maximum = Integer.MAX_VALUE; ! return r; ! } ! protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) { ! //idk ! //Thread.currentThread().dumpStack(); ! //idk ! Container container = getContainer(); ! Container parentContainer; ! if (container != null ! && (container instanceof javax.swing.JEditorPane) ! && (parentContainer = container.getParent()) != null ! && (parentContainer instanceof javax.swing.JViewport)) { ! JViewport viewPort = (JViewport)parentContainer; ! Object cachedObject; ! if (cachedViewPort != null) { ! if ((cachedObject = cachedViewPort.get()) != null) { ! if (cachedObject != viewPort) { ! ((JComponent)cachedObject).removeComponentListener(this); ! } ! } else { ! cachedViewPort = null; ! } ! } ! if (cachedViewPort == null) { ! viewPort.addComponentListener(this); ! cachedViewPort = new WeakReference(viewPort); ! } ! int n = getViewCount(); ! int widthStorage; ! componentVisibleWidth = viewPort.getExtentSize().width; ! Insets insets = container.getInsets(); ! viewVisibleWidth = componentVisibleWidth - insets.left - getLeftInset(); ! widthStorage = targetSpan; ! for (int i = 0; i < n; i++) { ! View v = getView(i); ! int min = (int) v.getMinimumSpan(axis); ! int max = (int) v.getMaximumSpan(axis); ! //try to use viewVisibleWidth if it is smaller than targetSpan ! //in case viewVisibleWidth smaller than min use min ! targetSpan = Math.min(widthStorage, Math.max(viewVisibleWidth, min)); ! if (max < targetSpan) { ! // can't make the child this wide, align it ! float align = v.getAlignment(axis); ! offsets[i] = (int) ((targetSpan - max) * align); ! spans[i] = max; ! } else { ! // make it the target width, or as small as it can get. ! offsets[i] = 0; ! spans[i] = Math.max(min, targetSpan); ! } ! } ! } else { ! if (cachedViewPort != null) { ! Object cachedObject; ! if ((cachedObject = cachedViewPort.get()) != null) { ! ((JComponent)cachedObject).removeComponentListener(this); ! } ! cachedViewPort = null; ! } ! super.layoutMinorAxis(targetSpan,axis,offsets,spans); ! } ! } + public void setParent(View parent) { + //if parent == null unregister component listener + if (parent == null) { + if (cachedViewPort != null) { + Object cachedObject; + if ((cachedObject = cachedViewPort.get()) != null) { + ((JComponent)cachedObject).removeComponentListener(this); + } + cachedViewPort = null; + } + } + super.setParent(parent); + } + + public void componentResized(ComponentEvent e) { + if ( !(e.getSource() instanceof JViewport) ) { + return; + } + JViewport viewPort = (JViewport)e.getSource(); + if (componentVisibleWidth != viewPort.getExtentSize().width) { + Document doc = getDocument(); + if (doc instanceof AbstractDocument) { + AbstractDocument document = (AbstractDocument)getDocument(); + document.readLock(); + try { + layoutChanged(X_AXIS); + preferenceChanged(null, true, true); + } finally { + document.readUnlock(); + } + + } + } + } + public void componentHidden(ComponentEvent e) { + } + public void componentMoved(ComponentEvent e) { + } + public void componentShown(ComponentEvent e) { + } + /* + * we keep weak reference to viewPort if and only if BodyBoxView is listening for ComponentEvents + * only in that case cachedViewPort is not equal to null. + * we need to keep this reference in order to remove BodyBoxView from viewPort listeners. + * + */ + private Reference cachedViewPort = null; + private boolean isListening = false; + private int viewVisibleWidth = Integer.MAX_VALUE; + private int componentVisibleWidth = Integer.MAX_VALUE; + } + + } + // --- Action implementations ------------------------------ /** The bold action identifier
11-06-2004

EVALUATION From the justification: While most browsers show this behavior the 3.2 html spec does not dictate this behavior, and the 4.0 spec is fuzzy at best. We will reevaluate and potentially reprioritze this post merlin. scott.violet@eng 2001-07-31 =============================================================================== The problem is that visible width of the view was not used for doing layout. The idea of the fix is to use visible width for laying out the sub-views of the BlockView which is responsible for body tag. BodyBlockView was created for this purpose. See BodyBlockView.layoutMinorAxis for details of the implementation. Also we need to relayout BodyBlockView every time visible width is changed. (It would not happen automatically because BodyBlockView sizes are not changing) BodyBlockView is listening for componentEvents of this.getComponent().getParent(); see BodyBlockView.componentResized for details. This fix is enabled only for JEditorPane inserted into JViewport ###@###.### 2001-11-06 ================================================================================
06-11-2001