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-2006 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.progress.spi;
043:
044: /**
045: *
046: * @author Milos Kleint (mkleint@netbeans.org)
047: */
048: public final class ProgressEvent {
049:
050: public static final int TYPE_START = 0;
051: public static final int TYPE_FINISH = 4;
052: public static final int TYPE_REQUEST_STOP = 3;
053: public static final int TYPE_PROGRESS = 1;
054: public static final int TYPE_SWITCH = 5;
055: public static final int TYPE_SILENT = 6;
056:
057: private InternalHandle source;
058: private long estimatedCompletion;
059: private double percentageDone;
060: private int workunitsDone;
061: private String message;
062: private int type;
063: private boolean watched;
064: private boolean switched;
065: private String displayName;
066:
067: /** Creates a new instance of ProgressEvent
068: * @param type one of TYPE_START, TYPE_REQUEST_STOP, TYPE_FINISH, TYPE_SWITCHED
069: */
070: public ProgressEvent(InternalHandle src, int type, boolean isWatched) {
071: source = src;
072: estimatedCompletion = -1;
073: percentageDone = -1;
074: workunitsDone = -1;
075: message = null;
076: this .type = type;
077: watched = isWatched;
078: switched = (type == TYPE_SWITCH);
079: }
080:
081: /** Creates a new instance of ProgressEvent
082: * @param type one of TYPE_SILENT
083: */
084: public ProgressEvent(InternalHandle src, int type,
085: boolean isWatched, String msg) {
086: this (src, type, isWatched);
087: message = msg;
088: }
089:
090: /**
091: * @param percentage completed work percentage
092: * @param estimate estimate of completion in seconds
093: */
094: public ProgressEvent(InternalHandle src, String msg, int units,
095: double percentage, long estimate, boolean isWatched) {
096: this (src, TYPE_PROGRESS, isWatched);
097: workunitsDone = units;
098: percentageDone = percentage;
099: estimatedCompletion = estimate;
100: message = msg;
101: }
102:
103: public ProgressEvent(InternalHandle src, String msg, int units,
104: double percentage, long estimate, boolean isWatched,
105: String displayName) {
106: this (src, msg, units, percentage, estimate, isWatched);
107: this .displayName = displayName;
108: }
109:
110: public InternalHandle getSource() {
111: return source;
112: }
113:
114: public long getEstimatedCompletion() {
115: return estimatedCompletion;
116: }
117:
118: public double getPercentageDone() {
119: return percentageDone;
120: }
121:
122: public int getWorkunitsDone() {
123: return workunitsDone;
124: }
125:
126: public String getMessage() {
127: return message;
128: }
129:
130: public int getType() {
131: return type;
132: }
133:
134: public boolean isWatched() {
135: return watched;
136: }
137:
138: /**
139: * used in controller, preserve dynamic message from earlier events
140: * if this one doesn't have it's own.
141: */
142: public void copyMessageFromEarlier(ProgressEvent last) {
143: if (message == null) {
144: message = last.getMessage();
145: }
146: if (displayName == null) {
147: displayName = last.getDisplayName();
148: }
149: }
150:
151: public void markAsSwitched() {
152: switched = true;
153: }
154:
155: public boolean isSwitched() {
156: return switched;
157: }
158:
159: public String getDisplayName() {
160: return displayName;
161: }
162:
163: }
|