Gridarta Editor
About.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 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.misc;
21 
22 import java.awt.Component;
23 import java.lang.ref.WeakReference;
24 import javax.swing.Action;
26 import net.sf.japi.swing.about.AboutDialog;
27 import net.sf.japi.swing.action.ActionBuilder;
28 import net.sf.japi.swing.action.ActionBuilderFactory;
29 import net.sf.japi.swing.action.ActionMethod;
30 import org.jetbrains.annotations.NotNull;
31 import org.jetbrains.annotations.Nullable;
32 
37 public class About implements EditorAction {
38 
42  @NotNull
43  private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta");
44 
48  @Nullable
49  private WeakReference<AboutDialog> aboutDialogRef;
50 
54  @NotNull
55  private final Component parent;
56 
60  @NotNull
61  private final Object sync = new Object();
62 
67  public About(@NotNull final Component parent) {
68  this.parent = parent;
69  }
70 
74  @ActionMethod
75  public void about() {
76  AboutDialog aboutDialog;
77  synchronized (sync) {
78  if (aboutDialogRef == null) {
79  aboutDialog = new AboutDialog(ACTION_BUILDER);
80  aboutDialogRef = new WeakReference<>(aboutDialog);
81  } else {
82  aboutDialog = aboutDialogRef.get();
83  if (aboutDialog == null) {
84  aboutDialog = new AboutDialog(ACTION_BUILDER);
85  aboutDialogRef = new WeakReference<>(aboutDialog);
86  }
87  }
88  }
89  aboutDialog.showAboutDialog(parent);
90  }
91 
92  @Override
93  public void setAction(@NotNull final Action action, @NotNull final String name) {
94  }
95 
96 }
name
name
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:2
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.misc.About.about
void about()
Action method for about.
Definition: About.java:75
net.sf
net
net.sf.gridarta.gui.misc.About
The about dialog.
Definition: About.java:37
net.sf.gridarta.gui.misc.About.setAction
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
Definition: About.java:93
net.sf.gridarta.gui.misc.About.sync
final Object sync
The synchronization object.
Definition: About.java:61
net.sf.gridarta.gui.misc.About.aboutDialogRef
WeakReference< AboutDialog > aboutDialogRef
The AboutDialog.
Definition: About.java:49
net.sf.gridarta.utils.EditorAction
A global editor action.
Definition: EditorAction.java:29
net.sf.gridarta.gui.misc.About.About
About(@NotNull final Component parent)
Creates a new instance.
Definition: About.java:67
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.gui.misc.About.parent
final Component parent
The parent component for the about dialog.
Definition: About.java:55
net.sf.gridarta.gui.misc.About.ACTION_BUILDER
static final ActionBuilder ACTION_BUILDER
Action Builder to create Actions.
Definition: About.java:43