From: <bur...@us...> - 2009-12-21 15:29:35
|
Revision: 6115 http://freecol.svn.sourceforge.net/freecol/?rev=6115&view=rev Author: burschik Date: 2009-12-21 15:29:25 +0000 (Mon, 21 Dec 2009) Log Message: ----------- Add rebel tooltip. Modified Paths: -------------- freecol/branches/0.9.x/src/net/sf/freecol/client/gui/i18n/FreeColMessages.properties freecol/branches/0.9.x/src/net/sf/freecol/client/gui/panel/ColonyPanel.java Added Paths: ----------- freecol/branches/0.9.x/src/net/sf/freecol/client/gui/panel/RebelToolTip.java Modified: freecol/branches/0.9.x/src/net/sf/freecol/client/gui/i18n/FreeColMessages.properties =================================================================== --- freecol/branches/0.9.x/src/net/sf/freecol/client/gui/i18n/FreeColMessages.properties 2009-12-21 09:41:07 UTC (rev 6114) +++ freecol/branches/0.9.x/src/net/sf/freecol/client/gui/i18n/FreeColMessages.properties 2009-12-21 15:29:25 UTC (rev 6115) @@ -2106,6 +2106,7 @@ report.stance=Stance report.50percent=Turns to reach 50% report.100percent=Turns to reach 100% +report.nextMember=Turns to increase rebels report.requirements.noExpert=%colony% is producing %goods%, but has no %unit%. report.requirements.missingGoods=%colony% is producing %goods%, but requires more %input%. Modified: freecol/branches/0.9.x/src/net/sf/freecol/client/gui/panel/ColonyPanel.java =================================================================== --- freecol/branches/0.9.x/src/net/sf/freecol/client/gui/panel/ColonyPanel.java 2009-12-21 09:41:07 UTC (rev 6114) +++ freecol/branches/0.9.x/src/net/sf/freecol/client/gui/panel/ColonyPanel.java 2009-12-21 15:29:25 UTC (rev 6115) @@ -55,6 +55,7 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JToolTip; import javax.swing.JViewport; import javax.swing.KeyStroke; import javax.swing.ScrollPaneConstants; @@ -116,7 +117,11 @@ private final JLabel royalistMemberLabel = new JLabel(); private final JPanel productionPanel = new JPanel(); - private final JPanel populationPanel = new JPanel(); + private final JPanel populationPanel = new JPanel() { + public JToolTip createToolTip() { + return new RebelToolTip(colony, getCanvas()); + } + }; private final JComboBox nameBox; @@ -182,6 +187,7 @@ productionPanel.setOpaque(false); populationPanel.setOpaque(false); + populationPanel.setToolTipText(" "); populationPanel.setLayout(new MigLayout("wrap 5, fill, insets 0", "[][]:push[center]:push[right][]", "")); populationPanel.add(rebelShield, "bottom"); Copied: freecol/branches/0.9.x/src/net/sf/freecol/client/gui/panel/RebelToolTip.java (from rev 6111, freecol/branches/0.9.x/src/net/sf/freecol/client/gui/panel/BuildingToolTip.java) =================================================================== --- freecol/branches/0.9.x/src/net/sf/freecol/client/gui/panel/RebelToolTip.java (rev 0) +++ freecol/branches/0.9.x/src/net/sf/freecol/client/gui/panel/RebelToolTip.java 2009-12-21 15:29:25 UTC (rev 6115) @@ -0,0 +1,120 @@ +/** + * Copyright (C) 2002-2007 The FreeCol Team + * + * This file is part of FreeCol. + * + * FreeCol is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * FreeCol is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FreeCol. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.freecol.client.gui.panel; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Image; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JToolTip; + +import net.sf.freecol.client.gui.Canvas; +import net.sf.freecol.client.gui.i18n.Messages; +import net.sf.freecol.common.Specification; +import net.sf.freecol.common.model.Building; +import net.sf.freecol.common.model.Colony; +import net.sf.freecol.common.model.GoodsType; +import net.sf.freecol.common.model.Unit; +import net.sf.freecol.common.resources.ResourceManager; + +import net.miginfocom.swing.MigLayout; + +/** + * This panel provides detailed information about rebels in a colony. + */ +public class RebelToolTip extends JToolTip { + + /** + * Creates this RebelToolTip. + * + * @param building The building to display information from. + * @param parent a <code>Canvas</code> value + */ + public RebelToolTip(Colony colony, Canvas parent) { + + setLayout(new MigLayout("fillx, wrap 3", "[][right][right]", "")); + + int members = colony.getMembers(); + int rebels = colony.getSoL(); + + add(new JLabel(Messages.message("colonyPanel.rebelLabel", "%number%", ""))); + add(new JLabel(Integer.toString(members))); + add(new JLabel(Integer.toString(rebels) + "%")); + add(new JLabel(Messages.message("colonyPanel.royalistLabel", "%number%", ""))); + add(new JLabel(Integer.toString(colony.getUnitCount() - members))); + add(new JLabel(Integer.toString(colony.getTory()) + "%")); + + int libertyProduction = 0; + for (GoodsType goodsType : Specification.getSpecification().getLibertyGoodsTypeList()) { + add(new JLabel(goodsType.getName())); + int netProduction = colony.getProductionNetOf(goodsType); + libertyProduction += netProduction; + add(new ProductionLabel(goodsType, netProduction, parent), "span 2"); + } + + float turns100 = 0; + float turns50 = 0; + float turnsNext = 0; + + if (libertyProduction > 0) { + int liberty = colony.getLiberty(); + int requiredLiberty = Colony.LIBERTY_PER_REBEL * colony.getUnitCount(); + + if (liberty < requiredLiberty) { + turns100 = (requiredLiberty - liberty) / libertyProduction; + } + + requiredLiberty = requiredLiberty / 2; + if (liberty < requiredLiberty) { + turns50 = (requiredLiberty - liberty) / libertyProduction; + } + + if (members < colony.getUnitCount()) { + requiredLiberty = Colony.LIBERTY_PER_REBEL * (members + 1); + if (liberty < requiredLiberty) { + turnsNext = (requiredLiberty - liberty) / libertyProduction; + } + } + } + + String na = Messages.message("notApplicable.short"); + add(new JLabel(Messages.message("report.nextMember"))); + add(new JLabel(turnsNext == 0 ? na : Integer.toString((int) Math.ceil(turnsNext))), "skip"); + add(new JLabel(Messages.message("report.50percent"))); + add(new JLabel(turns50 == 0 ? na : Integer.toString((int) Math.ceil(turns50))), "skip"); + add(new JLabel(Messages.message("report.100percent"))); + add(new JLabel(turns100 == 0 ? na : Integer.toString((int) Math.ceil(turns100))), "skip"); + + } + + + public Dimension getPreferredSize() { + return new Dimension(350, 250); + } +} + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |