edu.mines.jtk.mosaic.TileAxisResizing.txt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of edu-mines-jtk Show documentation
Show all versions of edu-mines-jtk Show documentation
Java packages for science and engineering
The newest version!
Dave Hale's notes on the TileAxis resizing problem.
During layout, a child must provide it's preferred size.
Suppose the child's preferred width depends on its height.
Then, when the parent sets its height, child needs a way
to indicate that its preferred size has changed. The
child cannot invalidate or revalidate itself during a
validate traversal and layout, because validate will
mark the child and its ancestors valid.
/////////////////////////////////////////////////////////////////////////////
Current solution
Implement a field revalidatePending and method revalidateLater in
the class TileAxis. The method revalidateLater uses invokeLater to
queue a runnable that will call revalidate *after* the current
validate traversal is complete. This method also sets the field
revalidatePending to true. We must call revalidateLater only in
the method setBounds. Elsewhere we can simply call revalidate.
Also provide a static method revalidatePending in TileAxis that
will return true if any TileAxis child of a specified container
has the revalidatePending flag set to true. Then, such containers
can delay any processing (using invokeLater) until no revalidates
are pending.
/////////////////////////////////////////////////////////////////////////////
Important methods
JComponent.revalidate
Container.invalidate
RepaintManager.addInvalidComponent(this)
Container.invalidate
tells layout manager to ignore any info cached for this
Component.invalidate
Component.invalidate
valid = false
nullifies cached prefSize,minSize,maxSize
if parent is valid,
parent.invalidate()
Container.validate
if not valid:
calls validateTree on self
calls doLayout on self
calls validate on children
valid = true
Component.validate
if not valid:
calls layout on peer
valid = true
RepaintManager.addInvalidComponent(this)
maintains a list of components to update
finds validateRoot for this
if validateRoot is already in list,
return
else
adds validateRoot for this to list
queues a request to
validateInvalidComponents
paintDirtyRegions
RepaintManager.validateInvalidComponents
copies invalidComponents list to ic
sets invalidComponents list to null
for all components c in ic
c.validate()
/////////////////////////////////////////////////////////////////////////////
Problem, in terms of classes and methods outlined above
when first validated, axis minimum size is too big
when axis bounds are first set by mosaic doLayout,
axis updates tics, because now it has non-zero size
this update may change axis minimum size
if minimum size changed, revalidate will
set valid=false upwards in tree
add validateRoot to repaint manager's invalid list
after doLayout of mosaic,
Container.validateTree sets valid = true
Container.validate sets valid = true
this setting valid=true will continue up to the validateRoot
therefore, revalidate will have no effect
although validateRoot is in repaint manager's invalid list,
it and its children are marked valid, so validate does nothing!
in summary, calling revalidate within validate/doLayout does not work
© 2015 - 2025 Weber Informatics LLC | Privacy Policy