use of com.codename1.ui.util.Resources in project CodenameOne by codenameone.
the class LazyValueC method readRendererer.
private GenericListCellRenderer readRendererer(Resources res, DataInputStream in) throws IOException {
int rendererComponentCount = in.readByte();
String f = in.readUTF();
String s = in.readUTF();
if (rendererComponentCount == 2) {
Component selected = createContainer(res, f);
Component unselected = createContainer(res, s);
GenericListCellRenderer g = new GenericListCellRenderer(selected, unselected);
g.setFisheye(!f.equals(s));
return g;
} else {
Component selected = createContainer(res, f);
Component unselected = createContainer(res, s);
Component even = createContainer(res, in.readUTF());
Component evenU = createContainer(res, in.readUTF());
GenericListCellRenderer g = new GenericListCellRenderer(selected, unselected, even, evenU);
g.setFisheye(!f.equals(s));
return g;
}
}
use of com.codename1.ui.util.Resources 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.util.Resources in project CodenameOne by codenameone.
the class UIManager method initFirstTheme.
/**
* This is a shorthand notation for boilerplate code for initializing the first theme in the given resource file
* and catching/doing nothing with the IOException since this would be invoked too early in the program
* where we would be out of options if something like that happens. Effectively this is the same as writing:
* <pre>
* try {
* theme = Resources.openLayered(resourceFile);
* UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
* } catch(IOException e){
* e.printStackTrace();
* }
* </pre>
* @param resourceFile the name of the resource file starting with / and without the res extension
* @return the resource file or null in case of a failure
*/
public static Resources initFirstTheme(String resourceFile) {
try {
Resources theme = Resources.openLayered(resourceFile);
UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
Resources.setGlobalResources(theme);
return theme;
} catch (IOException e) {
Log.e(e);
}
return null;
}
use of com.codename1.ui.util.Resources in project CodenameOne by codenameone.
the class UIManager method initNamedTheme.
/**
* Same as the initFirstTheme method, but unlike that method this allows specifying the theme resource name
* @param resourceFile the name of the resource file starting with / and without the res extension
* @param resName the name of the theme to use from the file if it contains more than one theme
* @return the resource file or null in case of a failure
*/
public static Resources initNamedTheme(String resourceFile, String resName) {
try {
Resources theme = Resources.openLayered(resourceFile);
UIManager.getInstance().setThemeProps(theme.getTheme(resName));
Resources.setGlobalResources(theme);
return theme;
} catch (IOException e) {
Log.e(e);
}
return null;
}
use of com.codename1.ui.util.Resources 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