diff --git a/.classpath b/.classpath
deleted file mode 100644
index 01bbadf..0000000
--- a/.classpath
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
Item to trigger an action + * @author StefanKrupop + */ +public class ActionMenuItem extends AbstractMenuItem +{ + public enum MenuResult { + /** + * Menu stays as it is + */ + None("none"), + /** + * Menu closes and returns to a higher level + */ + Close("close"), + /** + * Quits the menu completely + */ + Quit("quit"); + + public String val; + + MenuResult(String val) { + this.val = val; + } + } + + private MenuResult _menuResult; + + /** + * Constructor. + * @param id the of the action. + * @param menu the Submenu that knows about this MenuItem. + */ + protected ActionMenuItem(String id, Submenu menu) + { + super(id, menu); + _menuResult = MenuResult.None; + } + + /** + * Get the menu item type. + * @return the menu item type. + */ + public String getType() + { + return MENUITEM_ACTION; + } + + /** + * Sets what to do with the menu when this action is selected + * @param result the MenuResult + */ + public void setMenuResult(MenuResult result) { + _menuResult = result; + update(); + } + + @Override + public String getData() { + return super.getData() + " -menu_result " + _menuResult.val; + } + + /** + * Construct a new ActionMenuItem. + * @param menu the Submenu that owns the menu item. + * @param text the menu text. + * @return a new ActionMenuItem. + */ + public static ActionMenuItem construct(Submenu menu, String text) + { + return construct(menu, text, MenuResult.None); + } + + /** + * Construct a new ActionMenuItem. + * @param menu the Submenu that owns the menu item. + * @param text the menu text. + * @param result the MenuResult defining what to do when action is selected + * @return a new ActionMenuItem. + */ + public static ActionMenuItem construct(Submenu menu, String text, MenuResult result) + { + ActionMenuItem menuItem = null; + + try + { + menuItem = (ActionMenuItem)menu.constructMenuItem(MENUITEM_ACTION); + menuItem.setMenuResult(result); + menuItem.setText(text); + } + catch (LCDException e) //NOPMD + { + // Supress, would only get one if we asked for an invalid menu item. + } + + return menuItem; + } + + /** + * Adds an ActionListener to the menu item. + * @param listener the ActionListener to be added + */ + public void addActionListener(ActionListener listener) { + _listeners.add(ActionListener.class, listener); + } + + /** + * Removes an ActionListener from the menu item. + * @param listener the ActionListener to be removed + */ + public void removeActionListener(ActionListener listener) { + _listeners.remove(ActionListener.class, listener); + } + + public void notifyActionPerformed(ActionEvent e) { + for (ActionListener l : _listeners.getListeners(ActionListener.class)) { + l.actionPerformed(e); + } + } +} + diff --git a/src/main/java/org/lcdproc/lcdjava/AlphaMenuItem.java b/src/main/java/org/lcdproc/lcdjava/AlphaMenuItem.java new file mode 100644 index 0000000..c133525 --- /dev/null +++ b/src/main/java/org/lcdproc/lcdjava/AlphaMenuItem.java @@ -0,0 +1,194 @@ +package org.lcdproc.lcdjava; + + + + +/** + * AlphaMenuItem. + *
Is visible as a text. When selected, a screen comes up that shows the + * current string value, that you can edit with the cursor keys and Enter. + * The string is ended by selecting a 'null' input character. After that the + * menu returns. + * @author StefanKrupop + */ +public class AlphaMenuItem extends AbstractMenuItem +{ + private String _value; + private int _minlength; + private int _maxlength; + private String _passwordchar; + private boolean _allowCaps; + private boolean _allowNonCaps; + private boolean _allowNumbers; + private String _allowedExtra; + + /** + * Constructor. + * @param id the of the action. + * @param menu the Submenu that knows about this MenuItem. + */ + protected AlphaMenuItem(String id, Submenu menu) + { + super(id, menu); + _value = ""; + _minlength = 0; + _maxlength = 10; + _passwordchar = ""; + _allowCaps = true; + _allowNonCaps = true; + _allowNumbers = true; + _allowedExtra = ""; + } + + /** + * Get the menu item type. + * @return the menu item type. + */ + public String getType() + { + return MENUITEM_ALPHA; + } + + /** + * Sets current value of the entry + * @param value current value + */ + public void setValue(String value) { + _value = value; + update(); + } + + /** + * Sets current value of the entry but does not send the change to LCDd + * @param value current value + */ + public void setValueNoUpdate(String value) { + _value = value; + } + + /** + * Gets the currently set value + * @return value current value + */ + public String getValue() { + return _value; + } + + /** + * Sets the minimum length of the string that can be entered + * @param value min length + */ + public void setMinLength(int value) { + _minlength = value; + update(); + } + + /** + * Sets the maximum length of the string that can be entered + * @param value max length + */ + public void setMaxLength(int value) { + _maxlength = value; + update(); + } + + /** + * Sets the character that should be displayed instead of typed characters + * @param value password character + */ + public void setPasswordChar(String value) { + _passwordchar = value; + update(); + } + + /** + * Sets if upper case characters can be entered + * @param value new state + */ + public void setAllowCaps(boolean value) { + _allowCaps = value; + update(); + } + + /** + * Sets if lower case characters can be entered + * @param value new state + */ + public void setAllowNonCaps(boolean value) { + _allowNonCaps = value; + update(); + } + + /** + * Sets if numbers can be entered + * @param value new state + */ + public void setAllowNumbers(boolean value) { + _allowNumbers = value; + update(); + } + + /** + * Sets additional characters that can be entered + * @param chars allowed characters + */ + public void setAllowExtra(String chars) { + _allowedExtra = chars; + update(); + } + + @Override + public String getData() { + StringBuilder strb = new StringBuilder(); + strb.append(super.getData()); + strb.append(" -value \""); + strb.append(_value); + strb.append("\" -minlength "); + strb.append(_minlength); + strb.append(" -maxlength "); + strb.append(_maxlength); + if (!_passwordchar.isEmpty()) { + strb.append(" -password_char \""); + strb.append(_passwordchar); + strb.append('"'); + } + strb.append(" -allow_caps "); + strb.append(_allowCaps ? "true" : "false"); + strb.append(" -allow_noncaps "); + strb.append(_allowNonCaps ? "true" : "false"); + strb.append(" -allow_numbers "); + strb.append(_allowNumbers ? "true" : "false"); + if (!_allowedExtra.isEmpty()) { + strb.append(" -allowed_extra \""); + strb.append(_allowedExtra); + strb.append('"'); + } + + return strb.toString(); + } + + /** + * Construct a new AlphaMenuItem. + * @param menu the Submenu that owns the menu item. + * @param text the menu text. + * @param current the current string + * @return a new AlphaMenuItem. + */ + public static AlphaMenuItem construct(Submenu menu, String text, String current) + { + AlphaMenuItem menuItem = null; + + try + { + menuItem = (AlphaMenuItem)menu.constructMenuItem(MENUITEM_ALPHA); + menuItem.setValue(current); + menuItem.setText(text); + } + catch (LCDException e) //NOPMD + { + // Supress, would only get one if we asked for an invalid menu item. + } + + return menuItem; + } +} diff --git a/src/org/boncey/lcdjava/BarWidget.java b/src/main/java/org/lcdproc/lcdjava/BarWidget.java similarity index 82% rename from src/org/boncey/lcdjava/BarWidget.java rename to src/main/java/org/lcdproc/lcdjava/BarWidget.java index c54135e..4a45d7b 100644 --- a/src/org/boncey/lcdjava/BarWidget.java +++ b/src/main/java/org/lcdproc/lcdjava/BarWidget.java @@ -1,6 +1,4 @@ -package org.boncey.lcdjava; - -import org.apache.log4j.Logger; +package org.lcdproc.lcdjava; /** * Abstract Widget for displaying Bars. @@ -8,7 +6,7 @@ * @author Darren Greaves * @version $Id: BarWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $ */ -public abstract class BarWidget extends PositionalWidget +public abstract class BarWidget extends PositionalWidget { /** * Version details. @@ -17,11 +15,6 @@ public abstract class BarWidget extends PositionalWidget "$Id: BarWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $"; /** - * Logger for log4j. - */ - private static Logger _log = Logger.getLogger(LCD.class); - - /** * The length of the Widget. */ private int _length; @@ -46,7 +39,7 @@ public void setLength(int length) update(); } - /** + /** * Get the Widget length. * @return the Widget length. */ @@ -55,7 +48,7 @@ public int getLength() return _length; } - /** + /** * Return the data this Widget needs to update itself. * @return the data to update this Widget. */ diff --git a/src/main/java/org/lcdproc/lcdjava/CheckboxMenuItem.java b/src/main/java/org/lcdproc/lcdjava/CheckboxMenuItem.java new file mode 100644 index 0000000..2330571 --- /dev/null +++ b/src/main/java/org/lcdproc/lcdjava/CheckboxMenuItem.java @@ -0,0 +1,141 @@ +package org.lcdproc.lcdjava; + + + + +/** + * CheckboxnMenuItem. + *
Item to display a slectable status indicator + * @author StefanKrupop + */ +public class CheckboxMenuItem extends AbstractMenuItem +{ + public enum CheckboxValue { + /** + * Off + */ + Off("off"), + /** + * On + */ + On("on"), + /** + * Grayed out + */ + Gray("gray"); + + public String val; + + CheckboxValue(String val) { + this.val = val; + } + } + + private CheckboxValue _value; + private boolean _allowGray; + + /** + * Constructor. + * @param id the of the action. + * @param menu the Submenu that knows about this MenuItem. + */ + protected CheckboxMenuItem(String id, Submenu menu) + { + super(id, menu); + _allowGray = false; + _value = CheckboxValue.Off; + } + + /** + * Get the menu item type. + * @return the menu item type. + */ + public String getType() + { + return MENUITEM_CHECKBOX; + } + + /** + * Sets if a grayed checkbox is allowed + * @param allowGray whether grayed checkbox is allowed + */ + public void setAllowGray(boolean allowGray) { + _allowGray = allowGray; + update(); + } + + /** + * Sets current value of a checkbox + * @param value current status + */ + public void setValue(CheckboxValue value) { + _value = value; + update(); + } + + /** + * Sets current value of a checkbox but does not send the change to LCDd + * @param value current status + */ + public void setValueNoUpdate(CheckboxValue value) { + _value = value; + } + + /** + * Gets the current status of the checkbox + * @return status of the checkbox + */ + public CheckboxValue getValue() { + return _value; + } + + /** + * Gets the current status of the checkbox + * @return whether the checkbox is On + */ + public boolean isSelected() { + return _value.equals(CheckboxValue.On); + } + + @Override + public String getData() { + return super.getData() + " -value " + _value.val + " -allow_gray " + (_allowGray ? "true" : "false"); + } + + /** + * Construct a new CheckboxMenuItem. + * @param menu the Submenu that owns the menu item. + * @param text the menu text. + * @return a new ActionMenuItem. + */ + public static CheckboxMenuItem construct(Submenu menu, String text) + { + return construct(menu, text, false); + } + + /** + * Construct a new ActionMenuItem. + * @param menu the Submenu that owns the menu item. + * @param text the menu text. + * @param allowGray whether the "Gray" state is allowed + * @return a new ActionMenuItem. + */ + public static CheckboxMenuItem construct(Submenu menu, String text, boolean allowGray) + { + CheckboxMenuItem menuItem = null; + + try + { + menuItem = (CheckboxMenuItem)menu.constructMenuItem(MENUITEM_CHECKBOX); + menuItem.setAllowGray(allowGray); + menuItem.setText(text); + } + catch (LCDException e) //NOPMD + { + // Supress, would only get one if we asked for an invalid menu item. + } + + return menuItem; + } +} + diff --git a/src/org/boncey/lcdjava/HBarWidget.java b/src/main/java/org/lcdproc/lcdjava/HBarWidget.java similarity index 87% rename from src/org/boncey/lcdjava/HBarWidget.java rename to src/main/java/org/lcdproc/lcdjava/HBarWidget.java index bb9a50d..79c7057 100644 --- a/src/org/boncey/lcdjava/HBarWidget.java +++ b/src/main/java/org/lcdproc/lcdjava/HBarWidget.java @@ -1,6 +1,4 @@ -package org.boncey.lcdjava; - -import org.apache.log4j.Logger; +package org.lcdproc.lcdjava; /** * Horizontal Bar Widget. @@ -9,7 +7,7 @@ * @author Darren Greaves * @version $Id: HBarWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $ */ -public class HBarWidget extends BarWidget +public class HBarWidget extends BarWidget { /** * Version details. @@ -17,11 +15,6 @@ public class HBarWidget extends BarWidget public static final String CVSID = "$Id: HBarWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $"; - /** - * Logger for log4j. - */ - private static Logger _log = Logger.getLogger(LCD.class); - /** * Constructor. * @param id the of the Widget. @@ -32,7 +25,7 @@ protected HBarWidget(int id, Screen screen) super(id, screen); } - /** + /** * Get the Widget type. * @return the Widget type. */ @@ -41,7 +34,7 @@ public String getType() return Widget.WIDGET_HBAR; } - /** + /** * Construct a new HBarWidget. * @param screen the Screen that owns the Widget. * @param x the x position. diff --git a/src/org/boncey/lcdjava/IconWidget.java b/src/main/java/org/lcdproc/lcdjava/IconWidget.java similarity index 88% rename from src/org/boncey/lcdjava/IconWidget.java rename to src/main/java/org/lcdproc/lcdjava/IconWidget.java index 9c7151d..8ccdfe6 100644 --- a/src/org/boncey/lcdjava/IconWidget.java +++ b/src/main/java/org/lcdproc/lcdjava/IconWidget.java @@ -1,6 +1,4 @@ -package org.boncey.lcdjava; - -import org.apache.log4j.Logger; +package org.lcdproc.lcdjava; /** * Icon Widget. @@ -9,7 +7,7 @@ * @author Darren Greaves * @version $Id: IconWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $ */ -public class IconWidget extends PositionalWidget +public class IconWidget extends PositionalWidget { /** * Version details. @@ -17,118 +15,113 @@ public class IconWidget extends PositionalWidget public static final String CVSID = "$Id: IconWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $"; - /** - * Logger for log4j. - */ - private static Logger _log = Logger.getLogger(LCD.class); - - /** + /** * A predefined icon. */ public static final String ICON_BLOCK_FILLED = "BLOCK_FILLED"; - /** + /** * A predefined icon. */ public static final String ICON_HEART_OPEN = "HEART_OPEN"; - /** + /** * A predefined icon. */ public static final String ICON_HEART_FILLED = "HEART_FILLED"; - /** + /** * A predefined icon. */ public static final String ICON_ARROW_UP = "ARROW_UP"; - /** + /** * A predefined icon. */ public static final String ICON_ARROW_DOWN = "ARROW_DOWN"; - /** + /** * A predefined icon. */ public static final String ICON_ARROW_LEFT = "ARROW_LEFT"; - /** + /** * A predefined icon. */ public static final String ICON_ARROW_RIGHT = "ARROW_RIGHT"; - /** + /** * A predefined icon. */ public static final String ICON_CHECKBOX_OFF = "CHECKBOX_OFF"; - /** + /** * A predefined icon. */ public static final String ICON_CHECKBOX_ON = "CHECKBOX_ON"; - /** + /** * A predefined icon. */ public static final String ICON_CHECKBOX_GRAY = "CHECKBOX_GRAY"; - /** + /** * A predefined icon. */ public static final String ICON_SELECTOR_AT_LEFT = "SELECTOR_AT_LEFT"; - /** + /** * A predefined icon. */ public static final String ICON_SELECTOR_AT_RIGHT = "SELECTOR_AT_RIGHT"; - /** + /** * A predefined icon. */ public static final String ICON_ELLIPSIS = "ELLIPSIS"; - /** + /** * A predefined icon. */ public static final String ICON_PAUSE = "PAUSE"; - /** + /** * A predefined icon. */ public static final String ICON_PLAY = "PLAY"; - /** + /** * A predefined icon. */ public static final String ICON_PLAYR = "PLAYR"; - /** + /** * A predefined icon. */ public static final String ICON_FF = "FF"; - /** + /** * A predefined icon. */ public static final String ICON_FR = "FR"; - /** + /** * A predefined icon. */ public static final String ICON_NEXT = "NEXT"; - /** + /** * A predefined icon. */ public static final String ICON_PREV = "PREV"; - /** + /** * A predefined icon. */ public static final String ICON_REC = "REC"; - /** + /** * The Widget iconName. */ private String _iconName; @@ -143,13 +136,13 @@ protected IconWidget(int id, Screen screen) super(id, screen); } - /** + /** * Get the Widget type. * @return the Widget type. */ public String getType() { - return Widget.WIDGET_ICON; + return WIDGET_ICON; } /** @@ -162,7 +155,7 @@ public void setText(String iconName) update(); } - /** + /** * Get the Widget iconName. * @return the Widget iconName. */ @@ -171,7 +164,7 @@ public String getText() return _iconName; } - /** + /** * Return the data this Widget needs to update itself. * @return the data to update this Widget. */ @@ -180,7 +173,7 @@ public String getData() return super.getData() + "\"" + stripQuotes(_iconName) + "\""; } - /** + /** * Construct a new IconWidget. * @param screen the Screen that owns the Widget. * @param x the x position. @@ -197,7 +190,7 @@ public static IconWidget construct(Screen screen, try { - widget = (IconWidget)screen.constructWidget(Widget.WIDGET_ICON); + widget = (IconWidget)screen.constructWidget(WIDGET_ICON); widget.setX(x); widget.setY(y); widget.setText(iconName); diff --git a/src/main/java/org/lcdproc/lcdjava/IpMenuItem.java b/src/main/java/org/lcdproc/lcdjava/IpMenuItem.java new file mode 100644 index 0000000..f3d2a3f --- /dev/null +++ b/src/main/java/org/lcdproc/lcdjava/IpMenuItem.java @@ -0,0 +1,109 @@ +package org.lcdproc.lcdjava; + + + + +/** + * IpMenuItem. + *
Allows the user to input an IP number (v4 or v6). When selected, a + * screen comes up that shows an IP number that can be edited - digit by digit + * - via left/right (switch digit) and up/down keys (increase/decrease). + * @author StefanKrupop + */ +public class IpMenuItem extends AbstractMenuItem +{ + private String _value; + private boolean _v6; + + /** + * Constructor. + * @param id the of the action. + * @param menu the Submenu that knows about this MenuItem. + */ + protected IpMenuItem(String id, Submenu menu) + { + super(id, menu); + _value = ""; + _v6 = false; + } + + /** + * Get the menu item type. + * @return the menu item type. + */ + public String getType() + { + return MenuItem.MENUITEM_IP; + } + + /** + * Sets current value of the entry + * @param value current value + */ + public void setValue(String value) { + _value = value; + update(); + } + + /** + * Sets current value of the entry but does not send the change to LCDd + * @param value current value + */ + public void setValueNoUpdate(String value) { + _value = value; + } + + /** + * Gets the currently set ip + * @return value IP in string format + */ + public String getValue() { + return _value; + } + + /** + * Sets if this entry is for v6 IP addresses + * @param isV6 current value + */ + public void setV6(boolean isV6) { + _v6 = isV6; + update(); + } + + @Override + public String getData() { + StringBuilder strb = new StringBuilder(); + strb.append(super.getData()); + strb.append(" -value \""); + strb.append(_value); + strb.append("\" -v6 "); + strb.append(_v6 ? "true" : "false"); + + return strb.toString(); + } + + /** + * Construct a new IpMenuItem. + * @param menu the Submenu that owns the menu item. + * @param text the menu text. + * @param current the current IP + * @return a new IpMenuItem. + */ + public static IpMenuItem construct(Submenu menu, String text, String current) + { + IpMenuItem menuItem = null; + + try + { + menuItem = (IpMenuItem)menu.constructMenuItem(MenuItem.MENUITEM_IP); + menuItem.setValue(current); + menuItem.setText(text); + } + catch (LCDException e) //NOPMD + { + // Supress, would only get one if we asked for an invalid menu item. + } + + return menuItem; + } +} diff --git a/src/org/boncey/lcdjava/LCD.java b/src/main/java/org/lcdproc/lcdjava/LCD.java similarity index 64% rename from src/org/boncey/lcdjava/LCD.java rename to src/main/java/org/lcdproc/lcdjava/LCD.java index adda1a3..1d72e4a 100644 --- a/src/org/boncey/lcdjava/LCD.java +++ b/src/main/java/org/lcdproc/lcdjava/LCD.java @@ -1,5 +1,6 @@ -package org.boncey.lcdjava; +package org.lcdproc.lcdjava; +import java.awt.event.ActionEvent; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; @@ -10,7 +11,9 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.log4j.Logger; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Class to control access to an LCDproc LCDd daemon. @@ -26,28 +29,25 @@ public class LCD implements LCDListener public static final String CVSID = "$Id: LCD.java,v 1.3 2008-07-06 15:38:34 boncey Exp $"; - /** - * Logger for log4j. - */ - private static Logger _log = Logger.getLogger(LCD.class); + private static final Logger _log = LoggerFactory.getLogger(LCD.class); - /** + /** * How often to poll for changes. */ private static final int POLL = 100; - /** + /** * How many times to poll the server before giving up. */ - public static final int POLL_REPEAT = 30; + private static final int POLL_REPEAT = 30; - /** + /** * The pattern for matching a grouping of one or more numbers and . * characters. */ private static final String PATTERN_NUMERIC = "([\\d\\.]+)"; - /** + /** * The pattern for matching the server version. *
All numeric for stable, text for CVS version.
*/
@@ -64,67 +64,107 @@ public class LCD implements LCDListener
" cellwid " + PATTERN_NUMERIC +
" cellhgt " + PATTERN_NUMERIC;
- /**
+ /**
* The response from LCDd that indicates it didn't understand our command.
*/
public static final String RESPONSE_ERROR = "huh?";
- /**
+ /**
* The response from LCDd that indicates it is listening to a Screen.
*/
public static final String RESPONSE_IGNORE = "ignore";
- /**
+ /**
* The response from LCDd that indicates it is ignoring a Screen.
*/
public static final String RESPONSE_LISTEN = "listen";
- /**
+ /**
* The command to send to the server to initiate communication.
*/
private static final String CMD_INIT = "hello";
- /**
+ /**
* The command to send to the server to identify ourselves.
*/
- public static final String CMD_CLIENT_SET = "client_set -name lcdjava/1.0";
+ private static final String CMD_CLIENT_SET = "client_set -name ";
- /**
+ /**
* The command to send to the server to add a Screen.
*/
- public static final String CMD_SCREEN_ADD = "screen_add ";
+ private static final String CMD_SCREEN_ADD = "screen_add ";
- /**
+ /**
* The command to send to the server to set (modify) a Screen.
*/
- public static final String CMD_SCREEN_SET = "screen_set ";
+ private static final String CMD_SCREEN_SET = "screen_set ";
- /**
+ /**
* The command to send to the server to remove a Screen.
*/
- public static final String CMD_SCREEN_DEL = "screen_del ";
+ private static final String CMD_SCREEN_DEL = "screen_del ";
- /**
+ /**
* The command to send to the server to add a Widget.
*/
public static final String CMD_WIDGET_ADD = "widget_add ";
- /**
+ /**
* The command to send to the server to set (modify) a Widget.
*/
public static final String CMD_WIDGET_SET = "widget_set ";
- /**
+ /**
* The command to send to the server to remove a Widget.
*/
public static final String CMD_WIDGET_DEL = "widget_del ";
- /**
+ /**
+ * The command to send to the server to add a menu item.
+ */
+ public static final String CMD_MENU_ADD = "menu_add_item ";
+
+ /**
+ * The command to send to the server to remove a menu item.
+ */
+ public static final String CMD_MENU_DEL = "menu_del_item ";
+
+ /**
+ * The command to send to the server to set (modify) a MenuItem.
+ */
+ public static final String CMD_MENU_SET = "menu_set_item ";
+
+ /**
+ * The command to send to the server to set a menu as main menu
+ */
+ public static final String CMD_MENU_SET_MAIN = "menu_set_main ";
+
+ /**
+ * The response from LCDd that indicates an action menu item was selected.
+ */
+ private static final String EVENT_SELECT = "select";
+
+ /**
+ * The response from LCDd that indicates an menu item was updated.
+ */
+ private static final String EVENT_UPDATE = "update";
+
+ /**
+ * The response from LCDd that indicates a slider was moved to the right.
+ */
+ private static final String EVENT_PLUS = "plus";
+
+ /**
+ * The response from LCDd that indicates a slider was moved to the left.
+ */
+ private static final String EVENT_MINUS = "minus";
+
+ /**
* The protocol version that we know how to deal with.
*/
- public static final String PROTOCOL_VERSION = "0.3";
+ private static final String PROTOCOL_VERSION = "0.3";
- /**
+ /**
* This is the maximum data that can be sent at once.
* This is calculated from the following code in lcdproc-0.4.5/server/sock.c
* #define MAXMSG 8192
@@ -137,69 +177,74 @@ public class LCD implements LCDListener
*/
private static final int MAX_DATA_LENGTH = 7168;
- /**
+ /**
* The measurement of a LCD frame, documented as one eight of a
* second.
*/
public static final float FRAME = 0.125f;
- /**
+ /**
* The Socket used to talk and listen to the LCDd server.
*/
private Socket _socket;
- /**
+ /**
* The Writer we send all data to the server with.
*/
private BufferedWriter _out;
- /**
+ /**
* Thread that listens for responses from the server in a non-blocking
* manner.
*/
private LCDSocketPoller _poller;
- /**
+ /**
* The software version of LCDd.
*/
private String _version;
-
- /**
+
+ /**
* The protocol version.
*/
private String _protocolVersion;
-
- /**
+
+ /**
* The width in characters of the LCD device.
*/
private int _width;
-
- /**
+
+ /**
* The height in characters of the LCD device.
*/
private int _height;
-
- /**
+
+ /**
* The cell width of the LCD device.
*/
private int _cellWidth;
-
- /**
+
+ /**
* The cell height of the LCD device.
*/
private int _cellHeight;
- /**
+ /**
* The Map of Screens, indexed by the Screen id.
*/
- private Map _screens;
+ private final Map This is used internally to ensure Screens have unique ids.
*/
private int _screenCounter;
+ /**
+ * The root of the client's menu
+ */
+ private final Submenu _rootMenu;
+
/**
* Public constructor.
* @param host the LCDd host.
@@ -209,11 +254,25 @@ public class LCD implements LCDListener
public LCD(String host, int port)
throws LCDException
{
- _screens = new HashMap();
+ this(host, port, "lcdjava/1.0");
+ }
+
+ /**
+ * Public constructor.
+ * @param host the LCDd host.
+ * @param port the LCDd port.
+ * @param clientName the name of this client as shown to the user
+ * @throws LCDException if there was a problem connecting to the server.
+ */
+ public LCD(String host, int port, String clientName)
+ throws LCDException
+ {
+ _screens = new HashMap<>();
+ _rootMenu = new Submenu(this);
try
{
- String response = connect(host, port);
+ String response = connect(host, port, clientName);
if (response == null)
{
throw new LCDException(
@@ -239,7 +298,7 @@ else if (response.startsWith(RESPONSE_ERROR))
shutdown();
throw e;
}
-
+ _log.info("Connected");
}
/**
@@ -250,7 +309,7 @@ public String getVersion()
{
return _version;
}
-
+
/**
* Get the protocolVersion.
@@ -260,7 +319,7 @@ public String getProtocolVersion()
{
return _protocolVersion;
}
-
+
/**
* Get the width.
@@ -270,7 +329,7 @@ public int getWidth()
{
return _width;
}
-
+
/**
* Get the height.
@@ -280,7 +339,7 @@ public int getHeight()
{
return _height;
}
-
+
/**
* Get the cellWidth.
@@ -290,7 +349,7 @@ public int getCellWidth()
{
return _cellWidth;
}
-
+
/**
* Get the cellHeight.
@@ -301,7 +360,7 @@ public int getCellHeight()
return _cellHeight;
}
- /**
+ /**
* The listen/ignore state of a Screen has been notified to us by LCDd.
* @param screenId the id of the Screen.
* @param listening There is no need to call this, call {@link Screen#activate()} instead.
* @param screen the Screen to add.
*/
protected synchronized void addScreen(Screen screen)
{
- Integer id = new Integer(screen.getId());
+ Integer id = screen.getId();
if (!_screens.containsKey(id))
{
_screens.put(id, screen);
@@ -414,20 +547,20 @@ protected synchronized void addScreen(Screen screen)
}
}
- /**
+ /**
* Update this screen to the LCD server.
* @param screen the Screen to update.
*/
protected synchronized void updateScreen(Screen screen)
{
- Integer id = new Integer(screen.getId());
+ Integer id = screen.getId();
if (_screens.containsKey(id))
{
write(LCD.CMD_SCREEN_SET + screen.getData());
}
}
- /**
+ /**
* Remove a Screen from the server.
* @param screen the Screen to remove.
* @return the removed Screen, or null if not removed.
@@ -437,7 +570,7 @@ protected synchronized Screen removeScreen(Screen screen)
return removeScreen(screen.getId());
}
- /**
+ /**
* Remove a Screen from the server.
* @param screenId the Screen id to remove.
* @return the removed Screen, or null if not removed.
@@ -445,10 +578,14 @@ protected synchronized Screen removeScreen(Screen screen)
protected synchronized Screen removeScreen(int screenId)
{
write(CMD_SCREEN_DEL + screenId);
- return (Screen)_screens.remove(new Integer(screenId));
+ return _screens.remove(screenId);
}
- /**
+ public Submenu getRootMenu() {
+ return _rootMenu;
+ }
+
+ /**
* Parse the init string and split up into groups.
* @param init the init string.
* @throws LCDException if the protocol version is one we don't know about.
@@ -480,14 +617,15 @@ private void parseInitString(String init)
}
}
- /**
+ /**
* Connect to the LCDd server.
* @param host the hostname to connect to.
* @param port the port to connect to.
+ * @param clientName the name of this client as shown to the user
* @return the response from the server.
* @throws IOException in case of a network problem.
*/
- private String connect(String host, int port)
+ private String connect(String host, int port, String clientName)
throws IOException
{
_socket = new Socket(host, port);
@@ -496,8 +634,7 @@ private String connect(String host, int port)
_out = new BufferedWriter(new OutputStreamWriter(
_socket.getOutputStream()));
_poller = new LCDSocketPoller(in, this);
- Thread t = new Thread(_poller);
- t.start();
+ _poller.start();
write(CMD_INIT);
String response = null;
@@ -517,12 +654,12 @@ private String connect(String host, int port)
}
}
}
- write(CMD_CLIENT_SET);
+ write(CMD_CLIENT_SET + clientName);
return response;
}
- /**
+ /**
* Write the data to the server.
* @param text the text to write.
*/
@@ -542,7 +679,7 @@ protected void write(String text)
}
catch (IOException e)
{
- e.printStackTrace();
+ throw new LCDException(e);
}
}
diff --git a/src/org/boncey/lcdjava/LCDException.java b/src/main/java/org/lcdproc/lcdjava/LCDException.java
similarity index 85%
rename from src/org/boncey/lcdjava/LCDException.java
rename to src/main/java/org/lcdproc/lcdjava/LCDException.java
index ffdd1b1..3133245 100644
--- a/src/org/boncey/lcdjava/LCDException.java
+++ b/src/main/java/org/lcdproc/lcdjava/LCDException.java
@@ -1,4 +1,4 @@
-package org.boncey.lcdjava;
+package org.lcdproc.lcdjava;
/**
* Exception that wraps any Exceptions thrown when interacting with LCDProc.
@@ -6,20 +6,20 @@
* @author Darren Greaves.
* @version $Id: LCDException.java,v 1.2 2005-03-03 14:13:16 boncey Exp $
*/
-public class LCDException extends Exception
+public class LCDException extends RuntimeException
{
/**
* Version details.
*/
- public static final String CVSID =
+ public static final String CVSID =
"$Id: LCDException.java,v 1.2 2005-03-03 14:13:16 boncey Exp $";
-
+
/**
* Constructor.
* @param message The error message.
* @param t The wrapped exception.
- */
+ */
public LCDException(String message, Throwable t)
{
super(message, t);
@@ -29,7 +29,7 @@ public LCDException(String message, Throwable t)
/**
* Constructor.
* @param t The wrapped exception.
- */
+ */
public LCDException(Throwable t)
{
super(t);
@@ -39,7 +39,7 @@ public LCDException(Throwable t)
/**
* Constructor.
* @param message The error message.
- */
+ */
public LCDException(String message)
{
super(message);
diff --git a/src/org/boncey/lcdjava/LCDListener.java b/src/main/java/org/lcdproc/lcdjava/LCDListener.java
similarity index 61%
rename from src/org/boncey/lcdjava/LCDListener.java
rename to src/main/java/org/lcdproc/lcdjava/LCDListener.java
index 78486ce..f695774 100644
--- a/src/org/boncey/lcdjava/LCDListener.java
+++ b/src/main/java/org/lcdproc/lcdjava/LCDListener.java
@@ -1,7 +1,7 @@
-package org.boncey.lcdjava;
+package org.lcdproc.lcdjava;
/**
- * Interface for listening to the state of a Screen.
+ * Interface for listening to the state returned from LCDd.
* Copyright (c) 2004-2005 Darren Greaves.
* @author Darren Greaves
* @version $Id: LCDListener.java,v 1.2 2005-03-03 14:13:16 boncey Exp $
@@ -21,5 +21,13 @@ public interface LCDListener
* Copyright (c) 2004-2005 Darren Greaves.
+ * @author Darren Greaves
+ * @version $Id: LCDSocketPoller.java,v 1.3 2008-07-06 15:38:34 boncey Exp $
+ */
+public class LCDSocketPoller extends Thread
+{
+ /**
+ * Version details.
+ */
+ public static final String CVSID =
+ "$Id: LCDSocketPoller.java,v 1.3 2008-07-06 15:38:34 boncey Exp $";
+
+ private static Logger _log = LoggerFactory.getLogger(LCDSocketPoller.class);
+
+ /**
+ * How often to poll for changes.
+ */
+ private static final int POLL = 100;
+
+ /**
+ * The Pattern that matches ignore/listen events.
+ */
+ private static final Pattern IGNORE_STATUS = Pattern.compile(
+ "(ignore|listen)\\s+(\\d+).*");
+
+ /**
+ * The Pattern that matches menu events.
+ */
+ private static final Pattern MENU_STATUS = Pattern.compile(
+ "menuevent\\s+(\\w+)\\s+(\\w+)\\s*(.*)");
+
+ /**
+ * The Reader to read data from.
+ */
+ private BufferedReader _in;
+
+ /**
+ * The last line of data received.
+ * Will be null if no data was received.
+ */
+ private String _lastLine;
+
+ /**
+ * The listener to notify of listen/ignore events.
+ */
+ private LCDListener _listener;
+
+ /**
+ * Public constructor.
+ * @param in the BufferedReader that will recieve data from the server.
+ * @param listener the LCDListener that gets notified of screens being
+ * listened to or ignored.
+ */
+ public LCDSocketPoller(BufferedReader in, LCDListener listener)
+ {
+ _in = in;
+ _listener = listener;
+ }
+
+ /**
+ * Poll the socket every 100 milliseconds.
+ */
+ @Override
+ public void run()
+ {
+ while (!interrupted())
+ {
+ try {
+ if (!_in.ready()) {
+ Thread.sleep(POLL);
+ }
+ if (_in.ready())
+ {
+ _lastLine = _in.readLine();
+ if (_lastLine == null)
+ continue;
+ Matcher listenIgnore = IGNORE_STATUS.matcher(_lastLine);
+ Matcher menuEvent = MENU_STATUS.matcher(_lastLine);
+ if (_lastLine.startsWith(LCD.RESPONSE_ERROR))
+ {
+ _log.warn("Got a response of " + _lastLine +
+ " from server");
+ }
+ else if (_listener != null)
+ {
+
+ if (listenIgnore.matches())
+ {
+ boolean listen = (LCD.RESPONSE_LISTEN.equals(
+ listenIgnore.group(1)));
+ try
+ {
+ int screenId = Integer.parseInt(listenIgnore.group(2));
+ _listener.setListenStatus(screenId, listen);
+ }
+ catch (NumberFormatException e)
+ {
+ // Ignore
+ }
+ }
+ else if (menuEvent.matches())
+ {
+ _listener.menuAction(menuEvent.group(2), menuEvent.group(1), menuEvent.group(3));
+ }
+ }
+ }
+ }
+ catch (InterruptedException e)
+ {
+ interrupt();
+ }
+ catch (IOException e)
+ {
+ _log.error("Caught IOException", e);
+ }
+ }
+
+ _log.debug("Terminating");
+ }
+
+ /**
+ * Get the last line received non-blocking.
+ * Calling this clears the last line received.
+ * @return the last line received.
+ */
+ synchronized String getLastLine()
+ {
+ String ret = _lastLine;
+ _lastLine = null;
+ return ret;
+ }
+}
diff --git a/src/main/java/org/lcdproc/lcdjava/MenuItem.java b/src/main/java/org/lcdproc/lcdjava/MenuItem.java
new file mode 100644
index 0000000..facf998
--- /dev/null
+++ b/src/main/java/org/lcdproc/lcdjava/MenuItem.java
@@ -0,0 +1,78 @@
+package org.lcdproc.lcdjava;
+
+
+/**
+ * Interface for menu items.
+ * @author Stefan Krupop
+ */
+public interface MenuItem
+{
+ /**
+ * The name of the action item.
+ */
+ public static final String MENUITEM_ACTION = "action";
+
+ /**
+ * The name of the checkbox item.
+ */
+ public static final String MENUITEM_CHECKBOX = "checkbox";
+
+ /**
+ * The name of the ring item.
+ */
+ public static final String MENUITEM_RING = "ring";
+
+ /**
+ * The name of the slider item.
+ */
+ public static final String MENUITEM_SLIDER = "slider";
+
+ /**
+ * The name of the numeric item.
+ */
+ public static final String MENUITEM_NUMERIC = "numeric";
+
+ /**
+ * The name of the alpha item.
+ */
+ public static final String MENUITEM_ALPHA = "alpha";
+
+ /**
+ * The name of the IP item.
+ */
+ public static final String MENUITEM_IP = "ip";
+
+ /**
+ * The name of the menu item.
+ */
+ public static final String MENUITEM_MENU = "menu";
+
+ /**
+ * Get the menu id.
+ * @return the menu id.
+ */
+ public String getID();
+
+ /**
+ * Get the menu type.
+ * @return the menu type.
+ */
+ public String getType();
+
+ /**
+ * Return the data this item needs to update itself.
+ * @return the data to update this item.
+ */
+ public String getData();
+
+ /**
+ * Add this item to the Menu.
+ * @return whether or not the item was added successfully.
+ */
+ public boolean activate();
+
+ /**
+ * Remove this item.
+ */
+ public void remove();
+}
diff --git a/src/org/boncey/lcdjava/NumWidget.java b/src/main/java/org/lcdproc/lcdjava/NumWidget.java
similarity index 89%
rename from src/org/boncey/lcdjava/NumWidget.java
rename to src/main/java/org/lcdproc/lcdjava/NumWidget.java
index a81c59f..640546a 100644
--- a/src/org/boncey/lcdjava/NumWidget.java
+++ b/src/main/java/org/lcdproc/lcdjava/NumWidget.java
@@ -1,6 +1,4 @@
-package org.boncey.lcdjava;
-
-import org.apache.log4j.Logger;
+package org.lcdproc.lcdjava;
/**
* Number Widget.
@@ -9,7 +7,7 @@
* @author Darren Greaves
* @version $Id: NumWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $
*/
-public class NumWidget extends AbstractWidget
+public class NumWidget extends AbstractWidget
{
/**
* Version details.
@@ -18,16 +16,11 @@ public class NumWidget extends AbstractWidget
"$Id: NumWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $";
/**
- * Logger for log4j.
- */
- private static Logger _log = Logger.getLogger(LCD.class);
-
- /**
* The Widget number.
*/
private int _number;
- /**
+ /**
* The x position.
*/
private int _x = 1;
@@ -42,7 +35,7 @@ protected NumWidget(int id, Screen screen)
super(id, screen);
}
- /**
+ /**
* Get the Widget type.
* @return the Widget type.
*/
@@ -79,7 +72,7 @@ public void setNumber(int number)
update();
}
- /**
+ /**
* Get the Widget number.
* @return the Widget number.
*/
@@ -88,7 +81,7 @@ public int getNumber()
return _number;
}
- /**
+ /**
* Return the data this Widget needs to update itself.
* @return the data to update this Widget.
*/
@@ -97,7 +90,7 @@ public String getData()
return _x + " " + _number;
}
- /**
+ /**
* Construct a new NumWidget.
* @param screen the Screen that owns the Widget.
* @param x the x position.
diff --git a/src/main/java/org/lcdproc/lcdjava/NumericMenuItem.java b/src/main/java/org/lcdproc/lcdjava/NumericMenuItem.java
new file mode 100644
index 0000000..0acaf25
--- /dev/null
+++ b/src/main/java/org/lcdproc/lcdjava/NumericMenuItem.java
@@ -0,0 +1,149 @@
+package org.lcdproc.lcdjava;
+
+
+
+
+/**
+ * NumericMenuItem.
+ * Allows the user to input an integer value. Is visible as a text. When
+ * selected, a screen comes up that shows the current numeric value, that you
+ * can edit with the cursor keys and Enter. The number is ended by selecting
+ * a 'null' input digit. After that the menu returns.
+ * @author StefanKrupop
+ */
+public class NumericMenuItem extends AbstractMenuItem
+{
+ private int _value;
+ private int _minvalue;
+ private int _maxvalue;
+
+ /**
+ * Constructor.
+ * @param id the of the action.
+ * @param menu the Submenu that knows about this MenuItem.
+ */
+ protected NumericMenuItem(String id, Submenu menu)
+ {
+ super(id, menu);
+ _value = 0;
+ _minvalue = 0;
+ _maxvalue = 100;
+ }
+
+ /**
+ * Get the menu item type.
+ * @return the menu item type.
+ */
+ public String getType()
+ {
+ return MENUITEM_NUMERIC;
+ }
+
+ /**
+ * Sets current value of the entry
+ * @param value current value
+ */
+ public void setValue(int value) {
+ if (value >= _minvalue && value <= _maxvalue) {
+ _value = value;
+ update();
+ }
+ }
+
+ /**
+ * Sets current value of the entry but does not send the change to LCDd
+ * @param value current value
+ */
+ public void setValueNoUpdate(int value) {
+ if (value >= _minvalue && value <= _maxvalue) {
+ _value = value;
+ }
+ }
+
+ /**
+ * Gets the current value of the entry
+ * @return value of the entry
+ */
+ public int getValue() {
+ return _value;
+ }
+
+ /**
+ * Sets minimum value of the entry
+ * @param value min value
+ */
+ public void setMinValue(int value) {
+ _minvalue = value;
+ if (_value < _minvalue) {
+ _value = _minvalue;
+ }
+ if (_minvalue <= _maxvalue) {
+ update();
+ }
+ }
+
+ /**
+ * Sets maximum value of the entry
+ * @param value max value
+ */
+ public void setMaxValue(int value) {
+ _maxvalue = value;
+ if (_value > _maxvalue) {
+ _value = _maxvalue;
+ }
+ if (_maxvalue >= _minvalue) {
+ update();
+ }
+ }
+
+ @Override
+ public String getData() {
+ StringBuilder strb = new StringBuilder();
+ strb.append(super.getData());
+ strb.append(" -value ");
+ strb.append(_value);
+ strb.append(" -minvalue ");
+ strb.append(_minvalue);
+ strb.append(" -maxvalue ");
+ strb.append(_maxvalue);
+ return strb.toString();
+ }
+
+ /**
+ * Construct a new NumericMenuItem.
+ * @param menu the Submenu that owns the menu item.
+ * @param text the menu text.
+ * @return a new NumericMenuItem.
+ */
+ public static NumericMenuItem construct(Submenu menu, String text)
+ {
+ return construct(menu, text, 0, 100);
+ }
+
+ /**
+ * Construct a new NumericMenuItem.
+ * @param menu the Submenu that owns the menu item.
+ * @param text the menu text.
+ * @param minValue the minimum value of the entry
+ * @param maxValue the maximum value of the entry
+ * @return a new NumericMenuItem.
+ */
+ public static NumericMenuItem construct(Submenu menu, String text, int minValue, int maxValue)
+ {
+ NumericMenuItem menuItem = null;
+
+ try
+ {
+ menuItem = (NumericMenuItem)menu.constructMenuItem(MENUITEM_NUMERIC);
+ menuItem.setText(text);
+ menuItem.setMinValue(minValue);
+ menuItem.setMaxValue(maxValue);
+ }
+ catch (LCDException e) //NOPMD
+ {
+ // Supress, would only get one if we asked for an invalid menu item.
+ }
+
+ return menuItem;
+ }
+}
diff --git a/src/org/boncey/lcdjava/PositionalWidget.java b/src/main/java/org/lcdproc/lcdjava/PositionalWidget.java
similarity index 85%
rename from src/org/boncey/lcdjava/PositionalWidget.java
rename to src/main/java/org/lcdproc/lcdjava/PositionalWidget.java
index f8390ce..4475c7a 100644
--- a/src/org/boncey/lcdjava/PositionalWidget.java
+++ b/src/main/java/org/lcdproc/lcdjava/PositionalWidget.java
@@ -1,6 +1,4 @@
-package org.boncey.lcdjava;
-
-import org.apache.log4j.Logger;
+package org.lcdproc.lcdjava;
/**
* Abstract Widget that deals with x and y dimensions.
@@ -8,7 +6,7 @@
* @author Darren Greaves
* @version $Id: PositionalWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $
*/
-public abstract class PositionalWidget extends AbstractWidget
+public abstract class PositionalWidget extends AbstractWidget
{
/**
* Version details.
@@ -17,16 +15,11 @@ public abstract class PositionalWidget extends AbstractWidget
"$Id: PositionalWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $";
/**
- * Logger for log4j.
- */
- private static Logger _log = Logger.getLogger(LCD.class);
-
- /**
* The x position.
*/
private int _x = 1;
- /**
+ /**
* The y position.
*/
private int _y = 1;
@@ -77,7 +70,7 @@ public int getY()
return _y;
}
- /**
+ /**
* Return the data this Widget needs to update itself.
* @return the data to update this Widget.
*/
diff --git a/src/main/java/org/lcdproc/lcdjava/RingMenuItem.java b/src/main/java/org/lcdproc/lcdjava/RingMenuItem.java
new file mode 100644
index 0000000..db002a8
--- /dev/null
+++ b/src/main/java/org/lcdproc/lcdjava/RingMenuItem.java
@@ -0,0 +1,134 @@
+package org.lcdproc.lcdjava;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+
+
+/**
+ * RingMenuItem.
+ * Item to display a text and a status indicator.
+ * The status can be one of the strings specified for the item.
+ * @author StefanKrupop
+ */
+public class RingMenuItem extends AbstractMenuItem
+{
+ private int _value;
+ private List They are considered equal if the passed in Object is not null and is a
* Screen object that has the same id as this Screen.
@@ -496,7 +490,7 @@ public boolean equals(Object object)
return equal;
}
- /**
+ /**
* Return the hash code for this Screen, simply the id of the Screen.
* @return the id of the Screen.
*/
diff --git a/src/org/boncey/lcdjava/ScrollerWidget.java b/src/main/java/org/lcdproc/lcdjava/ScrollerWidget.java
similarity index 92%
rename from src/org/boncey/lcdjava/ScrollerWidget.java
rename to src/main/java/org/lcdproc/lcdjava/ScrollerWidget.java
index 1fb6937..0ea3f18 100644
--- a/src/org/boncey/lcdjava/ScrollerWidget.java
+++ b/src/main/java/org/lcdproc/lcdjava/ScrollerWidget.java
@@ -1,6 +1,4 @@
-package org.boncey.lcdjava;
-
-import org.apache.log4j.Logger;
+package org.lcdproc.lcdjava;
/**
* Scroller Widget.
@@ -9,7 +7,7 @@
* @author Darren Greaves
* @version $Id: ScrollerWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $
*/
-public class ScrollerWidget extends AbstractWidget
+public class ScrollerWidget extends AbstractWidget
{
/**
* Version details.
@@ -18,57 +16,52 @@ public class ScrollerWidget extends AbstractWidget
"$Id: ScrollerWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $";
/**
- * Logger for log4j.
- */
- private static Logger _log = Logger.getLogger(LCD.class);
-
- /**
* The Horizontal direction.
*/
public static final char DIRECTION_HORIZONTAL = 'h';
- /**
+ /**
* The Vertical direction.
*/
public static final char DIRECTION_VERTICAL = 'v';
- /**
+ /**
* The 'Marquee' direction.
* Will loop around horizontally rather than bounce back and forth.
*/
public static final char DIRECTION_MARQUEE = 'm';
- /**
+ /**
* The top position of the scroller.
*/
private int _top = 1;
- /**
+ /**
* The bottom position of the scroller.
*/
private int _bottom = 1;
- /**
+ /**
* The left position of the scroller.
*/
private int _left = 1;
- /**
+ /**
* The right position of the scroller.
*/
private int _right = 1;
- /**
+ /**
* The direction to scroll.
*/
private char _direction;
- /**
+ /**
* The speed of the scroller.
*/
private int _speed;
- /**
+ /**
* The Widget text.
*/
private String _text;
@@ -83,13 +76,13 @@ protected ScrollerWidget(int id, Screen screen)
super(id, screen);
}
- /**
+ /**
* Get the Widget type.
* @return the Widget type.
*/
public String getType()
{
- return Widget.WIDGET_SCROLLER;
+ return WIDGET_SCROLLER;
}
/**
@@ -102,7 +95,7 @@ public void setText(String text)
update();
}
- /**
+ /**
* Get the Widget text.
* @return the Widget text.
*/
@@ -230,7 +223,7 @@ public int getSpeed()
return _speed;
}
- /**
+ /**
* Return the data this Widget needs to update itself.
* @return the data to update this Widget.
*/
@@ -240,7 +233,7 @@ public String getData()
_direction + " " + _speed + " \"" + stripQuotes(_text) + "\"";
}
- /**
+ /**
* Construct a new ScrollerWidget.
* @param screen the Screen that owns the Widget.
* @param left the left position.
@@ -266,7 +259,7 @@ public static ScrollerWidget construct(Screen screen,
try
{
widget = (ScrollerWidget)screen.constructWidget(
- Widget.WIDGET_SCROLLER);
+ WIDGET_SCROLLER);
widget.setLeft(left);
widget.setTop(top);
widget.setRight(right);
diff --git a/src/main/java/org/lcdproc/lcdjava/SliderMenuItem.java b/src/main/java/org/lcdproc/lcdjava/SliderMenuItem.java
new file mode 100644
index 0000000..302881f
--- /dev/null
+++ b/src/main/java/org/lcdproc/lcdjava/SliderMenuItem.java
@@ -0,0 +1,124 @@
+package org.lcdproc.lcdjava;
+
+
+
+
+/**
+ * SliderMenuItem.
+ * Is visible as a text. When selected, a screen comes up that shows a
+ * slider. You can set the slider using the cursor keys. When Enter is
+ * pressed, the menu returns.
+ * @author StefanKrupop
+ */
+public class SliderMenuItem extends NumericMenuItem
+{
+ private String _mintext;
+ private String _maxtext;
+ private int _stepsize;
+
+ /**
+ * Constructor.
+ * @param id the of the action.
+ * @param menu the Submenu that knows about this MenuItem.
+ */
+ protected SliderMenuItem(String id, Submenu menu)
+ {
+ super(id, menu);
+ _mintext = "";
+ _maxtext = "";
+ _stepsize = 1;
+ }
+
+ /**
+ * Get the menu item type.
+ * @return the menu item type.
+ */
+ public String getType()
+ {
+ return MENUITEM_SLIDER;
+ }
+
+ /**
+ * Sets label for minimum value of the slider
+ * @param value text to be shown on left side of slider
+ */
+ public void setMinText(String value) {
+ _mintext = value;
+ update();
+ }
+
+ /**
+ * Sets label for maximum value of the slider
+ * @param value text to be shown on right side of slider
+ */
+ public void setMaxText(String value) {
+ _maxtext = value;
+ update();
+ }
+
+ /**
+ * Sets step size of the slider
+ * @param size step size
+ */
+ public void setStepSize(int size) {
+ _stepsize = size;
+ update();
+ }
+
+ @Override
+ public String getData() {
+ StringBuilder strb = new StringBuilder();
+ strb.append(super.getData());
+ strb.append(" -stepsize ");
+ strb.append(_stepsize);
+ if (!_mintext.isEmpty()) {
+ strb.append(" -mintext \"");
+ strb.append(_mintext);
+ strb.append('"');
+ }
+ if (!_maxtext.isEmpty()) {
+ strb.append(" -maxtext \"");
+ strb.append(_maxtext);
+ strb.append('"');
+ }
+ return strb.toString();
+ }
+
+ /**
+ * Construct a new SliderMenuItem.
+ * @param menu the Submenu that owns the menu item.
+ * @param text the menu text.
+ * @return a new SliderMenuItem.
+ */
+ public static SliderMenuItem construct(Submenu menu, String text)
+ {
+ return construct(menu, text, 0, 100);
+ }
+
+ /**
+ * Construct a new SliderMenuItem.
+ * @param menu the Submenu that owns the menu item.
+ * @param text the menu text.
+ * @param minValue the minimum value of the slider
+ * @param maxValue the maximum value of the slider
+ * @return a new SliderMenuItem.
+ */
+ public static SliderMenuItem construct(Submenu menu, String text, int minValue, int maxValue)
+ {
+ SliderMenuItem menuItem = null;
+
+ try
+ {
+ menuItem = (SliderMenuItem)menu.constructMenuItem(MENUITEM_SLIDER);
+ menuItem.setText(text);
+ menuItem.setMinValue(minValue);
+ menuItem.setMaxValue(maxValue);
+ }
+ catch (LCDException e) //NOPMD
+ {
+ // Supress, would only get one if we asked for an invalid menu item.
+ }
+
+ return menuItem;
+ }
+}
diff --git a/src/org/boncey/lcdjava/StringWidget.java b/src/main/java/org/lcdproc/lcdjava/StringWidget.java
similarity index 89%
rename from src/org/boncey/lcdjava/StringWidget.java
rename to src/main/java/org/lcdproc/lcdjava/StringWidget.java
index 3cb785d..f97530d 100644
--- a/src/org/boncey/lcdjava/StringWidget.java
+++ b/src/main/java/org/lcdproc/lcdjava/StringWidget.java
@@ -1,6 +1,4 @@
-package org.boncey.lcdjava;
-
-import org.apache.log4j.Logger;
+package org.lcdproc.lcdjava;
/**
* String Widget.
@@ -9,7 +7,7 @@
* @author Darren Greaves
* @version $Id: StringWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $
*/
-public class StringWidget extends PositionalWidget
+public class StringWidget extends PositionalWidget
{
/**
* Version details.
@@ -18,11 +16,6 @@ public class StringWidget extends PositionalWidget
"$Id: StringWidget.java,v 1.2 2005-03-03 14:13:16 boncey Exp $";
/**
- * Logger for log4j.
- */
- private static Logger _log = Logger.getLogger(LCD.class);
-
- /**
* The Widget text.
*/
private String _text;
@@ -37,7 +30,7 @@ protected StringWidget(int id, Screen screen)
super(id, screen);
}
- /**
+ /**
* Get the Widget type.
* @return the Widget type.
*/
@@ -56,7 +49,7 @@ public void setText(String text)
update();
}
- /**
+ /**
* Get the Widget text.
* @return the Widget text.
*/
@@ -65,7 +58,7 @@ public String getText()
return _text;
}
- /**
+ /**
* Return the data this Widget needs to update itself.
* @return the data to update this Widget.
*/
@@ -74,7 +67,7 @@ public String getData()
return super.getData() + "\"" + stripQuotes(_text) + "\"";
}
- /**
+ /**
* Construct a new StringWidget.
* @param screen the Screen that owns the Widget.
* @param x the x position.
diff --git a/src/main/java/org/lcdproc/lcdjava/Submenu.java b/src/main/java/org/lcdproc/lcdjava/Submenu.java
new file mode 100644
index 0000000..863df41
--- /dev/null
+++ b/src/main/java/org/lcdproc/lcdjava/Submenu.java
@@ -0,0 +1,214 @@
+package org.lcdproc.lcdjava;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Submenu.
+ * Displays the submenus name with tailing submenu marker
+ * @author StefanKrupop
+ */
+public class Submenu extends AbstractMenuItem
+{
+ /**
+ * The LCD that owns this Submenu.
+ */
+ private LCD _lcd;
+
+ /**
+ * A Map of MenuItems added to this Submenu.
+ */
+ private Map This triggers a timeout and any TimeoutHooks are notified.
*/
@@ -177,7 +172,7 @@ private void stop()
hide();
}
- /**
+ /**
* Switch to the hidden priority (hide the screen).
* Explicitly hide the screen without triggering a timeout.
*/
@@ -187,7 +182,7 @@ public void hide()
_screen.setPriority(Screen.PRIORITY_HIDDEN);
}
- /**
+ /**
* Tell this thread to die gracefully.
*/
public void destroy()
@@ -195,7 +190,7 @@ public void destroy()
_alive = false;
}
- /**
+ /**
* Are we displaying now?
* @return They are considered equal if the passed in Object is not null and is a
* ScreenThread object that has the same Screen, priority and timeout value
@@ -276,7 +271,7 @@ public boolean equals(Object object)
return equal;
}
- /**
+ /**
* Return the hash code for this ScreenThread.
* The hash is generated from a String representation of the Screen,
* priority and timeout value.
diff --git a/src/org/boncey/lcdjava/util/TimeoutHook.java b/src/main/java/org/lcdproc/lcdjava/util/TimeoutHook.java
similarity index 94%
rename from src/org/boncey/lcdjava/util/TimeoutHook.java
rename to src/main/java/org/lcdproc/lcdjava/util/TimeoutHook.java
index 81800cb..f60292d 100644
--- a/src/org/boncey/lcdjava/util/TimeoutHook.java
+++ b/src/main/java/org/lcdproc/lcdjava/util/TimeoutHook.java
@@ -1,4 +1,4 @@
-package org.boncey.lcdjava.util;
+package org.lcdproc.lcdjava.util;
/**
* Hook called when a ScreenThread times out.
diff --git a/src/org/boncey/lcdjava/util/WidgetTimer.java b/src/main/java/org/lcdproc/lcdjava/util/WidgetTimer.java
similarity index 89%
rename from src/org/boncey/lcdjava/util/WidgetTimer.java
rename to src/main/java/org/lcdproc/lcdjava/util/WidgetTimer.java
index 7456699..986ae14 100644
--- a/src/org/boncey/lcdjava/util/WidgetTimer.java
+++ b/src/main/java/org/lcdproc/lcdjava/util/WidgetTimer.java
@@ -1,7 +1,6 @@
-package org.boncey.lcdjava.util;
+package org.lcdproc.lcdjava.util;
-import org.apache.log4j.Logger;
-import org.boncey.lcdjava.Widget;
+import org.lcdproc.lcdjava.Widget;
/**
* A Runnable class to update a Widget on a specified time period.
@@ -18,21 +17,16 @@ public class WidgetTimer implements Runnable
"$Id: WidgetTimer.java,v 1.2 2005-03-03 14:13:16 boncey Exp $";
/**
- * Logger for log4j.
- */
- private static Logger _log = Logger.getLogger(WidgetTimer.class);
-
- /**
* The class that holds a Widget for updating.
*/
private WidgetUpdater _updater;
- /**
+ /**
* Flag that tracks if we are alive or not.
*/
private boolean _alive = true;
- /**
+ /**
* How long to display the widget for (in milliseconds).
*/
private int _timeout;
@@ -48,7 +42,7 @@ public WidgetTimer(WidgetUpdater updater, int timeout)
_timeout = timeout;
}
- /**
+ /**
* Switch to the specified priority for the specified time period.
*/
public void run()
@@ -67,7 +61,7 @@ public void run()
}
}
- /**
+ /**
* Return the wrapped Widget.
* @return the Widget.
*/
@@ -76,7 +70,7 @@ public Widget getWidget()
return _updater.getWidget();
}
- /**
+ /**
* Alter the timeout value and wake up the thread.
* @param timeout the new timeout value.
*/
@@ -86,7 +80,7 @@ public synchronized void setTimeout(int timeout)
notify();
}
- /**
+ /**
* Tell this thread to die gracefully.
*/
public synchronized void destroy()
diff --git a/src/org/boncey/lcdjava/util/WidgetUpdater.java b/src/main/java/org/lcdproc/lcdjava/util/WidgetUpdater.java
similarity index 90%
rename from src/org/boncey/lcdjava/util/WidgetUpdater.java
rename to src/main/java/org/lcdproc/lcdjava/util/WidgetUpdater.java
index 3271c92..17300ff 100644
--- a/src/org/boncey/lcdjava/util/WidgetUpdater.java
+++ b/src/main/java/org/lcdproc/lcdjava/util/WidgetUpdater.java
@@ -1,6 +1,6 @@
-package org.boncey.lcdjava.util;
+package org.lcdproc.lcdjava.util;
-import org.boncey.lcdjava.Widget;
+import org.lcdproc.lcdjava.Widget;
/**
* Interface for holding a Widget that will be updated by the WidgetTimer class.
diff --git a/src/org/boncey/lcdjava/util/package.html b/src/main/java/org/lcdproc/lcdjava/util/package.html
similarity index 100%
rename from src/org/boncey/lcdjava/util/package.html
rename to src/main/java/org/lcdproc/lcdjava/util/package.html
diff --git a/src/org/boncey/lcdjava/LCDSocketPoller.java b/src/org/boncey/lcdjava/LCDSocketPoller.java
deleted file mode 100644
index 517c92a..0000000
--- a/src/org/boncey/lcdjava/LCDSocketPoller.java
+++ /dev/null
@@ -1,160 +0,0 @@
-package org.boncey.lcdjava;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.log4j.Logger;
-
-/**
- * Thread that listens for data on the LCD socket.
- * Copyright (c) 2004-2005 Darren Greaves.
- * @author Darren Greaves
- * @version $Id: LCDSocketPoller.java,v 1.3 2008-07-06 15:38:34 boncey Exp $
- */
-public class LCDSocketPoller implements Runnable
-{
- /**
- * Version details.
- */
- public static final String CVSID =
- "$Id: LCDSocketPoller.java,v 1.3 2008-07-06 15:38:34 boncey Exp $";
-
- /**
- * Logger for log4j.
- */
- private static Logger _log = Logger.getLogger(LCDSocketPoller.class);
-
- /**
- * How often to poll for changes.
- */
- private static final int POLL = 100;
-
- /**
- * The Pattern that matches ignore/listen events.
- */
- private static final Pattern IGNORE_STATUS = Pattern.compile(
- "(ignore|listen)\\s+(\\d+).*");
-
- /**
- * The Reader to read data from.
- */
- private BufferedReader _in;
-
- /**
- * The last line of data received.
- * Will be null if no data was received.
- */
- private String _lastLine;
-
- /**
- * Flag that tracks if we are alive or not.
- */
- private boolean _alive = true;
-
- /**
- * Flag that tracks if we are polling or not.
- */
- private boolean _polling = true;
-
- /**
- * The listener to notify of listen/ignore events.
- */
- private LCDListener _listener;
-
- /**
- * Public constructor.
- * @param in the BufferedReader that will recieve data from the server.
- * @param listener the LCDListener that gets notified of screens being
- * listened to or ignored.
- */
- public LCDSocketPoller(BufferedReader in, LCDListener listener)
- {
- _in = in;
- _listener = listener;
- }
-
- /**
- * Poll the socket every 100 milliseconds.
- */
- public void run()
- {
- while (_alive)
- {
- synchronized (this)
- {
- try
- {
- Thread.sleep(POLL);
- if (_in.ready())
- {
- _lastLine = _in.readLine();
- Matcher m = IGNORE_STATUS.matcher(_lastLine);
- if (_lastLine.startsWith(LCD.RESPONSE_ERROR))
- {
- _log.warn("Got a response of " + _lastLine +
- " from server");
- }
- else if (m.matches())
- {
- if (_listener != null)
- {
- boolean listen = (LCD.RESPONSE_LISTEN.equals(
- m.group(1)));
- try
- {
- int screenId = Integer.parseInt(m.group(2));
- _listener.setListenStatus(screenId, listen);
- }
- catch (NumberFormatException e)
- {
- // Ignore
- }
- }
- }
- }
- }
- catch (InterruptedException e)
- {
- // Do nothing
- }
- catch (IOException e)
- {
- _log.error("Caught IOException", e);
- }
- }
- }
-
- _polling = false;
- }
-
- /**
- * Get the last line received non-blocking.
- * Calling this clears the last line received.
- * @return the last line received.
- */
- public synchronized String getLastLine()
- {
- String ret = _lastLine;
- _lastLine = null;
- return ret;
- }
-
- /**
- * Tell this thread to die gracefully.
- */
- public void shutdown()
- {
- _alive = false;
- }
-
- /**
- * Is the server still polling for data.
- * Call this after shutdown to see if we are still polling.
- * @return Copyright (c) 2004-2005 Darren Greaves.
- * @author Darren Greaves
- * @version $Id: RSSIdler.java,v 1.2 2005-03-03 14:13:16 boncey Exp $
- */
-public class RSSIdler extends AbstractIdler
-{
- /**
- * Version details.
- */
- public static final String CVSID =
- "$Id: RSSIdler.java,v 1.2 2005-03-03 14:13:16 boncey Exp $";
-
- /**
- * Logger for log4j.
- */
- private static Logger _log = Logger.getLogger(RSSIdler.class);
-
- /**
- * Pad the display to enhance readability.
- */
- private static final String PADDING = " *** ";
-
- /**
- * The User Agent for fetching feeds.
- */
- private static final String USER_AGENT =
- "FeedFetcher (Rome Client)/0.1";
-
- /**
- * The text to display.
- */
- private String _text = "";
-
- /**
- * The feed URL.
- */
- private URL _feed;
-
- /**
- * Does this Idler have anything to display?
- */
- private boolean _valid;
-
- /**
- * How often to update this feed in minutes.
- */
- private int _update;
-
- /**
- * Limit the number of entries to this number.
- * Will only show the first 'n' entries if set, otherwise shows all.
- */
- private int _limit = -1;
-
- /**
- * How many minutes old this feed has to be before we stop displaying it?
- * The feed will continue to be checked in the background so will
- * re-appear when it has been updated.
- */
- private int _expires = -1;
-
- /**
- * Whether or not to display the feed's description field.
- * False unless specified as Example: true if the server is listening to us,
@@ -309,7 +368,7 @@ public int getCellHeight()
*/
public void setListenStatus(int screenId, boolean listening)
{
- Screen screen = (Screen)_screens.get(new Integer(screenId));
+ Screen screen = _screens.get(screenId);
if (screen != null)
{
screen.setListening(listening);
@@ -323,24 +382,98 @@ public void setListenStatus(int screenId, boolean listening)
}
}
- /**
+ /**
+ * The user interacted with a menu
+ * @param menuId the id of the menu item.
+ * @param eventType the type of the event that occurred
+ * @param value the value returned or nullwhen not available
+ */
+ @Override
+ public void menuAction(String menuId, String eventType, String value) {
+ String menuParts[] = menuId.split("_");
+ StringBuilder id = new StringBuilder();
+ MenuItem menu = _rootMenu;
+ for (String part : menuParts) {
+ if (!"".equals(part)) {
+ id.append('_');
+ id.append(part);
+ if (menu instanceof Submenu) {
+ menu = ((Submenu)menu).getMenuItem(id.toString());
+ } else {
+ break;
+ }
+ if (menu == null) {
+ break;
+ }
+ }
+ }
+ if (menu != null) {
+ switch (eventType) {
+ case LCD.EVENT_SELECT:
+ if (menu instanceof ActionMenuItem) {
+ ((ActionMenuItem) menu).notifyActionPerformed(new ActionEvent(menu, ActionEvent.ACTION_PERFORMED, menu.getID()));
+ }
+ break;
+ case LCD.EVENT_UPDATE:
+ if (menu instanceof CheckboxMenuItem) {
+ if ("on".equals(value)) {
+ ((CheckboxMenuItem) menu).setValueNoUpdate(CheckboxMenuItem.CheckboxValue.On);
+ } else if ("off".equals(value)) {
+ ((CheckboxMenuItem) menu).setValueNoUpdate(CheckboxMenuItem.CheckboxValue.Off);
+ } else if ("gray".equals(value)) {
+ ((CheckboxMenuItem) menu).setValueNoUpdate(CheckboxMenuItem.CheckboxValue.Gray);
+ }
+ ((CheckboxMenuItem) menu).notifyActionPerformed(new ActionEvent(menu, ActionEvent.ACTION_PERFORMED, menu.getID()));
+ } else if (menu instanceof RingMenuItem) {
+ ((RingMenuItem) menu).setValueNoUpdate(Integer.parseInt(value));
+ ((RingMenuItem) menu).notifyActionPerformed(new ActionEvent(menu, ActionEvent.ACTION_PERFORMED, menu.getID()));
+ } else if (menu instanceof NumericMenuItem) {
+ ((NumericMenuItem) menu).setValueNoUpdate(Integer.parseInt(value));
+ ((NumericMenuItem) menu).notifyActionPerformed(new ActionEvent(menu, ActionEvent.ACTION_PERFORMED, menu.getID()));
+ } else if (menu instanceof AlphaMenuItem) {
+ ((AlphaMenuItem) menu).setValueNoUpdate(value);
+ ((AlphaMenuItem) menu).notifyActionPerformed(new ActionEvent(menu, ActionEvent.ACTION_PERFORMED, menu.getID()));
+ } else if (menu instanceof IpMenuItem) {
+ ((IpMenuItem) menu).setValueNoUpdate(value);
+ ((IpMenuItem) menu).notifyActionPerformed(new ActionEvent(menu, ActionEvent.ACTION_PERFORMED, menu.getID()));
+ }
+ break;
+ case LCD.EVENT_PLUS:
+ case LCD.EVENT_MINUS:
+ if (menu instanceof SliderMenuItem) {
+ int v = Integer.parseInt(value);
+ if (v != ((SliderMenuItem) menu).getValue()) {
+ ((SliderMenuItem) menu).setValueNoUpdate(v);
+ ((NumericMenuItem) menu).notifyActionPerformed(new ActionEvent(menu, ActionEvent.ACTION_PERFORMED, menu.getID()));
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ /**
* Shut down the server, terminating any threads.
* @throws LCDException in case of a network problem.
*/
public void shutdown()
throws LCDException
{
+ _log.debug("Shutdown requested");
if (_poller != null)
{
- _poller.shutdown();
- while (_poller.isPolling())
- {
- // loop until LCDSocketPoller has stopped polling
+ _poller.interrupt();
+ _log.debug("Waiting for LCDSocketPoller to terminate...");
+ try {
+ _poller.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
}
try
{
+ _log.debug("Closing socket");
if (_socket != null && !_socket.isClosed())
{
_socket.close();
@@ -352,9 +485,9 @@ public void shutdown()
}
}
- /**
+ /**
* Construct a new (unactivated) Screen.
- * @param name the Screeen name.
+ * @param name the Screen name.
* @return the newly constructed Screen.
*/
public synchronized Screen constructScreen(String name)
@@ -362,9 +495,9 @@ public synchronized Screen constructScreen(String name)
return constructScreen(name, Screen.PRIORITY_HIDDEN);
}
- /**
+ /**
* Construct a new (unactivated) Screen.
- * @param name the Screeen name.
+ * @param name the Screen name.
* @param priority the screen priority.
* @return the newly constructed Screen.
*/
@@ -373,9 +506,9 @@ public synchronized Screen constructScreen(String name, String priority)
return constructScreen(name, priority, false);
}
- /**
+ /**
* Construct and optionally activate a new Screen.
- * @param name the Screeen name.
+ * @param name the Screen name.
* @param priority the screen priority.
* @param activate true to activate this Screen immediately,
* false to leave in unactivated.
@@ -398,14 +531,14 @@ public synchronized Screen constructScreen(String name,
return screen;
}
- /**
+ /**
* Add this screen to the LCD server.
* false if not.
*/
public void setListenStatus(int screenId, boolean listening);
+
+ /**
+ * The user interacted with a menu
+ * @param menuId the id of the menu item.
+ * @param eventType the type of the event that occured
+ * @param value the value returned or nullwhen not available
+ */
+ public void menuAction(String menuId, String eventType, String value);
}
diff --git a/src/main/java/org/lcdproc/lcdjava/LCDSocketPoller.java b/src/main/java/org/lcdproc/lcdjava/LCDSocketPoller.java
new file mode 100644
index 0000000..6f1233b
--- /dev/null
+++ b/src/main/java/org/lcdproc/lcdjava/LCDSocketPoller.java
@@ -0,0 +1,144 @@
+package org.lcdproc.lcdjava;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Thread that listens for data on the LCD socket.
+ * true if success, false otherwise.
*/
@@ -127,7 +126,7 @@ private boolean execute()
return success;
}
- /**
+ /**
* Is there any text to display?
* @return true if there is anything to display,
* false otherwise.
@@ -137,7 +136,7 @@ public boolean isValid()
return _valid;
}
- /**
+ /**
* Get the text to display.
* @return the text to display.
*/
@@ -161,8 +160,8 @@ public String toString()
{
return "Program = " + _program + "; Valid = " + _valid;
}
-
- /**
+
+ /**
* Thread for handling periodic updates.
* @author Darren Greaves
*/
@@ -175,7 +174,7 @@ public ExecUpdater()
{
}
- /**
+ /**
* Update the feed.
*/
public void run()
diff --git a/src/org/boncey/lcdjava/idler/Idler.java b/src/main/java/org/lcdproc/lcdjava/idler/Idler.java
similarity index 97%
rename from src/org/boncey/lcdjava/idler/Idler.java
rename to src/main/java/org/lcdproc/lcdjava/idler/Idler.java
index bc5a37f..8da1fa8 100644
--- a/src/org/boncey/lcdjava/idler/Idler.java
+++ b/src/main/java/org/lcdproc/lcdjava/idler/Idler.java
@@ -1,4 +1,4 @@
-package org.boncey.lcdjava.idler;
+package org.lcdproc.lcdjava.idler;
/**
* Interface for anything that wants to display idle information
diff --git a/src/org/boncey/lcdjava/idler/IdlerLoader.java b/src/main/java/org/lcdproc/lcdjava/idler/IdlerLoader.java
similarity index 91%
rename from src/org/boncey/lcdjava/idler/IdlerLoader.java
rename to src/main/java/org/lcdproc/lcdjava/idler/IdlerLoader.java
index 4ef967b..7b9d7c3 100644
--- a/src/org/boncey/lcdjava/idler/IdlerLoader.java
+++ b/src/main/java/org/lcdproc/lcdjava/idler/IdlerLoader.java
@@ -1,14 +1,15 @@
-package org.boncey.lcdjava.idler;
+package org.lcdproc.lcdjava.idler;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import org.apache.log4j.Logger;
-import org.boncey.lcdjava.LCDException;
-import org.boncey.lcdjava.ScrollerWidget;
-import org.boncey.lcdjava.util.WidgetTimer;
+
+import org.lcdproc.lcdjava.LCDException;
+import org.lcdproc.lcdjava.ScrollerWidget;
+import org.lcdproc.lcdjava.util.WidgetTimer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -22,10 +23,7 @@
*/
public class IdlerLoader
{
- /**
- * Logger for log4j.
- */
- private static Logger _log = Logger.getLogger(IdlerLoader.class);
+ private static Logger _log = LoggerFactory.getLogger(IdlerLoader.class);
/**
* Version details.
@@ -33,42 +31,42 @@ public class IdlerLoader
public static final String CVSID =
"$Id: IdlerLoader.java,v 1.2 2005-03-03 14:13:16 boncey Exp $";
- /**
+ /**
* XML config value.
*/
private static final String IDLER_ELEMENT = "idler";
- /**
+ /**
* XML config value.
*/
private static final String CLASSNAME = "className";
- /**
+ /**
* XML config value.
*/
private static final String NAME = "name";
- /**
+ /**
* The amount of milliseconds in a second.
*/
public static final int ONE_SECOND = 1000;
- /**
+ /**
* The amount of seconds in a minute.
*/
public static final int ONE_MINUTE = 60;
- /**
+ /**
* The timer for controlling display of each Idler.
*/
private WidgetTimer _timer;
- /**
+ /**
* The WidgetUpdater that mananges displaying of the Idlers.
*/
private IdlerWidgetUpdater _updater;
- /**
+ /**
* Default constructor, initialise.
* @param doc the XML Document.
* @param scroller the Widget to display each Idler upon.
@@ -90,7 +88,7 @@ public IdlerLoader(Document doc,
load(config, scroller, name);
}
- /**
+ /**
* Default constructor, initialise.
* @param config the XML config.
* @param scroller the Widget to display each Idler upon.
@@ -105,7 +103,7 @@ public IdlerLoader(Element config,
load(config, scroller, name);
}
- /**
+ /**
* Load the Idlers from the config file.
* @param config the XML config.
* @param scroller the Widget to display each Idler upon.
@@ -121,11 +119,6 @@ private void load(Element config,
if (idlers.size() > 0)
{
- for (Iterator i = idlers.iterator(); i.hasNext();)
- {
- Idler idler = (Idler)i.next();
- }
-
_updater = new IdlerWidgetUpdater(scroller, name, idlers);
_timer = new WidgetTimer(_updater, ONE_MINUTE);
@@ -134,7 +127,7 @@ private void load(Element config,
}
}
- /**
+ /**
* IdlerLoader is being destroyed, kill off any threads.
*/
public void destroy()
@@ -153,7 +146,7 @@ public void next()
_updater.updateWidget(_timer);
}
- /**
+ /**
* Load the configs and store the classes in the internal Map.
* @param config the Element that holds the config.
* @return a List of Idlers.
@@ -162,10 +155,10 @@ public void next()
private List loadConfig(Element config)
throws LCDException
{
- List idlers = new ArrayList();
+ Listtrue if there is anything to display,
* false otherwise.
@@ -76,5 +70,5 @@ public String toString()
{
return "Text = " + _text;
}
-
+
}
diff --git a/src/org/boncey/lcdjava/idler/package.html b/src/main/java/org/lcdproc/lcdjava/idler/package.html
similarity index 100%
rename from src/org/boncey/lcdjava/idler/package.html
rename to src/main/java/org/lcdproc/lcdjava/idler/package.html
diff --git a/src/org/boncey/lcdjava/package.html b/src/main/java/org/lcdproc/lcdjava/package.html
similarity index 100%
rename from src/org/boncey/lcdjava/package.html
rename to src/main/java/org/lcdproc/lcdjava/package.html
diff --git a/src/org/boncey/lcdjava/util/ClockWidgetUpdater.java b/src/main/java/org/lcdproc/lcdjava/util/ClockWidgetUpdater.java
similarity index 84%
rename from src/org/boncey/lcdjava/util/ClockWidgetUpdater.java
rename to src/main/java/org/lcdproc/lcdjava/util/ClockWidgetUpdater.java
index 39ea2c2..f2c2c1d 100644
--- a/src/org/boncey/lcdjava/util/ClockWidgetUpdater.java
+++ b/src/main/java/org/lcdproc/lcdjava/util/ClockWidgetUpdater.java
@@ -1,10 +1,10 @@
-package org.boncey.lcdjava.util;
+package org.lcdproc.lcdjava.util;
+
+import org.lcdproc.lcdjava.StringWidget;
+import org.lcdproc.lcdjava.Widget;
import java.text.DateFormat;
import java.util.Date;
-import org.apache.log4j.Logger;
-import org.boncey.lcdjava.StringWidget;
-import org.boncey.lcdjava.Widget;
/**
* StringWidget that updates with the current time.
@@ -21,16 +21,11 @@ public class ClockWidgetUpdater implements WidgetUpdater
"$Id: ClockWidgetUpdater.java,v 1.2 2005-03-03 14:13:16 boncey Exp $";
/**
- * Logger for log4j.
- */
- private static Logger _log = Logger.getLogger(ClockWidgetUpdater.class);
-
- /**
* The StringWidget we will be updating.
*/
private StringWidget _widget;
- /**
+ /**
* Store the time as a String so we only write it when it has changed.
*/
private String _timeString;
@@ -44,7 +39,7 @@ public ClockWidgetUpdater(StringWidget widget)
_widget = widget;
}
- /**
+ /**
* Update the clock.
* @param timer the WidgetTimer.
*/
@@ -59,7 +54,7 @@ public void updateWidget(WidgetTimer timer)
}
}
- /**
+ /**
* Retrurn the wrapped Widget.
* @return the Widget.
*/
diff --git a/src/org/boncey/lcdjava/util/ScreenThread.java b/src/main/java/org/lcdproc/lcdjava/util/ScreenThread.java
similarity index 92%
rename from src/org/boncey/lcdjava/util/ScreenThread.java
rename to src/main/java/org/lcdproc/lcdjava/util/ScreenThread.java
index a585513..18b6b80 100644
--- a/src/org/boncey/lcdjava/util/ScreenThread.java
+++ b/src/main/java/org/lcdproc/lcdjava/util/ScreenThread.java
@@ -1,10 +1,10 @@
-package org.boncey.lcdjava.util;
+package org.lcdproc.lcdjava.util;
+
+import org.lcdproc.lcdjava.Screen;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.apache.log4j.Logger;
-import org.boncey.lcdjava.Screen;
/**
* A Runnable class to display a Screen for a specified time period.
@@ -21,52 +21,47 @@ public class ScreenThread implements Runnable
"$Id: ScreenThread.java,v 1.2 2005-03-03 14:13:16 boncey Exp $";
/**
- * Logger for log4j.
- */
- private static Logger _log = Logger.getLogger(ScreenThread.class);
-
- /**
* The screen we are displaying.
*/
private Screen _screen;
- /**
+ /**
* How long to display the screen for.
*/
private int _timeout;
- /**
+ /**
* The priority to set when displaying.
*/
private String _priority;
- /**
+ /**
* Flag that tracks if we are displaying or not.
*/
private boolean _displaying;
- /**
+ /**
* Flag that tracks if we are alive or not.
*/
private boolean _alive = true;
- /**
+ /**
* Flag that tracks whether we should die after the first timeout or not.
*/
private boolean _dieOnTimeout;
- /**
+ /**
* A List of TimeoutHook objects that want to be notified when the thread
* times out.
*/
- private List _timeoutHooks;
+ private Listtrue if the TimeoutHook was removed,
@@ -122,7 +117,7 @@ public boolean removeTimeoutHook(TimeoutHook hook)
return _timeoutHooks.remove(hook);
}
- /**
+ /**
* Switch to the specified priority for the specified time period.
*/
public void run()
@@ -139,7 +134,7 @@ public void run()
if (_step > 0)
{
_step--;
- if (_priority != _screen.getPriority())
+ if (!_priority.equals(_screen.getPriority()))
{
start();
}
@@ -159,7 +154,7 @@ public void run()
}
}
- /**
+ /**
* Switch to the specified priority (display the screen).
*/
private void start()
@@ -167,7 +162,7 @@ private void start()
_screen.setPriority(_priority);
}
- /**
+ /**
* Set counter to zero then hide the screen.
* true if displaying, false otherwise.
*/
@@ -204,7 +199,7 @@ public boolean isDisplaying()
return _displaying;
}
- /**
+ /**
* Tell the screen to display for the specified timeout.
*/
public void display()
@@ -213,7 +208,7 @@ public void display()
_displaying = true;
}
- /**
+ /**
* Get the Screen we are wrapping.
* @return the Screen we are wrapping.
*/
@@ -222,7 +217,7 @@ public Screen getScreen()
return _screen;
}
- /**
+ /**
* Call timeout for each TimeoutHook.
*/
private void timeout()
@@ -251,7 +246,7 @@ public String toString()
"; screen = " + _screen;
}
- /**
+ /**
* Determine if this ScreenThread is equal to the passed in Object.
* true if still polling, false otherwise.
- */
- public boolean isPolling()
- {
- return _polling;
- }
-}
diff --git a/src/org/boncey/lcdjava/demo/Demo.java b/src/org/boncey/lcdjava/demo/Demo.java
deleted file mode 100644
index 42d9759..0000000
--- a/src/org/boncey/lcdjava/demo/Demo.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package org.boncey.lcdjava.demo;
-
-import org.apache.log4j.Appender;
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.boncey.lcdjava.LCD;
-import org.boncey.lcdjava.LCDException;
-import org.boncey.lcdjava.Screen;
-import org.boncey.lcdjava.StringWidget;
-import org.boncey.lcdjava.TitleWidget;
-
-/**
- * Sample class to demonstrate how to display various widgets.
- * @author Darren Greaves
- * @version $Id: Demo.java,v 1.1 2008-07-06 15:38:34 boncey Exp $
- */
-public class Demo
-{
- /**
- * Version details.
- */
- public static final String CVSID =
- "$Id: Demo.java,v 1.1 2008-07-06 15:38:34 boncey Exp $";
-
- /**
- * Logger for log4j.
- */
- private static Logger _log = null;
-
- /**
- * Public constructor.
- * @param host the LCDd host.
- * @param port the LCDd port.
- * @throws LCDException if there was a problem connecting to the server.
- */
- private Demo(String host, int port)
- throws LCDException
- {
- LCD lcd = new LCD(host, port);
- System.out.println("Connected to LCDd: " + lcd);
-
- // Construct an unactivated Screen
- Screen demoScreen = lcd.constructScreen("demo");
-
- // Set to foreground priority (still won't be seen until activated)
- demoScreen.setPriority(Screen.PRIORITY_FOREGROUND);
-
- // Add some Widgets to the screen - nothing will be seen until activated
- TitleWidget titleWidget =
- TitleWidget.construct(demoScreen, "Demo Title");
- StringWidget stringWidget =
- StringWidget.construct(demoScreen, 1, 2, "Demo Text");
-
- // Must call Screen.activate before activating any of its Widgets
- demoScreen.activate();
-
- // This will fail (check return value) if Screen not activated
- titleWidget.activate();
- stringWidget.activate();
- }
-
- public static void main(String args[])
- {
- if (args.length != 2)
- {
- System.err.println(
- "Usage: java org.boncey.lcdjava.demo.Demo includeDescription="true" in
- * the config.
- */
- private boolean _includeDescription;
-
- /**
- * Any entry matching this pattern will be ignored.
- * ignoreEntryPattern=".*advert.*" to skip ads.
- */
- private Pattern _ignoreEntryPattern;
-
- /**
- * Public constructor, read the text from the config.
- * @param config the XML element for this Idler.
- * @param name the name of the Idler.
- * @throws LCDException if there was a problem.
- */
- public RSSIdler(Element config, String name)
- throws LCDException
- {
- super(config, name);
-
- try
- {
- String feed = config.getAttribute("feed");
- String update = config.getAttribute("update");
- String limit = config.getAttribute("limit");
- String expires = config.getAttribute("expires");
- String ignoreEntryPattern =
- config.getAttribute("ignoreEntryPattern");
- String includeDescription =
- config.getAttribute("includeDescription");
-
- _includeDescription =
- Boolean.valueOf(includeDescription).booleanValue();
- _update = Integer.parseInt(update) *
- IdlerLoader.ONE_SECOND *
- IdlerLoader.ONE_MINUTE;
- if (expires.length() > 0)
- {
- _expires = Integer.parseInt(expires);
- }
- if (limit.length() > 0)
- {
- _limit = Integer.parseInt(limit);
- }
-
- _feed = new URL(feed);
- _ignoreEntryPattern = Pattern.compile(ignoreEntryPattern);
-
- RSSUpdater updater = new RSSUpdater();
- Thread thread = new Thread(updater);
- thread.start();
-
- }
- catch (MalformedURLException e)
- {
- throw new LCDException(e);
- }
- }
-
- /**
- * Re-read the feed from the given URL.
- * @return true if success, false otherwise.
- */
- private boolean updateFeed()
- {
- _log.info("Fetching " + _feed);
-
- StringBuffer text = new StringBuffer();
- boolean success = false;
- boolean expired = false;
- try
- {
- FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance();
- FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache);
- feedFetcher.setUserAgent(USER_AGENT);
- SyndFeed feed = feedFetcher.retrieveFeed(_feed);
- WireFeed wire = feed.createWireFeed();
- SyndFeedInfo info = feedInfoCache.getFeedInfo(_feed);
- long lastModified =
- Long.parseLong(String.valueOf(info.getLastModified()));
- Date pubDate = new Date(lastModified);
-
- int max;
- if (_limit > 0)
- {
- max = _limit;
- }
- else
- {
- max = feed.getEntries().size();
- }
- int i = 0;
-
- if (_includeDescription)
- {
- text.append(PADDING + feed.getDescription());
- }
-
- for (Iterator it = feed.getEntries().iterator();
- it.hasNext() && i < max;)
- {
- SyndEntry entry = (SyndEntry)it.next();
- String title = entry.getTitle();
- Matcher m = _ignoreEntryPattern.matcher(title);
- if (!m.matches())
- {
- text.append(PADDING + title);
- i++;
- }
- }
-
- synchronized (_text)
- {
- _text = text.toString();
- }
-
- if (pubDate != null && _expires != -1)
- {
- Calendar feedCal = Calendar.getInstance();
- feedCal.setTime(pubDate);
-
- feedCal.add(Calendar.MINUTE, _expires);
-
- if (feedCal.getTime().before(new Date()))
- {
- expired = true;
- }
- }
-
- if (_text.length() > 0 && !expired)
- {
- success = true;
- }
- }
- catch (FetcherException e)
- {
- // HTTP error, don't abort - temporary error.
- _log.warn("Failed fetching feed " + _feed + " with status code " +
- e.getResponseCode());
- }
- catch (FeedException e)
- {
- // Feed error (likely invalid XML), don't abort - temporary error.
- _log.warn("Failed parsing feed " + _feed + " with message " + e);
- }
- catch (IOException e)
- {
- // Network error, don't abort - temporary error.
- _log.warn("Failed fetching feed " + _feed, e);
- }
-
- return success;
- }
-
- /**
- * Is there any text to display?
- * @return true if there is anything to display,
- * false otherwise.
- */
- public boolean isValid()
- {
- return _valid;
- }
-
- /**
- * Get the text to display.
- * @return the text to display.
- */
- public synchronized String getDisplayText()
- {
- return _text;
- }
-
- /**
- * Idler is being destroyed, do nothing.
- */
- public void destroy()
- {
- }
-
- /**
- * Return a String representing this object.
- * @return a String representing this object.
- */
- public String toString()
- {
- return "Feed = " + _feed + "; Valid = " + _valid;
- }
-
- /**
- * Thread for handling periodic updates.
- * @author Darren Greaves
- */
- private class RSSUpdater implements Runnable
- {
- /**
- * Public constructor.
- */
- public RSSUpdater()
- {
- }
-
- /**
- * Update the feed.
- */
- public void run()
- {
- while (true)
- {
- synchronized (this)
- {
- try
- {
- _valid = updateFeed();
- Thread.sleep(_update);
- }
- catch (InterruptedException e)
- {
- // Do nothing
- }
- }
- }
- }
- }
-}