View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.example.demo;
21  
22  import javax.enterprise.context.SessionScoped;
23  import javax.faces.event.FacesEvent;
24  import javax.inject.Named;
25  import javax.swing.DefaultBoundedRangeModel;
26  import java.io.Serializable;
27  import java.text.SimpleDateFormat;
28  import java.util.Date;
29  
30  @SessionScoped
31  @Named
32  public class ProgressController implements Serializable {
33  
34    private DefaultBoundedRangeModel progress = new DefaultBoundedRangeModel(3, 0, 0, 5);
35  
36    public DefaultBoundedRangeModel getProgress() {
37      return progress;
38    }
39  
40    public void addProgress() {
41      final int value = progress.getValue();
42  
43      if (value >= progress.getMaximum()) {
44        progress.setValue(0);
45      } else {
46        progress.setValue(value + 1);
47      }
48    }
49  
50    public void resetProgress(final FacesEvent event) {
51      progress.setValue(0);
52    }
53  
54    public Date getCurrentDate() {
55      return new Date();
56    }
57  
58    public double getCurrentHours() {
59      final SimpleDateFormat sdf = new SimpleDateFormat("HH");
60      return Double.valueOf(sdf.format(getCurrentDate()));
61    }
62  
63    public double getCurrentMinutes() {
64      final SimpleDateFormat sdf = new SimpleDateFormat("mm");
65      return Double.valueOf(sdf.format(getCurrentDate()));
66    }
67  
68    public double getCurrentSeconds() {
69      final SimpleDateFormat sdf = new SimpleDateFormat("ss");
70      return Double.valueOf(sdf.format(getCurrentDate()));
71    }
72  }