Skip to content

Commit

Permalink
support ancient java
Browse files Browse the repository at this point in the history
  • Loading branch information
jadevogt committed Jul 26, 2022
1 parent 60d998c commit cf8d1c3
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 179 deletions.
17 changes: 10 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/best/tigers/tynk_dialog/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@ public static void main(String... args) throws FileNotFoundException {
Integration.runIntegrations();

try {
var lf = new NimbusLookAndFeel();
NimbusLookAndFeel lf = new NimbusLookAndFeel();
UIManager.setLookAndFeel(lf);
} catch (UnsupportedLookAndFeelException e) {
Log.error("""
Nimbus LAF is not supported in this environment, so application appearance may be\
inconsistent with other platforms.
""");
Log.error("Nimbus LAF is not supported in this environment, so application appearance may be inconsistent with other platforms");
}

EventQueue.invokeLater(
() -> {
var x = new PrimaryListController();
PrimaryListController x = new PrimaryListController();
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/best/tigers/tynk_dialog/game/Dialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void addPage(DialogPage newPage) {
* @return the JSON representation of the Dialog
*/
public JsonObject serialize() {
var pageArray = Json.createArrayBuilder();
javax.json.JsonArrayBuilder pageArray = Json.createArrayBuilder();
for (DialogPage currentPage : contents) {
pageArray.add(currentPage.serialize());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/best/tigers/tynk_dialog/game/DialogPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void setCanSkip(boolean skippable) {
}

public JsonObject serialize() {
var result = Json.createObjectBuilder()
javax.json.JsonObjectBuilder result = Json.createObjectBuilder()
.add("txt", content)
.add("canSkip", canSkip)
.add("speaker", speaker);
Expand Down
64 changes: 1 addition & 63 deletions src/main/java/best/tigers/tynk_dialog/gui/Integration.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
import javax.swing.*;
import javax.swing.text.DefaultEditorKit;
import java.awt.*;
import java.awt.desktop.AboutEvent;
import java.awt.desktop.AboutHandler;
import java.awt.desktop.PreferencesEvent;
import java.awt.desktop.PreferencesHandler;
import java.awt.event.KeyEvent;

public class Integration {
Expand All @@ -26,9 +22,7 @@ private static void addOSXKeyStrokes(InputMap inputMap) {

public static void runIntegrations() {
System.setProperty("apple.awt.application.name", Integration.APPLICATION_NAME);
var desktop = Desktop.getDesktop();
desktop.setAboutHandler(new About());
desktop.setPreferencesHandler(new Preferences());
Desktop desktop = Desktop.getDesktop();
if (System.getProperty("os.name", "").startsWith("Mac OS X")) {
// Ensure OSX key bindings are used for copy, paste etc
// Use the Nimbus keys and ensure this occurs before any component creation
Expand All @@ -44,60 +38,4 @@ public static void runIntegrations() {
}

}
}

class About implements AboutHandler {
@Override
public void handleAbout(AboutEvent e) {
var about = new JDialog();
about.setModal(true);
about.setTitle("About " + Integration.APPLICATION_NAME);
var panel = new JPanel();
var layout = new GroupLayout(panel);
var heading = new JLabel(Integration.APPLICATION_NAME);
heading.setHorizontalAlignment(SwingConstants.CENTER);
var headingFont = heading.getFont();
headingFont = headingFont.deriveFont(headingFont.getStyle() | Font.BOLD, 16);
heading.setFont(headingFont);
var version = new JLabel("version " + Integration.APPLICATION_VERSION);
var versionFont = version.getFont();
versionFont = versionFont.deriveFont(versionFont.getStyle() | Font.ITALIC, 14);
version.setFont(versionFont);
version.setHorizontalAlignment(SwingConstants.CENTER);
panel.setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(heading, 300, 300, 300)
.addComponent(version, 300, 300, 300));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addGroup(layout.createSequentialGroup()
.addComponent(heading)
.addComponent(version)
));
about.add(panel);
panel.setMinimumSize(Integration.INTEGRATION_WINDOW_SIZE);
panel.setMaximumSize(Integration.INTEGRATION_WINDOW_SIZE);
about.setMinimumSize(Integration.INTEGRATION_WINDOW_SIZE);
about.setMaximumSize(Integration.INTEGRATION_WINDOW_SIZE);
about.setPreferredSize(Integration.INTEGRATION_WINDOW_SIZE);
panel.setPreferredSize(Integration.INTEGRATION_WINDOW_SIZE);
about.pack();
about.setLocationRelativeTo(null);
about.setVisible(true);
about.requestFocus();
}
}

class Preferences implements PreferencesHandler {
@Override
public void handlePreferences(PreferencesEvent e) {
var preferences = new JDialog();
preferences.setSize(Integration.INTEGRATION_WINDOW_SIZE);
preferences.setModal(true);
preferences.setTitle("Preferences");
preferences.setLocationRelativeTo(null);
preferences.setVisible(true);
preferences.requestFocus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,37 @@ public DialogModel getModel() {
}

public void swapUp() {
var page = view.getSelectedPage();
var pageIndex = model.getPageIndex(page);
DialogPageModel page = view.getSelectedPage();
int pageIndex = model.getPageIndex(page);
if (pageIndex > 0) {
model.swapListItems(pageIndex, pageIndex - 1);
}
view.selectPage(pageIndex - 1);
}

public void swapDown() {
var page = view.getSelectedPage();
var pageIndex = model.getPageIndex(page);
DialogPageModel page = view.getSelectedPage();
int pageIndex = model.getPageIndex(page);
if (pageIndex < (model.getPageCount() - 1)) {
model.swapListItems(pageIndex, pageIndex + 1);
}
view.selectPage(pageIndex + 1);
}

public void saveTitle() {
var newTitle = view.getTitle();
String newTitle = view.getTitle();
model.setTitle(newTitle);
}


public void addPage() {
var newModel = new DialogPageModel();
DialogPageModel newModel = new DialogPageModel();
model.addPage(newModel);
new DialogPageController(newModel, true);
}

public void editPage() {
var selectedModel = view.getSelectedModel();
DialogPageModel selectedModel = view.getSelectedModel();
if (selectedModel != null) {
new DialogPageController(view.getSelectedModel());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public DialogPageController(DialogPageModel model) {
view = new DialogPageEditorView(model).init();
view.makeTrans();
view.attachSaveFunction(e -> {
var newSpeaker = view.getSpeaker();
var newContent = view.getContent();
var newBlip = view.getBlip();
var newStyle = view.getStyle();
var blipEnabled = view.getBlipEnabled();
var styleEnabled = view.getStyleEnabled();
String newSpeaker = view.getSpeaker();
String newContent = view.getContent();
String newBlip = view.getBlip();
String newStyle = view.getStyle();
boolean blipEnabled = view.getBlipEnabled();
boolean styleEnabled = view.getStyleEnabled();
if (!model.getSpeaker().equals(newSpeaker)) {
model.setSpeaker(newSpeaker);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public enum Decision {
public NotSavedDialog() {
dialog = new JDialog();
dialog.setModal(true);
var message = new JLabel("Your changes have not been saved to disk. What would you like to do?");
var cancelButton = new JButton("Cancel");
var saveButton = new JButton("Save");
var saveAsButton = new JButton("Save As");
var continueButton = new JButton("Continue without saving");
var mainPanel = new JPanel();
JLabel message = new JLabel("Your changes have not been saved to disk. What would you like to do?");
JButton cancelButton = new JButton("Cancel");
JButton saveButton = new JButton("Save");
JButton saveAsButton = new JButton("Save As");
JButton continueButton = new JButton("Continue without saving");
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
var buttonPanel = new JPanel();
JPanel buttonPanel = new JPanel();
buttonPanel.add(cancelButton);
buttonPanel.add(saveButton);
buttonPanel.add(saveAsButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public PrimaryListController() {
}

public void exitOperation() {
var response = view.prompt();
int response = view.prompt();
switch (response) {
case 0:
saveInPlace();
Expand All @@ -78,7 +78,7 @@ public void exitOperation() {
}

public void newFile() {
var response = view.prompt();
int response = view.prompt();
switch (response) {
case 0:
saveInPlace();
Expand All @@ -94,23 +94,23 @@ public void newFile() {
}

public String selectFile() {
var chooser = new JFileChooser();
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
var jFilter = new JSONFilter();
var tFilter = new TextFilter();
JSONFilter jFilter = new JSONFilter();
TextFilter tFilter = new TextFilter();
chooser.addChoosableFileFilter(jFilter);
chooser.addChoosableFileFilter(tFilter);
chooser.showDialog(null, "Select or Create");
var newPath = chooser.getSelectedFile().getAbsolutePath();
String newPath = chooser.getSelectedFile().getAbsolutePath();
model.setPath(newPath);
return newPath;
}

public void openFile() {
// fileHandle = new DialogFile(path);
var path = selectFile();
String path = selectFile();
fileHandle.setPath(path);
var theDialogs = new ArrayList<Dialog>();
ArrayList<Dialog> theDialogs = new ArrayList<Dialog>();
try {
theDialogs = fileHandle.readFile();
} catch (Exception e) {
Expand All @@ -127,20 +127,20 @@ public void addMenuItem(ActionListener action, String shortText, String longText
}

public void addDialog() {
var newDialog = new DialogModel();
var newPanel = new DialogController(newDialog);
DialogModel newDialog = new DialogModel();
DialogController newPanel = new DialogController(newDialog);
model.addDialog(newPanel);
}

public void removeCurrentDialog() {
var selected = view.currentSelection();
DialogController selected = view.currentSelection();
if (selected != null) {
model.deleteDialog(selected);
}
}

public void duplicateCurrentDialog() {
var selected = view.currentSelection();
DialogController selected = view.currentSelection();
if (selected != null) {
// This isn't going to work until I implement deep copies
model.addDialog(selected);
Expand All @@ -163,7 +163,7 @@ public void saveInPlace() {
}

public void saveAs() {
var newPath = selectFile();
String newPath = selectFile();
Log.info("Setting path to " + newPath + "...");
fileHandle.setPath(newPath);
saveInPlace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void detachSubscriber(Observer observer) {
}

public void notifySubscribers() {
for (var observer : observers) {
for (Observer observer : observers) {
observer.update();
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/best/tigers/tynk_dialog/gui/model/DialogModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public DialogModel(Dialog dialog) {
pages = new ArrayList<>();
listDataListeners = new ArrayList<>();
setTitle(dialog.getTitle());
for (var page : dialog.getPages()) {
for (DialogPage page : dialog.getPages()) {
addPage(new DialogPageModel(page));
}
}
Expand Down Expand Up @@ -56,8 +56,8 @@ public void addListDataListener(ListDataListener l) {
}

public void notifyListeners() {
var event = new ListDataEvent(pages, ListDataEvent.CONTENTS_CHANGED, 0, pages.size() - 1);
for (var listener : listDataListeners) {
ListDataEvent event = new ListDataEvent(pages, ListDataEvent.CONTENTS_CHANGED, 0, pages.size() - 1);
for (ListDataListener listener : listDataListeners) {
listener.contentsChanged(event);
}
notifySubscribers();
Expand Down Expand Up @@ -96,8 +96,8 @@ public int getPageCount() {
}

public Dialog getDialog() {
var contents = new ArrayList<DialogPage>();
for (var page : pages) {
ArrayList<DialogPage> contents = new ArrayList<DialogPage>();
for (DialogPageModel page : pages) {
contents.add(page.getDialogPage());
}
return new Dialog(title, contents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public PrimaryListModel(ArrayList<Dialog> dialogs, String path) {
this.path = path;
dialogFiles = new ArrayList<>();
listDataListeners = new ArrayList<>();
for (var dialog : dialogs) {
var dialogModel = new DialogModel(dialog);
for (Dialog dialog : dialogs) {
DialogModel dialogModel = new DialogModel(dialog);
addDialog(new DialogController(dialogModel));
}
}
Expand Down Expand Up @@ -82,8 +82,8 @@ public void addListDataListener(ListDataListener l) {

public void notifyListeners() {
modified = true;
var event = new ListDataEvent(dialogFiles, ListDataEvent.CONTENTS_CHANGED, 0, dialogFiles.size() - 1);
for (var listener : listDataListeners) {
ListDataEvent event = new ListDataEvent(dialogFiles, ListDataEvent.CONTENTS_CHANGED, 0, dialogFiles.size() - 1);
for (ListDataListener listener : listDataListeners) {
listener.contentsChanged(event);
}
notifySubscribers();
Expand All @@ -106,8 +106,8 @@ public void update() {
}

public ArrayList<Dialog> getContent() {
var contents = new ArrayList<Dialog>();
for (var currentDialog : dialogFiles) {
ArrayList<Dialog> contents = new ArrayList<Dialog>();
for (DialogController currentDialog : dialogFiles) {
contents.add(currentDialog.getModel().getDialog());
}
return contents;
Expand Down
Loading

0 comments on commit cf8d1c3

Please sign in to comment.