From: Erik V. <ev...@us...> - 2010-01-01 14:00:40
|
Update of /cvsroot/rails/18xx/rails/game/model In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv4938/rails/game/model Modified Files: MoneyModel.java Log Message: Added fixed text facility (used for "MERGE"in 1856) Index: MoneyModel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/model/MoneyModel.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** MoneyModel.java 4 Jun 2008 19:00:37 -0000 1.8 --- MoneyModel.java 1 Jan 2010 14:00:31 -0000 1.9 *************** *** 5,8 **** --- 5,9 ---- import rails.game.state.BooleanState; import rails.game.state.IntegerState; + import rails.game.state.StringState; import rails.util.Util; *************** *** 13,17 **** public static final int ALLOW_NEGATIVE = 8; private BooleanState initialised; ! public MoneyModel(String name) { super(name, 0); --- 14,19 ---- public static final int ALLOW_NEGATIVE = 8; private BooleanState initialised; ! private StringState fixedText = null; ! public MoneyModel(String name) { super(name, 0); *************** *** 47,56 **** } public String getText() { int amount = intValue(); if (amount == 0 ! && (Util.bitSet(option, SUPPRESS_ZERO) || Util.bitSet(option, ! SUPPRESS_INITIAL_ZERO) ! && (initialised == null || !initialised.booleanValue()))) { return ""; } else if (amount < 0 && !Util.bitSet(option, ALLOW_NEGATIVE)) { --- 49,74 ---- } + /** Set a fixed text, which will override the money value + * as long as it is not null and not "". + * @param text + */ + public void setText (String text) { + if (fixedText == null) { + fixedText = new StringState (name+"_FixedText", text); + } else { + fixedText.set(text); + } + update(); + } + public String getText() { + if (fixedText != null && !"".equals(fixedText.getText())) { + return fixedText.getText(); + } int amount = intValue(); if (amount == 0 ! && (Util.bitSet(option, SUPPRESS_ZERO) ! || Util.bitSet(option, SUPPRESS_INITIAL_ZERO) ! && (initialised == null || !initialised.booleanValue()))) { return ""; } else if (amount < 0 && !Util.bitSet(option, ALLOW_NEGATIVE)) { |