Packagecom.soma.model
Classpublic class StyleManager

Author: Romuald Quantin - www.soundstep.com

Information:
Blog page - SomaUI
How does it work - Soma Protest
Project Host - Google Code
Documentation - Soma ASDOC
Class version: 2.0
Actionscript version: 3.0

Copyright:

The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied.
See the License for the specific language governing rights and
limitations under the License.

The Original Code is Soma.
The Initial Developer of the Original Code is Romuald Quantin.
Initial Developer are Copyright (C) 2008-2009 Soundstep. All Rights Reserved.

Usage:
The StyleManager handles external stylesheets (css) and gives you an easy access to the styles. The global stylesheet manager is accessible using:

Soma.getInstance().styles
Before starting Soma, you can register a "global stylesheet" to the framework using (the css will be loaded during the initialization process):
Soma.getInstance().registerGloBalStyleSheet("styles.css");
Other StyleSheets can easily be loaded using:
Soma.getInstance().addEventListener(StyleSheetEvent.LOADED, eventHandler);
Soma.getInstance().loadStyleSheet("myStyleSheetID", "css/custom.css");
   

See also

Soma
StyleSheetEvent
SomaText


Public Methods
 MethodDefined by
  
Creates an StyleManager instance
StyleManager
  
addStyleSheet(id:String, stylesheet:StyleSheet):void
Add a stylesheet to the StyleManager instance and register it with an id.
StyleManager
  
cloneStyleSheet(target:StyleSheet):StyleSheet
StyleManager
  
getColor(style:String, stylesheet:StyleSheet = null):uint
Get a color from a stylesheet (the global stylesheet will be used if you don't pass any).
StyleManager
  
getGlobalStyle(style:String):Object
Get a style from the global stylesheet.
StyleManager
  
getGlobalStyleSheet():StyleSheet
Get the global stylesheet instance registered (used by default with SomaText instances when a stylesheet is not specified).
StyleManager
  
getStyle(style:String, stylesheet:StyleSheet = null):Object
Get a style from a stylesheet (the global stylesheet will be used if you don't pass any).
StyleManager
  
getStyleSheet(stylesheetID:String):StyleSheet
Get a stylesheet using its id.
StyleManager
  
getStyleSheetID(stylesheet:StyleSheet):String
Get the id of a stylesheet.
StyleManager
  
getTextFormat(style:String, stylesheet:StyleSheet = null):TextFormat
Get a color from a stylesheet (the global stylesheet will be used if you don't pass any).
StyleManager
  
loadStyleSheet(id:String, url:String):void
Load a stylesheet and register it with an id.
StyleManager
  
removeStyleSheet(stylesheetID:String):void
Remove a styleheet from the StyleManager instance using its id.
StyleManager
  
setGlobalStyleSheet(stylesheet:StyleSheet):void
Set a stylesheet to be the "global stylesheet" (used by default with SomaText instances when a stylesheet is not specified).
StyleManager
Public Constants
 ConstantDefined by
  GLOBAL_STYLESHEET_ID : String = "global"
[static] id String of the global stylesheet.
StyleManager
Constructor detail
StyleManager()constructor
public function StyleManager()

Creates an StyleManager instance

Method detail
addStyleSheet()method
public function addStyleSheet(id:String, stylesheet:StyleSheet):void

Add a stylesheet to the StyleManager instance and register it with an id.

Parameters
id:String — id of the stylesheet.
 
stylesheet:StyleSheet — A StyleSheet.
cloneStyleSheet()method 
public function cloneStyleSheet(target:StyleSheet):StyleSheetParameters
target:StyleSheet

Returns
StyleSheet
getColor()method 
public function getColor(style:String, stylesheet:StyleSheet = null):uint

Get a color from a stylesheet (the global stylesheet will be used if you don't pass any).

var color:uint = Soma.getInstance().styles.getColor(".myStyle");
trace(color.toString(16));
   

Parameters
style:String — Name of the style.
 
stylesheet:StyleSheet (default = null) — StyleSheet instance.

Returns
uint — A uint value (color value).
getGlobalStyle()method 
public function getGlobalStyle(style:String):Object

Get a style from the global stylesheet.

var obj:Object = Soma.getInstance().styles.getGlobalStyle(".myStyle");
for (var i:String in obj) {
 trace(i, obj[i])
}
   

Parameters
style:String — Name of the style.

Returns
Object — An object.
getGlobalStyleSheet()method 
public function getGlobalStyleSheet():StyleSheet

Get the global stylesheet instance registered (used by default with SomaText instances when a stylesheet is not specified).

Returns
StyleSheet — A StyleSheet instance.
getStyle()method 
public function getStyle(style:String, stylesheet:StyleSheet = null):Object

Get a style from a stylesheet (the global stylesheet will be used if you don't pass any).

var obj:Object = Soma.getInstance().styles.getStyle(".myStyle", myStyleSheet);
for (var i:String in obj) {
 trace(i, obj[i])
}
   

Parameters
style:String — Name of the style.
 
stylesheet:StyleSheet (default = null)

Returns
Object — An object.
getStyleSheet()method 
public function getStyleSheet(stylesheetID:String):StyleSheet

Get a stylesheet using its id.

Parameters
stylesheetID:String — id of the stylesheet.

Returns
StyleSheet — A StyleSheet instance.
getStyleSheetID()method 
public function getStyleSheetID(stylesheet:StyleSheet):String

Get the id of a stylesheet.

Parameters
stylesheet:StyleSheet — A StyleSheet instance.

Returns
String — A String.
getTextFormat()method 
public function getTextFormat(style:String, stylesheet:StyleSheet = null):TextFormat

Get a color from a stylesheet (the global stylesheet will be used if you don't pass any).

var tf:TextFormat = Soma.getInstance().styles.getTextFormat(".body");

Parameters
style:String — Name of the style.
 
stylesheet:StyleSheet (default = null) — StyleSheet instance.

Returns
TextFormat — A TextFormat instance.
loadStyleSheet()method 
public function loadStyleSheet(id:String, url:String):void

Load a stylesheet and register it with an id.

Parameters
id:String — id of the stylesheet.
 
url:String — URL of the css file.
removeStyleSheet()method 
public function removeStyleSheet(stylesheetID:String):void

Remove a styleheet from the StyleManager instance using its id.

Parameters
stylesheetID:String — id of the stylesheet.
setGlobalStyleSheet()method 
public function setGlobalStyleSheet(stylesheet:StyleSheet):void

Set a stylesheet to be the "global stylesheet" (used by default with SomaText instances when a stylesheet is not specified).

Parameters
stylesheet:StyleSheet — A StyleSheet instance.
Constant detail
GLOBAL_STYLESHEET_IDconstant
public static const GLOBAL_STYLESHEET_ID:String = "global"

id String of the global stylesheet.