KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > utils > LoadOnShowListener


1 /*
2  * $Id: LoadOnShowListener.java,v 1.2 2005/01/27 13:32:04 kleopatra Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.swing.utils;
9
10 import java.awt.Component JavaDoc;
11 import java.awt.event.HierarchyEvent JavaDoc;
12 import java.awt.event.HierarchyListener JavaDoc;
13
14 import java.io.IOException JavaDoc;
15
16 // XXX msd: could be a circular dependencie
17
import org.jdesktop.swing.data.DefaultTableModelExt;
18
19 /**
20  * Listener which may be registered on a user interface component
21  * so that the specified data model object will start loading its
22  * data when the component is first made visible on the screen.
23  * @author Amy Fowler
24  * @version 1.0
25  */

26 public class LoadOnShowListener implements HierarchyListener JavaDoc {
27     private DefaultTableModelExt data;
28     public LoadOnShowListener(DefaultTableModelExt data) {
29         this.data = data;
30     }
31     public void hierarchyChanged(HierarchyEvent JavaDoc event) {
32         Component JavaDoc component = (Component JavaDoc)event.getComponent();
33         if ((event.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0 &&
34             component.isShowing()) {
35             try {
36                 data.startLoading();
37             } catch (IOException JavaDoc e) {
38                 //REMIND(aim): invoke app exception handler
39
System.out.println("could not load data: "+e.getMessage());
40                 e.printStackTrace();
41             }
42         }
43     }
44 }
45
Popular Tags