[jsword-svn] r2156 - in trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop: book passage
dmsmith at crosswire.org
dmsmith at crosswire.org
Sat Apr 9 09:21:19 MST 2011
Author: dmsmith
Date: 2011-04-09 09:21:19 -0700 (Sat, 09 Apr 2011)
New Revision: 2156
Modified:
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModel.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModelSet.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/WholeBibleTreeNode.java
Log:
Converted some magic numbers to Java 5 Enums
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModel.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModel.java 2011-04-09 16:15:35 UTC (rev 2155)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModel.java 2011-04-09 16:21:19 UTC (rev 2156)
@@ -42,14 +42,34 @@
*/
public class BibleComboBoxModel extends AbstractListModel implements ComboBoxModel {
/**
+ * The level of the book combo.
+ */
+ protected enum Level {
+ /**
+ * For when the we are a book level combo
+ */
+ BOOK,
+
+ /**
+ * For when the we are a chapter level combo
+ */
+ CHAPTER,
+
+ /**
+ * For when the we are a verse level combo
+ */
+ VERSE,
+ }
+
+ /**
* Simple ctor for choosing verses
*/
- protected BibleComboBoxModel(BibleComboBoxModelSet set, int level) {
+ protected BibleComboBoxModel(BibleComboBoxModelSet set, Level level) {
this.set = set;
this.level = level;
switch (level) {
- case LEVEL_BOOK:
+ case BOOK:
try {
selected = set.getVerse().getBook().getBookName();
} catch (NoSuchVerseException ex) {
@@ -57,11 +77,11 @@
}
break;
- case LEVEL_CHAPTER:
+ case CHAPTER:
selected = Integer.valueOf(set.getVerse().getChapter());
break;
- case LEVEL_VERSE:
+ case VERSE:
selected = Integer.valueOf(set.getVerse().getVerse());
break;
@@ -79,18 +99,18 @@
log.debug("setSelectedItem(" + selected + ") level=" + level);
switch (level) {
- case LEVEL_BOOK:
+ case BOOK:
BibleBook book = (BibleBook) selected;
assert book != null;
setBook(book);
break;
- case LEVEL_CHAPTER:
+ case CHAPTER:
Integer csel = (Integer) selected;
setChapter(csel.intValue());
break;
- case LEVEL_VERSE:
+ case VERSE:
Integer vsel = (Integer) selected;
setVerse(vsel.intValue());
break;
@@ -119,13 +139,13 @@
public int getSize() {
try {
switch (level) {
- case LEVEL_BOOK:
+ case BOOK:
return BibleInfo.booksInBible();
- case LEVEL_CHAPTER:
+ case CHAPTER:
return BibleInfo.chaptersInBook(set.getVerse().getBook());
- case LEVEL_VERSE:
+ case VERSE:
return BibleInfo.versesInChapter(set.getVerse().getBook(), set.getVerse().getChapter());
default:
@@ -145,7 +165,7 @@
*/
public Object getElementAt(int index) {
switch (level) {
- case LEVEL_BOOK:
+ case BOOK:
BibleBook[] books = BibleInfo.getBooks();
return books[index];
@@ -240,21 +260,6 @@
private static final Logger log = Logger.getLogger(BibleComboBoxModel.class);
/**
- * For when the we are a book level combo
- */
- public static final int LEVEL_BOOK = 0;
-
- /**
- * For when the we are a chapter level combo
- */
- public static final int LEVEL_CHAPTER = 1;
-
- /**
- * For when the we are a verse level combo
- */
- public static final int LEVEL_VERSE = 2;
-
- /**
* Shared settings
*/
private transient BibleComboBoxModelSet set;
@@ -267,7 +272,7 @@
/**
* Are we a book, chapter or verse selector
*/
- protected int level;
+ protected Level level;
/**
* Serialization ID
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModelSet.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModelSet.java 2011-04-09 16:15:35 UTC (rev 2155)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModelSet.java 2011-04-09 16:21:19 UTC (rev 2156)
@@ -51,14 +51,14 @@
listeners = new EventListenerList();
cil = new CustomItemListener();
- mdlBook = new BibleComboBoxModel(this, BibleComboBoxModel.LEVEL_BOOK);
+ mdlBook = new BibleComboBoxModel(this, BibleComboBoxModel.Level.BOOK);
setBookComboBox(books);
- mdlChapter = new BibleComboBoxModel(this, BibleComboBoxModel.LEVEL_CHAPTER);
+ mdlChapter = new BibleComboBoxModel(this, BibleComboBoxModel.Level.CHAPTER);
setChapterComboBox(chapters);
if (verses != null) {
- mdlVerse = new BibleComboBoxModel(this, BibleComboBoxModel.LEVEL_VERSE);
+ mdlVerse = new BibleComboBoxModel(this, BibleComboBoxModel.Level.VERSE);
setVerseComboBox(verses);
}
}
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java 2011-04-09 16:15:35 UTC (rev 2155)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java 2011-04-09 16:21:19 UTC (rev 2156)
@@ -309,7 +309,7 @@
*/
public void clear() {
setKey(selected == null || selected.length == 0 ? new RocketPassage() : selected[0].createEmptyKeyList());
- setTitle(CLEAR);
+ setTitle(Mode.CLEAR);
}
/**
@@ -349,7 +349,7 @@
setKey(txtKey.getText());
if (!key.isEmpty()) {
txtSearch.setText("");
- setTitle(PASSAGE);
+ setTitle(Mode.PASSAGE);
}
}
@@ -409,7 +409,7 @@
// I18N(DMS): This needs support for singular/plural and to show internationalized numbers.
Reporter.informUser(this, BDMsg.gettext("Showing {1} of {2} verses with: {0}", param, Integer.toString(partial), Integer.toString(total)));
}
- setTitle(SEARCH);
+ setTitle(Mode.SEARCH);
setKey(results);
}
} catch (BookException ex) {
@@ -504,7 +504,7 @@
txtSearch.setText("");
updateDisplay();
- setTitle(CLEAR);
+ setTitle(Mode.CLEAR);
}
} else if (!newKey.equals(key)) {
key = newKey;
@@ -512,7 +512,7 @@
txtKey.setText(text);
updateDisplay();
if (isClear()) {
- setTitle(PASSAGE);
+ setTitle(Mode.PASSAGE);
txtSearch.setText("");
}
}
@@ -565,8 +565,8 @@
maxNumRankedVerses = count;
}
- private void setTitle(int newMode) {
- mode = newMode;
+ private void setTitle(Mode clear) {
+ mode = clear;
switch (mode) {
case CLEAR:
// TRANSLATOR: This is the initial title of a Bible View. {0} is a placeholder for a number that uniquely identifies the Bible View.
@@ -582,7 +582,7 @@
assert false;
}
if (title.length() == 0) {
- setTitle(CLEAR);
+ setTitle(Mode.CLEAR);
} else {
fireTitleChanged(new TitleChangedEvent(this, title));
}
@@ -803,13 +803,15 @@
private AdvancedSearchPane advanced;
private JButton btnIndex;
+ private enum Mode {
+ CLEAR,
+ PASSAGE,
+ SEARCH,
+ }
/**
* The current state of the display: SEARCH, PASSAGE, CLEAR
*/
- private int mode;
- private static final int CLEAR = 0;
- private static final int PASSAGE = 1;
- private static final int SEARCH = 2;
+ private Mode mode;
/**
* The current passage.
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/WholeBibleTreeNode.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/WholeBibleTreeNode.java 2011-04-09 16:15:35 UTC (rev 2155)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/WholeBibleTreeNode.java 2011-04-09 16:21:19 UTC (rev 2156)
@@ -45,7 +45,7 @@
* The start point for all WholeBibleTreeNodes.
*/
public static WholeBibleTreeNode getRootNode() {
- return new WholeBibleTreeNode(null, VerseRange.getWholeBibleVerseRange(), LEVEL_BIBLE);
+ return new WholeBibleTreeNode(null, VerseRange.getWholeBibleVerseRange(), Level.BIBLE);
}
/**
@@ -55,23 +55,23 @@
try {
Verse start = null;
Verse end = null;
- int thislevel = 1;
+ Level thislevel = Level.BOOK;
if (b == null) {
assert false : b;
} else if (c == -1) {
- thislevel = LEVEL_BOOK;
+ thislevel = Level.BOOK;
int ec = BibleInfo.chaptersInBook(b);
int ev = BibleInfo.versesInChapter(b, ec);
start = new Verse(b, 1, 1);
end = new Verse(b, ec, ev);
} else if (v == -1) {
- thislevel = LEVEL_CHAPTER;
+ thislevel = Level.CHAPTER;
int ev = BibleInfo.versesInChapter(b, c);
start = new Verse(b, c, 1);
end = new Verse(b, c, ev);
} else {
- thislevel = LEVEL_VERSE;
+ thislevel = Level.VERSE;
start = new Verse(b, c, v);
end = start;
}
@@ -87,7 +87,7 @@
/**
* This constructor is for when we are really a BookTreeNode
*/
- private WholeBibleTreeNode(TreeNode parent, VerseRange range, int level) {
+ private WholeBibleTreeNode(TreeNode parent, VerseRange range, Level level) {
if (parent != null) {
this.parent = parent;
} else {
@@ -117,14 +117,14 @@
* @see javax.swing.tree.TreeNode#getAllowsChildren()
*/
public boolean getAllowsChildren() {
- return level != LEVEL_VERSE;
+ return level != Level.VERSE;
}
/**
* @see javax.swing.tree.TreeNode#isLeaf()
*/
public boolean isLeaf() {
- return level == LEVEL_VERSE;
+ return level == Level.VERSE;
}
/**
@@ -134,17 +134,17 @@
public String toString() {
try {
switch (level) {
- case LEVEL_BIBLE:
+ case BIBLE:
// TRANSLATOR: The top level of the tree of Bible books, chapters and verses.
return BDMsg.gettext("The Bible");
- case LEVEL_BOOK:
+ case BOOK:
return range.getStart().getBook().getPreferredName();
- case LEVEL_CHAPTER:
+ case CHAPTER:
return shaper.shape(Integer.toString(range.getStart().getChapter()));
- case LEVEL_VERSE:
+ case VERSE:
return shaper.shape(Integer.toString(range.getStart().getVerse()));
default:
@@ -162,14 +162,14 @@
*/
public TreeNode getChildAt(int i) {
switch (level) {
- case LEVEL_BIBLE:
+ case BIBLE:
BibleBook[] books = BibleInfo.getBooks();
return WholeBibleTreeNode.getNode(this, books[i], -1, -1);
- case LEVEL_BOOK:
+ case BOOK:
return WholeBibleTreeNode.getNode(this, range.getStart().getBook(), i + 1, -1);
- case LEVEL_CHAPTER:
+ case CHAPTER:
return WholeBibleTreeNode.getNode(this, range.getStart().getBook(), range.getStart().getChapter(), i + 1);
default:
@@ -184,13 +184,13 @@
public int getChildCount() {
try {
switch (level) {
- case LEVEL_BIBLE:
+ case BIBLE:
return BibleInfo.booksInBible();
- case LEVEL_BOOK:
+ case BOOK:
return BibleInfo.chaptersInBook(range.getStart().getBook());
- case LEVEL_CHAPTER:
+ case CHAPTER:
return BibleInfo.versesInChapter(range.getStart().getBook(), range.getStart().getChapter());
default:
@@ -214,13 +214,13 @@
WholeBibleTreeNode vnode = (WholeBibleTreeNode) node;
switch (level) {
- case LEVEL_BIBLE:
+ case BIBLE:
return vnode.getVerseRange().getStart().getBook().ordinal();
- case LEVEL_BOOK:
+ case BOOK:
return vnode.getVerseRange().getStart().getChapter() - 1;
- case LEVEL_CHAPTER:
+ case CHAPTER:
return vnode.getVerseRange().getStart().getVerse() - 1;
default:
@@ -255,10 +255,12 @@
private int count;
}
- private static final int LEVEL_BIBLE = 0;
- private static final int LEVEL_BOOK = 1;
- private static final int LEVEL_CHAPTER = 2;
- private static final int LEVEL_VERSE = 3;
+ private enum Level {
+ BIBLE,
+ BOOK,
+ CHAPTER,
+ VERSE,
+ }
/** Change the number representation as needed */
private NumberShaper shaper;
@@ -270,5 +272,5 @@
private TreeNode parent;
/** The level of this node one of: LEVEL_[BIBLE|BOOK|CHAPTER|VERSE] */
- private int level;
+ private Level level;
}
More information about the jsword-svn
mailing list