From: Frederick W. <fre...@us...> - 2012-01-13 17:50:42
|
rails/ui/swing/MapPanel.java | 6 ++- rails/ui/swing/MessagePanel.java | 75 +++++++++++++++++++++++++++----------- rails/ui/swing/ORPanel.java | 4 +- rails/ui/swing/ORUIManager.java | 26 +++++++++---- rails/ui/swing/ORWindow.java | 7 --- rails/ui/swing/hexmap/HexMap.java | 33 +++++++++++++++- 6 files changed, 110 insertions(+), 41 deletions(-) New commits: commit 4cdf576bea5a4364d278af8dc6f736b6b4868624 Author: Frederick Weld <fre...@gm...> Date: Fri Jan 13 18:47:21 2012 +0100 Enlarged message panel for route details Upon click details, the message panel's height is now increased. In addition, the bug of duplicating message contents for set revenue is fixed. diff --git a/rails/ui/swing/MessagePanel.java b/rails/ui/swing/MessagePanel.java index 6e8e1fc..6c50471 100644 --- a/rails/ui/swing/MessagePanel.java +++ b/rails/ui/swing/MessagePanel.java @@ -2,10 +2,9 @@ package rails.ui.swing; import java.awt.Color; +import java.awt.Dimension; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.util.ArrayList; -import java.util.List; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -14,14 +13,20 @@ public class MessagePanel extends JPanel { private static final long serialVersionUID = 1L; //the height of this panel (fixed because scroll bar is used) - public static final int fixedHeight = 45; + public static final int defaultHeight = 45; + + //the height of this panel if details are open + public static final int fullHeight = 90; + public static final int minWidth = 100; public static final int scrollUnit = 8; + public static final int minMarginForFullHeight = 8; private JLabel message; + private JScrollPane parentSlider; private String currentMessage; private StringBuffer currentInformation; - private List<String> currentDetails = new ArrayList<String>(); + private String currentDetails; private boolean showDetails; Color background = new Color(225, 225, 225); @@ -44,8 +49,7 @@ public class MessagePanel extends JPanel { this.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent arg0) { - showDetails = !showDetails; - updateMessageText(); + toggleDetailsEnablement(); } public void mouseEntered(MouseEvent arg0) {} @@ -56,6 +60,41 @@ public class MessagePanel extends JPanel { } + /** + * @param parentSlider Component between OR window and the panel + */ + public void setParentSlider(JScrollPane parentSlider) { + this.parentSlider = parentSlider; + parentSlider.setBorder(BorderFactory.createLoweredBevelBorder()); + parentSlider.getVerticalScrollBar().setUnitIncrement(scrollUnit); + parentSlider.setPreferredSize(new Dimension(minWidth,defaultHeight)); + } + + private void disableDetails() { + if (showDetails) { + showDetails = false; + parentSlider.setPreferredSize(new Dimension(minWidth,defaultHeight)); + parentSlider.getParent().revalidate(); + } + } + + private void enableDetails() { + if (!showDetails && currentDetails != null) { + showDetails = true; + parentSlider.setPreferredSize(new Dimension(minWidth,fullHeight)); + parentSlider.getParent().revalidate(); + } + } + + private void toggleDetailsEnablement() { + if (showDetails) { + disableDetails(); + } else { + enableDetails(); + } + updateMessageText(); + } + private void updateMessageText() { StringBuffer messageText = new StringBuffer() ; if (currentMessage != null) { @@ -68,19 +107,15 @@ public class MessagePanel extends JPanel { } if (showDetails) { messageText.append("<span style='color:blue; font-size:80%'>"); - for (String detail:currentDetails) { - messageText.append(detail); - } + messageText.append(currentDetails); messageText.append("</span>"); - } else if (currentDetails.size() != 0) { + } else if (currentDetails != null) { messageText.append("<span style='color:blue; font-size:80%'>"); - messageText.append("<BR> Click for more details"); + messageText.append(" Click for more details"); messageText.append("</span>"); } // display String text = messageText.toString(); - //int lines = text.split("<[Bb][Rr]>").length + 1; -// setLines(lines); message.setText("<html><center>" + text + "</center></html>"); } @@ -88,21 +123,19 @@ public class MessagePanel extends JPanel { public void setMessage(String messageText) { currentMessage = messageText; currentInformation = null; - currentDetails.clear(); - showDetails = false; + currentDetails = null; + disableDetails(); updateMessageText(); } - public void addInformation(String infoText) { - if (currentInformation == null) { - currentInformation = new StringBuffer(); - } + public void setInformation(String infoText) { + currentInformation = new StringBuffer(); currentInformation.append("<BR>" + infoText); updateMessageText(); } - public void addDetail(String detailText) { - currentDetails.add("<BR>" + detailText); + public void setDetail(String detailText) { + currentDetails = "<BR>" + detailText; updateMessageText(); } diff --git a/rails/ui/swing/ORPanel.java b/rails/ui/swing/ORPanel.java index b2251c3..0d0c5ec 100644 --- a/rails/ui/swing/ORPanel.java +++ b/rails/ui/swing/ORPanel.java @@ -1055,9 +1055,9 @@ implements ActionListener, KeyListener, RevenueListener { orUIManager.getMap().setTrainPaths(null); revenueAdapter.drawOptimalRunAsPath(orUIManager.getMap()); if (isRevenueValueToBeSet) { - orUIManager.addInformation("Best Run Value = " + bestRevenue + + orUIManager.setInformation("Best Run Value = " + bestRevenue + " with " + Util.convertToHtml(revenueAdapter.getOptimalRunPrettyPrint(false))); - orUIManager.addDetail(Util.convertToHtml(revenueAdapter.getOptimalRunPrettyPrint(true))); + orUIManager.setDetail(Util.convertToHtml(revenueAdapter.getOptimalRunPrettyPrint(true))); } } } diff --git a/rails/ui/swing/ORUIManager.java b/rails/ui/swing/ORUIManager.java index a7bef1c..410605e 100644 --- a/rails/ui/swing/ORUIManager.java +++ b/rails/ui/swing/ORUIManager.java @@ -1934,12 +1934,12 @@ public class ORUIManager implements DialogOwner { messagePanel.setMessage(message); } - public void addInformation(String infoText) { - messagePanel.addInformation(infoText); + public void setInformation(String infoText) { + messagePanel.setInformation(infoText); } - public void addDetail(String detailText) { - messagePanel.addDetail(detailText); + public void setDetail(String detailText) { + messagePanel.setDetail(detailText); } public void setLocalAction(boolean value) { diff --git a/rails/ui/swing/ORWindow.java b/rails/ui/swing/ORWindow.java index c0a162f..5c6f5bb 100644 --- a/rails/ui/swing/ORWindow.java +++ b/rails/ui/swing/ORWindow.java @@ -2,13 +2,11 @@ package rails.ui.swing; import java.awt.BorderLayout; -import java.awt.Dimension; import java.awt.Rectangle; import java.awt.event.*; import java.util.ArrayList; import java.util.List; -import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JScrollPane; @@ -65,9 +63,7 @@ public class ORWindow extends JFrame implements ActionPerformer { messagePanel = new MessagePanel(); JScrollPane slider = new JScrollPane(messagePanel); - slider.setBorder(BorderFactory.createLoweredBevelBorder()); - slider.getVerticalScrollBar().setUnitIncrement(MessagePanel.scrollUnit); - slider.setPreferredSize(new Dimension(100,MessagePanel.fixedHeight)); + messagePanel.setParentSlider(slider); getContentPane().add(slider, BorderLayout.NORTH); commit d011569730b37316997b35d67778dcd2014ba6cb Author: Frederick Weld <fre...@gm...> Date: Fri Jan 13 17:13:24 2012 +0100 Configured tooltips such that they remain visible forever unless mouse move Upon Erik's request: tool tip dismiss delay is on infinity. diff --git a/rails/ui/swing/MapPanel.java b/rails/ui/swing/MapPanel.java index 7f19442..265defe 100644 --- a/rails/ui/swing/MapPanel.java +++ b/rails/ui/swing/MapPanel.java @@ -64,6 +64,9 @@ public class MapPanel extends JPanel { //lightwight tooltip possible since tool tip has its own layer in hex map ToolTipManager.sharedInstance().setLightWeightPopupEnabled(true); + //tooltip should not be dismissed after at all + ToolTipManager.sharedInstance().setDismissDelay(Integer.MAX_VALUE); + layeredPane = new JLayeredPane(); layeredPane.setLayout(null); layeredPane.setPreferredSize(originalMapSize); commit 115afe5d4f7d12f6e8109e4f1e7aebd190979039 Author: Frederick Weld <fre...@gm...> Date: Fri Jan 13 17:07:44 2012 +0100 Polished hex map tool tips (lightwight tooltips, tooltip upon click) - mouseover on tooltip no longer leads to no highlighted hex (put tooltips as lightwight - possible due to new hexmap layering) - clicking on hex without associated action does not lead to disappearance of tooltip diff --git a/rails/ui/swing/MapPanel.java b/rails/ui/swing/MapPanel.java index 66c81d6..7f19442 100644 --- a/rails/ui/swing/MapPanel.java +++ b/rails/ui/swing/MapPanel.java @@ -61,7 +61,8 @@ public class MapPanel extends JPanel { return; } - ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); + //lightwight tooltip possible since tool tip has its own layer in hex map + ToolTipManager.sharedInstance().setLightWeightPopupEnabled(true); layeredPane = new JLayeredPane(); layeredPane.setLayout(null); diff --git a/rails/ui/swing/ORUIManager.java b/rails/ui/swing/ORUIManager.java index a097bf7..a7bef1c 100644 --- a/rails/ui/swing/ORUIManager.java +++ b/rails/ui/swing/ORUIManager.java @@ -600,9 +600,15 @@ public class ORUIManager implements DialogOwner { if (!(dialog instanceof MessageDialog)) orPanel.disableButtons(); } - public void hexClicked(GUIHex clickedHex, GUIHex selectedHex) { + /** + * @return True if the map panel expected hex clicks for actions / corrections + */ + public boolean hexClicked(GUIHex clickedHex, GUIHex selectedHex) { + boolean triggerORPanelRepaint = false; + if (mapCorrectionEnabled) { + triggerORPanelRepaint = true; boolean checkClickedHex = false; switch (mapCorrectionAction.getStep()) { case SELECT_HEX: @@ -622,11 +628,12 @@ public class ORUIManager implements DialogOwner { orWindow.process(mapCorrectionAction); } } else if (tokenLayingEnabled) { + triggerORPanelRepaint = true; // if clickedHex == null, then go back to select hex step if (clickedHex == null) { upgradePanel.setPossibleTokenLays(null); setLocalStep(SELECT_HEX_FOR_TOKEN); - return; + return true; } List<LayToken> allowances = map.getTokenAllowanceForHex(clickedHex.getHexModel()); @@ -645,10 +652,11 @@ public class ORUIManager implements DialogOwner { } } else if (tileLayingEnabled) { + triggerORPanelRepaint = true; if (localStep == ROTATE_OR_CONFIRM_TILE && clickedHex == selectedHex) { selectedHex.rotateTile(); - return; + return true; } else { if (selectedHex != null && clickedHex != selectedHex) { @@ -676,7 +684,9 @@ public class ORUIManager implements DialogOwner { } } - orWindow.repaintORPanel(); + if (triggerORPanelRepaint) orWindow.repaintORPanel(); + + return triggerORPanelRepaint; } public void tileSelected(int tileId) { diff --git a/rails/ui/swing/ORWindow.java b/rails/ui/swing/ORWindow.java index dcef993..c0a162f 100644 --- a/rails/ui/swing/ORWindow.java +++ b/rails/ui/swing/ORWindow.java @@ -12,7 +12,6 @@ import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JScrollPane; -import javax.swing.border.EmptyBorder; import org.apache.log4j.Logger; diff --git a/rails/ui/swing/hexmap/HexMap.java b/rails/ui/swing/hexmap/HexMap.java index 6029c93..e220614 100644 --- a/rails/ui/swing/hexmap/HexMap.java +++ b/rails/ui/swing/hexmap/HexMap.java @@ -780,7 +780,7 @@ public abstract class HexMap implements MouseListener, // } // do nothing as tooltip update before display } - + /** * Mouse Listener methods (hexMap offers listener for all layers) */ @@ -789,7 +789,34 @@ public abstract class HexMap implements MouseListener, Point point = arg0.getPoint(); GUIHex clickedHex = getHexContainingPoint(point); - orUIManager.hexClicked(clickedHex, selectedHex); + //if no action/correction was expected on the map panel + if (!orUIManager.hexClicked(clickedHex, selectedHex)) { + + // force the tool tip popup to appear immediately + ToolTipManager ttm = ToolTipManager.sharedInstance(); + MouseEvent phantomME = new MouseEvent( + toolTipsLayer, + MouseEvent.MOUSE_MOVED, + System.currentTimeMillis(), + 0, + arg0.getX(), + arg0.getY(), + 0, + false); + + int priorToolTipDelay = ttm.getInitialDelay(); + ttm.setInitialDelay(0); + ttm.mouseMoved(phantomME); + ttm.setInitialDelay(priorToolTipDelay); + +// int priorToolTipDelay = ttm.getInitialDelay(); +// ttm.mouseEntered(new MouseAdapter()); +// ToolTipManager.sharedInstance().setInitialDelay(0); +// try { +// this.wait(1); +// } catch (InterruptedException e) {} +// map = map; + } } public void mouseDragged(MouseEvent arg0) {} @@ -806,7 +833,7 @@ public abstract class HexMap implements MouseListener, if (newHex != null) newHex.addHighlightRequest(); //display tool tip - setToolTipText(newHex != null ? newHex.getToolTip() : ""); + setToolTipText(newHex != null ? newHex.getToolTip() : null); hexAtMousePosition = newHex; } |
From: Erik V. <ev...@us...> - 2012-01-30 12:32:40
|
rails/ui/swing/GameStatus.java | 1 rails/ui/swing/GameUIManager.java | 3 rails/ui/swing/ORUIManager.java | 6 rails/ui/swing/StartRoundWindow.java | 4 rails/ui/swing/elements/CheckBoxDialog.java | 107 ++-------- rails/ui/swing/elements/MessageDialog.java | 78 ------- rails/ui/swing/elements/NonModalDialog.java | 137 ++++++++++++++ rails/ui/swing/elements/RadioButtonDialog.java | 110 ++--------- rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java | 6 rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java | 4 rails/ui/swing/gamespecific/_18EU/GameStatus_18EU.java | 5 rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java | 7 12 files changed, 208 insertions(+), 260 deletions(-) New commits: commit 423369599568b645e0a86cbc2dc7d028ee1c3a77 Author: Erik Vos <eri...@xs...> Date: Mon Jan 30 13:29:51 2012 +0100 Refactored nonmodal dialog classes II Added MessageDialog. diff --git a/rails/ui/swing/elements/CheckBoxDialog.java b/rails/ui/swing/elements/CheckBoxDialog.java index 9c30081..0a56e91 100644 --- a/rails/ui/swing/elements/CheckBoxDialog.java +++ b/rails/ui/swing/elements/CheckBoxDialog.java @@ -46,7 +46,7 @@ public class CheckBoxDialog extends NonModalDialog { } @Override - protected void initializeContent() { + protected void initializeInput() { checkBoxes = new JCheckBox[numOptions]; diff --git a/rails/ui/swing/elements/MessageDialog.java b/rails/ui/swing/elements/MessageDialog.java index 47e6353..e4bfe66 100644 --- a/rails/ui/swing/elements/MessageDialog.java +++ b/rails/ui/swing/elements/MessageDialog.java @@ -1,93 +1,21 @@ /* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/ui/swing/elements/MessageDialog.java,v 1.1 2010/01/19 19:49:39 evos Exp $*/ package rails.ui.swing.elements; -import java.awt.*; -import java.awt.event.*; - -import javax.swing.*; - -import org.apache.log4j.Logger; - -import rails.common.LocalText; +import javax.swing.JFrame; /** * A generic dialog for presenting choices by checkboxes. */ -public class MessageDialog extends JDialog implements ActionListener { +public class MessageDialog extends NonModalDialog { private static final long serialVersionUID = 1L; - protected DialogOwner owner = null; - GridBagConstraints gc; - JPanel optionsPane, buttonPane; - JButton okButton; - Dimension size, optSize; - - String message; - - protected static Logger log = - Logger.getLogger(MessageDialog.class.getPackage().getName()); - public MessageDialog(DialogOwner owner, JFrame window, String title, String message) { - super((Frame) null, title, false); // Non-modal - this.owner = owner; - this.message = message; + super (Type.MESSAGE, null, owner, window, title, message, false); initialize(); - pack(); - - // Center on window - int x = (int) window.getLocationOnScreen().getX() - + (window.getWidth() - getWidth()) / 2; - int y = (int) window.getLocationOnScreen().getY() - + (window.getHeight() - getHeight()) / 2; - setLocation(x, y); - - setVisible(true); - toFront(); - } - - private void initialize() { - gc = new GridBagConstraints(); - - optionsPane = new JPanel(); - buttonPane = new JPanel(); - - okButton = new JButton(LocalText.getText("OK")); - okButton.setMnemonic(KeyEvent.VK_O); - okButton.addActionListener(this); - buttonPane.add(okButton); - - getContentPane().setLayout(new GridBagLayout()); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - optionsPane.setLayout(new GridBagLayout()); - optionsPane.add(new JLabel(message), constraints(0, 0, 10, 10, 10, 10)); - - getContentPane().add(optionsPane, constraints(0, 0, 0, 0, 0, 0)); - getContentPane().add(buttonPane, constraints(0, 1, 0, 0, 0, 0)); - } - - private GridBagConstraints constraints(int gridx, int gridy, int leftinset, - int topinset, int rightinset, int bottominset) { - if (gridx >= 0) gc.gridx = gridx; - if (gridy >= 0) gc.gridy = gridy; - gc.fill = GridBagConstraints.BOTH; - gc.weightx = 0.5; - gc.weighty = 0.5; - if (leftinset >= 0) gc.insets.left = leftinset; - if (topinset >= 0) gc.insets.top = topinset; - if (rightinset >= 0) gc.insets.right = rightinset; - if (bottominset >= 0) gc.insets.bottom = bottominset; - - return gc; - } - public void actionPerformed(ActionEvent arg0) { - setVisible(false); - dispose(); - owner.dialogActionPerformed (); } } diff --git a/rails/ui/swing/elements/NonModalDialog.java b/rails/ui/swing/elements/NonModalDialog.java index fff6538..0fe730c 100644 --- a/rails/ui/swing/elements/NonModalDialog.java +++ b/rails/ui/swing/elements/NonModalDialog.java @@ -39,7 +39,8 @@ public abstract class NonModalDialog extends JDialog implements ActionListener { public static enum Type { CHECKBOX, RADIO, - MESSAGE + MESSAGE, + MIXED } protected static Logger log = @@ -83,7 +84,7 @@ public abstract class NonModalDialog extends JDialog implements ActionListener { optionsPane.setLayout(new GridBagLayout()); optionsPane.add(new JLabel(message), constraints(0, 0, 10, 10, 10, 10)); - initializeContent(); + initializeInput(); getContentPane().add(optionsPane, constraints(0, 0, 0, 0, 0, 0)); getContentPane().add(buttonPane, constraints(0, 1, 0, 0, 0, 0)); @@ -101,7 +102,8 @@ public abstract class NonModalDialog extends JDialog implements ActionListener { setAlwaysOnTop(true); } - protected abstract void initializeContent(); + protected void initializeInput() { + } protected GridBagConstraints constraints(int gridx, int gridy, int leftinset, int topinset, int rightinset, int bottominset) { @@ -129,7 +131,7 @@ public abstract class NonModalDialog extends JDialog implements ActionListener { owner.dialogActionPerformed (); } - protected abstract void processOK (ActionEvent actionEvent); + protected void processOK (ActionEvent actionEvent) {}; - protected abstract void processCancel (ActionEvent actionEvent); + protected void processCancel (ActionEvent actionEvent) {}; } diff --git a/rails/ui/swing/elements/RadioButtonDialog.java b/rails/ui/swing/elements/RadioButtonDialog.java index a40b1a7..1d7cc59 100644 --- a/rails/ui/swing/elements/RadioButtonDialog.java +++ b/rails/ui/swing/elements/RadioButtonDialog.java @@ -35,7 +35,7 @@ public class RadioButtonDialog extends NonModalDialog { } @Override - protected void initializeContent() { + protected void initializeInput() { choiceButtons = new JRadioButton[numOptions]; group = new ButtonGroup(); commit 3d8a7a01e36779e6cf92ce6ea54d720d621d496a Merge: 6716550 6f3e1b3 Author: Erik Vos <eri...@xs...> Date: Mon Jan 30 12:49:33 2012 +0100 Merge branch 'master' of ssh://rails.git.sourceforge.net/gitroot/rails/rails into nonmodal commit 6716550625b1eca8cac294f59c38418d690e44c5 Author: Erik Vos <eri...@xs...> Date: Wed Jan 25 14:18:29 2012 +0100 Refactored non-modal dialog classes. All are now subclasses of a new abstract class NonModalDialog, which contains most of the common code. diff --git a/rails/ui/swing/GameStatus.java b/rails/ui/swing/GameStatus.java index 3e30944..b15bd42 100644 --- a/rails/ui/swing/GameStatus.java +++ b/rails/ui/swing/GameStatus.java @@ -764,6 +764,7 @@ public class GameStatus extends GridPanel implements ActionListener { if (options.size() > 1) { if (startCompany) { RadioButtonDialog dialog = new RadioButtonDialog ( + NonModalDialog.Usage.COMPANY_START_PRICE, gameUIManager, parent, LocalText.getText("PleaseSelect"), diff --git a/rails/ui/swing/GameUIManager.java b/rails/ui/swing/GameUIManager.java index e50d32e..ae71267 100644 --- a/rails/ui/swing/GameUIManager.java +++ b/rails/ui/swing/GameUIManager.java @@ -620,7 +620,8 @@ public class GameUIManager implements DialogOwner { orWindow.setVisible(true); orWindow.toFront(); - CheckBoxDialog dialog = new CheckBoxDialog(this, + CheckBoxDialog dialog = new CheckBoxDialog(NonModalDialog.Usage.EXCHANGE_TOKENS, + this, orWindow, LocalText.getText("ExchangeTokens"), prompt, diff --git a/rails/ui/swing/ORUIManager.java b/rails/ui/swing/ORUIManager.java index db96ac7..b31dd09 100644 --- a/rails/ui/swing/ORUIManager.java +++ b/rails/ui/swing/ORUIManager.java @@ -547,7 +547,8 @@ public class ORUIManager implements DialogOwner { orWindow.setVisible(true); orWindow.toFront(); - CheckBoxDialog dialog = new CheckBoxDialog(this, + CheckBoxDialog dialog = new CheckBoxDialog(NonModalDialog.Usage.SELECT_DESTINATION_COMPANIES, + this, orWindow, LocalText.getText("DestinationsReached"), LocalText.getText("DestinationsReachedPrompt"), @@ -1462,7 +1463,8 @@ public class ORUIManager implements DialogOwner { Bank.format(i * loanAmount)); } } - RadioButtonDialog currentDialog = new RadioButtonDialog (gameUIManager, + RadioButtonDialog currentDialog = new RadioButtonDialog (NonModalDialog.Usage.REPAY_LOANS, + gameUIManager, orWindow, LocalText.getText("Select"), LocalText.getText("SelectLoansToRepay", action.getCompanyName()), diff --git a/rails/ui/swing/StartRoundWindow.java b/rails/ui/swing/StartRoundWindow.java index 4cf1b88..1b9af8a 100644 --- a/rails/ui/swing/StartRoundWindow.java +++ b/rails/ui/swing/StartRoundWindow.java @@ -648,7 +648,9 @@ implements ActionListener, KeyListener, ActionPerformer, DialogOwner { options[i] = Bank.format(spacePerPrice.get(startPrices[i]).getPrice()); } - RadioButtonDialog dialog = new RadioButtonDialog(this, + RadioButtonDialog dialog = new RadioButtonDialog( + NonModalDialog.Usage.COMPANY_START_PRICE, + this, this, LocalText.getText("PleaseSelect"), LocalText.getText("WHICH_START_PRICE", diff --git a/rails/ui/swing/elements/CheckBoxDialog.java b/rails/ui/swing/elements/CheckBoxDialog.java index 910180c..9c30081 100644 --- a/rails/ui/swing/elements/CheckBoxDialog.java +++ b/rails/ui/swing/elements/CheckBoxDialog.java @@ -1,26 +1,18 @@ /* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/ui/swing/elements/CheckBoxDialog.java,v 1.9 2010/06/16 20:59:10 evos Exp $*/ package rails.ui.swing.elements; -import java.awt.*; -import java.awt.event.*; +import java.awt.Dimension; +import java.awt.event.ActionEvent; import javax.swing.*; -import org.apache.log4j.Logger; - -import rails.common.LocalText; - /** * A generic dialog for presenting choices by checkboxes. */ -public class CheckBoxDialog extends JDialog implements ActionListener { +public class CheckBoxDialog extends NonModalDialog { private static final long serialVersionUID = 1L; - protected DialogOwner owner = null; - GridBagConstraints gc; - JPanel optionsPane, buttonPane; - JButton okButton, cancelButton; JCheckBox[] checkBoxes; Dimension size, optSize; ButtonGroup group; @@ -32,22 +24,18 @@ public class CheckBoxDialog extends JDialog implements ActionListener { int chosenOption = -1; boolean hasCancelButton = false; - protected static Logger log = - Logger.getLogger(CheckBoxDialog.class.getPackage().getName()); - - public CheckBoxDialog(DialogOwner owner, JFrame window, String title, String message, + public CheckBoxDialog(Usage usage, DialogOwner owner, JFrame window, String title, String message, String[] options) { - this (owner, window, title, message, options, null, false); + this (usage, owner, window, title, message, options, null, false); } - public CheckBoxDialog(DialogOwner owner, JFrame window, String title, String message, + public CheckBoxDialog(Usage usage, DialogOwner owner, JFrame window, String title, String message, String[] options, boolean[] selectedOptions, boolean addCancelButton) { - super((Frame) null, title, false); // Non-modal - this.owner = owner; - this.message = message; + + super (Type.CHECKBOX, usage, owner, window, title, message, addCancelButton); + this.options = options; this.numOptions = options.length; - this.hasCancelButton = addCancelButton; if (selectedOptions != null) { this.selectedOptions = selectedOptions; } else { @@ -55,84 +43,31 @@ public class CheckBoxDialog extends JDialog implements ActionListener { } initialize(); - pack(); - - // Center on owner - int x = (int) window.getLocationOnScreen().getX() - + (window.getWidth() - getWidth()) / 2; - int y = (int) window.getLocationOnScreen().getY() - + (window.getHeight() - getHeight()) / 2; - setLocation(x, y); - - setVisible(true); - setAlwaysOnTop(true); } - private void initialize() { - gc = new GridBagConstraints(); - - optionsPane = new JPanel(); - buttonPane = new JPanel(); - - okButton = new JButton(LocalText.getText("OK")); - okButton.setMnemonic(KeyEvent.VK_O); - okButton.addActionListener(this); - buttonPane.add(okButton); - - if (hasCancelButton) { - cancelButton = new JButton(LocalText.getText("Cancel")); - cancelButton.setMnemonic(KeyEvent.VK_C); - cancelButton.addActionListener(this); - buttonPane.add(cancelButton); - } - - checkBoxes = new JCheckBox[numOptions]; - - getContentPane().setLayout(new GridBagLayout()); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - optionsPane.setLayout(new GridBagLayout()); - optionsPane.add(new JLabel(message), constraints(0, 0, 10, 10, 10, 10)); + @Override + protected void initializeContent() { checkBoxes = new JCheckBox[numOptions]; for (int i = 0; i < numOptions; i++) { checkBoxes[i] = - new JCheckBox(options[i], selectedOptions[i]); + new JCheckBox(options[i], selectedOptions[i]); optionsPane.add(checkBoxes[i], constraints(0, 1 + i, 0, 0, 0, 0)); - checkBoxes[i].setPreferredSize(size); + //checkBoxes[i].setPreferredSize(size); } - - getContentPane().add(optionsPane, constraints(0, 0, 0, 0, 0, 0)); - getContentPane().add(buttonPane, constraints(0, 1, 0, 0, 0, 0)); } - private GridBagConstraints constraints(int gridx, int gridy, int leftinset, - int topinset, int rightinset, int bottominset) { - if (gridx >= 0) gc.gridx = gridx; - if (gridy >= 0) gc.gridy = gridy; - gc.fill = GridBagConstraints.BOTH; - gc.weightx = 0.5; - gc.weighty = 0.5; - if (leftinset >= 0) gc.insets.left = leftinset; - if (topinset >= 0) gc.insets.top = topinset; - if (rightinset >= 0) gc.insets.right = rightinset; - if (bottominset >= 0) gc.insets.bottom = bottominset; - - return gc; + @Override + protected void processOK (ActionEvent actionEvent) { + for (int i = 0; i < numOptions; i++) { + selectedOptions[i] = checkBoxes[i].isSelected(); + } } - public void actionPerformed(ActionEvent arg0) { - if (arg0.getSource().equals(okButton)) { - for (int i = 0; i < numOptions; i++) { - selectedOptions[i] = checkBoxes[i].isSelected(); - } - } else if (arg0.getSource().equals(cancelButton)) { - // return; - } - setVisible(false); - dispose(); - owner.dialogActionPerformed (); + @Override + protected void processCancel (ActionEvent actionEvent) { + } public String[] getOptions () { diff --git a/rails/ui/swing/elements/NonModalDialog.java b/rails/ui/swing/elements/NonModalDialog.java new file mode 100644 index 0000000..fff6538 --- /dev/null +++ b/rails/ui/swing/elements/NonModalDialog.java @@ -0,0 +1,135 @@ +package rails.ui.swing.elements; + +import java.awt.*; +import java.awt.event.*; + +import javax.swing.*; + +import org.apache.log4j.Logger; + +import rails.common.LocalText; + +public abstract class NonModalDialog extends JDialog implements ActionListener { + + private static final long serialVersionUID = 1L; + + protected Type type; + protected Usage usage; + protected DialogOwner owner = null; + protected JFrame window = null; + protected String message; + protected boolean hasCancelButton = false; + + GridBagConstraints gc; + JPanel optionsPane, buttonPane; + JButton okButton, cancelButton; + + public static enum Usage { + REPAY_LOANS, + DESTINATION_REACHED, + BUY_WHICH_TRAIN, + COMPANY_START_PRICE, + EXCHANGE_TOKENS, + SELECT_FOLDING_COMPANIES, + SELECT_DESTINATION_COMPANIES, + SELECT_COMPANY, + SELECT_HOME_STATION + } + + public static enum Type { + CHECKBOX, + RADIO, + MESSAGE + } + + protected static Logger log = + Logger.getLogger(NonModalDialog.class.getPackage().getName()); + + public NonModalDialog(Type type, Usage usage, + DialogOwner owner, JFrame window, String title, String message, + boolean addCancelButton) { + + super((Frame) null, title, false); // Non-modal + this.type = type; + this.usage = usage; + this.owner = owner; + this.window = window; + this.message = message; + hasCancelButton = addCancelButton; + } + + protected final void initialize() { + + gc = new GridBagConstraints(); + + optionsPane = new JPanel(); + buttonPane = new JPanel(); + + okButton = new JButton(LocalText.getText("OK")); + okButton.setMnemonic(KeyEvent.VK_O); + okButton.addActionListener(this); + buttonPane.add(okButton); + + if (hasCancelButton) { + cancelButton = new JButton(LocalText.getText("Cancel")); + cancelButton.setMnemonic(KeyEvent.VK_C); + cancelButton.addActionListener(this); + buttonPane.add(cancelButton); + } + + getContentPane().setLayout(new GridBagLayout()); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + optionsPane.setLayout(new GridBagLayout()); + optionsPane.add(new JLabel(message), constraints(0, 0, 10, 10, 10, 10)); + + initializeContent(); + + getContentPane().add(optionsPane, constraints(0, 0, 0, 0, 0, 0)); + getContentPane().add(buttonPane, constraints(0, 1, 0, 0, 0, 0)); + + pack(); + + // Center on owner + int x = (int) window.getLocationOnScreen().getX() + + (window.getWidth() - getWidth()) / 2; + int y = (int) window.getLocationOnScreen().getY() + + (window.getHeight() - getHeight()) / 2; + setLocation(x, y); + + setVisible(true); + setAlwaysOnTop(true); + } + + protected abstract void initializeContent(); + + protected GridBagConstraints constraints(int gridx, int gridy, int leftinset, + int topinset, int rightinset, int bottominset) { + if (gridx >= 0) gc.gridx = gridx; + if (gridy >= 0) gc.gridy = gridy; + gc.fill = GridBagConstraints.BOTH; + gc.weightx = 0.5; + gc.weighty = 0.5; + if (leftinset >= 0) gc.insets.left = leftinset; + if (topinset >= 0) gc.insets.top = topinset; + if (rightinset >= 0) gc.insets.right = rightinset; + if (bottominset >= 0) gc.insets.bottom = bottominset; + + return gc; + } + + public void actionPerformed(ActionEvent actionEvent) { + if (actionEvent.getSource().equals(okButton)) { + processOK(actionEvent); + } else if (actionEvent.getSource().equals(cancelButton)) { + processCancel (actionEvent); + } + setVisible(false); + dispose(); + owner.dialogActionPerformed (); + } + + protected abstract void processOK (ActionEvent actionEvent); + + protected abstract void processCancel (ActionEvent actionEvent); +} diff --git a/rails/ui/swing/elements/RadioButtonDialog.java b/rails/ui/swing/elements/RadioButtonDialog.java index 5041ed5..a40b1a7 100644 --- a/rails/ui/swing/elements/RadioButtonDialog.java +++ b/rails/ui/swing/elements/RadioButtonDialog.java @@ -1,133 +1,67 @@ /* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/ui/swing/elements/RadioButtonDialog.java,v 1.8 2010/01/31 22:22:34 macfreek Exp $*/ package rails.ui.swing.elements; -import java.awt.*; -import java.awt.event.*; +import java.awt.Dimension; +import java.awt.event.ActionEvent; import javax.swing.*; -import org.apache.log4j.Logger; - -import rails.common.LocalText; - /** * A generic dialog for presenting choices by radio buttons. */ -public class RadioButtonDialog extends JDialog implements ActionListener { +public class RadioButtonDialog extends NonModalDialog { private static final long serialVersionUID = 1L; - GridBagConstraints gc; - JPanel optionsPane, buttonPane; - JButton okButton, cancelButton; + JRadioButton[] choiceButtons; Dimension size, optSize; ButtonGroup group; - DialogOwner owner; - String message; int numOptions; String[] options; int selectedOption; int chosenOption = -1; - protected static Logger log = - Logger.getLogger(RadioButtonDialog.class.getPackage().getName()); - - public RadioButtonDialog(DialogOwner owner, JFrame window, String title, String message, + public RadioButtonDialog(Usage usage, DialogOwner owner, JFrame window, String title, String message, String[] options, int selectedOption) { - super((Frame) null, title, false); // Non-modal - this.owner = owner; - this.message = message; + + super (Type.RADIO, usage, owner, window, title, message, selectedOption < 0); + this.options = options; this.numOptions = options.length; this.selectedOption = selectedOption; initialize(); - pack(); - - // Center on window - int x = (int) window.getLocationOnScreen().getX() - + (window.getWidth() - getWidth()) / 2; - int y = (int) window.getLocationOnScreen().getY() - + (window.getHeight() - getHeight()) / 2; - setLocation(x, y); - - setVisible(true); - setAlwaysOnTop(true); } - private void initialize() { - gc = new GridBagConstraints(); - - optionsPane = new JPanel(); - buttonPane = new JPanel(); - - okButton = new JButton(LocalText.getText("OK")); - okButton.setMnemonic(KeyEvent.VK_O); - okButton.addActionListener(this); - buttonPane.add(okButton); - - if (selectedOption < 0) { - // If an option has been preselected, selection is mandatory. - cancelButton = new JButton(LocalText.getText("Cancel")); - cancelButton.setMnemonic(KeyEvent.VK_C); - cancelButton.addActionListener(this); - buttonPane.add(cancelButton); - } - - choiceButtons = new JRadioButton[numOptions]; - - getContentPane().setLayout(new GridBagLayout()); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - optionsPane.setLayout(new GridBagLayout()); - // optionsPane.setBorder(BorderFactory.createLoweredBevelBorder()); - optionsPane.add(new JLabel(message), constraints(0, 0, 10, 10, 10, 10)); + @Override + protected void initializeContent() { choiceButtons = new JRadioButton[numOptions]; group = new ButtonGroup(); for (int i = 0; i < numOptions; i++) { choiceButtons[i] = - new JRadioButton(options[i], i == selectedOption); + new JRadioButton(options[i], i == selectedOption); optionsPane.add(choiceButtons[i], constraints(0, 1 + i, 0, 0, 0, 0)); choiceButtons[i].setPreferredSize(size); group.add(choiceButtons[i]); } - - getContentPane().add(optionsPane, constraints(0, 0, 0, 0, 0, 0)); - getContentPane().add(buttonPane, constraints(0, 1, 0, 0, 0, 0)); } - private GridBagConstraints constraints(int gridx, int gridy, int leftinset, - int topinset, int rightinset, int bottominset) { - if (gridx >= 0) gc.gridx = gridx; - if (gridy >= 0) gc.gridy = gridy; - gc.fill = GridBagConstraints.BOTH; - gc.weightx = 0.5; - gc.weighty = 0.5; - if (leftinset >= 0) gc.insets.left = leftinset; - if (topinset >= 0) gc.insets.top = topinset; - if (rightinset >= 0) gc.insets.right = rightinset; - if (bottominset >= 0) gc.insets.bottom = bottominset; - - return gc; - } - - public void actionPerformed(ActionEvent arg0) { - if (arg0.getSource().equals(okButton)) { - for (int i = 0; i < numOptions; i++) { - if (choiceButtons[i].isSelected()) { - chosenOption = i; - break; - } + @Override + protected void processOK(ActionEvent arg0) { + for (int i = 0; i < numOptions; i++) { + if (choiceButtons[i].isSelected()) { + chosenOption = i; + break; } - } else if (arg0.getSource().equals(cancelButton)) { - chosenOption = -1; } - this.setVisible(false); - this.dispose(); - owner.dialogActionPerformed(); + } + + @Override + protected void processCancel(ActionEvent arg0) { + chosenOption = -1; } public synchronized int getSelectedOption() { diff --git a/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java b/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java index d1bf925..aed46cc 100644 --- a/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java +++ b/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java @@ -11,8 +11,7 @@ import rails.game.special.ExchangeForShare; import rails.game.specific._1835.*; import rails.ui.swing.GameUIManager; import rails.ui.swing.StatusWindow; -import rails.ui.swing.elements.CheckBoxDialog; -import rails.ui.swing.elements.ConfirmationDialog; +import rails.ui.swing.elements.*; public class StatusWindow_1835 extends StatusWindow { @@ -88,7 +87,8 @@ public class StatusWindow_1835 extends StatusWindow { ((ExchangeForShare)(company.getSpecialProperties().get(0))).getShare() ); } - currentDialog = new CheckBoxDialog (gameUIManager, + currentDialog = new CheckBoxDialog (NonModalDialog.Usage.SELECT_FOLDING_COMPANIES, + gameUIManager, this, LocalText.getText("Select"), LocalText.getText("SelectCompaniesToFold", diff --git a/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java b/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java index 884c516..b48d117 100644 --- a/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java +++ b/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java @@ -9,6 +9,7 @@ import rails.game.RoundI; import rails.game.action.*; import rails.game.specific._1856.CGRFormationRound; import rails.ui.swing.StatusWindow; +import rails.ui.swing.elements.NonModalDialog; import rails.ui.swing.elements.RadioButtonDialog; import rails.util.Util; @@ -99,7 +100,8 @@ public class StatusWindow_1856 extends StatusWindow { + "<br>" + message; } - RadioButtonDialog currentDialog = new RadioButtonDialog (gameUIManager, + RadioButtonDialog currentDialog = new RadioButtonDialog (NonModalDialog.Usage.REPAY_LOANS, + gameUIManager, this, LocalText.getText("1856MergerDialog", action.getCompanyName()), message, diff --git a/rails/ui/swing/gamespecific/_18EU/GameStatus_18EU.java b/rails/ui/swing/gamespecific/_18EU/GameStatus_18EU.java index 70ce9df..81e816d 100644 --- a/rails/ui/swing/gamespecific/_18EU/GameStatus_18EU.java +++ b/rails/ui/swing/gamespecific/_18EU/GameStatus_18EU.java @@ -8,6 +8,7 @@ import rails.game.PublicCompanyI; import rails.game.action.MergeCompanies; import rails.game.action.PossibleAction; import rails.ui.swing.GameStatus; +import rails.ui.swing.elements.NonModalDialog; import rails.ui.swing.elements.RadioButtonDialog; /** @@ -69,7 +70,9 @@ public class GameStatus_18EU extends GameStatus { } } - RadioButtonDialog dialog = new RadioButtonDialog (gameUIManager, + RadioButtonDialog dialog = new RadioButtonDialog ( + NonModalDialog.Usage.SELECT_COMPANY, + gameUIManager, parent, LocalText.getText("PleaseSelect"), LocalText.getText("SelectCompanyToMergeMinorInto", diff --git a/rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java b/rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java index b881a5f..5c17748 100644 --- a/rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java +++ b/rails/ui/swing/gamespecific/_18EU/GameUIManager_18EU.java @@ -10,6 +10,7 @@ import rails.game.Stop; import rails.game.action.MergeCompanies; import rails.game.specific._18EU.StartCompany_18EU; import rails.ui.swing.GameUIManager; +import rails.ui.swing.elements.NonModalDialog; import rails.ui.swing.elements.RadioButtonDialog; public class GameUIManager_18EU extends GameUIManager { @@ -72,7 +73,8 @@ public class GameUIManager_18EU extends GameUIManager { "Minor " + minor.getName() + " " + minor.getLongName(); } - dialog = new RadioButtonDialog (this, + dialog = new RadioButtonDialog (NonModalDialog.Usage.SELECT_FOLDING_COMPANIES, + this, statusWindow, LocalText.getText("PleaseSelect"), LocalText.getText( @@ -91,7 +93,8 @@ public class GameUIManager_18EU extends GameUIManager { for (int i = 0; i < options.length; i++) { options[i] = cities.get(i).toString(); } - dialog = new RadioButtonDialog (this, + dialog = new RadioButtonDialog (NonModalDialog.Usage.SELECT_HOME_STATION, + this, statusWindow, LocalText.getText("PleaseSelect"), LocalText.getText( |