20 package net.sf.gridarta.gui.map.maptilepane;
22 import java.awt.Component;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Insets;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
29 import java.io.IOException;
30 import javax.swing.AbstractButton;
31 import javax.swing.Action;
32 import javax.swing.JButton;
33 import javax.swing.JFileChooser;
34 import javax.swing.JPanel;
35 import javax.swing.JTextField;
36 import javax.swing.filechooser.FileFilter;
40 import net.
sf.japi.swing.action.ActionBuilder;
41 import net.
sf.japi.swing.action.ActionBuilderFactory;
42 import net.
sf.japi.swing.action.ActionMethod;
43 import org.jetbrains.annotations.NotNull;
44 import org.jetbrains.annotations.Nullable;
63 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
112 super(
new GridBagLayout());
117 final GridBagConstraints gbc =
new GridBagConstraints();
121 gbc.fill = GridBagConstraints.NONE;
124 gbc.fill = GridBagConstraints.HORIZONTAL;
128 gbc.fill = GridBagConstraints.NONE;
145 return file.getCanonicalFile();
146 }
catch (
final IOException ignored) {
147 return file.getAbsoluteFile();
157 private static Component
iconButton(@NotNull
final Action action) {
158 final AbstractButton button =
new JButton(action);
159 button.setMargin(
new Insets(0, 0, 0, 0));
185 final JFileChooser chooser = tmpRelativeReference ==
null ?
new JFileChooser() :
new JFileChooser(tmpRelativeReference.getParentFile());
186 final String oldFilename =
getText();
187 if (!oldFilename.isEmpty()) {
190 if (tmpRelativeReference ==
null || oldFilename.startsWith(
"/")) {
193 oldFile =
new File(tmpRelativeReference.getParentFile(), oldFilename);
196 chooser.setSelectedFile(oldFile);
198 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
199 chooser.setMultiSelectionEnabled(
false);
202 final int returnVal = chooser.showOpenDialog(
this);
203 if (returnVal == JFileChooser.APPROVE_OPTION) {
205 final File selected = chooser.getSelectedFile();
206 final String relPath = selected.getCanonicalPath().substring(
absoluteReference.getCanonicalPath().length()).replace(
'\\',
'/');
208 }
catch (
final IOException ex) {
219 public void setText(@NotNull
final String text,
final boolean keepRA) {
251 textField.addActionListener(actionListener);
264 private class RASwitch extends JButton implements ActionListener {
280 setMargin(
new Insets(0, 0, 0, 0));
283 addActionListener(
this);
284 setPreferredSize(getMinimumSize());
295 if (path.isEmpty() || tmpRelativeReference ==
null) {
298 if (toggleRelative) {