use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.
the class ComponentTreeInspector method editStyle.
private void editStyle() {
File cn1dir = new File(System.getProperty("user.home"), ".codenameone");
if (!cn1dir.exists()) {
JOptionPane.showMessageDialog(this, "Please open the designer once by opening the theme.res file", "Error Opening Designer", JOptionPane.ERROR_MESSAGE);
return;
}
File resourceEditor = new File(cn1dir, "designer_1.jar");
if (!resourceEditor.exists()) {
resourceEditor = new File(cn1dir, "designer.jar");
}
if (!resourceEditor.exists()) {
JOptionPane.showMessageDialog(this, "Please open the designer once by opening the theme.res file", "Error Opening Designer", JOptionPane.ERROR_MESSAGE);
return;
}
File javaBin = new File(System.getProperty("java.home") + File.separator + "bin" + File.separator + "java.exe");
if (!javaBin.exists()) {
javaBin = new File(System.getProperty("java.home") + File.separator + "bin" + File.separator + "java");
}
final File javaExe = javaBin;
final File resourceEditorFinal = resourceEditor;
final String themeFile = themePaths.get(themes.getSelectedIndex());
if (themeFile.endsWith(".css.res")) {
File srcDir = new File(themeFile).getParentFile();
File projectDir = srcDir.getParentFile();
File cssDir = new File(projectDir, "css");
String cssThemeFileName = new File(themeFile).getName();
int lastDot = cssThemeFileName.lastIndexOf(".");
if (lastDot >= 0) {
cssThemeFileName = cssThemeFileName.substring(0, lastDot);
}
File cssThemeFile = new File(cssDir, cssThemeFileName);
System.out.println("Trying to open " + cssThemeFile);
if (cssThemeFile.exists()) {
try {
Desktop.getDesktop().edit(cssThemeFile);
} catch (Throwable t) {
t.printStackTrace();
}
return;
}
}
final String themeName = themeNames.get(themes.getSelectedIndex());
final String uiid = componentUIID.getText();
new Thread() {
@Override
public void run() {
try {
ProcessBuilder pb = new ProcessBuilder(javaExe.getAbsolutePath(), "-jar", resourceEditorFinal.getAbsolutePath(), "-style", themeFile, uiid, themeName).inheritIO();
Process proc = pb.start();
proc.waitFor();
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
try {
Resources res = Resources.open(new FileInputStream(themeFile));
UIManager.getInstance().addThemeProps(res.getTheme(themeName));
Display.getInstance().getCurrent().refreshTheme();
Display.getInstance().getCurrent().revalidate();
} catch (Exception err) {
err.printStackTrace();
}
}
});
} catch (Exception err) {
err.printStackTrace();
}
}
}.start();
}
use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.
the class GenericListCellRenderer method updateModelValues.
private Object updateModelValues(Map h, String currentName, Component[] entries, int iter, Object val) {
String uiid = (String) h.get(currentName + "_uiid");
if (uiid != null) {
entries[iter].setUIID(uiid);
}
if (currentName.endsWith("_URLImage")) {
URLImage img = (URLImage) h.get(currentName + "Actual");
if (img != null) {
val = img;
} else {
String name = (String) h.get(currentName + "Name");
if (name == null) {
name = val.toString();
name = name.substring(name.lastIndexOf('/'));
}
val = URLImage.createToStorage(placeholders.get(currentName), name, val.toString(), adapter);
h.put(currentName + "Actual", val);
}
}
return val;
}
use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.
the class CSSBorderTest method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Hi World", BoxLayout.y());
Label lineTest = new Label("1px solid #ff0000");
lineTest.getStyle().setBorder(new CSSBorder().backgroundColor("#00ff00").borderColor("#ff0000").borderWidth("1pt").borderStyle("solid").borderRadius("2mm"));
hi.add(lineTest);
lineTest = new Label("1px solid #ff0000");
lineTest.getStyle().setBorder(new CSSBorder().backgroundColor("#00ff00").borderColor("#ff0000").borderWidth("1pt 5pt 1px 5pt").borderStyle("solid").borderRadius("2mm"));
hi.add(lineTest);
lineTest = new Label("1px solid #ff0000");
lineTest.getStyle().setBorder(new CSSBorder().backgroundColor("#00ff00").borderColor("#ff0000").borderWidth("1pt").borderStyle("dashed").borderRadius("2mm"));
hi.add(lineTest);
lineTest = new Label("1px solid #ff0000");
CSSBorder border = new CSSBorder().backgroundColor("#00ff00").borderColor("#ff0000").borderWidth("1pt").borderStyle("dashed").borderRadius("2mm");
border = new CSSBorder(border.toCSSString());
lineTest.getStyle().setBorder(border);
hi.add(lineTest);
Container cnt = new Container();
cnt.getStyle().setBorder(new CSSBorder(theme).borderImage(theme.getImage("dashbg_landscape.png"), 0.4));
cnt.add(new Label("Setting CSS 9-Piece border manually"));
hi.add(cnt);
cnt = new Container();
cnt.setUIID("NinePiece");
cnt.add(new Label("9-piece border with UIID"));
hi.add(cnt);
cnt = new Container();
cnt.setUIID("BorderRadiusTopLeft");
cnt.add(new Label("Border Radius Top Left"));
hi.add(cnt);
hi.show();
}
use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.
the class AccordionSample method setupOpenCloseArrowStyles.
/**
* A sample of how to customize the style of the Accordion open/close arrows. In this case
* we are adjusting the padding at runtime so that the arrow is aligned with the edge of the
* longest header label, but with a small amount of padding.
* @param acc
*/
private void setupOpenCloseArrowStyles(Accordion acc) {
// Load the OpenCloseIconUIID Style. This is the UIID that is used to style the open/close arrows
// of the Accordion component.
Style openCloseIconStyle = UIManager.getInstance().getComponentStyle(acc.getOpenCloseIconUIID());
// Set the margin to use pixels.
openCloseIconStyle.setMarginUnit(Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS);
// Now figure out how wide the accordion labels are going to be.
String[] labels = new String[] { "Section 1", "Section 2", "Section 3 (Custom)" };
int maxLabelWidth = 0;
for (String label : labels) {
Font font = UIManager.getInstance().getComponentStyle(acc.getHeaderUIID()).getFont();
maxLabelWidth = Math.max(maxLabelWidth, font.stringWidth(label));
}
System.out.println("MaxLabelWidth = " + maxLabelWidth);
// Set the "Rigth" padding to be the screen width, less our label widths, and some constant padding.
int rightPadding = CN.getDisplayWidth() - maxLabelWidth - CN.convertToPixels(25);
System.out.println("Padding: " + rightPadding);
openCloseIconStyle.setPadding(RIGHT, rightPadding);
openCloseIconStyle.setFgColor(0x0);
String customUIID = "PaddedOpenCloseIcon" + (CN.isPortrait() ? "Portrait" : "Landscape");
String oldCustomUIID = "PaddedOpenCloseIcon" + (CN.isPortrait() ? "Landscape" : "Portrait");
// Now we install our modified style into the UIManager so that it can be referenced by UIID.
UIManager.getInstance().setComponentStyle(customUIID, openCloseIconStyle);
// Now specify that the Accordion should use this newly installed UIID for the open/close arrows.
acc.setOpenCloseIconUIID(customUIID);
// In the case of screen orientation changes, we will need to update the old UIIDs to the new UIID.
$(oldCustomUIID, acc).setUIID(customUIID);
if (acc.getComponentForm() != null) {
acc.revalidateWithAnimationSafety();
}
}
use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.
the class Tabs method insertTab.
/**
* Inserts a <code>component</code>, at <code>index</code>,
* represented by a <code>button</code>
* Uses java.util.Vector internally, see <code>insertElementAt</code>
* for details of insertion conventions.
* The Button styling will be associated with "Tab" UIID.
*
* @param tab represents the tab on top
* @param component The component to be displayed when this tab is clicked.
* @param index the position to insert this new tab
*
* @see #addTab
* @see #removeTabAt
* @deprecated should use radio button as an argument
*/
public void insertTab(Component tab, Component component, int index) {
checkIndex(index);
if (component == null) {
return;
}
final Component b = tab;
if (tabUIID != null) {
b.setUIID(tabUIID);
}
b.addFocusListener(focusListener);
bindTabActionListener(b, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (selectedTab != null) {
if (tabUIID != null) {
selectedTab.setUIID(tabUIID);
}
if (!animateTabSelection) {
selectedTab.setShouldCalcPreferredSize(true);
selectedTab.repaint();
}
int previousSelectedIndex = tabsContainer.getComponentIndex(selectedTab);
// this might happen if a tab was removed
if (previousSelectedIndex != -1) {
Component previousContent = contentPane.getComponentAt(previousSelectedIndex);
if (previousContent instanceof Container) {
((Container) previousContent).setBlockFocus(true);
}
}
}
if (active != tabsContainer.getComponentIndex(b)) {
active = tabsContainer.getComponentIndex(b);
Component content = contentPane.getComponentAt(active);
if (content instanceof Container) {
((Container) content).setBlockFocus(false);
}
setSelectedIndex(active, animateTabSelection);
initTabsFocus();
selectedTab = b;
if (!animateTabSelection) {
selectedTab.setShouldCalcPreferredSize(true);
tabsContainer.revalidateLater();
}
tabsContainer.scrollComponentToVisible(selectedTab);
}
}
});
if (component instanceof Container) {
((Container) component).setBlockFocus(true);
}
tabsContainer.addComponent(index, b);
contentPane.addComponent(index, component);
setTabsLayout(tabPlacement);
if (tabsContainer.getComponentCount() == 1) {
selectedTab = tabsContainer.getComponentAt(0);
if (component instanceof Container) {
((Container) component).setBlockFocus(false);
}
initTabsFocus();
}
checkTabsCanBeSeen();
}
Aggregations