|
From: Harry E. <har...@us...> - 2006-09-20 12:19:58
|
Update of /cvsroot/synclast/client/src/com/synclast/ui In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17424/src/com/synclast/ui Modified Files: Button.java Checkbox.java ColoredWidget.java Container.java GridMenu.java Input.java Label.java Menu.java RadioButton.java Style.java SynclastCanvas.java Widget.java Log Message: New version of styles using applyStyleSheet instead of init. This saves a few nonsensical applications of the StyleSheet, and saves looking up the UIContext for every single style application, since the stylesheet is handed to the call instead. Index: Widget.java =================================================================== RCS file: /cvsroot/synclast/client/src/com/synclast/ui/Widget.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Widget.java 18 Sep 2006 11:06:53 -0000 1.24 --- Widget.java 20 Sep 2006 12:19:53 -0000 1.25 *************** *** 27,30 **** --- 27,31 ---- import com.synclast.Event; import com.synclast.Styled; + import com.synclast.StyleSheet; /** *************** *** 73,78 **** */ protected Widget() { ! init(); setBits = 0L; } --- 74,81 ---- */ protected Widget() { ! //set bits to 0 before calling init, so that widgets that set ! //non default values in their init call don't get their values wiped out setBits = 0L; + init(); } *************** *** 99,103 **** properties = new int [getPropertyCount()]; } ! ALIGN.set(this, Graphics.LEFT | Graphics.TOP); } --- 102,107 ---- properties = new int [getPropertyCount()]; } ! //would prefer to not call this here, except that applyStyleSheet causes the default values for styles to get set, and many widgets need them to be set, even before being added to a container, since they use these values for logic in other areas of the app. ! applyStyleSheet(findStyleSheet()); } *************** *** 188,197 **** * via the set() method. */ ! public void applyStyleSheet() {//StyleSheet sheet) { /* if (sheet != null) { sheet.applyTo(this); } else {*/ ! init(); ! setBits = 0L; // } invalidate(); --- 192,202 ---- * via the set() method. */ ! protected void applyStyleSheet(StyleSheet sheet) { ! ALIGN.set(this, Graphics.LEFT | Graphics.TOP, sheet); /* if (sheet != null) { sheet.applyTo(this); } else {*/ ! // init(); ! // setBits = 0L; // } invalidate(); *************** *** 350,357 **** (!classStyleName.equals(aStyleName))) { classStyleName = aStyleName; ! init(); } //just like set, allow this method to be chained return this; } } --- 355,372 ---- (!classStyleName.equals(aStyleName))) { classStyleName = aStyleName; ! applyStyleSheet(findStyleSheet()); } //just like set, allow this method to be chained return this; } + + protected StyleSheet findStyleSheet() { + if(container != null) { + UIContext context = container.getContext(); + if(context != null) { + return context.getStyleSheet(); + } + } + return null; + } } Index: SynclastCanvas.java =================================================================== RCS file: /cvsroot/synclast/client/src/com/synclast/ui/SynclastCanvas.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** SynclastCanvas.java 18 Sep 2006 07:59:05 -0000 1.24 --- SynclastCanvas.java 20 Sep 2006 12:19:53 -0000 1.25 *************** *** 107,111 **** // Apply the old stylesheet to the new container this.container = container; ! container.applyStyleSheet();//styleSheet); } --- 107,111 ---- // Apply the old stylesheet to the new container this.container = container; ! container.applyStyleSheet(styleSheet); } *************** *** 123,127 **** public void setStyleSheet(StyleSheet styleSheet) { this.styleSheet = styleSheet; ! container.applyStyleSheet();//styleSheet); } --- 123,127 ---- public void setStyleSheet(StyleSheet styleSheet) { this.styleSheet = styleSheet; ! container.applyStyleSheet(styleSheet); } Index: RadioButton.java =================================================================== RCS file: /cvsroot/synclast/client/src/com/synclast/ui/RadioButton.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** RadioButton.java 18 Sep 2006 07:59:05 -0000 1.10 --- RadioButton.java 20 Sep 2006 12:19:53 -0000 1.11 *************** *** 21,24 **** --- 21,25 ---- import com.synclast.Event; + import com.synclast.StyleSheet; import javax.microedition.lcdui.Graphics; *************** *** 51,60 **** } ! protected void init() { ! super.init(); ! BACKGROUND_COLOR.set(this, Color.LIGHT_GRAY); ! BORDER_COLOR.set(this, Color.BLACK); ! BORDER_ARC.set(this, 90); ! BORDER_WIDTH.set(this, 1); } --- 52,61 ---- } ! protected void applyStyleSheet(StyleSheet sheet) { ! super.applyStyleSheet(sheet); ! BACKGROUND_COLOR.set(this, Color.LIGHT_GRAY, sheet); ! BORDER_COLOR.set(this, Color.BLACK, sheet); ! BORDER_ARC.set(this, 90, sheet); ! BORDER_WIDTH.set(this, 1, sheet); } Index: Menu.java =================================================================== RCS file: /cvsroot/synclast/client/src/com/synclast/ui/Menu.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Menu.java 18 Sep 2006 07:59:05 -0000 1.20 --- Menu.java 20 Sep 2006 12:19:53 -0000 1.21 *************** *** 27,30 **** --- 27,31 ---- import com.synclast.Event; + import com.synclast.StyleSheet; import com.synclast.SynclastTask; *************** *** 127,145 **** private SynclastTask scrollTask; ! protected void init() { ! super.init(); ! SELECTED_COLOR.set(this, 0); ! ITEM_ALIGN.set(this, Graphics.HCENTER); ! SCROLL_DELAY.set(this, 2000); ! SCROLL_PERIOD.set(this, 50); ! int dFace = DEFAULT_FONT_FACE.get(this, Font.FACE_PROPORTIONAL); ! int dStyle = DEFAULT_FONT_STYLE.get(this, Font.STYLE_PLAIN); ! int dSize = DEFAULT_FONT_SIZE.get(this, Font.SIZE_MEDIUM); setDefault(DEFAULT_FONT, Style.getFontValue(Font.getFont(dFace, dStyle, dSize))); ! int sFace = DEFAULT_FONT_FACE.get(this, Font.FACE_PROPORTIONAL); ! int sStyle = DEFAULT_FONT_STYLE.get(this, Font.STYLE_BOLD); ! int sSize = DEFAULT_FONT_SIZE.get(this, Font.SIZE_MEDIUM); setDefault(SELECTED_FONT, Style.getFontValue(Font.getFont(sFace, sStyle, sSize))); ! INSET_WIDTH.set(this, 2); } --- 128,146 ---- private SynclastTask scrollTask; ! protected void applyStyleSheet(StyleSheet sheet) { ! super.applyStyleSheet(sheet); ! SELECTED_COLOR.set(this, 0, sheet); ! ITEM_ALIGN.set(this, Graphics.HCENTER, sheet); ! SCROLL_DELAY.set(this, 2000, sheet); ! SCROLL_PERIOD.set(this, 50, sheet); ! int dFace = DEFAULT_FONT_FACE.get(this, Font.FACE_PROPORTIONAL, sheet); ! int dStyle = DEFAULT_FONT_STYLE.get(this, Font.STYLE_PLAIN, sheet); ! int dSize = DEFAULT_FONT_SIZE.get(this, Font.SIZE_MEDIUM, sheet); setDefault(DEFAULT_FONT, Style.getFontValue(Font.getFont(dFace, dStyle, dSize))); ! int sFace = DEFAULT_FONT_FACE.get(this, Font.FACE_PROPORTIONAL, sheet); ! int sStyle = DEFAULT_FONT_STYLE.get(this, Font.STYLE_BOLD, sheet); ! int sSize = DEFAULT_FONT_SIZE.get(this, Font.SIZE_MEDIUM, sheet); setDefault(SELECTED_FONT, Style.getFontValue(Font.getFont(sFace, sStyle, sSize))); ! INSET_WIDTH.set(this, 2, sheet); } Index: Button.java =================================================================== RCS file: /cvsroot/synclast/client/src/com/synclast/ui/Button.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Button.java 18 Sep 2006 07:59:05 -0000 1.13 --- Button.java 20 Sep 2006 12:19:52 -0000 1.14 *************** *** 21,24 **** --- 21,25 ---- import com.synclast.Event; + import com.synclast.StyleSheet; import javax.microedition.lcdui.Canvas; *************** *** 50,58 **** } ! protected void init() { ! super.init(); ! BORDER_COLOR.set(this, Color.BLACK); ! BORDER_WIDTH.set(this, 1); ! INSET_WIDTH.set(this, 2); } --- 51,59 ---- } ! protected void applyStyleSheet(StyleSheet sheet) { ! super.applyStyleSheet(sheet); ! BORDER_COLOR.set(this, Color.BLACK, sheet); ! BORDER_WIDTH.set(this, 1, sheet); ! INSET_WIDTH.set(this, 2, sheet); } Index: ColoredWidget.java =================================================================== RCS file: /cvsroot/synclast/client/src/com/synclast/ui/ColoredWidget.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** ColoredWidget.java 18 Sep 2006 07:59:05 -0000 1.21 --- ColoredWidget.java 20 Sep 2006 12:19:53 -0000 1.22 *************** *** 23,26 **** --- 23,27 ---- import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; + import com.synclast.StyleSheet; /** *************** *** 74,86 **** } ! protected void init() { ! super.init(); ! FOREGROUND_COLOR.set(this, 0x000000); ! BACKGROUND_COLOR.set(this, Color.TRANSPARENT); ! BORDER_COLOR.set(this, Color.TRANSPARENT); ! BORDER_ARC.set(this, 0); ! BORDER_WIDTH.set(this, 0); ! IMAGE_MODE.set(this, TILED); ! INSET_WIDTH.set(this, 0); } --- 75,87 ---- } ! protected void applyStyleSheet(StyleSheet sheet) { ! super.applyStyleSheet(sheet); ! FOREGROUND_COLOR.set(this, 0x000000, sheet); ! BACKGROUND_COLOR.set(this, Color.TRANSPARENT, sheet); ! BORDER_COLOR.set(this, Color.TRANSPARENT, sheet); ! BORDER_ARC.set(this, 0, sheet); ! BORDER_WIDTH.set(this, 0, sheet); ! IMAGE_MODE.set(this, TILED, sheet); ! INSET_WIDTH.set(this, 0, sheet); } Index: Container.java =================================================================== RCS file: /cvsroot/synclast/client/src/com/synclast/ui/Container.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** Container.java 18 Sep 2006 11:31:26 -0000 1.38 --- Container.java 20 Sep 2006 12:19:53 -0000 1.39 *************** *** 25,28 **** --- 25,29 ---- import com.synclast.Event; + import com.synclast.StyleSheet; /** *************** *** 185,196 **** * components may have been resized. */ ! public void applyStyleSheet() {//StyleSheet sheet) { ! super.applyStyleSheet();//sheet); // Apply just the new styleSheet to contained widgets Widget widget; ! for (int i = widgets.size() - 1; i >= 0; --i) { ! widget = (Widget) widgets.elementAt(i); ! widget.applyStyleSheet();//sheet); } } --- 186,206 ---- * components may have been resized. */ ! protected void applyStyleSheet(StyleSheet sheet) { ! super.applyStyleSheet(sheet); // Apply just the new styleSheet to contained widgets Widget widget; ! //avoid NullPointerExeption where widgets Vector is currently null ! //static initialization case, where instance variables have not ! //been initialized can leave widgets == null; ! //this happens because Widget constructor gets called before Container ! //constructor, but Widget constructor calls applyStyleSheet, which ! //causes this method to get called before our constructor (or instance ! //initialization) has run. Weird edge case, but applicable ! if(widgets != null) { ! for (int i = widgets.size() - 1; i >= 0; --i) { ! widget = (Widget) widgets.elementAt(i); ! widget.applyStyleSheet(sheet); ! } } } *************** *** 262,268 **** widgets.addElement(widget); } if (context != null) { ! widget.applyStyleSheet();//context.getStyleSheet()); } if (context != null && context.isShown()) { widget.showNotify(); --- 272,281 ---- widgets.addElement(widget); } + //applyStyleSheet even if null, so we at least get default values + StyleSheet sheet = null; if (context != null) { ! sheet = context.getStyleSheet(); } + widget.applyStyleSheet(sheet); if (context != null && context.isShown()) { widget.showNotify(); Index: Checkbox.java =================================================================== RCS file: /cvsroot/synclast/client/src/com/synclast/ui/Checkbox.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Checkbox.java 18 Sep 2006 07:59:05 -0000 1.11 --- Checkbox.java 20 Sep 2006 12:19:53 -0000 1.12 *************** *** 25,28 **** --- 25,29 ---- import com.synclast.Event; + import com.synclast.StyleSheet; /** *************** *** 40,48 **** } ! protected void init() { ! super.init(); ! BORDER_WIDTH.set(this, 1); ! BORDER_COLOR.set(this, Color.BLACK); ! BACKGROUND_COLOR.set(this, Color.LIGHT_GRAY); } --- 41,49 ---- } ! protected void applyStyleSheet(StyleSheet sheet) { ! super.applyStyleSheet(sheet); ! BORDER_WIDTH.set(this, 1, sheet); ! BORDER_COLOR.set(this, Color.BLACK, sheet); ! BACKGROUND_COLOR.set(this, Color.LIGHT_GRAY, sheet); } Index: Input.java =================================================================== RCS file: /cvsroot/synclast/client/src/com/synclast/ui/Input.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Input.java 18 Sep 2006 07:59:05 -0000 1.21 --- Input.java 20 Sep 2006 12:19:53 -0000 1.22 *************** *** 29,32 **** --- 29,33 ---- import com.synclast.Event; + import com.synclast.StyleSheet; import com.synclast.SynclastTask; import com.synclast.SynclastManager; *************** *** 115,135 **** } ! protected void init() { ! super.init(); ! MASK_CHAR.set(this, 0); ! CURSOR_BLINK_DELAY.set(this, 500); ! MAX_SIZE.set(this, 10); //WIDTH.set(this, 10); Font defaultFont = Font.getDefaultFont(); ! int fFace = FONT_FACE.get(this, defaultFont.getFace()); ! int fStyle = FONT_STYLE.get(this, defaultFont.getStyle()); ! int fSize = FONT_SIZE.get(this, defaultFont.getSize()); setDefault(FONT, Style.getFontValue(Font.getFont(fFace, fStyle, fSize))); ! BORDER_WIDTH.set(this, 1); ! BORDER_COLOR.set(this, Color.BLACK); ! INSET_WIDTH.set(this, 2); } --- 116,136 ---- } ! protected void applyStyleSheet(StyleSheet sheet) { ! super.applyStyleSheet(sheet); ! MASK_CHAR.set(this, 0, sheet); ! CURSOR_BLINK_DELAY.set(this, 500, sheet); ! MAX_SIZE.set(this, 10, sheet); //WIDTH.set(this, 10); Font defaultFont = Font.getDefaultFont(); ! int fFace = FONT_FACE.get(this, defaultFont.getFace(), sheet); ! int fStyle = FONT_STYLE.get(this, defaultFont.getStyle(), sheet); ! int fSize = FONT_SIZE.get(this, defaultFont.getSize(), sheet); setDefault(FONT, Style.getFontValue(Font.getFont(fFace, fStyle, fSize))); ! BORDER_WIDTH.set(this, 1, sheet); ! BORDER_COLOR.set(this, Color.BLACK, sheet); ! INSET_WIDTH.set(this, 2, sheet); } Index: Style.java =================================================================== RCS file: /cvsroot/synclast/client/src/com/synclast/ui/Style.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Style.java 18 Sep 2006 11:15:36 -0000 1.3 --- Style.java 20 Sep 2006 12:19:53 -0000 1.4 *************** *** 286,291 **** * Method to get the "parsed" value from this Style. Usually you will want to call Style.set(Widget). You should only call this if you need to do special handling with the returned value, instead of setting it directly on the widget. */ ! public int get(Widget widget, int defaultValue) { ! String value = getString(widget, defaultValue); //parseValue handles null return parseValue(value, defaultValue); --- 286,291 ---- * Method to get the "parsed" value from this Style. Usually you will want to call Style.set(Widget). You should only call this if you need to do special handling with the returned value, instead of setting it directly on the widget. */ ! public int get(Widget widget, int defaultValue, StyleSheet styleSheet) { ! String value = getString(widget, defaultValue, styleSheet); //parseValue handles null return parseValue(value, defaultValue); *************** *** 295,299 **** * Method to get the "raw" StyleSheet value for this Style. Calling this method will avoid any "parsing" being done on the value returned from the StyleSheet. Use this method if you know Style cannot handle the "raw" StyleSheet value in its parse method (such as style values that are not parsable to an int). This method still handles looking up the Stylesheet and gettng the cascaded value properly. Normally you will call Style.set(Widget) instead of this method. */ ! public String getString(Widget widget, int defaultValue) { if(widget == null) return null; Container parent = widget.container; --- 295,299 ---- * Method to get the "raw" StyleSheet value for this Style. Calling this method will avoid any "parsing" being done on the value returned from the StyleSheet. Use this method if you know Style cannot handle the "raw" StyleSheet value in its parse method (such as style values that are not parsable to an int). This method still handles looking up the Stylesheet and gettng the cascaded value properly. Normally you will call Style.set(Widget) instead of this method. */ ! /* public String getString(Widget widget, int defaultValue) { if(widget == null) return null; Container parent = widget.container; *************** *** 306,309 **** --- 306,313 ---- } } + return getString(widget, defaultValue, styleSheet); + } + */ + public String getString(Widget widget, int defaultValue, StyleSheet styleSheet) { String value = null; if(styleSheet != null) { *************** *** 316,321 **** * Method for getting the StyleSheet value, and setting it on the specified Widget. This is the normal method call on a Style. The Style will use the widget's current containement hierarchy to get the proper StyleSheet and to determine the proper cascade order for getting the Stylesheet vaalue. It will then parse this "raw" StyleSheet value, and set it on the widget, using the Style's id, and the parsed value, by calling Widget.set(int, int). This method is usually only called form inside Widget, and subclasses of Widget. */ ! public void set(Widget widget, int defaultValue) { ! int parsedValue = get(widget, defaultValue); widget.setDefault(id, parsedValue); } --- 320,325 ---- * Method for getting the StyleSheet value, and setting it on the specified Widget. This is the normal method call on a Style. The Style will use the widget's current containement hierarchy to get the proper StyleSheet and to determine the proper cascade order for getting the Stylesheet vaalue. It will then parse this "raw" StyleSheet value, and set it on the widget, using the Style's id, and the parsed value, by calling Widget.set(int, int). This method is usually only called form inside Widget, and subclasses of Widget. */ ! public void set(Widget widget, int defaultValue, StyleSheet styleSheet) { ! int parsedValue = get(widget, defaultValue, styleSheet); widget.setDefault(id, parsedValue); } Index: Label.java =================================================================== RCS file: /cvsroot/synclast/client/src/com/synclast/ui/Label.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Label.java 18 Sep 2006 11:09:10 -0000 1.17 --- Label.java 20 Sep 2006 12:19:53 -0000 1.18 *************** *** 22,25 **** --- 22,26 ---- import javax.microedition.lcdui.Font; import javax.microedition.lcdui.Graphics; + import com.synclast.StyleSheet; /** *************** *** 68,80 **** } ! protected void init() { ! super.init(); Font defaultFont = Font.getDefaultFont(); ! int fFace = FONT_FACE.get(this, defaultFont.getFace()); ! int fStyle = FONT_STYLE.get(this, defaultFont.getStyle()); ! int fSize = FONT_SIZE.get(this, defaultFont.getSize()); setDefault(FONT, Style.getFontValue(Font.getFont(fFace, fStyle, fSize))); ! INSET_WIDTH.set(this, 2); } --- 69,81 ---- } ! protected void applyStyleSheet(StyleSheet sheet) { ! super.applyStyleSheet(sheet); Font defaultFont = Font.getDefaultFont(); ! int fFace = FONT_FACE.get(this, defaultFont.getFace(), sheet); ! int fStyle = FONT_STYLE.get(this, defaultFont.getStyle(), sheet); ! int fSize = FONT_SIZE.get(this, defaultFont.getSize(), sheet); setDefault(FONT, Style.getFontValue(Font.getFont(fFace, fStyle, fSize))); ! INSET_WIDTH.set(this, 2, sheet); } Index: GridMenu.java =================================================================== RCS file: /cvsroot/synclast/client/src/com/synclast/ui/GridMenu.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GridMenu.java 18 Sep 2006 07:59:05 -0000 1.2 --- GridMenu.java 20 Sep 2006 12:19:53 -0000 1.3 *************** *** 27,30 **** --- 27,31 ---- import com.synclast.Event; + import com.synclast.StyleSheet; import com.synclast.SynclastTask; *************** *** 86,93 **** } ! protected void init() { ! super.init(); ! SELECTED_COLOR.set(this, 0x000000); ! INSET_WIDTH.set(this, 2); } --- 87,94 ---- } ! protected void applyStyleSheet(StyleSheet sheet) { ! super.applyStyleSheet(sheet); ! SELECTED_COLOR.set(this, 0x000000, sheet); ! INSET_WIDTH.set(this, 2, sheet); } |