130 |
|
|
131 |
/** |
/** |
132 |
* A {@link java.awt.event.ComponentListener} that listens for |
* A {@link java.awt.event.ComponentListener} that listens for |
133 |
* changes of the view's size. This class forbids changes of the view |
* changes of the view's size. This triggers a revalidate() call on the |
134 |
* component's size that would exceed the viewport's size. |
* viewport. |
135 |
*/ |
*/ |
136 |
protected class ViewListener |
protected class ViewListener extends ComponentAdapter implements Serializable |
|
extends ComponentAdapter |
|
|
implements Serializable |
|
137 |
{ |
{ |
138 |
private static final long serialVersionUID = -2812489404285958070L; |
private static final long serialVersionUID = -2812489404285958070L; |
139 |
|
|
146 |
|
|
147 |
/** |
/** |
148 |
* Receives notification when a component (in this case: the view |
* Receives notification when a component (in this case: the view |
149 |
* component) changes it's size. |
* component) changes it's size. This simply triggers a revalidate() on the |
150 |
|
* viewport. |
151 |
* |
* |
152 |
* @param ev the ComponentEvent describing the change |
* @param ev the ComponentEvent describing the change |
153 |
*/ |
*/ |
154 |
public void componentResized(ComponentEvent ev) |
public void componentResized(ComponentEvent ev) |
155 |
{ |
{ |
156 |
// According to some tests that I did with Sun's implementation |
revalidate(); |
|
// this class is supposed to make sure that the view component |
|
|
// is not resized to a larger size than the viewport. |
|
|
// This is not documented anywhere. What I did is: I subclassed JViewport |
|
|
// and ViewListener and 'disabled' the componentResized method by |
|
|
// overriding it and not calling super.componentResized(). |
|
|
// When this method is disabled I can set the size on the view component |
|
|
// normally, when it is enabled, it gets immediatly resized back, |
|
|
// after a resize attempt that would exceed the Viewport's size. |
|
|
Component comp = ev.getComponent(); |
|
|
Dimension newSize = comp.getSize(); |
|
|
Dimension viewportSize = getSize(); |
|
|
boolean revert = false; |
|
|
if (newSize.width > viewportSize.width) |
|
|
{ |
|
|
newSize.width = viewportSize.width; |
|
|
revert = true; |
|
|
} |
|
|
if (newSize.height > viewportSize.height) |
|
|
{ |
|
|
newSize.height = viewportSize.height; |
|
|
revert = true; |
|
|
} |
|
|
if (revert == true) |
|
|
comp.setSize(newSize); |
|
157 |
} |
} |
158 |
} |
} |
159 |
|
|
239 |
{ |
{ |
240 |
setOpaque(true); |
setOpaque(true); |
241 |
setScrollMode(BLIT_SCROLL_MODE); |
setScrollMode(BLIT_SCROLL_MODE); |
|
setLayout(createLayoutManager()); |
|
242 |
updateUI(); |
updateUI(); |
243 |
|
setLayout(createLayoutManager()); |
244 |
lastPaintPosition = new Point(); |
lastPaintPosition = new Point(); |
245 |
cachedBlitFrom = new Point(); |
cachedBlitFrom = new Point(); |
246 |
cachedBlitTo = new Point(); |
cachedBlitTo = new Point(); |
331 |
|
|
332 |
public void setViewPosition(Point p) |
public void setViewPosition(Point p) |
333 |
{ |
{ |
334 |
|
if (getViewPosition().equals(p)) |
335 |
|
return; |
336 |
Component view = getView(); |
Component view = getView(); |
337 |
if (view != null) |
if (view != null) |
338 |
{ |
{ |
395 |
{ |
{ |
396 |
if (viewListener != null) |
if (viewListener != null) |
397 |
getView().removeComponentListener(viewListener); |
getView().removeComponentListener(viewListener); |
398 |
remove(0); |
//remove(0); |
399 |
} |
} |
400 |
|
|
401 |
if (v != null) |
if (v != null) |
406 |
add(v); |
add(v); |
407 |
fireStateChanged(); |
fireStateChanged(); |
408 |
} |
} |
409 |
|
revalidate(); |
410 |
} |
} |
411 |
|
|
412 |
public void revalidate() |
public void revalidate() |