Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ttools: refactor captioner configuration
The logic for selecting a font from configuration options is now broken out into a new class CaptionerKeySet rather than using opaque logic within the StyleKeys class. This means it can be reused, which in turn means the LabelPlotter class is able to use a different instance of the relevant config keys than that used for the axis labelling. So now the logic in the topcat GUI classes lets you choose a different font for point labelling than for axis labelling.
- Loading branch information
Showing
16 changed files
with
207 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
ttools/src/main/uk/ac/starlink/ttools/plot2/config/CaptionerKeySet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package uk.ac.starlink.ttools.plot2.config; | ||
|
||
import java.awt.Font; | ||
import org.scilab.forge.jlatexmath.TeXFormula; | ||
import uk.ac.starlink.ttools.plot2.BasicCaptioner; | ||
import uk.ac.starlink.ttools.plot2.Captioner; | ||
import uk.ac.starlink.ttools.plot2.LatexCaptioner; | ||
|
||
/** | ||
* ConfigKeySet for specifying a captioner. | ||
* Font size, type, weight are configurable as well as plain/latex | ||
* rendering. | ||
* | ||
* @author Mark Taylor | ||
* @since 6 Mar 2014 | ||
*/ | ||
public class CaptionerKeySet implements KeySet<Captioner> { | ||
|
||
private final ConfigKey<TextSyntax> textSyntaxKey_; | ||
private final ConfigKey<Integer> fontSizeKey_; | ||
private final ConfigKey<FontType> fontTypeKey_; | ||
private final ConfigKey<FontWeight> fontWeightKey_; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public CaptionerKeySet() { | ||
textSyntaxKey_ = | ||
new OptionConfigKey<TextSyntax>( new ConfigMeta( "syntax", | ||
"Text Syntax" ), | ||
TextSyntax.class, | ||
TextSyntax.values(), | ||
TextSyntax.values()[ 0 ], true ); | ||
fontSizeKey_ = | ||
IntegerConfigKey.createSpinnerKey( new ConfigMeta( "fontsize", | ||
"Font Size" ), | ||
12, 2, 64 ); | ||
fontTypeKey_ = | ||
new OptionConfigKey<FontType>( new ConfigMeta( "fontstyle", | ||
"Font Style" ), | ||
FontType.class, FontType.values() ); | ||
fontWeightKey_ = | ||
new OptionConfigKey<FontWeight>( new ConfigMeta( "fontweight", | ||
"Font Weight" ), | ||
FontWeight.class, | ||
FontWeight.values() ); | ||
} | ||
|
||
public ConfigKey[] getKeys() { | ||
return new ConfigKey[] { | ||
textSyntaxKey_, | ||
fontSizeKey_, | ||
fontTypeKey_, | ||
fontWeightKey_, | ||
}; | ||
} | ||
|
||
public Captioner createValue( ConfigMap config ) { | ||
TextSyntax syntax = config.get( textSyntaxKey_ ); | ||
int size = config.get( fontSizeKey_ ); | ||
FontType type = config.get( fontTypeKey_ ); | ||
FontWeight weight = config.get( fontWeightKey_ ); | ||
return syntax.createCaptioner( type, weight, size ); | ||
} | ||
|
||
/** | ||
* Font type enum for use with captioner configuration. | ||
*/ | ||
private enum FontType { | ||
SANSSERIF( "Standard", "Dialog", TeXFormula.SANSSERIF ), | ||
SERIF( "Serif", "Serif", TeXFormula.ROMAN ), | ||
MONO( "Mono", "Monospaced", TeXFormula.TYPEWRITER ); | ||
|
||
private final String name_; | ||
private final String awtName_; | ||
private final int texType_; | ||
|
||
FontType( String name, String awtName, int texType ) { | ||
name_ = name; | ||
awtName_ = awtName; | ||
texType_ = texType; | ||
} | ||
|
||
public String toString() { | ||
return name_; | ||
} | ||
} | ||
|
||
/** | ||
* Font weight enum for use with captioner configuration. | ||
*/ | ||
private enum FontWeight { | ||
PLAIN( "Plain", Font.PLAIN, 0 ), | ||
BOLD( "Bold", Font.BOLD, TeXFormula.BOLD ), | ||
ITALIC( "Italic", Font.ITALIC, TeXFormula.ITALIC ), | ||
BOLDITALIC( "Bold Italic", Font.BOLD | Font.ITALIC, | ||
TeXFormula.BOLD | TeXFormula.ITALIC ); | ||
|
||
private final String name_; | ||
private final int awtWeight_; | ||
private final int texWeight_; | ||
|
||
FontWeight( String name, int awtWeight, int texWeight ) { | ||
name_ = name; | ||
awtWeight_ = awtWeight; | ||
texWeight_ = texWeight; | ||
} | ||
|
||
public String toString() { | ||
return name_; | ||
} | ||
} | ||
|
||
/** | ||
* Text interpretation language enum for use with captioner configuration. | ||
*/ | ||
private enum TextSyntax { | ||
PLAIN( "Plain" ) { | ||
public Captioner createCaptioner( FontType type, FontWeight weight, | ||
int size ) { | ||
return new BasicCaptioner( new Font( type.awtName_, | ||
weight.awtWeight_, | ||
size ) ); | ||
} | ||
}, | ||
LATEX( "LaTeX" ) { | ||
public Captioner createCaptioner( FontType type, FontWeight weight, | ||
int size ) { | ||
return new LatexCaptioner( size, | ||
type.texType_ | weight.texWeight_ ); | ||
} | ||
}; | ||
private final String name_; | ||
TextSyntax( String name ) { | ||
name_ = name; | ||
} | ||
public abstract Captioner createCaptioner( FontType type, | ||
FontWeight weight, | ||
int size ); | ||
public String toString() { | ||
return name_; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
ttools/src/main/uk/ac/starlink/ttools/plot2/config/KeySet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package uk.ac.starlink.ttools.plot2.config; | ||
|
||
/** | ||
* Aggregates a set of config keys which are used together to specify | ||
* an object. | ||
* | ||
* @author Mark Taylor | ||
* @since 6 Mar 2014 | ||
*/ | ||
public interface KeySet<T> { | ||
|
||
/** | ||
* The config keys used to specify an object. | ||
* | ||
* @return fixed list of config keys | ||
*/ | ||
ConfigKey[] getKeys(); | ||
|
||
/** | ||
* Creates a typed value based on the values in a map corresponding | ||
* to this object's keys. | ||
* | ||
* @param map map for which the values corresponding to | ||
* <code>getKeys</code> will be examined | ||
* @return specified typed value | ||
*/ | ||
T createValue( ConfigMap map ); | ||
} |
Oops, something went wrong.