[919] | 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 |
|
---|
[108] | 19 | package org.expeditee.items;
|
---|
| 20 |
|
---|
| 21 | public enum Justification {
|
---|
[147] | 22 | center, full, left, right;
|
---|
[108] | 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 | */
|
---|
[427] | 33 | public static Justification convertString(String justCode) {
|
---|
[108] | 34 | assert (justCode != null);
|
---|
| 35 | justCode = justCode.trim().toLowerCase();
|
---|
[348] | 36 |
|
---|
[108] | 37 | // if it is a single char just match the first character
|
---|
| 38 | if (justCode.length() == 1) {
|
---|
[348] | 39 | char code = justCode.charAt(0);
|
---|
[108] | 40 | Justification[] values = values();
|
---|
[348] | 41 | for (int i = 0; i < values.length; i++) {
|
---|
[108] | 42 | Justification j = values[i];
|
---|
[348] | 43 | if (Character.toLowerCase(j.name().charAt(0)) == code)
|
---|
[108] | 44 | return j;
|
---|
| 45 | }
|
---|
| 46 | // Otherwise match the whole string
|
---|
[348] | 47 | } else {
|
---|
| 48 | try {
|
---|
| 49 | return valueOf(justCode);
|
---|
| 50 | } catch (Exception e) {
|
---|
[108] | 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | // default justification
|
---|
[147] | 55 | return left;
|
---|
[108] | 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 | }
|
---|