Revision: 20
http://swingme.svn.sourceforge.net/swingme/?rev=20&view=rev
Author: yuranet
Date: 2008-07-08 08:21:55 -0700 (Tue, 08 Jul 2008)
Log Message:
-----------
better borders
Modified Paths:
--------------
SwingME/src/net/yura/mobile/gui/DesktopPane.java
SwingME/src/net/yura/mobile/gui/Font.java
SwingME/src/net/yura/mobile/gui/Theme.java
SwingME/src/net/yura/mobile/gui/cellrenderer/DefaultListCellRenderer.java
SwingME/src/net/yura/mobile/gui/components/Button.java
SwingME/src/net/yura/mobile/gui/components/DropDownMenu.java
SwingME/src/net/yura/mobile/gui/components/Label.java
SwingME/src/net/yura/mobile/gui/components/Spinner.java
SwingME/src/net/yura/mobile/gui/components/TextField.java
SwingME/src/net/yura/mobile/gui/components/Window.java
Modified: SwingME/src/net/yura/mobile/gui/DesktopPane.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/DesktopPane.java 2008-07-07 18:22:04 UTC (rev 19)
+++ SwingME/src/net/yura/mobile/gui/DesktopPane.java 2008-07-08 15:21:55 UTC (rev 20)
@@ -384,8 +384,8 @@
}
public CommandButton[] getCurrentCommands(){
- currentCommands[0] = omponentCommands[0] == null ? currentWindow.panelCmds[0] : omponentCommands[0];
- currentCommands[1] = omponentCommands[1] == null ? currentWindow.panelCmds[1] : omponentCommands[1];
+ currentCommands[0] = omponentCommands[0] == null ? currentWindow.getWindowCommands()[0] : omponentCommands[0];
+ currentCommands[1] = omponentCommands[1] == null ? currentWindow.getWindowCommands()[1] : omponentCommands[1];
return currentCommands;
}
@@ -415,7 +415,7 @@
}
- CommandButton[] panelCmds = currentWindow.getPanelCommands();
+ CommandButton[] panelCmds = currentWindow.getWindowCommands();
ActionListener actionListener = currentWindow.getActionListener();
boolean softkey1Action = keyevent.isDownKey(KeyEvent.KEY_SOFTKEY1) || keyevent.justReleasedKey(KeyEvent.KEY_SOFTKEY1);
Modified: SwingME/src/net/yura/mobile/gui/Font.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/Font.java 2008-07-07 18:22:04 UTC (rev 19)
+++ SwingME/src/net/yura/mobile/gui/Font.java 2008-07-08 15:21:55 UTC (rev 20)
@@ -11,33 +11,36 @@
public class Font {
- private int height;
- private int startX[];
- private int startY[];
- private int spaceWidth;
- private byte characterWidth[];
- private Image characterImage;
- private int characterSpacing;
-
+ private int height;
+ private int startX[];
+ private int startY[];
+ private int spaceWidth;
+ private byte characterWidth[];
+ private Image characterImage;
+ private int characterSpacing;
+
private javax.microedition.lcdui.Font systemFont=null;
private int fontColor=0;
private Hashtable imageTable;
private int[] colors;
-
+
private boolean numbermode;
-
-
+
public Font() {
+ this( javax.microedition.lcdui.Font.getDefaultFont() );
+ }
+
+ public Font(javax.microedition.lcdui.Font f) {
- setSystemFont( javax.microedition.lcdui.Font.getDefaultFont() );
+ setSystemFont( f );
// not sure if this is needed
colors = new int[2];
colors[0]=0x00000000;
colors[1]=0x000000FF;
}
-
+
public Font(String name) {
try {
@@ -192,26 +195,14 @@
height = getHeight();
}
- /**
- * Sets the distance in pixels between each character.
- * This is used when a string is rendered, between each adjacent pair of non-space characters a spacing gap is inserted.
- * This gap may be negative in order to overlap the character images. Be careful when changing this value as it affects
- * the width of strings and subsequently any alignment applied to them when rendered.
- * @param spacing The size in pixels of the gap between non-space characters (can be negative if desired).
- */
- public void setCharacterSpacing(int spacing)
+
+ public void setCharacterSpacing(int spacing)
{
characterSpacing = spacing;
}
- /**
- * Sets the size of a space character.
- * A space character is defined as any character with a width of zero. The default value for the space width in a newly
- * created font is the same width as that font's lower case 'o' character, so make sure this value is set for fonts
- * that do not contain a lowe case 'o'.
- * @param width The width of the space character.
- */
- public void setSpaceWidth(int width)
+
+ public void setSpaceWidth(int width)
{
spaceWidth = width;
}
@@ -219,8 +210,8 @@
/**
* Gets the width of a single character using this font.
* This will return the space width for any zero-width characters as these characters are treated as spaces.
- * @param c The character to get the width of.
- * @return The width of the requested character when rendered using this font.
+ * @param c The character to get the width of.
+ * @return The width of the requested character when rendered using this font.
*/
public int getWidth(char c) {
@@ -290,15 +281,7 @@
}
- /**
- * Gets the height of the font.
- * The height of the font is defined by the character data image. It may not always be the height of the tallest
- * character in the font, but should be the difference between the top of the character that stretches the highest
- * above the baseline and the bottom of the one that reaches the lowest below it.
- * @return The height of the font in pixels.
- */
- public int getHeight()
- {
+ public int getHeight() {
if(systemFont != null)
{
return systemFont.getHeight();
@@ -307,12 +290,6 @@
return height;
}
- /**
- * Gets the width in pixels of a string rendered using this font.
- * Be careful if you change the space width or the character spacing of the font as this will affect all string widths,
- * so if you need to store string widths, make sure you update those stored values after changing the display properties.
- * @return The width of the string in pixels when rendered using this font.
- */
public int getWidth(String s) {
if (numbermode) {
@@ -375,26 +352,19 @@
* Returns system font object, null if system font object is null and bitmap fonts being used.
* @return - javax.microedition.lcdui.Font or null if bitmap fonts used.
*/
- public javax.microedition.lcdui.Font getFont()
- {
+ public javax.microedition.lcdui.Font getFont() {
return systemFont;
}
- /**
+ /**
* Renders a string onto a graphics object.
* This will draw the specified string onto the specified graphics object using this font at the requested position and alignment.
* @param g The graphics object to draw onto.
* @param s The string to draw.
* @param x The x position in the graphics object.
* @param y The y position in the graphics object.
- * @param alignment The alignment to use. This can be one of TOP, MIDDLE, BOTTOM (vertical alignments), LEFT, CENTER, RIGHT
- * (horizontal alignments) or one of the combined flags TOP_LEFT, TOP_CENTER, TOP_RIGHT, etc. The combined values are the
- * same as bitwise or'ing together a vertical alignment value with a horizontal alignment value and are provided for
- * convenience and readability of your code. The default vertical alignment is TOP and the default horizontal alignment is LEFT.
- * The alignment will align the specified 'handle' of the string to the x, y position, so for example if you specify MIDDLE_RIGHT
- * then the string will be rendered such that the x, y position is at the middle right of the string, i.e. the entire string will
- * to the left of the point with half of the string above and half below the point.
- */
+ * @param alignment The alignment to use.
+ */
public int drawString(Graphics g, String s, int x, int y, int alignment) {
setColor( g.getColor() );
Modified: SwingME/src/net/yura/mobile/gui/Theme.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/Theme.java 2008-07-07 18:22:04 UTC (rev 19)
+++ SwingME/src/net/yura/mobile/gui/Theme.java 2008-07-08 15:21:55 UTC (rev 20)
@@ -1,5 +1,8 @@
package net.yura.mobile.gui;
+import net.yura.mobile.gui.border.Border;
+import net.yura.mobile.gui.border.LineBorder;
+
public class Theme {
public int scrollBarCol=0x00FFFFFF;
@@ -12,8 +15,8 @@
public int background;
public int foreground;
- public int itemBorderColor;
- public int itemActiveBorderColor;
+ public Border normalBorder;
+ public Border activeBorder;
public int defaultWidth;
public int defaultSpace;
@@ -34,8 +37,8 @@
background = 0x00FFFFFF;
foreground = 0;
- itemBorderColor = 0x00808080;
- itemActiveBorderColor = 0;
+ normalBorder = new LineBorder(0x00808080);
+ activeBorder = new LineBorder(0);
}
Modified: SwingME/src/net/yura/mobile/gui/cellrenderer/DefaultListCellRenderer.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/cellrenderer/DefaultListCellRenderer.java 2008-07-07 18:22:04 UTC (rev 19)
+++ SwingME/src/net/yura/mobile/gui/cellrenderer/DefaultListCellRenderer.java 2008-07-08 15:21:55 UTC (rev 20)
@@ -26,20 +26,15 @@
*/
public DefaultListCellRenderer() {
- this(
- DesktopPane.getDefaultTheme().font,
- DesktopPane.getDefaultTheme().itemBorderColor,
- DesktopPane.getDefaultTheme().itemActiveBorderColor);
+ this(0x00808080,0);
}
- public DefaultListCellRenderer(Font s,int color,int c2) {
-
- super("",s);
-
+ public DefaultListCellRenderer(int backColor,int borderColor) {
+
normal = new EmptyBorder(1,1,1,1);
- selected = new LineBorder(c2,-1,1,false,Graphics.DOTTED);
+ selected = new LineBorder(borderColor,-1,1,false,Graphics.DOTTED);
setBorder(normal);
- this.color=color;
+ this.color=backColor;
}
/**
* @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean) DefaultListCellRenderer.getListCellRendererComponent
Modified: SwingME/src/net/yura/mobile/gui/components/Button.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Button.java 2008-07-07 18:22:04 UTC (rev 19)
+++ SwingME/src/net/yura/mobile/gui/components/Button.java 2008-07-08 15:21:55 UTC (rev 20)
@@ -1,15 +1,19 @@
package net.yura.mobile.gui.components;
import javax.microedition.lcdui.Canvas;
+import javax.microedition.lcdui.Image;
import net.yura.mobile.gui.ActionListener;
import net.yura.mobile.util.ButtonGroup;
import net.yura.mobile.gui.CommandButton;
-import net.yura.mobile.gui.Font;
import net.yura.mobile.gui.DesktopPane;
import net.yura.mobile.gui.border.LineBorder;
import net.yura.mobile.gui.KeyEvent;
import net.yura.mobile.gui.border.Border;
+/**
+ * @author Yura Mamyrin
+ * @see javax.swing.JButton
+ */
public class Button extends Label implements ActionListener {
private static CommandButton selectButton = new CommandButton("Select","select");
@@ -31,34 +35,47 @@
private boolean useSelectButton;
- public Button(){
+ /**
+ * @see javax.swing.JButton#JButton() JButton.JButton
+ */
+ public Button() {
this(null);
}
+
+ /**
+ * @param label the text of the button
+ * @see javax.swing.JButton#JButton(java.lang.String) JButton.JButton
+ */
public Button(String label) {
- this(label,
- DesktopPane.getDefaultTheme().font,
- DesktopPane.getDefaultTheme().background,
- DesktopPane.getDefaultTheme().itemBorderColor,
- DesktopPane.getDefaultTheme().itemActiveBorderColor);
+ this(label,null);
}
- public Button(String label, Font font) {
+ /**
+ * @param label the text of the button
+ * @param img the Icon image to display on the button
+ * @see javax.swing.JButton#JButton(java.lang.String, javax.swing.Icon) JButton.JButton
+ */
+ public Button(String label, Image img) {
- this(label,font,0x00FFFFFF,0x00000000,0);
+ this(label,img,
+ DesktopPane.getDefaultTheme().background,
+ DesktopPane.getDefaultTheme().normalBorder,
+ DesktopPane.getDefaultTheme().activeBorder
+ );
}
// full constructor
- public Button(String label, Font font,int a,int b,int c) {
- super(label, font);
+ public Button(String label, Image img,int a,Border b,Border c) {
+ super(label, img);
background = a;
transparent = false;
- setBorder(new LineBorder(b));
- setActiveBorder(new LineBorder(c));
+ setBorder(b);
+ setActiveBorder(c);
selectable = true;
setForegroundByFontColorIndex(0);
Modified: SwingME/src/net/yura/mobile/gui/components/DropDownMenu.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/DropDownMenu.java 2008-07-07 18:22:04 UTC (rev 19)
+++ SwingME/src/net/yura/mobile/gui/components/DropDownMenu.java 2008-07-08 15:21:55 UTC (rev 20)
@@ -88,8 +88,8 @@
owner.setGlassPaneComponent(scroll);
pbuttons = new CommandButton[2];
- pbuttons[0]=owner.getPanelCommands()[0];
- pbuttons[1]=owner.getPanelCommands()[1];
+ pbuttons[0]=owner.getWindowCommands()[0];
+ pbuttons[1]=owner.getWindowCommands()[1];
owner.setWindowCommand(0, null);
owner.setWindowCommand(1, null);
Modified: SwingME/src/net/yura/mobile/gui/components/Label.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Label.java 2008-07-07 18:22:04 UTC (rev 19)
+++ SwingME/src/net/yura/mobile/gui/components/Label.java 2008-07-08 15:21:55 UTC (rev 20)
@@ -41,7 +41,7 @@
*/
public Label(String text) {
- this(text,DesktopPane.getDefaultTheme().font);
+ this(text,null);
}
@@ -65,12 +65,6 @@
this(text,DesktopPane.getDefaultTheme().font,icon);
}
-
- public Label(String text,Font f) {
-
- this(text,f,null);
-
- }
public Label(String text,Font f,Image icon) {
@@ -365,7 +359,9 @@
return DesktopPane.getDefaultTheme().defaultWidth;
}
-
+ /**
+ * @deprecated
+ */
public void setForegroundByFontColorIndex(int a) {
if (a < font.getColors().length ) {
Modified: SwingME/src/net/yura/mobile/gui/components/Spinner.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Spinner.java 2008-07-07 18:22:04 UTC (rev 19)
+++ SwingME/src/net/yura/mobile/gui/components/Spinner.java 2008-07-08 15:21:55 UTC (rev 20)
@@ -8,11 +8,10 @@
import net.yura.mobile.gui.DesktopPane;
import net.yura.mobile.gui.KeyEvent;
+import net.yura.mobile.gui.border.Border;
import net.yura.mobile.util.Option;
public class Spinner extends Label {
-
- private static final int lineTickness = 1;
private Image selectedImage;
private Image nonSelectedImage;
@@ -21,8 +20,8 @@
private Vector list;
- private int borderColor;
- private int activeBorderColor;
+ private Border borderColor;
+ private Border activeBorderColor;
private boolean continuous = false;
@@ -40,8 +39,8 @@
setForegroundByFontColorIndex(0);
- borderColor = DesktopPane.getDefaultTheme().itemBorderColor;
- activeBorderColor = DesktopPane.getDefaultTheme().itemActiveBorderColor;
+ borderColor = DesktopPane.getDefaultTheme().normalBorder;
+ activeBorderColor = DesktopPane.getDefaultTheme().activeBorder;
selectable = true;
@@ -74,8 +73,8 @@
}
- int w = maxWidth + getArrowWidth()*2 + gap*2 + lineTickness*2 + padding*2;
- int h = maxHeight + lineTickness*2 + padding*2;
+ int w = maxWidth + getArrowWidth()*2 + gap*2 + borderColor.getLeft() + borderColor.getRight() + padding*2;
+ int h = maxHeight + borderColor.getTop() + borderColor.getBottom() + padding*2;
if (w > width) width = w;
if (h > height) height = h;
@@ -142,14 +141,13 @@
int arrowWidth = getArrowWidth();
- if (isFocused()){
- g.setColor(activeBorderColor);
- }
- else{
- g.setColor(borderColor);
- }
- g.drawRect(arrowWidth+gap, 0, width -gap*2 - arrowWidth*2 -lineTickness, height-lineTickness);
+ Border b = isFocused()?activeBorderColor:borderColor;
+ g.translate(arrowWidth+gap+borderColor.getLeft(), borderColor.getTop());
+ b.paintBorder(this, g, width -gap*2 - arrowWidth*2 -borderColor.getLeft() - borderColor.getRight(), height-borderColor.getTop() - borderColor.getBottom());
+ g.translate(-arrowWidth-gap-borderColor.getLeft(), -borderColor.getTop());
+
+
if (nonSelectedImage != null) {
// TODO: Finish
@@ -161,18 +159,18 @@
int arrowHeight = getFont().getHeight();
if (leftPress){
- g.setColor(activeBorderColor);
+ g.setColor(0);
}
else{
- g.setColor(borderColor);
+ g.setColor(0x00808080);
}
ScrollPane.drawLeftArrow(g, 0, (height-arrowHeight)/2, arrowWidth, arrowHeight);
if (rightPress){
- g.setColor(activeBorderColor);
+ g.setColor(0);
}
else{
- g.setColor(borderColor);
+ g.setColor(0x00808080);
}
ScrollPane.drawRightArrow(g, width-arrowWidth, (height-arrowHeight)/2, arrowWidth, arrowHeight);
}
@@ -180,18 +178,18 @@
int xoffset = 0;
if (horizontalAlignment==Graphics.LEFT) {
- xoffset = arrowWidth+gap+lineTickness;
+ xoffset = arrowWidth+gap+borderColor.getLeft();
}
else if (horizontalAlignment==Graphics.RIGHT) {
- xoffset = -arrowWidth-gap-lineTickness;
+ xoffset = -arrowWidth-gap-borderColor.getRight();
}
int yoffset=0;
if (verticalAlignment==Graphics.TOP) {
- yoffset = lineTickness;
+ yoffset = borderColor.getTop();
}
else if (verticalAlignment==Graphics.BOTTOM) {
- yoffset = -lineTickness;
+ yoffset = -borderColor.getBottom();
}
g.translate(xoffset, yoffset);
@@ -233,7 +231,7 @@
}
public int getMaxTextWidth() {
- return width - getArrowWidth()*2 - gap*2 - lineTickness*2 - padding*2;
+ return width - getArrowWidth()*2 - gap*2 - borderColor.getLeft() - borderColor.getRight() - padding*2;
}
public void focusLost() {
@@ -246,19 +244,19 @@
repaint();
}
- public int getActiveBorderColor() {
+ public Border getActiveBorder() {
return activeBorderColor;
}
- public void setActiveBorderColor(int activeBorderColor) {
+ public void setActiveBorder(Border activeBorderColor) {
this.activeBorderColor = activeBorderColor;
}
- public int getBorderColor() {
+ public Border getNormalBorder() {
return borderColor;
}
- public void setBorderColor(int borderColor) {
+ public void setNormalBorderColor(Border borderColor) {
this.borderColor = borderColor;
}
Modified: SwingME/src/net/yura/mobile/gui/components/TextField.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/TextField.java 2008-07-07 18:22:04 UTC (rev 19)
+++ SwingME/src/net/yura/mobile/gui/components/TextField.java 2008-07-08 15:21:55 UTC (rev 20)
@@ -13,6 +13,7 @@
import net.yura.mobile.gui.KeyEvent;
import net.yura.mobile.gui.DesktopPane;
import net.yura.mobile.gui.border.LineBorder;
+import net.yura.mobile.gui.border.Border;
public class TextField extends Component implements ActionListener, CommandListener {
@@ -41,8 +42,8 @@
private String label;
private int mode;
- private int borderColor;
- private int activeBorderColor;
+ private Border borderColor;
+ private Border activeBorderColor;
private int activeTextColor;
private StringBuffer text;
@@ -79,10 +80,10 @@
setBackground(DesktopPane.getDefaultTheme().background);
setForeground(DesktopPane.getDefaultTheme().foreground);
- borderColor = DesktopPane.getDefaultTheme().itemBorderColor;
- activeBorderColor = DesktopPane.getDefaultTheme().itemActiveBorderColor;
+ borderColor = DesktopPane.getDefaultTheme().normalBorder;
+ activeBorderColor = DesktopPane.getDefaultTheme().activeBorder;
- setBorder(new LineBorder(borderColor));
+ setBorder(borderColor);
if (font.getColors().length >1) {
activeTextColor = font.getColors()[1];
@@ -347,10 +348,7 @@
public void focusLost() {
- if (border instanceof LineBorder) {
-
- ((LineBorder)border).setLineColor(borderColor);
- }
+ setBorder(borderColor);
active = false;
showCaret = false;
@@ -365,10 +363,7 @@
public void focusGained() {
- if (border instanceof LineBorder) {
-
- ((LineBorder)border).setLineColor(activeBorderColor);
- }
+ setBorder(activeBorderColor);
active = true;
showCaret = true;
@@ -419,10 +414,6 @@
mode = m;
}
- public void setBorderColor(int color) {
- borderColor = color;
- }
-
public int getLength() {
return text.length();
}
Modified: SwingME/src/net/yura/mobile/gui/components/Window.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Window.java 2008-07-07 18:22:04 UTC (rev 19)
+++ SwingME/src/net/yura/mobile/gui/components/Window.java 2008-07-08 15:21:55 UTC (rev 20)
@@ -17,6 +17,7 @@
private Panel contentPane;
private Panel glasspanecomponent;
+ private CommandButton[] panelCmds;
private ActionListener actionListener;
public ActionListener getActionListener() {
@@ -304,17 +305,13 @@
public void paintComponent(Graphics g) { }
-
-
- public CommandButton[] panelCmds;
+ public CommandButton[] getWindowCommands() {
+ return panelCmds;
+ }
- public CommandButton[] getPanelCommands(){
- return panelCmds;
- }
-
- /**
- * @see DesktopPane#setComponentCommand
- */
+ /**
+ * @see DesktopPane#setComponentCommand
+ */
public void setWindowCommand(int i, CommandButton softkey) {
panelCmds[i] = softkey;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|