20 package net.sf.gridarta.gui.scripts;
22 import java.awt.Color;
23 import java.awt.Component;
24 import java.awt.Container;
25 import java.awt.FlowLayout;
26 import java.awt.Frame;
27 import java.awt.Insets;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
31 import java.io.IOException;
32 import javax.swing.AbstractButton;
33 import javax.swing.BorderFactory;
34 import javax.swing.Box;
35 import javax.swing.BoxLayout;
36 import javax.swing.JButton;
37 import javax.swing.JComboBox;
38 import javax.swing.JDialog;
39 import javax.swing.JFileChooser;
40 import javax.swing.JLabel;
41 import javax.swing.JOptionPane;
42 import javax.swing.JPanel;
43 import javax.swing.JTextField;
44 import javax.swing.WindowConstants;
45 import javax.swing.filechooser.FileFilter;
46 import javax.swing.text.JTextComponent;
62 import net.
sf.japi.swing.action.ActionBuilder;
63 import net.
sf.japi.swing.action.ActionBuilderFactory;
64 import net.
sf.japi.util.Arrays2;
65 import org.jetbrains.annotations.NotNull;
77 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
148 public ScriptArchEditor(@NotNull
final ScriptedEventFactory<G, A, R> scriptedEventFactory, @NotNull
final String
scriptEnding, @NotNull
final String name, @NotNull
final ScriptArchUtils scriptArchUtils, @NotNull
final FileFilter
scriptFileFilter, @NotNull
final ProjectSettings projectSettings, @NotNull
final MapManager<?, ?, ?> mapManager, @NotNull
final PathManager pathManager, @NotNull
final ScriptEditControl scriptEditControl) {
167 final JComboBox<?> tmpEventTypeBox =
new JComboBox<>(valuesArray);
168 tmpEventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch(
"say", valuesArray));
169 return tmpEventTypeBox;
180 final String archName = gameObject.getBestName();
186 newScriptFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
188 final JPanel mainPanel =
new JPanel();
189 mainPanel.setLayout(
new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
190 mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5));
193 final Container line1 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
195 headingLabel.setForeground(Color.black);
196 line1.add(headingLabel);
197 mainPanel.add(line1);
200 mainPanel.add(Box.createVerticalStrut(10));
201 final Container line2 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
203 line2.add(typeLabel);
206 line2.add(Box.createHorizontalStrut(10));
210 line2.add(pluginLabel);
212 mainPanel.add(line2);
215 mainPanel.add(Box.createVerticalStrut(5));
216 final Container line3 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
218 line3.add(scriptFileLabel);
219 mainPanel.add(line3);
221 final AbstractButton browseButton =
new JButton(
"...");
222 browseButton.setMargin(
new Insets(0, 10, 0, 10));
223 browseButton.addActionListener(
new ActionListener() {
226 public void actionPerformed(@NotNull
final ActionEvent e) {
229 final JFileChooser fileChooser =
new JFileChooser();
231 fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
233 fileChooser.setMultiSelectionEnabled(
false);
236 if (fileChooser.showOpenDialog(newScriptFrame) == JFileChooser.APPROVE_OPTION) {
238 final File f = fileChooser.getSelectedFile();
244 line3.add(browseButton);
245 mainPanel.add(line3);
248 mainPanel.add(Box.createVerticalStrut(5));
249 final Container line4 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
253 mainPanel.add(line4);
256 final Container line5 =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
257 final JPanel textPanel =
new JPanel();
258 textPanel.setLayout(
new BoxLayout(textPanel, BoxLayout.Y_AXIS));
260 textPanel.add(label1);
262 textPanel.add(label2);
263 line5.add(textPanel);
264 mainPanel.add(line5);
267 mainPanel.add(Box.createVerticalStrut(10));
268 final Container line6 =
new JPanel(
new FlowLayout(FlowLayout.RIGHT));
270 nsOkButton.addActionListener(
new ActionListener() {
273 public void actionPerformed(@NotNull
final ActionEvent e) {
278 line6.add(nsOkButton);
281 cancelButton.addActionListener(
new ActionListener() {
284 public void actionPerformed(@NotNull
final ActionEvent e) {
285 newScriptFrame.setVisible(
false);
289 line6.add(cancelButton);
290 mainPanel.add(line6);
292 newScriptFrame.getContentPane().add(mainPanel);
293 newScriptFrame.pack();
294 newScriptFrame.setLocationRelativeTo(parent);
295 newScriptFrame.setVisible(
true);
299 final StringBuilder scriptPath =
new StringBuilder(
inputScriptPath.getText().trim().replace(
'\\',
'/'));
302 final String pluginName = ((String)
pluginNameBox.getSelectedItem()).trim();
307 final GameObject<G, A, R> replaceObject = scriptArchData.getScriptedEvent(eventType, gameObject);
308 if (replaceObject !=
null) {
316 String absScriptPath;
317 if (scriptPath.length() > 0 && scriptPath.charAt(0) ==
'/') {
320 if (!mapDir.exists()) {
322 frame.setVisible(
false);
323 ACTION_BUILDER.showMessageDialog(frame,
"mapDirDoesntExist", mapDir);
327 absScriptPath = mapDir.getAbsolutePath() + scriptPath;
330 absScriptPath = localMapDir.getAbsolutePath() +
"/" + scriptPath;
334 File newScriptFile =
new File(absScriptPath);
335 if (!newScriptFile.exists() && !absScriptPath.endsWith(
scriptEnding)) {
338 newScriptFile =
new File(absScriptPath);
341 if (newScriptFile.exists()) {
342 if (newScriptFile.isFile()) {
351 if (replaceObject !=
null) {
355 frame.setVisible(
false);
364 newScriptFile =
new File(absScriptPath);
372 boolean couldCreateFile =
false;
375 couldCreateFile = newScriptFile.createNewFile();
376 }
catch (
final IOException e) {
380 if (!couldCreateFile) {
393 if (replaceObject !=
null) {
397 frame.setVisible(
false);