KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > progress > spi > ProgressEvent


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
21 package org.netbeans.progress.spi;
22
23 /**
24  *
25  * @author Milos Kleint (mkleint@netbeans.org)
26  */

27 public final class ProgressEvent {
28
29     public static final int TYPE_START = 0;
30     public static final int TYPE_FINISH = 4;
31     public static final int TYPE_REQUEST_STOP = 3;
32     public static final int TYPE_PROGRESS = 1;
33     public static final int TYPE_SWITCH = 5;
34     public static final int TYPE_SILENT = 6;
35
36      private InternalHandle source;
37      private long estimatedCompletion;
38      private int percentageDone;
39      private int workunitsDone;
40      private String JavaDoc message;
41      private int type;
42      private boolean watched;
43      private boolean switched;
44      private String JavaDoc displayName;
45
46     /** Creates a new instance of ProgressEvent
47      * @param type one of TYPE_START, TYPE_REQUEST_STOP, TYPE_FINISH, TYPE_SWITCHED
48      */

49     public ProgressEvent(InternalHandle src, int type, boolean isWatched) {
50         source = src;
51         estimatedCompletion = -1;
52         percentageDone = -1;
53         workunitsDone = -1;
54         message = null;
55         this.type = type;
56         watched = isWatched;
57         switched = (type == TYPE_SWITCH);
58     }
59     
60     /** Creates a new instance of ProgressEvent
61      * @param type one of TYPE_SILENT
62      */

63     public ProgressEvent(InternalHandle src, int type, boolean isWatched, String JavaDoc msg) {
64         this(src, type, isWatched);
65         message = msg;
66     }
67     /**
68      * @param percentage completed work percentage
69      * @param estimate estimate of completion in seconds
70      */

71     public ProgressEvent(InternalHandle src, String JavaDoc msg, int units, int percentage, long estimate, boolean isWatched) {
72         this(src, TYPE_PROGRESS, isWatched);
73         workunitsDone = units;
74         percentageDone = percentage;
75         estimatedCompletion = estimate;
76         message = msg;
77     }
78     public ProgressEvent(InternalHandle src, String JavaDoc msg, int units, int percentage, long estimate, boolean isWatched, String JavaDoc displayName) {
79         this(src, msg, units, percentage, estimate, isWatched);
80         this.displayName = displayName;
81     }
82     
83     public InternalHandle getSource() {
84         return source;
85     }
86
87     public long getEstimatedCompletion() {
88         return estimatedCompletion;
89     }
90
91     public int getPercentageDone() {
92         return percentageDone;
93     }
94
95     public int getWorkunitsDone() {
96         return workunitsDone;
97     }
98
99     public String JavaDoc getMessage() {
100         return message;
101     }
102
103     public int getType() {
104         return type;
105     }
106     
107     public boolean isWatched() {
108         return watched;
109     }
110     
111     /**
112      * used in controller, preserve dynamic message from earlier events
113      * if this one doesn't have it's own.
114      */

115     public void copyMessageFromEarlier(ProgressEvent last) {
116         if (message == null) {
117             message = last.getMessage();
118         }
119         if (displayName == null) {
120             displayName = last.getDisplayName();
121         }
122     }
123     
124     public void markAsSwitched() {
125         switched = true;
126     }
127     
128     public boolean isSwitched() {
129         return switched;
130     }
131     
132     public String JavaDoc getDisplayName() {
133         return displayName;
134     }
135     
136 }
137
Popular Tags