[jsword-svn] r1850 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/book bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop bibledesktop/src/main/resources common common/src/main/java/org/crosswire/common/util common-swing/src/main/java/org/crosswire/common/config/swing common-swing/src/main/java/org/crosswire/common/swing jsword/src/main/java/org/crosswire/jsword/book/install jsword/src/main/java/org/crosswire/jsword/book/install/sword jsword/src/main/java/org/crosswire/jsword/book/sword jsword/src/main/java/org/crosswire/jsword/index/lucene jsword/src/main/java/org/crosswire/jsword/util jsword/src/test/java/org/crosswire/jsword/book jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Sat May 10 11:34:04 MST 2008
Author: dmsmith
Date: 2008-05-10 11:34:02 -0700 (Sat, 10 May 2008)
New Revision: 1850
Added:
trunk/common-swing/src/main/java/org/crosswire/common/swing/CWOptionPane.java
trunk/common-swing/src/main/java/org/crosswire/common/swing/CWOptionPane.properties
trunk/common/src/main/java/org/crosswire/common/util/CWProject.java
trunk/common/src/main/java/org/crosswire/common/util/Translations.java
trunk/common/src/main/java/org/crosswire/common/util/translations.txt
Removed:
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Translations.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/translations.txt
Modified:
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleViewPane.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/BookFont.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/EditSitePane.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/IndexResolver.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/DesktopActions.java
trunk/bibledesktop/src/main/resources/config.xml
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/Field.plugin
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/StringArrayField.java
trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java
trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java
trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java
trunk/common/JSwordDictionary.txt
trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop/DebugPane.java
trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser/SerIndexManager.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/install/InstallManager.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/install/sword/AbstractSwordInstaller.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookPath.java
trunk/jsword/src/main/java/org/crosswire/jsword/index/lucene/LuceneIndexManager.java
trunk/jsword/src/main/java/org/crosswire/jsword/util/WebWarning.java
trunk/jsword/src/test/java/org/crosswire/jsword/book/GatherAllReferences.java
trunk/jsword/src/test/java/org/crosswire/jsword/book/ReadEverything.java
Log:
Created CWOptionPane as an i18n version of JOptionPane that works with Farsi.
Moved Translations from BibleDesktop to common.
Moved Project from JSword to common
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleViewPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleViewPane.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleViewPane.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -46,13 +46,13 @@
import org.crosswire.common.swing.desktop.Titleable;
import org.crosswire.common.swing.desktop.event.TitleChangedEvent;
import org.crosswire.common.swing.desktop.event.TitleChangedListener;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.Logger;
import org.crosswire.common.util.Reporter;
import org.crosswire.jsword.passage.Key;
import org.crosswire.jsword.passage.NoSuchVerseException;
import org.crosswire.jsword.passage.Passage;
import org.crosswire.jsword.passage.PassageKeyFactory;
-import org.crosswire.jsword.util.Project;
/**
* A BibleViewPane consists of three areas for looking up passages,
@@ -92,11 +92,11 @@
{
try
{
- chooser = new JFileChooser(Project.instance().getWriteableProjectSubdir(BOOKMARK_DIR, true).getPath());
+ chooser = new JFileChooser(CWProject.instance().getWriteableProjectSubdir(BOOKMARK_DIR, true).getPath());
}
catch (IOException ex)
{
- chooser = new JFileChooser(Project.instance().getWritableProjectDir().getPath());
+ chooser = new JFileChooser(CWProject.instance().getWritableProjectDir().getPath());
}
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -46,6 +46,7 @@
import org.crosswire.bibledesktop.passage.KeyChangeEvent;
import org.crosswire.bibledesktop.passage.KeyChangeListener;
import org.crosswire.common.swing.ActionFactory;
+import org.crosswire.common.swing.CWOptionPane;
import org.crosswire.common.swing.GuiUtil;
import org.crosswire.common.swing.QuickHelpDialog;
import org.crosswire.common.swing.desktop.event.TitleChangedEvent;
@@ -576,7 +577,7 @@
private void noBookInstalled()
{
String noBible = Msg.NO_INSTALLED_BIBLE.toString();
- JOptionPane.showMessageDialog(this, noBible, noBible, JOptionPane.WARNING_MESSAGE);
+ CWOptionPane.showMessageDialog(this, noBible, noBible, JOptionPane.WARNING_MESSAGE);
}
/**
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/BookFont.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/BookFont.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/BookFont.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -27,10 +27,10 @@
import org.crosswire.bibledesktop.desktop.XSLTProperty;
import org.crosswire.common.swing.FontStore;
import org.crosswire.common.swing.GuiConvert;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.Language;
import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.book.BookMetaData;
-import org.crosswire.jsword.util.Project;
/**
*
@@ -47,7 +47,7 @@
*/
private BookFont()
{
- super("BookFonts", Project.instance().getWritableProjectDir()); //$NON-NLS-1$
+ super("BookFonts", CWProject.instance().getWritableProjectDir()); //$NON-NLS-1$
}
public static BookFont instance()
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/EditSitePane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/EditSitePane.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/EditSitePane.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -55,6 +55,7 @@
import javax.swing.event.ListSelectionListener;
import org.crosswire.common.swing.ActionFactory;
+import org.crosswire.common.swing.CWOptionPane;
import org.crosswire.common.swing.CWScrollPane;
import org.crosswire.common.swing.FixedSplitPane;
import org.crosswire.common.swing.GuiUtil;
@@ -350,7 +351,7 @@
String name = (String) lstSite.getSelectedValue();
if (name == null)
{
- JOptionPane.showMessageDialog(this, Msg.NO_SELECTED_SITE.toString(), Msg.NO_SITE.toString(), JOptionPane.INFORMATION_MESSAGE);
+ CWOptionPane.showMessageDialog(this, Msg.NO_SELECTED_SITE.toString(), Msg.NO_SITE.toString(), JOptionPane.INFORMATION_MESSAGE);
return;
}
@@ -376,7 +377,7 @@
return;
}
- if (JOptionPane.showConfirmDialog(this, Msg.CONFIRM_DELETE_SITE.toString(name), Msg.DELETE_SITE.toString(), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
+ if (CWOptionPane.showConfirmDialog(this, Msg.CONFIRM_DELETE_SITE.toString(name), Msg.DELETE_SITE.toString(), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
imanager.removeInstaller(name);
}
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/IndexResolver.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/IndexResolver.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/IndexResolver.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -32,6 +32,7 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;
+import org.crosswire.common.swing.CWOptionPane;
import org.crosswire.common.util.Logger;
import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.book.BookException;
@@ -77,7 +78,7 @@
// LATER(DMS): Enable this when we have indexes to download
// String title = Msg.HOW_MESSAGE_TITLE.toString();
// Msg msg = Msg.HOW_MESSAGE;
-// int choice = JOptionPane.showOptionDialog(parent, msg, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
+// int choice = CWOptionPane.showOptionDialog(parent, msg, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
int choice = 1;
@@ -113,7 +114,7 @@
String gtitle = Msg.HOW_GENERATE_TITLE.toString();
Msg gmsg = Msg.HOW_GENERATE;
- int yn = JOptionPane.showConfirmDialog(parent, gmsg, gtitle, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
+ int yn = CWOptionPane.showConfirmDialog(parent, gmsg, gtitle, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (yn == JOptionPane.YES_OPTION)
{
@@ -160,7 +161,7 @@
String title = Msg.HOW_SITE_TITLE.toString();
- int yn = JOptionPane.showConfirmDialog(parent, panel, title, JOptionPane.YES_OPTION);
+ int yn = CWOptionPane.showConfirmDialog(parent, panel, title, JOptionPane.YES_OPTION);
if (yn == JOptionPane.YES_OPTION)
{
installer = (Installer) choice.getSelectedItem();
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -48,6 +48,7 @@
import org.crosswire.common.icu.NumberShaper;
import org.crosswire.common.swing.ActionFactory;
+import org.crosswire.common.swing.CWOptionPane;
import org.crosswire.common.swing.CWScrollPane;
import org.crosswire.common.swing.FixedSplitPane;
import org.crosswire.common.swing.FontChooser;
@@ -321,7 +322,7 @@
try
{
String msg = shaper.shape(Msg.CONFIRM_DELETE_BOOK.toString(new Object[] {book.getName()}));
- if (JOptionPane.showConfirmDialog(this, msg,
+ if (CWOptionPane.showConfirmDialog(this, msg,
Msg.CONFIRM_DELETE_TITLE.toString(),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
@@ -355,7 +356,7 @@
Book book = getBook(last);
String unlockKey =
- (String) JOptionPane.showInputDialog(this,
+ (String) CWOptionPane.showInputDialog(this,
Msg.UNLOCK_BOOK.toString(new Object[] {book.getName()}),
Msg.UNLOCK_TITLE.toString(),
JOptionPane.QUESTION_MESSAGE,
@@ -388,7 +389,7 @@
{
IndexManager imanager = IndexManagerFactory.getIndexManager();
if (imanager.isIndexed(book)
- && JOptionPane.showConfirmDialog(this, Msg.CONFIRM_UNINSTALL_BOOK.toString(new Object[] {book.getName()}),
+ && CWOptionPane.showConfirmDialog(this, Msg.CONFIRM_UNINSTALL_BOOK.toString(new Object[] {book.getName()}),
Msg.CONFIRM_UNINSTALL_TITLE.toString(),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
@@ -478,7 +479,7 @@
msg = Msg.MB_SIZE;
}
- if (JOptionPane.showConfirmDialog(this, msg.toString(new Object[] {name.getName(), new Float(size)}),
+ if (CWOptionPane.showConfirmDialog(this, msg.toString(new Object[] {name.getName(), new Float(size)}),
Msg.CONFIRMATION_TITLE.toString(),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -74,6 +74,7 @@
import org.crosswire.common.history.History;
import org.crosswire.common.progress.JobManager;
import org.crosswire.common.progress.Progress;
+import org.crosswire.common.swing.CWOptionPane;
import org.crosswire.common.swing.CatchingThreadGroup;
import org.crosswire.common.swing.ExceptionPane;
import org.crosswire.common.swing.FixedSplitPane;
@@ -87,10 +88,12 @@
import org.crosswire.common.swing.desktop.event.ViewEvent;
import org.crosswire.common.swing.desktop.event.ViewEventListener;
import org.crosswire.common.util.CWClassLoader;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.Logger;
import org.crosswire.common.util.OSType;
import org.crosswire.common.util.Reporter;
import org.crosswire.common.util.ResourceUtil;
+import org.crosswire.common.util.Translations;
import org.crosswire.common.xml.XMLUtil;
import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.book.BookFilters;
@@ -101,7 +104,6 @@
import org.crosswire.jsword.passage.Key;
import org.crosswire.jsword.passage.NoSuchKeyException;
import org.crosswire.jsword.util.ConverterFactory;
-import org.crosswire.jsword.util.Project;
import org.jdom.Document;
import org.jdom.JDOMException;
@@ -118,12 +120,15 @@
{
// This must be the first static in the program.
// To ensure this we place it at the top of the class!
- // Calling Project.instance() will set up the PROJECT's home directory
- // ~/.jsword
// This will set it as a place to look for overrides for
// ResourceBundles, properties and other resources
- private static final Project PROJECT = Project.instance();
+ private static final CWProject PROJECT = CWProject.instance();
+ static
+ {
+ PROJECT.setHome("jsword.home", ".jsword", "JSword"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
/**
* Central start point.
* @param args The command line arguments
@@ -889,7 +894,7 @@
List bibles = Books.installed().getBooks(BookFilters.getBibles());
if (bibles.size() == 0)
{
- int reply = JOptionPane.showConfirmDialog(this, Msg.NO_BIBLES_MESSAGE, Msg.NO_BIBLES_TITLE.toString(), JOptionPane.OK_CANCEL_OPTION,
+ int reply = CWOptionPane.showConfirmDialog(this, Msg.NO_BIBLES_MESSAGE, Msg.NO_BIBLES_TITLE.toString(), JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (reply == JOptionPane.OK_OPTION)
{
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/DesktopActions.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/DesktopActions.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/DesktopActions.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -29,7 +29,6 @@
import javax.swing.Action;
import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JOptionPane;
import javax.swing.ToolTipManager;
import org.crosswire.bibledesktop.book.BibleViewPane;
@@ -41,15 +40,16 @@
import org.crosswire.common.config.swing.ConfigEditorFactory;
import org.crosswire.common.swing.ActionFactory;
import org.crosswire.common.swing.Actionable;
+import org.crosswire.common.swing.CWOptionPane;
import org.crosswire.common.swing.desktop.ViewVisitor;
import org.crosswire.common.util.ClassUtil;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.Logger;
import org.crosswire.common.util.OSType;
import org.crosswire.common.util.ReflectionUtil;
import org.crosswire.common.util.Reporter;
import org.crosswire.jsword.passage.Key;
import org.crosswire.jsword.passage.NoSuchVerseException;
-import org.crosswire.jsword.util.Project;
import org.crosswire.jsword.util.WebWarning;
/**
@@ -431,7 +431,7 @@
*/
public void doOptions()
{
- URI configUri = Project.instance().getWritablePropertiesURI("desktop"); //$NON-NLS-1$
+ URI configUri = CWProject.instance().getWritablePropertiesURI("desktop"); //$NON-NLS-1$
ConfigEditorFactory.showDialog(desktop.getConfig(), desktop, configUri);
}
@@ -440,7 +440,7 @@
*/
public void doContents()
{
- JOptionPane.showMessageDialog(getDesktop(), Msg.NO_HELP);
+ CWOptionPane.showMessageDialog(getDesktop(), Msg.NO_HELP);
}
/**
Deleted: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Translations.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Translations.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Translations.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -1,263 +0,0 @@
-/**
- * Distribution License:
- * BibleDesktop is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, version 2 as published by
- * the Free Software Foundation. This program is distributed in the hope
- * that it will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * The License is available on the internet at:
- * http://www.gnu.org/copyleft/gpl.html
- * or by writing to:
- * Free Software Foundation, Inc.
- * 59 Temple Place - Suite 330
- * Boston, MA 02111-1307, USA
- *
- * Copyright: 2005
- * The copyright to this program is held by it's authors.
- *
- * ID: $Id$
- */
-package org.crosswire.bibledesktop.desktop;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URL;
-import java.util.LinkedHashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Properties;
-
-import org.crosswire.common.config.ChoiceFactory;
-import org.crosswire.common.util.Countries;
-import org.crosswire.common.util.Languages;
-import org.crosswire.common.util.Logger;
-import org.crosswire.common.util.NetUtil;
-import org.crosswire.common.util.ResourceUtil;
-import org.crosswire.common.util.StringUtil;
-import org.crosswire.jsword.util.Project;
-
-/**
- * Translations provides a list of locales that BibleDesktop has been translated into.
- *
- * @see gnu.gpl.License for license details.
- * The copyright to this program is held by it's authors.
- * @author DM Smith [dmsmith555 at yahoo dot com]
- */
-public class Translations
-{
- /**
- * Singleton classes have private constructors.
- */
- private Translations()
- {
- try
- {
- Properties props = ResourceUtil.getProperties(getClass());
- translation = props.getProperty(TRANSLATION_KEY, DEFAULT_TRANSLATION);
- }
- catch (IOException e)
- {
- translation = DEFAULT_TRANSLATION;
- }
- }
-
- /**
- * All access to Translations is through this single instance.
- *
- * @return the singleton instance
- */
- public static Translations instance()
- {
- return instance;
- }
-
- /**
- * Gets a listing of all the translations that Bible Desktop supports.
- *
- * @return an string array of translations in locale friendly names.
- */
- public Map getSupported()
- {
- loadSupportedTranslations();
- // I18N(DMS) Collate these according to the current locale, putting the current locale's locale first.
- Map names = new LinkedHashMap();
-
- for (int i = 0; i < translations.length; i++)
- {
- names.put(translations[i], toString(translations[i]));
- }
-
- return names;
- }
-
- /**
- * Get the locale for the current translation.
- * @return the translation's locale
- */
- public Locale getCurrentLocale()
- {
- if (translation.indexOf('_') != -1)
- {
- String[] locale = StringUtil.split(translation, '_');
- return new Locale(locale[0], locale[1]);
- }
- return new Locale(translation);
- }
-
- /**
- * Get the current translation as a human readable string.
- *
- * @return the current translation
- */
- public String getCurrent()
- {
- return toString(translation);
- }
-
- /**
- * Set the current translation, using human readable string.
- *
- * @param translation the translation to use
- */
- public void setCurrent(String newTranslation)
- {
- String found = DEFAULT_TRANSLATION;
- String currentTranslation = ""; //$NON-NLS-1$
- for (int i = 0; i < translations.length; i++)
- {
- String trans = translations[i];
- currentTranslation = toString(translation);
-
- if (trans.equals(newTranslation) || currentTranslation.equals(newTranslation))
- {
- found = trans;
- break;
- }
- }
-
- try
- {
- translation = found;
- Properties props = new Properties();
- props.put(TRANSLATION_KEY, translation);
- URI outputURI = Project.instance().getWritablePropertiesURI(getClass().getName());
- NetUtil.storeProperties(props, outputURI, "BibleDesktop UI Translation"); //$NON-NLS-1$
- }
- catch (IOException ex)
- {
- log.error("Failed to save BibleDesktop UI Translation", ex); //$NON-NLS-1$
- }
- }
-
- /**
- * Set the locale for the program to the one the user has selected.
- * But don't set it to the default translation, so that the user's
- * actual locale, is used for Bible book names.
- *
- * This only makes sense after config has called setCurrentTranslation.
- */
- public void setLocale()
- {
- Locale.setDefault(getCurrentLocale());
- }
-
- /**
- * Register this class with the common config engine.
- */
- public void register()
- {
- ChoiceFactory.getDataMap().put(TRANSLATION_KEY, getSupportedTranslations());
- }
-
- /**
- * Get the current translation as a human readable string.
- *
- * @return the current translation
- */
- public static String getCurrentTranslation()
- {
- return Translations.instance().getCurrent();
- }
-
- /**
- * Set the current translation, using human readable string.
- *
- * @param translation the translation to use
- */
- public static void setCurrentTranslation(String newTranslation)
- {
- Translations.instance().setCurrent(newTranslation);
- }
-
- /**
- * Gets a listing of all the translations that Bible Desktop supports.
- *
- * @return an string array of translations in locale friendly names.
- */
- public static Map getSupportedTranslations()
- {
- return Translations.instance().getSupported();
- }
-
- /**
- * Get a list of the supported translations
- */
- private void loadSupportedTranslations()
- {
- if (translations == null)
- {
- try
- {
- URL index = ResourceUtil.getResource(Translations.class, "translations.txt"); //$NON-NLS-1$
- translations = NetUtil.listByIndexFile(NetUtil.toURI(index));
- }
- catch (IOException ex)
- {
- translations = new String[0];
- }
- }
- }
-
- public String toString(String translationCode)
- {
- StringBuffer currentTranslation = new StringBuffer(Languages.getLanguage(translationCode));
-
- if (translationCode.indexOf('_') != -1)
- {
- String[] locale = StringUtil.split(translationCode, '_');
- currentTranslation.append(", "); //$NON-NLS-1$
- currentTranslation.append(Countries.getCountry(locale[1]));
- }
-
- return currentTranslation.toString();
- }
-
- /**
- * The key used in config.xml
- */
- private static final String TRANSLATION_KEY = "translation-codes"; //$NON-NLS-1$
-
- /**
- * The default translation, if the user has not chosen anything else.
- */
- public static final String DEFAULT_TRANSLATION = "en"; //$NON-NLS-1$
-
- /**
- * The translation that BibleDesktop should use.
- */
- private String translation = DEFAULT_TRANSLATION;
-
- /**
- * List of available translations.
- */
- private String[] translations;
-
- private static Translations instance = new Translations();
-
- /**
- * The log stream
- */
- private static final Logger log = Logger.getLogger(Translations.class);
-}
Deleted: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/translations.txt
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/translations.txt 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/translations.txt 2008-05-10 18:34:02 UTC (rev 1850)
@@ -1,10 +0,0 @@
-# This is a listing of languages that BibleDesktop has been translated into.
-# Each language should be on a line to itself.
-# Note: This file is ordered by the English representation of the file.
-en
-zh_CN
-zh_TW
-de
-fa
-#tr
-vi
Modified: trunk/bibledesktop/src/main/resources/config.xml
===================================================================
--- trunk/bibledesktop/src/main/resources/config.xml 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/bibledesktop/src/main/resources/config.xml 2008-05-10 18:34:02 UTC (rev 1850)
@@ -201,7 +201,7 @@
</option>
<option key="Application.Language" type="map-options">
- <introspect class="org.crosswire.bibledesktop.desktop.Translations" property="CurrentTranslation"/>
+ <introspect class="org.crosswire.common.util.Translations" property="CurrentTranslation"/>
<map name="translation-codes"/>
</option>
Modified: trunk/common/JSwordDictionary.txt
===================================================================
--- trunk/common/JSwordDictionary.txt 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/common/JSwordDictionary.txt 2008-05-10 18:34:02 UTC (rev 1850)
@@ -67,3 +67,5 @@
tally
mapper
parsable
+gregorian
+downloaded
Copied: trunk/common/src/main/java/org/crosswire/common/util/CWProject.java (from rev 1829, trunk/jsword/src/main/java/org/crosswire/jsword/util/Project.java)
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/CWProject.java (rev 0)
+++ trunk/common/src/main/java/org/crosswire/common/util/CWProject.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -0,0 +1,306 @@
+/**
+ * Distribution License:
+ * JSword is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License, version 2.1 as published by
+ * the Free Software Foundation. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/lgpl.html
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2008
+ * The copyright to this program is held by it's authors.
+ *
+ * ID: $Id$
+ */
+package org.crosswire.common.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+
+/**
+ * The Project class looks after the source of project files.
+ * These are per user files and as such have a different location
+ * on different operating systems. These are:<br/>
+ *
+ * <table>
+ * <tr><td>Mac OS X</td><td>~/Library/Application Support/JSword</td></tr>
+ * <tr><td>Win NT/2000/XP/ME/9x</td><td>~/Application Data/JSword (~ is all over the place, but Java figures it out)</td></tr>
+ * <tr><td>Unix and otherwise</td><td>~/.jsword</td></tr>
+ * </table>
+ *
+ * <p>
+ * Previously the location was ~/.jsword, which is unfriendly in the Windows and Mac world.
+ * If this location is found on Mac or Windows, it will be moved to the new location,
+ * if different and possible.
+ * </p>
+ *
+ * <p>
+ * Note: If the Java System property jsword.home is set and it exists and is writable
+ * then it will be used instead of the above location. This is useful for USB Drives
+ * and other portable implementations of JSword. I is recommended that this name be JSword.
+ * </p>
+ *
+ * @see gnu.lgpl.License for license details.
+ * The copyright to this program is held by it's authors.
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public final class CWProject
+{
+ /**
+ * Accessor for the resource singleton.
+ */
+ public static CWProject instance()
+ {
+ return instance;
+ }
+
+ /**
+ * Establish how this project finds it's resources.
+ * @param homeProperty a property that is used as the home directory name.
+ * If this property has a value then homeDir and altHomeDir are ignored.
+ * Defaults to jsword.home.
+ * @param homeDir the name of the directory to be used for Unix.
+ * Typically this is a hidden directory, that is, it begins with a '.'.
+ * Defaults to .jsword
+ * @param altHomeDir the name of the directory to be used for other OSes. This should not be a hidden directory.
+ * Defaults to JSword.
+ */
+ public void setHome(String homeProperty, String homeDir, String altHomeDir)
+ {
+ CWProject.homeProperty = homeProperty;
+ CWProject.homeDirectory = homeDir;
+ CWProject.homeAltDirectory = altHomeDir;
+ establishProjectHome();
+ }
+
+ /**
+ * Get the writable user project directory.
+ *
+ * @return the writable user project directory.
+ */
+ public URI getWritableProjectDir()
+ {
+ establishProjectHome();
+ return writeHome;
+ }
+
+ /**
+ * Get the locations where project resources can be found.
+ *
+ * @return an array of URIs which can be used to look up resources.
+ */
+ public URI[] getProjectResourceDirs()
+ {
+ establishProjectHome();
+ return homes;
+ }
+
+ /**
+ * Get the location where the project directory used to be.
+ *
+ * @return ~/.jsword
+ */
+ public URI getDeprecatedWritableProjectDir()
+ {
+ return OSType.DEFAULT.getUserAreaFolder(homeDirectory, homeAltDirectory);
+ }
+
+ /**
+ * Get a the URI of a (potentially non-existent) properties file that we can
+ * write to. This method of acquiring properties files is preferred over
+ * getResourceProperties() as this is writable and can take into account
+ * user preferences.
+ * This method makes no promise that the URI returned is valid. It is
+ * totally untested, so reading may well cause errors.
+ * @param subject The name (minus the .properties extension)
+ * @return The resource as a URI
+ */
+ public URI getWritablePropertiesURI(String subject)
+ {
+ return NetUtil.lengthenURI(getWritableProjectDir(), subject + FileUtil.EXTENSION_PROPERTIES);
+ }
+
+ /**
+ * A directory within the project directory.
+ *
+ * @param subject A name for the subdirectory of the Project directory.
+ * @return A file: URI pointing at a local writable directory.
+ */
+ public URI getWriteableProjectSubdir(String subject, boolean create) throws IOException
+ {
+ URI temp = NetUtil.lengthenURI(getWritableProjectDir(), subject);
+
+ if (create && !NetUtil.isDirectory(temp))
+ {
+ NetUtil.makeDirectory(temp);
+ }
+
+ return temp;
+ }
+
+ /**
+ * Prevent instantiation.
+ */
+ private CWProject()
+ {
+ }
+
+ /**
+ * Establishes the user's project directory.
+ * In a CD installation, the home directory on the CD will be read-only.
+ * This is not sufficient. We also need a writable home directory. And
+ * in looking up resources, the ones in the writable directory trump
+ * those in the readable directory, allowing the read-only resources
+ * to be overridden.
+ * <p>Here is the lookup order:
+ * <ol>
+ * <li>Check first to see if the jsword.home property is set.</li>
+ * <li>Check for the existence of a platform specific project area and for the existence of a deprecated project area (~/.jsword on Windows and Mac)
+ * and if it exists and it is possible "upgrade" to the platform specific project area. Of these "two" only one is the folder to check.</li>
+ * </ol>
+ * In checking these areas, if the one is read-only, add it to the list and keep going.
+ * However, if it is also writable, then use it alone.
+ */
+ private void establishProjectHome()
+ {
+ if (writeHome == null && readHome == null)
+ {
+ // if there is a property set for the jsword home directory
+ String cwHome = System.getProperty(homeProperty);
+ if (cwHome != null)
+ {
+ URI home = NetUtil.getURI(new File(cwHome));
+ if (NetUtil.canWrite(home))
+ {
+ writeHome = home;
+ }
+ else if (NetUtil.canRead(home))
+ {
+ readHome = home;
+ }
+ // otherwise jsword.home is not usable.
+ }
+ }
+
+ if (writeHome == null)
+ {
+ URI path = OSType.getOSType().getUserAreaFolder(homeDirectory, homeAltDirectory);
+ URI oldPath = getDeprecatedWritableProjectDir();
+ writeHome = migrateUserProjectDir(oldPath, path);
+ }
+
+ if (homes == null)
+ {
+ if (readHome == null)
+ {
+ homes = new URI[] { writeHome };
+ }
+ else
+ {
+ homes = new URI[] { writeHome, readHome };
+ }
+
+ // Now that we know the "home" we can set other global notions of home.
+ // TODO(dms): refactor this to CWClassLoader and NetUtil.
+ CWClassLoader.setHome(getProjectResourceDirs());
+
+ try
+ {
+ URI uricache = getWriteableProjectSubdir(DIR_NETCACHE, true);
+ File filecache = new File(uricache.getPath());
+ NetUtil.setURICacheDir(filecache);
+ }
+ catch (IOException ex)
+ {
+ // This isn't fatal, it just means that NetUtil will try to use $TMP
+ // in place of a more permanent solution.
+ log.warn("Failed to get directory for NetUtil.setURICacheDir()", ex); //$NON-NLS-1$
+ }
+
+ }
+ }
+
+ /**
+ * Migrates the user's project dir, if necessary and possible.
+ *
+ * @param oldPath the path to the old, deprecated location
+ * @param newPath the path to the new location
+ * @return newPath if the migration was possible or not needed.
+ */
+ private URI migrateUserProjectDir(URI oldPath, URI newPath)
+ {
+ if (oldPath.toString().equals(newPath.toString()))
+ {
+ return newPath;
+ }
+
+ if (NetUtil.isDirectory(oldPath))
+ {
+ File oldDir = new File(oldPath.getPath());
+ File newDir = new File(newPath.getPath());
+
+ // This will return false if it could not rename.
+ // This will happen if the directory already exists.
+ oldDir.renameTo(newDir);
+ if (NetUtil.isDirectory(newPath))
+ {
+ return newPath;
+ }
+ return oldPath;
+ }
+ return newPath;
+ }
+
+ /**
+ * The cache of downloaded files inside the project directory
+ */
+ private static final String DIR_NETCACHE = "netcache"; //$NON-NLS-1$
+
+ /**
+ * The homes for this application: first is writable, second (if present) is read-only and specified by the system property jsword.home.
+ */
+ private URI[] homes;
+
+ /**
+ * The writable home for this application.
+ */
+ private URI writeHome;
+
+ /**
+ * The readable home for this application, specified by the system property jsword.home. Null, if jsword.home is also writable.
+ */
+ private URI readHome;
+
+ /**
+ * System property for home directory
+ */
+ private static String homeProperty = "jsword.home"; //$NON-NLS-1$
+
+ /**
+ * The JSword user settings directory
+ */
+ private static String homeDirectory = ".jsword"; //$NON-NLS-1$
+
+ /**
+ * The JSword user settings directory for Mac and Windows
+ */
+ private static String homeAltDirectory = "JSword"; //$NON-NLS-1$
+
+ /**
+ * The filesystem resources
+ */
+ private static CWProject instance = new CWProject();
+
+ /**
+ * The log stream
+ */
+ private static final Logger log = Logger.getLogger(CWProject.class);
+}
Added: trunk/common/src/main/java/org/crosswire/common/util/Translations.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/Translations.java (rev 0)
+++ trunk/common/src/main/java/org/crosswire/common/util/Translations.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -0,0 +1,256 @@
+/**
+ * Distribution License:
+ * BibleDesktop is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, version 2 as published by
+ * the Free Software Foundation. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2005
+ * The copyright to this program is held by it's authors.
+ *
+ * ID: $Id: Translations.java 1738 2008-01-15 02:56:55Z dmsmith $
+ */
+package org.crosswire.common.util;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+
+import org.crosswire.common.config.ChoiceFactory;
+
+/**
+ * Translations provides a list of locales that BibleDesktop has been translated into.
+ *
+ * @see gnu.gpl.License for license details.
+ * The copyright to this program is held by it's authors.
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class Translations
+{
+ /**
+ * Singleton classes have private constructors.
+ */
+ private Translations()
+ {
+ try
+ {
+ Properties props = ResourceUtil.getProperties(getClass());
+ translation = props.getProperty(TRANSLATION_KEY, DEFAULT_TRANSLATION);
+ }
+ catch (IOException e)
+ {
+ translation = DEFAULT_TRANSLATION;
+ }
+ }
+
+ /**
+ * All access to Translations is through this single instance.
+ *
+ * @return the singleton instance
+ */
+ public static Translations instance()
+ {
+ return instance;
+ }
+
+ /**
+ * Gets a listing of all the translations that Bible Desktop supports.
+ *
+ * @return an string array of translations in locale friendly names.
+ */
+ public Map getSupported()
+ {
+ loadSupportedTranslations();
+ // I18N(DMS) Collate these according to the current locale, putting the current locale's locale first.
+ Map names = new LinkedHashMap();
+
+ for (int i = 0; i < translations.length; i++)
+ {
+ names.put(translations[i], toString(translations[i]));
+ }
+
+ return names;
+ }
+
+ /**
+ * Get the locale for the current translation.
+ * @return the translation's locale
+ */
+ public Locale getCurrentLocale()
+ {
+ if (translation.indexOf('_') != -1)
+ {
+ String[] locale = StringUtil.split(translation, '_');
+ return new Locale(locale[0], locale[1]);
+ }
+ return new Locale(translation);
+ }
+
+ /**
+ * Get the current translation as a human readable string.
+ *
+ * @return the current translation
+ */
+ public String getCurrent()
+ {
+ return toString(translation);
+ }
+
+ /**
+ * Set the current translation, using human readable string.
+ *
+ * @param translation the translation to use
+ */
+ public void setCurrent(String newTranslation)
+ {
+ String found = DEFAULT_TRANSLATION;
+ String currentTranslation = ""; //$NON-NLS-1$
+ for (int i = 0; i < translations.length; i++)
+ {
+ String trans = translations[i];
+ currentTranslation = toString(translation);
+
+ if (trans.equals(newTranslation) || currentTranslation.equals(newTranslation))
+ {
+ found = trans;
+ break;
+ }
+ }
+
+ try
+ {
+ translation = found;
+ Properties props = new Properties();
+ props.put(TRANSLATION_KEY, translation);
+ URI outputURI = CWProject.instance().getWritablePropertiesURI(getClass().getName());
+ NetUtil.storeProperties(props, outputURI, "BibleDesktop UI Translation"); //$NON-NLS-1$
+ }
+ catch (IOException ex)
+ {
+ log.error("Failed to save BibleDesktop UI Translation", ex); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Set the locale for the program to the one the user has selected.
+ * But don't set it to the default translation, so that the user's
+ * actual locale, is used for Bible book names.
+ *
+ * This only makes sense after config has called setCurrentTranslation.
+ */
+ public void setLocale()
+ {
+ Locale.setDefault(getCurrentLocale());
+ }
+
+ /**
+ * Register this class with the common config engine.
+ */
+ public void register()
+ {
+ ChoiceFactory.getDataMap().put(TRANSLATION_KEY, getSupportedTranslations());
+ }
+
+ /**
+ * Get the current translation as a human readable string.
+ *
+ * @return the current translation
+ */
+ public static String getCurrentTranslation()
+ {
+ return Translations.instance().getCurrent();
+ }
+
+ /**
+ * Set the current translation, using human readable string.
+ *
+ * @param translation the translation to use
+ */
+ public static void setCurrentTranslation(String newTranslation)
+ {
+ Translations.instance().setCurrent(newTranslation);
+ }
+
+ /**
+ * Gets a listing of all the translations that Bible Desktop supports.
+ *
+ * @return an string array of translations in locale friendly names.
+ */
+ public static Map getSupportedTranslations()
+ {
+ return Translations.instance().getSupported();
+ }
+
+ /**
+ * Get a list of the supported translations
+ */
+ private void loadSupportedTranslations()
+ {
+ if (translations == null)
+ {
+ try
+ {
+ URL index = ResourceUtil.getResource(Translations.class, "translations.txt"); //$NON-NLS-1$
+ translations = NetUtil.listByIndexFile(NetUtil.toURI(index));
+ }
+ catch (IOException ex)
+ {
+ translations = new String[0];
+ }
+ }
+ }
+
+ public String toString(String translationCode)
+ {
+ StringBuffer currentTranslation = new StringBuffer(Languages.getLanguage(translationCode));
+
+ if (translationCode.indexOf('_') != -1)
+ {
+ String[] locale = StringUtil.split(translationCode, '_');
+ currentTranslation.append(", "); //$NON-NLS-1$
+ currentTranslation.append(Countries.getCountry(locale[1]));
+ }
+
+ return currentTranslation.toString();
+ }
+
+ /**
+ * The key used in config.xml
+ */
+ private static final String TRANSLATION_KEY = "translation-codes"; //$NON-NLS-1$
+
+ /**
+ * The default translation, if the user has not chosen anything else.
+ */
+ public static final String DEFAULT_TRANSLATION = "en"; //$NON-NLS-1$
+
+ /**
+ * The translation that BibleDesktop should use.
+ */
+ private String translation = DEFAULT_TRANSLATION;
+
+ /**
+ * List of available translations.
+ */
+ private String[] translations;
+
+ private static Translations instance = new Translations();
+
+ /**
+ * The log stream
+ */
+ private static final Logger log = Logger.getLogger(Translations.class);
+}
Added: trunk/common/src/main/java/org/crosswire/common/util/translations.txt
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/translations.txt (rev 0)
+++ trunk/common/src/main/java/org/crosswire/common/util/translations.txt 2008-05-10 18:34:02 UTC (rev 1850)
@@ -0,0 +1,10 @@
+# This is a listing of languages that BibleDesktop has been translated into.
+# Each language should be on a line to itself.
+# Note: This file is ordered by the English representation of the file.
+en
+zh_CN
+zh_TW
+de
+fa
+#tr
+vi
Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/Field.plugin
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/Field.plugin 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/Field.plugin 2008-05-10 18:34:02 UTC (rev 1850)
@@ -1,5 +1,6 @@
string=org.crosswire.common.config.swing.TextField
-password=org.crosswire.common.config.swing.PasswordField
+#password is now in jsword-limbo
+#password=org.crosswire.common.config.swing.PasswordField
boolean=org.crosswire.common.config.swing.BooleanField
int-options=org.crosswire.common.config.swing.MappedOptionsField
map-options=org.crosswire.common.config.swing.MappedOptionsField
Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/StringArrayField.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/StringArrayField.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/StringArrayField.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -45,6 +45,7 @@
import org.crosswire.common.config.Choice;
import org.crosswire.common.swing.ActionFactory;
+import org.crosswire.common.swing.CWOptionPane;
import org.crosswire.common.swing.CWScrollPane;
import org.crosswire.common.util.Convert;
@@ -152,7 +153,7 @@
{
InputPane input = new InputPane();
- if (JOptionPane.showConfirmDialog(this, input, Msg.NEW_CLASS.toString(), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
+ if (CWOptionPane.showConfirmDialog(this, input, Msg.NEW_CLASS.toString(), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
{
String new_name = input.name_field.getText();
@@ -168,7 +169,7 @@
InputPane input = new InputPane();
input.name_field.setText(currentValue());
- if (JOptionPane.showConfirmDialog(this, input, Msg.EDIT_CLASS.toString(), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
+ if (CWOptionPane.showConfirmDialog(this, input, Msg.EDIT_CLASS.toString(), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
{
String new_name = input.name_field.getText();
Added: trunk/common-swing/src/main/java/org/crosswire/common/swing/CWOptionPane.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/CWOptionPane.java (rev 0)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/CWOptionPane.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -0,0 +1,803 @@
+/**
+ * Distribution License:
+ * JSword is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License, version 2.1 as published by
+ * the Free Software Foundation. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/lgpl.html
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2008
+ * The copyright to this program is held by it's authors.
+ *
+ * ID: $Id: org.eclipse.jdt.ui.prefs 1178 2006-11-06 12:48:02Z dmsmith $
+ */
+package org.crosswire.common.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dialog;
+import java.awt.Frame;
+import java.awt.HeadlessException;
+import java.awt.Window;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.Action;
+import javax.swing.Icon;
+import javax.swing.JDialog;
+import javax.swing.JOptionPane;
+import javax.swing.JRootPane;
+import javax.swing.UIManager;
+
+/**
+ * CWOptionPane is just like JOptionPane, but internationalize the button text
+ * for some languages that Java does not handle, for which JSword has translations.
+ *
+ * @see gnu.lgpl.License for license details.<br>
+ * The copyright to this program is held by it's authors.
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class CWOptionPane extends JOptionPane
+{
+
+ /**
+ * Creates a <code>CWOptionPane</code> with a test message.
+ */
+ public CWOptionPane()
+ {
+ this("CWOptionPane message", PLAIN_MESSAGE, DEFAULT_OPTION, null, null, null); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates a instance of <code>CWOptionPane</code> to display a
+ * message using the
+ * plain-message message type and the default options delivered by
+ * the UI.
+ *
+ * @param message the <code>Object</code> to display
+ */
+ public CWOptionPane(Object message)
+ {
+ this(message, PLAIN_MESSAGE, DEFAULT_OPTION, null, null, null);
+ }
+
+ /**
+ * Creates an instance of <code>CWOptionPane</code> to display a message
+ * with the specified message type and the default options,
+ *
+ * @param message the <code>Object</code> to display
+ * @param messageType the type of message to be displayed:
+ * <code>ERROR_MESSAGE</code>,
+ * <code>INFORMATION_MESSAGE</code>,
+ * <code>WARNING_MESSAGE</code>,
+ * <code>QUESTION_MESSAGE</code>,
+ * or <code>PLAIN_MESSAGE</code>
+ */
+ public CWOptionPane(Object message, int messageType)
+ {
+ this(message, messageType, DEFAULT_OPTION, null, null, null);
+ }
+
+ /**
+ * Creates an instance of <code>CWOptionPane</code> to display a message
+ * with the specified message type and options.
+ *
+ * @param message the <code>Object</code> to display
+ * @param messageType the type of message to be displayed:
+ * <code>ERROR_MESSAGE</code>,
+ * <code>INFORMATION_MESSAGE</code>,
+ * <code>WARNING_MESSAGE</code>,
+ * <code>QUESTION_MESSAGE</code>,
+ * or <code>PLAIN_MESSAGE</code>
+ * @param optionType the options to display in the pane:
+ * <code>DEFAULT_OPTION</code>, <code>YES_NO_OPTION</code>,
+ * <code>YES_NO_CANCEL_OPTION</code>,
+ * <code>OK_CANCEL_OPTION</code>
+ */
+ public CWOptionPane(Object message, int messageType, int optionType)
+ {
+ this(message, messageType, optionType, null, null, null);
+ }
+
+ /**
+ * Creates an instance of <code>CWOptionPane</code> to display a message
+ * with the specified message type, options, and icon.
+ *
+ * @param message the <code>Object</code> to display
+ * @param messageType the type of message to be displayed:
+ * <code>ERROR_MESSAGE</code>,
+ * <code>INFORMATION_MESSAGE</code>,
+ * <code>WARNING_MESSAGE</code>,
+ * <code>QUESTION_MESSAGE</code>,
+ * or <code>PLAIN_MESSAGE</code>
+ * @param optionType the options to display in the pane:
+ * <code>DEFAULT_OPTION</code>, <code>YES_NO_OPTION</code>,
+ * <code>YES_NO_CANCEL_OPTION</code>,
+ * <code>OK_CANCEL_OPTION</code>
+ * @param icon the <code>Icon</code> image to display
+ */
+ public CWOptionPane(Object message, int messageType, int optionType, Icon icon)
+ {
+ this(message, messageType, optionType, icon, null, null);
+ }
+
+ /**
+ * Creates an instance of <code>CWOptionPane</code> to display a message
+ * with the specified message type, icon, and options.
+ * None of the options is initially selected.
+ * <p>
+ * The options objects should contain either instances of
+ * <code>Component</code>s, (which are added directly) or
+ * <code>Strings</code> (which are wrapped in a <code>JButton</code>).
+ * If you provide <code>Component</code>s, you must ensure that when the
+ * <code>Component</code> is clicked it messages <code>setValue</code>
+ * in the created <code>CWOptionPane</code>.
+ *
+ * @param message the <code>Object</code> to display
+ * @param messageType the type of message to be displayed:
+ * <code>ERROR_MESSAGE</code>,
+ * <code>INFORMATION_MESSAGE</code>,
+ * <code>WARNING_MESSAGE</code>,
+ * <code>QUESTION_MESSAGE</code>,
+ * or <code>PLAIN_MESSAGE</code>
+ * @param optionType the options to display in the pane:
+ * <code>DEFAULT_OPTION</code>,
+ * <code>YES_NO_OPTION</code>,
+ * <code>YES_NO_CANCEL_OPTION</code>,
+ * <code>OK_CANCEL_OPTION</code>
+ * @param icon the <code>Icon</code> image to display
+ * @param options the choices the user can select
+ */
+ public CWOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options)
+ {
+ this(message, messageType, optionType, icon, options, null);
+
+ GuiUtil.applyDefaultOrientation(this);
+ }
+
+ /**
+ * Creates an instance of <code>CWOptionPane</code> to display a message
+ * with the specified message type, icon, and options, with the
+ * initially-selected option specified.
+ *
+ * @param message the <code>Object</code> to display
+ * @param messageType the type of message to be displayed:
+ * <code>ERROR_MESSAGE</code>,
+ * <code>INFORMATION_MESSAGE</code>,
+ * <code>WARNING_MESSAGE</code>,
+ * <code>QUESTION_MESSAGE</code>,
+ * or <code>PLAIN_MESSAGE</code>
+ * @param optionType the options to display in the pane:
+ * <code>DEFAULT_OPTION</code>,
+ * <code>YES_NO_OPTION</code>,
+ * <code>YES_NO_CANCEL_OPTION</code>,
+ * <code>OK_CANCEL_OPTION</code>
+ * @param icon the Icon image to display
+ * @param options the choices the user can select
+ * @param initialValue the choice that is initially selected; if
+ * <code>null</code>, then nothing will be initially selected;
+ * only meaningful if <code>options</code> is used
+ */
+ public CWOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options, Object initialValue)
+ {
+ super(message, messageType, optionType, icon, CWOptionPane.fixOptions(options, optionType), initialValue);
+ }
+
+ /**
+ * Shows a question-message dialog requesting input from the user. The
+ * dialog uses the default frame, which usually means it is centered on
+ * the screen.
+ *
+ * @param message the <code>Object</code> to display
+ * @exception HeadlessException if
+ * <code>GraphicsEnvironment.isHeadless</code> returns
+ * <code>true</code>
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ */
+ public static String showInputDialog(Object message) throws HeadlessException
+ {
+ return showInputDialog(null, message);
+ }
+
+ /**
+ * Shows a question-message dialog requesting input from the user, with
+ * the input value initialized to <code>initialSelectionValue</code>. The
+ * dialog uses the default frame, which usually means it is centered on
+ * the screen.
+ *
+ * @param message the <code>Object</code> to display
+ * @param initialSelectionValue the value used to initialize the input
+ * field
+ */
+ public static String showInputDialog(Object message, Object initialSelectionValue) {
+ return showInputDialog(null, message, initialSelectionValue);
+ }
+
+ /**
+ * Shows a question-message dialog requesting input from the user
+ * parented to <code>parentComponent</code>.
+ * The dialog is displayed on top of the <code>Component</code>'s
+ * frame, and is usually positioned below the <code>Component</code>.
+ *
+ * @param parentComponent the parent <code>Component</code> for the
+ * dialog
+ * @param message the <code>Object</code> to display
+ * @exception HeadlessException if
+ * <code>GraphicsEnvironment.isHeadless</code> returns
+ * <code>true</code>
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ */
+ public static String showInputDialog(Component parentComponent, Object message) throws HeadlessException
+ {
+ return showInputDialog(parentComponent, message, "?", QUESTION_MESSAGE); //$NON-NLS-1$
+ }
+
+ /**
+ * Shows a question-message dialog requesting input from the user and
+ * parented to <code>parentComponent</code>. The input value will be
+ * initialized to <code>initialSelectionValue</code>.
+ * The dialog is displayed on top of the <code>Component</code>'s
+ * frame, and is usually positioned below the <code>Component</code>.
+ *
+ * @param parentComponent the parent <code>Component</code> for the
+ * dialog
+ * @param message the <code>Object</code> to display
+ * @param initialSelectionValue the value used to initialize the input
+ * field
+ */
+ public static String showInputDialog(Component parentComponent, Object message, Object initialSelectionValue)
+ {
+ return (String)showInputDialog(parentComponent, message, "?", QUESTION_MESSAGE, null, null, initialSelectionValue); //$NON-NLS-1$
+ }
+
+ /**
+ * Shows a dialog requesting input from the user parented to
+ * <code>parentComponent</code> with the dialog having the title
+ * <code>title</code> and message type <code>messageType</code>.
+ *
+ * @param parentComponent the parent <code>Component</code> for the
+ * dialog
+ * @param message the <code>Object</code> to display
+ * @param title the <code>String</code> to display in the dialog
+ * title bar
+ * @param messageType the type of message that is to be displayed:
+ * <code>ERROR_MESSAGE</code>,
+ * <code>INFORMATION_MESSAGE</code>,
+ * <code>WARNING_MESSAGE</code>,
+ * <code>QUESTION_MESSAGE</code>,
+ * or <code>PLAIN_MESSAGE</code>
+ * @exception HeadlessException if
+ * <code>GraphicsEnvironment.isHeadless</code> returns
+ * <code>true</code>
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ */
+ public static String showInputDialog(Component parentComponent, Object message, String title, int messageType) throws HeadlessException
+ {
+ return (String)showInputDialog(parentComponent, message, title, messageType, null, null, null);
+ }
+
+ /**
+ * Prompts the user for input in a blocking dialog where the
+ * initial selection, possible selections, and all other options can
+ * be specified. The user will able to choose from
+ * <code>selectionValues</code>, where <code>null</code> implies the
+ * user can input
+ * whatever they wish, usually by means of a <code>JTextField</code>.
+ * <code>initialSelectionValue</code> is the initial value to prompt
+ * the user with. It is up to the UI to decide how best to represent
+ * the <code>selectionValues</code>, but usually a
+ * <code>JComboBox</code>, <code>JList</code>, or
+ * <code>JTextField</code> will be used.
+ *
+ * @param parentComponent the parent <code>Component</code> for the
+ * dialog
+ * @param message the <code>Object</code> to display
+ * @param title the <code>String</code> to display in the
+ * dialog title bar
+ * @param messageType the type of message to be displayed:
+ * <code>ERROR_MESSAGE</code>,
+ * <code>INFORMATION_MESSAGE</code>,
+ * <code>WARNING_MESSAGE</code>,
+ * <code>QUESTION_MESSAGE</code>,
+ * or <code>PLAIN_MESSAGE</code>
+ * @param icon the <code>Icon</code> image to display
+ * @param selectionValues an array of <code>Object</code>s that
+ * gives the possible selections
+ * @param initialSelectionValue the value used to initialize the input
+ * field
+ * @return user's input, or <code>null</code> meaning the user
+ * canceled the input
+ * @exception HeadlessException if
+ * <code>GraphicsEnvironment.isHeadless</code> returns
+ * <code>true</code>
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ */
+ public static Object showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) throws HeadlessException
+ {
+ CWOptionPane pane = new CWOptionPane(message, messageType, OK_CANCEL_OPTION, icon, null, null);
+
+ pane.setWantsInput(true);
+ pane.setSelectionValues(selectionValues);
+ pane.setInitialSelectionValue(initialSelectionValue);
+ GuiUtil.applyDefaultOrientation(pane);
+
+ int style = styleFromMessageType(messageType);
+ JDialog dialog = pane.createDialog(parentComponent, title, style);
+
+ pane.selectInitialValue();
+ dialog.show();
+ dialog.dispose();
+
+ Object value = pane.getInputValue();
+
+ if (value == UNINITIALIZED_VALUE)
+ {
+ return null;
+ }
+
+ return value;
+ }
+
+ /**
+ * Brings up an information-message dialog titled "Message".
+ *
+ * @param parentComponent determines the <code>Frame</code> in
+ * which the dialog is displayed; if <code>null</code>,
+ * or if the <code>parentComponent</code> has no
+ * <code>Frame</code>, a default <code>Frame</code> is used
+ * @param message the <code>Object</code> to display
+ * @exception HeadlessException if
+ * <code>GraphicsEnvironment.isHeadless</code> returns
+ * <code>true</code>
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ */
+ public static void showMessageDialog(Component parentComponent, Object message) throws HeadlessException
+ {
+ showMessageDialog(parentComponent, message, "?", INFORMATION_MESSAGE); //$NON-NLS-1$
+ }
+
+ /**
+ * Brings up a dialog that displays a message using a default
+ * icon determined by the <code>messageType</code> parameter.
+ *
+ * @param parentComponent determines the <code>Frame</code>
+ * in which the dialog is displayed; if <code>null</code>,
+ * or if the <code>parentComponent</code> has no
+ * <code>Frame</code>, a default <code>Frame</code> is used
+ * @param message the <code>Object</code> to display
+ * @param title the title string for the dialog
+ * @param messageType the type of message to be displayed:
+ * <code>ERROR_MESSAGE</code>,
+ * <code>INFORMATION_MESSAGE</code>,
+ * <code>WARNING_MESSAGE</code>,
+ * <code>QUESTION_MESSAGE</code>,
+ * or <code>PLAIN_MESSAGE</code>
+ * @exception HeadlessException if
+ * <code>GraphicsEnvironment.isHeadless</code> returns
+ * <code>true</code>
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ */
+ public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType) throws HeadlessException
+ {
+ showMessageDialog(parentComponent, message, title, messageType, null);
+ }
+
+ /**
+ * Brings up a dialog displaying a message, specifying all parameters.
+ *
+ * @param parentComponent determines the <code>Frame</code> in which the
+ * dialog is displayed; if <code>null</code>,
+ * or if the <code>parentComponent</code> has no
+ * <code>Frame</code>, a
+ * default <code>Frame</code> is used
+ * @param message the <code>Object</code> to display
+ * @param title the title string for the dialog
+ * @param messageType the type of message to be displayed:
+ * <code>ERROR_MESSAGE</code>,
+ * <code>INFORMATION_MESSAGE</code>,
+ * <code>WARNING_MESSAGE</code>,
+ * <code>QUESTION_MESSAGE</code>,
+ * or <code>PLAIN_MESSAGE</code>
+ * @param icon an icon to display in the dialog that helps the user
+ * identify the kind of message that is being displayed
+ * @exception HeadlessException if
+ * <code>GraphicsEnvironment.isHeadless</code> returns
+ * <code>true</code>
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ */
+ public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon) throws HeadlessException
+ {
+ showOptionDialog(parentComponent, message, title, DEFAULT_OPTION, messageType, icon, null, null);
+ }
+
+ /**
+ * Brings up a dialog with the options <i>Yes</i>,
+ * <i>No</i> and <i>Cancel</i>; with the
+ * title, <b>Select an Option</b>.
+ *
+ * @param parentComponent determines the <code>Frame</code> in which the
+ * dialog is displayed; if <code>null</code>,
+ * or if the <code>parentComponent</code> has no
+ * <code>Frame</code>, a
+ * default <code>Frame</code> is used
+ * @param message the <code>Object</code> to display
+ * @return an integer indicating the option selected by the user
+ * @exception HeadlessException if
+ * <code>GraphicsEnvironment.isHeadless</code> returns
+ * <code>true</code>
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ */
+ public static int showConfirmDialog(Component parentComponent, Object message) throws HeadlessException
+ {
+ return showConfirmDialog(parentComponent, message, "?", YES_NO_CANCEL_OPTION); //$NON-NLS-1$
+ }
+
+ /**
+ * Brings up a dialog where the number of choices is determined
+ * by the <code>optionType</code> parameter.
+ *
+ * @param parentComponent determines the <code>Frame</code> in which the
+ * dialog is displayed; if <code>null</code>,
+ * or if the <code>parentComponent</code> has no
+ * <code>Frame</code>, a
+ * default <code>Frame</code> is used
+ * @param message the <code>Object</code> to display
+ * @param title the title string for the dialog
+ * @param optionType an int designating the options available on the dialog:
+ * <code>YES_NO_OPTION</code>, or
+ * <code>YES_NO_CANCEL_OPTION</code>
+ * @return an int indicating the option selected by the user
+ * @exception HeadlessException if
+ * <code>GraphicsEnvironment.isHeadless</code> returns
+ * <code>true</code>
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ */
+ public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType) throws HeadlessException
+ {
+ return showConfirmDialog(parentComponent, message, title, optionType, QUESTION_MESSAGE);
+ }
+
+ /**
+ * Brings up a dialog where the number of choices is determined
+ * by the <code>optionType</code> parameter, where the
+ * <code>messageType</code>
+ * parameter determines the icon to display.
+ * The <code>messageType</code> parameter is primarily used to supply
+ * a default icon from the Look and Feel.
+ *
+ * @param parentComponent determines the <code>Frame</code> in
+ * which the dialog is displayed; if <code>null</code>,
+ * or if the <code>parentComponent</code> has no
+ * <code>Frame</code>, a
+ * default <code>Frame</code> is used.
+ * @param message the <code>Object</code> to display
+ * @param title the title string for the dialog
+ * @param optionType an integer designating the options available
+ * on the dialog: <code>YES_NO_OPTION</code>,
+ * or <code>YES_NO_CANCEL_OPTION</code>
+ * @param messageType an integer designating the kind of message this is;
+ * primarily used to determine the icon from the pluggable
+ * Look and Feel: <code>ERROR_MESSAGE</code>,
+ * <code>INFORMATION_MESSAGE</code>,
+ * <code>WARNING_MESSAGE</code>,
+ * <code>QUESTION_MESSAGE</code>,
+ * or <code>PLAIN_MESSAGE</code>
+ * @return an integer indicating the option selected by the user
+ * @exception HeadlessException if
+ * <code>GraphicsEnvironment.isHeadless</code> returns
+ * <code>true</code>
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ */
+ public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) throws HeadlessException
+ {
+ return showConfirmDialog(parentComponent, message, title, optionType, messageType, null);
+ }
+
+ /**
+ * Brings up a dialog with a specified icon, where the number of
+ * choices is determined by the <code>optionType</code> parameter.
+ * The <code>messageType</code> parameter is primarily used to supply
+ * a default icon from the look and feel.
+ *
+ * @param parentComponent determines the <code>Frame</code> in which the
+ * dialog is displayed; if <code>null</code>,
+ * or if the <code>parentComponent</code> has no
+ * <code>Frame</code>, a
+ * default <code>Frame</code> is used
+ * @param message the Object to display
+ * @param title the title string for the dialog
+ * @param optionType an int designating the options available on the dialog:
+ * <code>YES_NO_OPTION</code>,
+ * or <code>YES_NO_CANCEL_OPTION</code>
+ * @param messageType an int designating the kind of message this is,
+ * primarily used to determine the icon from the pluggable
+ * Look and Feel: <code>ERROR_MESSAGE</code>,
+ * <code>INFORMATION_MESSAGE</code>,
+ * <code>WARNING_MESSAGE</code>,
+ * <code>QUESTION_MESSAGE</code>,
+ * or <code>PLAIN_MESSAGE</code>
+ * @param icon the icon to display in the dialog
+ * @return an int indicating the option selected by the user
+ * @exception HeadlessException if
+ * <code>GraphicsEnvironment.isHeadless</code> returns
+ * <code>true</code>
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ */
+ public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon) throws HeadlessException
+ {
+ return showOptionDialog(parentComponent, message, title, optionType, messageType, icon, null, null);
+ }
+
+ /**
+ * Brings up a dialog with a specified icon, where the initial choice is
+ * determined by the <code>initialValue</code> parameter and the number of
+ * choices is determined by the <code>optionType</code> parameter.
+ * <p>
+ * If <code>optionType</code> is <code>YES_NO_OPTION</code>, or
+ * <code>YES_NO_CANCEL_OPTION</code> and the <code>options</code>
+ * parameter is <code>null</code>, then the options are supplied by the
+ * look and feel.
+ * <p>
+ * The <code>messageType</code> parameter is primarily used to supply a
+ * default icon from the look and feel.
+ *
+ * @param parentComponent determines the <code>Frame</code> in which the
+ * dialog is displayed; if <code>null</code>, or if the
+ * <code>parentComponent</code> has no <code>Frame</code>, a
+ * default <code>Frame</code> is used
+ * @param message the <code>Object</code> to display
+ * @param title the title string for the dialog
+ * @param optionType an integer designating the options available on the
+ * dialog: <code>YES_NO_OPTION</code>, or
+ * <code>YES_NO_CANCEL_OPTION</code>
+ * @param messageType an integer designating the kind of message this is,
+ * primarily used to determine the icon from the pluggable Look
+ * and Feel: <code>ERROR_MESSAGE</code>,
+ * <code>INFORMATION_MESSAGE</code>,
+ * <code>WARNING_MESSAGE</code>, <code>QUESTION_MESSAGE</code>,
+ * or <code>PLAIN_MESSAGE</code>
+ * @param icon the icon to display in the dialog
+ * @param options an array of objects indicating the possible choices the
+ * user can make; if the objects are components, they are
+ * rendered properly; non-<code>String</code> objects are
+ * rendered using their <code>toString</code> methods; if this
+ * parameter is <code>null</code>, the options are determined
+ * by the Look and Feel
+ * @param initialValue the object that represents the default selection for
+ * the dialog; only meaningful if <code>options</code> is used;
+ * can be <code>null</code>
+ * @return an integer indicating the option chosen by the user, or
+ * <code>CLOSED_OPTION</code> if the user closed the dialog
+ * @exception HeadlessException if
+ * <code>GraphicsEnvironment.isHeadless</code> returns
+ * <code>true</code>
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ */
+ public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException
+ {
+ CWOptionPane pane = new CWOptionPane(message, messageType, optionType, icon, options, initialValue);
+
+ pane.setInitialValue(initialValue);
+ GuiUtil.applyDefaultOrientation(pane);
+
+ int style = styleFromMessageType(messageType);
+ JDialog dialog = pane.createDialog(parentComponent, title, style);
+
+ pane.selectInitialValue();
+ dialog.show();
+ dialog.dispose();
+
+ Object selectedValue = pane.getValue();
+
+ if (selectedValue == null)
+ {
+ return CLOSED_OPTION;
+ }
+
+ Object [] opts = pane.getOptions();
+ if (opts == null)
+ {
+ if (selectedValue instanceof Integer)
+ {
+ return ((Integer) selectedValue).intValue();
+ }
+ return CLOSED_OPTION;
+ }
+
+ if (getActionName("Yes").equals(selectedValue)) //$NON-NLS-1$
+ {
+ return YES_OPTION;
+ }
+
+ if (getActionName("No").equals(selectedValue)) //$NON-NLS-1$
+ {
+ return NO_OPTION;
+ }
+
+ if (getActionName("OK").equals(selectedValue)) //$NON-NLS-1$
+ {
+ return OK_OPTION;
+ }
+
+ if (getActionName("CANCEL").equals(selectedValue)) //$NON-NLS-1$
+ {
+ return CANCEL_OPTION;
+ }
+
+ for (int counter = 0, maxCounter = opts.length; counter < maxCounter; counter++ )
+ {
+ if (opts[counter].equals(selectedValue))
+ {
+ return counter;
+ }
+ }
+
+ return CLOSED_OPTION;
+ }
+
+ private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException
+ {
+
+ final JDialog dialog;
+
+ Window window = GuiUtil.getWindow(parentComponent);
+ if (window instanceof Frame)
+ {
+ dialog = new JDialog((Frame) window, title, true);
+ }
+ else
+ {
+ dialog = new JDialog((Dialog) window, title, true);
+ }
+
+ Container contentPane = dialog.getContentPane();
+
+ contentPane.setLayout(new BorderLayout());
+ contentPane.add(this, BorderLayout.CENTER);
+ dialog.setResizable(false);
+
+ if (JDialog.isDefaultLookAndFeelDecorated())
+ {
+ boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();
+ if (supportsWindowDecorations)
+ {
+ dialog.setUndecorated(true);
+ getRootPane().setWindowDecorationStyle(style);
+ }
+ }
+
+ dialog.pack();
+ dialog.setLocationRelativeTo(parentComponent);
+ dialog.addWindowListener(new WindowAdapter()
+ {
+ private boolean gotFocus = false;
+
+ public void windowClosing(WindowEvent we)
+ {
+ setValue(null);
+ }
+
+ public void windowGainedFocus(WindowEvent we)
+ {
+ // Once window gets focus, set initial focus
+ if ( !gotFocus)
+ {
+ selectInitialValue();
+ gotFocus = true;
+ }
+ }
+ });
+
+ dialog.addComponentListener(new ComponentAdapter()
+ {
+ public void componentShown(ComponentEvent ce)
+ {
+ // reset value to ensure closing works properly
+ setValue(JOptionPane.UNINITIALIZED_VALUE);
+ }
+ });
+
+ addPropertyChangeListener(new PropertyChangeListener()
+ {
+ public void propertyChange(PropertyChangeEvent event)
+ {
+ // Let the defaultCloseOperation handle the closing
+ // if the user closed the window without selecting a button
+ // (newValue = null in that case). Otherwise, close the dialog.
+ if (dialog.isVisible() &&
+ event.getSource() == CWOptionPane.this &&
+ event.getPropertyName().equals(VALUE_PROPERTY) &&
+ event.getNewValue() != null &&
+ event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE)
+ {
+ dialog.setVisible(false);
+ }
+ }
+ });
+
+ return dialog;
+ }
+
+ private static int styleFromMessageType(int messageType)
+ {
+ switch (messageType)
+ {
+ case ERROR_MESSAGE:
+ return JRootPane.ERROR_DIALOG;
+ case QUESTION_MESSAGE:
+ return JRootPane.QUESTION_DIALOG;
+ case WARNING_MESSAGE:
+ return JRootPane.WARNING_DIALOG;
+ case INFORMATION_MESSAGE:
+ return JRootPane.INFORMATION_DIALOG;
+ case PLAIN_MESSAGE:
+ default:
+ return JRootPane.PLAIN_DIALOG;
+ }
+ }
+
+ private static String getActionName(String key)
+ {
+ if (actions == null)
+ {
+ actions = new ActionFactory(CWOptionPane.class, null);
+ }
+
+ return actions.getAction(key).getValue(Action.NAME).toString();
+ }
+
+ private static Object[] fixOptions(Object[] options, int optionType)
+ {
+ Object[] opts = options;
+ if (options == null)
+ {
+ switch (optionType)
+ {
+ case YES_NO_OPTION:
+ opts = new Object[]
+ {
+ getActionName("Yes"), //$NON-NLS-1$
+ getActionName("No")}; //$NON-NLS-1$
+ break;
+ case OK_CANCEL_OPTION:
+ opts = new Object[]
+ {
+ getActionName("OK"), //$NON-NLS-1$
+ getActionName("Cancel")}; //$NON-NLS-1$
+ break;
+ default:
+ opts = new Object[]
+ {
+ getActionName("Yes"), //$NON-NLS-1$
+ getActionName("No"), //$NON-NLS-1$
+ getActionName("Cancel")}; //$NON-NLS-1$
+ break;
+ }
+ }
+ return opts;
+ }
+
+ /**
+ * The actions for this dialog.
+ */
+ protected static ActionFactory actions;
+
+ /**
+ * Serialization ID
+ */
+ private static final long serialVersionUID = -1870422750863765033L;
+
+}
Added: trunk/common-swing/src/main/java/org/crosswire/common/swing/CWOptionPane.properties
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/CWOptionPane.properties (rev 0)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/CWOptionPane.properties 2008-05-10 18:34:02 UTC (rev 1850)
@@ -0,0 +1,4 @@
+Yes.Name=Alias.Yes
+No.Name=Alias.No
+OK.Name=Alias.OK
+Cancel.Name=Alias.Cancel
Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -48,7 +48,6 @@
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
-import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
@@ -655,11 +654,11 @@
{
if (event.getSource() instanceof Component)
{
- JOptionPane.showMessageDialog((Component) event.getSource(), event.getMessage());
+ CWOptionPane.showMessageDialog((Component) event.getSource(), event.getMessage());
}
else
{
- JOptionPane.showMessageDialog(null, event.getMessage());
+ CWOptionPane.showMessageDialog(null, event.getMessage());
}
}
Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -95,12 +95,12 @@
{
Component temp = com;
- while (!(temp instanceof Window))
+ while (!(temp instanceof Frame || temp instanceof Dialog))
{
temp = temp.getParent();
if (temp == null)
{
- return null;
+ return getFrame(com);
}
}
@@ -108,6 +108,16 @@
}
/**
+ * Find the best frame to which to root a dialog, generally the largest visible
+ * frame of the application.
+ * @return the best frame.
+ */
+ public static Frame getRootFrame()
+ {
+ return getFrame(null);
+ }
+
+ /**
* Find the parent Frame. This method can do more than simply walking up
* the tree to find a parent frame by looking for default frames from
* JOptionPane and by looking for all visible Frames. We can be sure to
Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -23,7 +23,6 @@
import java.util.Enumeration;
-import javax.swing.JOptionPane;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
@@ -87,7 +86,7 @@
// newLaFClass is null if the user enters a bogus value
if (currentLAF != null && !currentLAF.equals(newLaFClass))
{
- JOptionPane.showMessageDialog(null, Msg.PLAF_CHANGE);
+ CWOptionPane.showMessageDialog(null, Msg.PLAF_CHANGE);
}
else
{
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/install/InstallManager.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/install/InstallManager.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/install/InstallManager.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -30,12 +30,12 @@
import java.util.Properties;
import java.util.Set;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.EventListenerList;
import org.crosswire.common.util.Logger;
import org.crosswire.common.util.NetUtil;
import org.crosswire.common.util.PluginUtil;
import org.crosswire.common.util.Reporter;
-import org.crosswire.jsword.util.Project;
/**
* A manager to abstract out the non-view specific book installation tasks.
@@ -119,7 +119,7 @@
buf.append(installer.getInstallerDefinition());
props.setProperty(PREFIX + i++, buf.toString());
}
- URI outputURI = Project.instance().getWritablePropertiesURI(getClass().getName());
+ URI outputURI = CWProject.instance().getWritablePropertiesURI(getClass().getName());
try
{
NetUtil.storeProperties(props, outputURI, "Saved Installer Sites"); //$NON-NLS-1$
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/install/sword/AbstractSwordInstaller.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/install/sword/AbstractSwordInstaller.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/install/sword/AbstractSwordInstaller.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -34,6 +34,7 @@
import org.crosswire.common.progress.JobManager;
import org.crosswire.common.progress.Progress;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.CollectionUtil;
import org.crosswire.common.util.IOUtil;
import org.crosswire.common.util.Logger;
@@ -56,7 +57,6 @@
import org.crosswire.jsword.book.sword.SwordBookMetaData;
import org.crosswire.jsword.book.sword.SwordBookPath;
import org.crosswire.jsword.book.sword.SwordConstants;
-import org.crosswire.jsword.util.Project;
import com.ice.tar.TarEntry;
import com.ice.tar.TarInputStream;
@@ -238,7 +238,7 @@
/* @Override */
public void run()
{
- URI predictURI = Project.instance().getWritablePropertiesURI("sword-install"); //$NON-NLS-1$
+ URI predictURI = CWProject.instance().getWritablePropertiesURI("sword-install"); //$NON-NLS-1$
Progress job = JobManager.createJob(UserMsg.INSTALLING.toString(sbmd.getName()), predictURI, this, true);
yield();
@@ -555,7 +555,7 @@
{
try
{
- URI scratchdir = Project.instance().getWriteableProjectSubdir(getTempFileExtension(host, catalogDirectory), true);
+ URI scratchdir = CWProject.instance().getWriteableProjectSubdir(getTempFileExtension(host, catalogDirectory), true);
return NetUtil.lengthenURI(scratchdir, FILE_LIST_GZ);
}
catch (IOException ex)
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookPath.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookPath.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookPath.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -31,12 +31,12 @@
import java.util.List;
import java.util.Properties;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.Logger;
import org.crosswire.common.util.OSType;
import org.crosswire.common.util.StringUtil;
import org.crosswire.jsword.book.BookException;
import org.crosswire.jsword.book.Books;
-import org.crosswire.jsword.util.Project;
/**
* This represents all of the Sword Books (aka modules).
@@ -196,7 +196,7 @@
// JSword used to hold books in ~/.jsword (or its equivalent) but has code that will
// migrate it to ~/.sword (or its equivalent)
// If the migration did not work then use the old area
- testDefaultPath(bookDirs, new File(Project.instance().getWritableProjectDir().getPath()));
+ testDefaultPath(bookDirs, new File(CWProject.instance().getWritableProjectDir().getPath()));
return (File[]) bookDirs.toArray(new File[bookDirs.size()]);
}
@@ -316,7 +316,7 @@
// The "old" Book location might be in one of two locations
// It might be ~/.jsword or the new project dir
- File oldPath = new File(Project.instance().getDeprecatedWritableProjectDir().getPath());
+ File oldPath = new File(CWProject.instance().getDeprecatedWritableProjectDir().getPath());
if (oldPath.isDirectory())
{
@@ -324,7 +324,7 @@
return;
}
- oldPath = new File(Project.instance().getWritableProjectDir().getPath());
+ oldPath = new File(CWProject.instance().getWritableProjectDir().getPath());
if (oldPath.isDirectory())
{
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/index/lucene/LuceneIndexManager.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/index/lucene/LuceneIndexManager.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/index/lucene/LuceneIndexManager.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.FileUtil;
import org.crosswire.common.util.IOUtil;
import org.crosswire.common.util.Logger;
@@ -38,7 +39,6 @@
import org.crosswire.jsword.index.Index;
import org.crosswire.jsword.index.IndexManager;
import org.crosswire.jsword.index.IndexStatus;
-import org.crosswire.jsword.util.Project;
/**
* An implementation of IndexManager for Lucene indexes.
@@ -190,7 +190,7 @@
assert driverName != null;
assert bookName != null;
- URI base = Project.instance().getWriteableProjectSubdir(DIR_LUCENE, false);
+ URI base = CWProject.instance().getWriteableProjectSubdir(DIR_LUCENE, false);
URI driver = NetUtil.lengthenURI(base, driverName);
return NetUtil.lengthenURI(driver, bookName);
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/util/WebWarning.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/util/WebWarning.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/util/WebWarning.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -25,6 +25,7 @@
import java.net.URI;
import java.util.Properties;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.Logger;
import org.crosswire.common.util.NetUtil;
import org.crosswire.common.util.ResourceUtil;
@@ -76,7 +77,7 @@
shown = newShown;
Properties props = new Properties();
props.put(SHOWN_KEY, Boolean.valueOf(shown).toString());
- URI outputURI = Project.instance().getWritablePropertiesURI(getClass().getName());
+ URI outputURI = CWProject.instance().getWritablePropertiesURI(getClass().getName());
NetUtil.storeProperties(props, outputURI, "JSword WebWarning"); //$NON-NLS-1$
}
catch (IOException ex)
Modified: trunk/jsword/src/test/java/org/crosswire/jsword/book/GatherAllReferences.java
===================================================================
--- trunk/jsword/src/test/java/org/crosswire/jsword/book/GatherAllReferences.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/jsword/src/test/java/org/crosswire/jsword/book/GatherAllReferences.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -35,6 +35,7 @@
import org.crosswire.common.config.ChoiceFactory;
import org.crosswire.common.config.Config;
import org.crosswire.common.util.CWClassLoader;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.Logger;
import org.crosswire.common.util.ResourceUtil;
import org.crosswire.common.xml.XMLUtil;
@@ -42,7 +43,6 @@
import org.crosswire.jsword.passage.KeyFactory;
import org.crosswire.jsword.passage.NoSuchKeyException;
import org.crosswire.jsword.passage.PassageKeyFactory;
-import org.crosswire.jsword.util.Project;
import org.jdom.Document;
import org.jdom.JDOMException;
@@ -72,7 +72,7 @@
// ~/.jsword
// This will set it as a place to look for overrides for
// ResourceBundles, properties and other resources
- Project.instance();
+ CWProject.instance();
// And the array of allowed osis>html converters
ChoiceFactory.getDataMap().put("converters", new String[] {}); //$NON-NLS-1$
Modified: trunk/jsword/src/test/java/org/crosswire/jsword/book/ReadEverything.java
===================================================================
--- trunk/jsword/src/test/java/org/crosswire/jsword/book/ReadEverything.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/jsword/src/test/java/org/crosswire/jsword/book/ReadEverything.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -30,11 +30,11 @@
import org.crosswire.common.config.ChoiceFactory;
import org.crosswire.common.config.Config;
import org.crosswire.common.util.CWClassLoader;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.Logger;
import org.crosswire.common.util.ResourceUtil;
import org.crosswire.common.xml.XMLUtil;
import org.crosswire.jsword.passage.Key;
-import org.crosswire.jsword.util.Project;
import org.jdom.Document;
import org.jdom.JDOMException;
@@ -61,11 +61,11 @@
{
Logger.outputEverything();
- // Calling Project.instance() will set up the project's home directory
- // ~/.jsword
+ // This must be the first static in the program.
+ // To ensure this we place it at the top of the class!
// This will set it as a place to look for overrides for
// ResourceBundles, properties and other resources
- Project.instance();
+ CWProject.instance().setHome("jsword.home", ".jsword", "JSword"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// And the array of allowed osis>html converters
ChoiceFactory.getDataMap().put("converters", new String[] {}); //$NON-NLS-1$
Modified: trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop/DebugPane.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop/DebugPane.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop/DebugPane.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -46,8 +46,8 @@
import org.crosswire.bibledesktop.book.BibleViewPane;
import org.crosswire.common.progress.JobManager;
import org.crosswire.common.progress.Progress;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.Logger;
-import org.crosswire.jsword.util.Project;
/**
* Various debug actions, for easy editing to help us hack over time.
@@ -181,7 +181,7 @@
*/
public static void createTestJob(final long millis, final String predictbase, final int steps, final boolean fake)
{
- final URI predicturl = Project.instance().getWritablePropertiesURI(predictbase);
+ final URI predicturl = CWProject.instance().getWritablePropertiesURI(predictbase);
final Thread test = new Thread()
{
/* (non-Javadoc)
Modified: trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser/SerIndexManager.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser/SerIndexManager.java 2008-05-10 15:24:02 UTC (rev 1849)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser/SerIndexManager.java 2008-05-10 18:34:02 UTC (rev 1850)
@@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.crosswire.common.util.CWProject;
import org.crosswire.common.util.IOUtil;
import org.crosswire.common.util.Logger;
import org.crosswire.common.util.NetUtil;
@@ -36,7 +37,6 @@
import org.crosswire.jsword.book.BookMetaData;
import org.crosswire.jsword.index.Index;
import org.crosswire.jsword.index.IndexManager;
-import org.crosswire.jsword.util.Project;
/**
* An implementation of IndexManager that controls Ser indexes.
@@ -161,7 +161,7 @@
assert driverName != null;
assert bookName != null;
- URI base = Project.instance().getWriteableProjectSubdir(DIR_SER, false);
+ URI base = CWProject.instance().getWriteableProjectSubdir(DIR_SER, false);
URI driver = NetUtil.lengthenURI(base, driverName);
return NetUtil.lengthenURI(driver, bookName);
More information about the jsword-svn
mailing list