use of com.codename1.util.Wrapper in project CodenameOne by codenameone.
the class MultiButton method setHorizontalLayout.
/**
* Indicates the first two labels should be side by side
*
* @param b true to place the first two labels side by side
*/
public void setHorizontalLayout(boolean b) {
if (isHorizontalLayout() != b) {
if (isHorizontalLayout()) {
secondRow.getParent().getParent().removeComponent(secondRow.getParent());
}
secondRow.getParent().removeComponent(secondRow);
if (b) {
Container wrapper = new Container();
Container c = firstRow.getParent();
wrapper.addComponent(secondRow);
c.addComponent(BorderLayout.EAST, wrapper);
} else {
Container c = thirdRow.getParent();
c.addComponent(0, secondRow);
}
}
}
use of com.codename1.util.Wrapper in project CodenameOne by codenameone.
the class CodenameOneImplementation method paintDirty.
/**
* Invoked by the EDT to paint the dirty regions
*/
public void paintDirty() {
int size = 0;
synchronized (displayLock) {
size = paintQueueFill;
Animation[] array = paintQueue;
paintQueue = paintQueueTemp;
paintQueueTemp = array;
paintQueueFill = 0;
}
if (size > 0) {
Graphics wrapper = getCodenameOneGraphics();
int dwidth = getDisplayWidth();
int dheight = getDisplayHeight();
int topX = dwidth;
int topY = dheight;
int bottomX = 0;
int bottomY = 0;
for (int iter = 0; iter < size; iter++) {
Animation ani = paintQueueTemp[iter];
// might happen due to paint queue removal
if (ani == null) {
continue;
}
paintQueueTemp[iter] = null;
wrapper.translate(-wrapper.getTranslateX(), -wrapper.getTranslateY());
wrapper.resetAffine();
wrapper.setClip(0, 0, dwidth, dheight);
if (ani instanceof Component) {
Component cmp = (Component) ani;
Rectangle dirty = cmp.getDirtyRegion();
if (dirty != null) {
Dimension d = dirty.getSize();
wrapper.setClip(dirty.getX(), dirty.getY(), d.getWidth(), d.getHeight());
cmp.setDirtyRegion(null);
}
cmp.paintComponent(wrapper);
getPaintableBounds(cmp, paintDirtyTmpRect);
int cmpAbsX = paintDirtyTmpRect.getX();
topX = Math.min(cmpAbsX, topX);
bottomX = Math.max(cmpAbsX + paintDirtyTmpRect.getWidth(), bottomX);
int cmpAbsY = paintDirtyTmpRect.getY();
topY = Math.min(cmpAbsY, topY);
bottomY = Math.max(cmpAbsY + paintDirtyTmpRect.getHeight(), bottomY);
} else {
bottomX = dwidth;
bottomY = dheight;
topX = 0;
topY = 0;
ani.paint(wrapper);
}
}
paintOverlay(wrapper);
// Log.p("Flushing graphics : "+topX+","+topY+","+bottomX+","+bottomY);
flushGraphics(topX, topY, bottomX - topX, bottomY - topY);
}
}
use of com.codename1.util.Wrapper in project CodenameOne by codenameone.
the class SpanMultiButton method setHorizontalLayout.
/**
* Indicates the first two labels should be side by side
*
* @param b true to place the first two labels side by side
*/
public void setHorizontalLayout(boolean b) {
if (isHorizontalLayout() != b) {
if (isHorizontalLayout()) {
secondRow.getParent().getParent().removeComponent(secondRow.getParent());
}
secondRow.getParent().removeComponent(secondRow);
if (b) {
Container wrapper = new Container();
Container c = firstRow.getParent();
wrapper.addComponent(secondRow);
c.addComponent(BorderLayout.EAST, wrapper);
} else {
Container c = thirdRow.getParent();
c.addComponent(0, secondRow);
}
}
}
use of com.codename1.util.Wrapper 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")) {
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 resourceFile = new File(args[1]);
File imageFile = new File(fileName);
if (!imageFile.exists()) {
System.out.println("File not found: " + imageFile.getAbsolutePath());
System.exit(1);
return;
}
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
CSSImageImporter cssImporter = new CSSImageImporter(resourceFile, imageFile, 0);
if (cssImporter.checkIfCSSProject()) {
// CSS projects can't just import images into the res file. They need to
// be added to the CSS file, and then have the resource file regenerated.
cssImporter.doImportAndExit();
System.exit(0);
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();
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")) {
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;
int sourceDpi = 0;
switch(dpi.toLowerCase()) {
case "high":
dpiInt = 3;
sourceDpi = 240;
break;
case "veryhigh":
dpiInt = 4;
sourceDpi = 320;
break;
case "hd":
dpiInt = 5;
sourceDpi = 480;
break;
case "560":
dpiInt = 6;
sourceDpi = 480;
break;
case "2hd":
dpiInt = 7;
sourceDpi = 640;
break;
case "4k":
dpiInt = 8;
sourceDpi = 720;
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;
}
File resourceFile = new File(args[1]);
java.awt.Container cnt = new java.awt.Container();
com.codename1.ui.Display.init(cnt);
CSSImageImporter cssImporter = new CSSImageImporter(resourceFile, imageFile, sourceDpi);
if (cssImporter.checkIfCSSProject()) {
cssImporter.doImportAndExit();
System.exit(0);
return;
}
boolean isXMLEnabled = Preferences.userNodeForPackage(ResourceEditorView.class).getBoolean("XMLFileMode", true);
EditableResources.setXMLEnabled(isXMLEnabled);
EditableResources res = new EditableResources();
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;
}
if (args[0].equalsIgnoreCase("-sync-xml")) {
try {
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();
} finally {
System.exit(0);
}
return;
}
if (args.length >= 2 && args[0].equalsIgnoreCase("-css")) {
List<String> cssArgs = new ArrayList<String>(Arrays.asList(args));
cssArgs.remove(0);
CN1CSSCLI.main(cssArgs.toArray(new String[cssArgs.size()]));
return;
}
}
JavaSEPortWithSVGSupport.setDefaultInitTarget(new JPanel());
Display.init(null);
launch(ResourceEditorApp.class, args);
}
use of com.codename1.util.Wrapper in project CodenameOne by codenameone.
the class RADActionBoundUIIDSample method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Toggled Actions Sample", new BorderLayout());
// Create a tag fo the online status property.
Tag TAG_ONLINE = new Tag("online");
// Create an action that will indicte the online/offline status
ActionNode status = UI.action(// on state of TAG_ONLINE property.
UI.label(person -> {
if (person.isFalsey(TAG_ONLINE)) {
return "Offline";
} else {
return "Online";
}
}), // Depending on state of TAG_ONLINE property
UI.uiid(person -> {
if (person.isFalsey(TAG_ONLINE)) {
return "LoggedOutStatusButton";
} else {
return "LoggedInStatusButton";
}
}), // Icon for the action
UI.icon(FontImage.MATERIAL_PERSON), // define it to always return true so action is always visible.
UI.condition(person -> {
return true;
}));
// A User entity we use for the models.
class User extends Entity {
}
entityTypeBuilder(User.class).Boolean(TAG_ONLINE).string(Thing.name).factory(cls -> {
return new User();
}).build();
// Create an entity list that will hold several users.
EntityList el = new EntityList();
for (int i = 0; i < 200; i++) {
User u = new User();
u.set(Thing.name, "User " + i);
u.set(TAG_ONLINE, i % 2 == 0);
el.add(u);
}
// The ListNode is a wrapper that will be passed to our View so that
// they can access our action.
ListNode node = new ListNode(// for each row.
UI.actions(ProfileListView.ACCOUNT_LIST_ROW_ACTIONS, status));
// Use a ProfileListView to display all of the users
// https://shannah.github.io/CodeRAD/javadoc/com/codename1/rad/ui/entityviews/ProfileListView.html
ProfileListView plv = new ProfileListView(el, node, 8);
plv.setScrollableY(true);
// In order to respond to events raised by the action, our view needs to be wrapped
// in a controller. Normally our form would have a FormViewController so we could
// just use FormController, but this sample is compressed to be inside
// a single method here so we'll create a dedicated ViewController for the list
ViewController ctrl = new ViewController(null);
ctrl.setView(plv);
ctrl.addActionListener(status, evt -> {
// The action was pressed by the user
// Update the model's online status
User u = (User) evt.getEntity();
u.set(TAG_ONLINE, u.isFalsey(TAG_ONLINE));
// This will trigger a property change in the model which will update the view.
});
hi.add(CENTER, plv);
hi.show();
}
Aggregations