TreePanel tp;
+ /*
+ * The font on opening the dialog (to be restored on Cancel)
+ */
Font oldFont;
boolean oldProteinScale;
JInternalFrame frame;
+ /*
+ * The last font settings selected in the dialog
+ */
+ private Font lastSelected = null;
+
+ private boolean lastSelMono = false;
+
/**
* Creates a new FontChooser object.
*
}
}
- private Font lastSelected = null;
-
- private int lastSelStyle = 0;
-
- private int lastSelSize = 0;
-
- private boolean lastSelMono = false;
-
/**
* DOCUMENT ME!
*/
{
// initialise with original font
lastSelected = oldFont;
- lastSelSize = oldFont.getSize();
- lastSelStyle = oldFont.getStyle();
FontMetrics fm = getGraphics().getFontMetrics(oldFont);
- double mw = fm.getStringBounds("M", getGraphics()).getWidth(), iw = fm
- .getStringBounds("I", getGraphics()).getWidth();
- lastSelMono = mw == iw;
+ double mw = fm.getStringBounds("M", getGraphics()).getWidth();
+ double iw = fm.getStringBounds("I", getGraphics()).getWidth();
+ lastSelMono = (mw == iw); // == on double - flaky?
}
Font newFont = new Font(fontName.getSelectedItem().toString(),
MessageManager.getString("label.font_doesnt_have_letters_defined"),
MessageManager.getString("label.invalid_font"), JOptionPane.WARNING_MESSAGE);
/*
- * Restore previous values - size first to avoid recursive calls to this
- * point!
+ * Restore the changed value - note this will reinvoke this method via the
+ * ActionListener, but now validation should pass
*/
- fontSize.setSelectedItem(lastSelSize);
- fontName.setSelectedItem(lastSelected.getName());
- fontStyle.setSelectedIndex(lastSelStyle);
- monospaced.setSelected(lastSelMono);
+ if (lastSelected.getSize() != (Integer) fontSize.getSelectedItem()) // autoboxing
+ {
+ fontSize.setSelectedItem(lastSelected.getSize());
+ }
+ if (!lastSelected.getName().equals(
+ fontName.getSelectedItem().toString()))
+ {
+ fontName.setSelectedItem(lastSelected.getName());
+ }
+ if (lastSelected.getStyle() != fontStyle.getSelectedIndex())
+ {
+ fontStyle.setSelectedIndex(lastSelected.getStyle());
+ }
+ if (lastSelMono != monospaced.isSelected())
+ {
+ monospaced.setSelected(lastSelMono);
+ }
return;
}
if (tp != null)
}
monospaced.setSelected(mw == iw);
- // remember last selected
+
+ /*
+ * Remember latest valid selection, so it can be restored if followed by an
+ * invalid one
+ */
lastSelected = newFont;
}
{
String[] fonts = java.awt.GraphicsEnvironment
.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
+ final Canvas canvas = new Canvas();
for (int pointSize = 1;; pointSize++)
{
System.out.println(System.lineSeparator()
- + "Fonts with insufficient width at " + pointSize + "pt:");
+ + "Plain fonts with sub-pixel width at " + pointSize + "pt:");
if (pointSize == 1)
{
System.out.println("All except:");
for (String fontname : fonts)
{
Font newFont = new Font(fontname, Font.PLAIN, pointSize);
- FontMetrics fontm = new Canvas().getFontMetrics(newFont);
+ FontMetrics fontm = canvas.getFontMetrics(newFont);
double iw = fontm.getStringBounds("I", null).getWidth();
final boolean tooSmall = iw < 1d;
if (tooSmall)