Skip to content

Commit be87ac3

Browse files
committed
Add support for bookmarked locations.
1 parent 64fbad2 commit be87ac3

25 files changed

+948
-8
lines changed

pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@
8181
</plugins>
8282
</build>
8383
<dependencies>
84+
<dependency>
85+
<groupId>com.google.guava</groupId>
86+
<artifactId>guava</artifactId>
87+
<version>27.0.1-jre</version>
88+
</dependency>
89+
<dependency>
90+
<groupId>org.dishevelled</groupId>
91+
<artifactId>dsh-eventlist-view</artifactId>
92+
<version>2.2</version>
93+
</dependency>
8494
<dependency>
8595
<groupId>com.google.code.gson</groupId>
8696
<artifactId>gson</artifactId>
@@ -115,4 +125,4 @@
115125
<type>maven-plugin</type>
116126
</dependency>
117127
</dependencies>
118-
</project>
128+
</project>

src/main/java/amidst/AmidstSettings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class AmidstSettings {
2828
public final Setting<Boolean> showOceanFeatures;
2929
public final Setting<Boolean> showNetherFortresses;
3030
public final Setting<Boolean> showEndCities;
31+
public final Setting<Boolean> showBookmarks;
3132

3233
public final Setting<Boolean> smoothScrolling;
3334
public final Setting<Boolean> fragmentFading;
@@ -65,6 +66,7 @@ public AmidstSettings(Preferences preferences) {
6566
showOceanFeatures = Setting.createBoolean( preferences, "oceanFeaturesIcons", true);
6667
showNetherFortresses = Setting.createBoolean( preferences, "netherFortressIcons", false);
6768
showEndCities = Setting.createBoolean( preferences, "endCityIcons", false);
69+
showBookmarks = Setting.createBoolean( preferences, "bookmarkIcons", true);
6870

6971
smoothScrolling = Setting.createBoolean( preferences, "mapFlicking", true);
7072
fragmentFading = Setting.createBoolean( preferences, "mapFading", true);

src/main/java/amidst/fragment/layer/LayerBuilder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ private List<LayerDeclaration> createDeclarations(AmidstSettings settings, List<
9999
declare(settings, declarations, enabledLayers, LayerIds.OCEAN_FEATURES, Dimension.OVERWORLD, false, settings.showOceanFeatures);
100100
declare(settings, declarations, enabledLayers, LayerIds.NETHER_FORTRESS, Dimension.OVERWORLD, false, settings.showNetherFortresses);
101101
declare(settings, declarations, enabledLayers, LayerIds.END_CITY, Dimension.END, false, settings.showEndCities);
102+
declare(settings, declarations, enabledLayers, LayerIds.BOOKMARKS, Dimension.OVERWORLD, false, settings.showBookmarks);
102103
// @formatter:on
103104
return Collections.unmodifiableList(Arrays.asList(declarations));
104105
}
@@ -144,7 +145,8 @@ private Iterable<FragmentLoader> createLoaders(
144145
new WorldIconLoader<>(declarations.get(LayerIds.WOODLAND_MANSION),world.getWoodlandMansionProducer()),
145146
new WorldIconLoader<>(declarations.get(LayerIds.OCEAN_FEATURES), world.getOceanFeaturesProducer()),
146147
new WorldIconLoader<>(declarations.get(LayerIds.NETHER_FORTRESS), world.getNetherFortressProducer()),
147-
new WorldIconLoader<>(declarations.get(LayerIds.END_CITY), world.getEndCityProducer(), Fragment::getEndIslands)
148+
new WorldIconLoader<>(declarations.get(LayerIds.END_CITY), world.getEndCityProducer(), Fragment::getEndIslands),
149+
new WorldIconLoader<>(declarations.get(LayerIds.BOOKMARKS), world.getBookmarkProducer())
148150
));
149151
// @formatter:on
150152
}
@@ -173,7 +175,8 @@ private Iterable<FragmentDrawer> createDrawers(
173175
new WorldIconDrawer(declarations.get(LayerIds.WOODLAND_MANSION),zoom, worldIconSelection),
174176
new WorldIconDrawer(declarations.get(LayerIds.OCEAN_FEATURES), zoom, worldIconSelection),
175177
new WorldIconDrawer(declarations.get(LayerIds.NETHER_FORTRESS), zoom, worldIconSelection),
176-
new WorldIconDrawer(declarations.get(LayerIds.END_CITY), zoom, worldIconSelection)
178+
new WorldIconDrawer(declarations.get(LayerIds.END_CITY), zoom, worldIconSelection),
179+
new WorldIconDrawer(declarations.get(LayerIds.BOOKMARKS), zoom, worldIconSelection)
177180
));
178181
// @formatter:on
179182
}

src/main/java/amidst/fragment/layer/LayerIds.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class LayerIds {
2626
public static final int OCEAN_FEATURES = 14;
2727
public static final int NETHER_FORTRESS = 15;
2828
public static final int END_CITY = 16;
29-
public static final int NUMBER_OF_LAYERS = 17;
29+
public static final int BOOKMARKS = 17;
30+
public static final int NUMBER_OF_LAYERS = 18;
3031
// @formatter:on
3132
}

src/main/java/amidst/gui/main/Actions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ public void switchProfile() {
121121
application.displayProfileSelectWindow();
122122
}
123123

124+
@CalledOnlyBy(AmidstThread.EDT)
125+
public void displayBookmarks() {
126+
dialogs.displayBookmarks();
127+
}
128+
124129
@CalledOnlyBy(AmidstThread.EDT)
125130
public void exit() {
126131
if (BiomeExporter.isExporterRunning()) {

src/main/java/amidst/gui/main/MainWindowDialogs.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import amidst.documentation.CalledOnlyBy;
1313
import amidst.documentation.NotThreadSafe;
1414
import amidst.logging.AmidstMessageBox;
15+
import amidst.gui.main.bookmarks.BookmarkDialog;
1516
import amidst.mojangapi.RunningLauncherProfile;
1617
import amidst.mojangapi.world.WorldSeed;
1718
import amidst.mojangapi.world.WorldType;
@@ -90,8 +91,13 @@ private Path showSaveDialogAndGetSelectedFileOrNull(JFileChooser fileChooser) {
9091
return null;
9192
}
9293
}
94+
95+
@CalledOnlyBy(AmidstThread.EDT)
96+
public void displayBookmarks() {
97+
new BookmarkDialog(frame).setVisible(true);
98+
}
9399

94-
@CalledOnlyBy(AmidstThread.EDT)
100+
@CalledOnlyBy(AmidstThread.EDT)
95101
public void displayInfo(String title, String message) {
96102
AmidstMessageBox.displayInfo(frame, title, message);
97103
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package amidst.gui.main.bookmarks;
2+
3+
import java.io.Serializable;
4+
5+
import java.util.Objects;
6+
7+
/**
8+
* Bookmark.
9+
*/
10+
public final class Bookmark implements Serializable {
11+
private final long x;
12+
private final long z;
13+
private final String label;
14+
private final int hashCode;
15+
16+
private Bookmark(final long x, final long z, final String label) {
17+
if (label == null) {
18+
throw new NullPointerException("label must not be null");
19+
}
20+
this.x = x;
21+
this.z = z;
22+
this.label = label;
23+
this.hashCode = Objects.hash(this.x, this.z, this.label);
24+
}
25+
26+
public long getX() {
27+
return x;
28+
}
29+
30+
public long getZ() {
31+
return z;
32+
}
33+
34+
public String getLabel() {
35+
return label;
36+
}
37+
38+
@Override
39+
public int hashCode() {
40+
return hashCode;
41+
}
42+
43+
public static Bookmark valueOf(final long x, final long z, final String label) {
44+
return new Bookmark(x, z, label);
45+
}
46+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package amidst.gui.main.bookmarks;
2+
3+
import java.awt.Component;
4+
import java.awt.Dialog;
5+
import java.awt.Frame;
6+
import java.awt.Window;
7+
8+
import javax.swing.JDialog;
9+
import javax.swing.JTextField;
10+
import javax.swing.SwingUtilities;
11+
12+
import javax.swing.border.EmptyBorder;
13+
14+
import org.dishevelled.layout.LabelFieldPanel;
15+
16+
final class BookmarkChooser extends LabelFieldPanel {
17+
private final JTextField x;
18+
private final JTextField z;
19+
private final JTextField label;
20+
21+
BookmarkChooser(final int x, final int z) {
22+
super();
23+
this.x = new JTextField(String.valueOf(x));
24+
this.z = new JTextField(String.valueOf(z));
25+
label = new JTextField();
26+
label.requestFocus();
27+
28+
layoutComponents();
29+
}
30+
31+
private void layoutComponents() {
32+
setBorder(new EmptyBorder(12, 12, 0, 12));
33+
addField("X", x);
34+
addField("Z", z);
35+
addField("Label", label);
36+
addFinalSpacing(12);
37+
}
38+
39+
JTextField x() {
40+
return x;
41+
}
42+
43+
JTextField z() {
44+
return z;
45+
}
46+
47+
JTextField label() {
48+
return label;
49+
}
50+
51+
boolean ready() {
52+
// todo validate
53+
return true;
54+
}
55+
56+
Bookmark getBookmark() {
57+
if (ready()) {
58+
return Bookmark.valueOf(Integer.parseInt(x.getText()), Integer.parseInt(z.getText()), label.getText());
59+
}
60+
return null;
61+
}
62+
63+
public static Bookmark showDialog(final Component component, final String title, final int x, final int z) {
64+
if (component == null) {
65+
throw new IllegalArgumentException("component must not be null");
66+
}
67+
if (title == null) {
68+
throw new IllegalArgumentException("title must not be null");
69+
}
70+
BookmarkChooser chooserPane = new BookmarkChooser(x, z);
71+
BookmarkChooserDialog dialog = createDialog(component, title, true, chooserPane);
72+
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
73+
dialog.setLocationRelativeTo(component);
74+
dialog.show();
75+
return dialog.getBookmark();
76+
}
77+
78+
static BookmarkChooserDialog createDialog(final Component component, final String title, final boolean modal, final BookmarkChooser chooserPane) {
79+
if (component == null) {
80+
throw new IllegalArgumentException("component must not be null");
81+
}
82+
if (title == null) {
83+
throw new IllegalArgumentException("title must not be null");
84+
}
85+
if (chooserPane == null) {
86+
throw new IllegalArgumentException("chooserPane must not be null");
87+
}
88+
Window window = SwingUtilities.windowForComponent(component);
89+
BookmarkChooserDialog dialog;
90+
if (window instanceof Frame) {
91+
dialog = new BookmarkChooserDialog((Frame) window, title, modal, chooserPane);
92+
}
93+
else { //if (window instanceof Dialog)
94+
dialog = new BookmarkChooserDialog((Dialog) window, title, modal, chooserPane);
95+
}
96+
dialog.getAccessibleContext().setAccessibleDescription(title);
97+
return dialog;
98+
}
99+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package amidst.gui.main.bookmarks;
2+
3+
import java.awt.BorderLayout;
4+
import java.awt.Color;
5+
import java.awt.Dialog;
6+
import java.awt.Frame;
7+
8+
import java.awt.event.ActionEvent;
9+
10+
import javax.swing.AbstractAction;
11+
import javax.swing.JButton;
12+
import javax.swing.JDialog;
13+
import javax.swing.JPanel;
14+
15+
import javax.swing.border.EmptyBorder;
16+
17+
import javax.swing.event.DocumentEvent;
18+
import javax.swing.event.DocumentListener;
19+
20+
import org.dishevelled.layout.ButtonPanel;
21+
22+
class BookmarkChooserDialog extends JDialog {
23+
private boolean canceled = true;
24+
25+
private final AbstractAction cancel = new AbstractAction("Cancel") {
26+
@Override
27+
public void actionPerformed(final ActionEvent event)
28+
{
29+
cancel();
30+
}
31+
};
32+
private final AbstractAction ok = new AbstractAction("OK") {
33+
@Override
34+
public void actionPerformed(final ActionEvent event)
35+
{
36+
ok();
37+
}
38+
};
39+
40+
private final JButton okButton;
41+
private final BookmarkChooser chooser;
42+
43+
BookmarkChooserDialog(final Dialog owner, final String title, final boolean modal, final BookmarkChooser chooser)
44+
{
45+
super(owner, title, modal);
46+
47+
ok.setEnabled(false);
48+
okButton = new JButton(ok);
49+
this.chooser = chooser;
50+
51+
initialize();
52+
}
53+
54+
BookmarkChooserDialog(final Frame owner, final String title, final boolean modal, final BookmarkChooser chooser)
55+
{
56+
super(owner, title, modal);
57+
58+
ok.setEnabled(false);
59+
okButton = new JButton(ok);
60+
this.chooser = chooser;
61+
62+
initialize();
63+
}
64+
65+
private void initialize()
66+
{
67+
getRootPane().setDefaultButton(okButton);
68+
createListeners();
69+
layoutComponents();
70+
setSize(320, 200);
71+
}
72+
73+
private void createListeners()
74+
{
75+
DocumentListener l = new DocumentListener() {
76+
@Override
77+
public void changedUpdate(final DocumentEvent e) {
78+
ok.setEnabled(chooser.ready());
79+
}
80+
81+
@Override
82+
public void insertUpdate(final DocumentEvent e) {
83+
ok.setEnabled(chooser.ready());
84+
}
85+
86+
@Override
87+
public void removeUpdate(final DocumentEvent e) {
88+
ok.setEnabled(chooser.ready());
89+
}
90+
};
91+
92+
chooser.x().getDocument().addDocumentListener(l);
93+
chooser.z().getDocument().addDocumentListener(l);
94+
chooser.label().getDocument().addDocumentListener(l);
95+
}
96+
97+
private void layoutComponents()
98+
{
99+
ButtonPanel buttonPanel = new ButtonPanel();
100+
buttonPanel.setBorder(new EmptyBorder(0, 12, 12, 12));
101+
buttonPanel.add(cancel);
102+
buttonPanel.add(okButton);
103+
104+
JPanel mainPanel = new JPanel();
105+
mainPanel.setLayout(new BorderLayout());
106+
mainPanel.add("Center", chooser);
107+
mainPanel.add("South", buttonPanel);
108+
109+
setContentPane(mainPanel);
110+
}
111+
112+
private void cancel()
113+
{
114+
canceled = true;
115+
hide();
116+
}
117+
118+
private void ok()
119+
{
120+
canceled = false;
121+
hide();
122+
}
123+
124+
boolean wasCanceled()
125+
{
126+
return canceled;
127+
}
128+
129+
Bookmark getBookmark()
130+
{
131+
return wasCanceled() ? null : chooser.getBookmark();
132+
}
133+
}

0 commit comments

Comments
 (0)