use of com.codename1.ui in project CodenameOne by codenameone.
the class Resources method loadBitmapFont.
Font loadBitmapFont(DataInputStream input, String id, com.codename1.ui.Font font) throws IOException {
Image bitmap = createImage(input);
int charCount = input.readShort();
int[] cutOffsets = new int[charCount];
int[] charWidth = new int[charCount];
for (int iter = 0; iter < charCount; iter++) {
cutOffsets[iter] = input.readShort();
}
for (int iter = 0; iter < charCount; iter++) {
charWidth[iter] = input.readByte();
}
String charset = input.readUTF();
readRenderingHint(input);
if (font == null) {
if (Font.isBitmapFontEnabled()) {
Font old = Font.getBitmapFont(id);
if (old != null) {
// old resource file use Font.clearBitmapCache()
return old;
}
return Font.createBitmapFont(id, bitmap, cutOffsets, charWidth, charset);
}
}
return font;
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class LazyValueC method showContainerImpl.
private Container showContainerImpl(String resourceName, Command sourceCommand, Component sourceComponent, boolean forceBack) {
if (sourceComponent != null) {
Form currentForm = sourceComponent.getComponentForm();
// avoid the overhead of searching if no embedding is used
if (currentForm.getClientProperty(EMBEDDED_FORM_FLAG) != null) {
Container destContainer = sourceComponent.getParent();
while (!(destContainer instanceof EmbeddedContainer || destContainer instanceof Form)) {
// race condition, container was already removed by someone else
if (destContainer == null) {
return null;
}
destContainer = destContainer.getParent();
}
if (destContainer instanceof EmbeddedContainer) {
Container cnt = createContainer(fetchResourceFile(), resourceName, (EmbeddedContainer) destContainer);
if (cnt instanceof Form) {
// Form f = (Form)cnt;
// cnt = formToContainer(f);
showForm((Form) cnt, sourceCommand, sourceComponent);
return cnt;
}
Component fromCmp = destContainer.getComponentAt(0);
// This seems to be no longer necessary now that we have the replaceAndWait version that drops events
// block the user from the ability to press the button twice by mistake
// fromCmp.setEnabled(false);
boolean isBack = forceBack;
Transition t = fromCmp.getUIManager().getLookAndFeel().getDefaultFormTransitionOut();
if (forceBack) {
initBackContainer(cnt, destContainer.getComponentForm(), getFormNavigationStackForComponent(sourceComponent));
t = t.copy(true);
} else {
if (sourceCommand != null) {
if (t != null && backCommands != null && backCommands.contains(sourceCommand) || Display.getInstance().getCurrent().getBackCommand() == sourceCommand) {
isBack = true;
t = t.copy(true);
}
}
}
// create a back command if supported
String commandAction = cnt.getName();
Vector formNavigationStack = getFormNavigationStackForComponent(fromCmp);
if (formNavigationStack != null && !isBack && allowBackTo(commandAction) && !isSameBackDestination((Container) fromCmp, cnt)) {
// trigger listener creation if this is the only command in the form
getFormListenerInstance(destContainer.getComponentForm(), null);
formNavigationStack.addElement(getContainerState((com.codename1.ui.Container) fromCmp));
}
beforeShowContainer(cnt);
destContainer.replaceAndWait(fromCmp, cnt, t, true);
postShowContainer(cnt);
return cnt;
} else {
Container cnt = createContainer(fetchResourceFile(), resourceName);
showForm((Form) cnt, sourceCommand, sourceComponent);
return cnt;
}
}
}
Container cnt = createContainer(fetchResourceFile(), resourceName);
if (cnt instanceof Form) {
showForm((Form) cnt, sourceCommand, sourceComponent);
} else {
Form f = new Form();
f.setLayout(new BorderLayout());
f.addComponent(BorderLayout.CENTER, cnt);
f.setName("Form" + cnt.getName());
showForm(f, sourceCommand, sourceComponent);
}
return cnt;
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class UIManager method buildTheme.
private void buildTheme(Hashtable themeProps) {
String con = (String) themeProps.get("@includeNativeBool");
if (con != null && con.equalsIgnoreCase("true") && Display.getInstance().hasNativeTheme()) {
boolean a = accessible;
accessible = true;
Display.getInstance().installNativeTheme();
accessible = a;
}
Enumeration e = themeProps.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
// this is a constant not a theme entry
if (key.startsWith("@")) {
themeConstants.put(key.substring(1, key.length()), themeProps.get(key));
continue;
}
this.themeProps.put(key, themeProps.get(key));
}
// necessary to clear up the style so we don't get resedue from the previous UI
defaultStyle = new Style();
// create's the default style
defaultStyle = createStyle("", "", false);
defaultSelectedStyle = new Style(defaultStyle);
defaultSelectedStyle = createStyle("", "sel#", true);
String overlayThemes = (String) themeProps.get("@OverlayThemes");
if (overlayThemes != null) {
java.util.List<String> overlayThemesArr = StringUtil.tokenize(overlayThemes, ',');
for (String th : overlayThemesArr) {
th = th.trim();
if (th.length() == 0) {
continue;
}
try {
Resources res = Resources.openLayered("/" + th);
boolean a = accessible;
accessible = true;
addThemeProps(res.getTheme(res.getThemeResourceNames()[0]));
accessible = a;
} catch (Exception ex) {
System.err.println("Failed to load overlay theme file specified by @overlayThemes theme constant: " + th);
Log.e(ex);
}
}
}
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class InstantUI method createEditUI.
/**
* Creates editing UI for the given business object
* @param bo the business object
* @param autoCommit true if the bindings used should be auto-committed
* @return a UI container that can be used to edit the business object
*/
public Container createEditUI(PropertyBusinessObject bo, boolean autoCommit) {
Container cnt;
if (Display.getInstance().isTablet()) {
TableLayout tl = new TableLayout(1, 2);
tl.setGrowHorizontally(true);
cnt = new Container(tl);
} else {
cnt = new Container(BoxLayout.y());
}
UiBinding uib = new UiBinding();
ArrayList<UiBinding.Binding> allBindings = new ArrayList<UiBinding.Binding>();
for (PropertyBase b : bo.getPropertyIndex()) {
if (isExcludedProperty(b)) {
continue;
}
Class cls = (Class) b.getClientProperty("cn1$cmpCls");
if (cls != null) {
try {
Component cmp = (Component) cls.newInstance();
cmp.setName(b.getName());
cnt.add(b.getLabel()).add(cmp);
allBindings.add(uib.bind(b, cmp));
} catch (Exception err) {
Log.e(err);
throw new RuntimeException("Custom property instant UI failed for " + b.getName() + " " + err);
}
continue;
}
String[] multiLabels = (String[]) b.getClientProperty("cn1$multiChceLbl");
if (multiLabels != null) {
// multi choice component
final Object[] multiValues = (Object[]) b.getClientProperty("cn1$multiChceVal");
if (multiLabels.length < 5) {
// toggle buttons
ButtonGroup bg = new ButtonGroup();
RadioButton[] rbs = new RadioButton[multiLabels.length];
cnt.add(b.getLabel());
Container radioBox = new Container(new GridLayout(multiLabels.length));
for (int iter = 0; iter < multiLabels.length; iter++) {
rbs[iter] = RadioButton.createToggle(multiLabels[iter], bg);
radioBox.add(rbs[iter]);
}
cnt.add(radioBox);
allBindings.add(uib.bindGroup(b, multiValues, rbs));
} else {
Picker stringPicker = new Picker();
stringPicker.setStrings(multiLabels);
Map<Object, Object> m1 = new HashMap<Object, Object>();
Map<Object, Object> m2 = new HashMap<Object, Object>();
for (int iter = 0; iter < multiLabels.length; iter++) {
m1.put(multiLabels[iter], multiValues[iter]);
m2.put(multiValues[iter], multiLabels[iter]);
}
cnt.add(b.getLabel()).add(stringPicker);
allBindings.add(uib.bind(b, stringPicker, new UiBinding.PickerAdapter<Object>(new UiBinding.MappingConverter(m1), new UiBinding.MappingConverter(m2))));
}
continue;
}
Class t = b.getGenericType();
if (t != null) {
if (t == Boolean.class) {
CheckBox cb = new CheckBox();
uib.bind(b, cb);
cnt.add(b.getLabel()).add(cb);
continue;
}
if (t == Date.class) {
Picker dp = new Picker();
dp.setType(Display.PICKER_TYPE_DATE);
uib.bind(b, dp);
cnt.add(b.getLabel()).add(dp);
continue;
}
}
TextField tf = new TextField();
tf.setConstraint(getTextFieldConstraint(b));
uib.bind(b, tf);
cnt.add(b.getLabel()).add(tf);
}
cnt.putClientProperty("cn1$iui-binding", uib.createGroupBinding(allBindings));
return cnt;
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class UserInterfaceEditor method createCustomComponentButton.
private void createCustomComponentButton(final CustomComponent c) {
try {
final JButton b = new JButton(c.getType());
b.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jdesktop/swingx/resources/placeholder32.png")));
b.setHorizontalAlignment(SwingConstants.LEFT);
b.setBorder(null);
userComponents.add(b);
b.putClientProperty("CustomComponent", c);
final Class codenameOneBaseClass = c.getCls();
makeDraggable(b, codenameOneBaseClass, c.getType(), c);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (lockForDragging) {
lockForDragging = false;
return;
}
try {
if (c.isUiResource()) {
UIBuilderOverride u = new UIBuilderOverride();
com.codename1.ui.Component cmp = u.createContainer(res, c.getType());
String t = (String) cmp.getClientProperty(TYPE_KEY);
if (t == null) {
cmp.putClientProperty(TYPE_KEY, c.getType());
t = c.getType();
}
addComponentToContainer(cmp, t);
return;
}
com.codename1.ui.Component cmp = (com.codename1.ui.Component) codenameOneBaseClass.newInstance();
cmp.putClientProperty("CustomComponent", c);
cmp.putClientProperty(TYPE_KEY, c.getType());
initializeComponentText(cmp);
addComponentToContainer(cmp, c.getType());
} catch (Exception err) {
err.printStackTrace();
JOptionPane.showMessageDialog(UserInterfaceEditor.this, err.getClass().getName() + ": " + err, "Error", JOptionPane.ERROR_MESSAGE);
}
}
});
/*b.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if(BaseForm.isRightClick(e)) {
JPopupMenu p = new JPopupMenu();
AbstractAction deleteAction = new AbstractAction("Delete") {
public void actionPerformed(ActionEvent e) {
componentPalette.remove(b);
componentPalette.revalidate();
customComponents.remove(c);
res.setUi(name, persistContainer(containerInstance));
}
};
p.add(deleteAction);
p.show(b, e.getPoint().x, e.getPoint().y);
}
}
});*/
} catch (Exception err) {
err.printStackTrace();
JOptionPane.showMessageDialog(UserInterfaceEditor.this, err.getClass().getName() + ": " + err, "Error", JOptionPane.ERROR_MESSAGE);
}
}
Aggregations