Revision: 2993
http://sourceforge.net/p/swingme/code/2993
Author: yuranet
Date: 2026-01-14 15:37:08 +0000 (Wed, 14 Jan 2026)
Log Message:
-----------
support emoji icons
Modified Paths:
--------------
SwingME/src/net/yura/mobile/gui/Icon.java
Modified: SwingME/src/net/yura/mobile/gui/Icon.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/Icon.java 2026-01-14 13:36:05 UTC (rev 2992)
+++ SwingME/src/net/yura/mobile/gui/Icon.java 2026-01-14 15:37:08 UTC (rev 2993)
@@ -14,11 +14,12 @@
* You should have received a copy of the GNU Lesser General Public License
* along with 'yura.net Swing ME'. If not, see <http://www.gnu.org/licenses/>.
*/
-
package net.yura.mobile.gui;
import javax.microedition.lcdui.Image;
import net.yura.mobile.gui.components.Component;
+import net.yura.mobile.gui.components.Label;
+import net.yura.mobile.gui.plaf.Style;
/**
* @author Yura Mamyrin
@@ -41,9 +42,15 @@
initImage(img);
}
+ public Icon(String emoji, int w, int h) {
+ image = emoji;
+ width = w;
+ height = h;
+ }
+
/**
* this constructor does not throw an exception on Image that is not found,
- * instead it creates a Icon with 0 height and width, (in Swing height and width are -1)
+ * instead, just like Swing it creates a Icon with -1 height and width.
*
* @see javax.swing.ImageIcon#ImageIcon(java.lang.String) ImageIcon.ImageIcon
* @see java.lang.Class#getResourceAsStream(java.lang.String) Class.getResourceAsStream
@@ -85,6 +92,21 @@
if (image instanceof Image) {
g.drawRegion((Image)image, px, py, width, height, x, y);
}
+ else if (image instanceof String) {
+ if (c != null) {
+ if (c.getForeground() != Style.NO_COLOR) {
+ g.setColor(c.getForeground());
+ }
+ if (c instanceof Label) {
+ g.setFont(((Label) c).getFont());
+ }
+ }
+ String emoji = (String) image;
+ Font font = g.getFont();
+ int w = font.getWidth(emoji);
+ int h = font.getHeight();
+ g.drawString(emoji, x + (width - w) / 2, y + (height - h) / 2);
+ }
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|