From: <aki...@us...> - 2008-08-09 09:09:56
|
Revision: 4818 http://gridarta.svn.sourceforge.net/gridarta/?rev=4818&view=rev Author: akirschbaum Date: 2008-08-09 09:10:03 +0000 (Sat, 09 Aug 2008) Log Message: ----------- Improve GameObject's setter methods for text messages: replace deleteTextMsg() and resetTextMsg() with setTextMsg(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/GameObjectAttributesDialog.java trunk/src/app/net/sf/gridarta/gui/gameobjectattributespanel/MsgTextTab.java trunk/src/app/net/sf/gridarta/io/AbstractGameObjectParser.java trunk/src/app/net/sf/gridarta/map/DefaultMapModel.java Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java 2008-08-09 08:14:33 UTC (rev 4817) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java 2008-08-09 09:10:03 UTC (rev 4818) @@ -162,7 +162,7 @@ if (thisLine.equals("endmsg")) { msgflag = false; } else { - archetype.addMsgText(thisLine2 + "\n"); // thisLine2 allows leading whitespaces + archetype.addMsgTextLine(thisLine2); // thisLine2 allows leading whitespaces } } else if (animflag) { if (thisLine.equals("mina")) { Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java 2008-08-09 08:14:33 UTC (rev 4817) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java 2008-08-09 09:10:03 UTC (rev 4818) @@ -160,7 +160,7 @@ if (thisLine.equals("endmsg")) { msgflag = false; } else { - archetype.addMsgText(thisLine2 + "\n"); // thisLine2 allows leading whitespaces + archetype.addMsgTextLine(thisLine2); // thisLine2 allows leading whitespaces } } else if (animflag) { if (thisLine.equals("mina")) { Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2008-08-09 08:14:33 UTC (rev 4817) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2008-08-09 09:10:03 UTC (rev 4818) @@ -834,58 +834,22 @@ gameObjectChanged(); } - /** Delete message text by nullification. */ - public void deleteMsgText() { - if (msgText == null) { - return; - } - - // FIXME, see addMsgText for information - msgText = null; - gameObjectChanged(); - } - - /** Delete message text by emptying. */ - public void resetMsgText() { - if (msgText == null || msgText.length() == 0) { - return; - } - - //noinspection ConstantConditions - msgText.delete(0, msgText.length()); - gameObjectChanged(); - } - /** * Add a line of message text. This is used when creating the GameObject - * from the ArchetypeParser. Special: invoking this method with - * <code>null</code> creates an empty string. + * from the ArchetypeParser. * @param text text to append to message text */ - public void addMsgText(@Nullable final String text) { - boolean isChanged = false; - + public void addMsgTextLine(@Nullable final String text) { // It's intentional that if text == null, msgText still is created if it's empty. // FIXME: Though it's intentional, it's not nice, search for users and fix this. // (Also look at deleteMsgText() and getMsgText() then) - StringBuilder myMsgText = msgText; - if (myMsgText == null) { - myMsgText = new StringBuilder(); - msgText = myMsgText; - isChanged = true; + if (msgText == null) { + msgText = new StringBuilder(); } - if (text != null) { - final String trimmedText = StringUtils.removeTrailingWhitespace(text); - if (trimmedText.length() > 0) { - myMsgText.append(trimmedText); - isChanged = true; - } - } - - if (isChanged) { - gameObjectChanged(); - } + msgText.append(StringUtils.removeTrailingWhitespace(text)); + msgText.append("\n"); + gameObjectChanged(); } /** @@ -898,6 +862,27 @@ } /** + * Sets the message text. + * @param msgText the message text + */ + public void setMsgText(@Nullable final String msgText) { + final String trimmedMsgText = msgText == null ? null : StringUtils.removeTrailingWhitespaceFromLines(msgText); + if (this.msgText == null ? trimmedMsgText == null : this.msgText.toString().equals(trimmedMsgText)) { + return; + } + + if (trimmedMsgText == null) { + this.msgText = null; + } else if (this.msgText == null) { + this.msgText = new StringBuilder(trimmedMsgText); + } else { + this.msgText.setLength(0); + this.msgText.append(trimmedMsgText); + } + gameObjectChanged(); + } + + /** * Get the X coordinate of this GameObject on its map. This method only * guarantees a reasonable value for GameObjects that are directly bound to * a map (i.e. {@link #getTopContainer()} returns <code>null</code>). Modified: trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/GameObjectAttributesDialog.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/GameObjectAttributesDialog.java 2008-08-09 08:14:33 UTC (rev 4817) +++ trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/GameObjectAttributesDialog.java 2008-08-09 09:10:03 UTC (rev 4818) @@ -700,18 +700,16 @@ if (newMsg[0] != null) { // set new msg text only when it is not equal to Archetype if (!newMsg[0].trim().equals(archetype.getMsgText() == null ? "" : archetype.getMsgText().trim())) { - gameObject.deleteMsgText(); - gameObject.addMsgText(newMsg[0]); + gameObject.setMsgText(newMsg[0]); } else { - gameObject.deleteMsgText(); + gameObject.setMsgText(null); } } else if (archetype.getMsgText() != null && archetype.getMsgText().trim().length() > 0) { // we must override archetype msg by an empty msg - gameObject.deleteMsgText(); - gameObject.addMsgText(""); + gameObject.setMsgText(""); } else { - gameObject.deleteMsgText(); // all empty + gameObject.setMsgText(null); // all empty } if (newAnim[0] != null) { Modified: trunk/src/app/net/sf/gridarta/gui/gameobjectattributespanel/MsgTextTab.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/gameobjectattributespanel/MsgTextTab.java 2008-08-09 08:14:33 UTC (rev 4817) +++ trunk/src/app/net/sf/gridarta/gui/gameobjectattributespanel/MsgTextTab.java 2008-08-09 09:10:03 UTC (rev 4818) @@ -125,19 +125,18 @@ newMsgText = ""; } if (newMsgText.equals(archetype.getMsgText().trim())) { - gameObject.deleteMsgText(); // yes, we don't need it in map + gameObject.setMsgText(null); // yes, we don't need it in map } else { - gameObject.resetMsgText(); - gameObject.addMsgText(newMsgText); + gameObject.setMsgText(newMsgText); } } else { - gameObject.resetMsgText(); - gameObject.addMsgText(archTextArea.getText()); + gameObject.setMsgText(archTextArea.getText()); } } else { // there is nothing in the msg win - gameObject.deleteMsgText(); // always delete this... if (archetype.getMsgText() != null) { - gameObject.addMsgText(""); // but here we must overrule default with msg/endmsg (empty msg) + gameObject.setMsgText(""); // but here we must overrule default with msg/endmsg (empty msg) + } else { + gameObject.setMsgText(null); // always delete this... } } } Modified: trunk/src/app/net/sf/gridarta/io/AbstractGameObjectParser.java =================================================================== --- trunk/src/app/net/sf/gridarta/io/AbstractGameObjectParser.java 2008-08-09 08:14:33 UTC (rev 4817) +++ trunk/src/app/net/sf/gridarta/io/AbstractGameObjectParser.java 2008-08-09 09:10:03 UTC (rev 4818) @@ -108,7 +108,7 @@ if (thisLine.startsWith("endmsg")) { msgflag = false; } else { - gameObject.addMsgText(thisLine2 + "\n"); // thisLine2 allows leading whitespaces + gameObject.addMsgTextLine(thisLine2); // thisLine2 allows leading whitespaces } } else if (thisLine.startsWith("arch ")) { // ok, we had a full arch... don't care here about map or object @@ -123,7 +123,7 @@ } return gameObject; } else if (thisLine.startsWith("msg")) { - gameObject.addMsgText(""); + gameObject.setMsgText(""); msgflag = true; } else if (parseLine(thisLine, gameObject)) { // ignore Modified: trunk/src/app/net/sf/gridarta/map/DefaultMapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/DefaultMapModel.java 2008-08-09 08:14:33 UTC (rev 4817) +++ trunk/src/app/net/sf/gridarta/map/DefaultMapModel.java 2008-08-09 09:10:03 UTC (rev 4818) @@ -814,8 +814,7 @@ if (newObject != null) { newObject.setObjectText(newarchHead.getObjectText()); newObject.setObjName(newarchHead.getObjName()); - newObject.resetMsgText(); - newObject.addMsgText(newarchHead.getMsgText()); + newObject.setMsgText(newarchHead.getMsgText()); } return newObject; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |