[jsword-svn] r1151 - in trunk/common-swing/src/main/java/org/crosswire/common: config/swing swing swing/desktop
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Tue Oct 10 16:30:04 MST 2006
Author: dmsmith
Date: 2006-10-10 16:29:42 -0700 (Tue, 10 Oct 2006)
New Revision: 1151
Removed:
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/MapField.java
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/MapField.properties
Modified:
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AbstractConfigEditor.java
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AdvancedConfigEditor.java
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/ButtonPane.java
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/ConfigEditorFactory.java
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/FieldMap.java
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/Msg.java
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/Msg.properties
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/OptionsField.java
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/WizardConfigEditor.java
trunk/common-swing/src/main/java/org/crosswire/common/swing/ActionFactory.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/desktop/AbstractViewLayout.java
trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/MDIViewLayout.java
trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/ViewManager.java
Log:
Fixing bugs reported by findbugs.
Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AbstractConfigEditor.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AbstractConfigEditor.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AbstractConfigEditor.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -42,7 +42,6 @@
import org.crosswire.common.swing.FormPane;
import org.crosswire.common.swing.GuiUtil;
import org.crosswire.common.util.Logger;
-import org.crosswire.common.util.Reporter;
/**
* Page of a Config.
@@ -139,16 +138,9 @@
*/
public void okPressed(ActionEvent ev)
{
- try
- {
- screenToLocal();
- al.actionPerformed(ev);
- hideDialog();
- }
- catch (Exception ex)
- {
- Reporter.informUser(this, ex);
- }
+ screenToLocal();
+ al.actionPerformed(ev);
+ hideDialog();
}
/* (non-Javadoc)
@@ -164,19 +156,12 @@
*/
public void applyPressed(ActionEvent ev)
{
- try
+ screenToLocal();
+ al.actionPerformed(ev);
+ if (dialog != null)
{
- screenToLocal();
- al.actionPerformed(ev);
- if (dialog != null)
- {
- dialog.pack();
- }
+ dialog.pack();
}
- catch (Exception ex)
- {
- Reporter.informUser(this, ex);
- }
}
/**
@@ -186,37 +171,30 @@
{
String path = Config.getPath(model.getFullPath());
- try
- {
- // Check if we want to display this option
- Field field = FieldMap.getField(model);
- fields.put(key, field);
+ // Check if we want to display this option
+ Field field = FieldMap.getField(model);
+ fields.put(key, field);
- // Get or create a FieldPanel
- FormPane card = (FormPane) decks.get(path);
+ // Get or create a FieldPanel
+ FormPane card = (FormPane) decks.get(path);
- if (card == null)
- {
- card = new FormPane();
- decks.put(path, card);
- cards++;
- }
+ if (card == null)
+ {
+ card = new FormPane();
+ decks.put(path, card);
+ cards++;
+ }
- // Add the Field to the FieldPanel
- JComponent comp = field.getComponent();
- comp.setToolTipText(model.getHelpText());
+ // Add the Field to the FieldPanel
+ JComponent comp = field.getComponent();
+ comp.setToolTipText(model.getHelpText());
- String name = Config.getLeaf(model.getFullPath()) + ':';
- card.addEntry(name, comp);
+ String name = Config.getLeaf(model.getFullPath()) + ':';
+ card.addEntry(name, comp);
- // Fill in the current value
- String value = config.getLocal(key);
- field.setValue(value);
- }
- catch (Exception ex)
- {
- Reporter.informUser(this, ex);
- }
+ // Fill in the current value
+ String value = config.getLocal(key);
+ field.setValue(value);
}
/**
@@ -226,28 +204,21 @@
{
String path = Config.getPath(model.getFullPath());
- try
+ Field field = (Field) fields.get(key);
+ if (field != null)
{
- Field field = (Field) fields.get(key);
- if (field != null)
- {
- fields.remove(field);
- FormPane card = (FormPane) decks.get(path);
+ fields.remove(field);
+ FormPane card = (FormPane) decks.get(path);
- // Remove field from card.
- String name = Config.getLeaf(model.getFullPath()) + ':';
- card.removeEntry(name);
+ // Remove field from card.
+ String name = Config.getLeaf(model.getFullPath()) + ':';
+ card.removeEntry(name);
- if (card.isEmpty())
- {
- decks.remove(card);
- }
+ if (card.isEmpty())
+ {
+ decks.remove(card);
}
}
- catch (Exception ex)
- {
- Reporter.informUser(this, ex);
- }
}
/**
@@ -272,23 +243,16 @@
Iterator it = config.getNames();
while (it.hasNext())
{
- try
- {
- String key = (String) it.next();
- Field field = (Field) fields.get(key);
- String value = field.getValue();
+ String key = (String) it.next();
+ Field field = (Field) fields.get(key);
+ String value = field.getValue();
- if (value == null)
- {
- log.error("null value from key=" + key); //$NON-NLS-1$
- }
-
- config.setLocal(key, value);
- }
- catch (Exception ex)
+ if (value == null)
{
- Reporter.informUser(this, ex);
+ log.error("null value from key=" + key); //$NON-NLS-1$
}
+
+ config.setLocal(key, value);
}
}
@@ -300,25 +264,18 @@
Iterator it = config.getNames();
while (it.hasNext())
{
- try
- {
- String key = (String) it.next();
+ String key = (String) it.next();
- Field field = (Field) fields.get(key);
- String value = config.getLocal(key);
+ Field field = (Field) fields.get(key);
+ String value = config.getLocal(key);
- if (field == null)
- {
- log.error("Null field from key=" + key + ", skipping setting value=" + value); //$NON-NLS-1$ //$NON-NLS-2$
- }
- else
- {
- field.setValue(value);
- }
+ if (field == null)
+ {
+ log.error("Null field from key=" + key + ", skipping setting value=" + value); //$NON-NLS-1$ //$NON-NLS-2$
}
- catch (Exception ex)
+ else
{
- Reporter.informUser(this, ex);
+ field.setValue(value);
}
}
}
Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AdvancedConfigEditor.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AdvancedConfigEditor.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AdvancedConfigEditor.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -39,7 +39,6 @@
import javax.swing.tree.DefaultTreeCellRenderer;
import org.crosswire.common.config.Choice;
-import org.crosswire.common.util.Reporter;
/**
* A mutable view of Fields setting array.
@@ -110,24 +109,17 @@
*/
protected void addChoice(String key, Choice model)
{
- try
- {
- Field field = FieldMap.getField(model);
- fields.put(key, field);
+ Field field = FieldMap.getField(model);
+ fields.put(key, field);
- // Add the Field to the FieldPanel
- JComponent comp = field.getComponent();
- comp.setToolTipText(model.getHelpText());
- comps.put(key, comp);
+ // Add the Field to the FieldPanel
+ JComponent comp = field.getComponent();
+ comp.setToolTipText(model.getHelpText());
+ comps.put(key, comp);
- // Fill in the current value
- String value = config.getLocal(key);
- field.setValue(value);
- }
- catch (Exception ex)
- {
- Reporter.informUser(this, ex);
- }
+ // Fill in the current value
+ String value = config.getLocal(key);
+ field.setValue(value);
}
/**
@@ -135,30 +127,22 @@
*/
protected void removeChoice(String key)
{
- try
+ Field field = (Field) fields.get(key);
+ if (field != null)
{
- Field field = (Field) fields.get(key);
- if (field != null)
- {
- fields.remove(field);
- }
-
- Component comp = (Component) comps.get(key);
- if (comp != null)
- {
- comps.remove(key);
- }
+ fields.remove(field);
}
- catch (Exception ex)
+
+ Component comp = (Component) comps.get(key);
+ if (comp != null)
{
- Reporter.informUser(this, ex);
+ comps.remove(key);
}
}
/**
- * Used to update the configuration panel whenever someone
- * selects a different item form the tree on the LHS of the
- * configuation dialog.
+ * Used to update the configuration panel whenever someone selects a
+ * different item form the tree on the LHS of the configuation dialog.
*/
public void selectCard()
{
Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/ButtonPane.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/ButtonPane.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/ButtonPane.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -109,7 +109,7 @@
/**
* The action factory for the buttons
*/
- private static transient ActionFactory actions;
+ private transient ActionFactory actions;
/**
* PENDING: turn this into a [add|remove]ButtonPaneListener thing
Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/ConfigEditorFactory.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/ConfigEditorFactory.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/ConfigEditorFactory.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -58,24 +58,48 @@
*/
public static void showDialog(Config config, Component parent, ActionListener al)
{
+ Exception ex = null;
try
{
ConfigEditor base = (ConfigEditor) ClassUtil.getImplementation(ConfigEditor.class);
base.construct(config);
base.showDialog(parent, al);
}
- catch (Exception ex)
+ catch (ClassCastException e)
{
+ ex = e;
+ }
+ catch (IOException e)
+ {
+ ex = e;
+ }
+ catch (ClassNotFoundException e)
+ {
+ ex = e;
+ }
+ catch (InstantiationException e)
+ {
+ ex = e;
+ }
+ catch (IllegalAccessException e)
+ {
+ ex = e;
+ }
+
+ if (ex != null)
+ {
Reporter.informUser(parent, ex);
}
}
/**
- * Create a dialog to house a TreeConfig component
- * using the default set of Fields, with the default accept action
- * of config.localToAppliation and config,localToPermanentURL
+ * Create a dialog to house a TreeConfig component using the default set of
+ * Fields, with the default accept action of config.localToAppliation and
+ * config,localToPermanentURL
+ *
* @param config The set of Choices to display
- * @param parent A component to use to find a frame to use as a dialog parent
+ * @param parent A component to use to find a frame to use as a dialog
+ * parent
*/
public static void showDialog(Config config, Component parent, URL url)
{
Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/FieldMap.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/FieldMap.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/FieldMap.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -57,7 +57,7 @@
public static Field getField(Choice type)
{
Field field = null;
-
+ Exception ex = null;
try
{
// We need to treat instances of MultipleChoice differently
@@ -80,17 +80,27 @@
field = new TextField();
}
}
+ field.setChoice(type);
}
- catch (Exception ex)
+ catch (InstantiationException e)
{
+ ex = e;
+ }
+ catch (IllegalAccessException e)
+ {
+ ex = e;
+ }
+
+ if (ex != null)
+ {
log.warn("field type (" + type + ") initialization failed:", ex); //$NON-NLS-1$ //$NON-NLS-2$
Reporter.informUser(type, ex);
log.warn("field type (" + type + ") unregistered."); //$NON-NLS-1$ //$NON-NLS-2$
field = new TextField();
+ field.setChoice(type);
}
- field.setChoice(type);
return field;
}
Deleted: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/MapField.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/MapField.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/MapField.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -1,331 +0,0 @@
-/**
- * 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: 2005
- * The copyright to this program is held by it's authors.
- *
- * ID: $Id$
- */
-package org.crosswire.common.config.swing;
-
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-import java.awt.Font;
-import java.util.Hashtable;
-import java.util.Map;
-
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JComponent;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTable;
-import javax.swing.JTextField;
-import javax.swing.border.Border;
-
-import org.crosswire.common.config.Choice;
-import org.crosswire.common.swing.ActionFactory;
-import org.crosswire.common.swing.ExceptionPane;
-import org.crosswire.common.swing.FieldLayout;
-import org.crosswire.common.swing.MapTableModel;
-import org.crosswire.common.util.Convert;
-
-/**
- * A MapField allows editing of a Map in a JTable.
- * It allows the user to specify additional classes that extend the
- * functionality of the program.
- *
- * @see gnu.lgpl.License for license details.
- * The copyright to this program is held by it's authors.
- * @author Joe Walker [joe at eireneh dot com]
- */
-public class MapField extends JPanel implements Field
-{
- /**
- * Create a PropertyHashtableField for editing Hashtables.
- */
- public MapField()
- {
- tableModel = new NamedMapTableModel();
- table = new JTable(tableModel);
-
- actions = new ActionFactory(MapField.class, this);
-
- JPanel buttons = new JPanel(new FlowLayout());
-
- table.setFont(new Font("Monospaced", Font.PLAIN, 12)); //$NON-NLS-1$
- table.setPreferredScrollableViewportSize(new Dimension(30, 100));
- table.setColumnSelectionAllowed(false);
-
- JScrollPane scroll = new JScrollPane();
- scroll.setViewportView(table);
-
- buttons.add(new JButton(actions.getAction(ADD)));
- buttons.add(new JButton(actions.getAction(REMOVE)));
- buttons.add(new JButton(actions.getAction(UPDATE)));
-
- Border title = BorderFactory.createTitledBorder(Msg.COMPONENT_EDITOR.toString());
- Border pad = BorderFactory.createEmptyBorder(5, 5, 5, 5);
- setBorder(BorderFactory.createCompoundBorder(title, pad));
-
- setLayout(new BorderLayout());
- add(scroll, BorderLayout.CENTER);
- add(buttons, BorderLayout.PAGE_END);
- }
-
- /* (non-Javadoc)
- * @see org.crosswire.common.config.swing.Field#setChoice(org.crosswire.common.config.Choice)
- */
- public void setChoice(Choice param)
- {
- //superclass = ((MapChoice) param).getSuperClass();
- }
-
- /* (non-Javadoc)
- * @see org.crosswire.common.config.swing.Field#getValue()
- */
- public String getValue()
- {
- return tableModel.getValue();
- }
-
- /* (non-Javadoc)
- * @see org.crosswire.common.config.swing.Field#setValue(java.lang.String)
- */
- public void setValue(String value)
- {
- setMap(Convert.string2Hashtable(value, superclass));
- }
-
- /**
- * Set the current value using a Map
- * @param value The new text
- */
- public void setMap(Map value)
- {
- tableModel.setMap(value);
- table.setModel(tableModel);
- table.getColumnModel().getColumn(0).setWidth(15);
- }
-
- /* (non-Javadoc)
- * @see org.crosswire.common.config.swing.Field#getComponent()
- */
- public JComponent getComponent()
- {
- return this;
- }
-
- /**
- * Pop up a dialog to allow editing of a new value
- */
- public void doAddEntry()
- {
- InputPane input = new InputPane();
-
- if (JOptionPane.showConfirmDialog(this, input, Msg.NEW_CLASS.toString(), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
- {
- String newClass = input.classField.getText();
- String newName = input.nameField.getText();
-
- if (isValid(newClass))
- {
- tableModel.add(newName, newClass);
- }
- }
- }
-
- /**
- * Pop up a dialog to allow editing of a current value
- */
- public void doUpdateEntry()
- {
- InputPane input = new InputPane();
- input.nameField.setText(currentKey());
- input.classField.setText(currentValue());
-
- if (JOptionPane.showConfirmDialog(this, input, Msg.EDIT_CLASS.toString(), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
- {
- String newClass = input.classField.getText();
- String newName = input.nameField.getText();
-
- if (isValid(newClass))
- {
- tableModel.update(currentKey(), newName, newClass);
- }
- }
- }
-
- /**
- * Delete the current value in the Map
- */
- public void doRemoveEntry()
- {
- tableModel.remove(currentKey());
- }
-
- /**
- * Create an instance of a class for the Map
- * @param name The name of the class to create
- * @return The instansiated object or null if the name is not valid
- */
- public boolean isValid(String name)
- {
- try
- {
- Class clazz = Class.forName(name);
-
- if (!superclass.isAssignableFrom(clazz))
- {
- throw new ClassCastException(Msg.BAD_SUPERCLASS.toString(new Object[] { name, superclass }));
- }
-
- return true;
- }
- catch (ClassNotFoundException ex)
- {
- JOptionPane.showMessageDialog(this, Msg.CLASS_NOT_FOUND.toString(name));
- }
- catch (Exception ex)
- {
- ExceptionPane.showExceptionDialog(this, ex);
- }
-
- return false;
- }
-
- /**
- * What is the currently selected key?
- * @return The currently selected key
- */
- private String currentKey()
- {
- return (String) tableModel.getValueAt(table.getSelectedRow(), 0);
- }
-
- /**
- * What is the currently selected value?
- * @return The currently selected value
- */
- private String currentValue()
- {
- return (String) tableModel.getValueAt(table.getSelectedRow(), 1);
- }
-
- /**
- * A MapTableModel with named columns that is not ediatble
- */
- static class NamedMapTableModel extends MapTableModel
- {
- /**
- *
- */
- protected NamedMapTableModel()
- {
- super(new Hashtable());
- }
-
- /* (non-Javadoc)
- * @see javax.swing.table.TableModel#getColumnName(int)
- */
- public String getColumnName(int col)
- {
- return (col == 0) ? Msg.NAME.toString() : Msg.CLASS.toString();
- }
-
- /* (non-Javadoc)
- * @see javax.swing.table.TableModel#isCellEditable(int, int)
- */
- public boolean isCellEditable(int row, int col)
- {
- return false;
- }
-
- /**
- * Serialization ID
- */
- private static final long serialVersionUID = 3257566217748427059L;
- }
-
- /**
- * The panel for a JOptionPane that allows editing a name/class
- * combination.
- */
- static class InputPane extends JPanel
- {
- /**
- *
- */
- protected InputPane()
- {
- super(new FieldLayout(10, 10));
-
- nameField = new JTextField();
- classField = new JTextField(20);
-
- add(new JLabel(Msg.NAME + ":")); //$NON-NLS-1$
- add(nameField);
- add(new JLabel(Msg.CLASS + ":")); //$NON-NLS-1$
- add(classField);
-
- setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
- }
-
- /**
- * To edit a name (Map key)
- */
- protected JTextField nameField;
-
- /**
- * To edit a class (Map value)
- */
- protected JTextField classField;
-
- /**
- * Serialization ID
- */
- private static final long serialVersionUID = 3257849861683296313L;
- }
-
- private static final String ADD = "AddMapEntry"; //$NON-NLS-1$
- private static final String REMOVE = "RemoveMapEntry"; //$NON-NLS-1$
- private static final String UPDATE = "UpdateMapEntry"; //$NON-NLS-1$
-
- private transient ActionFactory actions;
-
- /**
- * The TableModel that points the JTable at the Map
- */
- private NamedMapTableModel tableModel;
-
- /**
- * The Table - displays the Hashtble
- */
- private JTable table;
-
- /**
- * The class that everything must inherit from
- */
- private Class superclass;
-
- /**
- * Serialization ID
- */
- private static final long serialVersionUID = 3257849861683296313L;
-}
Deleted: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/MapField.properties
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/MapField.properties 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/MapField.properties 2006-10-10 23:29:42 UTC (rev 1151)
@@ -1,30 +0,0 @@
-
-AddMapEntry.Enabled=true
-AddMapEntry.Name=Add
-AddMapEntry.ShortDescription=
-AddMapEntry.LongDescription=
-AddMapEntry.SmallIcon=
-AddMapEntry.LargeIcon=
-AddMapEntry.MnemonicKey=A
-AddMapEntry.AcceleratorKey=
-AddMapEntry.AcceleratorKey.Modifiers=
-
-RemoveMapEntry.Enabled=true
-RemoveMapEntry.Name=Remove
-RemoveMapEntry.ShortDescription=
-RemoveMapEntry.LongDescription=
-RemoveMapEntry.SmallIcon=
-RemoveMapEntry.LargeIcon=
-RemoveMapEntry.MnemonicKey=R
-RemoveMapEntry.AcceleratorKey=
-RemoveMapEntry.AcceleratorKey.Modifiers=
-
-UpdateMapEntry.Enabled=false
-UpdateMapEntry.Name=Update
-UpdateMapEntry.ShortDescription=
-UpdateMapEntry.LongDescription=
-UpdateMapEntry.SmallIcon=
-UpdateMapEntry.LargeIcon=
-UpdateMapEntry.MnemonicKey=U
-UpdateMapEntry.AcceleratorKey=
-UpdateMapEntry.AcceleratorKey.Modifiers=
Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/Msg.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/Msg.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/Msg.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -35,12 +35,9 @@
static final Msg EDIT = new Msg("ColorField.Edit"); //$NON-NLS-1$
static final Msg CONFIG_SAVE_FAILED = new Msg("ConfigEditorFactory.ConfigFileFailed"); //$NON-NLS-1$
static final Msg SELECT_FONT = new Msg("FontField.SelectFont"); //$NON-NLS-1$
- static final Msg CLASS = new Msg("MapField.Class"); //$NON-NLS-1$
- static final Msg NAME = new Msg("MapField.Name"); //$NON-NLS-1$
- static final Msg COMPONENT_EDITOR = new Msg("MapField.ComponentEditor"); //$NON-NLS-1$
- static final Msg EDIT_CLASS = new Msg("MapField.EditClass"); //$NON-NLS-1$
- static final Msg CLASS_NOT_FOUND = new Msg("MapField.ClassNotFound."); //$NON-NLS-1$
- static final Msg BAD_SUPERCLASS = new Msg("MapField.BadSuperclass"); //$NON-NLS-1$
+ static final Msg NAME = new Msg("StringArrayField.Name"); //$NON-NLS-1$
+ static final Msg COMPONENT_EDITOR = new Msg("StringArrayField.ComponentEditor"); //$NON-NLS-1$
+ static final Msg EDIT_CLASS = new Msg("StringArrayField.EditClass"); //$NON-NLS-1$
static final Msg ERROR = new Msg("OptionsField.Error"); //$NON-NLS-1$
static final Msg NO_OPTIONS = new Msg("OptionsField.NoOptions"); //$NON-NLS-1$
static final Msg PATH_EDITOR = new Msg("PathField.PathEditor"); //$NON-NLS-1$
Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/Msg.properties
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/Msg.properties 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/Msg.properties 2006-10-10 23:29:42 UTC (rev 1151)
@@ -8,17 +8,14 @@
WizardConfigEditor.Properties=Properties
FontField.SelectFont=Select Font
ColorField.Edit=Edit
-MapField.Class=Class
-MapField.Name=Name
+StringArrayField.Name=Name
OptionsField.Error=Error
PathField.PathEditor=Path Editor
TabbedConfigEditor.Basic=Basic
-MapField.ComponentEditor=Component Editor
+StringArrayField.ComponentEditor=Component Editor
StringArrayField.NewClass=New Class
-MapField.EditClass=Edit Class
+StringArrayField.EditClass=Edit Class
TreeConfigEditor.SelectSubnode=Select a sub-node in the tree for more options
-MapField.ClassNotFound=A class named {0} could not be found.
-MapField.BadSuperclass=The class {0} does not inherit from {1}. Instansiation failed.
OptionsField.NoOptions=No Options Set
WizardConfigEditor.PropertiesPosn=Properties ({0} out of {1})
ConfigEditorFactory.ConfigFileFailed=Could not save config file: {0}
\ No newline at end of file
Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/OptionsField.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/OptionsField.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/OptionsField.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -87,17 +87,17 @@
*/
public void setValue(String value)
{
- for (int i = 0; i < list.length; i++)
+ if (list != null && list.length > 0)
{
- if (value.equals(list[i]))
+ for (int i = 0; i < list.length; i++)
{
- combo.setSelectedItem(list[i]);
- return;
+ if (value.equals(list[i]))
+ {
+ combo.setSelectedItem(list[i]);
+ return;
+ }
}
- }
- if (list != null && list.length > 0)
- {
combo.setSelectedItem(list[0]);
}
Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/WizardConfigEditor.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/WizardConfigEditor.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/WizardConfigEditor.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -48,7 +48,6 @@
import org.crosswire.common.swing.EdgeBorder;
import org.crosswire.common.swing.FormPane;
import org.crosswire.common.util.Logger;
-import org.crosswire.common.util.Reporter;
/**
* A mutable view of Fields setting array.
@@ -67,12 +66,10 @@
public class WizardConfigEditor extends AbstractConfigEditor
{
/**
- * <br />Danger - this method is not called by the TreeConfigEditor
- * constructor, it is called by the AbstractConfigEditor constructor so
- * any field initializers will be called AFTER THIS METHOD EXECUTES
- * so don't use field initializers.
+ * Default constructor
+ *
*/
- protected void initializeGUI()
+ public WizardConfigEditor()
{
actions = new ActionFactory(WizardConfigEditor.class, this);
@@ -80,29 +77,6 @@
layout = new CardLayout();
deck = new JPanel(layout);
- // We need to Enumerate thru the Model names not the Path names in the
- // deck because the deck is a Hashtable that re-orders them.
- Iterator it = config.getNames();
- while (it.hasNext())
- {
- String key = (String) it.next();
-
- int last_dot = key.lastIndexOf('.');
- String path = key.substring(0, last_dot);
-
- FormPane card = (FormPane) decks.get(path);
- if (card.getParent() == null)
- {
- JScrollPane scroll = new JScrollPane(card);
- scroll.setBorder(BorderFactory.createEmptyBorder());
- deck.add(path, scroll);
- wcards++;
-
- // The name for the title bar
- names.add(path.replace('.', ' '));
- }
- }
-
title = new JLabel(Msg.PROPERTIES.toString(), SwingConstants.LEFT);
title.setIcon(TASK_ICON_LARGE);
title.setFont(new Font(getFont().getName(), Font.PLAIN, 16));
@@ -111,7 +85,6 @@
title.setBackground(Color.gray);
title.setForeground(Color.white);
title.setOpaque(true);
- title.setText(names.get(1) + Msg.PROPERTIES_POSN.toString(new Object[] { new Integer(1), new Integer(wcards) }));
deck.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
@@ -132,6 +105,41 @@
add(panel, BorderLayout.CENTER);
add(getButtonPane(), BorderLayout.PAGE_END);
+ }
+
+ /**
+ * <br />Danger - this method is not called by the TreeConfigEditor
+ * constructor, it is called by the AbstractConfigEditor constructor so
+ * any field initializers will be called AFTER THIS METHOD EXECUTES
+ * so don't use field initializers.
+ */
+ protected void initializeGUI()
+ {
+ // We need to Enumerate thru the Model names not the Path names in the
+ // deck because the deck is a Hashtable that re-orders them.
+ Iterator it = config.getNames();
+ while (it.hasNext())
+ {
+ String key = (String) it.next();
+
+ int last_dot = key.lastIndexOf('.');
+ String path = key.substring(0, last_dot);
+
+ FormPane card = (FormPane) decks.get(path);
+ if (card.getParent() == null)
+ {
+ JScrollPane scroll = new JScrollPane(card);
+ scroll.setBorder(BorderFactory.createEmptyBorder());
+ deck.add(path, scroll);
+ wcards++;
+
+ // The name for the title bar
+ names.add(path.replace('.', ' '));
+ }
+ }
+
+ title.setText(names.get(1) + Msg.PROPERTIES_POSN.toString(new Object[] { new Integer(1), new Integer(wcards) }));
+
SwingUtilities.updateComponentTreeUI(this);
}
@@ -195,16 +203,9 @@
public void doWizardFinish(ActionEvent ev)
{
- try
- {
- screenToLocal();
- al.actionPerformed(ev);
- hideDialog();
- }
- catch (Exception ex)
- {
- Reporter.informUser(this, ex);
- }
+ screenToLocal();
+ al.actionPerformed(ev);
+ hideDialog();
}
/**
Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/ActionFactory.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/ActionFactory.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/ActionFactory.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -25,6 +25,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.HashMap;
@@ -86,6 +87,7 @@
// Instead of cascading if/then/else
// use reflecton to do a direct lookup and call
String methodName = METHOD_PREFIX + action;
+ Exception ex = null;
try
{
try
@@ -93,14 +95,31 @@
Method doMethod = bean.getClass().getDeclaredMethod(methodName, new Class[] { ActionEvent.class });
doMethod.invoke(bean, new Object[] { ev });
}
- catch (NoSuchMethodException ex)
+ catch (NoSuchMethodException e)
{
Method doMethod = bean.getClass().getDeclaredMethod(methodName, new Class[0]);
doMethod.invoke(bean, new Object[0]);
}
}
- catch (Exception ex)
+ catch (NoSuchMethodException e)
{
+ ex = e;
+ }
+ catch (IllegalArgumentException e)
+ {
+ ex = e;
+ }
+ catch (IllegalAccessException e)
+ {
+ ex = e;
+ }
+ catch (InvocationTargetException e)
+ {
+ ex = e;
+ }
+
+ if (ex != null)
+ {
log.error("Could not execute method " + bean.getClass().getName() + "." + methodName + "()", ex); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
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 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -251,7 +251,7 @@
*/
public static File[] getSourcePath()
{
- return sources;
+ return (File[]) sources.clone();
}
/**
@@ -445,9 +445,10 @@
// Find a file
name = File.separator + orig.replace('.', File.separatorChar) + FileUtil.EXTENSION_JAVA;
- for (int i = 0; i < sources.length; i++)
+ File [] srcs = ExceptionPane.getSourcePath();
+ for (int i = 0; i < srcs.length; i++)
{
- File file = new File(sources[i], name);
+ File file = new File(srcs[i], name);
if (file.isFile() && file.canRead())
{
// Found the file, load it into the window
@@ -483,7 +484,7 @@
}
}
}
- catch (Exception ex)
+ catch (IOException ex)
{
data.append(ex.getMessage());
}
@@ -514,9 +515,9 @@
// If we can't find a matching file
String error = Msg.SOURCE_NOT_FOUND.toString(new Object[] { st.getClassName(level), errorLine });
- for (int i = 0; i < sources.length; i++)
+ for (int i = 0; i < srcs.length; i++)
{
- error += Msg.SOURCE_ATTEMPT.toString(new Object[] { sources[i].getAbsolutePath() + name });
+ error += Msg.SOURCE_ATTEMPT.toString(new Object[] { srcs[i].getAbsolutePath() + name });
}
mytext.setText(error);
@@ -626,6 +627,7 @@
private ReporterEvent event;
}
+
/**
* The exception we are displaying
*/
@@ -643,7 +645,7 @@
/**
* The directories searched for source
*/
- protected static File[] sources = new File[0];
+ private static File[] sources = new File[0];
/**
* The listener that pops up the ExceptionPanes
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 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -289,7 +289,7 @@
// One of the dimensions may have changed via setSize,
// and the other may be waiting to change here
- if (honoredState != 0)
+ if (honoredState != 0 && win instanceof Frame)
{
Frame frame = (Frame) win;
// Make sure to preserve existing states
Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/AbstractViewLayout.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/AbstractViewLayout.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/AbstractViewLayout.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -23,7 +23,6 @@
import java.awt.BorderLayout;
import java.awt.Component;
-import java.awt.GridBagConstraints;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -261,7 +260,7 @@
*/
protected Object getConstraint()
{
- return gbc;
+ return null;
}
/**
@@ -330,9 +329,4 @@
*/
private JPanel panel;
- /**
- * A shared, reusable constraint that makes its contents
- * grow to fill the area.
- */
- private GridBagConstraints gbc;
}
Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/MDIViewLayout.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/MDIViewLayout.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/MDIViewLayout.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -84,28 +84,30 @@
*/
public void removeView(Component view)
{
- JInternalFrame iframe = (JInternalFrame) SwingUtilities.getAncestorOfClass(JInternalFrame.class, view);
- if (getViewCount() > 1)
+ Component comp = SwingUtilities.getAncestorOfClass(JInternalFrame.class, view);
+ if (comp instanceof JInternalFrame)
{
- if (iframe != null)
+ JInternalFrame iframe = (JInternalFrame) comp;
+ if (getViewCount() > 1)
{
// We need to remove our listener
// because calling dispose will call it otherwise.
// We want it to be called only when the 'X' window close button is pressed
removeInternalFrameListener(iframe);
iframe.dispose();
+
+ super.removeView(view);
}
- super.removeView(view);
- }
- else
- {
- if (view instanceof Clearable)
+ else
{
- ((Clearable) view).clear();
+ if (view instanceof Clearable)
+ {
+ ((Clearable) view).clear();
+ }
+ // Some one may have clicked on the close button,
+ // which made the view hidden
+ iframe.setVisible(true);
}
- // Some one may have clicked on the close button,
- // which made the view hidden
- iframe.setVisible(true);
}
}
@@ -114,12 +116,14 @@
*/
protected void forceRemoveView(Component component)
{
- JInternalFrame iframe = (JInternalFrame) SwingUtilities.getAncestorOfClass(JInternalFrame.class, component);
- if (iframe != null)
+ Component comp = SwingUtilities.getAncestorOfClass(JInternalFrame.class, component);
+ if (comp instanceof JInternalFrame)
{
+ JInternalFrame iframe = (JInternalFrame) comp;
// We need to remove our listener
// because calling dispose will call it otherwise.
- // We want it to be called only when the 'X' window close button is pressed
+ // We want it to be called only when the 'X' window close button is
+ // pressed
removeInternalFrameListener(iframe);
iframe.dispose();
}
@@ -131,9 +135,10 @@
*/
public void updateTitle(Component view)
{
- JInternalFrame iframe = (JInternalFrame) SwingUtilities.getAncestorOfClass(JInternalFrame.class, view);
- if (iframe != null)
+ Component comp = SwingUtilities.getAncestorOfClass(JInternalFrame.class, view);
+ if (comp instanceof JInternalFrame)
{
+ JInternalFrame iframe = (JInternalFrame) comp;
iframe.setTitle(getTitle(view));
}
}
Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/ViewManager.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/ViewManager.java 2006-10-10 23:28:31 UTC (rev 1150)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/ViewManager.java 2006-10-10 23:29:42 UTC (rev 1151)
@@ -68,7 +68,7 @@
panel.add(getViewLayout().getPanel(), getConstraint());
// Get the action definitions from the calling class
- contextActions = new ActionFactory(CallContext.instance().getCallingClass(), this);
+ contextActions = new ActionFactory(CallContext.getCallingClass(), this);
tdiView = new JRadioButtonMenuItem(contextActions.getAction(TAB_MODE));
mdiView = new JRadioButtonMenuItem(contextActions.getAction(WINDOW_MODE));
More information about the jsword-svn
mailing list