Tuesday Sep 18, 2007

[TIP] User Code in Component Properties

When you are creating an application in Mobility Pack Visual Designer you probably use the Properties to change texts and other properties of the components used in your midlet. The Properties window is opened by default in right bottom corner of the Visual Designer. The Properties window shows the properties of selected component either in Flow/Screen Designer view or in Inspector/Navigator.


When the property name is in bold then the property doesn't have the default value. It means that you (or the IDE) changed it. The same approach is used by the Properties window in Matisse GUI Designer.
Look at the String, Timeout, Title, Instance Name properties at the picture on right side.

You can change Title of component, you can change the text shown etc. There are two ways how to do it.
The first one is to use a string that you write to the appropriate property of the component - e.g. .

The other option is to open Property editor(PE) of a property by click on the three dots button. In the PE you can use your User Code to assign the value to the property.



Property Editor in 5.5.1



Property Editor in 6.0
The generated code for the user code value of the property from the pictures above will look like
    public Alert getAlert() {
        if (alert == null) {
            // write pre-init user code here
            alert = new Alert("My Little Alert", LocalizationSupport.getMessage("licenseincorrect"), null, null);
            alert.setTimeout(Alert.FOREVER);
            // write post-init user code here
        }
        return alert;
    }

Wednesday Mar 28, 2007

[TIP] Using ColorSchema for TableItem

There is custom component TableItem available in palette of NetBeans Mobility Pack. It was added in version 5.0 of the Mobility Pack. Later we discovered that the TableItem displays in black color only on some devices - e.g. BlackBerry. There are issues filled for those problems 79625, 80447.

The "all in black" problem is mostly caused by the wrong return values of getDisplay().getColor(Display.COLOR_\*);. It returns 0 for all the Display.COLOR_\* constants on BlackBerry.



This issue can be solved in Mobility Pack 5.5 (and later) with ColorSchema class. Look at the image on the right side. The table looks definitely better.
You can specify what ColorSchema should be used by your TableItem by calling method aTableItem.setColorSchema(ColorSchema schema);.


Example of ColorSchema Usage

I will define a ColorSchema first.
ColorSchema myOwnColorSchema = new ColorSchema() {
            
            public int WHITE = 0xffffff;
            public int BLACK = 0x000000;
            public Image getBackgroundImage() {
                return null; //there won't be any background image
            }
            public int getBackgroundImageAnchorPoint() {
                return 0; //there won't be any background image
            }
            public int getColor(int aColorSpecifier) {
                switch (aColorSpecifier) {
                    case Display.COLOR_BACKGROUND:
                    case Display.COLOR_HIGHLIGHTED_FOREGROUND:
                        return WHITE;
                    case Display.COLOR_HIGHLIGHTED_BACKGROUND:
                    case Display.COLOR_BORDER:
                    case Display.COLOR_HIGHLIGHTED_BORDER:
                    case Display.COLOR_FOREGROUND:
                        return BLACK;
                    default:
                        return BLACK;
                }
            }
            
            public boolean isBackgroundImageTiled() {
                return false;//there won't be any background image
            }
            public boolean isBackgroundTransparent() {
                return false;//there won't be any background image
            }
        };

The ColorSchema is abstract class therefore you have to implement its methods when you are creating it.

Then I'll use the color schema for my TableItem. It's highly recommended to access the components used in Visual Design by the getter methods(get_).
get_tableItem1().setColorSchema(myOwnColorSchema);


You can download sample project. It shows how to use the ColorSchema. It will display the settings of your device too.
About

This is the main channel to share news, tips and other stuff related to my work. Sometimes you can find even personal stuff. Enjoy your reading...

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
news
Blogroll

No bookmarks in folder

OldNews
MyTrash
NavBar
NetBeans
LinksToBeExpanded