Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI Refactor #1743

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
96d7cf5
Removed dependency on the Action annotation
May 24, 2024
a302311
Removed dependency on @Action annotation
May 30, 2024
f75ddc7
Fixed icons
May 30, 2024
be89639
Fixed issue with icons not being found.
Jun 3, 2024
6bb8241
Removed dependence on Action annotation in all GUI
Jun 3, 2024
32acd69
Fixed typos in .properties files
Jun 3, 2024
952abe2
Removed ResourceMap dependency
Jun 5, 2024
48e5231
Added a skeleton for the new framework
Jun 17, 2024
9150a4f
Replaced BSAF connections with new framework
Jun 17, 2024
9ebf9e5
Started implementing BaseApplication
Jun 18, 2024
31a938e
Further BaseApplication implementation
Mrockwell2 Jun 19, 2024
9f8ee48
Basic SimControlPanel Implementation
Jul 1, 2024
db019d1
Removed extraneous print statements
Mrockwell2 Jul 9, 2024
21d0c50
Fixed issue with Menu Bar names
Mrockwell2 Jul 11, 2024
3a001a1
Merge branch 'master' into GUI_Refactor
Mrockwell2 Jul 14, 2024
2c7c496
Replaced Mnemonic signifiers
Mrockwell2 Jul 16, 2024
be6784d
Fixed mnemonics
Mrockwell2 Jul 16, 2024
c197586
Got MTV to pop up
Mrockwell2 Jul 24, 2024
2662562
Tagged methods for implementation and fixed status messages
Mrockwell2 Jul 24, 2024
52d4cda
Implemented InputBlocker and associated classes
Mrockwell2 Jul 29, 2024
b503a8b
Implemented some of the Task methods
Mrockwell2 Aug 1, 2024
3f9d7a2
transfer to pc
Mrockwell2 Aug 5, 2024
9f07b8b
Fixed menu items not registering properties
Mrockwell2 Aug 7, 2024
7108a9c
Merge branch 'GUI_Refactor-Property_Injection' of https://github.com/…
Mrockwell2 Aug 7, 2024
f88e5fb
A bit of code cleanup
Mrockwell2 Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 66 additions & 21 deletions trick_source/java/src/main/java/trick/common/TrickApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Desktop.Action;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Method;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
Expand Down Expand Up @@ -47,13 +51,13 @@
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.View;
import org.jdesktop.application.session.PropertySupport;

import trick.common.framework.BaseApplication;
import trick.common.framework.PropertySupport;
import trick.common.framework.View;
import trick.common.ui.UIUtils;
import trick.common.utils.TrickAction;
import trick.common.utils.TrickResources;
import trick.common.utils.SwingAction;

/**
* The parent class which all other Trick Java GUI applications extend.
Expand All @@ -64,16 +68,18 @@
* @author Hong Chen
* @since Trick 10
*/
public abstract class TrickApplication extends SingleFrameApplication implements PropertySupport {
public abstract class TrickApplication extends BaseApplication implements PropertySupport {

//========================================
// Public data
//========================================
/** User settable properties, such as default directories, etc. */
public Properties trickProperties;
//public Properties appProperties;
//public TrickResources appProperties;

/** The resource map for the application. */
public ResourceMap resourceMap;
public TrickResources resourceMap;

/** The action map for the application. */
public ActionMap actionMap;
Expand All @@ -100,12 +106,16 @@ public abstract class TrickApplication extends SingleFrameApplication implements

/** The look and feel short name list */
protected static String[] lafShortNames;

protected static String SOURCE_PATH;
protected static String RESOURCE_PATH;


//========================================
// Private Data
//========================================
//========================================
private static int popupInvokerType;
private static TrickApplication the_trick_app;

// if we want to put the properties into a different location, change here.
static {
Expand Down Expand Up @@ -137,18 +147,28 @@ public abstract class TrickApplication extends SingleFrameApplication implements
}

private JDialog aboutBox = null;

//stop in trick.common.framework.BaseApplication$GUIDisplayRunner.run()
//========================================
// Constructors
//========================================

protected TrickApplication() {
String trick_home = System.getenv("TRICK_HOME");
if (trick_home == null || trick_home.isEmpty()) {
trick_home = System.getProperty("user.home") + java.io.File.separator + "trick";
}

SOURCE_PATH = trick_home + "/trick_source/java/src/main/java";
RESOURCE_PATH = trick_home + "/trick_source/java/src/main/resources";
the_trick_app = this;
}

//========================================
// Actions
//========================================
/**
* closes the application. Called when the "Exit" menu item is clicked.
*/
@Action
@SwingAction
public void exitConfirmation() {
if (confirmExitSelection.isSelected()) {
addExitListener(exitListener);
Expand All @@ -157,16 +177,16 @@ public void exitConfirmation() {
removeExitListener(exitListener);
}
}

@Action
@SwingAction
public void helpContents() {

}

/**
* Show the about box dialog.
*/
@Action
@SwingAction
public void showAboutBox() {
if (aboutBox == null) {
aboutBox = createAboutBox();
Expand All @@ -179,15 +199,15 @@ public void showAboutBox() {
/**
* Close the about box dialog.
*/
@Action
@SwingAction
public void closeAboutBox() {
if (aboutBox != null) {
aboutBox.setVisible(false);
aboutBox = null;
}
}

@Action
@SwingAction
public void lookAndFeel() {
if (lafMap == null) {
JOptionPane.showMessageDialog(getMainFrame(),
Expand Down Expand Up @@ -233,6 +253,15 @@ public void lookAndFeel() {
}
}

@SwingAction
public void quit(ActionEvent e) {
super.exit(e);
}

@SwingAction
public void quit() {
quit(null);
}

//========================================
// Set/Get methods
Expand All @@ -244,6 +273,8 @@ public static void setPopupInvoker(int type) {
public static int getPopupInvoker() {
return popupInvokerType;
}

public static TrickApplication getInstance() { return the_trick_app; }

//========================================
// Methods
Expand Down Expand Up @@ -306,6 +337,20 @@ public static String arrayToString(String[] arr, String separator) {
}
return result.toString();
}

public static String getResourcePath(Class app) {
String canon = app.getCanonicalName();
canon = "/" + canon.replace(".", "/") + ".properties";

int filePos = canon.lastIndexOf("/");
if (filePos >= 0 && filePos < canon.length()) {
String tail = canon.substring(0, filePos) + "/resources";
tail += canon.substring(filePos);
return RESOURCE_PATH + tail;
} else {
return "";
}
}


/**
Expand All @@ -323,9 +368,9 @@ protected void initialize(String[] args) {

// register property for JToggleButton class so that its state can be saved
getContext().getSessionStorage().putProperty(JToggleButton.class, this);

actionMap = getContext().getActionMap();
resourceMap = getContext().getResourceMap(getClass());
resourceMap = getContext().getResourceMap();
actionMap = getContext().getActionMap(this.getClass(), this);

// Load any saved user settable properties from properties file
trickProperties = new Properties();
Expand Down Expand Up @@ -449,7 +494,7 @@ protected JComponent createStatusBar() {
* @return A {@link javax.swing.Action} of the specified action name.
*/
protected javax.swing.Action getAction(String actionName) {
return getContext().getActionMap().get(actionName);
return actionMap.get(actionName);
}

/**
Expand Down
Loading
Loading