|
From: Frederick W. <fre...@us...> - 2012-02-12 06:31:18
|
LocalisedText.properties | 4
data/Properties.xml | 8 -
rails/ui/images/add.png |binary
rails/ui/images/cancel.png |binary
rails/ui/swing/UpgradesPanel.java | 13 +-
rails/ui/swing/elements/ActionButton.java | 102 ----------------------
rails/ui/swing/elements/NonModalDialog.java | 7 -
rails/ui/swing/elements/RailsIcon.java | 9 +-
rails/ui/swing/elements/RailsIconButton.java | 121 +++++++++++++++++++++++++++
9 files changed, 146 insertions(+), 118 deletions(-)
New commits:
commit 827a52602ab7f82c1831d8a64648b5e37300bc0c
Author: Frederick Weld <fre...@gm...>
Date: Sun Feb 12 07:29:44 2012 +0100
Applied rails icon functionality to upgrade panel buttons
diff --git a/rails/ui/images/add.png b/rails/ui/images/add.png
new file mode 100644
index 0000000..60a7a29
Binary files /dev/null and b/rails/ui/images/add.png differ
diff --git a/rails/ui/swing/UpgradesPanel.java b/rails/ui/swing/UpgradesPanel.java
index edf24a2..c1a9df7 100644
--- a/rails/ui/swing/UpgradesPanel.java
+++ b/rails/ui/swing/UpgradesPanel.java
@@ -18,6 +18,8 @@ import rails.game.*;
import rails.game.action.*;
import rails.game.correct.MapCorrectionAction;
import rails.ui.swing.elements.ActionLabel;
+import rails.ui.swing.elements.RailsIcon;
+import rails.ui.swing.elements.RailsIconButton;
import rails.ui.swing.hexmap.GUIHex;
import rails.ui.swing.hexmap.GUITile;
import rails.ui.swing.hexmap.HexHighlightMouseListener;
@@ -42,13 +44,10 @@ public class UpgradesPanel extends Box implements MouseListener, ActionListener
private JScrollPane scrollPane;
private Dimension preferredSize;
private Border border = new EtchedBorder();
- private final String INIT_CANCEL_TEXT = "NoTile";
- private final String INIT_DONE_TEXT = "LayTile";
private boolean tokenMode = false;
private boolean correctionTokenMode = false;
- private JButton cancelButton =
- new JButton(LocalText.getText(INIT_CANCEL_TEXT));
- private JButton doneButton = new JButton(LocalText.getText(INIT_DONE_TEXT));
+ private RailsIconButton cancelButton = new RailsIconButton(RailsIcon.NO_TILE);
+ private RailsIconButton doneButton = new RailsIconButton(RailsIcon.LAY_TILE);
private HexMap hexMap;
//list of tiles with an attached reason why it would represent an invalid upgrade
@@ -452,11 +451,11 @@ public class UpgradesPanel extends Box implements MouseListener, ActionListener
}
public void setCancelText(String text) {
- cancelButton.setText(LocalText.getText(text));
+ cancelButton.setRailsIcon(RailsIcon.getByConfigKey(text));
}
public void setDoneText(String text) {
- doneButton.setText(LocalText.getText(text));
+ doneButton.setRailsIcon(RailsIcon.getByConfigKey(text));
}
public void setDoneEnabled(boolean enabled) {
commit 29e2d4953062a95616a3a1333b7930091f7be8e9
Author: Frederick Weld <fre...@gm...>
Date: Sun Feb 12 07:23:02 2012 +0100
Applied rails icon functionality to non modal dialogs
Model dialogs will stay unaffected as they don't provide for an
easy way to customize the option buttons.
diff --git a/rails/ui/images/cancel.png b/rails/ui/images/cancel.png
new file mode 100644
index 0000000..1b20ae0
Binary files /dev/null and b/rails/ui/images/cancel.png differ
diff --git a/rails/ui/swing/elements/NonModalDialog.java b/rails/ui/swing/elements/NonModalDialog.java
index 72718d2..36d8581 100644
--- a/rails/ui/swing/elements/NonModalDialog.java
+++ b/rails/ui/swing/elements/NonModalDialog.java
@@ -7,7 +7,6 @@ import javax.swing.*;
import org.apache.log4j.Logger;
-import rails.common.LocalText;
import rails.util.Util;
public abstract class NonModalDialog extends JDialog implements ActionListener {
@@ -22,7 +21,7 @@ public abstract class NonModalDialog extends JDialog implements ActionListener {
GridBagConstraints gc;
JPanel optionsPane, buttonPane;
- JButton okButton, cancelButton;
+ RailsIconButton okButton, cancelButton;
String okTextKey = "OK";
String cancelTextKey = "Cancel";
@@ -58,13 +57,13 @@ public abstract class NonModalDialog extends JDialog implements ActionListener {
optionsPane = new JPanel();
buttonPane = new JPanel();
- okButton = new JButton(LocalText.getText(okTextKey));
+ okButton = new RailsIconButton(RailsIcon.getByConfigKey(okTextKey));
okButton.setMnemonic(okTextKey.startsWith("Y") ? KeyEvent.VK_Y : KeyEvent.VK_O);
okButton.addActionListener(this);
buttonPane.add(okButton);
if (hasCancelButton) {
- cancelButton = new JButton(LocalText.getText(cancelTextKey));
+ cancelButton = new RailsIconButton(RailsIcon.getByConfigKey(cancelTextKey));
cancelButton.setMnemonic(cancelTextKey.startsWith("N") ? KeyEvent.VK_N : KeyEvent.VK_C);
cancelButton.addActionListener(this);
buttonPane.add(cancelButton);
diff --git a/rails/ui/swing/elements/RailsIcon.java b/rails/ui/swing/elements/RailsIcon.java
index bc420b0..90db59c 100644
--- a/rails/ui/swing/elements/RailsIcon.java
+++ b/rails/ui/swing/elements/RailsIcon.java
@@ -20,9 +20,15 @@ public enum RailsIcon {
BID ("money_add.png","BID"),
BUY_PRIVATE ("money_bag.png","BUY_PRIVATE"),
BUY_TRAIN ("train.png","BUY_TRAIN"),
+ CANCEL ("cancel.png","CANCEL"),
DONE ("accept.png","Done"),
INFO ("information.png","Info"),
- LAY_TILE ("rails32.png","LayTile"),
+ LAY_TILE ("add.png","LayTile"),
+ LAY_TOKEN ("add.png","LayToken"),
+ NO ("cancel.png","No"),
+ NO_TILE ("control_play_blue.png","NoTile"),
+ NO_TOKEN ("control_play_blue.png","NoToken"),
+ OK ("accept.png","OK"),
PANEL_OR ("participation_rate.png","Dockable.orWindow.orPanel"),
PANEL_OR_BUTTONS ("button.png","Dockable.orWindow.buttonPanel"),
PANEL_MAP ("globe_model.png","Dockable.orWindow.mapPanel"),
@@ -40,6 +46,7 @@ public enum RailsIcon {
SPLIT ("traffic_lights_yellow.png","SPLIT"),
UNDO ("arrow_undo.png","UNDO"),
WITHHOLD ("traffic_lights_red.png","WITHHOLD"),
+ YES ("accept.png","Yes"),
//no icons by purpose
END_OF_GAME_CLOSE_ALL_WINDOWS ("","END_OF_GAME_CLOSE_ALL_WINDOWS"),
commit 484cea4cbdc5d083c3f4587a682c624d0dc835a5
Author: Frederick Weld <fre...@gm...>
Date: Sun Feb 12 06:57:46 2012 +0100
Extracted icon functionality from ActionButton to generic superclass
Needed in order to prepare for using the same icon functionality
on non-action buttons.
diff --git a/LocalisedText.properties b/LocalisedText.properties
index a6f24f6..eac4de9 100644
--- a/LocalisedText.properties
+++ b/LocalisedText.properties
@@ -183,8 +183,8 @@ Config.infoText.sound.sfx.gen.newCurrentPlayer=<html>Enter assignment of sound e
Config.infoText.sound.sfx.or.buyTrain=<html>Enter assignment of sound effect files to train types.<ul><li>Separate the assignments by commas.<li>Each assignment has the syntax trainName=complete file path<li>Default sound effect is defined by omitting "trainName=" in the assignment.</ul><strong>Examples:</strong><ul><li>Set default sound effect: <br><code>c:\BuyTrain-default.mp3</code><li>Set train-dependent sound effect and a default (for trains above 6): <br><code>2=c:\BuyTrain-2.mp3,3=c:\BuyTrain-3.mp3,4=c:\BuyTrain-4.mp3,5=c:\BuyTrain-5.mp3,6=c:\BuyTrain-6.mp3,c:\BuyTrain-D.mp3</code></ul> </html>
Config.infoText.sound.sfx.or.setRevenue=<html><ul><li>Only the latter portion of this file is played.<ul><li>For an average revenue, the last third is played.</ul><li>The higher the company's revenue the longer this file is played.<ul><li>But the file is at most played once as a whole.</li></ul></html>
Config.infoText.sound.sfx.sr.newPresident=This also includes becoming the president when buying the president share.
-Config.label.actionButton.iconText=Button display type
-Config.label.actionButton.iconSize=Icon size
+Config.label.button.iconText=Button display type
+Config.label.button.iconSize=Button icon size
Config.label.default_game=Default game
Config.label.default_players=Default players
Config.label.font.ui.name=Font selection
diff --git a/data/Properties.xml b/data/Properties.xml
index b78d097..c207cbc 100644
--- a/data/Properties.xml
+++ b/data/Properties.xml
@@ -48,10 +48,10 @@
</Section>
<Section name="Appearance">
<Property name="gridPanel.tableBorders" type="LIST" values="disabled,enabled"/>
- <Property name="actionButton.iconText" type="LIST" values="text and icon,only text,only icon"
- initClass="rails.ui.swing.elements.ActionButton" initMethod="resetRailsIcons" initParameter="no" />
- <Property name="actionButton.iconSize" type="LIST" values="small,large"
- initClass="rails.ui.swing.elements.ActionButton" initMethod="resetRailsIcons" initParameter="no" />
+ <Property name="button.iconText" type="LIST" values="text and icon,only text,only icon"
+ initClass="rails.ui.swing.elements.RailsIconButton" initMethod="resetRailsIcons" initParameter="no" />
+ <Property name="button.iconSize" type="LIST" values="small,large"
+ initClass="rails.ui.swing.elements.RailsIconButton" initMethod="resetRailsIcons" initParameter="no" />
<Property name="route.colour.1" type="COLOR"
initClass="rails.ui.swing.hexmap.HexMap" initMethod="setRouteColours" />
<Property name="route.colour.2" type="COLOR"
diff --git a/rails/ui/swing/elements/ActionButton.java b/rails/ui/swing/elements/ActionButton.java
index d07bbba..b591fd3 100644
--- a/rails/ui/swing/elements/ActionButton.java
+++ b/rails/ui/swing/elements/ActionButton.java
@@ -1,16 +1,9 @@
/* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/ui/swing/elements/ActionButton.java,v 1.5 2008/06/04 19:00:38 evos Exp $*/
package rails.ui.swing.elements;
-import java.awt.Insets;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-import javax.swing.JButton;
-
-import rails.common.parser.Config;
import rails.game.action.ActionTaker;
import rails.game.action.PossibleAction;
@@ -19,38 +12,14 @@ import rails.game.action.PossibleAction;
*
* @see ClickField
*/
-public class ActionButton extends JButton implements ActionTaker {
+public class ActionButton extends RailsIconButton implements ActionTaker {
private static final long serialVersionUID = 1L;
- private static final Set<String> KEYS_TEXT_DISPLAY = new HashSet<String>
- (Arrays.asList( new String[] {
- "text and icon",
- "only text",
- "",
- null
- }));
- private static final Set<String> KEYS_ICON_DISPLAY = new HashSet<String>
- (Arrays.asList( new String[] {
- "text and icon",
- "only icon"
- }));
-
- private static Set<ActionButton> actionButtons = new HashSet<ActionButton>();
-
private List<PossibleAction> actions = new ArrayList<PossibleAction>(1);
- /**
- * null value means that the action button is not set up by an appropriate
- * RailsIcon (eg., by calling setText directly).
- */
- private RailsIcon railsIcon = null;
-
public ActionButton(RailsIcon railsIcon) {
- super();
- setRailsIcon(railsIcon);
- this.setMargin(new Insets(2,2,2,2));
- actionButtons.add(this);
+ super(railsIcon);
}
public void addPossibleAction(PossibleAction o) {
@@ -70,71 +39,4 @@ public class ActionButton extends JButton implements ActionTaker {
addPossibleAction(action);
}
- public void setRailsIcon(RailsIcon railsIcon) {
- if (railsIcon == null) railsIcon = RailsIcon.NULL;
- this.railsIcon = railsIcon;
- showRailsIcon();
- }
-
- /**
- * Display according to configuration.
- * If no text/icon is attached, then icon/text is displayed as fallback
- * (irrespective of configuration).
- * Text becomes the tool tip text in case of icon-only display.
- */
- private void showRailsIcon() {
- if (railsIcon != null) {
- if (isTextEnabled() || railsIcon.largeIcon == null) {
- super.setText(railsIcon.description);
- } else {
- super.setText(null);
- }
- if (isIconEnabled() || railsIcon.description == null) {
- if (isIconSizeSmall()) {
- super.setIcon(railsIcon.smallIcon);
- } else {
- super.setIcon(railsIcon.largeIcon);
- }
- if (!isTextEnabled()) {
- super.setToolTipText(railsIcon.description);
- }
- } else {
- super.setIcon(null);
- }
- }
- }
-
- private boolean isTextEnabled() {
- return KEYS_TEXT_DISPLAY.contains(Config.get("actionButton.iconText",""));
- }
-
- private boolean isIconEnabled() {
- return KEYS_ICON_DISPLAY.contains(Config.get("actionButton.iconText",""));
- }
-
- private boolean isIconSizeSmall() {
- //small is default
- return !"large".equals(Config.get("actionButton.iconSize"));
- }
-
- /**
- * Should only be used if an arbitrary text is to displayed without icon.
- * In any other case, setRailsIcon should be used.
- */
- @Override
- public void setText(String text) {
- super.setText(text);
- setIcon(null);
- railsIcon = null;
- }
-
- /**
- * To be called upon change of button display type
- */
- public static void resetRailsIcons() {
- for (ActionButton ab : actionButtons) {
- ab.showRailsIcon();
- }
- }
-
}
diff --git a/rails/ui/swing/elements/RailsIconButton.java b/rails/ui/swing/elements/RailsIconButton.java
new file mode 100644
index 0000000..3f6d628
--- /dev/null
+++ b/rails/ui/swing/elements/RailsIconButton.java
@@ -0,0 +1,121 @@
+/**
+ *
+ */
+package rails.ui.swing.elements;
+
+import java.awt.Insets;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.swing.JButton;
+
+import rails.common.parser.Config;
+
+/**
+ * A JButton which is able to hold/manage a RailsIcon (specifying what
+ * text / icon is to be displayed)
+ *
+ * @author Frederick Weld
+ *
+ */
+public class RailsIconButton extends JButton {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Set<String> KEYS_TEXT_DISPLAY = new HashSet<String>
+ (Arrays.asList( new String[] {
+ "text and icon",
+ "only text",
+ "",
+ null
+ }));
+ private static final Set<String> KEYS_ICON_DISPLAY = new HashSet<String>
+ (Arrays.asList( new String[] {
+ "text and icon",
+ "only icon"
+ }));
+
+ private static Set<RailsIconButton> railsIconButtons = new HashSet<RailsIconButton>();
+
+ /**
+ * null value means that the button is not set up by an appropriate
+ * RailsIcon (eg., by calling setText directly).
+ */
+ private RailsIcon railsIcon = null;
+
+ public RailsIconButton(RailsIcon railsIcon) {
+ super();
+ setRailsIcon(railsIcon);
+ this.setMargin(new Insets(2,2,2,2));
+ railsIconButtons.add(this);
+ }
+
+ public void setRailsIcon(RailsIcon railsIcon) {
+ if (railsIcon == null) railsIcon = RailsIcon.NULL;
+ this.railsIcon = railsIcon;
+ showRailsIcon();
+ }
+
+ /**
+ * Display according to configuration.
+ * If no text/icon is attached, then icon/text is displayed as fallback
+ * (irrespective of configuration).
+ * Text becomes the tool tip text in case of icon-only display.
+ */
+ private void showRailsIcon() {
+ if (railsIcon != null) {
+ if (isTextEnabled() || railsIcon.largeIcon == null) {
+ super.setText(railsIcon.description);
+ } else {
+ super.setText(null);
+ }
+ if (isIconEnabled() || railsIcon.description == null) {
+ if (isIconSizeSmall()) {
+ super.setIcon(railsIcon.smallIcon);
+ } else {
+ super.setIcon(railsIcon.largeIcon);
+ }
+ if (!isTextEnabled()) {
+ super.setToolTipText(railsIcon.description);
+ }
+ } else {
+ super.setIcon(null);
+ }
+ }
+ }
+
+ private boolean isTextEnabled() {
+ return KEYS_TEXT_DISPLAY.contains(Config.get("button.iconText",""));
+ }
+
+ private boolean isIconEnabled() {
+ return KEYS_ICON_DISPLAY.contains(Config.get("button.iconText",""));
+ }
+
+ private boolean isIconSizeSmall() {
+ //small is default
+ return !"large".equals(Config.get("button.iconSize"));
+ }
+
+ /**
+ * Should only be used if an arbitrary text is to displayed without icon.
+ * In any other case, setRailsIcon should be used.
+ */
+ @Override
+ public void setText(String text) {
+ super.setText(text);
+ setIcon(null);
+ railsIcon = null;
+ }
+
+ /**
+ * To be called upon change of button display type
+ */
+ public static void resetRailsIcons() {
+ for (RailsIconButton rib : railsIconButtons) {
+ rib.showRailsIcon();
+ }
+ }
+
+}
|