From: Brett L. <wak...@us...> - 2012-01-07 19:05:33
|
LocalisedText.properties | 2 data/Properties.xml | 1 rails/ui/swing/GameStatus.java | 18 rails/ui/swing/MapPanel.java | 4 rails/ui/swing/ORPanel.java | 55 + rails/ui/swing/ORUIManager.java | 19 rails/ui/swing/StartRoundWindow.java | 10 rails/ui/swing/hexmap/GUIHex.java | 201 ++++-- rails/ui/swing/hexmap/HexHighlightMouseListener.java | 214 +++++++ rails/ui/swing/hexmap/HexMap.java | 561 ++++++++++++++----- rails/ui/swing/hexmap/HexMapImage.java | 48 - 11 files changed, 881 insertions(+), 252 deletions(-) New commits: commit a979db3b904deb6cec88268a5debf39674829c96 Author: Frederick Weld <fre...@gm...> Date: Sat Jan 7 19:38:45 2012 +0100 Added handling of concurrent hex map paints The key blocks / methods are now synchronized on the hex map (acting as the monitor). This became necessary after observing very rare paintComponent calls with invalid clip rectangles (out of JComponent bounds), leading to out-of-bounds paints of the background map. After this addition, no further occurrence of this symptom could be observed. diff --git a/rails/ui/swing/MapPanel.java b/rails/ui/swing/MapPanel.java index 1cce585..e1be54b 100644 --- a/rails/ui/swing/MapPanel.java +++ b/rails/ui/swing/MapPanel.java @@ -62,7 +62,7 @@ public class MapPanel extends JPanel { if (mmgr.isMapImageUsed()) { mapImage = new HexMapImage (); - mapImage.init(mmgr); + mapImage.init(mmgr,map); mapImage.setPreferredSize(originalMapSize); mapImage.setBounds(0, 0, originalMapSize.width, originalMapSize.height); layeredPane.add(mapImage, -1); diff --git a/rails/ui/swing/hexmap/HexHighlightMouseListener.java b/rails/ui/swing/hexmap/HexHighlightMouseListener.java index 2627357..7cc2a96 100644 --- a/rails/ui/swing/hexmap/HexHighlightMouseListener.java +++ b/rails/ui/swing/hexmap/HexHighlightMouseListener.java @@ -13,7 +13,6 @@ import rails.game.Portfolio; import rails.game.PrivateCompanyI; import rails.game.PublicCompanyI; import rails.game.StartItem; -import rails.game.TokenI; import rails.game.special.LocatedBonus; import rails.game.special.SellBonusToken; import rails.game.special.SpecialPropertyI; diff --git a/rails/ui/swing/hexmap/HexMap.java b/rails/ui/swing/hexmap/HexMap.java index f5cbdb8..0dc3c1a 100644 --- a/rails/ui/swing/hexmap/HexMap.java +++ b/rails/ui/swing/hexmap/HexMap.java @@ -23,7 +23,10 @@ import rails.util.Util; * Base class that stores common info for HexMap independant of Hex * orientations. * The hex map manages several layers. Content is seperated in layers in order to ensure - * good performance in case of only some aspects of the map need to be redrawn. + * good performance in case of only some aspects of the map need to be redrawn. + * + * In order to avert race conditions during layer drawing, the critical code is + * synchronized on the hex map instance as monitor object. */ public abstract class HexMap implements MouseListener, MouseMotionListener { @@ -44,51 +47,53 @@ public abstract class HexMap implements MouseListener, final public void paintComponent(Graphics g) { super.paintComponents(g); - // Abort if called too early. - Rectangle rectClip = g.getClipBounds(); - if (rectClip == null) { - return; - } - - //ensure that image buffer of this layer is valid - if (bufferedImage == null - || bufferedImage.getWidth() != getWidth() - || bufferedImage.getHeight() != getHeight() ) { - //create new buffer image - bufferedImage = new BufferedImage(getWidth(), getHeight(),BufferedImage.TYPE_INT_ARGB); - isBufferDirty = true; - - //since the buffered image is empty, it has to be completely redrawn - rectClip = new Rectangle (0, 0, getWidth(), getHeight()); - } - - if (isBufferDirty) { - //buffer redraw is necessary - Graphics2D imageGraphics = (Graphics2D)bufferedImage.getGraphics(); - - //apply the clip of the component's repaint to its image buffer - imageGraphics.setClip(rectClip.x, rectClip.y, rectClip.width, rectClip.height); - - //set the background to transparent so that only drawn parts of the - //buffer will be taken over - imageGraphics.setBackground(new Color(0,0,0,0)); - imageGraphics.setColor(Color.BLACK); - - //clear the clip (for a non-virtual graphic, this would have been - //done by super.paintComponent) - imageGraphics.clearRect(rectClip.x, rectClip.y, rectClip.width, rectClip.height); + //avoid that paintComponent is processed concurrently + synchronized (HexLayer.this) { + + // Abort if called too early or if bounds are invalid. + Rectangle rectClip = g.getClipBounds(); + if (rectClip == null) return; - //paint within the buffer - paintImage(imageGraphics); + //ensure that image buffer of this layer is valid + if (bufferedImage == null + || bufferedImage.getWidth() != getWidth() + || bufferedImage.getHeight() != getHeight() ) { + //create new buffer image + bufferedImage = new BufferedImage(getWidth(), getHeight(),BufferedImage.TYPE_INT_ARGB); + isBufferDirty = true; + + //since the buffered image is empty, it has to be completely redrawn + rectClip = new Rectangle (0, 0, getWidth(), getHeight()); + } - imageGraphics.dispose(); - isBufferDirty = false; + if (isBufferDirty) { + //buffer redraw is necessary + Graphics2D imageGraphics = (Graphics2D)bufferedImage.getGraphics(); + + //apply the clip of the component's repaint to its image buffer + imageGraphics.setClip(rectClip.x, rectClip.y, rectClip.width, rectClip.height); + + //set the background to transparent so that only drawn parts of the + //buffer will be taken over + imageGraphics.setBackground(new Color(0,0,0,0)); + imageGraphics.setColor(Color.BLACK); + + //clear the clip (for a non-virtual graphic, this would have been + //done by super.paintComponent) + imageGraphics.clearRect(rectClip.x, rectClip.y, rectClip.width, rectClip.height); + + //paint within the buffer + paintImage(imageGraphics); + + imageGraphics.dispose(); + isBufferDirty = false; + } + + //buffer is valid and can be used + BufferedImage bufferedRect = bufferedImage.getSubimage( + rectClip.x, rectClip.y, rectClip.width, rectClip.height); + g.drawImage(bufferedRect, rectClip.x, rectClip.y, null); } - - //buffer is valid and can be used - BufferedImage bufferedRect = bufferedImage.getSubimage( - rectClip.x, rectClip.y, rectClip.width, rectClip.height); - g.drawImage(bufferedRect, rectClip.x, rectClip.y, null); } } @@ -812,7 +817,7 @@ public abstract class HexMap implements MouseListener, * Mouse Listener methods (hexMap offers listener for all layers) */ - public void mouseClicked(MouseEvent arg0) { + public synchronized void mouseClicked(MouseEvent arg0) { Point point = arg0.getPoint(); GUIHex clickedHex = getHexContainingPoint(point); @@ -821,7 +826,7 @@ public abstract class HexMap implements MouseListener, public void mouseDragged(MouseEvent arg0) {} - public void mouseMoved(MouseEvent arg0) { + public synchronized void mouseMoved(MouseEvent arg0) { Point point = arg0.getPoint(); GUIHex newHex = getHexContainingPoint(point); @@ -840,7 +845,13 @@ public abstract class HexMap implements MouseListener, public void mouseEntered(MouseEvent arg0) {} - public void mouseExited(MouseEvent arg0) {} + public synchronized void mouseExited(MouseEvent arg0) { + //provide for hex highlighting + if (hexAtMousePosition != null) { + hexAtMousePosition.removeHighlightRequest(); + hexAtMousePosition = null; + } + } public void mousePressed(MouseEvent arg0) {} @@ -852,26 +863,26 @@ public abstract class HexMap implements MouseListener, * - only apply for a specified area */ - public void repaintTiles (Rectangle r) { + public synchronized void repaintTiles (Rectangle r) { tilesLayer.repaint(r); } - private void repaintRoutes (Rectangle r) { + private synchronized void repaintRoutes (Rectangle r) { routesLayer.repaint(r); } - public void repaintMarks (Rectangle r) { + public synchronized void repaintMarks (Rectangle r) { marksLayer.repaint(r); } - public void repaintTokens (Rectangle r) { + public synchronized void repaintTokens (Rectangle r) { tokensTextsLayer.repaint(r); } /** * Do only call this method if you are sure that a complete repaint is needed! */ - public void repaintAll (Rectangle r) { + public synchronized void repaintAll (Rectangle r) { for (JComponent l : layers ) { l.repaint(r); } diff --git a/rails/ui/swing/hexmap/HexMapImage.java b/rails/ui/swing/hexmap/HexMapImage.java index 5ad44af..06a7af5 100644 --- a/rails/ui/swing/hexmap/HexMapImage.java +++ b/rails/ui/swing/hexmap/HexMapImage.java @@ -30,14 +30,15 @@ public final class HexMapImage extends JSVGCanvas { Logger.getLogger(HexMapImage.class.getPackage().getName()); private MapManager mapManager; - private AffineTransform initialTransform; + private HexMap hexMap; private double zoomFactor = 1; // defined dynamically if zoomStep changed private int zoomStep = 10; // default value, can be overwritten in config private boolean initialized = false; - public void init(MapManager mapManager) { + public void init(MapManager mapManager,HexMap hexMap) { this.mapManager = mapManager; + this.hexMap = hexMap; this.setRecenterOnResize(false); @@ -127,38 +128,17 @@ public final class HexMapImage extends JSVGCanvas { public int getZoomStep () { return zoomStep; } - - public void mouseClicked(MouseEvent arg0) { - Point point = arg0.getPoint(); - //GUIHex clickedHex = getHexContainingPoint(point); - - //orUIManager.hexClicked(clickedHex, selectedHex); - } - - /* - * (non-Javadoc) - * - * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) - */ - public void mouseDragged(MouseEvent arg0) {} - - /* - * (non-Javadoc) - * - * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent) + + /** + * paint component synchronized with hex map in order to ensure that + * - painting background image is not affected by concurrent changes in the hexmap + * (such glitches were observed in the past) */ - public void mouseMoved(MouseEvent arg0) { - Point point = arg0.getPoint(); - //GUIHex hex = getHexContainingPoint(point); - //setToolTipText(hex != null ? hex.getToolTip() : ""); + @Override + public void paintComponent(Graphics g) { + synchronized (hexMap) { + super.paintComponent(g); + } } - - public void mouseEntered(MouseEvent arg0) {} - - public void mouseExited(MouseEvent arg0) {} - - public void mousePressed(MouseEvent arg0) {} - - public void mouseReleased(MouseEvent arg0) {} - + } commit 8655633be785451a5f2cf5da68fd99fe183c1ce5 Author: Frederick Weld <fre...@gm...> Date: Sat Jan 7 14:40:26 2012 +0100 Added dirty region handling for hexmap's routes layer Changes to the train routes do not lead to a redraw of the complete layered pane any more. This has been achieved by adding logic for determining the region affected by train route changes. Apart from further performance gains, this also fixes prior issue that routes were not correctly refreshed. diff --git a/rails/ui/swing/hexmap/HexMap.java b/rails/ui/swing/hexmap/HexMap.java index 50cb6aa..f5cbdb8 100644 --- a/rails/ui/swing/hexmap/HexMap.java +++ b/rails/ui/swing/hexmap/HexMap.java @@ -33,7 +33,7 @@ public abstract class HexMap implements MouseListener, private BufferedImage bufferedImage; private boolean isBufferDirty = false; protected abstract void paintImage(Graphics g); - public void repaint() { + final public void repaint() { isBufferDirty = true; super.repaint(); } @@ -131,6 +131,35 @@ public abstract class HexMap implements MouseListener, */ private class RoutesLayer extends HexLayer { private static final long serialVersionUID = 1L; + + public Rectangle getRoutesBounds(List<GeneralPath> p1,List<GeneralPath> p2) { + int margin = (int)Math.ceil(strokeWidth * zoomFactor); + + List<Rectangle> pathRects = new ArrayList<Rectangle>(); + if (p1 != null) { + for (GeneralPath p : p1 ) pathRects.add(p.getBounds()); + } + if (p2 != null) { + for (GeneralPath p : p2 ) pathRects.add(p.getBounds()); + } + + Rectangle r = null; + for (Rectangle pathRect : pathRects ) { + //enlarge path rectangle with margin + Rectangle pathMarginRect = new Rectangle( + pathRect.x - margin, + pathRect.y - margin, + pathRect.width + margin * 2, + pathRect.y + margin * 2); + if (r == null) { + r = pathMarginRect; + } else { + r.add(pathMarginRect); + } + } + return r; + }; + @Override public void paintImage(Graphics g) { try { @@ -740,8 +769,11 @@ public abstract class HexMap implements MouseListener, } public void setTrainPaths(List<GeneralPath> trainPaths) { + Rectangle dirtyRect = routesLayer.getRoutesBounds(this.trainPaths, trainPaths); this.trainPaths = trainPaths; - repaintRoutes(); + + //only repaint if routes existed before or exist now + if (dirtyRect != null) repaintRoutes(dirtyRect); } /** @@ -824,8 +856,8 @@ public abstract class HexMap implements MouseListener, tilesLayer.repaint(r); } - public void repaintRoutes () { - routesLayer.repaint(); + private void repaintRoutes (Rectangle r) { + routesLayer.repaint(r); } public void repaintMarks (Rectangle r) { commit 0b92c862c534981fa3b6d31f2b926ab8cd7a9e22 Author: Frederick Weld <fre...@gm...> Date: Sat Jan 7 13:16:53 2012 +0100 Added hex highlighting on mouse position and fixed tooltips Added a new layer on top-most z-order for tool tips. By this means, tool tips are available again (they were not displayed any more after having introduced layered off-screen buffers). Provided for highlighting of the hex under the mouse pointer. diff --git a/rails/ui/swing/GameStatus.java b/rails/ui/swing/GameStatus.java index 3e3e033..bab6fb0 100644 --- a/rails/ui/swing/GameStatus.java +++ b/rails/ui/swing/GameStatus.java @@ -330,8 +330,9 @@ public class GameStatus extends GridPanel implements ActionListener { f.setForeground(c.getFgColour()); f.setBackground(c.getBgColour()); HexHighlightMouseListener.addMouseListener(f, - gameUIManager.getORUIManager(),(PublicCompanyI)c,false); + gameUIManager.getORUIManager(),c,false); f.addMouseListener(companyCaptionMouseClickListener); + f.setToolTipText(LocalText.getText("NetworkInfoDialogTitle",c.getName())); addField(f, 0, certPerPlayerYOffset + i, 1, 1, WIDE_RIGHT, visible); for (int j = 0; j < np; j++) { @@ -454,8 +455,9 @@ public class GameStatus extends GridPanel implements ActionListener { f.setForeground(c.getFgColour()); f.setBackground(c.getBgColour()); HexHighlightMouseListener.addMouseListener(f, - gameUIManager.getORUIManager(),(PublicCompanyI)c,false); + gameUIManager.getORUIManager(),c,false); f.addMouseListener(companyCaptionMouseClickListener); + f.setToolTipText(LocalText.getText("NetworkInfoDialogTitle",c.getName())); addField(f, rightCompCaptionXOffset, certPerPlayerYOffset + i, 1, 1, WIDE_LEFT, visible); } diff --git a/rails/ui/swing/ORPanel.java b/rails/ui/swing/ORPanel.java index ba24299..03bbc19 100644 --- a/rails/ui/swing/ORPanel.java +++ b/rails/ui/swing/ORPanel.java @@ -458,6 +458,7 @@ implements ActionListener, KeyListener, RevenueListener { HexHighlightMouseListener.addMouseListener(f, orUIManager,(PublicCompanyI)c,false); f.addMouseListener(companyCaptionMouseClickListener); + f.setToolTipText(LocalText.getText("NetworkInfoDialogTitle",c.getName())); addField(f, leftCompNameXOffset, leftCompNameYOffset + i, 1, 1, WIDE_RIGHT, visible); @@ -550,6 +551,7 @@ implements ActionListener, KeyListener, RevenueListener { HexHighlightMouseListener.addMouseListener(f, orUIManager,(PublicCompanyI)c,false); f.addMouseListener(companyCaptionMouseClickListener); + f.setToolTipText(LocalText.getText("NetworkInfoDialogTitle",c.getName())); addField(f, rightCompNameXOffset, rightCompNameYOffset + i, 1, 1, 0, visible); } diff --git a/rails/ui/swing/hexmap/HexMap.java b/rails/ui/swing/hexmap/HexMap.java index 6750115..50cb6aa 100644 --- a/rails/ui/swing/hexmap/HexMap.java +++ b/rails/ui/swing/hexmap/HexMap.java @@ -266,11 +266,19 @@ public abstract class HexMap implements MouseListener, } } + /** + * The only "real" (=swing managed) layer that is used for tool tips + */ + private class ToolTipsLayer extends JComponent { + private static final long serialVersionUID = 1L; + } + private TilesLayer tilesLayer; private RoutesLayer routesLayer; private MarksLayer marksLayer; - private TokensTextsLayer tokensTextsLayer; - private List<HexLayer> hexLayers; + private TokensTextsLayer tokensTextsLayer; + private ToolTipsLayer toolTipsLayer; + private List<JComponent> layers; protected static Logger log = Logger.getLogger(HexMap.class.getPackage().getName()); @@ -297,6 +305,11 @@ public abstract class HexMap implements MouseListener, protected int minX, minY, maxX, maxY; protected int minCol, maxCol, minRow, maxRow; + /** + * The hex over which the mouse pointer is currently situated + */ + private GUIHex hexAtMousePosition = null; + /** A list of all allowed tile lays */ /* (may be redundant) */ protected List<LayTile> allowedTileLays = null; @@ -369,15 +382,17 @@ public abstract class HexMap implements MouseListener, //the following order of instantiation and list-adding defines the layering //from the top to the bottom - hexLayers = new ArrayList<HexLayer>(); + layers = new ArrayList<JComponent>(); + toolTipsLayer = new ToolTipsLayer(); + layers.add(toolTipsLayer); tokensTextsLayer = new TokensTextsLayer(); - hexLayers.add(tokensTextsLayer); + layers.add(tokensTextsLayer); marksLayer = new MarksLayer(); - hexLayers.add(marksLayer); + layers.add(marksLayer); routesLayer = new RoutesLayer(); - hexLayers.add(routesLayer); + layers.add(routesLayer); tilesLayer = new TilesLayer(); - hexLayers.add(tilesLayer); + layers.add(tilesLayer); setScale(); setupHexes(); @@ -412,7 +427,7 @@ public abstract class HexMap implements MouseListener, public void addLayers (JLayeredPane p, int startingZOffset) { int z = startingZOffset; - for (HexLayer l : hexLayers ) { + for (JComponent l : layers ) { p.add(l, z++); } } @@ -776,8 +791,19 @@ public abstract class HexMap implements MouseListener, public void mouseMoved(MouseEvent arg0) { Point point = arg0.getPoint(); - GUIHex hex = getHexContainingPoint(point); - setToolTipText(hex != null ? hex.getToolTip() : ""); + GUIHex newHex = getHexContainingPoint(point); + + //ignore if mouse has not entered a new hex + if (hexAtMousePosition == newHex) return; + + //provide for hex highlighting + if (hexAtMousePosition != null) hexAtMousePosition.removeHighlightRequest(); + if (newHex != null) newHex.addHighlightRequest(); + + //display tool tip + setToolTipText(newHex != null ? newHex.getToolTip() : ""); + + hexAtMousePosition = newHex; } public void mouseEntered(MouseEvent arg0) {} @@ -814,7 +840,7 @@ public abstract class HexMap implements MouseListener, * Do only call this method if you are sure that a complete repaint is needed! */ public void repaintAll (Rectangle r) { - for (HexLayer l : hexLayers ) { + for (JComponent l : layers ) { l.repaint(r); } } @@ -824,35 +850,34 @@ public abstract class HexMap implements MouseListener, */ public void setBounds (int x, int y, int width, int height) { - for (HexLayer l : hexLayers) { + for (JComponent l : layers) { l.setBounds(x, y, width, height); } } private void setPreferredSize (Dimension size) { - for (HexLayer l : hexLayers) { + for (JComponent l : layers) { l.setPreferredSize(size); } } private void setToolTipText (String text) { - //set tool tip on top-most layer (so that it is always visible) - hexLayers.get(hexLayers.size()-1).setToolTipText(text); + toolTipsLayer.setToolTipText(text); } public Dimension getSize () { //get size from top-most layer (all layers have the same size anyways) - return hexLayers.get(hexLayers.size()-1).getSize(); + return layers.get(layers.size()-1).getSize(); } private void addMouseListener (MouseListener ml) { - for (HexLayer l : hexLayers) { + for (JComponent l : layers) { l.addMouseListener(ml); } } private void addMouseMotionListener (MouseMotionListener ml) { - for (HexLayer l : hexLayers) { + for (JComponent l : layers) { l.addMouseMotionListener(ml); } } commit 4948533d6fe55dd990e9ee3a6ca940f8cc6940f0 Author: Frederick Weld <fre...@gm...> Date: Sat Jan 7 12:41:32 2012 +0100 Enabled company network info upon click on company captions If the caption of a company (both in ORPanel and StatusWindow) is clicked, its network info is displayed as if the corresponding network info menu item had been clicked. diff --git a/rails/ui/swing/GameStatus.java b/rails/ui/swing/GameStatus.java index e5b7c11..3e3e033 100644 --- a/rails/ui/swing/GameStatus.java +++ b/rails/ui/swing/GameStatus.java @@ -3,6 +3,7 @@ package rails.ui.swing; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseListener; import java.util.*; import java.util.List; @@ -188,6 +189,8 @@ public class GameStatus extends GridPanel implements ActionListener { upperPlayerCaption = new Caption[np]; lowerPlayerCaption = new Caption[np]; + MouseListener companyCaptionMouseClickListener = gameUIManager.getORUIManager().getORPanel().getCompanyCaptionMouseClickListener(); + int lastX = 0; int lastY = 1; certPerPlayerXOffset = ++lastX; @@ -328,6 +331,7 @@ public class GameStatus extends GridPanel implements ActionListener { f.setBackground(c.getBgColour()); HexHighlightMouseListener.addMouseListener(f, gameUIManager.getORUIManager(),(PublicCompanyI)c,false); + f.addMouseListener(companyCaptionMouseClickListener); addField(f, 0, certPerPlayerYOffset + i, 1, 1, WIDE_RIGHT, visible); for (int j = 0; j < np; j++) { @@ -451,6 +455,7 @@ public class GameStatus extends GridPanel implements ActionListener { f.setBackground(c.getBgColour()); HexHighlightMouseListener.addMouseListener(f, gameUIManager.getORUIManager(),(PublicCompanyI)c,false); + f.addMouseListener(companyCaptionMouseClickListener); addField(f, rightCompCaptionXOffset, certPerPlayerYOffset + i, 1, 1, WIDE_LEFT, visible); } diff --git a/rails/ui/swing/ORPanel.java b/rails/ui/swing/ORPanel.java index 4d20a9e..ba24299 100644 --- a/rails/ui/swing/ORPanel.java +++ b/rails/ui/swing/ORPanel.java @@ -61,7 +61,7 @@ implements ActionListener, KeyListener, RevenueListener { private JMenuItem zoomIn, zoomOut, fitToWindow, fitToWidth, fitToHeight, calibrateMap; private ActionMenuItem takeLoans; private ActionMenuItem repayLoans; - + // Grid elements per function private Caption leftCompName[]; private int leftCompNameXOffset, leftCompNameYOffset; @@ -310,6 +310,21 @@ implements ActionListener, KeyListener, RevenueListener { buttonPanel.setOpaque(true); } + public MouseListener getCompanyCaptionMouseClickListener() { + return new MouseListener() { + public void mouseClicked(MouseEvent e) { + if (e.getComponent() instanceof Caption) { + Caption c = (Caption)e.getComponent(); + executeNetworkInfo(c.getText()); + } + } + public void mouseExited(MouseEvent e) {} + public void mouseEntered(MouseEvent e) {} + public void mousePressed(MouseEvent e) {} + public void mouseReleased(MouseEvent e) {} + }; + } + private void initFields() { leftCompName = new Caption[nc]; rightCompName = new Caption[nc]; @@ -336,6 +351,8 @@ implements ActionListener, KeyListener, RevenueListener { leftCompNameYOffset = 2; int currentXOffset = leftCompNameXOffset; int lastXWidth = 0; + + MouseListener companyCaptionMouseClickListener = getCompanyCaptionMouseClickListener(); /* Top titles */ addField(new Caption("Company"), 0, 0, lastXWidth = 1, 2, @@ -440,6 +457,7 @@ implements ActionListener, KeyListener, RevenueListener { f.setForeground(c.getFgColour()); HexHighlightMouseListener.addMouseListener(f, orUIManager,(PublicCompanyI)c,false); + f.addMouseListener(companyCaptionMouseClickListener); addField(f, leftCompNameXOffset, leftCompNameYOffset + i, 1, 1, WIDE_RIGHT, visible); @@ -531,6 +549,7 @@ implements ActionListener, KeyListener, RevenueListener { f.setForeground(companies[i].getFgColour()); HexHighlightMouseListener.addMouseListener(f, orUIManager,(PublicCompanyI)c,false); + f.addMouseListener(companyCaptionMouseClickListener); addField(f, rightCompNameXOffset, rightCompNameYOffset + i, 1, 1, 0, visible); } @@ -683,6 +702,9 @@ implements ActionListener, KeyListener, RevenueListener { } else { CompanyManagerI cm = gm.getCompanyManager(); PublicCompanyI company = cm.getPublicCompany(companyName); + //handle the case of invalid parameters + //could occur if the method is not invoked by the menu (but by the click listener) + if (company == null) return; // // NetworkGraphBuilder nwGraph = NetworkGraphBuilder.create(gm); // NetworkCompanyGraph companyGraph = NetworkCompanyGraph.create(nwGraph, company); diff --git a/rails/ui/swing/ORUIManager.java b/rails/ui/swing/ORUIManager.java index 0ad825f..40da760 100644 --- a/rails/ui/swing/ORUIManager.java +++ b/rails/ui/swing/ORUIManager.java @@ -1950,6 +1950,11 @@ public class ORUIManager implements DialogOwner { return map; } + // TEMPORARY + public ORPanel getORPanel() { + return orPanel; + } + public GameUIManager getGameUIManager () { return gameUIManager; } commit f93b4e135a57554d10cafb17f27db0d0c90e0ea0 Author: Frederick Weld <fre...@gm...> Date: Sat Jan 7 12:11:10 2012 +0100 Added config option for highlighting and public company highlighting Introduced highlighting for public/minor companies, d... [truncated message content] |