use of com.codename1.io in project CodeRAD by shannah.
the class FieldEditorFormController method onStartController.
protected void onStartController() {
super.onStartController();
Form f = new Form(new BorderLayout());
f.getToolbar().hideToolbar();
Container titleBar = new Container(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
titleBar.setSafeArea(true);
titleBar.setUIID("TitleArea");
if (hasBackCommand()) {
Button back = new Button();
FontImage.setIcon(back, FontImage.MATERIAL_ARROW_BACK_IOS, -1);
titleBar.add(BorderLayout.WEST, back);
back.addActionListener(evt -> {
evt.consume();
ActionSupport.dispatchEvent(new FormController.FormBackEvent(back));
});
}
AppSectionController sectionCtl = getSectionController();
if (sectionCtl != null) {
Button done = new Button("Done");
done.addActionListener(evt -> {
evt.consume();
ActionSupport.dispatchEvent(new AppSectionController.ExitSectionEvent(done));
});
titleBar.add(BorderLayout.EAST, done);
}
Label l = field.getLabel(entity.getEntity().getEntityType());
if (l != null) {
titleBar.add(BorderLayout.CENTER, new com.codename1.ui.Label(l.getValue(entity.getEntity()), "Title"));
}
f.add(BorderLayout.NORTH, titleBar);
field.setAttributes(new LabelStyleAttribute(LabelStyle.None), new DescriptionStyleAttribute(DescriptionStyle.SpanLabel));
UI ui = new UI() {
{
form(columns(1), field, editable(true));
}
};
EntityEditor editor = new EntityEditor(entity, ui);
editor.setScrollableY(true);
f.add(BorderLayout.CENTER, editor);
setView(f);
}
use of com.codename1.io in project CodeRAD by shannah.
the class FormController method setView.
/**
* Overrides parent setView(). Delegates to {@link #setView(com.codename1.ui.Form) } if cmp is
* a form. Throws IllegalArgumentException otherwise.
* @param cmp
*/
public void setView(Component cmp) {
if (cmp == null) {
setView((Form) null);
return;
}
Form currView = getView();
if (currView != null) {
currView.removeShowListener(showListener());
}
if (cmp instanceof Form) {
((Form) cmp).addShowListener(showListener());
setView((Form) cmp);
} else {
Form f = new Form(new BorderLayout()) {
@Override
public void setTitle(String title) {
super.setTitle(title);
if (titleLbl != null) {
titleLbl.setText(title);
revalidateLater();
}
}
@Override
public void layoutContainer() {
super.layoutContainer();
if (true)
return;
int maxLeftX = 0;
ComponentSelector cmps = $(".left-inset", this);
for (Component c : cmps) {
if (!c.isVisible() || c.isHidden() || c.getWidth() == 1 || c.getHeight() == 0) {
continue;
}
Component wrap = $(c).parents(".left-edge").first().asComponent();
if (wrap == null) {
continue;
}
int thisLeftX = c.getAbsoluteX() + c.getStyle().getPaddingLeftNoRTL() - wrap.getAbsoluteX();
maxLeftX = Math.max(maxLeftX, thisLeftX);
}
for (Component c : cmps) {
if (!c.isVisible() || c.isHidden() || c.getWidth() == 1 || c.getHeight() == 0) {
continue;
}
Component wrap = $(c).parents(".left-edge").first().asComponent();
if (wrap == null) {
continue;
}
int absX = c.getAbsoluteX() + c.getStyle().getPaddingLeftNoRTL() - wrap.getAbsoluteX();
if (absX < maxLeftX) {
int marginLeft = c.getStyle().getMarginLeftNoRTL();
c.getAllStyles().setMarginUnitLeft(Style.UNIT_TYPE_PIXELS);
c.getAllStyles().setMarginLeft(marginLeft + maxLeftX - absX);
}
}
}
};
boolean hasTitle = !addTitleBar;
Component titleBarEast = null;
Component titleBarWest = null;
if (!hasTitle) {
for (Component c : $("*", cmp).add(cmp, true)) {
if (c instanceof CollapsibleHeaderContainer) {
hasTitle = true;
break;
}
if ("Title".equals(c)) {
hasTitle = true;
break;
}
if ("TitleBarEast".equalsIgnoreCase(c.getName())) {
titleBarEast = c;
} else if ("TitleBarWest".equalsIgnoreCase(c.getName())) {
titleBarWest = c;
}
}
}
if (titleBarEast != null)
titleBarEast.remove();
if (titleBarWest != null)
titleBarWest.remove();
f.addShowListener(showListener());
f.getToolbar().hideToolbar();
Container titleBar = new Container(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
titleBar.setSafeArea(true);
titleBar.setUIID("TitleArea");
if (hasBackCommand()) {
Button back = new Button();
FontImage.setIcon(back, FontImage.MATERIAL_ARROW_BACK_IOS, -1);
titleBarWest = titleBarWest == null ? back : BoxLayout.encloseX(back, titleBarWest);
// titleBar.add(BorderLayout.WEST, back);
back.addActionListener(evt -> {
evt.consume();
ActionSupport.dispatchEvent(new FormController.FormBackEvent(back));
});
}
AppSectionController sectionCtl = getSectionController();
if (sectionCtl != null) {
Button done = new Button("Done");
done.addActionListener(evt -> {
evt.consume();
ActionSupport.dispatchEvent(new AppSectionController.ExitSectionEvent(done));
});
titleBarEast = titleBarEast == null ? done : BoxLayout.encloseX(titleBarEast, done);
// titleBar.add(BorderLayout.EAST, done);
}
if (titleComponent != null) {
titleBar.add(BorderLayout.CENTER, titleComponent);
} else {
titleLbl = new Label();
titleLbl.setUIID("Title");
if (getTitle() != null) {
titleLbl.setText(getTitle());
}
titleBar.add(BorderLayout.CENTER, titleLbl);
}
if (titleBarEast != null)
titleBar.add(BorderLayout.EAST, titleBarEast);
if (titleBarWest != null)
titleBar.add(BorderLayout.WEST, titleBarWest);
if (!hasTitle)
f.add(BorderLayout.NORTH, titleBar);
f.add(BorderLayout.CENTER, decorateView(cmp));
f.revalidateLater();
setView(f);
}
}
use of com.codename1.io in project CodeRAD by shannah.
the class EntityListTableCellEditor method getTableCellEditorComponent.
@Override
public Component getTableCellEditorComponent(Table table, Object value, boolean isSelected, int row, int column) {
EntityListTableModel model = (EntityListTableModel) table.getModel();
FieldNode field = model.getColumnField(column);
Entity entity = model.getEntity(row);
if (entity == null) {
if (parent != null) {
return parent.getTableCellEditorComponent(table, value, isSelected, row, column);
} else {
return new com.codename1.ui.Label();
}
}
return viewFactory.createPropertyView(entity, field);
}
use of com.codename1.io 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.io 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);
}
Aggregations