use of com.codename1.ui.table.Table in project CodenameOne by codenameone.
the class CSSEngine method setMatchingFont.
/**
* Sets the font of the component to the closest font that can be found according to the specified properties
* Note that system fonts will be matched only with system fonts and same goes for bitmap fonts
*
* @param htmlC The HTMLComponent this component belongs to (For the available bitmap fonts table)
* @param cmp The component to work on
* @param fontFamily The font family
* @param fontSize The font size in pixels
* @param fontStyle The font style - either Font.STYLE_PLAIN or Font.STYLE_ITALIC
* @param fontWeight The font weight - either Font.STYLE_PLAIN ot Font.STYLE_BOLD
*/
private void setMatchingFont(HTMLComponent htmlC, Component cmp, String fontFamily, int fontSize, int fontStyle, int fontWeight, CSSElement selector) {
int styles = getApplicableStyles(cmp, selector);
Font curFont = cmp.getUnselectedStyle().getFont();
if (((styles & STYLE_SELECTED) != 0) && ((styles & STYLE_UNSELECTED) == 0)) {
// Focus
curFont = cmp.getSelectedStyle().getFont();
}
if ((styles & STYLE_PRESSED) != 0) {
// Active
curFont = ((HTMLLink) cmp).getPressedStyle().getFont();
}
int curSize = 0;
boolean isBold = false;
boolean isItalic = false;
String curFamily = null;
if (curFont.getCharset() == null) {
// The family string in system fonts is just used to index the font in the matchingFonts cache hashtable
switch(curFont.getFace()) {
case Font.FACE_SYSTEM:
curFamily = "system";
break;
case Font.FACE_PROPORTIONAL:
curFamily = "proportional";
break;
default:
curFamily = "monospace";
}
// Font height is roughly 2-3 pixels above the font size, and is the best indicator we have to what the system font size is
curSize = curFont.getHeight() - 2;
isBold = ((curFont.getStyle() & Font.STYLE_BOLD) != 0);
isItalic = ((curFont.getStyle() & Font.STYLE_ITALIC) != 0);
} else {
// bitmap font
HTMLFont hFont = htmlC.getHTMLFont(curFont);
if (hFont != null) {
curSize = hFont.getSize();
isBold = hFont.isBold();
isItalic = hFont.isItalic();
curFamily = hFont.getFamily();
}
}
if (((fontFamily != null) && (curFamily != null) && (!fontFamily.equalsIgnoreCase(curFamily))) || (fontSize != curSize) || ((isBold) != (fontWeight == Font.STYLE_BOLD)) || ((isItalic) != (fontWeight == Font.STYLE_ITALIC))) {
// Set the unspecified attributes of the requested font to match those of the current one
if ((fontFamily == null) && (curFamily != null)) {
fontFamily = curFamily.toLowerCase();
}
if (fontSize == -1) {
fontSize = curSize;
}
if (fontStyle == -1) {
if (isItalic) {
fontStyle = Font.STYLE_ITALIC;
} else {
fontStyle = 0;
}
}
if (fontWeight == -1) {
if (isBold) {
fontWeight = Font.STYLE_BOLD;
} else {
fontWeight = 0;
}
}
String fontKey = fontFamily + "." + fontSize + "." + fontStyle + "." + fontWeight;
Object obj = matchingFonts.get(fontKey);
if (obj != null) {
Font font = (Font) obj;
setFontForStyles(styles, cmp, font);
return;
}
Font font = null;
if (curFont.getCharset() == null) {
// system font
int systemFontSize = curFont.getSize();
if (fontSize > curSize) {
// bigger font
if (systemFontSize == Font.SIZE_SMALL) {
systemFontSize = Font.SIZE_MEDIUM;
} else if (systemFontSize == Font.SIZE_MEDIUM) {
systemFontSize = Font.SIZE_LARGE;
}
} else if (fontSize < curSize) {
// smaller font
if (systemFontSize == Font.SIZE_LARGE) {
systemFontSize = Font.SIZE_MEDIUM;
} else if (systemFontSize == Font.SIZE_MEDIUM) {
systemFontSize = Font.SIZE_SMALL;
}
}
font = Font.createSystemFont(curFont.getFace(), fontStyle + fontWeight, systemFontSize);
} else {
font = htmlC.getClosestFont(fontFamily, fontSize, fontStyle, fontWeight);
}
if (font != null) {
matchingFonts.put(fontKey, font);
setFontForStyles(styles, cmp, font);
}
}
}
use of com.codename1.ui.table.Table in project CodenameOne by codenameone.
the class TextModeLayout method layoutContainer.
/**
* {@inheritDoc}
*/
@Override
public void layoutContainer(Container parent) {
if (autoGrouping && actual != table && lastComponentCount != parent.getComponentCount()) {
lastComponentCount = parent.getComponentCount();
ArrayList<Component> tc = new ArrayList<Component>();
for (Component c : parent) {
if (c instanceof InputComponent) {
tc.add(c);
}
}
if (tc.size() > 0) {
Component[] tcArr = new Component[tc.size()];
tc.toArray(tcArr);
InputComponent.group(tcArr);
}
}
actual.layoutContainer(parent);
}
use of com.codename1.ui.table.Table in project CodenameOne by codenameone.
the class UIFragment method getChildren.
private List<Element> getChildren(Element el) {
String tagName = el.getTagName();
if ("table".equals(tagName)) {
List<Element> out = new ArrayList<Element>();
for (Object row : el.getChildrenByTagName("tr")) {
Element erow = (Element) row;
for (Object cell : erow.getChildrenByTagName("td")) {
Element ecell = (Element) cell;
if (ecell.getNumChildren() > 0) {
out.add(ecell.getChildAt(0));
}
}
}
return out;
} else {
List<Element> out = new ArrayList<Element>();
int len = el.getNumChildren();
for (int i = 0; i < len; i++) {
out.add(el.getChildAt(i));
}
return out;
}
}
use of com.codename1.ui.table.Table in project CodenameOne by codenameone.
the class TextField method createSymbolTable.
/**
* Creates a symbol table container used by the showSymbolDialog method.
* This method is designed for subclases to override and customize.
*
* @return container for the symbol table.
*/
protected Container createSymbolTable() {
char[] symbolArray = getSymbolTable();
Container symbols = new Container(new GridLayout(symbolArray.length / 5, 5));
int slen = symbolArray.length;
for (int iter = 0; iter < slen; iter++) {
Button button = new Button(new Command("" + symbolArray[iter]));
button.setUIID("VKBButton");
button.setAlignment(CENTER);
symbols.addComponent(button);
}
return symbols;
}
use of com.codename1.ui.table.Table in project CodenameOne by codenameone.
the class DatabaseTests method testSimpleQueries.
private void testSimpleQueries() throws Exception {
String dbName = "testdb";
Database.delete(dbName);
Database db = Database.openOrCreate(dbName);
db.execute("create table tests (name text)");
db.execute("insert into tests values ('Steve'), ('Mike'), ('Ryan')");
Cursor c = db.executeQuery("select count(*) from tests");
c.next();
this.assertEqual(3, c.getRow().getInteger(0), "Expected result of 3 for count(*) after inserting 3 rows");
}
Aggregations