001 /*
002 * $Id: ProgressEvent.java,v 1.2 2005/10/10 18:03:07 rbair Exp $
003 *
004 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005 * Santa Clara, California 95054, U.S.A. All rights reserved.
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
020 */
021
022 package org.jdesktop.swingx.event;
023
024 /**
025 * A MessageEvent that represents the cycle of a long running operation.
026 * Use the constructors to indicate the stage of the operation.
027 *
028 * @author Mark Davidson
029 */
030 public class ProgressEvent extends MessageEvent {
031
032 private int minimum;
033 private int maximum;
034 private int progress;
035
036 private boolean indeterminate = true;
037
038 /**
039 * Constructs an indeterminate progress event.
040 */
041 public ProgressEvent(Object source) {
042 super(source);
043 }
044
045 /**
046 * Constructs a progress event used to indicate an increment of progress.
047 *
048 * @param source the object which orignated the event
049 * @param progress the value between min and max which indicates
050 * the progression of the operation.
051 */
052 public ProgressEvent(Object source, int progress) {
053 super(source);
054 this.progress = progress;
055 setIndeterminate(false);
056 }
057
058 /**
059 * Constructs a ProgressEvent which indicates the beginning of a long operation.
060 * For a determinite progress operation, the minimum value should be less than
061 * the maximum value. For indterminate operations, set minimum equal to maximum.
062 *
063 * @param source the object which orignated the event
064 * @param min the minimum value of the progress operation
065 * @param max the maximum value of the progress operation
066 */
067 public ProgressEvent(Object source, int min, int max) {
068 super(source);
069 setMaximum(max);
070 setMinimum(min);
071 setIndeterminate(max == min);
072 }
073
074 private void setMaximum(int max) {
075 this.maximum = max;
076 }
077
078 public int getMaximum() {
079 return maximum;
080 }
081
082 private void setMinimum(int min) {
083 this.minimum = min;
084 }
085
086 public int getMinimum() {
087 return minimum;
088 }
089
090 private void setIndeterminate(boolean indeterminate) {
091 this.indeterminate = indeterminate;
092 }
093
094 public boolean isIndeterminate() {
095 return indeterminate;
096 }
097
098 public int getProgress() {
099 return progress;
100 }
101 }