### Eclipse Workspace Patch 1.0 #P common-swing Index: src/main/java/org/crosswire/common/swing/FontChooser.java =================================================================== --- src/main/java/org/crosswire/common/swing/FontChooser.java (revision 1949) +++ src/main/java/org/crosswire/common/swing/FontChooser.java (working copy) @@ -112,7 +112,11 @@ ? new JDialog((JFrame) root, title, true) : new JDialog((JDialog) root, title, true); - fontc.name.setSelectedItem(initial != null ? initial : DEFAULT_FONT.getFont()); + Font font = (initial != null) ? initial : DEFAULT_FONT.getFont(); + fontc.name.setSelectedItem(font); + fontc.bold.setSelected(font.isBold()); + fontc.italic.setSelected(font.isItalic()); + fontc.size.setSelectedItem(new Integer(font.getSize())); final ActionFactory actions = new ActionFactory(FontChooser.class, fontc); @@ -332,6 +336,30 @@ */ private static final long serialVersionUID = 3256726195025358905L; } + + /** + * An extension of JComboBox that selects a font in the combo based on it's + * name, not object equivalence. + */ + static class FontNameComboBox extends JComboBox + { + public void setSelectedItem(Object anObject) + { + if ((selectedItemReminder == null || !selectedItemReminder.equals(anObject)) && (anObject instanceof Font)) + { + String fontName = ((Font) anObject).getName(); + for (int i = 0; i < dataModel.getSize(); i++ ) + { + Object element = dataModel.getElementAt(i); + if (element instanceof Font && (((Font) element).getName().equals(fontName))) + { + super.setSelectedItem(element); + return; + } + } + } + } + } public static final String PROPERTY_STYLE = "style"; // //$NON-NLS-1$ @@ -368,7 +396,7 @@ /** * The choice of font name */ - protected JComboBox name = new JComboBox(); + protected JComboBox name = new FontNameComboBox(); /** * Bold font?