8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.swing; 27 28 import java.awt.*; 29 import java.awt.event.*; 30 import java.awt.peer.ComponentPeer; 31 import java.beans.Transient; 32 import javax.swing.plaf.ViewportUI; 33 34 import javax.swing.event.*; 35 import javax.swing.border.*; 36 import javax.accessibility.*; 37 38 39 import java.io.Serializable; 40 41 42 /** 43 * The "viewport" or "porthole" through which you see the underlying 44 * information. When you scroll, what moves is the viewport. It is like 45 * peering through a camera's viewfinder. Moving the viewfinder upwards 46 * brings new things into view at the top of the picture and loses 47 * things that were at the bottom. 344 * @param child the lightweight <code>child</code> of the viewport 345 * @param constraints the <code>constraints</code> to be respected 346 * @param index the index 347 * @see #setView 348 */ 349 protected void addImpl(Component child, Object constraints, int index) { 350 setView(child); 351 } 352 353 354 /** 355 * Removes the <code>Viewport</code>s one lightweight child. 356 * 357 * @see #setView 358 */ 359 public void remove(Component child) { 360 child.removeComponentListener(viewListener); 361 super.remove(child); 362 } 363 364 365 /** 366 * Scrolls the view so that <code>Rectangle</code> 367 * within the view becomes visible. 368 * <p> 369 * This attempts to validate the view before scrolling if the 370 * view is currently not valid - <code>isValid</code> returns false. 371 * To avoid excessive validation when the containment hierarchy is 372 * being created this will not validate if one of the ancestors does not 373 * have a peer, or there is no validate root ancestor, or one of the 374 * ancestors is not a <code>Window</code> or <code>Applet</code>. 375 * <p> 376 * Note that this method will not scroll outside of the 377 * valid viewport; for example, if <code>contentRect</code> is larger 378 * than the viewport, scrolling will be confined to the viewport's 379 * bounds. 380 * 381 * @param contentRect the <code>Rectangle</code> to display 382 * @see JComponent#isValidateRoot 383 * @see java.awt.Component#isValid | 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.swing; 27 28 import sun.swing.JLightweightFrame; 29 30 import java.awt.*; 31 import java.awt.event.*; 32 import java.awt.peer.ComponentPeer; 33 import java.beans.Transient; 34 import javax.swing.plaf.ViewportUI; 35 36 import javax.swing.event.*; 37 import javax.swing.border.*; 38 import javax.accessibility.*; 39 40 41 import java.io.Serializable; 42 43 44 /** 45 * The "viewport" or "porthole" through which you see the underlying 46 * information. When you scroll, what moves is the viewport. It is like 47 * peering through a camera's viewfinder. Moving the viewfinder upwards 48 * brings new things into view at the top of the picture and loses 49 * things that were at the bottom. 346 * @param child the lightweight <code>child</code> of the viewport 347 * @param constraints the <code>constraints</code> to be respected 348 * @param index the index 349 * @see #setView 350 */ 351 protected void addImpl(Component child, Object constraints, int index) { 352 setView(child); 353 } 354 355 356 /** 357 * Removes the <code>Viewport</code>s one lightweight child. 358 * 359 * @see #setView 360 */ 361 public void remove(Component child) { 362 child.removeComponentListener(viewListener); 363 super.remove(child); 364 } 365 366 @Override 367 public void addNotify() { 368 super.addNotify(); 369 // JLightweightFrame does not support BLIT_SCROLL_MODE, so it should be replaced 370 Window rootWindow = SwingUtilities.getWindowAncestor(this); 371 if (rootWindow instanceof JLightweightFrame 372 && getScrollMode() == BLIT_SCROLL_MODE) { 373 setScrollMode(BACKINGSTORE_SCROLL_MODE); 374 } 375 } 376 377 378 /** 379 * Scrolls the view so that <code>Rectangle</code> 380 * within the view becomes visible. 381 * <p> 382 * This attempts to validate the view before scrolling if the 383 * view is currently not valid - <code>isValid</code> returns false. 384 * To avoid excessive validation when the containment hierarchy is 385 * being created this will not validate if one of the ancestors does not 386 * have a peer, or there is no validate root ancestor, or one of the 387 * ancestors is not a <code>Window</code> or <code>Applet</code>. 388 * <p> 389 * Note that this method will not scroll outside of the 390 * valid viewport; for example, if <code>contentRect</code> is larger 391 * than the viewport, scrolling will be confined to the viewport's 392 * bounds. 393 * 394 * @param contentRect the <code>Rectangle</code> to display 395 * @see JComponent#isValidateRoot 396 * @see java.awt.Component#isValid |