use of com.codename1.ui.Font in project CodenameOne by codenameone.
the class AddResourceDialog method addResource.
public String addResource(EditableResources res, ResourceEditorView view) {
// "Image", "Animation", "Font", "Theme", "Data", "Localization (L10N)"
String newName = name.getText();
for (String r : res.getResourceNames()) {
if (r.equalsIgnoreCase(newName)) {
JOptionPane.showMessageDialog(this, "A resource called: " + newName + " already exists\nYou must delete the resource first.", "Add Resource", JOptionPane.ERROR_MESSAGE);
return null;
}
}
switch(type.getSelectedIndex()) {
case // image
IMAGE:
ImageRGBEditor imageEditor = new ImageRGBEditor(res, name.getText(), view);
imageEditor.selectFile();
view.setSelectedResource(name.getText());
break;
case MULTI_IMAGE:
ImageMultiEditor multiImageEditor = new ImageMultiEditor(res, name.getText(), view);
view.setSelectedResource(name.getText());
break;
case TIMELINE:
new TimelineEditor(res, name.getText(), view);
view.setSelectedResource(name.getText());
break;
case // animation
ANIMATION:
TimelineEditor.selectFile(view, res, name.getText());
/*ImageEditor animationEditor = new ImageEditor(res, name.getText());
animationEditor.setAnimation(true);
animationEditor.selectFile(view);*/
break;
case // font
FONT:
new FontEditor(res, new EditorFont(com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_PLAIN, com.codename1.ui.Font.SIZE_MEDIUM), null, "Arial-plain-12", true, RenderingHints.VALUE_TEXT_ANTIALIAS_ON, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,;:!@/\\*()[]{}|#$%^&<>?'\"+- "), name.getText()).createFont();
view.setSelectedResource(name.getText());
break;
case // theme
THEME:
res.setTheme(name.getText(), new Hashtable());
view.setSelectedResource(name.getText());
// ResourceEditorView.expandAndSelect(tree, name.getText());
break;
case // data
DATA:
DataEditor dataEditor = new DataEditor(res, name.getText());
dataEditor.selectDataFile(view);
view.setSelectedResource(name.getText());
break;
case // localization
LOCALIZATION:
Hashtable h = new Hashtable();
Hashtable local = new Hashtable();
local.put("cancel", "Cancel");
local.put("ok", "OK");
local.put("menu", "Menu");
local.put("select", "Select");
local.put("edit", "Edit");
h.put("en", local);
res.setL10N(name.getText(), h);
view.setSelectedResource(name.getText());
// ResourceEditorView.expandAndSelect(tree, name.getText());
break;
case UI:
UserInterfaceEditor uiEditor = new UserInterfaceEditor(name.getText(), res, view.getProjectGeneratorSettings(), view);
view.setSelectedResource(name.getText());
break;
}
return name.getText();
}
use of com.codename1.ui.Font in project CodenameOne by codenameone.
the class AddThemeResource method addResource.
// GEN-LAST:event_templateActionPerformed
public String addResource(EditableResources res, ResourceEditorView view) {
String newName = name.getText();
for (String r : res.getResourceNames()) {
if (r.equalsIgnoreCase(newName)) {
JOptionPane.showMessageDialog(this, "A resource called: " + newName + " already exists\nYou must delete the resource first.", "Add Resource", JOptionPane.ERROR_MESSAGE);
return null;
}
}
Hashtable theme = new Hashtable();
InputStream is = getClass().getResourceAsStream("/templates/" + template.getSelectedItem().toString() + ".res");
if (is != null) {
try {
EditableResources r = new EditableResources();
r.openFile(is);
is.close();
theme = r.getTheme(r.getThemeResourceNames()[0]);
view.checkDuplicateResourcesLoop(r, res.getImageResourceNames(), r.getImageResourceNames(), "Rename Image", "Image ", true);
view.checkDuplicateResourcesLoop(r, res.getL10NResourceNames(), r.getL10NResourceNames(), "Rename Localization", "Localization ", true);
view.checkDuplicateResourcesLoop(r, res.getDataResourceNames(), r.getDataResourceNames(), "Rename Data", "Data ", true);
view.checkDuplicateResourcesLoop(r, res.getUIResourceNames(), r.getUIResourceNames(), "Rename GUI", "GUI ", true);
view.checkDuplicateResourcesLoop(r, res.getFontResourceNames(), r.getFontResourceNames(), "Rename Font", "Font ", true);
for (String s : r.getImageResourceNames()) {
if (r.isMultiImage(s)) {
res.setMultiImage(s, (EditableResources.MultiImage) r.getResourceObject(s));
} else {
res.setImage(s, r.getImage(s));
}
}
for (String s : r.getL10NResourceNames()) {
res.setL10N(s, (Hashtable) r.getResourceObject(s));
}
for (String s : r.getDataResourceNames()) {
res.setData(s, (byte[]) r.getResourceObject(s));
}
for (String s : r.getUIResourceNames()) {
res.setUi(s, (byte[]) r.getResourceObject(s));
}
for (String s : r.getFontResourceNames()) {
res.setFont(s, r.getFont(s));
}
} catch (IOException err) {
err.printStackTrace();
}
}
res.setTheme(name.getText(), theme);
view.setSelectedResource(name.getText());
return name.getText();
}
use of com.codename1.ui.Font in project CodenameOne by codenameone.
the class FontEditor method createFont.
/**
* Creates a font instance based on the current state to place into the
* undoable edit within the Editor.
*/
public EditorFont createFont() {
if (!completedConstruction) {
return null;
}
com.codename1.ui.Font systemFont = com.codename1.ui.Font.createSystemFont(FONT_FACE_VALUES[systemFontFace.getSelectedIndex()], FONT_STYLE_VALUES[systemFontStyle.getSelectedIndex()], FONT_SIZE_VALUES[systemFontSize.getSelectedIndex()]);
java.awt.Font aFont = preview.getFont();
String s = aFont.getFamily() + "-";
if (aFont.isBold()) {
s += aFont.isItalic() ? "bolditalic" : "bold";
} else {
s += aFont.isItalic() ? "italic" : "plain";
}
s += "-" + aFont.getSize();
int selIndex = fontMainType.getSelectedIndex();
EditorFont newFont = new EditorFont(systemFont, null, s + ";" + lookupString.getText(), selIndex == 1 || selIndex == 2, ANTI_ALIASING_VALUES[antiAliasing.getSelectedIndex()], charset.getText());
if (!factoryCreation) {
resources.setFont(fontName, newFont);
}
return newFont;
}
use of com.codename1.ui.Font in project CodenameOne by codenameone.
the class SpinnerRenderer method drawCharPerspectivePosition.
/**
* Draws the character with the given perspective effect
*/
private int drawCharPerspectivePosition(Graphics g, char c, int x, int y) {
if (imageCache == null) {
imageCache = new HashMap[PERSPECTIVES];
for (int iter = 0; iter < PERSPECTIVES; iter++) {
if (iter != FRONT_ANGLE) {
imageCache[iter] = new HashMap<Character, Image>();
}
}
}
Character chr = new Character(c);
Image i = imageCache[perspective].get(chr);
if (i == null) {
// UIManager.getInstance().getLookAndFeel().setFG(g, this);
Font f = getStyle().getFont();
int w = f.charWidth(c);
int h = f.getHeight();
i = Image.createImage(w, h, 0);
g = i.getGraphics();
UIManager.getInstance().getLookAndFeel().setFG(g, this);
g.drawChar(c, 0, 0);
i = Effects.verticalPerspective(i, TOP_SCALE[perspective], BOTTOM_SCALE[perspective], VERTICAL_SHRINK[perspective]);
imageCache[perspective].put(chr, i);
}
g.drawImage(i, x, y);
return i.getWidth();
}
use of com.codename1.ui.Font in project CodenameOne by codenameone.
the class BlackBerryImplementation method nativeEdit.
public void nativeEdit(final Component cmp, final int maxSize, final int constraint, String text, int keyCode) {
if (nativeEdit != null) {
finishEdit(true);
}
lightweightEdit = (TextArea) cmp;
if (keyCode > 0 && getKeyboardType() == Display.KEYBOARD_TYPE_QWERTY) {
// if this is a number
if ((constraint & TextArea.DECIMAL) == TextArea.DECIMAL || (constraint & TextArea.NUMERIC) == TextArea.NUMERIC || (constraint & TextArea.PHONENUMBER) == TextArea.PHONENUMBER) {
if (keyCode == 119) {
text += "1";
} else if (keyCode == 101) {
text += "2";
} else if (keyCode == 114) {
text += "3";
} else if (keyCode == 115) {
text += "4";
} else if (keyCode == 100) {
text += "5";
} else if (keyCode == 102) {
text += "6";
} else if (keyCode == 122) {
text += "7";
} else if (keyCode == 120) {
text += "8";
} else if (keyCode == 99) {
text += "9";
}
} else {
text += ((char) keyCode);
}
lightweightEdit.setText(text);
}
class LightweightEdit implements Runnable, Animation {
public void run() {
long type = 0;
TextArea lightweightEditTmp = lightweightEdit;
if (lightweightEditTmp == null) {
return;
}
int constraint = lightweightEditTmp.getConstraint();
if ((constraint & TextArea.DECIMAL) == TextArea.DECIMAL) {
type = BasicEditField.FILTER_REAL_NUMERIC;
} else if ((constraint & TextArea.EMAILADDR) == TextArea.EMAILADDR) {
type = BasicEditField.FILTER_EMAIL;
} else if ((constraint & TextArea.NUMERIC) == TextArea.NUMERIC) {
type = BasicEditField.FILTER_NUMERIC;
}
if ((constraint & TextArea.PHONENUMBER) == TextArea.PHONENUMBER) {
type = BasicEditField.FILTER_PHONE;
}
if ((constraint & TextArea.NON_PREDICTIVE) == TextArea.NON_PREDICTIVE) {
type |= BasicEditField.NO_COMPLEX_INPUT;
}
if (lightweightEditTmp.isSingleLineTextArea()) {
type |= BasicEditField.NO_NEWLINE;
}
if ((constraint & TextArea.PASSWORD) == TextArea.PASSWORD) {
nativeEdit = new BBPasswordEditField(lightweightEditTmp, type, maxSize);
} else {
nativeEdit = new BBEditField(lightweightEditTmp, type, maxSize);
}
nativeEdit.setEditable(true);
Font f = nativeEdit.getFont();
if (f.getHeight() > lightweightEditTmp.getStyle().getFont().getHeight()) {
nativeEdit.setFont(f.derive(f.getStyle(), lightweightEditTmp.getStyle().getFont().getHeight()));
}
canvas.add(nativeEdit);
nativeEdit.setCursorPosition(lightweightEditTmp.getText().length());
try {
nativeEdit.setFocus();
} catch (Throwable t) {
// no idea why this throws an exception sometimes
// t.printStackTrace();
}
}
public boolean animate() {
BasicEditField ef = nativeEdit;
Component lw = lightweightEdit;
if (lw == null || lw.getComponentForm() != Display.getInstance().getCurrent()) {
Display.getInstance().getCurrent().deregisterAnimated(this);
finishEdit(false);
} else {
if (ef != null) {
if (ef.isDirty()) {
lw.repaint();
}
}
}
return false;
}
public void paint(com.codename1.ui.Graphics g) {
}
}
LightweightEdit lw = new LightweightEdit();
Display.getInstance().getCurrent().registerAnimated(lw);
Application.getApplication().invokeLater(lw);
}
Aggregations