001    /**
002     * planningtool - A Planning Tool with Critiquing Support.
003     * 
004     * Copyright (C) 2006 olale
005    
006     * This program is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU General Public License
008     * as published by the Free Software Foundation; either version 2
009     * of the License, or (at your option) any later version.
010    
011     * This program is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     * GNU General Public License for more details.
015    
016     * You should have received a copy of the GNU General Public License
017     * along with this program; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019    
020     * Contact information: 
021     * E-mail: olale@ida.liu.se
022     *         olale@lysator.liu.se
023     */
024    package se.liu.ida.critiquer.activities.parameters;
025    
026    import java.io.Serializable;
027    import java.text.DateFormat;
028    import java.util.Calendar;
029    import java.util.GregorianCalendar;
030    
031    import se.liu.ida.critiquer.activities.Activity;
032    /**
033     * Parameter that holds a Calendar value. Used for start and end time of activities.
034     * 
035     * @author olale
036     *
037     */
038    public class TimeParameter extends ActivityParameter<Calendar>
039                    implements Serializable {
040    
041            public enum Type {
042                    
043                    START("start"),
044                    END("end");
045                    
046                    private String name;
047                    Type(String name) {
048                            this.name=name;
049                    }
050                    
051                    public String getName() {
052                            return name;
053                    }
054            }
055            
056            /**
057             * 
058             */
059            private static final long serialVersionUID = 1L;
060    
061            private boolean editable;
062    
063            private Type type;
064    
065            public TimeParameter(String name, Type type, Activity a) {
066                    super(name, a);
067                    this.type=type;
068                    init();
069            }
070    
071            private void init() {
072                    value = new GregorianCalendar();
073                    setEditable(true);
074    
075            }
076    
077            public int getHour() {
078                    return value.get(Calendar.HOUR_OF_DAY);
079            }
080    
081            public int getMinute() {
082                    return value.get(Calendar.MINUTE);
083            }
084    
085            @Override
086            public String toString() {
087                    return getName()
088                                    + ": "
089                                    + DateFormat.getTimeInstance(DateFormat.SHORT).format(
090                                                    value.getTime());
091            }
092    
093            /**
094             * @return Returns the editable.
095             */
096            public boolean isEditable() {
097                    return editable;
098            }
099    
100            /**
101             * @param editable
102             *            The editable to set.
103             */
104            public void setEditable(boolean editable) {
105                    this.editable = editable;
106    
107            }
108    
109            public String getFullName() {
110                    return "[" + getActivity() + " " + getName() + "]";
111            }
112    
113            /**
114             * @return Returns the type.
115             */
116            public Type getType() {
117                    return type;
118            }
119    
120    }