View Javadoc
1 package org.argosfields.widget; 2 3 import org.argosfields.image.UnitImageSet; 4 import org.argosfields.model.IAntiAircraft; 5 import org.argosfields.model.IAntiGround; 6 import org.argosfields.model.IAntiSea; 7 import org.argosfields.model.IMobile; 8 import org.argosfields.model.Unit; 9 import org.argosfields.resource.ResourceManager; 10 import org.eclipse.swt.SWT; 11 import org.eclipse.swt.graphics.Point; 12 import org.eclipse.swt.layout.FormAttachment; 13 import org.eclipse.swt.layout.FormData; 14 import org.eclipse.swt.layout.FormLayout; 15 import org.eclipse.swt.layout.GridData; 16 import org.eclipse.swt.layout.GridLayout; 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.swt.widgets.Group; 19 import org.eclipse.swt.widgets.Label; 20 21 /*** 22 * InformationPanel.java 23 * 24 * @author Xavier Cho 25 * @version $Revision: 1.8 $ $Date: 2003/12/01 07:38:04 $ 26 */ 27 public class InformationPanel extends Composite { 28 private UnitImageSet unitSet; 29 private Composite unitPanel; 30 private UnitView unitView; 31 private TerrainSet terrainSet; 32 private Label unitNameLabel; 33 private Label unitMoveLabel; 34 private Label unitDefenseLabel; 35 private Label unitAAirLabel; 36 private Label unitAGroundLabel; 37 private Label unitASeaLabel; 38 39 /*** 40 * @param parent 41 * @param style 42 */ 43 public InformationPanel(final Composite parent, final int style) { 44 super(parent, style); 45 46 createContents(); 47 } 48 49 private void createContents() { 50 ResourceManager resources = ResourceManager.getInstance(); 51 52 this.unitSet = UnitImageSet.getInstance(); 53 54 GridLayout gridLayout = new GridLayout(); 55 gridLayout.numColumns = 1; 56 gridLayout.marginWidth = 5; 57 gridLayout.marginHeight = 5; 58 gridLayout.horizontalSpacing = 2; 59 gridLayout.verticalSpacing = 2; 60 61 setLayout(gridLayout); 62 63 Group group1 = new Group(this, SWT.SHADOW_ETCHED_IN); 64 group1.setText(resources.getString("group.title.players")); 65 66 GridData data1 = new GridData(GridData.FILL_HORIZONTAL); 67 data1.heightHint = 100; 68 69 group1.setLayoutData(data1); 70 71 Group unitGroup = new Group(this, SWT.SHADOW_ETCHED_IN); 72 unitGroup.setText(resources.getString("group.title.unit")); 73 74 createUnitPanel(unitGroup); 75 76 GridData data2 = new GridData(GridData.FILL_BOTH); 77 78 unitGroup.setLayoutData(data2); 79 } 80 81 private void createUnitPanel(final Composite parent) { 82 this.unitPanel = new Composite(parent, SWT.NULL); 83 84 FormLayout formLayout = new FormLayout(); 85 formLayout.marginWidth = 5; 86 formLayout.marginHeight = 5; 87 88 unitPanel.setLayout(formLayout); 89 90 this.unitView = new UnitView(unitPanel, SWT.NONE); 91 92 Point size = unitView.computeSize(0, 0); 93 94 FormData data1 = new FormData(); 95 data1.left = new FormAttachment(0, 0); 96 data1.top = new FormAttachment(0, 0); 97 data1.width = size.x; 98 data1.height = size.y; 99 100 unitView.setLayoutData(data1); 101 102 this.unitNameLabel = new Label(unitPanel, SWT.LEFT); 103 104 FormData data2 = new FormData(); 105 data2.left = new FormAttachment(0, 0); 106 data2.top = new FormAttachment(unitView, 5, SWT.BOTTOM); 107 data2.right = new FormAttachment(100, -5); 108 109 unitNameLabel.setLayoutData(data2); 110 111 ResourceManager resources = ResourceManager.getInstance(); 112 113 Label label1 = new Label(unitPanel, SWT.NONE); 114 label1.setImage(resources.getImage("icon.defense")); 115 116 FormData data3 = new FormData(); 117 data3.left = new FormAttachment(unitView, 10, SWT.RIGHT); 118 data3.bottom = new FormAttachment(unitView, -5, SWT.BOTTOM); 119 120 label1.setLayoutData(data3); 121 122 this.unitDefenseLabel = new Label(unitPanel, SWT.NONE); 123 124 FormData data4 = new FormData(); 125 data4.left = new FormAttachment(label1, 5, SWT.RIGHT); 126 data4.bottom = new FormAttachment(label1, 0, SWT.BOTTOM); 127 128 unitDefenseLabel.setLayoutData(data4); 129 130 Label label2 = new Label(unitPanel, SWT.NONE); 131 label2.setImage(resources.getImage("icon.move")); 132 133 FormData data5 = new FormData(); 134 data5.left = new FormAttachment(unitDefenseLabel, 10, SWT.RIGHT); 135 data5.bottom = new FormAttachment(unitDefenseLabel, 0, SWT.BOTTOM); 136 137 label2.setLayoutData(data5); 138 139 this.unitMoveLabel = new Label(unitPanel, SWT.NONE); 140 141 FormData data6 = new FormData(); 142 data6.left = new FormAttachment(label2, 5, SWT.RIGHT); 143 data6.bottom = new FormAttachment(label2, 0, SWT.BOTTOM); 144 145 unitMoveLabel.setLayoutData(data6); 146 147 Label label3 = new Label(unitPanel, SWT.NONE); 148 label3.setImage(resources.getImage("icon.anti-ground")); 149 150 FormData data7 = new FormData(); 151 data7.left = new FormAttachment(unitNameLabel, 0, SWT.LEFT); 152 data7.top = new FormAttachment(unitNameLabel, 15, SWT.BOTTOM); 153 154 label3.setLayoutData(data7); 155 156 this.unitAGroundLabel = new Label(unitPanel, SWT.NONE); 157 158 FormData data8 = new FormData(); 159 data8.left = new FormAttachment(label3, 5, SWT.RIGHT); 160 data8.bottom = new FormAttachment(label3, 0, SWT.BOTTOM); 161 162 unitAGroundLabel.setLayoutData(data8); 163 164 Label label4 = new Label(unitPanel, SWT.NONE); 165 label4.setImage(resources.getImage("icon.anti-air")); 166 167 FormData data9 = new FormData(); 168 data9.left = new FormAttachment(unitAGroundLabel, 10, SWT.RIGHT); 169 data9.top = new FormAttachment(label3, 0, SWT.TOP); 170 171 label4.setLayoutData(data9); 172 173 this.unitAAirLabel = new Label(unitPanel, SWT.NONE); 174 175 FormData data10 = new FormData(); 176 data10.left = new FormAttachment(label4, 5, SWT.RIGHT); 177 data10.bottom = new FormAttachment(unitAGroundLabel, 0, SWT.BOTTOM); 178 179 unitAAirLabel.setLayoutData(data10); 180 181 Label label5 = new Label(unitPanel, SWT.NONE); 182 label5.setImage(resources.getImage("icon.anti-sea")); 183 184 FormData data11 = new FormData(); 185 data11.left = new FormAttachment(unitAAirLabel, 10, SWT.RIGHT); 186 data11.top = new FormAttachment(label4, 0, SWT.TOP); 187 188 label5.setLayoutData(data11); 189 190 this.unitASeaLabel = new Label(unitPanel, SWT.NONE); 191 192 FormData data12 = new FormData(); 193 data12.left = new FormAttachment(label5, 5, SWT.RIGHT); 194 data12.bottom = new FormAttachment(unitAAirLabel, 0, SWT.BOTTOM); 195 196 unitASeaLabel.setLayoutData(data12); 197 198 this.terrainSet = new TerrainSet(unitPanel, SWT.NONE); 199 200 FormData data13 = new FormData(); 201 data13.left = new FormAttachment(label3, 10, SWT.LEFT); 202 data13.top = new FormAttachment(label3, 15, SWT.BOTTOM); 203 data13.width = terrainSet.getSize().x; 204 data13.height = terrainSet.getSize().y; 205 206 terrainSet.setLayoutData(data13); 207 } 208 209 public void displayUnitInfo(final Unit unit) { 210 if (unit == null) { 211 unitPanel.setVisible(false); 212 } else { 213 unitNameLabel.setText(unit.getName()); 214 unitView.setUnit(unit); 215 216 String value = Integer.toString(unit.getDefensePoint()); 217 unitDefenseLabel.setText(value); 218 219 terrainSet.setUnit(unit); 220 221 if (unit instanceof IMobile) { 222 int moves = ((IMobile) unit).getMovesPerTurn(); 223 value = Integer.toString(moves); 224 } else { 225 value = "-"; 226 } 227 228 unitMoveLabel.setText(value); 229 230 if (unit instanceof IAntiGround) { 231 int power = ((IAntiGround) unit).getAntiGroundPower(); 232 unitAGroundLabel.setText(Integer.toString(power)); 233 } else { 234 unitAGroundLabel.setText("-"); 235 } 236 237 if (unit instanceof IAntiAircraft) { 238 int power = ((IAntiAircraft) unit).getAntiAircraftPower(); 239 unitAAirLabel.setText(Integer.toString(power)); 240 } else { 241 unitAAirLabel.setText("-"); 242 } 243 244 if (unit instanceof IAntiSea) { 245 int power = ((IAntiSea) unit).getAntiSeaPower(); 246 unitASeaLabel.setText(Integer.toString(power)); 247 } else { 248 unitASeaLabel.setText("-"); 249 } 250 251 unitPanel.pack(true); 252 unitPanel.setVisible(true); 253 } 254 } 255 }

This page was automatically generated by Maven