use of com.codename1.ui.spinner.Picker in project CodenameOne by codenameone.
the class TestPicker method testTimePicker.
private void testTimePicker() {
Picker p = new Picker();
p.setType(Display.PICKER_TYPE_TIME);
}
use of com.codename1.ui.spinner.Picker in project CodenameOne by codenameone.
the class ThemeEditor method initMIDlet.
private void initMIDlet() {
JavaSEPortWithSVGSupport.setShowEDTWarnings(false);
JavaSEPortWithSVGSupport.setShowEDTViolationStacks(false);
// its a UI form
if (uiPreviewContent.getSelectedIndex() == uiPreviewContent.getModel().getSize() - 1) {
previewPanel.removeAll();
if (com.codename1.ui.Display.isInitialized()) {
com.codename1.ui.Display.deinitialize();
}
JavaSEPortWithSVGSupport.setDefaultInitTarget(previewPanel);
com.codename1.ui.Display.init(previewPanel);
previewPanel.getComponent(0).setBounds(0, 0, get(widthResoltution), get(heightResolution));
previewPanel.getComponent(0).setPreferredSize(new java.awt.Dimension(get(widthResoltution), get(heightResolution)));
PickMIDlet.startMIDlet(themeHash);
} else {
Preferences.userNodeForPackage(getClass()).put("uiPreviewContent", (String) uiPreviewContent.getSelectedItem());
Accessor.setTheme(themeHash);
if (com.codename1.ui.Display.isInitialized()) {
com.codename1.ui.Display.deinitialize();
}
previewPanel.removeAll();
com.codename1.ui.Display.init(previewPanel);
previewPanel.getComponent(0).setBounds(0, 0, get(widthResoltution), get(heightResolution));
previewPanel.getComponent(0).setPreferredSize(new java.awt.Dimension(get(widthResoltution), get(heightResolution)));
com.codename1.ui.util.UIBuilder.registerCustomComponent("Table", com.codename1.ui.table.Table.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("MediaPlayer", com.codename1.components.MediaPlayer.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("ContainerList", com.codename1.ui.list.ContainerList.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("ComponentGroup", com.codename1.ui.ComponentGroup.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("Tree", com.codename1.ui.tree.Tree.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("HTMLComponent", com.codename1.ui.html.HTMLComponent.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("RSSReader", com.codename1.components.RSSReader.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("FileTree", com.codename1.components.FileTree.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("WebBrowser", com.codename1.components.WebBrowser.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("NumericSpinner", com.codename1.ui.spinner.NumericSpinner.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("DateSpinner", com.codename1.ui.spinner.DateSpinner.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("TimeSpinner", com.codename1.ui.spinner.TimeSpinner.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("DateTimeSpinner", com.codename1.ui.spinner.DateTimeSpinner.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("GenericSpinner", com.codename1.ui.spinner.GenericSpinner.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("LikeButton", com.codename1.facebook.ui.LikeButton.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("InfiniteProgress", com.codename1.components.InfiniteProgress.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("MultiButton", com.codename1.components.MultiButton.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("SpanButton", com.codename1.components.SpanButton.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("SpanLabel", com.codename1.components.SpanLabel.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("Ads", com.codename1.components.Ads.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("MapComponent", com.codename1.maps.MapComponent.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("MultiList", com.codename1.ui.list.MultiList.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("ShareButton", com.codename1.components.ShareButton.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("OnOffSwitch", com.codename1.components.OnOffSwitch.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("ImageViewer", com.codename1.components.ImageViewer.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("AutoCompleteTextField", com.codename1.ui.AutoCompleteTextField.class);
com.codename1.ui.util.UIBuilder.registerCustomComponent("Picker", com.codename1.ui.spinner.Picker.class);
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
com.codename1.ui.util.UIBuilder builder = new com.codename1.ui.util.UIBuilder();
final com.codename1.ui.Container c = builder.createContainer(resources, (String) uiPreviewContent.getSelectedItem());
if (c instanceof com.codename1.ui.Form) {
if (c instanceof com.codename1.ui.Dialog) {
com.codename1.ui.animations.Transition t = ((com.codename1.ui.Dialog) c).getTransitionInAnimator();
((com.codename1.ui.Dialog) c).setTransitionInAnimator(com.codename1.ui.animations.CommonTransitions.createEmpty());
((com.codename1.ui.Dialog) c).showModeless();
((com.codename1.ui.Dialog) c).setTransitionInAnimator(t);
} else {
com.codename1.ui.animations.Transition t = ((com.codename1.ui.Form) c).getTransitionInAnimator();
((com.codename1.ui.Form) c).setTransitionInAnimator(com.codename1.ui.animations.CommonTransitions.createEmpty());
((com.codename1.ui.Form) c).show();
((com.codename1.ui.Form) c).setTransitionInAnimator(t);
}
} else {
com.codename1.ui.Form f = new Form();
f.setTransitionInAnimator(com.codename1.ui.animations.CommonTransitions.createEmpty());
f.setLayout(new com.codename1.ui.layouts.BorderLayout());
f.addComponent(com.codename1.ui.layouts.BorderLayout.CENTER, c);
f.show();
}
}
});
}
}
use of com.codename1.ui.spinner.Picker in project CodenameOne by codenameone.
the class JavaSEPort method createSkinsMenu.
private JMenu createSkinsMenu(final JFrame frm, final JMenu menu) throws MalformedURLException {
JMenu m;
if (menu == null) {
m = new JMenu("Skins");
m.setDoubleBuffered(true);
} else {
m = menu;
m.removeAll();
}
final JMenu skinMenu = m;
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
String skinNames = pref.get("skins", DEFAULT_SKINS);
if (skinNames != null) {
if (skinNames.length() < DEFAULT_SKINS.length()) {
skinNames = DEFAULT_SKINS;
}
ButtonGroup skinGroup = new ButtonGroup();
StringTokenizer tkn = new StringTokenizer(skinNames, ";");
while (tkn.hasMoreTokens()) {
final String current = tkn.nextToken();
String name = current;
if (current.contains(":")) {
try {
URL u = new URL(current);
File f = new File(u.getFile());
if (!f.exists()) {
continue;
}
name = f.getName();
} catch (Exception e) {
continue;
}
} else {
// remove the old builtin skins from the menu
if (current.startsWith("/") && !current.equals("/iphone3gs.skin")) {
continue;
}
}
String d = System.getProperty("dskin");
JRadioButtonMenuItem i = new JRadioButtonMenuItem(name, name.equals(pref.get("skin", d)));
i.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if (netMonitor != null) {
netMonitor.dispose();
netMonitor = null;
}
if (perfMonitor != null) {
perfMonitor.dispose();
perfMonitor = null;
}
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
pref.putBoolean("desktopSkin", false);
String mainClass = System.getProperty("MainClass");
if (mainClass != null) {
pref.put("skin", current);
deinitializeSync();
frm.dispose();
System.setProperty("reload.simulator", "true");
} else {
loadSkinFile(current, frm);
refreshSkin(frm);
}
}
});
skinGroup.add(i);
skinMenu.add(i);
}
}
JMenuItem dSkin = new JMenuItem("Desktop.skin");
dSkin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if (netMonitor != null) {
netMonitor.dispose();
netMonitor = null;
}
if (perfMonitor != null) {
perfMonitor.dispose();
perfMonitor = null;
}
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
pref.putBoolean("desktopSkin", true);
String mainClass = System.getProperty("MainClass");
if (mainClass != null) {
deinitializeSync();
frm.dispose();
System.setProperty("reload.simulator", "true");
}
}
});
skinMenu.addSeparator();
skinMenu.add(dSkin);
skinMenu.addSeparator();
JMenuItem more = new JMenuItem("More...");
skinMenu.add(more);
more.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final JDialog pleaseWait = new JDialog(frm, false);
pleaseWait.setLocationRelativeTo(frm);
pleaseWait.setTitle("Message");
pleaseWait.setLayout(new BorderLayout());
pleaseWait.add(new JLabel(" Please Wait... "), BorderLayout.CENTER);
pleaseWait.pack();
pleaseWait.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final JDialog d = new JDialog(frm, true);
d.setLocationRelativeTo(frm);
d.setTitle("Skins");
d.setLayout(new BorderLayout());
String userDir = System.getProperty("user.home");
final File skinDir = new File(userDir + "/.codenameone/");
if (!skinDir.exists()) {
skinDir.mkdir();
}
Vector data = new Vector();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
final Document[] doc = new Document[1];
try {
DocumentBuilder db = dbf.newDocumentBuilder();
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
InputStream is = openSkinsURL();
doc[0] = db.parse(is);
NodeList skins = doc[0].getElementsByTagName("Skin");
for (int i = 0; i < skins.getLength(); i++) {
Node skin = skins.item(i);
NamedNodeMap attr = skin.getAttributes();
String url = attr.getNamedItem("url").getNodeValue();
int ver = 0;
Node n = attr.getNamedItem("version");
if (n != null) {
ver = Integer.parseInt(n.getNodeValue());
}
boolean exists = new File(skinDir.getAbsolutePath() + url).exists();
if (!(exists) || Integer.parseInt(pref.get(url, "0")) < ver) {
Vector row = new Vector();
row.add(new Boolean(false));
row.add(new ImageIcon(new URL(defaultCodenameOneComProtocol + "://www.codenameone.com/OTA" + attr.getNamedItem("icon").getNodeValue())));
row.add(attr.getNamedItem("name").getNodeValue());
if (exists) {
row.add("Update");
} else {
row.add("New");
}
data.add(row);
}
}
} catch (Exception ex) {
Logger.getLogger(JavaSEPort.class.getName()).log(Level.SEVERE, null, ex);
}
if (data.size() == 0) {
pleaseWait.setVisible(false);
JOptionPane.showMessageDialog(frm, "No New Skins to Install");
return;
}
Vector cols = new Vector();
cols.add("Install");
cols.add("Icon");
cols.add("Name");
cols.add("");
final DefaultTableModel tableModel = new DefaultTableModel(data, cols) {
@Override
public boolean isCellEditable(int row, int column) {
return column == 0;
}
};
JTable skinsTable = new JTable(tableModel) {
@Override
public Class<?> getColumnClass(int column) {
if (column == 0) {
return Boolean.class;
}
if (column == 1) {
return Icon.class;
}
return super.getColumnClass(column);
}
};
skinsTable.setRowHeight(112);
skinsTable.getTableHeader().setReorderingAllowed(false);
d.add(new JScrollPane(skinsTable), BorderLayout.CENTER);
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
JButton download = new JButton("Download");
download.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final Vector toDowload = new Vector();
NodeList skins = doc[0].getElementsByTagName("Skin");
for (int i = 0; i < tableModel.getRowCount(); i++) {
if (((Boolean) tableModel.getValueAt(i, 0)).booleanValue()) {
Node skin;
for (int j = 0; j < skins.getLength(); j++) {
skin = skins.item(j);
NamedNodeMap attr = skin.getAttributes();
if (attr.getNamedItem("name").getNodeValue().equals(tableModel.getValueAt(i, 2))) {
String url = attr.getNamedItem("url").getNodeValue();
String[] data = new String[2];
data[0] = defaultCodenameOneComProtocol + "://www.codenameone.com/OTA" + url;
data[1] = attr.getNamedItem("version").getNodeValue();
toDowload.add(data);
break;
}
}
}
}
if (toDowload.size() > 0) {
final JDialog downloadMessage = new JDialog(d, true);
downloadMessage.setTitle("Downloading");
downloadMessage.setLayout(new FlowLayout());
downloadMessage.setLocationRelativeTo(d);
final JLabel details = new JLabel("<br><br>Details");
downloadMessage.add(details);
final JLabel progress = new JLabel("Progress<br><br>");
downloadMessage.add(progress);
new Thread() {
@Override
public void run() {
for (Iterator it = toDowload.iterator(); it.hasNext(); ) {
String[] data = (String[]) it.next();
String url = data[0];
details.setText(url.substring(url.lastIndexOf("/")));
details.repaint();
progress.setText("");
progress.repaint();
try {
File skin = downloadSkin(skinDir, url, data[1], progress);
if (skin.exists()) {
addSkinName(skin.toURI().toString());
}
} catch (Exception e) {
}
}
downloadMessage.setVisible(false);
d.setVisible(false);
try {
createSkinsMenu(frm, skinMenu);
} catch (MalformedURLException ex) {
Logger.getLogger(JavaSEPort.class.getName()).log(Level.SEVERE, null, ex);
}
}
}.start();
downloadMessage.pack();
downloadMessage.setSize(200, 70);
downloadMessage.setVisible(true);
} else {
JOptionPane.showMessageDialog(d, "Choose a Skin to Download");
}
}
});
p.add(download);
d.add(p, BorderLayout.SOUTH);
d.pack();
pleaseWait.dispose();
d.setVisible(true);
}
});
}
});
skinMenu.addSeparator();
JMenuItem addSkin = new JMenuItem("Add New...");
skinMenu.add(addSkin);
addSkin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
FileDialog picker = new FileDialog(frm, "Add Skin");
picker.setMode(FileDialog.LOAD);
picker.setFilenameFilter(new FilenameFilter() {
public boolean accept(File file, String string) {
return string.endsWith(".skin");
}
});
picker.setModal(true);
picker.setVisible(true);
String file = picker.getFile();
if (file != null) {
if (netMonitor != null) {
netMonitor.dispose();
netMonitor = null;
}
if (perfMonitor != null) {
perfMonitor.dispose();
perfMonitor = null;
}
String mainClass = System.getProperty("MainClass");
if (mainClass != null) {
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
pref.put("skin", picker.getDirectory() + File.separator + file);
deinitializeSync();
frm.dispose();
System.setProperty("reload.simulator", "true");
} else {
loadSkinFile(picker.getDirectory() + File.separator + file, frm);
refreshSkin(frm);
}
}
}
});
skinMenu.addSeparator();
JMenuItem reset = new JMenuItem("Reset Skins");
skinMenu.add(reset);
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if (JOptionPane.showConfirmDialog(frm, "Are you sure you want to reset skins to default?", "Clean Storage", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
pref.put("skins", DEFAULT_SKINS);
String userDir = System.getProperty("user.home");
final File skinDir = new File(userDir + "/.codenameone/");
if (skinDir.exists()) {
File[] childs = skinDir.listFiles();
for (int i = 0; i < childs.length; i++) {
File child = childs[i];
if (child.getName().endsWith(".skin")) {
child.delete();
}
}
}
if (netMonitor != null) {
netMonitor.dispose();
netMonitor = null;
}
if (perfMonitor != null) {
perfMonitor.dispose();
perfMonitor = null;
}
String mainClass = System.getProperty("MainClass");
if (mainClass != null) {
pref.put("skin", "/iphone3gs.skin");
deinitializeSync();
frm.dispose();
System.setProperty("reload.simulator", "true");
} else {
loadSkinFile("/iphone3gs.skin", frm);
refreshSkin(frm);
}
}
}
});
return skinMenu;
}
use of com.codename1.ui.spinner.Picker in project CodenameOne by codenameone.
the class IOSImplementation method showNativePicker.
@Override
public Object showNativePicker(final int type, final Component source, final Object currentValue, final Object data) {
datePickerResult = -2;
int x = 0, y = 0, w = 20, h = 20, preferredHeight = 0, preferredWidth = 0;
if (source != null) {
x = source.getAbsoluteX();
y = source.getAbsoluteY();
w = source.getWidth();
h = source.getHeight();
}
if (source instanceof Picker) {
Picker p = (Picker) source;
preferredHeight = p.getPreferredPopupHeight();
preferredWidth = p.getPreferredPopupWidth();
}
if (type == Display.PICKER_TYPE_STRINGS) {
String[] strs = (String[]) data;
int offset = -1;
if (currentValue != null) {
int slen = strs.length;
for (int iter = 0; iter < slen; iter++) {
if (strs[iter].equals(currentValue)) {
offset = iter;
break;
}
}
}
nativeInstance.openStringPicker(strs, offset, x, y, w, h, preferredWidth, preferredHeight);
} else if (type == Display.PICKER_TYPE_DURATION) {
long time;
if (currentValue instanceof Long) {
time = (Long) currentValue;
} else {
time = 0l;
}
int minuteStep = 5;
if (data instanceof String) {
String strData = (String) data;
String[] parts = Util.split(strData, "\n");
for (String part : parts) {
if (part.indexOf("minuteStep=") != -1) {
minuteStep = Integer.parseInt(part.substring(part.indexOf("=") + 1));
}
}
}
nativeInstance.openDatePicker(type, time, x, y, w, h, preferredWidth, preferredHeight, minuteStep);
} else {
long time;
if (currentValue instanceof Integer) {
java.util.Calendar c = java.util.Calendar.getInstance();
c.set(java.util.Calendar.HOUR_OF_DAY, ((Integer) currentValue).intValue() / 60);
c.set(java.util.Calendar.MINUTE, ((Integer) currentValue).intValue() % 60);
time = c.getTime().getTime();
} else if (currentValue != null) {
time = ((java.util.Date) currentValue).getTime();
} else {
time = new java.util.Date().getTime();
}
nativeInstance.openDatePicker(type, time, x, y, w, h, preferredWidth, preferredHeight, 5);
}
// wait for the native code to complete
Display.getInstance().invokeAndBlock(new Runnable() {
public void run() {
while (datePickerResult == -2) {
synchronized (PICKER_LOCK) {
try {
PICKER_LOCK.wait(100);
} catch (InterruptedException err) {
}
}
}
}
}, true);
if (datePickerResult == -1) {
// }
return null;
}
if (type == Display.PICKER_TYPE_STRINGS) {
if (datePickerResult < 0) {
return null;
}
return ((String[]) data)[(int) datePickerResult];
}
Object result;
if (type == Display.PICKER_TYPE_DURATION || type == Display.PICKER_TYPE_DURATION_HOURS || type == Display.PICKER_TYPE_DURATION_MINUTES) {
if (datePickerResult < 0) {
return null;
}
return new Long(datePickerResult);
}
if (type == Display.PICKER_TYPE_TIME) {
java.util.Calendar c = java.util.Calendar.getInstance();
c.setTime(new Date(datePickerResult));
result = new Integer(c.get(java.util.Calendar.HOUR_OF_DAY) * 60 + c.get(java.util.Calendar.MINUTE));
} else {
result = new Date(datePickerResult);
}
return result;
}
use of com.codename1.ui.spinner.Picker in project CodenameOne by codenameone.
the class TestPicker method testStringsPicker.
private void testStringsPicker() {
Picker p = new Picker();
p.setType(Display.PICKER_TYPE_STRINGS);
}
Aggregations