use of com.codename1.rad.models.Property.Name 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);
}
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class UserInterfaceEditor method addComponentToContainer.
private void addComponentToContainer(com.codename1.ui.Component c, String name) {
if (c instanceof com.codename1.ui.Label || c instanceof com.codename1.ui.TextArea) {
setPropertyModified(c, PROPERTY_TEXT);
}
c.putClientProperty(TYPE_KEY, name);
c.setName(findUniqueName(name));
com.codename1.ui.Container destContainer = containerInstance;
if (componentHierarchy.getSelectionPath() != null) {
com.codename1.ui.Component cmp = (com.codename1.ui.Component) componentHierarchy.getSelectionPath().getLastPathComponent();
if (isActualContainer(cmp)) {
destContainer = (com.codename1.ui.Container) cmp;
} else {
destContainer = cmp.getParent();
}
}
if (destContainer instanceof com.codename1.ui.Tabs) {
((com.codename1.ui.Tabs) destContainer).addTab("Tab", c);
} else {
if (destContainer.getLayout() instanceof com.codename1.ui.layouts.BorderLayout) {
destContainer.addComponent(findAvailableSpotInBorderLayout(destContainer), c);
} else {
destContainer.addComponent(c);
}
}
containerInstance.revalidate();
destContainer.revalidate();
/*int[] index = new int[] {componentHierarchy.getModel().getIndexOfChild(c.getParent(), c)};
Object[] children = new Object[] {c};
c = c.getParent();
Object[] path = pathToComponent(c);
if(path != null && path.length > 0) {
((ComponentHierarchyModel)componentHierarchy.getModel()).fireTreeNodesInserted(
new TreeModelEvent(componentHierarchy.getModel(), new TreePath(path), index, children));
uiPreview.repaint();
saveUI();
}*/
((ComponentHierarchyModel) componentHierarchy.getModel()).fireTreeStructureChanged(new TreeModelEvent(componentHierarchy.getModel(), new TreePath(componentHierarchy.getModel().getRoot())));
uiPreview.repaint();
saveUI();
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class EditableResources method setMultiImage.
public void setMultiImage(final String name, final MultiImage value) {
// we need to replace the image in all the themes...
final Object oldValue = getResourceObject(name);
pushUndoable(new UndoableEdit() {
@Override
protected String performAction() {
replaceThemeValue(oldValue, value);
setResource(name, MAGIC_IMAGE, value);
return name;
}
@Override
protected String performUndo() {
replaceThemeValue(value, value);
setResource(name, MAGIC_IMAGE, oldValue);
return name;
}
});
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class EditableResources method setSVGDPIs.
public void setSVGDPIs(final String name, final int[] dpi, final int[] widths, final int[] heights) {
final SVG sv = (SVG) getImage(name).getSVGDocument();
final int[] currentDPIs = sv.getDpis();
final int[] currentWidths = sv.getWidthForDPI();
final int[] currentHeights = sv.getHeightForDPI();
pushUndoable(new UndoableEdit() {
@Override
protected String performAction() {
sv.setDpis(dpi);
sv.setWidthForDPI(widths);
sv.setHeightForDPI(heights);
return name;
}
@Override
protected String performUndo() {
sv.setDpis(currentDPIs);
sv.setWidthForDPI(currentWidths);
sv.setHeightForDPI(currentHeights);
return name;
}
});
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class EditableResources method setImage.
public void setImage(final String name, final com.codename1.ui.Image value) {
if (overrideResource != null) {
overrideResource.setImage(name, value);
return;
}
// we need to replace the image in all the themes...
final com.codename1.ui.Image oldValue = getImage(name);
byte type;
if (value instanceof Timeline) {
type = MAGIC_TIMELINE;
} else {
type = MAGIC_IMAGE;
}
final byte finalType = type;
pushUndoable(new UndoableEdit() {
@Override
protected String performAction() {
replaceThemeValue(oldValue, value);
setResource(name, finalType, value);
return name;
}
@Override
protected String performUndo() {
replaceThemeValue(value, oldValue);
setResource(name, finalType, oldValue);
return name;
}
});
}
Aggregations