From: Stefan F. <ste...@us...> - 2010-04-04 22:03:01
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv19412/rails/ui/swing Modified Files: StatusWindow.java GameUIManager.java ORPanel.java Log Message: Adding the experimental network code. Example graphs are shown under Info on the Map Panel. Index: StatusWindow.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/StatusWindow.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** StatusWindow.java 28 Mar 2010 20:14:19 -0000 1.41 --- StatusWindow.java 4 Apr 2010 22:02:53 -0000 1.42 *************** *** 35,38 **** --- 35,40 ---- protected static final String SAVE_CMD = "Save"; + protected static final String EXPORT_CMD = "Export"; + protected static final String UNDO_CMD = "Undo"; *************** *** 79,83 **** private JMenuItem menuItem; ! private ActionMenuItem saveItem; private ActionMenuItem undoItem, forcedUndoItem, redoItem, redoItem2; --- 81,85 ---- private JMenuItem menuItem; ! private ActionMenuItem saveItem, exportItem; private ActionMenuItem undoItem, forcedUndoItem, redoItem, redoItem2; *************** *** 110,113 **** --- 112,122 ---- fileMenu.add(saveItem); + exportItem = new ActionMenuItem(LocalText.getText("EXPORT")); + exportItem.setActionCommand(EXPORT_CMD); + exportItem.addActionListener(this); + exportItem.setEnabled(true); + exportItem.setPossibleAction(new GameAction(GameAction.EXPORT)); + fileMenu.add(exportItem); + fileMenu.addSeparator(); *************** *** 575,579 **** gameUIManager.saveGame((GameAction) executedAction); break; ! case GameAction.UNDO: case GameAction.FORCED_UNDO: --- 584,590 ---- gameUIManager.saveGame((GameAction) executedAction); break; ! case GameAction.EXPORT: ! gameUIManager.exportGame((GameAction) executedAction); ! break; case GameAction.UNDO: case GameAction.FORCED_UNDO: Index: GameUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameUIManager.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** GameUIManager.java 14 Mar 2010 13:10:15 -0000 1.44 --- GameUIManager.java 4 Apr 2010 22:02:53 -0000 1.45 *************** *** 603,606 **** --- 603,632 ---- } + public void exportGame(GameAction exportAction) { + JFileChooser jfc = new JFileChooser(); + String filename; + if (providedName != null) + filename = providedName; + else { + filename = saveDirectory + "/" + gameManager.getGameName() + "_" + + saveDateTimeFormat.format(new Date()) + + saveSuffix + ".txt"; + + File proposedFile = new File(filename); + jfc.setSelectedFile(proposedFile); + if (jfc.showSaveDialog(statusWindow) == JFileChooser.APPROVE_OPTION) { + File selectedFile = jfc.getSelectedFile(); + String filepath = selectedFile.getPath(); + saveDirectory = selectedFile.getParent(); + if (!selectedFile.getName().equalsIgnoreCase(proposedFile.getName())) { + providedName = filepath; + } + exportAction.setFilepath(filepath); + processOnServer(exportAction); + } + } + } + + public void saveGame(GameAction saveAction) { Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** ORPanel.java 27 Mar 2010 18:44:24 -0000 1.50 --- ORPanel.java 4 Apr 2010 22:02:53 -0000 1.51 *************** *** 10,13 **** --- 10,16 ---- import org.apache.log4j.Logger; + import org.jgrapht.graph.SimpleGraph; + + import rails.algorithms.*; import rails.common.GuiDef; import rails.game.*; *************** *** 34,37 **** --- 37,41 ---- private static final String REDO_CMD = "Redo"; public static final String REM_TILES_CMD = "RemainingTiles"; + private static final String NETWORK_INFO_CMD = "NetworkInfo"; public static final String TAKE_LOANS_CMD = "TakeLoans"; public static final String REPAY_LOANS_CMD = "RepayLoans"; *************** *** 162,165 **** --- 166,170 ---- addTrainsInfo(); addPhasesInfo(); + addNetworkInfo(); specialMenu = new JMenu(LocalText.getText("SPECIAL")); *************** *** 557,560 **** --- 562,605 ---- } + protected void addNetworkInfo() { + CompanyManagerI cm = orUIManager.getGameUIManager().getGameManager().getCompanyManager(); + + JMenu networkMenu = new JMenu(LocalText.getText("NetworkInfo")); + networkMenu.setEnabled(true); + infoMenu.add(networkMenu); + + JMenuItem item = new JMenuItem("All"); + item.addActionListener(this); + item.setActionCommand(NETWORK_INFO_CMD); + networkMenu.add(item); + + for (PublicCompanyI comp : cm.getAllPublicCompanies()) { + if (!comp.hasFloated() || comp.isClosed()) continue; + item = new JMenuItem(comp.getName()); + item.addActionListener(this); + item.setActionCommand(NETWORK_INFO_CMD); + networkMenu.add(item); + } + } + + protected void executeNetworkInfo(String companyName) { + + MapManager mapManager = orUIManager.getGameUIManager().getGameManager().getMapManager(); + + NetworkGraphBuilder nwGraph = new NetworkGraphBuilder(); + nwGraph.generateGraph(mapManager.getHexesAsList()); + SimpleGraph<NetworkVertex, NetworkEdge> graph; + graph = nwGraph.getMapGraph(); + + if (!companyName.equals("All")) { + CompanyManagerI cm = orUIManager.getGameUIManager().getGameManager().getCompanyManager(); + PublicCompanyI company = cm.getCompanyByName(companyName); + graph = nwGraph.getRailRoadGraph(company); + } + NetworkGraphBuilder.visualize(graph, "Network of " + companyName); + NetworkGraphBuilder.optimizeGraph(graph); + NetworkGraphBuilder.visualize(graph, "Optimized Network of " + companyName); + } + private void appendInfoText (StringBuffer b, String text) { if (text == null || text.length() == 0) return; *************** *** 604,611 **** } else if (source == zoomOut) { orWindow.getMapPanel().zoomOut(); } else { orUIManager.processAction(command, null); } - } --- 649,658 ---- } else if (source == zoomOut) { orWindow.getMapPanel().zoomOut(); + } else if (command == NETWORK_INFO_CMD) { + JMenuItem item = (JMenuItem)actor.getSource(); + executeNetworkInfo(item.getText()); } else { orUIManager.processAction(command, null); } } |