com.jmex.bui
Class BStyleSheet

java.lang.Object
  extended by com.jmex.bui.BStyleSheet

public class BStyleSheet
extends Object

Defines a stylesheet which is used to configure the style (font family, font size, foreground and background color, etc.) of components in the BUI library. The BUI stylesheets syntax is a subset of the Cascading Style Sheet sytnax and follows its semantic conventions as well where possible.

A basic stylesheet enumerating most usable values is as follows:

 style_class {
   // foreground and background properties
   color: 0 0 0;
   background: solid #00000088; // note the 50% alpha
   background: image monkey.png XX; // XX = centerx|centery|centerxy|
                                    //      scalex|scaley|scalexy|
                                    //      tilex|tiley|tilexy|
                                    //      framex|framey|framexy
   background: image monkey.png framexy top right bottom left;
   cursor: name;

   // text properties
   font: Helvetica XX 12; // XX = normal|bold|italic|bolditalic
   text-align: XX; // XX = left|center|right
   vertical-align: XX; // XX = top|center|bottom
   text-effect: XX; // XX = none|outline|shadow|glow
   line-spacing: -2; // XX = amount of space to add/remove between lines

   // box properties
   padding: top; // right=top, bottom=top, left=top
   padding: top, right; // bottom=top, left=right
   padding: top, right, bottom, left;
   border: 1 solid #FFCC99;
   border: 1 blank;
   size: 250 100; // overrrides component preferred size

   // explicit inheritance
   parent: other_class; // other_class must be defined *before* this one

   tooltip: other_class; // used to define the style class for the tool_tip
 }
 
Each component is identified by its default stylesheet class, which are derived from the component's Java class name: window, label, textfield, component, popupmenu, etc. The component's stylesheet class can be overridden with a call to BComponent.setStyleClass(java.lang.String).

A component's style is resolved in the following manner:

This resolution process is followed at the time the component is added to the interface hierarchy and the result is used to configure the component. We tradeoff the relative expense of doing the lookup every time the component is rendered (every frame) with the memory expense of storing the style of every component in memory.


Nested Class Summary
protected static class BStyleSheet.BackgroundProperty
           
protected static class BStyleSheet.CursorProperty
           
static class BStyleSheet.DefaultResourceProvider
          A default implementation of the stylesheet resource provider.
protected static class BStyleSheet.FontProperty
           
protected static class BStyleSheet.IconProperty
           
protected static class BStyleSheet.Property
           
static interface BStyleSheet.ResourceProvider
          An interface used by the stylesheet to obtain font and image resources.
protected static class BStyleSheet.Rule
           
 
Field Summary
protected static HashMap<String,Integer> _ibconsts
           
protected  BStyleSheet.ResourceProvider _rsrcprov
           
protected  HashMap<String,BStyleSheet.Rule> _rules
           
protected static HashMap<String,Integer> _taconsts
           
protected static HashMap<String,Integer> _teconsts
           
protected static HashMap<String,Integer> _vaconsts
           
static String BOLD
          A font style constant.
static String BOLD_ITALIC
          A font style constant.
static String ITALIC
          A font style constant.
static String PLAIN
          A font style constant.
 
Constructor Summary
BStyleSheet(Reader reader, BStyleSheet.ResourceProvider rsrcprov)
          Creates a stylesheet from the specified textual source.
 
Method Summary
protected  Object createProperty(String name, ArrayList args)
           
protected  void fail(StreamTokenizer tok, String expected)
           
protected  Object findProperty(BComponent component, String pseudoClass, String property, boolean climb)
           
 BBackground getBackground(BComponent component, String pseudoClass)
           
 BBorder getBorder(BComponent component, String pseudoClass)
           
 ColorRGBA getColor(BComponent component, String pseudoClass)
           
 BCursor getCursor(BComponent component, String pseudoClass)
           
 ColorRGBA getEffectColor(BComponent component, String pseudoClass)
           
 int getEffectSize(BComponent component, String pseudoClass)
           
 BIcon getIcon(BComponent component, String pseudoClass)
           
 Insets getInsets(BComponent component, String pseudoClass)
           
 BKeyMap getKeyMap(BComponent component, String pseudoClass)
           
 int getLineSpacing(BComponent component, String pseudoClass)
           
protected  Object getProperty(String fqClass, String property)
           
 Dimension getSize(BComponent component, String pseudoClass)
           
 int getTextAlignment(BComponent component, String pseudoClass)
           
 int getTextEffect(BComponent component, String pseudoClass)
           
 BTextFactory getTextFactory(BComponent component, String pseudoClass)
           
 String getTooltipStyle(BComponent component, String pseudoClass)
           
 int getVerticalAlignment(BComponent component, String pseudoClass)
           
static void main(String[] args)
           
protected static String makeFQClass(String styleClass, String pseudoClass)
           
protected  void parse(StreamTokenizer tok)
           
protected  ColorRGBA parseColor(String hex)
           
protected  int parseInt(Object arg)
           
protected  boolean parseProperty(StreamTokenizer tok, BStyleSheet.Rule rule)
           
protected  BStyleSheet.Rule startRule(StreamTokenizer tok)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLAIN

public static final String PLAIN
A font style constant.

See Also:
Constant Field Values

BOLD

public static final String BOLD
A font style constant.

See Also:
Constant Field Values

ITALIC

public static final String ITALIC
A font style constant.

See Also:
Constant Field Values

BOLD_ITALIC

public static final String BOLD_ITALIC
A font style constant.

See Also:
Constant Field Values

_rsrcprov

protected BStyleSheet.ResourceProvider _rsrcprov

_rules

protected HashMap<String,BStyleSheet.Rule> _rules

_taconsts

protected static HashMap<String,Integer> _taconsts

_vaconsts

protected static HashMap<String,Integer> _vaconsts

_teconsts

protected static HashMap<String,Integer> _teconsts

_ibconsts

protected static HashMap<String,Integer> _ibconsts
Constructor Detail

BStyleSheet

public BStyleSheet(Reader reader,
                   BStyleSheet.ResourceProvider rsrcprov)
            throws IOException
Creates a stylesheet from the specified textual source.

Throws:
IOException
Method Detail

main

public static void main(String[] args)

getColor

public ColorRGBA getColor(BComponent component,
                          String pseudoClass)

getBackground

public BBackground getBackground(BComponent component,
                                 String pseudoClass)

getIcon

public BIcon getIcon(BComponent component,
                     String pseudoClass)

getCursor

public BCursor getCursor(BComponent component,
                         String pseudoClass)

getTextFactory

public BTextFactory getTextFactory(BComponent component,
                                   String pseudoClass)

getTextAlignment

public int getTextAlignment(BComponent component,
                            String pseudoClass)

getVerticalAlignment

public int getVerticalAlignment(BComponent component,
                                String pseudoClass)

getTextEffect

public int getTextEffect(BComponent component,
                         String pseudoClass)

getLineSpacing

public int getLineSpacing(BComponent component,
                          String pseudoClass)

getEffectSize

public int getEffectSize(BComponent component,
                         String pseudoClass)

getEffectColor

public ColorRGBA getEffectColor(BComponent component,
                                String pseudoClass)

getInsets

public Insets getInsets(BComponent component,
                        String pseudoClass)

getBorder

public BBorder getBorder(BComponent component,
                         String pseudoClass)

getSize

public Dimension getSize(BComponent component,
                         String pseudoClass)

getTooltipStyle

public String getTooltipStyle(BComponent component,
                              String pseudoClass)

getKeyMap

public BKeyMap getKeyMap(BComponent component,
                         String pseudoClass)

findProperty

protected Object findProperty(BComponent component,
                              String pseudoClass,
                              String property,
                              boolean climb)

getProperty

protected Object getProperty(String fqClass,
                             String property)

parse

protected void parse(StreamTokenizer tok)
              throws IOException
Throws:
IOException

startRule

protected BStyleSheet.Rule startRule(StreamTokenizer tok)
                              throws IOException
Throws:
IOException

parseProperty

protected boolean parseProperty(StreamTokenizer tok,
                                BStyleSheet.Rule rule)
                         throws IOException
Throws:
IOException

createProperty

protected Object createProperty(String name,
                                ArrayList args)

fail

protected void fail(StreamTokenizer tok,
                    String expected)
             throws IOException
Throws:
IOException

parseColor

protected ColorRGBA parseColor(String hex)

parseInt

protected int parseInt(Object arg)

makeFQClass

protected static String makeFQClass(String styleClass,
                                    String pseudoClass)


Copyright © 2008 Michael Bayne. All Rights Reserved.