From: Erik V. <ev...@us...> - 2010-01-01 14:03:43
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv5469/rails/ui/swing Modified Files: GameStatus.java Log Message: Added facility to hide closed company rows via a nested class RowVisibility Index: GameStatus.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameStatus.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** GameStatus.java 8 Dec 2009 19:31:33 -0000 1.31 --- GameStatus.java 1 Jan 2010 14:03:32 -0000 1.32 *************** *** 14,17 **** --- 14,20 ---- import rails.game.*; import rails.game.action.*; + import rails.game.model.ModelObject; + import rails.game.model.ViewUpdate; + import rails.game.state.BooleanState; import rails.ui.swing.elements.*; import rails.util.LocalText; *************** *** 88,91 **** --- 91,99 ---- protected int futureTrainsXOffset, futureTrainsYOffset, futureTrainsWidth; protected int rightCompCaptionXOffset; + + /** 2D-array of fields to enable show/hide per row or column */ + protected JComponent[][] fields; + /** Array of Observer objects to set row visibility */ + protected RowVisibility[] rowVisibilityObservers; private Caption[] upperPlayerCaption; *************** *** 247,250 **** --- 255,261 ---- futureTrainsWidth = rightCompCaptionXOffset - futureTrainsXOffset; + fields = new JComponent[1+lastX][2+lastY]; + rowVisibilityObservers = new RowVisibility[nc]; + addField(new Caption(LocalText.getText("COMPANY")), 0, 0, 1, 2, WIDE_RIGHT + WIDE_BOTTOM); *************** *** 307,310 **** --- 318,324 ---- c = companies[i]; companyIndex.put(c, new Integer(i)); + rowVisibilityObservers[i] + = new RowVisibility (certPerPlayerYOffset + i, c.getClosedModel()); + f = new Caption(c.getName()); f.setForeground(c.getFgColour()); *************** *** 532,535 **** --- 546,550 ---- add(comp, gbc); + if (fields[x][y] == null) fields[x][y] = comp; } *************** *** 751,755 **** lowerPlayerCaption[j].setHighlight(false); for (i = 0; i < nc; i++) { ! setPlayerCertButton(i, j, false); } } else if (j == -1 && compCanHoldOwnShares) { --- 766,772 ---- lowerPlayerCaption[j].setHighlight(false); for (i = 0; i < nc; i++) { ! if (rowVisibilityObservers[i].lastValue()) { ! setPlayerCertButton(i, j, false); ! } } } else if (j == -1 && compCanHoldOwnShares) { *************** *** 757,764 **** } for (i = 0; i < nc; i++) { ! setIPOCertButton(i, false); ! setPoolCertButton(i, false); ! setPlayerCertButton (i, actorIndex, false); ! if (compCanHoldOwnShares) setTreasuryCertButton(i, false); } --- 774,783 ---- } for (i = 0; i < nc; i++) { ! if (rowVisibilityObservers[i].lastValue) { ! setIPOCertButton(i, false); ! setPoolCertButton(i, false); ! setPlayerCertButton (i, actorIndex, false); ! if (compCanHoldOwnShares) setTreasuryCertButton(i, false); ! } } *************** *** 922,925 **** --- 941,991 ---- certInTreasuryButton[i].setVisible(clickable); } + + protected void setRowVisibility (int rowIndex, boolean value) { + for (int j=0; j < fields.length; j++) { + if (fields[j][rowIndex] != null) { + fields[j][rowIndex].setVisible(value); + } + } + parent.pack(); + } + + class RowVisibility implements ViewObject + { + private ModelObject modelObject; + private int rowIndex; + private boolean lastValue; + + RowVisibility (int rowIndex, ModelObject model) { + this.modelObject = model; + this.rowIndex = rowIndex; + modelObject.addObserver(this); + lastValue = !((BooleanState)modelObject).booleanValue(); + } + + protected boolean lastValue () { + return lastValue; + } + + /** Needed to satisfy the ViewObject interface. */ + public ModelObject getModel() { + return modelObject; + } + + /** Needed to satisfy the Observer interface. + * The closedObject model will send true if the company is closed. */ + public void update(Observable o1, Object o2) { + if (o2 instanceof Boolean) { + lastValue = !(Boolean)o2; + setRowVisibility(rowIndex, lastValue); + } + } + + /** Needed to satisfy the ViewObject interface. Currently not used. */ + public void deRegister() { + if (modelObject != null) + modelObject.deleteObserver(this); + } + } } |