use of com.codename1.ui.TextSelection.Char in project CodeRAD by shannah.
the class FirstCharEntityImageRenderer method getLetterBackground.
private Image getLetterBackground(char c) {
c = Character.toUpperCase(c);
String cstr = "" + c;
int color = colors[Math.max(0, c - 'A') % colors.length];
Image i = backgroundImageCache.get(color);
if (i != null) {
return i;
}
int circleMaskWidth = width;
int circleMaskHeight = height;
Image img = Image.createImage(circleMaskWidth, circleMaskHeight, 0);
Graphics g = img.getGraphics();
g.setAntiAliased(true);
g.setColor(color);
g.fillArc(1, 1, circleMaskWidth - 2, circleMaskHeight - 2, 0, 360);
backgroundImageCache.put(color, img);
return img;
}
use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.
the class FontImage method setMaterialIcon.
/**
* <p>Applies a material design icon (one of the MATERIAL_* icons above) to the given component using the
* styling of the label</p>
* <script src="https://gist.github.com/codenameone/8cf6f70188959524474b.js"></script>
* @param l a multibutton
* @param icon one of the MATERIAL_* icons
* @param size the size of the icon in millimeters
*/
public static void setMaterialIcon(MultiButton l, char icon, float size) {
if (Font.isTrueTypeFileSupported()) {
Style s = new Style(l.getUnselectedStyle());
s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
l.setIcon(FontImage.create("" + icon, s));
}
}
use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.
the class FontImage method setMaterialIcon.
/**
* <p>Applies a material design icon (one of the MATERIAL_* icons above) to the given component using the
* styling of the label</p>
* <script src="https://gist.github.com/codenameone/8cf6f70188959524474b.js"></script>
* @param l a SpanButton
* @param icon one of the MATERIAL_* icons
* @param size the size of the icon in millimeters
*/
public static void setMaterialIcon(SpanButton l, char icon, float size) {
if (Font.isTrueTypeFileSupported()) {
Style s = new Style(l.getUnselectedStyle());
s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
l.setIcon(FontImage.create("" + icon, s));
Style sel = l.getSelectedStyle();
Style pre = l.getPressedStyle();
Style dis = l.getDisabledStyle();
if (sel.getFgColor() != s.getFgColor() || (sel.getBgColor() != s.getBgColor()) || (sel.getBgTransparency() != s.getBgTransparency())) {
sel = new Style(sel);
sel.setFont(getMaterialDesignFont().derive(rightSize(sel, size), Font.STYLE_PLAIN));
l.setRolloverIcon(FontImage.create("" + icon, sel));
}
if (pre.getFgColor() != s.getFgColor() || (pre.getBgColor() != s.getBgColor()) || (pre.getBgTransparency() != s.getBgTransparency())) {
pre = new Style(pre);
pre.setFont(getMaterialDesignFont().derive(rightSize(pre, size), Font.STYLE_PLAIN));
l.setPressedIcon(FontImage.create("" + icon, pre));
}
if (dis.getFgColor() != s.getFgColor() || (dis.getBgColor() != s.getBgColor()) || (dis.getBgTransparency() != s.getBgTransparency())) {
dis = new Style(dis);
dis.setFont(getMaterialDesignFont().derive(rightSize(dis, size), Font.STYLE_PLAIN));
l.setDisabledIcon(FontImage.create("" + icon, dis));
}
}
}
use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.
the class FontImage method setMaterialIcon.
/**
* <p>Applies a material design icon (one of the MATERIAL_* icon constants) to the given command using the
* given UIID. Notice that the pressed/selected & disabled states will be set appropriately.</p>
*
* @param c a command
* @param icon one of the MATERIAL_* icons
* @param uiid the UIID for the command (e.g. TitleCommand)
* @param size the size of the icon in millimeters
*/
public static void setMaterialIcon(Command c, char icon, String uiid, float size) {
if (Font.isTrueTypeFileSupported()) {
UIManager uim = UIManager.getInstance();
Style s = uim.getComponentStyle(uiid);
s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
c.setIcon(FontImage.create("" + icon, s));
Style sel = uim.getComponentSelectedStyle(uiid);
Style pre = uim.getComponentCustomStyle(uiid, "press");
Style dis = uim.getComponentCustomStyle(uiid, "dis");
;
if (sel.getFgColor() != s.getFgColor() || (sel.getBgColor() != s.getBgColor()) || (sel.getBgTransparency() != s.getBgTransparency())) {
sel = new Style(sel);
sel.setFont(getMaterialDesignFont().derive(rightSize(sel, size), Font.STYLE_PLAIN));
c.setRolloverIcon(FontImage.create("" + icon, sel));
}
if (pre.getFgColor() != s.getFgColor() || (pre.getBgColor() != s.getBgColor()) || (pre.getBgTransparency() != s.getBgTransparency())) {
pre = new Style(pre);
pre.setFont(getMaterialDesignFont().derive(rightSize(pre, size), Font.STYLE_PLAIN));
c.setPressedIcon(FontImage.create("" + icon, pre));
}
if (dis.getFgColor() != s.getFgColor() || (dis.getBgColor() != s.getBgColor()) || (dis.getBgTransparency() != s.getBgTransparency())) {
dis = new Style(dis);
dis.setFont(getMaterialDesignFont().derive(rightSize(dis, size), Font.STYLE_PLAIN));
c.setDisabledIcon(FontImage.create("" + icon, dis));
}
}
}
use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.
the class ResourceEditorView method initImagesComboBox.
/**
* Creates a sorted image combo box that includes image previews. The combo box
* can be searched by typing a letter even when images are used for the values...
*/
public static void initImagesComboBox(JComboBox cb, final EditableResources res, boolean asString, final boolean includeNull, boolean blockTimelines) {
String[] imgs = res.getImageResourceNames();
if (blockTimelines) {
List<String> nonT = new ArrayList<String>();
for (String c : imgs) {
if (!(res.getImage(c) instanceof Timeline)) {
nonT.add(c);
}
}
imgs = new String[nonT.size()];
nonT.toArray(imgs);
}
final String[] images = imgs;
Arrays.sort(images, String.CASE_INSENSITIVE_ORDER);
if (asString) {
if (includeNull) {
String[] n = new String[images.length + 1];
System.arraycopy(images, 0, n, 1, images.length);
cb.setModel(new DefaultComboBoxModel(n));
} else {
cb.setModel(new DefaultComboBoxModel(images));
}
cb.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
boolean n = false;
if (value == null) {
value = "[null]";
n = true;
}
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (!n) {
setIcon(new CodenameOneImageIcon(res.getImage((String) value), 24, 24));
} else {
setIcon(null);
}
return this;
}
});
} else {
int offset = 0;
com.codename1.ui.Image[] arr;
if (includeNull) {
arr = new com.codename1.ui.Image[images.length + 1];
offset++;
} else {
arr = new com.codename1.ui.Image[images.length];
}
for (String c : images) {
arr[offset] = res.getImage(c);
offset++;
}
cb.setModel(new DefaultComboBoxModel(arr));
cb.setKeySelectionManager(new JComboBox.KeySelectionManager() {
private String current;
private long lastPress;
public int selectionForKey(char aKey, ComboBoxModel aModel) {
long t = System.currentTimeMillis();
aKey = Character.toLowerCase(aKey);
if (t - lastPress < 800) {
current += aKey;
} else {
current = "" + aKey;
}
lastPress = t;
for (int iter = 0; iter < images.length; iter++) {
if (images[iter].toLowerCase().startsWith(current)) {
if (includeNull) {
return iter + 1;
}
return iter;
}
}
return -1;
}
});
cb.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
com.codename1.ui.Image i = (com.codename1.ui.Image) value;
if (value == null) {
value = "[null]";
} else {
value = res.findId(value);
}
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (i != null) {
setIcon(new CodenameOneImageIcon(i, 24, 24));
} else {
setIcon(null);
}
return this;
}
});
}
}
Aggregations