I focused on the QuickActionMenu class to add the terrain information
to some popup menus.
Now it is possible to have information about the terrain types for all
tiles in the colony.
I modified the popup menu of units and added a popup for other tiles,
including the tile of
the colony itself.
I hope I did it in the right way, especially concerning the listeners.
Feel free to make some criticism if I've done something wrong, I'm a
newcomer ;-)

---

Index: src/net/sf/freecol/client/gui/panel/DragListener.java
===================================================================
--- src/net/sf/freecol/client/gui/panel/DragListener.java       (revision 10295)
+++ src/net/sf/freecol/client/gui/panel/DragListener.java       (working copy)
@@ -30,6 +30,7 @@

 import net.sf.freecol.client.FreeColClient;
 import net.sf.freecol.client.gui.GUI;
+import net.sf.freecol.client.gui.panel.ColonyPanel.TilePanel.ASingleTilePanel;
 import net.sf.freecol.common.model.GoodsType;
 import net.sf.freecol.common.model.Unit;

@@ -90,6 +91,11 @@
                         ((EuropePanel) parentPanel).revalidate();
                         ((EuropePanel) parentPanel).refresh();
                     }
+                } else if (comp instanceof ASingleTilePanel
+                        || (comp.getParent() != null &&
comp.getParent() instanceof ASingleTilePanel)) {
+                    menu = new QuickActionMenu(freeColClient, gui,
parentPanel);
+                    // Also check the parent to show the popup in the
center of the colony panel tile
+                    menu.createTileMenu((ASingleTilePanel)(comp
instanceof ASingleTilePanel ? comp : comp.getParent()));
                 }
                 if (menu != null) {
                     int elements = menu.getSubElements().length;
Index: src/net/sf/freecol/client/gui/panel/QuickActionMenu.java
===================================================================
--- src/net/sf/freecol/client/gui/panel/QuickActionMenu.java    (revision 10295)
+++ src/net/sf/freecol/client/gui/panel/QuickActionMenu.java    (working copy)
@@ -39,6 +39,7 @@
 import net.sf.freecol.client.gui.GUI;
 import net.sf.freecol.client.gui.ImageLibrary;
 import net.sf.freecol.client.gui.i18n.Messages;
+import net.sf.freecol.client.gui.panel.ColonyPanel.TilePanel.ASingleTilePanel;
 import net.sf.freecol.client.gui.panel.UnitLabel.UnitAction;
 import net.sf.freecol.common.model.Ability;
 import net.sf.freecol.common.model.AbstractGoods;
@@ -51,6 +52,7 @@
 import net.sf.freecol.common.model.GoodsType;
 import net.sf.freecol.common.model.Specification;
 import net.sf.freecol.common.model.StringTemplate;
+import net.sf.freecol.common.model.Tile;
 import net.sf.freecol.common.model.Unit;
 import net.sf.freecol.common.model.Unit.Role;
 import net.sf.freecol.common.model.Unit.UnitState;
@@ -110,6 +112,9 @@

         if (tempUnit.getLocation().getTile() != null &&
             tempUnit.getLocation().getTile().getColony() != null) {
+            if (addTileItem(unitLabel)) {
+                this.addSeparator();
+            }
             if (addWorkItems(unitLabel)) {
                 this.addSeparator();
             }
@@ -590,6 +595,38 @@
         }
         return separatorNeeded;
     }
+
+    /**
+     * Creates a menu for a tile.
+     */
+    public void createTileMenu(final ASingleTilePanel singleTilePanel) {
+        if (singleTilePanel.getColonyTile() != null &&
singleTilePanel.getColonyTile().getColony() != null) {
+            addTileItem(singleTilePanel.getColonyTile().getWorkTile());
+        }
+    }
+
+    private boolean addTileItem(final UnitLabel unitLabel) {
+        final Unit unit = unitLabel.getUnit();
+        if (unit.getWorkTile() != null) {
+            final Tile tile = unit.getWorkTile().getWorkTile();
+            addTileItem(tile);
+           return true;
+        }
+        return false;
+    }
+
+    private void addTileItem(final Tile tile) {
+        if (tile != null) {
+            JMenuItem menuItem = new
JMenuItem(Messages.message(tile.getNameKey()));
+            menuItem.addActionListener(new ActionListener() {
+                public void actionPerformed(ActionEvent event) {
+                    gui.showTilePanel(tile);
+                }
+            });
+            add(menuItem);
+        }
+    }
+
     /**
      * Creates a menu for a good.
      */
Index: src/net/sf/freecol/client/gui/panel/ColonyPanel.java
===================================================================
--- src/net/sf/freecol/client/gui/panel/ColonyPanel.java        (revision 10296)
+++ src/net/sf/freecol/client/gui/panel/ColonyPanel.java        (working copy)
@@ -38,7 +38,6 @@
 import java.awt.event.MouseListener;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
@@ -1475,6 +1474,7 @@
                 this.colonyTile = colonyTile;

                 addPropertyChangeListeners();
+                addMouseListener(pressListener);

                 setOpaque(false);
                 TileType tileType = colonyTile.getTile().getType();
@@ -1496,7 +1496,9 @@
                 ProductionInfo info = colony.getProductionInfo(colonyTile);
                 if (info == null) return;
                 for (AbstractGoods goods : info.getProduction()) {
-                    add(new ProductionLabel(getFreeColClient(),
getGUI(), goods));
+                    ProductionLabel productionLabel = new
ProductionLabel(getFreeColClient(), getGUI(), goods);
+                    productionLabel.addMouseListener(pressListener);
+                    add(productionLabel);
                 }
             }

@@ -1717,7 +1719,11 @@
             public boolean accepts(Goods goods) {
                 return false;
             }
-
+
+            public ColonyTile getColonyTile() {
+                return colonyTile;
+            }
+
         }
     }
 }

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Freecol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freecol-developers

Reply via email to