View Javadoc

1   // %1980238621:hoplugins.teamAnalyzer.ui%
2   /*
3    * Created on 23.10.2005
4    */
5   package hoplugins.teamAnalyzer.ui;
6   
7   import hoplugins.Commons;
8   
9   import hoplugins.commons.utils.PluginProperty;
10  
11  import hoplugins.teamAnalyzer.manager.PlayerDataManager;
12  import hoplugins.teamAnalyzer.vo.PlayerInfo;
13  
14  import java.awt.BorderLayout;
15  import java.awt.GridBagConstraints;
16  import java.awt.GridBagLayout;
17  import java.awt.Insets;
18  
19  import javax.swing.JLabel;
20  import javax.swing.JPanel;
21  import javax.swing.border.EtchedBorder;
22  
23  
24  /***
25   * DOCUMENT ME!
26   *
27   * @author <a href="mailto:kenmooda@users.sourceforge.net">Tommi Rautava </a>
28   */
29  public class PlayerInfoPanel extends JPanel {
30      //~ Instance fields ----------------------------------------------------------------------------
31  
32      /*** TODO Missing Parameter Documentation */
33      protected JLabel ageLabel = new JLabel("");
34  
35      /*** TODO Missing Parameter Documentation */
36      protected JLabel expLabel = new JLabel("");
37  
38      /*** TODO Missing Parameter Documentation */
39      protected JLabel formLabel = new JLabel("");
40  
41      /*** TODO Missing Parameter Documentation */
42      protected JLabel tsiLabel = new JLabel("");
43  
44      //~ Constructors -------------------------------------------------------------------------------
45  
46      /***
47       *
48       */
49      public PlayerInfoPanel() {
50          super();
51  
52          //this.setOpaque(false);
53          this.setLayout(new GridBagLayout());
54  
55          //this.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
56          addInfo(Commons.getModel().getResource().getProperty("Alter"), ageLabel, 0, 0);
57          addInfo(PluginProperty.getString("TSI"), tsiLabel, 0, 1);
58          addInfo(Commons.getModel().getResource().getProperty("Form"), formLabel, 1, 0);
59          addInfo(PluginProperty.getString("EXPCode"), expLabel, 1, 1);
60      }
61  
62      //~ Methods ------------------------------------------------------------------------------------
63  
64      /***
65       * TODO Missing Method Documentation
66       *
67       * @param oldPlayer TODO Missing Method Parameter Documentation
68       */
69      public void setValue(PlayerInfo oldPlayer) {
70          clearData();
71          expLabel.setText(Commons.getModel().getHelper().getNameForSkill(oldPlayer.getExperience(),
72                                                                          false));
73          tsiLabel.setText("" + oldPlayer.getTSI());
74          ageLabel.setText("" + oldPlayer.getAge());
75          formLabel.setText(Commons.getModel().getHelper().getNameForSkill(oldPlayer.getForm(), false));
76  
77          PlayerInfo actual = PlayerDataManager.getPlayerInfo(oldPlayer.getPlayerId());
78  
79          if (actual.getForm() == 0) {
80              return;
81          }
82  
83          if (Commons.getModel().getHelper().isDevVersion()) {
84              expLabel.setIcon(Commons.getModel().getHelper().getImageIcon4Veraenderung(actual
85                                                                                        .getExperience()
86                                                                                        - oldPlayer
87                                                                                          .getExperience()));
88              formLabel.setIcon(Commons.getModel().getHelper().getImageIcon4Veraenderung(actual
89                                                                                         .getForm()
90                                                                                         - oldPlayer
91                                                                                           .getForm()));
92  
93              int diff = actual.getTSI() - oldPlayer.getTSI();
94              String desc = "";
95  
96              if (diff > 0) {
97                  desc = "+";
98              }
99  
100             desc = desc + diff;
101             tsiLabel.setToolTipText(desc);
102         }
103     }
104 
105     /***
106      *
107      */
108     public void clearData() {
109         ageLabel.setText("");
110         formLabel.setText("");
111         expLabel.setText("");
112         tsiLabel.setText("");
113         expLabel.setIcon(null);
114         formLabel.setIcon(null);
115         tsiLabel.setToolTipText("");
116     }
117 
118     /***
119      * DOCUMENT ME!
120      *
121      * @param gridx
122      * @param gridy
123      * @param gridwidth
124      * @param gridheight
125      *
126      * @return constraint
127      */
128     private GridBagConstraints getConstraint(int gridx, int gridy, int gridwidth, int gridheight) {
129         GridBagConstraints c = new GridBagConstraints();
130 
131         c.gridx = gridx;
132         c.gridy = gridy;
133         c.gridwidth = gridwidth;
134         c.gridheight = gridheight;
135         c.weightx = 0.5D;
136         c.weighty = 0.5D;
137         c.anchor = GridBagConstraints.CENTER;
138         c.fill = GridBagConstraints.BOTH;
139         c.insets = new Insets(0, 0, 0, 0);
140         c.ipadx = 0;
141         c.ipady = 0;
142 
143         return c;
144     }
145 
146     /***
147      * DOCUMENT ME!
148      *
149      * @param title
150      * @param label
151      * @param x
152      * @param y
153      */
154     private void addInfo(String title, JLabel label, int x, int y) {
155         GridBagConstraints c = getConstraint(x, y, 1, 1);
156 
157         JLabel titleLabel = new JLabel(title);
158 
159         titleLabel.setOpaque(false);
160         titleLabel.setHorizontalAlignment(JLabel.LEFT);
161         titleLabel.setHorizontalTextPosition(JLabel.LEFT);
162 
163         label.setOpaque(false);
164         label.setHorizontalAlignment(JLabel.RIGHT);
165         label.setHorizontalTextPosition(JLabel.RIGHT);
166 
167         JPanel panel = Commons.getModel().getGUI().createImagePanel();
168 
169         panel.setOpaque(false);
170         panel.setLayout(new BorderLayout());
171         panel.setBorder(javax.swing.BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
172 
173         panel.add(titleLabel, BorderLayout.WEST);
174         panel.add(label, BorderLayout.CENTER);
175 
176         this.add(panel, c);
177     }
178 }