Gridarta Editor
ConfirmErrorsDialog.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.dialog.gameobjectattributes;
21 
22 import java.awt.Component;
23 import java.awt.Container;
24 import java.awt.FlowLayout;
25 import java.awt.Frame;
26 import java.awt.GridLayout;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.awt.event.WindowEvent;
30 import java.awt.event.WindowListener;
31 import javax.swing.AbstractButton;
32 import javax.swing.BorderFactory;
33 import javax.swing.Box;
34 import javax.swing.BoxLayout;
35 import javax.swing.JButton;
36 import javax.swing.JDialog;
37 import javax.swing.JLabel;
38 import javax.swing.JPanel;
39 import javax.swing.JScrollPane;
40 import javax.swing.JTextArea;
41 import javax.swing.JViewport;
42 import javax.swing.WindowConstants;
43 import org.jetbrains.annotations.NotNull;
44 
51 public class ConfirmErrorsDialog {
52 
56  private ConfirmErrorsDialog() {
57  }
58 
72  public static boolean askConfirmErrors(@NotNull final String errors, @NotNull final Component parent) {
73  final JDialog dialog = new JDialog((Frame) null, "Syntax Errors", true);
74  dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
75 
76  final JPanel mainPanel = new JPanel();
77  mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
78  final Container headerPanel = new JPanel(new GridLayout(2, 1));
79  final Container buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
80 
81  // create header labels
82  final Component header1 = new JLabel("The following lines from the archetype text appear to be wrong.");
83  final Component header2 = new JLabel("They do not match the type definitions:");
84  headerPanel.add(header1);
85  headerPanel.add(header2);
86 
87  // create text area for showing errors
88  final JTextArea textArea = new JTextArea(errors, 7, 25);
89  textArea.setBorder(BorderFactory.createEmptyBorder(1, 4, 0, 0));
90  final JScrollPane scrollPane = new JScrollPane(textArea);
91  scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
92 
93  // create buttons
94  final AbstractButton dumpButton = new JButton("Dump All Errors");
95  final AbstractButton keepButton = new JButton("Keep Above Text");
96  buttonPanel.add(dumpButton);
97  buttonPanel.add(keepButton);
98 
99  final boolean[] result = { true };
100 
101  // attach action listener to the buttons (and the dialog)
102  final ActionListener actionListener = new ActionListener() {
103 
104  @Override
105  public void actionPerformed(@NotNull final ActionEvent e) {
106  result[0] = e.getSource() == keepButton;
107  dialog.dispose();
108  }
109 
110  };
111  keepButton.addActionListener(actionListener);
112  dumpButton.addActionListener(actionListener);
113  final WindowListener windowListener = new WindowListener() {
114 
115  @Override
116  public void windowOpened(@NotNull final WindowEvent e) {
117  }
118 
119  @Override
120  public void windowClosing(@NotNull final WindowEvent e) {
121  result[0] = true;
122  dialog.dispose();
123  }
124 
125  @Override
126  public void windowClosed(@NotNull final WindowEvent e) {
127  }
128 
129  @Override
130  public void windowIconified(@NotNull final WindowEvent e) {
131  }
132 
133  @Override
134  public void windowDeiconified(@NotNull final WindowEvent e) {
135  }
136 
137  @Override
138  public void windowActivated(@NotNull final WindowEvent e) {
139  }
140 
141  @Override
142  public void windowDeactivated(@NotNull final WindowEvent e) {
143  }
144 
145  };
146  dialog.addWindowListener(windowListener);
147 
148  // stick panels together
149  mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
150  mainPanel.add(headerPanel);
151  mainPanel.add(Box.createVerticalStrut(10));
152  mainPanel.add(scrollPane);
153  mainPanel.add(Box.createVerticalStrut(10));
154  mainPanel.add(buttonPanel);
155 
156  dialog.getContentPane().add(mainPanel);
157 
158  // pack, position and show the popup
159  dialog.pack();
160  dialog.setLocationRelativeTo(parent);
161  dialog.setVisible(true);
162  return result[0];
163  }
164 
165 }
net.sf.gridarta.gui.dialog.gameobjectattributes.ConfirmErrorsDialog.askConfirmErrors
static boolean askConfirmErrors(@NotNull final String errors, @NotNull final Component parent)
Definition: ConfirmErrorsDialog.java:72
net.sf.gridarta.gui.dialog.gameobjectattributes.ConfirmErrorsDialog
Definition: ConfirmErrorsDialog.java:51
net.sf.gridarta.gui.dialog.gameobjectattributes.ConfirmErrorsDialog.ConfirmErrorsDialog
ConfirmErrorsDialog()
Definition: ConfirmErrorsDialog.java:56