-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeldungen.java
More file actions
356 lines (323 loc) · 12.1 KB
/
Meldungen.java
File metadata and controls
356 lines (323 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.filechooser.FileFilter;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class Meldungen extends JDialog implements ActionListener {
public static JFileChooser fileChooser = new JFileChooser();
private static Frame owner;
public TileSet selectedTS;
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JPanel center;
private JPanel south;
private JLabel abfrage;
private JPanel north;
private JTextArea[] eingabe;
private JButton[] button;
private String[] userInput;
private boolean firstStart = true;
private JCheckBox notificationCheckBox;
public Meldungen(Frame owner, boolean modal, String bestimmteAbfrage) {
super(owner, modal);
Meldungen.owner = owner;
$$$setupUI$$$();
setContentPane(contentPane);
getRootPane().setDefaultButton(buttonOK);
setSize(500, 300);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
setAlwaysOnTop(true);
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
buttonCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
});
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
switch (bestimmteAbfrage) {
case "Map":
mapGroesseAbfrage();
break;
case "null":
setVisible(false);
break;
case "TileSet":
getFilesAt("TileSet");
break;
case "Path":
break;
}
}
public static File getFileAt(String openOrSave) { //Methode des Filechosers; offnet einen Speicher-Dialog
if (openOrSave.equals("Open")) {
fileChooser.setCurrentDirectory(new File("Content/maps"));
String extension = ".txt";
setFileFilter(extension);
if (fileChooser.showOpenDialog(owner) == JFileChooser.APPROVE_OPTION) { //Wenn der Ok-Button gedrueckt wird...
return fileChooser.getSelectedFile();
}
}
if (openOrSave.equals("Save")) {
fileChooser.setCurrentDirectory(new File("Content/maps"));
String extension = ".txt";
setFileFilter(extension);
if (fileChooser.showSaveDialog(owner) == JFileChooser.APPROVE_OPTION) { //Wenn der Ok-Button gedrueckt wird...
File saveFile = fileChooser.getSelectedFile();
if (!saveFile.getName().contains(extension)) {
saveFile = new File(saveFile.getPath() + extension);
}
return saveFile;
}
}
JOptionPane.showMessageDialog(owner, "Keine Datei ausgewählt.", "", JOptionPane.WARNING_MESSAGE);
return null;
}
public static File[] getFilesAt(String openOrSaveOrTileSet) { //Methode des Filechosers; offnet einen Speicher-Dialog
if (openOrSaveOrTileSet.equals("TileSet")) {
fileChooser.setCurrentDirectory(new File("Content/graphics/tileSets"));
String extension = ".png";
fileChooser.setMultiSelectionEnabled(true);
setFileFilter(extension);
if (fileChooser.showOpenDialog(owner) == JFileChooser.APPROVE_OPTION) { //Wenn der Ok-Button gedrueckt wird...
return fileChooser.getSelectedFiles();
}
}
return null;
}
private static void setFileFilter(String extension) {
fileChooser.resetChoosableFileFilters();
fileChooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
return f.getName().endsWith(extension);
}
@Override
public String getDescription() {
return "Text Files" + String.format(" (*%s)", extension);
}
});
}
private void onOK() {
setVisible(false);
}
//Templates von Meldungen!
public void mapGroesseAbfrage() {
createComponents(1, "Geben Sie bitte die Mapgröße an!", false);
//On Release:
Font f = new Font(eingabe[0].getFont().getName(), Font.BOLD, 20);
eingabe[0].setFont(f);
eingabe[0].setText("Map - Groesse");
setVisible(true);
}
// Manuelles TileSet (wird von TileSet beim fehlschlagen aufgerufen):
public void tileSetAbfrage(String pPath) {
// Manuelles laden:
createComponents(3, "Bitte nähere Angaben zu den Tiles (Tiles pro Länge und Breite + Abstand zwischen Tiles)", false);
eingabe[0].setText("Breite");
eingabe[1].setText("Höhe");
eingabe[2].setText("Border");
setVisible(true);
}
public void chapterAbfrage() {
createComponents(2, "Um wie viele Tiles soll die Map verschoben werden ?", false);
eingabe[0].setText("In X - Tiles");
eingabe[1].setText("In Y - Tiles");
button = new JButton[1];
button[0] = new JButton("Standard Groesse (20 nach rechts)");
button[0].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
eingabe[0].setText("20");
eingabe[1].setText("0");
}
});
for (int i = 0; i < button.length; i++) {
center.add(button[i]);
}
setVisible(true);
}
public void unSimilarTS(EditorMap current, TileSet tsSelected) {
createComponents(0, "TileSets sind ungleich. Es kann pro Map nur ein TileSet verwendet werden !", false);
notificationCheckBox = new JCheckBox("Warnung ausblenden", false);
notificationCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
current.setToIgnore(notificationCheckBox.isSelected());
}
});
south.add(notificationCheckBox);
button = new JButton[2];
button[0] = new JButton("Map Tile Set");
button[0].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectedTS = current.tileSet;
onOK();
}
});
button[1] = new JButton("Gewähltes Tile Set");
button[1].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectedTS = tsSelected;
onOK();
}
});
button[0].setIcon(new ImageIcon(current.tileSet.getTileSetImage().getScaledInstance(100, 100, BufferedImage.SCALE_SMOOTH)));
button[0].setBorder(null);
button[1].setIcon(new ImageIcon(tsSelected.getTileSetImage().getScaledInstance(100, 100, BufferedImage.SCALE_SMOOTH)));
button[0].setBorder(null);
buttonOK.setVisible(false);
for (int i = 0; i < button.length; i++) {
button[i].setFocusable(false);
center.add(button[i]);
}
setVisible(true);
}
public void createComponents(int eingabeAnzahl, String abfrageText, boolean visible) {
eingabe = new JTextArea[eingabeAnzahl];
userInput = new String[eingabeAnzahl];
for (int i = 0; i < eingabe.length; i++) {
eingabe[i] = new JTextArea("Test");
Font f = new Font(eingabe[i].getFont().getName(), Font.BOLD, 15);
eingabe[i].setFont(f);
abfrage.setFont(f);
eingabe[i].setVisible(true);
eingabe[i].getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
setUserInput();
}
@Override
public void removeUpdate(DocumentEvent e) {
setUserInput();
}
@Override
public void changedUpdate(DocumentEvent e) {
setUserInput();
}
});
int finalI = i;
eingabe[i].addKeyListener(new KeyAdapter() {
/**
* Invoked when a key has been pressed.
*
* @param e
*/
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_TAB) {
if (e.getModifiers() > 0) {
eingabe[finalI].transferFocus();
} else {
eingabe[finalI].transferFocus();
}
e.consume();
}
}
});
center.add(eingabe[i]);
}
abfrage.setText(abfrageText);
if (visible) {
setVisible(true);
}
}
private void setUserInput() {
for (int i = 0; i < eingabe.length; i++) {
if (firstStart) {
eingabe[i].setText("");
firstStart = false;
}
userInput[i] = eingabe[i].getText();
}
}
public JTextArea[] getEingabe() {
return eingabe;
}
public String getUserInput(int welcheAWBox) {
try {
return userInput[welcheAWBox];
} catch (Exception e) {
e.printStackTrace();
return "Falscher Input";
}
}
private void onCancel() {
dispose();
}
/**
* Invoked when an action occurs.
*
* @param e
*/
@Override
public void actionPerformed(ActionEvent e) {
}
/**
* Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
* DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
private void $$$setupUI$$$() {
contentPane = new JPanel();
contentPane.setLayout(new BorderLayout(0, 0));
contentPane.setPreferredSize(new Dimension(300, 125));
center = new JPanel();
center.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
contentPane.add(center, BorderLayout.CENTER);
north = new JPanel();
north.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
contentPane.add(north, BorderLayout.NORTH);
abfrage = new JLabel();
abfrage.setText("Das ist eine Demoabfrage die modifiziert werden soll !");
north.add(abfrage);
south = new JPanel();
south.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
south.setBackground(new Color(-3486771));
contentPane.add(south, BorderLayout.SOUTH);
south.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(-10790053)), null));
buttonOK = new JButton();
buttonOK.setText("OK");
south.add(buttonOK);
buttonCancel = new JButton();
buttonCancel.setText("Cancel");
south.add(buttonCancel);
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() {
return contentPane;
}
private void createUIComponents() {
}
}