1
2
3
4
5 package hoplugins.conv;
6
7 import java.awt.BorderLayout;
8 import java.awt.Component;
9 import java.awt.Dimension;
10 import java.awt.FlowLayout;
11 import java.awt.GraphicsEnvironment;
12 import java.awt.GridBagConstraints;
13 import java.awt.GridBagLayout;
14 import java.awt.Insets;
15 import java.awt.ScrollPane;
16 import java.io.File;
17 import java.io.FileWriter;
18 import java.util.Iterator;
19 import java.util.Vector;
20
21 import javax.swing.ImageIcon;
22 import javax.swing.JButton;
23 import javax.swing.JCheckBox;
24 import javax.swing.JComboBox;
25 import javax.swing.JDialog;
26 import javax.swing.JFrame;
27 import javax.swing.JLabel;
28 import javax.swing.JList;
29 import javax.swing.JPanel;
30 import javax.swing.JTextField;
31 import javax.swing.SwingConstants;
32
33 import plugins.ISpieler;
34
35 /***
36 * @author Thorsten Dietz
37 *
38 */
39 public class TxtExpDialog extends JDialog {
40 private int width, height;
41 private JPanel optionPanel;
42 private JPanel southPanel;
43 private JPanel middlePanel;
44 private JCheckBox chk_columnNames;
45 private JList list;
46 private TxtExpListener listener;
47 private JTextField txt_limiter;
48 private JComboBox filterBox;
49
50 protected TxtExpDialog(JFrame frame) {
51 super(frame,RSC.PROP_PLAYERS+" => "+RSC.PROP_FILE);
52 width = (int) GraphicsEnvironment.getLocalGraphicsEnvironment()
53 .getMaximumWindowBounds().getWidth();
54 height = (int) GraphicsEnvironment.getLocalGraphicsEnvironment()
55 .getMaximumWindowBounds().getHeight();
56 setLocation((width - 400) / 2, (height - 320) / 2);
57 setSize(400, 320);
58 listener = new TxtExpListener();
59 initialize();
60 }
61
62 private void initialize() {
63 getContentPane().setLayout(new BorderLayout());
64 getContentPane().add(getMiddlePanel(), BorderLayout.CENTER);
65 getContentPane().add(getSouthPanel(), BorderLayout.SOUTH);
66
67 }
68
69 private JPanel getSouthPanel() {
70 if (southPanel == null) {
71
72 southPanel = RSC.MINIMODEL.getGUI().createImagePanel();
73 ((FlowLayout) southPanel.getLayout())
74 .setAlignment(FlowLayout.RIGHT);
75
76 JButton okButton = new JButton(RSC.PROP_ADD);
77 okButton.setActionCommand(RSC.PROP_ADD);
78 okButton.addActionListener(listener);
79
80 JButton cancelButton = new JButton(RSC.PROP_CANCEL);
81 cancelButton.setActionCommand(RSC.ACT_CANCEL);
82 cancelButton.addActionListener(listener);
83
84 southPanel.add(okButton);
85 southPanel.add(cancelButton);
86
87 }
88 return southPanel;
89 }
90
91 private JPanel getMiddlePanel() {
92 if (middlePanel == null) {
93
94 middlePanel = RSC.MINIMODEL.getGUI().createImagePanel();
95 middlePanel.setLayout(new BorderLayout());
96 ScrollPane scrolli = new ScrollPane();
97 scrolli.add(getList());
98
99 middlePanel.add(scrolli, BorderLayout.CENTER);
100 middlePanel.add(getOptionPanel(), BorderLayout.WEST);
101
102 }
103 return middlePanel;
104 }
105
106 private JPanel getOptionPanel() {
107 if (optionPanel == null) {
108 optionPanel = RSC.MINIMODEL.getGUI().createImagePanel();
109 optionPanel.setPreferredSize(new Dimension(200, 100));
110 optionPanel.setLayout(new GridBagLayout());
111
112 GridBagConstraints c = new GridBagConstraints();
113
114 c.anchor = GridBagConstraints.NORTHWEST;
115 c.insets = new Insets(15, 5, 5, 5);
116 c.fill = GridBagConstraints.NONE;
117
118 add(optionPanel, new JLabel("Separator:"), 0, 0, c);
119 add(optionPanel, getLimiterField(), 1, 0, c);
120
121 add(optionPanel, new JLabel("Columnnames:"), 0, 1, c);
122 add(optionPanel, getColumnNamesCheck(), 1, 1, c);
123 add(optionPanel, new JLabel("Group:"), 0, 2, c);
124 add(optionPanel, getFilterBox(), 1, 2, c);
125
126 }
127 return optionPanel;
128 }
129
130 private JComboBox getFilterBox() {
131 if (filterBox == null) {
132 ImageIcon [] smilies = new ImageIcon[6];
133 for (int i = 0; i < smilies.length; i++) {
134 smilies[i] = new javax.swing.ImageIcon(RSC.MINIMODEL.getHelper().makeColorTransparent(
135 RSC.MINIMODEL.getHelper().loadImage("gui/bilder/smilies/"+RSC.TEAM[i]), 210, 210, 185, 255, 255, 255));
136 }
137 filterBox = new JComboBox(smilies);
138 }
139 return filterBox;
140 }
141
142 private JCheckBox getColumnNamesCheck() {
143 if (chk_columnNames == null) {
144 chk_columnNames = new JCheckBox();
145 }
146 return chk_columnNames;
147 }
148
149 protected JList getList() {
150 if (list == null) {
151 list = new JList(RSC.playerColumns);
152 }
153 return list;
154 }
155
156 public void writeFile(File file) throws Exception {
157 String limiter = getLimiterField().getText();
158 Object[] selected = getList().getSelectedValues();
159 Vector players = RSC.MINIMODEL.getAllSpieler();
160
161
162 FileWriter fileWriter = new FileWriter(file);
163 if (getColumnNamesCheck().isSelected()) {
164 for (int i = 0; i < selected.length; i++) {
165 fileWriter.write(((CColumn) selected[i]).getDisplay());
166 if (i < selected.length - 1)
167 fileWriter.write(limiter);
168 }
169 fileWriter.write("\n");
170 }
171
172 for (Iterator iter = players.iterator(); iter.hasNext();) {
173 ISpieler player = (ISpieler) iter.next();
174 if (getFilterBox().getSelectedIndex() > 0) {
175 String group = RSC.TEAM[getFilterBox().getSelectedIndex()];
176 if (group.equals(player.getTeamInfoSmilie())) {
177 for (int i = 0; i < selected.length; i++) {
178 fileWriter.write(((CColumn) selected[i]).getPlayerValue(player));
179 if (i < selected.length - 1)
180 fileWriter.write(limiter);
181 }
182
183 fileWriter.write("\n");
184
185 }
186 }
187 }
188 fileWriter.flush();
189 fileWriter.close();
190 }
191
192
193
194
195
196 private JTextField getLimiterField() {
197 if (txt_limiter == null) {
198 txt_limiter = new JTextField();
199 txt_limiter.setPreferredSize(new Dimension(100, 23));
200 txt_limiter.setHorizontalAlignment(SwingConstants.CENTER);
201 txt_limiter.setText(";");
202 }
203 return txt_limiter;
204 }
205
206 private void add(JPanel parent, Component comp, int x, int y,
207 GridBagConstraints c) {
208 c.gridx = x;
209 c.gridy = y;
210 parent.add(comp, c);
211 }
212 }