use of com.codename1.rad.models.Property.Name 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.models.Property.Name in project CodenameOne by codenameone.
the class CloudPersona method createOrLogin.
/**
* Creates a new user if a user isn't occupying the given login already,
* if the user exists performs a login operation.
*
* @param login a user name
* @param password a password
* @return true if the login is successful false otherwise
*/
public static boolean createOrLogin(String login, String password) {
if (instance == null) {
getCurrentPersona();
if (instance.persona != null) {
return true;
}
}
ConnectionRequest loginRequest = new ConnectionRequest();
loginRequest.setPost(true);
loginRequest.setUrl(CloudStorage.SERVER_URL + "/objStoreUser");
loginRequest.addArgument("l", login);
loginRequest.addArgument("p", password);
loginRequest.addArgument("pk", Display.getInstance().getProperty("package_name", null));
loginRequest.addArgument("bb", Display.getInstance().getProperty("built_by_user", null));
NetworkManager.getInstance().addToQueueAndWait(loginRequest);
if (loginRequest.getResposeCode() != 200) {
return false;
}
ByteArrayInputStream bi = new ByteArrayInputStream(loginRequest.getResponseData());
DataInputStream di = new DataInputStream(bi);
try {
if (di.readBoolean()) {
if (instance == null) {
instance = new CloudPersona();
}
instance.persona = di.readUTF();
Preferences.set("CN1Persona", instance.persona);
Util.cleanup(di);
} else {
Util.cleanup(di);
return false;
}
} catch (IOException ex) {
ex.printStackTrace();
}
return true;
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class ResourceEditorView method generateStateMachineCodeImpl.
private static String generateStateMachineCodeImpl(String uiResourceName, File destFile, boolean promptUserForPackageName, EditableResources loadResources, java.awt.Component errorParent) {
String packageString = "";
File currentFile = destFile;
while (currentFile.getParent() != null) {
String shortName = currentFile.getParentFile().getName();
if (shortName.equalsIgnoreCase("src")) {
break;
}
if (shortName.indexOf(':') > -1 || shortName.length() == 0) {
break;
}
if (shortName.equalsIgnoreCase("org") || shortName.equalsIgnoreCase("com") || shortName.equalsIgnoreCase("net") || shortName.equalsIgnoreCase("gov")) {
if (packageString.length() > 0) {
packageString = shortName + "." + packageString;
} else {
packageString = shortName;
}
break;
}
if (packageString.length() > 0) {
packageString = shortName + "." + packageString;
} else {
packageString = shortName;
}
currentFile = currentFile.getParentFile();
}
final Map<String, String> nameToClassLookup = new HashMap<String, String>();
final Map<String, Integer> commandMap = new HashMap<String, Integer>();
final List<Integer> unhandledCommands = new ArrayList<Integer>();
final List<String[]> actionComponents = new ArrayList<String[]>();
final Map<String, String> allComponents = new HashMap<String, String>();
initCommandMapAndNameToClassLookup(nameToClassLookup, commandMap, unhandledCommands, actionComponents, allComponents);
// list all the .ovr files and add them to the nameToClassLookup
if (loadedFile != null && loadedFile.getParentFile() != null) {
File overrideDir = new File(loadedFile.getParentFile().getParentFile(), "override");
if (overrideDir.exists()) {
File[] ovrFiles = overrideDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File file, String string) {
return string.endsWith(".ovr");
}
});
for (File ovr : ovrFiles) {
try {
EditableResources er = EditableResources.open(new FileInputStream(ovr));
for (String currentResourceName : er.getUIResourceNames()) {
UIBuilder b = new UIBuilder() {
protected com.codename1.ui.Component createComponentInstance(String componentType, Class cls) {
if (cls.getName().startsWith("com.codename1.ui.")) {
// subpackage of CodenameOne should be registered
if (cls.getName().lastIndexOf(".") > 15) {
nameToClassLookup.put(componentType, cls.getName());
}
} else {
nameToClassLookup.put(componentType, cls.getName());
}
return null;
}
};
b.createContainer(er, currentResourceName);
}
} catch (IOException ioErr) {
ioErr.printStackTrace();
}
}
}
}
if (promptUserForPackageName) {
JTextField packageName = new JTextField(packageString);
JOptionPane.showMessageDialog(errorParent, packageName, "Please Pick The Package Name", JOptionPane.PLAIN_MESSAGE);
packageString = packageName.getText();
}
List<String> createdMethodNames = new ArrayList<String>();
try {
Writer w = new FileWriter(destFile);
w.write("/**\n");
w.write(" * This class contains generated code from the Codename One Designer, DO NOT MODIFY!\n");
w.write(" * This class is designed for subclassing that way the code generator can overwrite it\n");
w.write(" * anytime without erasing your changes which should exist in a subclass!\n");
w.write(" * For details about this file and how it works please read this blog post:\n");
w.write(" * http://codenameone.blogspot.com/2010/10/ui-builder-class-how-to-actually-use.html\n");
w.write("*/\n");
if (packageString.length() > 0) {
w.write("package " + packageString + ";\n\n");
}
String className = destFile.getName().substring(0, destFile.getName().indexOf('.'));
boolean hasIo = false;
for (String currentName : nameToClassLookup.keySet()) {
if (nameToClassLookup.get(currentName).indexOf("com.codename1.ui.io") > -1) {
hasIo = true;
break;
}
}
w.write("import com.codename1.ui.*;\n");
w.write("import com.codename1.ui.util.*;\n");
w.write("import com.codename1.ui.plaf.*;\n");
w.write("import java.util.Hashtable;\n");
if (hasIo) {
w.write("import com.codename1.ui.io.*;\n");
w.write("import com.codename1.components*;\n");
}
w.write("import com.codename1.ui.events.*;\n\n");
w.write("public abstract class " + className + " extends UIBuilder {\n");
w.write(" private Container aboutToShowThisContainer;\n");
w.write(" /**\n");
w.write(" * this method should be used to initialize variables instead of\n");
w.write(" * the constructor/class scope to avoid race conditions\n");
w.write(" */\n");
w.write(" /**\n * @deprecated use the version that accepts a resource as an argument instead\n \n**/\n");
w.write(" protected void initVars() {}\n\n");
w.write(" protected void initVars(Resources res) {}\n\n");
w.write(" public " + className + "(Resources res, String resPath, boolean loadTheme) {\n");
w.write(" startApp(res, resPath, loadTheme);\n");
w.write(" }\n\n");
w.write(" public Container startApp(Resources res, String resPath, boolean loadTheme) {\n");
w.write(" initVars();\n");
if (hasIo) {
w.write(" NetworkManager.getInstance().start();\n");
}
for (String currentName : nameToClassLookup.keySet()) {
w.write(" UIBuilder.registerCustomComponent(\"" + currentName + "\", " + nameToClassLookup.get(currentName) + ".class);\n");
}
w.write(" if(loadTheme) {\n");
w.write(" if(res == null) {\n");
w.write(" try {\n");
w.write(" if(resPath.endsWith(\".res\")) {\n");
w.write(" res = Resources.open(resPath);\n");
w.write(" System.out.println(\"Warning: you should construct the state machine without the .res extension to allow theme overlays\");\n");
w.write(" } else {\n");
w.write(" res = Resources.openLayered(resPath);\n");
w.write(" }\n");
w.write(" } catch(java.io.IOException err) { err.printStackTrace(); }\n");
w.write(" }\n");
w.write(" initTheme(res);\n");
w.write(" }\n");
w.write(" if(res != null) {\n");
w.write(" setResourceFilePath(resPath);\n");
w.write(" setResourceFile(res);\n");
w.write(" initVars(res);\n");
w.write(" return showForm(getFirstFormName(), null);\n");
w.write(" } else {\n");
w.write(" Form f = (Form)createContainer(resPath, getFirstFormName());\n");
w.write(" initVars(fetchResourceFile());\n");
w.write(" beforeShow(f);\n");
w.write(" f.show();\n");
w.write(" postShow(f);\n");
w.write(" return f;\n");
w.write(" }\n");
w.write(" }\n\n");
w.write(" protected String getFirstFormName() {\n");
w.write(" return \"" + uiResourceName + "\";\n");
w.write(" }\n\n");
w.write(" public Container createWidget(Resources res, String resPath, boolean loadTheme) {\n");
w.write(" initVars();\n");
if (hasIo) {
w.write(" NetworkManager.getInstance().start();\n");
}
for (String currentName : nameToClassLookup.keySet()) {
w.write(" UIBuilder.registerCustomComponent(\"" + currentName + "\", " + nameToClassLookup.get(currentName) + ".class);\n");
}
w.write(" if(loadTheme) {\n");
w.write(" if(res == null) {\n");
w.write(" try {\n");
w.write(" res = Resources.openLayered(resPath);\n");
w.write(" } catch(java.io.IOException err) { err.printStackTrace(); }\n");
w.write(" }\n");
w.write(" initTheme(res);\n");
w.write(" }\n");
w.write(" return createContainer(resPath, \"" + uiResourceName + "\");\n");
w.write(" }\n\n");
w.write(" protected void initTheme(Resources res) {\n");
w.write(" String[] themes = res.getThemeResourceNames();\n");
w.write(" if(themes != null && themes.length > 0) {\n");
w.write(" UIManager.getInstance().setThemeProps(res.getTheme(themes[0]));\n");
w.write(" }\n");
w.write(" }\n\n");
w.write(" public " + className + "() {\n");
w.write(" }\n\n");
w.write(" public " + className + "(String resPath) {\n");
w.write(" this(null, resPath, true);\n");
w.write(" }\n\n");
w.write(" public " + className + "(Resources res) {\n");
w.write(" this(res, null, true);\n");
w.write(" }\n\n");
w.write(" public " + className + "(String resPath, boolean loadTheme) {\n");
w.write(" this(null, resPath, loadTheme);\n");
w.write(" }\n\n");
w.write(" public " + className + "(Resources res, boolean loadTheme) {\n");
w.write(" this(res, null, loadTheme);\n");
w.write(" }\n\n");
for (String componentName : allComponents.keySet()) {
String componentType = allComponents.get(componentName);
String methodName = " find" + normalizeFormName(componentName);
// exists without a space might trigger this situation and thus code that won't compile
if (!createdMethodNames.contains(methodName)) {
if (componentType.equals("com.codename1.ui.Form") || componentType.equals("com.codename1.ui.Dialog")) {
continue;
}
createdMethodNames.add(methodName);
w.write(" public " + componentType + methodName + "(Component root) {\n");
w.write(" return (" + componentType + ")" + "findByName(\"" + componentName + "\", root);\n");
w.write(" }\n\n");
w.write(" public " + componentType + methodName + "() {\n");
w.write(" " + componentType + " cmp = (" + componentType + ")" + "findByName(\"" + componentName + "\", Display.getInstance().getCurrent());\n");
w.write(" if(cmp == null && aboutToShowThisContainer != null) {\n");
w.write(" cmp = (" + componentType + ")" + "findByName(\"" + componentName + "\", aboutToShowThisContainer);\n");
w.write(" }\n");
w.write(" return cmp;\n");
w.write(" }\n\n");
}
}
if (commandMap.size() > 0) {
for (String key : commandMap.keySet()) {
w.write(" public static final int COMMAND_" + key + " = " + commandMap.get(key) + ";\n");
}
w.write("\n");
StringBuilder methodSwitch = new StringBuilder(" protected void processCommand(ActionEvent ev, Command cmd) {\n switch(cmd.getId()) {\n");
for (String key : commandMap.keySet()) {
String camelCase = "on" + key;
boolean isAbstract = unhandledCommands.contains(commandMap.get(key));
if (isAbstract) {
w.write(" protected abstract void ");
w.write(camelCase);
w.write("();\n\n");
} else {
w.write(" protected boolean ");
w.write(camelCase);
w.write("() {\n return false;\n }\n\n");
}
methodSwitch.append(" case COMMAND_");
methodSwitch.append(key);
methodSwitch.append(":\n");
methodSwitch.append(" ");
if (isAbstract) {
methodSwitch.append(camelCase);
methodSwitch.append("();\n break;\n\n");
} else {
methodSwitch.append("if(");
methodSwitch.append(camelCase);
methodSwitch.append("()) {\n ev.consume();\n return;\n }\n break;\n\n");
}
}
methodSwitch.append(" }\n if(ev.getComponent() != null) {\n handleComponentAction(ev.getComponent(), ev);\n }\n }\n\n");
w.write(methodSwitch.toString());
}
writeFormCallbackCode(w, " protected void exitForm(Form f) {\n", "f.getName()", "exit", "f", "Form f");
writeFormCallbackCode(w, " protected void beforeShow(Form f) {\n aboutToShowThisContainer = f;\n", "f.getName()", "before", "f", "Form f");
writeFormCallbackCode(w, " protected void beforeShowContainer(Container c) {\n aboutToShowThisContainer = c;\n", "c.getName()", "beforeContainer", "c", "Container c");
writeFormCallbackCode(w, " protected void postShow(Form f) {\n", "f.getName()", "post", "f", "Form f");
writeFormCallbackCode(w, " protected void postShowContainer(Container c) {\n", "c.getName()", "postContainer", "c", "Container c");
writeFormCallbackCode(w, " protected void onCreateRoot(String rootName) {\n", "rootName", "onCreate", "", "");
writeFormCallbackCode(w, " protected Hashtable getFormState(Form f) {\n Hashtable h = super.getFormState(f);\n", "f.getName()", "getState", "f, h", "Form f, Hashtable h", "return h;");
writeFormCallbackCode(w, " protected void setFormState(Form f, Hashtable state) {\n super.setFormState(f, state);\n", "f.getName()", "setState", "f, state", "Form f, Hashtable state");
List<String> listComponents = new ArrayList<String>();
for (String currentName : allComponents.keySet()) {
String value = allComponents.get(currentName);
if (value.equals("com.codename1.ui.List") || value.equals("com.codename1.ui.ComboBox") || value.equals("com.codename1.ui.list.MultiList") || value.equals("com.codename1.ui.Calendar")) {
listComponents.add(currentName);
}
}
List<String> containerListComponents = new ArrayList<String>();
for (String currentName : allComponents.keySet()) {
String value = allComponents.get(currentName);
if (value.equals("com.codename1.ui.list.ContainerList")) {
containerListComponents.add(currentName);
}
}
if (listComponents.size() > 0) {
w.write(" protected boolean setListModel(List cmp) {\n");
w.write(" String listName = cmp.getName();\n");
for (String listName : listComponents) {
w.write(" if(\"");
w.write(listName);
w.write("\".equals(listName)) {\n");
w.write(" return initListModel");
w.write(normalizeFormName(listName));
w.write("(cmp);\n }\n");
}
w.write(" return super.setListModel(cmp);\n }\n\n");
for (String listName : listComponents) {
w.write(" protected boolean initListModel");
w.write(normalizeFormName(listName));
w.write("(List cmp) {\n");
w.write(" return false;\n }\n\n");
}
}
if (containerListComponents.size() > 0) {
w.write(" protected boolean setListModel(com.codename1.ui.list.ContainerList cmp) {\n");
w.write(" String listName = cmp.getName();\n");
for (String listName : containerListComponents) {
w.write(" if(\"");
w.write(listName);
w.write("\".equals(listName)) {\n");
w.write(" return initListModel");
w.write(normalizeFormName(listName));
w.write("(cmp);\n }\n");
}
w.write(" return super.setListModel(cmp);\n }\n\n");
for (String listName : containerListComponents) {
w.write(" protected boolean initListModel");
w.write(normalizeFormName(listName));
w.write("(com.codename1.ui.list.ContainerList cmp) {\n");
w.write(" return false;\n }\n\n");
}
}
if (actionComponents.size() > 0) {
Object lastFormName = null;
StringBuilder methods = new StringBuilder();
w.write(" protected void handleComponentAction(Component c, ActionEvent event) {\n");
w.write(" Container rootContainerAncestor = getRootAncestor(c);\n");
w.write(" if(rootContainerAncestor == null) return;\n");
w.write(" String rootContainerName = rootContainerAncestor.getName();\n");
w.write(" Container leadParentContainer = c.getParent().getLeadParent();\n");
w.write(" if(leadParentContainer != null && leadParentContainer.getClass() != Container.class) {\n");
w.write(" c = c.getParent().getLeadParent();\n");
w.write(" }\n");
w.write(" if(rootContainerName == null) return;\n");
for (String[] currentCmp : actionComponents) {
if (lastFormName != currentCmp[1]) {
if (lastFormName != null) {
w.write(" }\n");
}
w.write(" if(rootContainerName.equals(\"");
w.write(currentCmp[1]);
w.write("\")) {\n");
lastFormName = currentCmp[1];
}
w.write(" if(\"");
w.write(currentCmp[0]);
w.write("\".equals(c.getName())) {\n");
String methodName = "on" + normalizeFormName(currentCmp[1]) + "_" + normalizeFormName(currentCmp[0]) + "Action";
w.write(" ");
w.write(methodName);
w.write("(c, event);\n");
w.write(" return;\n");
w.write(" }\n");
methods.append(" protected void ");
methods.append(methodName);
methods.append("(Component c, ActionEvent event) {\n }\n\n");
}
w.write(" }\n }\n\n");
w.write(methods.toString());
}
w.write("}\n");
w.close();
} catch (IOException ioErr) {
ioErr.printStackTrace();
JOptionPane.showMessageDialog(errorParent, "IO Error: " + ioErr, "IO Error", JOptionPane.ERROR_MESSAGE);
}
return packageString;
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class ResourceEditorView method duplicateItemActionPerformed.
// GEN-LAST:event_deleteUnusedImagesActionPerformed
private void duplicateItemActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_duplicateItemActionPerformed
if (selectedResource != null && loadedResources.containsResource(selectedResource)) {
Box rename = new Box(BoxLayout.X_AXIS);
rename.add(new JLabel("New Name: "));
JTextField field = new JTextField(selectedResource, 20);
rename.add(Box.createHorizontalStrut(3));
rename.add(field);
int result = JOptionPane.showConfirmDialog(mainPanel, rename, "Duplicate", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
String val = field.getText();
if (loadedResources.containsResource(val)) {
JOptionPane.showMessageDialog(mainPanel, "An Element By This Name Already Exists", "Rename", JOptionPane.ERROR_MESSAGE);
duplicateItemActionPerformed(evt);
return;
}
try {
// this effectively creates a new instance of the object
ByteArrayOutputStream bo = new ByteArrayOutputStream();
boolean m = loadedResources.isModified();
loadedResources.save(bo);
if (m) {
loadedResources.setModified();
}
bo.close();
EditableResources r = new EditableResources();
r.openFile(new ByteArrayInputStream(bo.toByteArray()));
loadedResources.addResourceObjectDuplicate(selectedResource, val, r.getResourceObject(selectedResource));
setSelectedResource(val);
} catch (IOException err) {
err.printStackTrace();
}
}
} else {
JOptionPane.showMessageDialog(mainPanel, "An Element Must Be Selected", "Rename", JOptionPane.ERROR_MESSAGE);
}
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class ResourceEditorView method imageSizesActionPerformed.
// GEN-LAST:event_pulsateEffectActionPerformed
private void imageSizesActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_imageSizesActionPerformed
class ImageSize {
String name;
int size;
}
int total = 0;
Vector images = new Vector();
for (String imageName : loadedResources.getImageResourceNames()) {
com.codename1.ui.Image img = loadedResources.getImage(imageName);
ImageSize size = new ImageSize();
size.name = imageName;
Object o = loadedResources.getResourceObject(imageName);
// special case for multi image which can be all of the internal images...
if (o instanceof EditableResources.MultiImage) {
for (Object c : ((EditableResources.MultiImage) o).getInternalImages()) {
size.size += ((com.codename1.ui.EncodedImage) c).getImageData().length;
}
images.add(size);
} else {
if (img instanceof com.codename1.ui.EncodedImage) {
size.size = ((com.codename1.ui.EncodedImage) img).getImageData().length;
images.add(size);
} else {
if (img.isSVG()) {
SVG s = (SVG) img.getSVGDocument();
size.size = s.getSvgData().length;
images.add(size);
}
}
}
total += size.size;
}
Collections.sort(images, new Comparator() {
public int compare(Object o1, Object o2) {
ImageSize i1 = (ImageSize) o1;
ImageSize i2 = (ImageSize) o2;
return i2.size - i1.size;
}
});
JPanel p = new JPanel(new java.awt.BorderLayout());
JList list = new JList(images);
p.add(java.awt.BorderLayout.NORTH, new JLabel("Total " + (total / 1024) + "kb in " + loadedResources.getImageResourceNames().length + " images"));
p.add(java.awt.BorderLayout.CENTER, new JScrollPane(list));
list.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
ImageSize s = (ImageSize) value;
value = s.name + " " + (s.size / 1024) + "kb (" + s.size + "b)";
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
JOptionPane.showMessageDialog(mainPanel, p, "Sizes", JOptionPane.PLAIN_MESSAGE);
}
Aggregations