001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.ui.support.wizard;
043:
044: import org.netbeans.modules.uml.common.ETSystem;
045: import org.netbeans.modules.uml.ui.support.ProductHelper;
046: import org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface;
047:
048: import java.awt.event.ComponentEvent;
049: import java.awt.event.ComponentListener;
050:
051: import java.awt.Component;
052: import java.awt.Cursor;
053: import java.awt.Frame;
054:
055: /**
056: * @author KevinM
057: *
058: */
059: public abstract class ETModalWizardThread {
060: protected Thread m_pThread = null;
061: protected Runnable m_pRunnable = null;
062: protected boolean m_bLockFrameInput = true;
063:
064: /**
065: * @param target
066: */
067: public ETModalWizardThread(Runnable target) {
068: super ();
069: m_pRunnable = target;
070: }
071:
072: /*
073: * Protected constructor this class is abstract, and you need a runnable to use the start method.
074: */
075: protected ETModalWizardThread() {
076: super ();
077: }
078:
079: protected Thread getThread() {
080: return m_pThread;
081: }
082:
083: /*
084: *
085: * @author KevinM
086: *
087: * This class watches for componenet to be moved and it repaints the
088: * parent frame windows, when the component is hidden it reenables the frame window so it will except input.
089: */
090: public class ProgreessMoveListener implements ComponentListener {
091: public ProgreessMoveListener() {
092: super ();
093: }
094:
095: /**
096: * Invoked when the component's size changes.
097: */
098: public void componentResized(ComponentEvent e) {
099: ETSystem.out
100: .println("ETModalWizardThread componentResized");
101: repaintFrame();
102: }
103:
104: /**
105: * Invoked when the component's position changes.
106: */
107: public void componentMoved(ComponentEvent e) {
108: ETSystem.out.println("ETModalWizardThread componentMoved");
109: repaintFrame();
110: }
111:
112: /**
113: * Invoked when the component has been made visible.
114: */
115: public void componentShown(ComponentEvent e) {
116: ETSystem.out.println("ETModalWizardThread componentShown");
117: repaintFrame();
118: }
119:
120: /**
121: * Invoked when the component has been made invisible.
122: */
123: public void componentHidden(ComponentEvent e) {
124: ETSystem.out.println("ETModalWizardThread componentHidden");
125:
126: if (m_bLockFrameInput && getOwnerFrame() != null) {
127: getOwnerFrame().setEnabled(true);
128: getOwnerFrame().setVisible(true);
129: getOwnerFrame()
130: .setCursor(
131: Cursor
132: .getPredefinedCursor(Cursor.DEFAULT_CURSOR));
133: }
134:
135: if (e != null)
136: e.getComponent().removeComponentListener(this );
137: }
138:
139: /*
140: * Redraws the frame window when the component moves or is resized to fix the Tracks.
141: */
142: protected void repaintFrame() {
143: Frame frame = getOwnerFrame();
144: if (frame != null) {
145: // Fix the Tracks on the frame window.
146: frame.invalidate();
147: Thread currentThread = Thread.currentThread();
148: if (currentThread == ETModalWizardThread.this
149: .getThread())
150: currentThread.yield();
151: }
152: }
153: };
154:
155: /*
156: * Returns the main integration app frmae.
157: */
158: protected Frame getOwnerFrame() {
159: IProxyUserInterface ui = ProductHelper.getProxyUserInterface();
160: return ui != null ? ui.getWindowHandle() : null;
161: }
162:
163: /*
164: * Start the thread and invoke the Runnable
165: */
166: public void start() {
167: start(m_bLockFrameInput);
168: }
169:
170: /*
171: * Strat the Runnable and disables the application frame until the thread is complete.
172: */
173: public void start(boolean lockTheFrame) {
174: // if (getRunnable() != null)
175: // getRunnable().run();
176:
177: m_bLockFrameInput = lockTheFrame;
178: if (getRunnable() != null) {
179: Thread reportThread = new Thread(getRunnable());
180: reportThread.setPriority(this .getDefaultPrioity());
181:
182: // disable the integration frame, so the dialog pumps msg's but it acts modal.
183: if (m_bLockFrameInput && getOwnerFrame() != null) {
184: getOwnerFrame().setEnabled(false);
185: }
186:
187: reportThread.start();
188: Component pWizardComponent = getComponent();
189:
190: if (pWizardComponent != null) {
191: pWizardComponent
192: .addComponentListener(new ProgreessMoveListener());
193: } else if (getOwnerFrame() != null) {
194: // Make sure the frame isn't locked up.
195: getOwnerFrame().setEnabled(true);
196: getOwnerFrame().setVisible(true);
197: }
198: }
199:
200: }
201:
202: protected int getDefaultPrioity() {
203: return java.lang.Thread.NORM_PRIORITY;
204: }
205:
206: /*
207: * Return your progress bar component.
208: */
209: protected abstract Component getComponent();
210:
211: /*
212: * Retuns the action interface to invoke from the the start method.
213: */
214: protected Runnable getRunnable() {
215: return m_pRunnable;
216: }
217: }
|