[jsword-svn] r1583 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic bibledesktop/src/main/java/org/crosswire/bibledesktop/util bibledesktop/src/main/resources/xsl/cswing 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
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Mon Jul 30 10:04:05 MST 2007
Author: dmsmith
Date: 2007-07-30 10:04:04 -0700 (Mon, 30 Jul 2007)
New Revision: 1583
Modified:
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/XSLTProperty.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/util/ConfigurableSwingConverter.java
trunk/bibledesktop/src/main/resources/xsl/cswing/simple.xsl
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/TreeConfigEditor.java
trunk/common-swing/src/main/java/org/crosswire/common/config/swing/WizardConfigEditor.java
trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiConvert.java
trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java
trunk/common/src/main/java/org/crosswire/common/util/EventListenerList.java
Log:
Fixed a config bug which prevented bold/italic display changes from taking immediate effect.
Changed the font spec saved by options to be one readable by Font.decode.
Changed font creation to be by derivation in several places.
Fixed some spellings in documentation.
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/XSLTProperty.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/XSLTProperty.java 2007-07-30 15:37:11 UTC (rev 1582)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/XSLTProperty.java 2007-07-30 17:04:04 UTC (rev 1583)
@@ -110,7 +110,7 @@
* What is the base of the current document.
* Note this needs to be set each time the font changes.
*/
- public static final XSLTProperty FONT = new XSLTProperty("font", "Serif,0,14"); //$NON-NLS-1$ //$NON-NLS-2$
+ public static final XSLTProperty FONT = new XSLTProperty("font", "Serif-PLAIN-14"); //$NON-NLS-1$ //$NON-NLS-2$
/**
* What is the base of the current document.
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java 2007-07-30 15:37:11 UTC (rev 1582)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java 2007-07-30 17:04:04 UTC (rev 1583)
@@ -471,7 +471,7 @@
*/
public Key getKey()
{
- return bdata.getKey();
+ return bdata == null ? null : bdata.getKey();
}
/* (non-Javadoc)
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/util/ConfigurableSwingConverter.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/util/ConfigurableSwingConverter.java 2007-07-30 15:37:11 UTC (rev 1582)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/util/ConfigurableSwingConverter.java 2007-07-30 17:04:04 UTC (rev 1583)
@@ -29,10 +29,10 @@
import javax.xml.transform.TransformerException;
import org.crosswire.bibledesktop.desktop.XSLTProperty;
+import org.crosswire.common.swing.GuiConvert;
import org.crosswire.common.util.FileUtil;
import org.crosswire.common.util.NetUtil;
import org.crosswire.common.util.ResourceUtil;
-import org.crosswire.common.util.StringUtil;
import org.crosswire.common.util.URIFilter;
import org.crosswire.common.xml.Converter;
import org.crosswire.common.xml.SAXEventProvider;
@@ -110,10 +110,7 @@
*/
public static Font toFont()
{
- String[] fontSpec = StringUtil.split(font, ","); //$NON-NLS-1$
- int fontStyle = Integer.parseInt(fontSpec[1]);
- int fontSize = Integer.parseInt(fontSpec[2]);
- return new Font(fontSpec[0], fontStyle, fontSize);
+ return GuiConvert.string2Font(font);
}
/**
@@ -158,7 +155,7 @@
/**
* The font to be used in OSIS->HTML generation
*/
- private static String font = "Serif,0,14"; //$NON-NLS-1$
+ private static String font = "Serif-PLAIN-14"; //$NON-NLS-1$
/**
* The stylesheet we are transforming using
Modified: trunk/bibledesktop/src/main/resources/xsl/cswing/simple.xsl
===================================================================
--- trunk/bibledesktop/src/main/resources/xsl/cswing/simple.xsl 2007-07-30 15:37:11 UTC (rev 1582)
+++ trunk/bibledesktop/src/main/resources/xsl/cswing/simple.xsl 2007-07-30 17:04:04 UTC (rev 1583)
@@ -96,26 +96,43 @@
<!-- The order of display. Hebrew is rtl (right to left) -->
<xsl:param name="direction" select="'ltr'"/>
- <!--
- The font that is passed in is of the form: font or font,style,size
- where style is a bit mask with 1 being bold and 2 being italic.
- This needs to be changed into a style="xxx" specification
+ <!-- The font that is passed in is in one of two forms:
+ FamilyName-STYLE-size, where STYLE is either PLAIN, BOLD, ITALIC or BOLDITALIC
+ or
+ FamilyName,style,size, where STYLE is 0 for PLAIN, 1 for BOLD, 2 for ITALIC or 3 for BOLDITALIC.
+ This needs to be changed into a CSS style specification
-->
<xsl:param name="font" select="Serif"/>
+ <xsl:variable name="fontSeparator">
+ <xsl:choose>
+ <xsl:when test="contains($font, ',')">
+ <xsl:value-of select="','"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="'-'"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
<xsl:variable name="aFont">
<xsl:choose>
- <xsl:when test="substring-before($font, ',') = ''"><xsl:value-of select="$font"/>,0,16</xsl:when>
+ <xsl:when test="substring-before($font, $fontSeparator) = ''"><xsl:value-of select="$font"/>,0,16</xsl:when>
<xsl:otherwise><xsl:value-of select="$font"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
- <xsl:variable name="fontfamily" select='concat("font-family: '", substring-before($aFont, ","), "';")' />
- <xsl:variable name="fontsize" select="concat(' font-size: ', substring-after(substring-after($aFont, ','), ','), 'pt;')" />
- <xsl:variable name="styling" select="substring-before(substring-after($aFont, ','), ',')" />
+ <xsl:variable name="fontfamily" select='concat("font-family: '", substring-before($aFont, $fontSeparator), "', Serif;")' />
+ <xsl:variable name="fontsize" select="concat(' font-size: ', substring-after(substring-after($aFont, $fontSeparator), $fontSeparator), 'pt;')" />
+ <xsl:variable name="styling" select="substring-before(substring-after($aFont, $fontSeparator), $fontSeparator)" />
<xsl:variable name="fontweight">
- <xsl:if test="$styling = '1' or $styling = '3'"><xsl:text> font-weight: bold;</xsl:text></xsl:if>
+ <xsl:choose>
+ <xsl:when test="$styling = '1' or $styling = '3' or contains($styling, 'bold')"> font-weight: bold;</xsl:when>
+ <xsl:otherwise> font-weight: normal;</xsl:otherwise>
+ </xsl:choose>
</xsl:variable>
<xsl:variable name="fontstyle">
- <xsl:if test="$styling = '2' or $styling = '3'"> font-style: italic;</xsl:if>
+ <xsl:choose>
+ <xsl:when test="$styling = '2' or $styling = '3' or contains($styling, 'italic')"> font-style: italic;</xsl:when>
+ <xsl:otherwise> font-style: normal;</xsl:otherwise>
+ </xsl:choose>
</xsl:variable>
<xsl:variable name="fontspec" select="concat($fontfamily, $fontsize, $fontweight, $fontstyle)"/>
Modified: trunk/common/src/main/java/org/crosswire/common/util/EventListenerList.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/EventListenerList.java 2007-07-30 15:37:11 UTC (rev 1582)
+++ trunk/common/src/main/java/org/crosswire/common/util/EventListenerList.java 2007-07-30 17:04:04 UTC (rev 1583)
@@ -38,7 +38,7 @@
*
* <p>If you inculde sw*ng code in non-gui code then you can end up not being
* able to run your code in a headerless environment because X includes Y which
- * inculdes Font which tries to lookup font metrics and then everything dies.
+ * includes Font which tries to lookup font metrics and then everything dies.
* I appreciate the Headerless changes in 1.4, but my rule (from before 1.4)
* was "Don't inculde sw*ng code from non-sw*ng code", and I enforced that by
* making sure all my sw*ng code was in a package with sw*ng in the name and by
Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/TreeConfigEditor.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/TreeConfigEditor.java 2007-07-30 15:37:11 UTC (rev 1582)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/TreeConfigEditor.java 2007-07-30 17:04:04 UTC (rev 1583)
@@ -103,7 +103,7 @@
});
title.setIcon(TASK_ICON_LARGE);
- title.setFont(new Font(getFont().getName(), Font.PLAIN, 16));
+ title.setFont(getFont().deriveFont(Font.PLAIN, 16));
title.setPreferredSize(new Dimension(30, 30));
title.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
title.setBackground(Color.gray);
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 2007-07-30 15:37:11 UTC (rev 1582)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/WizardConfigEditor.java 2007-07-30 17:04:04 UTC (rev 1583)
@@ -85,7 +85,7 @@
title = new JLabel(Msg.PROPERTIES.toString(), SwingConstants.LEADING);
title.setIcon(TASK_ICON_LARGE);
- title.setFont(new Font(getFont().getName(), Font.PLAIN, 16));
+ title.setFont(getFont().deriveFont(Font.PLAIN, 16));
title.setPreferredSize(new Dimension(30, 30));
title.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
title.setBackground(Color.gray);
Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiConvert.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiConvert.java 2007-07-30 15:37:11 UTC (rev 1582)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiConvert.java 2007-07-30 17:04:04 UTC (rev 1583)
@@ -44,7 +44,10 @@
}
/**
- * Convert a String to a Font
+ * Convert a String to a Font. Accepts one of two inputs:
+ * FamilyName-STYLE-size, where STYLE is either PLAIN, BOLD, ITALIC or BOLDITALIC<br/>
+ * or<br/>
+ * FamilyName,style,size, where STYLE is 0 for PLAIN, 1 for BOLD, 2 for ITALIC or 3 for BOLDITALIC.
* @param value the thing to convert
* @return the converted data
*/
@@ -55,18 +58,25 @@
return null;
}
+ // new way
+ if (value.indexOf(',') == -1)
+ {
+ return Font.decode(value);
+ }
+
+ // old way
String[] values = StringUtil.split(value, ","); //$NON-NLS-1$
if (values.length != 3)
{
log.warn("Illegal font name: " + value); //$NON-NLS-1$
return null;
}
-
return new Font(values[0], Integer.parseInt(values[1]), Integer.parseInt(values[2]));
}
/**
- * Convert a Font to a String
+ * Convert a Font to a String. Produces a format that can be read with <code>Font.decode(String)</code>.
+ *
* @param font the thing to convert
* @return the converted data
*/
@@ -77,7 +87,19 @@
return ""; //$NON-NLS-1$
}
- return font.getName() + "," + font.getStyle() + "," + font.getSize(); //$NON-NLS-1$ //$NON-NLS-2$
+ String strStyle = "plain"; //$NON-NLS-1$
+
+ if (font.isBold())
+ {
+ strStyle = font.isItalic() ? "bolditalic" : "bold"; // //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ else if (font.isItalic())
+ {
+ strStyle = "italic"; // //$NON-NLS-1$
+ }
+
+
+ return font.getName() + "-" + strStyle + "-" + font.getSize(); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
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 2007-07-30 15:37:11 UTC (rev 1582)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java 2007-07-30 17:04:04 UTC (rev 1583)
@@ -33,7 +33,6 @@
import org.crosswire.common.swing.plaf.MetalLFCustoms;
import org.crosswire.common.swing.plaf.OtherLFCustoms;
import org.crosswire.common.swing.plaf.WindowsLFCustoms;
-import org.crosswire.common.util.StringUtil;
/**
* LookAndFeelUtil declares the Choices and actions
@@ -109,10 +108,7 @@
*/
public static FontUIResource toFontUIResource()
{
- String[] fontSpec = StringUtil.split(LookAndFeelUtil.font, ","); //$NON-NLS-1$
- int fontStyle = Integer.parseInt(fontSpec[1]);
- int fontSize = Integer.parseInt(fontSpec[2]);
- return new FontUIResource(fontSpec[0], fontStyle, fontSize);
+ return new FontUIResource(GuiConvert.string2Font(LookAndFeelUtil.font));
}
/**
@@ -160,7 +156,7 @@
/**
* The font to be used for the application
*/
- private static String font = "Dialog,0,12"; //$NON-NLS-1$
+ private static String font = "Dialog-PLAIN-12"; //$NON-NLS-1$
/**
* Setup the default PLAF
More information about the jsword-svn
mailing list