source: trunk/src/org/expeditee/items/Justification.java@ 1450

Last change on this file since 1450 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 1.9 KB
Line 
1/**
2 * Justification.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU 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 General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.items;
20
21public enum Justification {
22 center, full, left, right;
23
24 /**
25 * Converts the given Expeditee justification code into a int corresponding
26 * to the constants defined in Item.
27 *
28 * @param justCode
29 * The Expeditee justification code to convert
30 * @return The resulting int corresponding to one of the constants defined
31 * in Item
32 */
33 public static Justification convertString(String justCode) {
34 assert (justCode != null);
35 justCode = justCode.trim().toLowerCase();
36
37 // if it is a single char just match the first character
38 if (justCode.length() == 1) {
39 char code = justCode.charAt(0);
40 Justification[] values = values();
41 for (int i = 0; i < values.length; i++) {
42 Justification j = values[i];
43 if (Character.toLowerCase(j.name().charAt(0)) == code)
44 return j;
45 }
46 // Otherwise match the whole string
47 } else {
48 try {
49 return valueOf(justCode);
50 } catch (Exception e) {
51 }
52 }
53
54 // default justification
55 return left;
56 }
57
58 public char getCode() {
59 return Character.toUpperCase(this.toString().charAt(0));
60 }
61
62 public String toString() {
63 return this.name();
64 }
65}
Note: See TracBrowser for help on using the repository browser.