use of com.codename1.rad.attributes.UIID in project CodeRAD by shannah.
the class Buttons method rebuild.
private void rebuild() {
built = true;
requiresRefresh = false;
removeAll();
this.actionCategory = actionCategory;
Actions actions = getViewNode().getInheritedActions(this.actionCategory);
Actions overflowActions = null;
actions = actions.proxy(getViewNode());
if (limit >= 0 && actions.size() >= limit) {
// Note: >= because need to fit overflow button under limit
overflowActions = new Actions();
Actions tempActions = new Actions();
int len = actions.size();
int index = -1;
UIID uiid = null;
for (ActionNode action : actions) {
index++;
if (index < limit - (overflowMenuStyle == OverflowMenuStyle.None ? 0 : 1)) {
tempActions.add(action);
} else {
overflowActions.add(action);
}
if (uiid == null) {
uiid = action.getUIID();
}
}
actions = tempActions;
if (overflowActions.size() > 0) {
ActionNode overflowAction = overflowButtonAction.icon(FontImage.MATERIAL_MORE_HORIZ).build();
// Try to match the UIID of the other actions
if (uiid != null) {
overflowAction.setAttributes(uiid);
}
overflowAction.setParent(getViewNode());
final Actions fOverflowActions = overflowActions;
overflowActions.copyAttributesIfNotExists(overflowActionTemplate.build());
overflowAction.addActionListener(e -> {
e.consume();
showOverflowMenu(fOverflowActions);
});
if (overflowMenuStyle != OverflowMenuStyle.None) {
actions.add(overflowAction);
}
}
}
actions.copyAttributesIfNotExists(actionTemplate.build());
actions.addToContainer(this, getEntity(), buttonWrapper);
revalidateWithAnimationSafety();
}
use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.
the class ResourceEditorApp method main.
/**
* Main method launching the application.
*/
public static void main(String[] args) throws Exception {
JavaSEPortWithSVGSupport.blockMonitors();
JavaSEPortWithSVGSupport.setDesignMode(true);
JavaSEPortWithSVGSupport.setShowEDTWarnings(false);
JavaSEPortWithSVGSupport.setShowEDTViolationStacks(false);
// creates a deadlock between FX, Swing and CN1. Horrible horrible deadlock...
JavaSEPortWithSVGSupport.blockNativeBrowser = true;
if (args.length > 0) {
if (args[0].equalsIgnoreCase("-buildVersion")) {
Properties p = new Properties();
try {
p.load(ResourceEditorApp.class.getResourceAsStream("/version.properties"));
} catch (IOException ex) {
ex.printStackTrace();
}
System.out.println(p.getProperty("build", "1"));
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("-style")) {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
final String uiid = args[2];
String themeName = args[3];
boolean isXMLEnabled = Preferences.userNodeForPackage(ResourceEditorView.class).getBoolean("XMLFileMode", true);
EditableResources.setXMLEnabled(isXMLEnabled);
EditableResources res = new EditableResources();
File resourceFile = new File(args[1]);
res.openFileWithXMLSupport(resourceFile);
Hashtable themeHash = res.getTheme(themeName);
final AddThemeEntry entry = new AddThemeEntry(false, res, null, new Hashtable(themeHash), "", themeName);
entry.setKeyValues(uiid, "");
entry.setPreferredSize(new Dimension(1000, 600));
JPanel wrapper = new JPanel(new BorderLayout());
wrapper.add(entry, BorderLayout.CENTER);
JPanel bottom = new JPanel();
ButtonGroup gr = new ButtonGroup();
JRadioButton unsel = new JRadioButton("Unselected", true);
gr.add(unsel);
unsel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
entry.setPrefix("");
entry.setKeyValues(uiid, "");
entry.revalidate();
}
});
bottom.add(unsel);
JRadioButton sel = new JRadioButton("Selected");
gr.add(sel);
sel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
entry.setPrefix("sel#");
entry.setKeyValues(uiid, "sel#");
entry.revalidate();
}
});
bottom.add(sel);
JRadioButton press = new JRadioButton("Pressed");
gr.add(press);
press.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
entry.setPrefix("press#");
entry.setKeyValues(uiid, "press#");
entry.revalidate();
}
});
bottom.add(press);
JRadioButton dis = new JRadioButton("Disabled");
gr.add(dis);
dis.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
entry.setPrefix("dis#");
entry.setKeyValues(uiid, "dis#");
entry.revalidate();
}
});
bottom.add(dis);
wrapper.add(bottom, BorderLayout.SOUTH);
if (ModifiableJOptionPane.showConfirmDialog(null, wrapper, "Edit") == JOptionPane.OK_OPTION) {
Hashtable tmp = new Hashtable(themeHash);
entry.updateThemeHashtable(tmp);
res.setTheme(themeName, tmp);
}
try (FileOutputStream fos = new FileOutputStream(resourceFile)) {
res.save(fos);
}
res.saveXML(resourceFile);
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("-img")) {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
String imageName;
String fileName;
if (args.length == 3) {
imageName = args[2];
fileName = args[2];
} else {
if (args.length == 4) {
imageName = args[3];
fileName = args[2];
} else {
System.out.println("The img command works as: -img path_to_resourceFile.res pathToImageFile [image name]");
System.exit(1);
return;
}
}
File imageFile = new File(fileName);
if (!imageFile.exists()) {
System.out.println("File not found: " + imageFile.getAbsolutePath());
System.exit(1);
return;
}
com.codename1.ui.Image img = ImageRGBEditor.createImageStatic(imageFile);
boolean isXMLEnabled = Preferences.userNodeForPackage(ResourceEditorView.class).getBoolean("XMLFileMode", true);
EditableResources.setXMLEnabled(isXMLEnabled);
EditableResources res = new EditableResources();
File resourceFile = new File(args[1]);
res.openFileWithXMLSupport(resourceFile);
res.setImage(imageName, img);
try (FileOutputStream fos = new FileOutputStream(resourceFile)) {
res.save(fos);
}
res.saveXML(resourceFile);
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("-mimg")) {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
String fileName;
if (args.length == 4) {
fileName = args[3];
} else {
System.out.println("The mimg command works as: -img path_to_resourceFile.res dpi pathToImageFile");
System.out.println("dpi can be one of: high, veryhigh, hd, 560, 2hd, 4k");
System.exit(1);
return;
}
String dpi = args[2];
int dpiInt = -1;
switch(dpi.toLowerCase()) {
case "high":
dpiInt = 3;
break;
case "veryhigh":
dpiInt = 4;
break;
case "hd":
dpiInt = 5;
break;
case "560":
dpiInt = 6;
break;
case "2hd":
dpiInt = 7;
break;
case "4k":
dpiInt = 8;
break;
default:
System.out.println("dpi can be one of: high, veryhigh, hd, 560, 2hd, 4k");
System.exit(1);
return;
}
File imageFile = new File(fileName);
if (!imageFile.exists()) {
System.out.println("File not found: " + imageFile.getAbsolutePath());
System.exit(1);
return;
}
boolean isXMLEnabled = Preferences.userNodeForPackage(ResourceEditorView.class).getBoolean("XMLFileMode", true);
EditableResources.setXMLEnabled(isXMLEnabled);
EditableResources res = new EditableResources();
File resourceFile = new File(args[1]);
res.openFileWithXMLSupport(resourceFile);
AddAndScaleMultiImage.generateImpl(new File[] { imageFile }, res, dpiInt);
try (FileOutputStream fos = new FileOutputStream(resourceFile)) {
res.save(fos);
}
res.saveXML(resourceFile);
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("gen")) {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
File output = new File(args[1]);
generateResourceFile(output, args[2], args[3]);
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("mig")) {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
File projectDir = new File(args[1]);
EditableResources.setXMLEnabled(true);
EditableResources res = new EditableResources();
res.openFileWithXMLSupport(new File(args[2]));
migrateGuiBuilder(projectDir, res, args[3]);
System.exit(0);
return;
}
if (args[0].equalsIgnoreCase("-regen")) {
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
File output = new File(args[1]);
EditableResources.setXMLEnabled(true);
EditableResources res = new EditableResources();
res.openFileWithXMLSupport(output);
FileOutputStream fos = new FileOutputStream(output);
res.save(fos);
fos.close();
generate(res, output);
System.exit(0);
return;
}
}
JavaSEPortWithSVGSupport.setDefaultInitTarget(new JPanel());
Display.init(null);
launch(ResourceEditorApp.class, args);
}
use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.
the class Component method refreshTheme.
/**
* Makes sure the component is up to date with the given UIID
*
* @param id The Style Id to update the Component with
* @param merge indicates if the current styles should be merged with the new styles
*/
protected void refreshTheme(String id, boolean merge) {
UIManager manager = getUIManager();
if (merge) {
Style unSelected = getUnselectedStyle();
if (hasInlineUnselectedStyle()) {
setUnselectedStyle(mergeStyle(unSelected, manager.parseComponentStyle(getInlineStylesTheme(), id, getInlineStylesUIID(id), getInlineUnselectedStyleStrings())));
} else {
setUnselectedStyle(mergeStyle(unSelected, manager.getComponentStyle(id)));
}
if (selectedStyle != null) {
if (hasInlineSelectedStyle()) {
setSelectedStyle(mergeStyle(selectedStyle, manager.parseComponentSelectedStyle(getInlineStylesTheme(), id, getInlineStylesUIID(id), getInlineSelectedStyleStrings())));
} else {
setSelectedStyle(mergeStyle(selectedStyle, manager.getComponentSelectedStyle(id)));
}
}
if (disabledStyle != null) {
if (hasInlineDisabledStyle()) {
setDisabledStyle(mergeStyle(disabledStyle, manager.parseComponentCustomStyle(getInlineStylesTheme(), id, getInlineStylesUIID(id), "dis", getInlineDisabledStyleStrings())));
} else {
setDisabledStyle(mergeStyle(disabledStyle, manager.getComponentCustomStyle(id, "dis")));
}
}
if (pressedStyle != null) {
if (hasInlinePressedStyle()) {
setPressedStyle(mergeStyle(pressedStyle, manager.parseComponentCustomStyle(getInlineStylesTheme(), id, getInlineStylesUIID(id), "press", getInlinePressedStyleStrings())));
} else {
setPressedStyle(mergeStyle(pressedStyle, manager.getComponentCustomStyle(id, "press")));
}
}
} else {
unSelectedStyle = null;
unSelectedStyle = getUnselectedStyle();
selectedStyle = null;
disabledStyle = null;
pressedStyle = null;
allStyles = null;
}
checkAnimation();
manager.getLookAndFeel().bind(this);
}
use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.
the class Component method createStyleAnimation.
/**
* Creates an animation that will transform the current component to the styling of the destination UIID when
* completed. Notice that fonts will only animate within the truetype and native familiy and we recommend that you
* don't shift weight/typeface/style as this might diminish the effect.<br>
* <b>Important: </b> Only unselected styles are animated but once the animation completes all styles are applied.
* @param destUIID the UIID to which this component will gradually shift
* @param duration the duration of the animation or the number of steps
* @return an animation component that can either be stepped or played
*/
public ComponentAnimation createStyleAnimation(final String destUIID, final int duration) {
final Style sourceStyle = getUnselectedStyle();
final Style destStyle = hasInlineUnselectedStyle() ? getUIManager().parseComponentStyle(getInlineStylesTheme(), destUIID, getInlineStylesUIID(destUIID), getInlineUnselectedStyleStrings()) : getUIManager().getComponentStyle(destUIID);
return createStyleAnimation(sourceStyle, destStyle, duration, destUIID);
}
use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.
the class FontImage method setMaterialIcon.
/**
* <p>Applies a material design icon (one of the MATERIAL_* icon constants) to the given command using the
* given UIID. Notice that the pressed/selected & disabled states will be set appropriately.</p>
*
* @param c a command
* @param icon one of the MATERIAL_* icons
* @param uiid the UIID for the command (e.g. TitleCommand)
* @param size the size of the icon in millimeters
*/
public static void setMaterialIcon(Command c, char icon, String uiid, float size) {
if (Font.isTrueTypeFileSupported()) {
UIManager uim = UIManager.getInstance();
Style s = uim.getComponentStyle(uiid);
s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
c.setIcon(FontImage.create("" + icon, s));
Style sel = uim.getComponentSelectedStyle(uiid);
Style pre = uim.getComponentCustomStyle(uiid, "press");
Style dis = uim.getComponentCustomStyle(uiid, "dis");
;
if (sel.getFgColor() != s.getFgColor() || (sel.getBgColor() != s.getBgColor()) || (sel.getBgTransparency() != s.getBgTransparency())) {
sel = new Style(sel);
sel.setFont(getMaterialDesignFont().derive(rightSize(sel, size), Font.STYLE_PLAIN));
c.setRolloverIcon(FontImage.create("" + icon, sel));
}
if (pre.getFgColor() != s.getFgColor() || (pre.getBgColor() != s.getBgColor()) || (pre.getBgTransparency() != s.getBgTransparency())) {
pre = new Style(pre);
pre.setFont(getMaterialDesignFont().derive(rightSize(pre, size), Font.STYLE_PLAIN));
c.setPressedIcon(FontImage.create("" + icon, pre));
}
if (dis.getFgColor() != s.getFgColor() || (dis.getBgColor() != s.getBgColor()) || (dis.getBgTransparency() != s.getBgTransparency())) {
dis = new Style(dis);
dis.setFont(getMaterialDesignFont().derive(rightSize(dis, size), Font.STYLE_PLAIN));
c.setDisabledIcon(FontImage.create("" + icon, dis));
}
}
}
Aggregations