KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > progress > ProgressHandleFactory


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.progress;
21
22 import javax.swing.Action JavaDoc;
23 import javax.swing.JComponent JavaDoc;
24 import javax.swing.JLabel JavaDoc;
25 import org.netbeans.progress.spi.InternalHandle;
26 import org.openide.util.Cancellable;
27
28 /**
29  * Factory to create various ProgressHandle instances that allow long lasting
30  * tasks to show their progress using various progress UIs.
31  *
32  * @author Milos Kleint (mkleint@netbeans.org)
33  */

34 public final class ProgressHandleFactory {
35
36     /** Creates a new instance of ProgressIndicatorFactory */
37     private ProgressHandleFactory() {
38     }
39
40     /**
41      * Create a progress ui handle for a long lasting task.
42      * @param displayName to be shown in the progress UI
43      * @return an instance of {@link org.netbeans.api.progress.ProgressHandle}, initialized but not started.
44      */

45     public static ProgressHandle createHandle(String JavaDoc displayName) {
46         return createHandle(displayName, null, null);
47     }
48     
49     /**
50      * Create a progress ui handle for a long lasting task.
51      * @param allowToCancel either null, if the task cannot be cancelled or
52      * an instance of {@link org.openide.util.Cancellable} that will be called when user
53      * triggers cancel of the task.
54      * @param displayName to be shown in the progress UI
55      * @return an instance of {@link org.netbeans.api.progress.ProgressHandle}, initialized but not started.
56      */

57     public static ProgressHandle createHandle(String JavaDoc displayName, Cancellable allowToCancel) {
58         return createHandle(displayName, allowToCancel, null);
59     }
60
61     /**
62      * Create a progress ui handle for a long lasting task.
63      * @param linkOutput an <code>Action</code> instance that links the running task in the progress bar
64      * to an output of the task. The action is assumed to open the apropriate component with the task's output.
65      * @param displayName to be shown in the progress UI
66      * @return an instance of {@link org.netbeans.api.progress.ProgressHandle}, initialized but not started.
67      *
68      */

69     public static ProgressHandle createHandle(String JavaDoc displayName, Action JavaDoc linkOutput) {
70         return createHandle(displayName, null, linkOutput);
71     }
72     
73     /**
74      * Create a progress ui handle for a long lasting task.
75      * @param allowToCancel either null, if the task cannot be cancelled or
76      * an instance of {@link org.openide.util.Cancellable} that will be called when user
77      * triggers cancel of the task.
78      * @param linkOutput an <code>Action</code> instance that links the running task in the progress bar
79      * to an output of the task. The action is assumed to open the apropriate component with the task's output.
80      * @param displayName to be shown in the progress UI
81      * @return an instance of {@link org.netbeans.api.progress.ProgressHandle}, initialized but not started.
82      *
83      */

84     public static ProgressHandle createHandle(String JavaDoc displayName, Cancellable allowToCancel, Action JavaDoc linkOutput) {
85         return new ProgressHandle(new InternalHandle(displayName, allowToCancel, true, linkOutput));
86     }
87     
88     /**
89      * Get the progress bar component for use in custom dialogs, the task won't
90      * show in the progress bar anymore.
91      * @return the component to use in custom UI.
92      */

93     public static JComponent JavaDoc createProgressComponent(ProgressHandle handle) {
94         return handle.extractComponent();
95     }
96     
97     /**
98      * Get the task title component for use in custom dialogs, the task won't
99      * show in the progress bar anymore. The text of the label is changed by calls to <code>ProgressHandle.setDisplayName()</code> method
100      * @return the component to use in custom UI.
101      * @since org.netbeans.api.progress 1.8
102      */

103     public static JLabel JavaDoc createMainLabelComponent(ProgressHandle handle) {
104         return handle.extractMainLabel();
105     }
106     
107     /**
108      * Get the detail messages component for use in custom dialogs, the task won't
109      * show in the progress bar anymore. The text of the label is changed by calls to <code>ProgressHandle.progress(String)</code> method.
110      * @return the component to use in custom UI.
111      * @since org.netbeans.api.progress 1.8
112      */

113     public static JLabel JavaDoc createDetailLabelComponent(ProgressHandle handle) {
114         return handle.extractDetailLabel();
115     }
116     
117     /**
118      * Create a handle for a long lasting task that is not triggered by explicit user action.
119      * Such tasks have lower priority in the UI.
120      * @param displayName to be shown in the progress UI
121      * @return an instance of {@link org.netbeans.api.progress.ProgressHandle}, initialized but not started.
122      */

123     public static ProgressHandle createSystemHandle(String JavaDoc displayName) {
124         return createSystemHandle(displayName, null);
125     }
126
127     /**
128      * Create a cancelable handle for a task that is not triggered by explicit user action.
129      * Such tasks have lower priority in the UI.
130      * @param displayName to be shown in the progress UI
131      * @param allowToCancel either null, if the task cannot be cancelled or
132      * an instance of {@link org.openide.util.Cancellable} that will be called when user
133      * triggers cancel of the task.
134      * @return an instance of {@link org.netbeans.api.progress.ProgressHandle}, initialized but not started.
135      */

136     public static ProgressHandle createSystemHandle(String JavaDoc displayName, Cancellable allowToCancel) {
137         return new ProgressHandle(new InternalHandle(displayName, allowToCancel, false, null));
138     }
139     
140     /**
141      * Create a progress ui handle for a task that is not triggered by explicit user action.
142      * @param allowToCancel either null, if the task cannot be cancelled or
143      * an instance of {@link org.openide.util.Cancellable} that will be called when user
144      * triggers cancel of the task.
145      * @param linkOutput an <code>Action</code> instance that links the running task in the progress bar
146      * to an output of the task. The action is assumed to open the apropriate component with the task's output.
147      * @param displayName to be shown in the progress UI
148      * @return an instance of {@link org.netbeans.api.progress.ProgressHandle}, initialized but not started.
149      *
150      */

151     public static ProgressHandle createSystemHandle(String JavaDoc displayName, Cancellable allowToCancel, Action JavaDoc linkOutput) {
152         return new ProgressHandle(new InternalHandle(displayName, allowToCancel, false, linkOutput));
153     }
154     
155 }
156
Popular Tags