use of com.codename1.ui.util.xml.Val in project CodenameOne by codenameone.
the class L10nEditor method initTable.
private void initTable() {
bundleTable.setModel(new AbstractTableModel() {
public int getRowCount() {
return keys.size();
}
public int getColumnCount() {
return 1 + localeList.size();
}
public boolean isCellEditable(int row, int col) {
boolean b = col != 0;
if (b) {
String s = (String) getValueAt(row, col);
return s == null || !s.contains("\n");
}
return b;
}
public String getColumnName(int columnIndex) {
if (columnIndex == 0) {
return "Key";
}
return (String) localeList.get(columnIndex - 1);
}
public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == 0) {
return keys.get(rowIndex);
}
Hashtable h = res.getL10N(localeName, (String) localeList.get(columnIndex - 1));
return h.get(keys.get(rowIndex));
}
public void setValueAt(Object val, int rowIndex, int columnIndex) {
res.setModified();
if (columnIndex == 0) {
if (!keys.contains(val)) {
// ...
}
return;
}
// Hashtable h = (Hashtable)bundle.get(localeList.get(columnIndex - 1));
// h.put(keys.get(rowIndex), val);
String currentKey = (String) keys.get(rowIndex);
res.setLocaleProperty(localeName, (String) localeList.get(columnIndex - 1), currentKey, val);
if (currentKey.equals("@im")) {
StringTokenizer tok = new StringTokenizer((String) val, "|");
boolean modified = false;
while (tok.hasMoreTokens()) {
String currentIm = tok.nextToken();
if ("ABC".equals(currentIm) || "123".equals(currentIm) || "Abc".equals(currentIm) || "abc".equals(currentIm)) {
continue;
}
String prop = "@im-" + currentIm;
if (!keys.contains(prop)) {
keys.add(prop);
for (Object locale : localeList) {
res.setLocaleProperty(localeName, (String) locale, prop, "");
}
modified = true;
}
}
if (modified) {
fireTableDataChanged();
}
return;
}
if (currentKey.equals("@vkb")) {
boolean modified = false;
StringTokenizer tok = new StringTokenizer((String) val, "|");
while (tok.hasMoreTokens()) {
String currentIm = tok.nextToken();
if ("ABC".equals(currentIm) || "123".equals(currentIm) || ".,123".equals(currentIm) || ".,?".equals(currentIm)) {
continue;
}
String prop = "@vkb-" + currentIm;
if (!keys.contains(prop)) {
keys.add(prop);
for (Object locale : localeList) {
res.setLocaleProperty(localeName, (String) locale, prop, "");
}
modified = true;
}
}
if (modified) {
fireTableDataChanged();
}
}
}
});
bundleTable.setDefaultRenderer(Object.class, new SwingRenderer() {
private JCheckBox chk = new JCheckBox();
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (column > 0) {
// constant value
String key = (String) keys.get(row);
if (key.startsWith("@")) {
if (key.equalsIgnoreCase("@rtl")) {
chk.setSelected(value != null && "true".equalsIgnoreCase(value.toString()));
updateComponentSelectedState(chk, isSelected, table, row, column, hasFocus);
return chk;
}
if (key.startsWith("@vkb") || key.startsWith("@im")) {
JButton b = new JButton("...");
updateComponentSelectedState(b, isSelected, table, row, column, hasFocus);
return b;
}
}
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
});
bundleTable.setDefaultEditor(Object.class, new DefaultCellEditor(new JTextField()) {
private Object currentValue;
String editedKey;
private DefaultCellEditor standardEditor = new DefaultCellEditor(new JTextField());
private DefaultCellEditor buttonEditor = new DefaultCellEditor(new JTextField()) {
private JButton button = new JButton("...");
{
button.setBorderPainted(false);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (editedKey.equals("@vkb") || editedKey.equals("@im")) {
currentValue = editInputModeOrder((String) currentValue, editedKey.equals("@vkb"));
fireEditingStoppedExt();
return;
}
/*if(editedKey.startsWith("@vkb")) {
VKBEditor v = new VKBEditor(button, editedKey.substring(5), (String)currentValue);
currentValue = v.getValue();
fireEditingStoppedExt();
return;
}*/
if (editedKey.startsWith("@im")) {
currentValue = editTextFieldInputMode((String) currentValue);
fireEditingStoppedExt();
return;
}
}
});
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
editedKey = (String) keys.get(row);
return button;
}
};
private DefaultCellEditor checkBoxEditor = new DefaultCellEditor(new JCheckBox()) {
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
return super.getTableCellEditorComponent(table, new Boolean("true".equalsIgnoreCase((String) value)), isSelected, row, column);
}
public Object getCellEditorValue() {
Boolean b = (Boolean) super.getCellEditorValue();
if (b.booleanValue()) {
return "true";
}
return "false";
}
};
private TableCellEditor current = standardEditor;
{
buttonEditor.setClickCountToStart(1);
checkBoxEditor.setClickCountToStart(1);
}
private void updateEditor(int row) {
// constant value
final String key = (String) keys.get(row);
if (key.startsWith("@")) {
if (key.equalsIgnoreCase("@rtl")) {
current = checkBoxEditor;
return;
}
if (key.startsWith("@vkb") || key.startsWith("@im")) {
current = buttonEditor;
return;
}
}
current = standardEditor;
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
updateEditor(row);
currentValue = value;
return current.getTableCellEditorComponent(table, value, isSelected, row, column);
}
public void fireEditingStoppedExt() {
fireEditingStopped();
}
public Object getCellEditorValue() {
if (current == buttonEditor) {
return currentValue;
}
return current.getCellEditorValue();
}
public boolean stopCellEditing() {
return current.stopCellEditing();
}
public void cancelCellEditing() {
current.cancelCellEditing();
}
public void addCellEditorListener(CellEditorListener l) {
current.addCellEditorListener(l);
super.addCellEditorListener(l);
}
public void removeCellEditorListener(CellEditorListener l) {
current.removeCellEditorListener(l);
super.removeCellEditorListener(l);
}
public boolean isCellEditable(EventObject anEvent) {
return current.isCellEditable(anEvent);
}
public boolean shouldSelectCell(EventObject anEvent) {
return current.shouldSelectCell(anEvent);
}
});
locales.setModel(new DefaultComboBoxModel(localeList.toArray()));
removeLocale.setEnabled(localeList.size() > 1);
}
use of com.codename1.ui.util.xml.Val in project CodenameOne by codenameone.
the class L10nEditor method importResourceActionPerformed.
// GEN-LAST:event_exportResourceActionPerformed
private void importResourceActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_importResourceActionPerformed
final String locale = (String) locales.getSelectedItem();
int val = JOptionPane.showConfirmDialog(this, "This will overwrite existing values for " + locale + "\nAre you sure?", "Import", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (val == JOptionPane.YES_OPTION) {
File[] files = ResourceEditorView.showOpenFileChooser("Properties, XML, CSV", "prop", "properties", "l10n", "locale", "xml", "csv");
if (files != null) {
FileInputStream f = null;
try {
f = new FileInputStream(files[0]);
if (files[0].getName().toLowerCase().endsWith("xml")) {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser saxParser = spf.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
xmlReader.setErrorHandler(new ErrorHandler() {
public void warning(SAXParseException exception) throws SAXException {
exception.printStackTrace();
}
public void error(SAXParseException exception) throws SAXException {
exception.printStackTrace();
}
public void fatalError(SAXParseException exception) throws SAXException {
exception.printStackTrace();
}
});
xmlReader.setContentHandler(new ContentHandler() {
private String currentName;
private StringBuilder chars = new StringBuilder();
@Override
public void setDocumentLocator(Locator locator) {
}
@Override
public void startDocument() throws SAXException {
}
@Override
public void endDocument() throws SAXException {
}
@Override
public void startPrefixMapping(String prefix, String uri) throws SAXException {
}
@Override
public void endPrefixMapping(String prefix) throws SAXException {
}
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
if ("string".equals(localName) || "string".equals(qName)) {
currentName = atts.getValue("name");
chars.setLength(0);
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if ("string".equals(localName) || "string".equals(qName)) {
String str = chars.toString();
if (str.startsWith("\"") && str.endsWith("\"")) {
str = str.substring(1);
str = str.substring(0, str.length() - 1);
res.setLocaleProperty(localeName, locale, currentName, str);
return;
}
str = str.replace("\\'", "'");
res.setLocaleProperty(localeName, locale, currentName, str);
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
chars.append(ch, start, length);
}
@Override
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
}
@Override
public void processingInstruction(String target, String data) throws SAXException {
}
@Override
public void skippedEntity(String name) throws SAXException {
}
});
xmlReader.parse(new InputSource(new InputStreamReader(f, "UTF-8")));
} else {
if (files[0].getName().toLowerCase().endsWith("csv")) {
CSVParserOptions po = new CSVParserOptions(this);
if (po.isCanceled()) {
f.close();
return;
}
CSVParser p = new CSVParser(po.getDelimiter());
String[][] data = p.parse(new InputStreamReader(f, po.getEncoding()));
for (int iter = 1; iter < data.length; iter++) {
if (data[iter].length > 0) {
String key = data[iter][0];
for (int col = 1; col < data[iter].length; col++) {
if (res.getL10N(localeName, data[0][col]) == null) {
res.addLocale(localeName, data[0][col]);
}
res.setLocaleProperty(localeName, data[0][col], key, data[iter][col]);
}
}
}
} else {
Properties prop = new Properties();
prop.load(f);
for (Object key : prop.keySet()) {
res.setLocaleProperty(localeName, locale, (String) key, prop.getProperty((String) key));
}
}
}
f.close();
initLocaleList();
for (Object localeObj : localeList) {
Hashtable current = res.getL10N(localeName, (String) localeObj);
for (Object key : current.keySet()) {
if (!keys.contains(key)) {
keys.add(key);
}
}
}
Collections.sort(keys);
initTable();
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(this, "Error: " + ex, "Error Occured", JOptionPane.ERROR_MESSAGE);
}
}
}
}
use of com.codename1.ui.util.xml.Val in project CodenameOne by codenameone.
the class ThemeEditor method findFlushingPropertyContrust.
/**
* Returns a "contrasting" value for the property to flash, e.g. for a font,
* return a differnet font or for a color return a ligher/darker color...
*/
private Object findFlushingPropertyContrust() {
if (flashingProperty.indexOf("Color") > -1) {
// flash to white or black depending on whether the color is closer to white
int val = Integer.decode("0x" + originalFlashingPropertyValue);
if (val > 0xf0f0f0) {
return "000000";
} else {
return "ffffff";
}
}
if (flashingProperty.indexOf("derive") > -1) {
return "NoPropertyUIIDExists";
}
if (flashingProperty.indexOf("font") > -1) {
// if this is not a bold font then just return a system bold font
if ((((com.codename1.ui.Font) originalFlashingPropertyValue).getStyle() & com.codename1.ui.Font.STYLE_BOLD) != 0) {
return com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_PLAIN, com.codename1.ui.Font.SIZE_LARGE);
}
return com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_BOLD, com.codename1.ui.Font.SIZE_LARGE);
}
if (flashingProperty.indexOf("bgImage") > -1) {
com.codename1.ui.Image i = (com.codename1.ui.Image) originalFlashingPropertyValue;
return i.modifyAlpha((byte) 128);
}
if (flashingProperty.indexOf("transparency") > -1) {
int v = Integer.parseInt((String) originalFlashingPropertyValue);
if (v < 128) {
return "255";
} else {
return "100";
}
}
/*
* if(flashingProperty.indexOf("scale") > -1) { return "false"; }
*/
if (flashingProperty.indexOf("padding") > -1 || flashingProperty.indexOf("margin") > -1) {
return "10,10,10,10";
}
if (flashingProperty.indexOf("border") > -1) {
if (originalFlashingPropertyValue != null) {
Border pressed = ((Border) originalFlashingPropertyValue).createPressedVersion();
if (pressed != null) {
return pressed;
}
}
return Border.createBevelRaised();
}
if (flashingProperty.indexOf("bgType") > -1) {
return originalFlashingPropertyValue;
}
if (flashingProperty.indexOf("bgGradient") > -1) {
Object[] gradient = new Object[4];
System.arraycopy(originalFlashingPropertyValue, 0, gradient, 0, 4);
gradient[0] = ((Object[]) originalFlashingPropertyValue)[1];
gradient[1] = ((Object[]) originalFlashingPropertyValue)[0];
return gradient;
}
if (flashingProperty.indexOf("align") > -1 || flashingProperty.indexOf("textDecoration") > -1) {
return originalFlashingPropertyValue;
}
throw new IllegalArgumentException("Unsupported property type: " + flashingProperty);
}
use of com.codename1.ui.util.xml.Val in project CodenameOne by codenameone.
the class PulsateEditor method pulsateWizard.
public void pulsateWizard(EditableResources res, JComponent parent) {
File[] f = ResourceEditorView.showOpenFileChooser("Image", ".png", ".jpg", ".jpeg", ".gif");
if (f != null && f.length > 0) {
try {
timelineName.setText(f[0].getName());
sourceImage = ImageIO.read(f[0]);
updateTimeline();
timer = new javax.swing.Timer(130, new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
if (previewLabel.animate()) {
previewLabel.repaint();
preview.repaint();
}
}
});
timer.setRepeats(true);
timer.setCoalesce(true);
timer.start();
int val = JOptionPane.showConfirmDialog(parent, this, "Edit Effect", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
timer.stop();
if (val == JOptionPane.OK_OPTION) {
store(res, currentImage, timelineName.getText() + ": TL ");
for (EncodedImage img : internalImages) {
store(res, img, timelineName.getText() + ": Fr ");
}
}
} catch (IOException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(parent, "Error in reading image file", "File Read Error", JOptionPane.ERROR_MESSAGE);
}
}
}
use of com.codename1.ui.util.xml.Val in project CodenameOne by codenameone.
the class JavaSEPort method getProperty.
/**
* @inheritDoc
*/
public String getProperty(String key, String defaultValue) {
if (key.equalsIgnoreCase("cn1_push_prefix") || key.equalsIgnoreCase("cellId") || key.equalsIgnoreCase("IMEI") || key.equalsIgnoreCase("UDID") || key.equalsIgnoreCase("MSISDN")) {
if (!checkForPermission("android.permission.READ_PHONE_STATE", "This is required to get the phone state")) {
return "";
}
return defaultValue;
}
if ("OS".equals(key)) {
return "SE";
}
if ("AppName".equals(key)) {
File f = new File("codenameone_settings.properties");
if (f.exists()) {
try {
Properties p = new Properties();
p.load(new FileInputStream(f));
return p.getProperty("codename1.displayName");
} catch (IOException ex) {
ex.printStackTrace();
}
}
return defaultValue;
}
if ("AppVersion".equals(key)) {
File f = new File("codenameone_settings.properties");
if (f.exists()) {
try {
Properties p = new Properties();
p.load(new FileInputStream(f));
return p.getProperty("codename1.version");
} catch (IOException ex) {
ex.printStackTrace();
}
}
return defaultValue;
}
String s = System.getProperty(key);
if (key.equals("built_by_user")) {
Preferences p = Preferences.userNodeForPackage(com.codename1.ui.Component.class);
String user = p.get("user", null);
Display d = Display.getInstance();
if (user == null) {
JPanel pnl = new JPanel();
JTextField tf = new JTextField(20);
pnl.add(new JLabel("E-Mail For Push"));
pnl.add(tf);
int val = JOptionPane.showConfirmDialog(canvas, pnl, "Please Enter Build Email Account", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (val != JOptionPane.OK_OPTION) {
return null;
}
user = tf.getText();
// p.put("user", user);
}
d.setProperty("built_by_user", user);
return user;
}
if (key.equals("package_name")) {
String mainClass = System.getProperty("MainClass");
if (mainClass != null) {
mainClass = mainClass.substring(0, mainClass.lastIndexOf('.'));
Display.getInstance().setProperty("package_name", mainClass);
}
return mainClass;
}
if (s == null) {
return defaultValue;
}
return s;
}
Aggregations