BrightSide Workbench Full Report + Source Code
MonthListbox.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.zkoss.input;
20 
21 import java.text.DateFormatSymbols;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.TreeSet;
25 import org.turro.string.Strings;
26 import org.turro.elephant.context.Application;
27 import org.turro.util.PhraseBuilder;
28 
33 public class MonthListbox extends CollectionListbox<Integer> {
34 
35  DateFormatSymbols dfs = DateFormatSymbols.getInstance(Application.getUsedLocale());
36 
37  public MonthListbox() {
38  TreeSet<Integer> months = new TreeSet<Integer>();
39  for(int d = 1; d <= 12; d++) {
40  months.add(d);
41  }
42  setCollection(months);
43  setMultiple(true);
44  setCheckmark(true);
45  setSelectFirst(false);
46  }
47 
48  @Override
49  protected String convertToString(Integer v) {
50  return Strings.capitalize(dfs.getMonths()[v - 1]);
51  }
52 
53  public void selectItemByText(String value) {
54  String[] va = value == null ? null : value.split(",");
55  ArrayList<Integer> ali = new ArrayList<Integer>();
56  for(String v : va) {
57  ali.add(Integer.valueOf(v.trim()));
58  }
59  setObjectValues(ali);
60  }
61 
62  public String getStringValues() {
63  return getStringValues(getObjectValues());
64  }
65 
66  public static String getStringValues(Collection<Integer> values) {
67  PhraseBuilder pb = new PhraseBuilder();
68  for(Integer i : values) {
69  pb.addWord(i.toString());
70  pb.addPendingSeparator(", ");
71  }
72  return pb.toString();
73  }
74 
75 }
static String getStringValues(Collection< Integer > values)