From 96d7cf5265a01c8ca5dc0e17c5a335540e153784 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Fri, 24 May 2024 09:45:22 -0500 Subject: [PATCH 01/23] Removed dependency on the Action annotation --- .../java/trick/common/TrickApplication.java | 84 ++++++++++++--- .../java/trick/common/utils/SwingAction.java | 13 +++ .../java/trick/common/utils/TrickAction.java | 101 ++++++++++++++++++ .../simcontrol/SimControlApplication.java | 44 ++++---- 4 files changed, 209 insertions(+), 33 deletions(-) create mode 100644 trick_source/java/src/main/java/trick/common/utils/SwingAction.java create mode 100644 trick_source/java/src/main/java/trick/common/utils/TrickAction.java diff --git a/trick_source/java/src/main/java/trick/common/TrickApplication.java b/trick_source/java/src/main/java/trick/common/TrickApplication.java index 6a83affcb..6649cafab 100644 --- a/trick_source/java/src/main/java/trick/common/TrickApplication.java +++ b/trick_source/java/src/main/java/trick/common/TrickApplication.java @@ -12,9 +12,11 @@ import java.awt.Insets; 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.net.URI; import java.net.URISyntaxException; @@ -47,13 +49,14 @@ 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.ui.UIUtils; +import trick.common.utils.TrickAction; +import trick.common.utils.SwingAction; /** * The parent class which all other Trick Java GUI applications extend. @@ -71,6 +74,7 @@ public abstract class TrickApplication extends SingleFrameApplication implements //======================================== /** User settable properties, such as default directories, etc. */ public Properties trickProperties; + public Properties appProperties; /** The resource map for the application. */ public ResourceMap resourceMap; @@ -100,11 +104,14 @@ public abstract class TrickApplication extends SingleFrameApplication implements /** The look and feel short name list */ protected static String[] lafShortNames; + + protected final String SOURCE_PATH; + protected final String RESOURCE_PATH; //======================================== // Private Data - //======================================== + //======================================== private static int popupInvokerType; // if we want to put the properties into a different location, change here. @@ -141,14 +148,23 @@ public abstract class TrickApplication extends SingleFrameApplication implements //======================================== // Constructors //======================================== - + protected TrickApplication() { + String trick_home = System.getenv("TRICK_HOME"); + if (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"; + } + //======================================== // Actions //======================================== /** * closes the application. Called when the "Exit" menu item is clicked. */ - @Action + @SwingAction public void exitConfirmation() { if (confirmExitSelection.isSelected()) { addExitListener(exitListener); @@ -157,8 +173,8 @@ public void exitConfirmation() { removeExitListener(exitListener); } } - - @Action + + @SwingAction public void helpContents() { } @@ -166,7 +182,7 @@ public void helpContents() { /** * Show the about box dialog. */ - @Action + @SwingAction public void showAboutBox() { if (aboutBox == null) { aboutBox = createAboutBox(); @@ -179,7 +195,7 @@ public void showAboutBox() { /** * Close the about box dialog. */ - @Action + @SwingAction public void closeAboutBox() { if (aboutBox != null) { aboutBox.setVisible(false); @@ -187,7 +203,7 @@ public void closeAboutBox() { } } - @Action + @SwingAction public void lookAndFeel() { if (lafMap == null) { JOptionPane.showMessageDialog(getMainFrame(), @@ -306,6 +322,49 @@ public static String arrayToString(String[] arr, String separator) { } return result.toString(); } + + protected void createActionMap() { + if(actionMap == null) actionMap = new ActionMap(); + + Class appClass = this.getClass(); + + for (Method man : appClass.getDeclaredMethods()) { + if (isSwingAction(man)) { + Properties actProp = TrickAction.extractProperties(appProperties, man.getName()); + actionMap.put(man.getName(), new TrickAction(actProp, this, man)); + } + } + } + + private boolean isSwingAction(Method man) { + return man.getAnnotation(SwingAction.class) != null; + } + + public String getResourcePath() { + String canon = this.getClass().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 ""; + } + } + + private void parseResources() { + try { + if (appProperties == null) appProperties = new Properties(); + + String path = getResourcePath(); + File prop = new File(path); + appProperties.load(new FileReader(prop)); + } catch(IOException ioe) { + System.err.println(ioe.getMessage()); + } + } /** @@ -323,8 +382,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(); + + parseResources(); + createActionMap(); resourceMap = getContext().getResourceMap(getClass()); // Load any saved user settable properties from properties file @@ -449,7 +509,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); } /** diff --git a/trick_source/java/src/main/java/trick/common/utils/SwingAction.java b/trick_source/java/src/main/java/trick/common/utils/SwingAction.java new file mode 100644 index 000000000..fca839aa6 --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/utils/SwingAction.java @@ -0,0 +1,13 @@ +package trick.common.utils; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface SwingAction {} + diff --git a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java new file mode 100644 index 000000000..051669ddf --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java @@ -0,0 +1,101 @@ +package trick.common.utils; + +import java.awt.event.ActionEvent; +import java.lang.reflect.Method; +import java.util.Properties; + +import javax.swing.AbstractAction; +import javax.swing.Action; + +import trick.common.TrickApplication; + +public class TrickAction extends AbstractAction { + private Properties props; + private TrickApplication invoker; + private Method man; + + + public TrickAction(Properties p, TrickApplication target, Method m) { + props = new Properties(p); + invoker = target; + man = m; + applyProperties(); + } + + @Override + public void actionPerformed(ActionEvent actionEvent) { + // System.out.println(props.getProperty("text")); + try { + man.invoke(invoker); + } catch (Exception e) { + System.err.println(e.getMessage()); + } + } + + @Override + public boolean isEnabled() { + return super.isEnabled(); + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + } + + @Override + public void putValue(String key, Object value) { + super.putValue(key, value); + } + + @Override + public String toString() { + return ""; + } + + private void applyProperties() { + putValue(Action.NAME, props.getProperty("text")); + } + + public static Properties extractProperties(Properties props, String name) { + String head = name + ".Action."; + String textKey = head + TEXT_PROPERTY, + iconKey = head + ICON_PROPERTY, + sIconKey = head + SMALL_ICON_PROPERTY, + lIconKey = head + LARGE_ICON_PROPERTY, + sDescKey = head + SHORT_DESCRIPTION_PROPERTY, + lDescKey = head + LONG_DESCRIPTION_PROPERTY; + + String textVal, sDescVal, lDescVal, + iconVal, sIconVal, lIconVal; + + Properties actionProp = new Properties(); + + if((textVal = props.getProperty(textKey)) != null) + actionProp.setProperty(TEXT_PROPERTY, textVal); + + if((sDescVal = props.getProperty(sDescKey)) != null) + actionProp.setProperty(SHORT_DESCRIPTION_PROPERTY, sDescVal); + + if((lDescVal = props.getProperty(lDescKey)) != null) + actionProp.setProperty(LONG_DESCRIPTION_PROPERTY, lDescVal); + + if((iconVal = props.getProperty(iconKey)) != null) + actionProp.setProperty(ICON_PROPERTY, iconVal); + + if((sIconVal = props.getProperty(sIconKey)) != null) + actionProp.setProperty(SMALL_ICON_PROPERTY, sIconVal); + + if((lIconVal = props.getProperty(lIconKey)) != null) + actionProp.setProperty(LARGE_ICON_PROPERTY, lIconVal); + + return actionProp; + } + + + private static final String TEXT_PROPERTY = "text"; + private static final String ICON_PROPERTY = "icon"; + private static final String SMALL_ICON_PROPERTY = "smallIcon"; + private static final String LARGE_ICON_PROPERTY = "largeIcon"; + private static final String SHORT_DESCRIPTION_PROPERTY = "shortDescription"; + private static final String LONG_DESCRIPTION_PROPERTY = "longDescription"; +} diff --git a/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java b/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java index ab4aeb053..e373676e2 100644 --- a/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java +++ b/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java @@ -70,7 +70,6 @@ import javax.swing.text.StyleContext; import javax.swing.text.StyledEditorKit; -import org.jdesktop.application.Action; import org.jdesktop.application.Application; import org.jdesktop.application.Task; import org.jdesktop.application.View; @@ -87,6 +86,7 @@ import trick.common.ui.panels.AnimationPlayer; import trick.common.ui.panels.FindBar; import trick.common.utils.VariableServerConnection; +import trick.common.utils.SwingAction; import trick.simcontrol.utils.SimControlActionController; import trick.simcontrol.utils.SimState; @@ -192,15 +192,16 @@ public class SimControlApplication extends TrickApplication implements PropertyC //======================================== // Actions //======================================== - @Action + + @SwingAction public void showStatusFont() { Font font = FontChooser.showDialog(statusMsgPane, "Choose Font", statusMsgPane.getFont()); if (font != null) { statusMsgPane.setFont(font); } } - - @Action + + @SwingAction public void saveStatusMsgs() { String initialName = "sim_msg_"; File file = UIUtils.chooseSaveFile(simState.getRunPath(), initialName, null, getMainFrame()); @@ -216,7 +217,7 @@ public void saveStatusMsgs() { } } - @Action + @SwingAction public void clearStatusMsgs() { if (statusMsgPane != null) { Document doc = statusMsgPane.getDocument(); @@ -230,67 +231,67 @@ public void clearStatusMsgs() { } } - @Action + @SwingAction public void startTV() { launchTrickApplication("tv", "--host " + host + " --port " + port); } - @Action + @SwingAction public void startMTV() { launchTrickApplication("mtv", host + " " + port); } - @Action + @SwingAction public void freezeAt() { actionController.handleFreezeAt(simState.getExecOutTime(), getMainFrame()); } - @Action + @SwingAction public void freezeIn() { actionController.handleFreezeIn(simState.getExecOutTime(), getMainFrame()); } - @Action + @SwingAction public void checkpointObjects() { customizedCheckpointObjects = actionController.handleCheckpointObjects(getMainFrame(), customizedCheckpointObjects); } - @Action + @SwingAction public void throttle() { actionController.handleThrottle(getMainFrame()); } - @Action + @SwingAction public void stepSim() { actionController.handleStep(debug_flag); } - @Action + @SwingAction public void recordingSim() { actionController.handleRecOnOff(dataRecButton.isSelected()); } - @Action + @SwingAction public void startSim() { actionController.handleStartSim(); } - @Action + @SwingAction public void realtime() { actionController.handleRealtime(realtimeButton.isSelected()); } - @Action + @SwingAction public void freezeSim() { actionController.handleFreeze(debug_flag); } - @Action + @SwingAction public void shutdownSim() { actionController.handleShutdown(); } - @Action + @SwingAction public void dumpChkpntASCII() { String fileName = "chkpnt_" + simState.getTwoFractionFormatted(simState.getExecOutTime()); @@ -312,14 +313,14 @@ public void dumpChkpntASCII() { currentSimStatusDesc = "PreCheckpoint"; } - @Action + @SwingAction public void loadChkpnt() { actionController.handleLoadChkpnt(simState.getRunPath(), getMainFrame()); runtimeStatePanel.setTitle("Loading Checkpoint"); currentSimStatusDesc = "PreCheckpoint"; } - @Action + @SwingAction public void lite() { if (liteButton.isSelected()) { getMainFrame().setSize(LITE_SIZE); @@ -332,7 +333,8 @@ public void lite() { * Connects to the variable server if {@link VariableServerConnection} is able to be created successfully and * starts the communication server for sim health status messages. */ - @Action + + @SwingAction public void connect() { // get host and port for selected sim if (runningSimList != null && runningSimList.getSelectedItem() != null) { From a3023114b98f8b59633c6a706f6c8eec2b78d834 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Thu, 30 May 2024 15:24:56 -0500 Subject: [PATCH 02/23] Removed dependency on @Action annotation --- .../java/trick/common/TrickApplication.java | 36 ++++++++++++++----- .../resources/TrickApplication.properties | 3 ++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/trick_source/java/src/main/java/trick/common/TrickApplication.java b/trick_source/java/src/main/java/trick/common/TrickApplication.java index 6649cafab..9cc0f0916 100644 --- a/trick_source/java/src/main/java/trick/common/TrickApplication.java +++ b/trick_source/java/src/main/java/trick/common/TrickApplication.java @@ -249,6 +249,10 @@ public void lookAndFeel() { } } + @SwingAction + public void quit() { + super.exit(null); + } //======================================== // Set/Get methods @@ -328,7 +332,7 @@ protected void createActionMap() { Class appClass = this.getClass(); - for (Method man : appClass.getDeclaredMethods()) { + for (Method man : appClass.getMethods()) { if (isSwingAction(man)) { Properties actProp = TrickAction.extractProperties(appProperties, man.getName()); actionMap.put(man.getName(), new TrickAction(actProp, this, man)); @@ -340,8 +344,8 @@ private boolean isSwingAction(Method man) { return man.getAnnotation(SwingAction.class) != null; } - public String getResourcePath() { - String canon = this.getClass().getCanonicalName(); + public String getResourcePath(Class app) { + String canon = app.getCanonicalName(); canon = "/" + canon.replace(".", "/") + ".properties"; int filePos = canon.lastIndexOf("/"); @@ -354,13 +358,27 @@ public String getResourcePath() { } } - private void parseResources() { + private Properties parseResources(Class app) throws IOException { + Properties prop; + File resource; + String path; + + if(app.getSimpleName().equals("TrickApplication")) { + prop = new Properties(); + } else { + Class superApp = app.getSuperclass(); + prop = new Properties(parseResources(superApp)); + } + + path = getResourcePath(app); + resource = new File(path); + prop.load(new FileReader(resource)); + return prop; + } + + protected void parseResources() { try { - if (appProperties == null) appProperties = new Properties(); - - String path = getResourcePath(); - File prop = new File(path); - appProperties.load(new FileReader(prop)); + appProperties = parseResources(this.getClass()); } catch(IOException ioe) { System.err.println(ioe.getMessage()); } diff --git a/trick_source/java/src/main/resources/trick/common/resources/TrickApplication.properties b/trick_source/java/src/main/resources/trick/common/resources/TrickApplication.properties index 53fc6086e..ac6bd3f78 100644 --- a/trick_source/java/src/main/resources/trick/common/resources/TrickApplication.properties +++ b/trick_source/java/src/main/resources/trick/common/resources/TrickApplication.properties @@ -86,6 +86,9 @@ openDR.Action.icon = fileopen.gif # saveDR action icon for DreApplication saveDR.Action.icon = filesave.gif +quit.Action.text = Quit +quit.Action.shortDescription = Quit Application + treeNodeClosed.icon = firefox_folder_closed.gif treeNodeOpen.icon = firefox_folder_open.gif treeNodeLeaf.icon = gnome-fs-regular.gif From f75ddc723a2ce08f74bf188950681615f7d41309 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Thu, 30 May 2024 16:53:10 -0500 Subject: [PATCH 03/23] Fixed icons --- .../java/trick/common/utils/TrickAction.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java index 051669ddf..df1d1ea6a 100644 --- a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java +++ b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java @@ -6,6 +6,7 @@ import javax.swing.AbstractAction; import javax.swing.Action; +import javax.swing.ImageIcon; import trick.common.TrickApplication; @@ -44,7 +45,7 @@ public void setEnabled(boolean enabled) { @Override public void putValue(String key, Object value) { - super.putValue(key, value); + if(value != null) super.putValue(key, value); } @Override @@ -53,7 +54,33 @@ public String toString() { } private void applyProperties() { - putValue(Action.NAME, props.getProperty("text")); + String propValue; + + putValue(Action.NAME, props.getProperty(TEXT_PROPERTY)); + putValue(Action.SHORT_DESCRIPTION, + props.getProperty(SHORT_DESCRIPTION_PROPERTY)); + putValue(Action.LONG_DESCRIPTION, + props.getProperty(LONG_DESCRIPTION_PROPERTY)); + + if((propValue = props.getProperty(ICON_PROPERTY)) != null) { + putValue(Action.SMALL_ICON, getIcon(propValue)); + putValue(Action.LARGE_ICON_KEY, getIcon(propValue)); + } else { + if((propValue = props.getProperty(SMALL_ICON_PROPERTY)) != null) { + putValue(Action.SMALL_ICON, getIcon(propValue)); + } + + if((propValue = props.getProperty(LARGE_ICON_PROPERTY)) != null) { + putValue(Action.LARGE_ICON_KEY, getIcon(propValue)); + } + } + } + + private ImageIcon getIcon(String fileName) { + String iconPath = invoker.getResourcePath(invoker.getClass()); + int finalSlash = iconPath.lastIndexOf("/") + 1; + iconPath = iconPath.substring(0, finalSlash) + fileName; + return new ImageIcon(iconPath); } public static Properties extractProperties(Properties props, String name) { From be89639192111db207d3b19987783b87fff1bc03 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Mon, 3 Jun 2024 09:32:03 -0500 Subject: [PATCH 04/23] Fixed issue with icons not being found. --- .../java/trick/common/TrickApplication.java | 11 ++- .../java/trick/common/utils/TrickAction.java | 45 ++++++++--- .../dataproducts/DataProductsApplication.java | 29 +++---- .../trickdp/TrickDPApplication.java | 67 +++++++++-------- .../trickqp/TrickQPApplication.java | 75 ++++++++++--------- 5 files changed, 132 insertions(+), 95 deletions(-) diff --git a/trick_source/java/src/main/java/trick/common/TrickApplication.java b/trick_source/java/src/main/java/trick/common/TrickApplication.java index 9cc0f0916..4f512d8fd 100644 --- a/trick_source/java/src/main/java/trick/common/TrickApplication.java +++ b/trick_source/java/src/main/java/trick/common/TrickApplication.java @@ -334,7 +334,8 @@ protected void createActionMap() { for (Method man : appClass.getMethods()) { if (isSwingAction(man)) { - Properties actProp = TrickAction.extractProperties(appProperties, man.getName()); + String name = man.getName(); + Properties actProp = TrickAction.extractProperties(appProperties, name); actionMap.put(man.getName(), new TrickAction(actProp, this, man)); } } @@ -373,6 +374,14 @@ private Properties parseResources(Class app) throws path = getResourcePath(app); resource = new File(path); prop.load(new FileReader(resource)); + + int filePos = path.lastIndexOf("/") + 1; + path = path.substring(0, filePos); + if(prop.getProperty("PATH") != null) + path += ";" + prop.getProperty("PATH"); + + prop.setProperty("PATH", path); + return prop; } diff --git a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java index df1d1ea6a..097c0c63b 100644 --- a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java +++ b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java @@ -1,6 +1,7 @@ package trick.common.utils; import java.awt.event.ActionEvent; +import java.io.File; import java.lang.reflect.Method; import java.util.Properties; @@ -77,12 +78,33 @@ private void applyProperties() { } private ImageIcon getIcon(String fileName) { - String iconPath = invoker.getResourcePath(invoker.getClass()); - int finalSlash = iconPath.lastIndexOf("/") + 1; - iconPath = iconPath.substring(0, finalSlash) + fileName; + String iconPath; + + if(fileName.indexOf("/") >= 0) { + iconPath = fileName; + } else { + iconPath = invoker.getResourcePath(invoker.getClass()); + int finalSlash = iconPath.lastIndexOf("/") + 1; + iconPath = iconPath.substring(0, finalSlash) + fileName; + } return new ImageIcon(iconPath); } + private static String resolveFilePath(String PATH, String fileName) { + String paths[] = PATH.split(";"); + String resolvedName; + File f; + + for(String path : paths) { + resolvedName = path + fileName; + f = new File(resolvedName); + if(f.exists() && !f.isDirectory()) + return resolvedName; + } + + return fileName; + } + public static Properties extractProperties(Properties props, String name) { String head = name + ".Action."; String textKey = head + TEXT_PROPERTY, @@ -106,14 +128,17 @@ public static Properties extractProperties(Properties props, String name) { if((lDescVal = props.getProperty(lDescKey)) != null) actionProp.setProperty(LONG_DESCRIPTION_PROPERTY, lDescVal); - if((iconVal = props.getProperty(iconKey)) != null) + if((iconVal = props.getProperty(iconKey)) != null) { + iconVal = resolveFilePath(props.getProperty("PATH"), iconVal); + actionProp.setProperty(ICON_PROPERTY, iconVal); - - if((sIconVal = props.getProperty(sIconKey)) != null) - actionProp.setProperty(SMALL_ICON_PROPERTY, sIconVal); - - if((lIconVal = props.getProperty(lIconKey)) != null) - actionProp.setProperty(LARGE_ICON_PROPERTY, lIconVal); + } else { + if((sIconVal = props.getProperty(sIconKey)) != null) + actionProp.setProperty(SMALL_ICON_PROPERTY, sIconVal); + + if((lIconVal = props.getProperty(lIconKey)) != null) + actionProp.setProperty(LARGE_ICON_PROPERTY, lIconVal); + } return actionProp; } diff --git a/trick_source/java/src/main/java/trick/dataproducts/DataProductsApplication.java b/trick_source/java/src/main/java/trick/dataproducts/DataProductsApplication.java index 6a174fb86..5e2ab10b2 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/DataProductsApplication.java +++ b/trick_source/java/src/main/java/trick/dataproducts/DataProductsApplication.java @@ -38,6 +38,7 @@ import trick.common.TrickApplication; import trick.common.ui.UIUtils; import trick.common.ui.components.NumberTextField; +import trick.common.utils.SwingAction; import trick.dataproducts.trickqp.TrickQPApplication; import trick.dataproducts.utils.Session; import trick.dataproducts.utils.SessionRun; @@ -210,7 +211,7 @@ protected JComponent getCommonBottom() { //======================================== // Methods //======================================== - @Action + @SwingAction public void configureRunTimename() { String msgStr1 = "Please specify the time name for the selected run\n"; String msgStr2 = "\n\n"; @@ -232,7 +233,7 @@ public void configureRunTimename() { } } - @Action + @SwingAction public void toggleGnuplot() { if (gnuplotButton.isSelected()) { gnuplotButton.setIcon(resourceMap.getIcon("gnuplot.on.icon")); @@ -251,68 +252,68 @@ public void toggleGnuplot() { } } - @Action + @SwingAction public void selectFermi() { gnuplotButton.setSelected(false); getAction("selectGnuplotTerminal").setEnabled(false); toggleGnuplot(); } - @Action + @SwingAction public void selectGnuplot() { gnuplotButton.setSelected(true); getAction("selectGnuplotTerminal").setEnabled(true); toggleGnuplot(); } - @Action + @SwingAction public void selectJavaPlot() { gnuplotButton.setSelected(false); getAction("selectGnuplotTerminal").setEnabled(false); toggleGnuplot(); } - @Action + @SwingAction public void selectTerminalDevice() { setDevice(Session.TERMINAL_DEVICE); } - @Action + @SwingAction public void selectPrinterDevice() { setDevice(Session.PRINTER_DEVICE); } - @Action + @SwingAction public void selectGnuplotTerminal() { // do nothing } - @Action + @SwingAction public void selectX11() { setGnuplotTerminal(Session.X11_GNUPLOT_TERMINAL); } - @Action + @SwingAction public void selectPSColor() { setGnuplotTerminal(Session.PS_COLOR_GNUPLOT_TERMINAL); } - @Action + @SwingAction public void selectPSBW() { setGnuplotTerminal(Session.PS_BW_GNUPLOT_TERMINAL); } - @Action + @SwingAction public void selectPNG() { setGnuplotTerminal(Session.PNG_GNUPLOT_TERMINAL); } - @Action + @SwingAction public void selectEPS() { setGnuplotTerminal(Session.EPS_GNUPLOT_TERMINAL); } - @Action + @SwingAction public void selectAQUA() { setGnuplotTerminal(Session.AQUA_GNUPLOT_TERMINAL); } diff --git a/trick_source/java/src/main/java/trick/dataproducts/trickdp/TrickDPApplication.java b/trick_source/java/src/main/java/trick/dataproducts/trickdp/TrickDPApplication.java index 603401d44..e99313784 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/trickdp/TrickDPApplication.java +++ b/trick_source/java/src/main/java/trick/dataproducts/trickdp/TrickDPApplication.java @@ -45,6 +45,7 @@ import trick.common.ui.UIUtils; import trick.common.ui.panels.DataPanel; import trick.common.ui.panels.ListPanel; +import trick.common.utils.SwingAction; import trick.dataproducts.DataProductsApplication; import trick.dataproducts.trickdp.utils.DPRemoteCallInterface; import trick.dataproducts.trickdp.utils.DPRemoteCallInterfaceImpl; @@ -110,62 +111,62 @@ public class TrickDPApplication extends DataProductsApplication { //======================================== // Actions //======================================== - @Action + @SwingAction public void newSession() { actionController.handleNewSession(); } - @Action + @SwingAction public void openSession() { actionController.handleOpenSession(); } - @Action + @SwingAction public void saveSession() { actionController.handleSaveSession(); } - @Action + @SwingAction public void refreshSession() { actionController.handleRefreshSession(); } - @Action + @SwingAction public void singlePlot() { setPreferredPresentation(Session.PRESENTATION_OPTIONS[Session.SIMPLE_PRESENTATION]); setDisplayMode(Session.MODE_OPTIONS[Session.PLOT_MODE]); actionController.handleSinglePlot(); } - @Action + @SwingAction public void comparisonPlot() { setPreferredPresentation(Session.PRESENTATION_OPTIONS[Session.COMPARISON_PRESENTATION]); setDisplayMode(Session.MODE_OPTIONS[Session.PLOT_MODE]); actionController.handleComparisonPlot(); } - @Action + @SwingAction public void errorPlot() { setPreferredPresentation(Session.PRESENTATION_OPTIONS[Session.DELTA_PRESENTATION]); setDisplayMode(Session.MODE_OPTIONS[Session.PLOT_MODE]); actionController.handleErrorPlot(); } - @Action + @SwingAction public void contrastPlot() { setPreferredPresentation(Session.PRESENTATION_OPTIONS[Session.CONTRAST_PRESENTATION]); setDisplayMode(Session.MODE_OPTIONS[Session.PLOT_MODE]); actionController.handleContrastPlot(); } - @Action + @SwingAction public void tabularData() { setPreferredPresentation(Session.PRESENTATION_OPTIONS[Session.SIMPLE_PRESENTATION]); setDisplayMode(Session.MODE_OPTIONS[Session.TABLE_MODE]); actionController.handleTabularData(); } - @Action + @SwingAction public void tabularErrorData() { setPreferredPresentation(Session.PRESENTATION_OPTIONS[Session.DELTA_PRESENTATION]); setDisplayMode(Session.MODE_OPTIONS[Session.TABLE_MODE]); @@ -173,44 +174,44 @@ public void tabularErrorData() { } // user selected Import Sim Dir from Sims/Runs menu - @Action + @SwingAction public void importSimDir() { actionController.handleImportSimDir(); } // user selected Add Run Dir from Sims/Runs menu - @Action + @SwingAction public void addRunDir() { actionController.handleAddRunDir(); } - @Action + @SwingAction public void gnuSinglePlot() { JOptionPane.showMessageDialog(getMainFrame(), "UNIMPLEMENTED FEATURE !\n" + "Gnu plot is not implemented yet.", "Error", JOptionPane.WARNING_MESSAGE); } - @Action + @SwingAction public void gnuComparisonPlot() { JOptionPane.showMessageDialog(getMainFrame(), "UNIMPLEMENTED FEATURE !\n" + "Gnu plot is not implemented yet.", "Error", JOptionPane.WARNING_MESSAGE); } - @Action + @SwingAction public void gnuErrorPlot() { JOptionPane.showMessageDialog(getMainFrame(), "UNIMPLEMENTED FEATURE !\n" + "Gnu plot is not implemented yet.", "Error", JOptionPane.WARNING_MESSAGE); } - @Action + @SwingAction public void quickPlot() { actionController.launchQP(getSelectedRunPaths()); } - @Action + @SwingAction public void createPDF() { if (fileDevice == null) { fileDevice = new File(UIUtils.getTrickUserHome()); @@ -218,7 +219,7 @@ public void createPDF() { PDFBooklet.showDialog(getMainFrame(), "Create PDF", fileDevice); } - @Action + @SwingAction public void addRuns() { actionController.handleAddRuns(); @@ -261,22 +262,22 @@ public void addRuns() { } } - @Action + @SwingAction public void readDPList() { actionController.handleReadDPList(); } - @Action + @SwingAction public void openSelected() { simRunTree.expandSelectedNodes(); } - @Action + @SwingAction public void closeSelected() { simRunTree.collapseSelectedNodes(); } - @Action + @SwingAction public void removeSelectedNodes() { if (TrickApplication.getPopupInvoker() == DataPanel.SIM_RUN_TREE) { simRunTree.removeSelectedData(); @@ -285,7 +286,7 @@ public void removeSelectedNodes() { } } - @Action + @SwingAction public void removeSelectedItems() { if (TrickApplication.getPopupInvoker() == DataPanel.RUN_LIST) { runList.removeSelectedData(); @@ -294,7 +295,7 @@ public void removeSelectedItems() { } } - @Action + @SwingAction public void removeAllItems() { if (TrickApplication.getPopupInvoker() == DataPanel.RUN_LIST) { runList.removeAllData(); @@ -303,19 +304,19 @@ public void removeAllItems() { } } - @Action + @SwingAction public void addDPs() { dpList.addData(simDPTree.getSelectedItems().toArray()); } // Add DP from Data Product menu - @Action + @SwingAction public void addDP() { actionController.handleAddDP(); } // Edit DP from Data Product menu - @Action + @SwingAction public void editSelectedDP() { int selectedLen = dpList.getSelectedData().length; if (selectedLen < 1) { @@ -334,19 +335,19 @@ public void editSelectedDP() { } // Edit DP... from the popup menu after right-clicking on a DP_ file - @Action + @SwingAction public void editRightClickedDP() { actionController.handleEditDP(rightClickedDP); } // Filter from Data Product menu - @Action + @SwingAction public void filterDP() { actionController.handleFilterDP(); } - @Action + @SwingAction public void runSim() { String simExe = "./S_main_" + UIUtils.getTrickHostCPU() + ".exe"; for (String eachItem : simRunTree.getSelectedItems()) { @@ -373,17 +374,17 @@ public void runSim() { } } - @Action + @SwingAction public void refreshSelected() { actionController.handleRefreshSelected(); } - @Action + @SwingAction public void plotDestination() { } - @Action + @SwingAction public void selectFileDevice() { fileDevice = UIUtils.chooseSaveFile(UIUtils.getTrickUserHome(), "dp_out", null, getMainFrame()); if (fileDevice != null) { diff --git a/trick_source/java/src/main/java/trick/dataproducts/trickqp/TrickQPApplication.java b/trick_source/java/src/main/java/trick/dataproducts/trickqp/TrickQPApplication.java index 1d00a7616..b5bdfbbbc 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/trickqp/TrickQPApplication.java +++ b/trick_source/java/src/main/java/trick/dataproducts/trickqp/TrickQPApplication.java @@ -47,6 +47,7 @@ import trick.common.ui.panels.ListPanel; import trick.common.utils.LogVar; import trick.common.utils.LogVar.DisplayType; +import trick.common.utils.SwingAction; import trick.common.utils.XMLCreator; import trick.dataproducts.DataProductsApplication; import trick.dataproducts.trickdp.utils.DPRemoteCallInterface; @@ -145,7 +146,7 @@ public String getTabTitle() { // Actions //======================================== - @Action + @SwingAction public void singlePlot() { setDisplayMode(Session.MODE_OPTIONS[Session.PLOT_MODE]); setPreferredPresentation(Session.PRESENTATION_OPTIONS[Session.SIMPLE_PRESENTATION]); @@ -154,7 +155,7 @@ public void singlePlot() { } } - @Action + @SwingAction public void comparisonPlot() { setDisplayMode(Session.MODE_OPTIONS[Session.PLOT_MODE]); setPreferredPresentation(Session.PRESENTATION_OPTIONS[Session.COMPARISON_PRESENTATION]); @@ -163,7 +164,7 @@ public void comparisonPlot() { } } - @Action + @SwingAction public void errorPlot() { setDisplayMode(Session.MODE_OPTIONS[Session.PLOT_MODE]); setPreferredPresentation(Session.PRESENTATION_OPTIONS[Session.DELTA_PRESENTATION]); @@ -172,7 +173,7 @@ public void errorPlot() { } } - @Action + @SwingAction public void contrastPlot() { setDisplayMode(Session.MODE_OPTIONS[Session.PLOT_MODE]); setPreferredPresentation(Session.PRESENTATION_OPTIONS[Session.CONTRAST_PRESENTATION]); @@ -181,7 +182,7 @@ public void contrastPlot() { } } - @Action + @SwingAction public void tabularData() { setDisplayMode(Session.MODE_OPTIONS[Session.TABLE_MODE]); setPreferredPresentation(Session.PRESENTATION_OPTIONS[Session.SIMPLE_PRESENTATION]); @@ -190,7 +191,7 @@ public void tabularData() { } } - @Action + @SwingAction public void tabularErrorData() { setDisplayMode(Session.MODE_OPTIONS[Session.TABLE_MODE]); setPreferredPresentation(Session.PRESENTATION_OPTIONS[Session.DELTA_PRESENTATION]); @@ -209,129 +210,129 @@ private void launchPlot() { launchPlotProgram(sessionFile); } - @Action + @SwingAction public void newDP() { actionController.handleNewDP(); } - @Action + @SwingAction public void openDP() { actionController.handleOpenDP(); } - //@Action + //@SwingAction //public void convertDP() { //TODO //} - @Action + @SwingAction public void refreshDP() { actionController.handleRefreshDP(); } // Return true if file is actually saved, false otherwise such as cancel selection. - @Action + @SwingAction public boolean saveDP() { return actionController.handleSaveDP(); } // Return true if file is actually saved, false otherwise such as cancel selection. - @Action + @SwingAction public boolean saveAsDP() { return actionController.handleSaveAsDP(); } - //@Action + //@SwingAction //public void propertiesDP() { //} - @Action + @SwingAction public void searchVar() { actionController.handleSearchVar(); } - @Action + @SwingAction public void addVar() { actionController.handleAddVar(); } - @Action + @SwingAction public void expandVar() { actionController.expandVar(); } - @Action + @SwingAction public void contractVar() { actionController.contractVar(); } - @Action + @SwingAction public void changeUnits() { actionController.changeUnits(); } - @Action + @SwingAction public void addRun() { actionController.handleAddRun(); } - @Action + @SwingAction public void removeRun() { actionController.handleRemoveRun(); } - @Action + @SwingAction public void newPage() { actionController.handleNewPage(); } - @Action + @SwingAction public void removeAllPages() { plotsNode.removeAllChildren(); productTree.getDefaultModel().nodeStructureChanged(plotsNode); } - @Action + @SwingAction public void newPlot() { actionController.handleNewPlot(); } - @Action + @SwingAction public void newCurve() { actionController.handleNewCurve(); } - @Action + @SwingAction public void newVarcase() { actionController.handleNewVarcase(); } - @Action + @SwingAction public void removeSelectedNode() { if (productTree != null) { productTree.removeClickedNode(); } } - @Action + @SwingAction public void newTable() { actionController.handleNewTable(); } - @Action + @SwingAction public void removeTable() { tablesNode.removeAllChildren(); productTree.getDefaultModel().nodeStructureChanged(tablesNode); } - @Action + @SwingAction public void newColumn() { actionController.handleNewColumn(); } - @Action + @SwingAction public void newProgram() { if (programsNode.getChildCount() >= 1) { JOptionPane.showMessageDialog(getMainFrame(), @@ -343,13 +344,13 @@ public void newProgram() { } } - @Action + @SwingAction public void removeAllPrograms() { programsNode.removeAllChildren(); productTree.getDefaultModel().nodeStructureChanged(programsNode); } - @Action + @SwingAction public void newProgramOutput() { if (programsNode.getChildCount() < 1) { JOptionPane.showMessageDialog(getMainFrame(), @@ -367,13 +368,13 @@ public void newProgramOutput() { } } - @Action + @SwingAction public void selectFunction() { // handled in LocalListMouseListener#MouseClicked // this empty action method is for gui display } - @Action + @SwingAction public void subtractFunction() { if (varList == null || varList.getSelectedData() == null || varList.getSelectedData().length != 2) { JOptionPane.showMessageDialog(getMainFrame(), @@ -385,7 +386,7 @@ public void subtractFunction() { } } - @Action + @SwingAction public void reverseSubtractFunction() { if (varList == null || varList.getSelectedData() == null || varList.getSelectedData().length != 2) { JOptionPane.showMessageDialog(getMainFrame(), @@ -397,13 +398,13 @@ public void reverseSubtractFunction() { } } - @Action + @SwingAction public void cancelFunction() { // do nothing as if it is selected, the related popup will be closed and this is what is desired. } @Override - @Action + @SwingAction public void quit(ActionEvent e) { if ((productTree.getAllChildren(plotsNode) != null && productTree.getAllChildren(plotsNode).size() > 0) || (productTree.getAllChildren(tablesNode) != null && productTree.getAllChildren(tablesNode).size() > 0)) { From 6bb82411049e76f58e6376f8f89fd4133b67cdf6 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Mon, 3 Jun 2024 16:32:12 -0500 Subject: [PATCH 05/23] Removed dependence on Action annotation in all GUI --- .../dataproducts/DataProductsApplication.java | 1 - .../dataproducts/plot/JXPlotApplication.java | 4 +- .../trickdp/TrickDPApplication.java | 1 - .../trickqp/TrickQPApplication.java | 1 - .../main/java/trick/dre/DreApplication.java | 54 ++++++++++--------- .../java/src/main/java/trick/mtv/MtvView.java | 28 +++++----- .../main/java/trick/sie/SieApplication.java | 6 +-- 7 files changed, 48 insertions(+), 47 deletions(-) diff --git a/trick_source/java/src/main/java/trick/dataproducts/DataProductsApplication.java b/trick_source/java/src/main/java/trick/dataproducts/DataProductsApplication.java index 5e2ab10b2..1b30549bf 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/DataProductsApplication.java +++ b/trick_source/java/src/main/java/trick/dataproducts/DataProductsApplication.java @@ -30,7 +30,6 @@ import javax.swing.JToggleButton; import javax.swing.SwingWorker; -import org.jdesktop.application.Action; import org.jdesktop.application.View; import org.jdesktop.swingx.JXMultiSplitPane; import org.jdesktop.swingx.MultiSplitLayout; diff --git a/trick_source/java/src/main/java/trick/dataproducts/plot/JXPlotApplication.java b/trick_source/java/src/main/java/trick/dataproducts/plot/JXPlotApplication.java index 3abfa78c2..1fef95d67 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/plot/JXPlotApplication.java +++ b/trick_source/java/src/main/java/trick/dataproducts/plot/JXPlotApplication.java @@ -27,7 +27,6 @@ import javax.swing.tree.TreePath; import javax.xml.parsers.ParserConfigurationException; -import org.jdesktop.application.Action; import org.jdesktop.application.Application; import org.jdesktop.application.View; import org.jdesktop.swingx.JXMultiSplitPane; @@ -51,6 +50,7 @@ import trick.common.TrickApplication; import trick.common.ui.UIUtils; +import trick.common.utils.SwingAction; import trick.dataproducts.plot.utils.PlotUtils; import trick.dataproducts.plot.utils.TrickChart; import trick.dataproducts.plot.utils.TrickChartFrame; @@ -108,7 +108,7 @@ public class JXPlotApplication extends TrickApplication { //======================================== // Actions //======================================== - @Action + @SwingAction public void saveAllToPDF() { File file = UIUtils.chooseSaveFile(null, "plot_", "pdf", getMainFrame()); if (file == null) { diff --git a/trick_source/java/src/main/java/trick/dataproducts/trickdp/TrickDPApplication.java b/trick_source/java/src/main/java/trick/dataproducts/trickdp/TrickDPApplication.java index e99313784..c06d24096 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/trickdp/TrickDPApplication.java +++ b/trick_source/java/src/main/java/trick/dataproducts/trickdp/TrickDPApplication.java @@ -37,7 +37,6 @@ import javax.swing.border.EtchedBorder; import javax.swing.tree.DefaultMutableTreeNode; -import org.jdesktop.application.Action; import org.jdesktop.application.Application; import trick.common.TrickApplication; diff --git a/trick_source/java/src/main/java/trick/dataproducts/trickqp/TrickQPApplication.java b/trick_source/java/src/main/java/trick/dataproducts/trickqp/TrickQPApplication.java index b5bdfbbbc..8ff46c199 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/trickqp/TrickQPApplication.java +++ b/trick_source/java/src/main/java/trick/dataproducts/trickqp/TrickQPApplication.java @@ -38,7 +38,6 @@ import javax.swing.border.EtchedBorder; import javax.swing.tree.DefaultMutableTreeNode; -import org.jdesktop.application.Action; import org.jdesktop.application.Application; import trick.common.ui.UIUtils; diff --git a/trick_source/java/src/main/java/trick/dre/DreApplication.java b/trick_source/java/src/main/java/trick/dre/DreApplication.java index 369d12c68..b090a8465 100644 --- a/trick_source/java/src/main/java/trick/dre/DreApplication.java +++ b/trick_source/java/src/main/java/trick/dre/DreApplication.java @@ -8,23 +8,23 @@ // Imports //======================================== -import org.jdesktop.application.Action; import org.jdesktop.application.Application; import org.jdesktop.application.View; import org.jdesktop.swingx.JXLabel; +import org.jdesktop.swingx.JXButton; +import org.jdesktop.swingx.JXPanel; +import org.jdesktop.swingx.JXTextField; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import trick.common.TrickApplication; + import trick.common.ui.UIUtils; import trick.common.ui.components.NumberTextField; import trick.common.ui.panels.ListPanel; +import trick.common.utils.SwingAction; +import trick.common.utils.vs.Variable; +import trick.common.TrickApplication; import trick.sie.utils.*; -import javax.swing.*; -import javax.swing.tree.TreePath; -import org.jdesktop.swingx.JXButton; -import org.jdesktop.swingx.JXPanel; -import org.jdesktop.swingx.JXTextField; -import javax.xml.parsers.ParserConfigurationException; + import java.awt.*; import java.awt.event.KeyEvent; import java.awt.event.ActionEvent; @@ -42,13 +42,17 @@ import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; -import trick.common.utils.vs.Variable; + +import javax.swing.*; +import javax.swing.tree.TreePath; +import javax.xml.parsers.ParserConfigurationException; /** * Dre - data recording editor application. * * @author Hong Chen * @author Scott Fennell + * @intern Marcus Rockwell * @since Trick 10 * @since Trick 17 */ @@ -154,7 +158,7 @@ public class DreApplication extends TrickApplication { //======================================== // Actions //======================================== - @Action + @SwingAction public void openDR() { File file = UIUtils.chooseOpenFile(null, null, "dr", getMainFrame()); if (file != null) { @@ -162,7 +166,7 @@ public void openDR() { } } - @Action + @SwingAction public void saveDR() { if (nameField.getText().trim().compareTo("") == 0) { JOptionPane.showMessageDialog(getMainFrame(), "A group name must be entered!", @@ -179,7 +183,7 @@ public void saveDR() { } } - @Action + @SwingAction public void selectDRBinary() { format = "DRBinary"; DRAscii_item.setSelected(false); @@ -187,7 +191,7 @@ public void selectDRBinary() { DRHDF5_item.setSelected(false); } - @Action + @SwingAction public void selectDRAscii() { format = "DRAscii"; DRAscii_item.setSelected(true); @@ -195,7 +199,7 @@ public void selectDRAscii() { DRHDF5_item.setSelected(false); } - @Action + @SwingAction public void selectDRHDF5() { format = "DRHDF5"; DRAscii_item.setSelected(false); @@ -203,7 +207,7 @@ public void selectDRHDF5() { DRHDF5_item.setSelected(true); } - @Action + @SwingAction public void selectDRAlways() { frequency = "DR_Always"; DRAlways_item.setSelected(true); @@ -211,7 +215,7 @@ public void selectDRAlways() { DRStepChanges_item.setSelected(false); } - @Action + @SwingAction public void selectDRChanges() { frequency = "DR_Changes"; DRAlways_item.setSelected(false); @@ -219,7 +223,7 @@ public void selectDRChanges() { DRStepChanges_item.setSelected(false); } - @Action + @SwingAction public void selectDRStepChanges() { frequency = "DR_Step_Changes"; DRAlways_item.setSelected(false); @@ -227,7 +231,7 @@ public void selectDRStepChanges() { DRStepChanges_item.setSelected(true); } - @Action + @SwingAction public void toggleSinglePrecision() { isSinglePrecision = singlePrecisionCheckBox.getState(); if (isSinglePrecision) { @@ -237,7 +241,7 @@ public void toggleSinglePrecision() { } } - @Action + @SwingAction public void selectDRBuffer() { buffering = "DR_Buffer"; DRBuffer_item.setSelected(true); @@ -245,7 +249,7 @@ public void selectDRBuffer() { DRRingBuffer_item.setSelected(false); } - @Action + @SwingAction public void selectDRNoBuffer() { buffering = "DR_No_Buffer"; DRBuffer_item.setSelected(false); @@ -253,7 +257,7 @@ public void selectDRNoBuffer() { DRRingBuffer_item.setSelected(false); } - @Action + @SwingAction public void selectDRRingBuffer() { buffering = "DR_Ring_Buffer"; DRBuffer_item.setSelected(false); @@ -261,7 +265,7 @@ public void selectDRRingBuffer() { DRRingBuffer_item.setSelected(true); } - @Action + @SwingAction public void selectDRThreadBuffer() { buffering = "DR_Thread_Buffer"; DRBuffer_item.setSelected(false); @@ -269,7 +273,7 @@ public void selectDRThreadBuffer() { DRRingBuffer_item.setSelected(false); } - @Action + @SwingAction public void removeSelected() { Object[] values = selectedVarList.getSelectedData(); for (int i = 0; i < values.length; i++) { @@ -278,13 +282,13 @@ public void removeSelected() { selectedVarList.removeSelectedData(); } - @Action + @SwingAction public void removeAll() { selectedVarList.removeAllData(); variables.clear(); } - @Action + @SwingAction public void addVariables() { for (SieTemplate thisValue : searchPanel.getSelectedValues()) { addVariable(thisValue.toString()); diff --git a/trick_source/java/src/main/java/trick/mtv/MtvView.java b/trick_source/java/src/main/java/trick/mtv/MtvView.java index b0ff9a030..c9dda3d65 100644 --- a/trick_source/java/src/main/java/trick/mtv/MtvView.java +++ b/trick_source/java/src/main/java/trick/mtv/MtvView.java @@ -49,13 +49,13 @@ import javax.swing.event.TableModelListener; import javax.swing.table.DefaultTableCellRenderer; -import org.jdesktop.application.Action; import org.jdesktop.application.Application.ExitListener; import org.jdesktop.application.FrameView; import org.jdesktop.application.ResourceMap; import org.jdesktop.application.TaskMonitor; import trick.common.TrickApplication; +import trick.common.utils.SwingAction; /** * The application's main frame. @@ -142,7 +142,7 @@ public void propertyChange(java.beans.PropertyChangeEvent evt) { // ================================== General Functions ======================================= // user clicked Show Exit Confirmation Prompt from file menu - @Action + @SwingAction public void show_exit_prompt() { MtvApp.confirmExit = confirmExitMenuItem.isSelected(); if (MtvApp.confirmExit) { @@ -154,14 +154,14 @@ public void show_exit_prompt() { } } // user clicked Exit from file menu - @Action + @SwingAction public void quit() { //System.out.println("Quit action."); MtvApp.getApplication().exit(); } // user clicked Connect button, or hit return in host field or port field - @Action + @SwingAction public void connect() { if (!connect_button.isEnabled()) { JOptionPane.showMessageDialog(viewPanel, "Already connected.", @@ -177,7 +177,7 @@ public void connect() { // ================================== View Tab Functions ======================================= // DANNY: NO LONGER USED user clicked Hide Unnamed Events toggle in edit menu - //@Action + //@SwingAction //public void hide_nonames() { // MtvApp.getApplication().hide_nonames = hideNonamesMenuItem.getState(); // if (MtvApp.vscom != null) { @@ -192,7 +192,7 @@ public void connect() { // } // user clicked Customize Event Display... in edit menu - @Action + @SwingAction public void customize_event_display() { if (connect_button.isEnabled()) { @@ -403,7 +403,7 @@ public void stateChanged(ChangeEvent e) { } // user clicked a Cycle from cycle menu - @Action + @SwingAction public void set_cycle() { MtvApp.getApplication().var_cycle = Double.parseDouble(cycle_group.getSelection().getActionCommand()); if (MtvApp.vscom != null) { @@ -430,7 +430,7 @@ public void get_one_shot_data() { // user clicked Load Event from file menu - @Action + @SwingAction public void load_event() { FileReader fr = null; BufferedReader br = null; @@ -489,7 +489,7 @@ public void load_event() { } // user clicked Delete Event from edit menu - @Action + @SwingAction public void delete_event() { Object[] options = { "Yes, DELETE it!", "Cancel" }; String results[] = null; @@ -629,7 +629,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, // ================================== Edit Tab Functions ======================================= // Starting up MTV, or user clicked Create New Event from edit menu - @Action + @SwingAction public void edit_new_event() { if (edit_not_saved) { @@ -676,7 +676,7 @@ public void edit_new_event() { } // user clicked Save in file menu - @Action + @SwingAction public void save_event() { FileWriter fw = null; BufferedWriter bw = null; @@ -752,7 +752,7 @@ public void save_event() { } // user clicked Send To Sim button - @Action + @SwingAction public void send_to_sim() { String line, stmt, col; String parse_string = ""; @@ -845,7 +845,7 @@ public void add_new_statement(String command, Vector new_row) { } // user clicked Add Line or Add Statement from edit menu - @Action + @SwingAction public void add_line(ActionEvent e) { String stmt, command, starting, data, ending; int num; @@ -995,7 +995,7 @@ public void add_line(ActionEvent e) { } // user clicked Delete Line from edit menu - @Action + @SwingAction public void delete_line() { String stmt, starting, ending; int count, num, num_to_delete; diff --git a/trick_source/java/src/main/java/trick/sie/SieApplication.java b/trick_source/java/src/main/java/trick/sie/SieApplication.java index 4d772792d..99e551132 100644 --- a/trick_source/java/src/main/java/trick/sie/SieApplication.java +++ b/trick_source/java/src/main/java/trick/sie/SieApplication.java @@ -51,7 +51,6 @@ import javax.swing.tree.TreePath; import javax.xml.parsers.ParserConfigurationException; -import org.jdesktop.application.Action; import org.jdesktop.application.Application; import org.jdesktop.application.View; import org.jdesktop.swingx.JXEditorPane; @@ -61,6 +60,7 @@ import trick.common.TrickApplication; import trick.common.ui.UIUtils; import trick.common.ui.panels.FindBar; +import trick.common.utils.SwingAction; import trick.sie.utils.SearchPanel; import trick.sie.utils.SieEnumeration; import trick.sie.utils.SieResourceDomParser; @@ -142,7 +142,7 @@ public String getTitle() { //======================================== // Actions //======================================== - @Action + @SwingAction public void saveVariableDetails() { String initialName = "sie_var_"; File file = UIUtils.chooseSaveFile(null, initialName, null, getMainFrame()); @@ -153,7 +153,7 @@ public void saveVariableDetails() { } } - @Action + @SwingAction public void showVariableDetails() { try { updateReadingPaneForSearch(); From 32acd6942b6b2966631f7164b1f4f4ce66dc06f6 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Mon, 3 Jun 2024 16:32:54 -0500 Subject: [PATCH 06/23] Fixed typos in .properties files --- .../resources/TrickApplication.properties | 10 +-- .../DataProductsApplication.properties | 12 ++-- .../resources/TrickDPApplication.properties | 42 ++++++------ .../resources/TrickQPApplication.properties | 66 +++++++++---------- .../dre/resources/DreApplication.properties | 14 ++-- .../SimControlApplication.properties | 18 ++--- .../SimSnifferApplication.properties | 4 +- 7 files changed, 83 insertions(+), 83 deletions(-) diff --git a/trick_source/java/src/main/resources/trick/common/resources/TrickApplication.properties b/trick_source/java/src/main/resources/trick/common/resources/TrickApplication.properties index ac6bd3f78..c6018bc93 100644 --- a/trick_source/java/src/main/resources/trick/common/resources/TrickApplication.properties +++ b/trick_source/java/src/main/resources/trick/common/resources/TrickApplication.properties @@ -21,7 +21,7 @@ trick.logo = trick.gif sie.resource.file = S_sie.resource ## File menu - can be used/override in any subclass -fileMenu.text = &File +fileMenu.text = File exitConfirmation.Action.text = Show Exit Confirmation Prompt exitConfirmation.Action.shortDescription = Turn On/Off popup box that verifies \ @@ -29,11 +29,11 @@ if the user really wants to close this application. ## Help menu -helpContents.Action.text = &Help Contents +helpContents.Action.text = Help Contents helpContents.Action.shortDescription = Show Help Contents ## About -showAboutBox.Action.text = &About... +showAboutBox.Action.text = About... showAboutBox.Action.shortDescription = Show the application's about box dialog closeAboutBox.Action.text = OK @@ -59,7 +59,7 @@ homepageLabel.text = Homepage: homepageTextField.text = ${Application.homepage} ## Look and Feel -lookAndFeel.Action.text = &Look and Feel +lookAndFeel.Action.text = Look and Feel lookAndFeel.Action.ShortDescription = Change Look and Feel ## Specify certain action icons here so that they can be put in common @@ -86,7 +86,7 @@ openDR.Action.icon = fileopen.gif # saveDR action icon for DreApplication saveDR.Action.icon = filesave.gif -quit.Action.text = Quit +quit.Action.text = Exit quit.Action.shortDescription = Quit Application treeNodeClosed.icon = firefox_folder_closed.gif diff --git a/trick_source/java/src/main/resources/trick/dataproducts/resources/DataProductsApplication.properties b/trick_source/java/src/main/resources/trick/dataproducts/resources/DataProductsApplication.properties index 417e5d15c..166bde852 100644 --- a/trick_source/java/src/main/resources/trick/dataproducts/resources/DataProductsApplication.properties +++ b/trick_source/java/src/main/resources/trick/dataproducts/resources/DataProductsApplication.properties @@ -6,27 +6,27 @@ Application.title = Data Products mainFrame.title = Data Products -singlePlot.Action.text = &Single Plot... +singlePlot.Action.text = Single Plot... singlePlot.Action.shortDescription = Show Single Plot singlePlot.Action.icon = plot_single.gif -comparisonPlot.Action.text = &Comparison Plot... +comparisonPlot.Action.text = Comparison Plot... comparisonPlot.Action.shortDescription = Show Comparison Plot comparisonPlot.Action.icon = plot_coplot.gif -errorPlot.Action.text = &Error Plot... +errorPlot.Action.text = Error Plot... errorPlot.Action.shortDescription = Show Error Plot errorPlot.Action.icon = plot_error.gif -contrastPlot.Action.text = Co&ntrast Plot... +contrastPlot.Action.text = Contrast Plot... contrastPlot.Action.shortDescription = Contrast Plot: Show Both Comparison and Error Plots contrastPlot.Action.icon = plot_contrast.gif -tabularData.Action.text = &Table... +tabularData.Action.text = Table... tabularData.Action.shortDescription = Show Tabular Data tabularData.Action.icon = table_callback1.gif -tabularErrorData.Action.text = Table Err&or... +tabularErrorData.Action.text = Table Error... tabularErrorData.Action.shortDescription = Show Tabular Error Data tabularErrorData.Action.icon = table_error_callback.gif diff --git a/trick_source/java/src/main/resources/trick/dataproducts/trickdp/resources/TrickDPApplication.properties b/trick_source/java/src/main/resources/trick/dataproducts/trickdp/resources/TrickDPApplication.properties index a06c724ea..dab67e7f6 100644 --- a/trick_source/java/src/main/resources/trick/dataproducts/trickdp/resources/TrickDPApplication.properties +++ b/trick_source/java/src/main/resources/trick/dataproducts/trickdp/resources/TrickDPApplication.properties @@ -8,58 +8,58 @@ Application.description = Trick Data Products Application mainFrame.title = Trick DP # Menu Bar -sessionMenu.text = &Session -simsRunsMenu.text = Sims/&Runs -dataProductMenu.text = &Data Product -settingsMenu.text = Se&ttings -actionsMenu.text = &Actions -helpMenu.text = &Help +sessionMenu.text = Session +simsRunsMenu.text = Sims/Runs +dataProductMenu.text = Data Product +settingsMenu.text = Settings +actionsMenu.text = Actions +helpMenu.text = Help # Menu items ## Session menu -newSession.Action.text = &New... +newSession.Action.text = New... newSession.Action.shortDescription = Start a New Session -openSession.Action.text = &Open... +openSession.Action.text = Open... openSession.Action.shortDescription = Open an Existing Session -##convertSession.Action.text = &Convert... +##convertSession.Action.text = Convert... ##convertSession.Action.shortDescription = Convert Session File to XML Format -saveSession.Action.text = &Save... +saveSession.Action.text = Save... saveSession.Action.shortDescription = Save Current Session -refreshSession.Action.text = R&efresh... +refreshSession.Action.text = Refresh... refreshSession.Action.shortDescription = Refresh Current Session -#propertiesSession.Action.text = &Properties... +#propertiesSession.Action.text = Properties... #propertiesSession.Action.shortDescription = Show Properties of Current Session ## Sims/Runs menu -importSimDir.Action.text = Import &Sim Dir... +importSimDir.Action.text = Import Sim Dir... importSimDir.Action.shortDescription = Import Sim Directory to Current Session -addRunDir.Action.text = Add &Run Dir... +addRunDir.Action.text = Add Run Dir... addRunDir.Action.shortDescription = Add a Run Directory to Current Session ## Data Product menu -addDP.Action.text = &Add DP... +addDP.Action.text = Add DP... addDP.Action.shortDescription = Add a Data Product file to Current Session -editSelectedDP.Action.text = &Edit DP... +editSelectedDP.Action.text = Edit DP... editSelectedDP.Action.shortDescription = Open Quickplot to edit the Selected Data Product from DP Selections -editRightClickedDP.Action.text = &Edit DP... +editRightClickedDP.Action.text = Edit DP... editRightClickedDP.Action.shortDescription = Open Quickplot to edit the Selected Data Product file -filterDP.Action.text = &Filter... +filterDP.Action.text = Filter... filterDP.Action.shortDescription = Filter the Displayed Data Product files ## Settings -plotDestination.Action.text = &Destination +plotDestination.Action.text = Destination plotDestination.Action.shortDescritpion = The Destination for Plotting @@ -76,11 +76,11 @@ gnuErrorPlot.Action.text = GNUplot Postscript Error Plot... gnuErrorPlot.Action.shortDescription = Show GNU Postscript Error Plot gnuErrorPlot.Action.icon = ps_error.gif -quickPlot.Action.text = &Quickplot... +quickPlot.Action.text = Quickplot... quickPlot.Action.shortDescription = Quick Plot quickPlot.Action.icon = quickplot.gif -createPDF.Action.text = Create &PDF Booklet... +createPDF.Action.text = Create PDF Booklet... createPDF.Action.shortDescription = Create PDF Booklet... createPDF.Action.icon = adobe_pdf.gif diff --git a/trick_source/java/src/main/resources/trick/dataproducts/trickqp/resources/TrickQPApplication.properties b/trick_source/java/src/main/resources/trick/dataproducts/trickqp/resources/TrickQPApplication.properties index 417ef5776..363a996e2 100644 --- a/trick_source/java/src/main/resources/trick/dataproducts/trickqp/resources/TrickQPApplication.properties +++ b/trick_source/java/src/main/resources/trick/dataproducts/trickqp/resources/TrickQPApplication.properties @@ -7,14 +7,14 @@ Application.description = Trick Quick Plotting Application mainFrame.title = Trick QP # Menu Bar -varsMenu.text = &Vars -runsMenu.text = &Runs -plotsMenu.text = &Plots -tablesMenu.text = &Tables -programsMenu.text = Pro&grams -settingsMenu.text = &Settings -actionsMenu.text = &Actions -helpMenu.text = &Help +varsMenu.text = Vars +runsMenu.text = Runs +plotsMenu.text = Plots +tablesMenu.text = Tables +programsMenu.text = Programs +settingsMenu.text = Settings +actionsMenu.text = Actions +helpMenu.text = Help searchVar.Action.text = Search @@ -25,51 +25,51 @@ searchVar.Action.shortDescription = Search Variables (all variables return if le # Menu items ## File menu -newDP.Action.text = &New DP... +newDP.Action.text = New DP... newDP.Action.shortDescription = Start a New DP -openDP.Action.text = &Open DP... +openDP.Action.text = Open DP... openDP.Action.shortDescription = Open an Existing DP File # May add later -#convertDP.Action.text = Conver&t CP... +#convertDP.Action.text = Convert CP... #convertDP.Action.shortDescription = Convert Old DP File to XML Format -refreshDP.Action.text = &Refresh... +refreshDP.Action.text = Refresh... refreshDP.Action.shortDescription = Refresh DP -saveDP.Action.text = &Save... +saveDP.Action.text = Save... saveDP.Action.shortDescription = Save Current DP -saveAsDP.Action.text = Save &As... +saveAsDP.Action.text = Save As... saveAsDP.Action.shortDescription = Save Current DP As # No need -##propertiesDP.Action.text = &Properties... +##propertiesDP.Action.text = Properties... ##propertiesDP.Action.shortDescription = Show Properties of Current DP ## Vars menu -addVar.Action.text = &Add Var +addVar.Action.text = Add Var addVar.Action.shortDescription = Add Selected Variables -expandVar.Action.text = &Expand Var +expandVar.Action.text = Expand Var expandVar.Action.shortDescription = Expand Selected Variables / All -contractVar.Action.text = &Contract Var +contractVar.Action.text = Contract Var contractVar.Action.shortDescription = Contract Selected Variables / All -changeUnits.Action.text = Change &Units... +changeUnits.Action.text = Change Units... changeUnits.Action.shortDescription = Change Units ## Runs menu -addRun.Action.text = &Add Run... +addRun.Action.text = Add Run... addRun.Action.shortDescription = Add Run Directories -removeRun.Action.text = &Remove Run +removeRun.Action.text = Remove Run removeRun.Action.shortDescription = Remove Selected Run Directories ## Plots menu -newPage.Action.text = &New Page +newPage.Action.text = New Page newPage.Action.shortDescription =Add a New Page removeAllPages.Action.text = Remove All Pages @@ -81,33 +81,33 @@ removeAllPages.Action.shortDescription = Remove All Pages ##removePlotFromPage.Action.text = Remove Plots From Selected Page ##removePlotFromPage.Action.shortDescription = Remove All Plots From Selected Pages -newPlot.Action.text = New &Plot +newPlot.Action.text = New Plot newPlot.Action.shortDescription = Add a New Plot -newCurve.Action.text = New &Curve +newCurve.Action.text = New Curve newCurve.Action.shortDescription = Add a New Curve -newVarcase.Action.text = New &Varcase +newVarcase.Action.text = New Varcase newVarcase.Action.shortDescription = Add One Variable Group Option for the Curve ## Tables menu -newTable.Action.text = &New Table +newTable.Action.text = New Table newTable.Action.shortDescription =Add a New Table -newColumn.Action.text = New &Column +newColumn.Action.text = New Column newColumn.Action.shortDescription = Add a New Column to Table removeTable.Action.text = Remove All Tables removeTable.Action.shortDescription = Remove All Tables ## Programs menu -newProgram.Action.text = &New Program +newProgram.Action.text = New Program newProgram.Action.shortDescription =Add a New Program removeAllPrograms.Action.text = Remove All Programs removeAllPrograms.Action.shortDescription =Remove All Programs -newProgramOutput.Action.text = New &Output... +newProgramOutput.Action.text = New Output... newProgramOutput.Action.shortDescription = Add an Output ##removeSelectedTable.Action.text = Remove Selected (table/variable) @@ -120,17 +120,17 @@ newProgramOutput.Action.shortDescription = Add an Output ## Actions menu -selectFunction.Action.text = &Function +selectFunction.Action.text = Function selectFunction.Action.shortDescription = Select a Function selectFunction.Action.icon = function.gif -subtractFunction.Action.text = &Subtract (A-B) +subtractFunction.Action.text = Subtract (A-B) subtractFunction.Action.shortDescription = Subtract -reverseSubtractFunction.Action.text = &Subtract (B-A) +reverseSubtractFunction.Action.text = Subtract (B-A) reverseSubtractFunction.Action.shortDescription = Subtract -cancelFunction.Action.text = &Cancel +cancelFunction.Action.text = Cancel cancelFunction.Action.shortDescription = Cancel diff --git a/trick_source/java/src/main/resources/trick/dre/resources/DreApplication.properties b/trick_source/java/src/main/resources/trick/dre/resources/DreApplication.properties index 55e493554..70081e2a1 100644 --- a/trick_source/java/src/main/resources/trick/dre/resources/DreApplication.properties +++ b/trick_source/java/src/main/resources/trick/dre/resources/DreApplication.properties @@ -6,14 +6,14 @@ Application.title = Dre mainFrame.title = Data Recording Editor # Menu Bar -optionsMenu.text = &Options +optionsMenu.text = Options # Menu items ## File menu -openDR.Action.text = &Open... +openDR.Action.text = Open... openDR.Action.shortDescription = Open a dre file -saveDR.Action.text = &Save... +saveDR.Action.text = Save... saveDR.Action.shortDescription = Save a dre file @@ -42,18 +42,18 @@ removeAll.Action.text = Remove All addVariables.Action.text = Add ## Options pane -#formatGroup.title = &Format +#formatGroup.title = Format #formatGroup.collapsed = true #formatGroup.scrollOnExpand = true -#freqGroup.title = &How Frequent +#freqGroup.title = How Frequent #freqGroup.collapsed = true #freqGroup.scrollOnExpand = true -#precisionGroup.title = &Single Precision +#precisionGroup.title = Single Precision #precisionGroup.collapsed = true #precisionGroup.scrollOnExpand = true -#bufferingGroup.title = &Buffering +#bufferingGroup.title = Buffering #bufferingGroup.collapsed = true #bufferingGroup.scrollOnExpand = true diff --git a/trick_source/java/src/main/resources/trick/simcontrol/resources/SimControlApplication.properties b/trick_source/java/src/main/resources/trick/simcontrol/resources/SimControlApplication.properties index 87c64763a..cc35fa397 100644 --- a/trick_source/java/src/main/resources/trick/simcontrol/resources/SimControlApplication.properties +++ b/trick_source/java/src/main/resources/trick/simcontrol/resources/SimControlApplication.properties @@ -10,30 +10,30 @@ mainFrame.title = Sim Control showStatusFont.Action.text = Font... showStatusFont.Action.shortDescription = Show Status Pane Font -saveStatusMsgs.Action.text = &Save Status Msgs... +saveStatusMsgs.Action.text = Save Status Msgs... saveStatusMsgs.Action.shortDescription = Save Status Messages -clearStatusMsgs.Action.text = &Clear Status Msgs... +clearStatusMsgs.Action.text = Clear Status Msgs... clearStatusMsgs.Action.shortDescription = Clear Status Messages -startTV.Action.text = Start Trick &View +startTV.Action.text = Start Trick View startTV.Action.shortDescription = Start Trick View (TV) startTV.Action.icon = tv_22x22.png -startMTV.Action.text = Start &Event/Malfunction Trick View +startMTV.Action.text = Start Event/Malfunction Trick View startMTV.Action.shortDescription = Start Event/Malfunction Trick View (MTV) startMTV.Action.icon = mtv_22x22.png -freezeAt.Action.text = Freeze &At... +freezeAt.Action.text = Freeze At... freezeAt.Action.shortDescription = Freeze At -freezeIn.Action.text = Freeze &In... +freezeIn.Action.text = Freeze In... freezeIn.Action.shortDescription = Freeze In -checkpointObjects.Action.text = Checkpoint &Objects... +checkpointObjects.Action.text = Checkpoint Objects... checkpointObjects.Action.shortDescription = Checkpoint the specified objects -throttle.Action.text = &Throttle... +throttle.Action.text = Throttle... throttle.Action.shortDescription = Throttle throttle.Action.icon = throttle_22x22.png @@ -70,4 +70,4 @@ lite.Action.text = Lite lite.Action.shortDescription = Lite/Full # Resource for menu -actionsMenu.text = &Actions +actionsMenu.text = Actions diff --git a/trick_source/java/src/main/resources/trick/sniffer/resources/SimSnifferApplication.properties b/trick_source/java/src/main/resources/trick/sniffer/resources/SimSnifferApplication.properties index d9e643e78..c9038de35 100644 --- a/trick_source/java/src/main/resources/trick/sniffer/resources/SimSnifferApplication.properties +++ b/trick_source/java/src/main/resources/trick/sniffer/resources/SimSnifferApplication.properties @@ -7,9 +7,9 @@ Application.icon = nose.gif mainFrame.title = Sim Sniffer # Resources for the @Actions defined in SimSnifferApplication -launchSimControlPanel.Action.text = Launch Sim &Control Panel +launchSimControlPanel.Action.text = Launch Sim Control Panel launchSimControlPanel.Action.shortDescription = Launch the Sim Control Panel and connect it to the selected simulation. -launchTrickView.Action.text = Launch Trick &View +launchTrickView.Action.text = Launch Trick View launchTrickView.Action.shortDescription = Launch Trick View and connect it to the selected simulation. From 952abe280ce8193c0effd767926c0651884e8837 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Wed, 5 Jun 2024 15:48:51 -0500 Subject: [PATCH 07/23] Removed ResourceMap dependency --- .../java/trick/common/TrickApplication.java | 35 +++-- .../java/trick/common/utils/TrickAction.java | 31 ++-- .../trick/common/utils/TrickResources.java | 136 ++++++++++++++++++ .../trickqp/utils/VarListPanel.java | 7 +- .../java/src/main/java/trick/mtv/MtvView.java | 34 ++++- 5 files changed, 208 insertions(+), 35 deletions(-) create mode 100644 trick_source/java/src/main/java/trick/common/utils/TrickResources.java diff --git a/trick_source/java/src/main/java/trick/common/TrickApplication.java b/trick_source/java/src/main/java/trick/common/TrickApplication.java index 4f512d8fd..d378fa0e6 100644 --- a/trick_source/java/src/main/java/trick/common/TrickApplication.java +++ b/trick_source/java/src/main/java/trick/common/TrickApplication.java @@ -18,6 +18,7 @@ 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; @@ -49,13 +50,13 @@ import javax.swing.UIManager; import javax.swing.border.EmptyBorder; -import org.jdesktop.application.ResourceMap; import org.jdesktop.application.SingleFrameApplication; import org.jdesktop.application.View; import org.jdesktop.application.session.PropertySupport; import trick.common.ui.UIUtils; import trick.common.utils.TrickAction; +import trick.common.utils.TrickResources; import trick.common.utils.SwingAction; /** @@ -74,10 +75,11 @@ public abstract class TrickApplication extends SingleFrameApplication implements //======================================== /** User settable properties, such as default directories, etc. */ public Properties trickProperties; - public Properties appProperties; + //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; @@ -105,14 +107,15 @@ public abstract class TrickApplication extends SingleFrameApplication implements /** The look and feel short name list */ protected static String[] lafShortNames; - protected final String SOURCE_PATH; - protected final String RESOURCE_PATH; + 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 { @@ -156,6 +159,7 @@ protected TrickApplication() { SOURCE_PATH = trick_home + "/trick_source/java/src/main/java"; RESOURCE_PATH = trick_home + "/trick_source/java/src/main/resources"; + the_trick_app = this; } //======================================== @@ -264,6 +268,10 @@ public static void setPopupInvoker(int type) { public static int getPopupInvoker() { return popupInvokerType; } + + public TrickResources getResourceMap() { return resourceMap; } + + public static TrickApplication getInstance() { return the_trick_app; } //======================================== // Methods @@ -335,7 +343,7 @@ protected void createActionMap() { for (Method man : appClass.getMethods()) { if (isSwingAction(man)) { String name = man.getName(); - Properties actProp = TrickAction.extractProperties(appProperties, name); + TrickResources actProp = TrickAction.extractProperties(resourceMap, name); actionMap.put(man.getName(), new TrickAction(actProp, this, man)); } } @@ -345,7 +353,7 @@ private boolean isSwingAction(Method man) { return man.getAnnotation(SwingAction.class) != null; } - public String getResourcePath(Class app) { + public static String getResourcePath(Class app) { String canon = app.getCanonicalName(); canon = "/" + canon.replace(".", "/") + ".properties"; @@ -359,21 +367,21 @@ public String getResourcePath(Class app) { } } - private Properties parseResources(Class app) throws IOException { - Properties prop; + private TrickResources parseResources(Class app) throws IOException, FileNotFoundException { + TrickResources prop; File resource; String path; if(app.getSimpleName().equals("TrickApplication")) { - prop = new Properties(); + prop = new TrickResources(); } else { Class superApp = app.getSuperclass(); - prop = new Properties(parseResources(superApp)); + prop = new TrickResources(parseResources(superApp)); } path = getResourcePath(app); resource = new File(path); - prop.load(new FileReader(resource)); + prop.loadProperties(resource); int filePos = path.lastIndexOf("/") + 1; path = path.substring(0, filePos); @@ -387,7 +395,7 @@ private Properties parseResources(Class app) throws protected void parseResources() { try { - appProperties = parseResources(this.getClass()); + resourceMap = parseResources(this.getClass()); } catch(IOException ioe) { System.err.println(ioe.getMessage()); } @@ -412,7 +420,6 @@ protected void initialize(String[] args) { parseResources(); createActionMap(); - resourceMap = getContext().getResourceMap(getClass()); // Load any saved user settable properties from properties file trickProperties = new Properties(); diff --git a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java index 097c0c63b..c33fac2ac 100644 --- a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java +++ b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java @@ -12,13 +12,13 @@ import trick.common.TrickApplication; public class TrickAction extends AbstractAction { - private Properties props; + private TrickResources props; private TrickApplication invoker; private Method man; - public TrickAction(Properties p, TrickApplication target, Method m) { - props = new Properties(p); + public TrickAction(TrickResources p, TrickApplication target, Method m) { + props = new TrickResources(p); invoker = target; man = m; applyProperties(); @@ -56,23 +56,24 @@ public String toString() { private void applyProperties() { String propValue; + ImageIcon iconValue; - putValue(Action.NAME, props.getProperty(TEXT_PROPERTY)); + putValue(Action.NAME, props.getString(TEXT_PROPERTY)); putValue(Action.SHORT_DESCRIPTION, - props.getProperty(SHORT_DESCRIPTION_PROPERTY)); + props.getString(SHORT_DESCRIPTION_PROPERTY)); putValue(Action.LONG_DESCRIPTION, - props.getProperty(LONG_DESCRIPTION_PROPERTY)); + props.getString(LONG_DESCRIPTION_PROPERTY)); - if((propValue = props.getProperty(ICON_PROPERTY)) != null) { - putValue(Action.SMALL_ICON, getIcon(propValue)); - putValue(Action.LARGE_ICON_KEY, getIcon(propValue)); + if((iconValue = props.getIcon(ICON_PROPERTY)) != null) { + putValue(Action.SMALL_ICON , iconValue); + putValue(Action.LARGE_ICON_KEY, iconValue); } else { - if((propValue = props.getProperty(SMALL_ICON_PROPERTY)) != null) { - putValue(Action.SMALL_ICON, getIcon(propValue)); + if((iconValue = props.getIcon(SMALL_ICON_PROPERTY)) != null) { + putValue(Action.SMALL_ICON, iconValue); } - if((propValue = props.getProperty(LARGE_ICON_PROPERTY)) != null) { - putValue(Action.LARGE_ICON_KEY, getIcon(propValue)); + if((iconValue = props.getIcon(LARGE_ICON_PROPERTY)) != null) { + putValue(Action.LARGE_ICON_KEY, iconValue); } } } @@ -105,7 +106,7 @@ private static String resolveFilePath(String PATH, String fileName) { return fileName; } - public static Properties extractProperties(Properties props, String name) { + public static TrickResources extractProperties(TrickResources props, String name) { String head = name + ".Action."; String textKey = head + TEXT_PROPERTY, iconKey = head + ICON_PROPERTY, @@ -117,7 +118,7 @@ public static Properties extractProperties(Properties props, String name) { String textVal, sDescVal, lDescVal, iconVal, sIconVal, lIconVal; - Properties actionProp = new Properties(); + TrickResources actionProp = new TrickResources(); if((textVal = props.getProperty(textKey)) != null) actionProp.setProperty(TEXT_PROPERTY, textVal); diff --git a/trick_source/java/src/main/java/trick/common/utils/TrickResources.java b/trick_source/java/src/main/java/trick/common/utils/TrickResources.java new file mode 100644 index 000000000..c9223bda6 --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/utils/TrickResources.java @@ -0,0 +1,136 @@ + +//======================================== +// Package +//======================================== +package trick.common.utils; + +import java.awt.Color; +import java.io.File; +import java.io.FileReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.swing.ImageIcon; + +public class TrickResources extends Properties { + public TrickResources() { + super(); + } + + public TrickResources(TrickResources tr) { + super(tr); + } + + public String getString(String key) { + return getResolvedProperty(key); + } + + public ImageIcon getIcon(String key) { + String iconPath = getString(key); + + return new ImageIcon(iconPath); + } + + public ImageIcon getImageIcon(String key) { + return getIcon(key); + } + + public int getInteger(String key) { + return Integer.parseInt(getString(key)); + } + + public Color getColor(String key) { + String colorStr = getString(key); + String[] rgba; + if(colorStr != null && (rgba = colorStr.split(", ")).length >= 3) { + return getColorFromRGBA(rgba); + } + + return null; + } + + private Color getColorFromRGBA(String[] code) { + if(code[0].indexOf(".") >= 0) { + float rgba[] = getRGBA_Float(code); + return new Color(rgba[0], rgba[1], rgba[2], rgba[3]); + } else { + int rgba[] = getRGBA_Integer(code); + return new Color(rgba[0], rgba[1], rgba[2], rgba[3]); + } + } + + private float[] getRGBA_Float(String[] code) { + float[] rgba = { 1.0f, 1.0f, 1.0f, 1.0f }; + rgba[0] = Float.parseFloat(code[0]); + rgba[1] = Float.parseFloat(code[1]); + rgba[2] = Float.parseFloat(code[2]); + + if(code.length == 4) { + rgba[3] = Float.parseFloat(code[3]); + } + + return rgba; + } + + private int[] getRGBA_Integer(String[] code) { + int[] rgba = { 255, 255, 255, 255 }; + rgba[0] = Integer.parseInt(code[0]); + rgba[1] = Integer.parseInt(code[1]); + rgba[2] = Integer.parseInt(code[2]); + + if(code.length == 4) { + rgba[3] = Integer.parseInt(code[3]); + } + + return rgba; + + } + + public void loadProperties(File resource) throws IOException, FileNotFoundException { + String icon, path = resource.getAbsolutePath(); + int lastSlash = path.lastIndexOf("/"); + path = path.substring(0, lastSlash + 1); + + load(new FileReader(resource)); + + for(String key : stringPropertyNames()) { + if(isIcon(key)) { + icon = getString(key); + if(icon.indexOf("/") < 0) { + icon = path + icon; + setProperty(key, icon); + } + } + } + } + + private boolean isIcon(String key) { + return key.endsWith(".icon") || + key.endsWith(".smallIcon") || + key.endsWith(".largeIcon"); + } + + private String getResolvedProperty(String key) { + String val = getProperty(key); + + if(val != null) { + Pattern pat = Pattern.compile("\\$\\{.*?\\}"); + Matcher match = pat.matcher(val); + + while(match.find()) { + String found = match.group(0); + found = found.substring(2, found.length() - 1); + + String replace = getResolvedProperty(found); + + val = match.replaceFirst(replace); + match = pat.matcher(val); + } + } + + return val; + } +} diff --git a/trick_source/java/src/main/java/trick/dataproducts/trickqp/utils/VarListPanel.java b/trick_source/java/src/main/java/trick/dataproducts/trickqp/utils/VarListPanel.java index 85d677269..d07baa404 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/trickqp/utils/VarListPanel.java +++ b/trick_source/java/src/main/java/trick/dataproducts/trickqp/utils/VarListPanel.java @@ -17,7 +17,6 @@ import javax.swing.JList; import javax.swing.ListCellRenderer; -import org.jdesktop.application.ResourceMap; import org.jdesktop.swingx.JXList; import trick.common.TrickApplication; @@ -25,6 +24,7 @@ import trick.common.utils.LogVar; import trick.common.utils.LogVar.DisplayType; import trick.common.utils.SortedListModel; +import trick.common.utils.TrickResources; /** @@ -169,7 +169,10 @@ public Component getListCellRendererComponent(JList list, Object value, if (varObj.getCount() < runcnt.getCount()) { fg = red; } - ResourceMap resourceMap = TrickApplication.getInstance().getContext().getResourceMap(TrickApplication.class); + + TrickApplication app = TrickApplication.getInstance(); + TrickResources resourceMap = app.getResourceMap(); + if (varObj.getDisplay()==DisplayType.HIDDEN) { // Hide these using a blank filler component: // 1st line of varlist is the RUN dir count (it's name is "@@@"); and contracted array components diff --git a/trick_source/java/src/main/java/trick/mtv/MtvView.java b/trick_source/java/src/main/java/trick/mtv/MtvView.java index c9dda3d65..e02615ae2 100644 --- a/trick_source/java/src/main/java/trick/mtv/MtvView.java +++ b/trick_source/java/src/main/java/trick/mtv/MtvView.java @@ -51,11 +51,11 @@ import org.jdesktop.application.Application.ExitListener; import org.jdesktop.application.FrameView; -import org.jdesktop.application.ResourceMap; import org.jdesktop.application.TaskMonitor; import trick.common.TrickApplication; import trick.common.utils.SwingAction; +import trick.common.utils.TrickResources; /** * The application's main frame. @@ -74,13 +74,19 @@ public void windowClosing(WindowEvent e) { MtvApp.getApplication().exit(); } }); + + try { + resourceMap = parseResources(app.resourceMap); + } catch(IOException ioe) { + resourceMap = new TrickResources(); + System.err.println(ioe.getMessage()); + } initComponents(); edit_new_event(); // status bar initialization - message timeout, idle icon and busy animation, etc - ResourceMap resourceMap = getResourceMap(); int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout"); messageTimer = new Timer(messageTimeout, new ActionListener() { @Override @@ -138,6 +144,26 @@ public void propertyChange(java.beans.PropertyChangeEvent evt) { }); } // end MtvView constructor + + private TrickResources parseResources(TrickResources base) throws IOException, FileNotFoundException { + TrickResources prop = new TrickResources(base); + File resource; + String path; + + path = TrickApplication.getResourcePath(this.getClass()); + System.out.println("PATH: " + path); + resource = new File(path); + prop.loadProperties(resource); + + int filePos = path.lastIndexOf("/") + 1; + path = path.substring(0, filePos); + if(prop.getProperty("PATH") != null) + path += ";" + prop.getProperty("PATH"); + + prop.setProperty("PATH", path); + + return prop; + } // ================================== General Functions ======================================= @@ -1225,7 +1251,6 @@ private void initComponents() { menuBar.setName("menuBar"); // NOI18N - org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(MtvView.class); fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N fileMenu.setName("fileMenu"); // NOI18N @@ -2001,7 +2026,8 @@ public enum Mode { NORMAL, MANUALON, MANUALOFF } public boolean active[]; // is this row (event/condition/action) Active/Enabled public Mode mode[]; // is this row (event/condition/action) mode Normal, or Manual On/Off public boolean canEditRow[]; // whole row is not editable when user does not specify event name - public boolean canEdit[][]; // if canEditRow, is this particular cell editable (Active/Enable/Hold/Mode) + public boolean canEdit[][]; // if canEditRow, is this particular cell editable (Active/Enable/Hold/Mode) + public TrickResources resourceMap; private final Timer messageTimer; private final Timer busyIconTimer; From 48e52312cfc3df6ab4f31771af0ea3d87a858f2e Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Mon, 17 Jun 2024 14:04:56 -0500 Subject: [PATCH 08/23] Added a skeleton for the new framework --- .../trick/common/framework/AppContext.java | 32 ++++ .../common/framework/BaseApplication.java | 152 ++++++++++++++++++ .../common/framework/PropertySupport.java | 12 ++ .../java/trick/common/framework/Session.java | 19 +++ .../java/trick/common/framework/Task.java | 27 ++++ .../trick/common/framework/TaskMonitor.java | 19 +++ .../trick/common/framework/TaskService.java | 12 ++ .../java/trick/common/framework/View.java | 42 +++++ 8 files changed, 315 insertions(+) create mode 100644 trick_source/java/src/main/java/trick/common/framework/AppContext.java create mode 100644 trick_source/java/src/main/java/trick/common/framework/BaseApplication.java create mode 100644 trick_source/java/src/main/java/trick/common/framework/PropertySupport.java create mode 100644 trick_source/java/src/main/java/trick/common/framework/Session.java create mode 100644 trick_source/java/src/main/java/trick/common/framework/Task.java create mode 100644 trick_source/java/src/main/java/trick/common/framework/TaskMonitor.java create mode 100644 trick_source/java/src/main/java/trick/common/framework/TaskService.java create mode 100644 trick_source/java/src/main/java/trick/common/framework/View.java diff --git a/trick_source/java/src/main/java/trick/common/framework/AppContext.java b/trick_source/java/src/main/java/trick/common/framework/AppContext.java new file mode 100644 index 000000000..d0eac36a1 --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/AppContext.java @@ -0,0 +1,32 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework; + +import javax.swing.ActionMap; + +import trick.common.framework.Session; +import trick.common.framework.TaskService; + +public class AppContext { + public Class getApplicationClass() { + return null; + } + + public ActionMap getActionMap(Class c, Object o) { + return null; + } + + public Session getSessionStorage() { + return null; + } + + public Session getLocalStorage() { + return null; + } + + public TaskService getTaskService() { + return null; + } +} diff --git a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java new file mode 100644 index 000000000..66b56fe8e --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java @@ -0,0 +1,152 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework; + +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.lang.reflect.Constructor; +import java.util.EventObject; +import java.util.List; + +import javax.swing.JDialog; +import javax.swing.JFrame; + +import trick.common.framework.AppContext; +import trick.common.framework.View; + +public abstract class BaseApplication { + + //======================================== + // Attributes + //======================================== + + // -- PUBLIC ----------------------------- + + // -- PRIVATE ---------------------------- + private final AppContext context; + // -- PROTECTED -------------------------- + + //======================================== + // Constructors + //======================================== + protected BaseApplication() { + context = new AppContext(); + } + + //======================================== + // Public Methods + //======================================== + + public static void launch(Class c, String[] args) { + + } + + // public static BaseApplication getInstance() { + // return null; + // } + + public static T getInstance(Class appClass) { + return null; + } + + public void show() { + + } + + public void show(JDialog d) { + + } + + public void show(View v) { + + } + + public void exit() { exit(null); } + + public void exit(ActionEvent event) { + + } + + public void addExitListener(ExitListener e) { + + } + + public void removeExitListener(ExitListener e) { + + } + + //======================================== + // Protected Methods + //======================================== + + protected void configureWindow(Window root) { + + } + + //======================================== + // Private Methods + //======================================== + + private static create(Class appClass) { + T app = createInstanceOf(appClass); + AppContext ctx = app.getContext(); + } + + //======================================== + // Helper Methods + //======================================== + + private static createInstanceOf(Class cls) { + Constructor clsCtor = cls.getDeclaredConstructor(); + + if(!canAccess(clsCtor)) { + try { clsCtor.setAccessible(true); } + catch (SecurityException UNUSED) { } + } + + return clsCtor.newInstance(); + } + + //======================================== + // Getters/Setters + //======================================== + + public JFrame getMainFrame() { + return null; + } + + public View getMainView() { + return null; + } + + public AppContext getContext() { + return null; + } + + public ExitListener[] getExitListeners() { + return null; + } + + //======================================== + // Undefined Methods + //======================================== + + protected abstract void initialize(String[] args); + + protected abstract void startup(); + + protected void ready() {} + + protected void shutdown() {} + + //======================================== + // Inner Classes + //======================================== + + public abstract class ExitListener { + public abstract boolean canExit(EventObject e); + public abstract void willExit(EventObject e); + } +} diff --git a/trick_source/java/src/main/java/trick/common/framework/PropertySupport.java b/trick_source/java/src/main/java/trick/common/framework/PropertySupport.java new file mode 100644 index 000000000..c8e9f7851 --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/PropertySupport.java @@ -0,0 +1,12 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework; + +import java.awt.Component; + +public interface PropertySupport { + public abstract Object getSessionState(Component c); + public abstract void setSessionState(Component c, Object state); +} diff --git a/trick_source/java/src/main/java/trick/common/framework/Session.java b/trick_source/java/src/main/java/trick/common/framework/Session.java new file mode 100644 index 000000000..46fa5338d --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/Session.java @@ -0,0 +1,19 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework; + +import java.io.File; + +import trick.common.framework.PropertySupport; + +public class Session { + public void setDirectory(File f) { + + } + + public void putProperty(Class c, PropertySupport p) { + + } +} diff --git a/trick_source/java/src/main/java/trick/common/framework/Task.java b/trick_source/java/src/main/java/trick/common/framework/Task.java new file mode 100644 index 000000000..b1f64288d --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/Task.java @@ -0,0 +1,27 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework; + +import javax.swing.SwingWorker; + +import trick.common.framework.BaseApplication; + +public abstract class Task extends SwingWorker { + + public Task(BaseApplication app) { + + } + + // protected abstract Void doInBackground(); + protected abstract void finished(); + protected void succeeded(Void ignored) { + + } + + protected final void setProgress(float percentage) { + + } + +} diff --git a/trick_source/java/src/main/java/trick/common/framework/TaskMonitor.java b/trick_source/java/src/main/java/trick/common/framework/TaskMonitor.java new file mode 100644 index 000000000..3a075c477 --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/TaskMonitor.java @@ -0,0 +1,19 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework; + +import java.beans.PropertyChangeListener; + +import trick.common.framework.AppContext; + +public class TaskMonitor { + public TaskMonitor(AppContext context) { + + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + + } +} diff --git a/trick_source/java/src/main/java/trick/common/framework/TaskService.java b/trick_source/java/src/main/java/trick/common/framework/TaskService.java new file mode 100644 index 000000000..e5e902d9d --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/TaskService.java @@ -0,0 +1,12 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework; + +public class TaskService { + public void execute(Task t) { + + } + +} diff --git a/trick_source/java/src/main/java/trick/common/framework/View.java b/trick_source/java/src/main/java/trick/common/framework/View.java new file mode 100644 index 000000000..d96c85f11 --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/View.java @@ -0,0 +1,42 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework; + +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JMenuBar; +import javax.swing.JToolBar; + +import trick.common.framework.BaseApplication; + +public class View { + public View(BaseApplication app) { + + } + + public void setComponent(JComponent c) { + + } + + public void setMenuBar(JMenuBar m) { + + } + + public void setToolBar(JToolBar t) { + + } + + public void setStatusBar(JComponent c) { + + } + + public JFrame getFrame() { + return null; + } + + public BaseApplication getApplication() { + return null; + } +} From 9150a4f49f71358db75af5bc07efc7319f7f9b3a Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Mon, 17 Jun 2024 14:05:21 -0500 Subject: [PATCH 09/23] Replaced BSAF connections with new framework --- .../java/trick/common/TrickApplication.java | 19 ++++++++++++------- .../dataproducts/DataProductsApplication.java | 2 +- .../dataproducts/plot/JXPlotApplication.java | 5 +++-- .../trickdp/TrickDPApplication.java | 3 ++- .../trickqp/TrickQPApplication.java | 3 ++- .../main/java/trick/dre/DreApplication.java | 5 +++-- .../montemonitor/MonteMonitorApplication.java | 5 +++-- .../java/src/main/java/trick/mtv/MtvApp.java | 9 +++++---- .../java/src/main/java/trick/mtv/MtvView.java | 12 ++++++------ .../main/java/trick/sie/SieApplication.java | 5 +++-- .../simcontrol/SimControlApplication.java | 11 ++++++----- .../trick/sniffer/SimSnifferApplication.java | 5 +++-- .../src/main/java/trick/tv/TVApplication.java | 5 +++-- 13 files changed, 52 insertions(+), 37 deletions(-) diff --git a/trick_source/java/src/main/java/trick/common/TrickApplication.java b/trick_source/java/src/main/java/trick/common/TrickApplication.java index d378fa0e6..325c74964 100644 --- a/trick_source/java/src/main/java/trick/common/TrickApplication.java +++ b/trick_source/java/src/main/java/trick/common/TrickApplication.java @@ -10,6 +10,7 @@ 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; @@ -50,10 +51,9 @@ import javax.swing.UIManager; import javax.swing.border.EmptyBorder; -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; @@ -68,7 +68,7 @@ * @author Hong Chen * @since Trick 10 */ -public abstract class TrickApplication extends SingleFrameApplication implements PropertySupport { +public abstract class TrickApplication extends BaseApplication implements PropertySupport { //======================================== // Public data @@ -254,10 +254,15 @@ public void lookAndFeel() { } @SwingAction - public void quit() { - super.exit(null); + public void quit(ActionEvent e) { + super.exit(e); } + @SwingAction + public void quit() { + quit(null); + } + //======================================== // Set/Get methods //======================================== diff --git a/trick_source/java/src/main/java/trick/dataproducts/DataProductsApplication.java b/trick_source/java/src/main/java/trick/dataproducts/DataProductsApplication.java index 1b30549bf..fb114e1d8 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/DataProductsApplication.java +++ b/trick_source/java/src/main/java/trick/dataproducts/DataProductsApplication.java @@ -30,10 +30,10 @@ import javax.swing.JToggleButton; import javax.swing.SwingWorker; -import org.jdesktop.application.View; import org.jdesktop.swingx.JXMultiSplitPane; import org.jdesktop.swingx.MultiSplitLayout; +import trick.common.framework.View; import trick.common.TrickApplication; import trick.common.ui.UIUtils; import trick.common.ui.components.NumberTextField; diff --git a/trick_source/java/src/main/java/trick/dataproducts/plot/JXPlotApplication.java b/trick_source/java/src/main/java/trick/dataproducts/plot/JXPlotApplication.java index 1fef95d67..8a974ce36 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/plot/JXPlotApplication.java +++ b/trick_source/java/src/main/java/trick/dataproducts/plot/JXPlotApplication.java @@ -28,7 +28,6 @@ import javax.xml.parsers.ParserConfigurationException; import org.jdesktop.application.Application; -import org.jdesktop.application.View; import org.jdesktop.swingx.JXMultiSplitPane; import org.jdesktop.swingx.JXTree; import org.jdesktop.swingx.MultiSplitLayout; @@ -48,6 +47,8 @@ import org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory; import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; +import trick.common.framework.BaseApplication; +import trick.common.framework.View; import trick.common.TrickApplication; import trick.common.ui.UIUtils; import trick.common.utils.SwingAction; @@ -152,7 +153,7 @@ public void saveAllToPDF() { * @param args command line arguments */ public static void main(String[] args) { - Application.launch(JXPlotApplication.class, args); + BaseApplication.launch(JXPlotApplication.class, args); } /** diff --git a/trick_source/java/src/main/java/trick/dataproducts/trickdp/TrickDPApplication.java b/trick_source/java/src/main/java/trick/dataproducts/trickdp/TrickDPApplication.java index c06d24096..68747415b 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/trickdp/TrickDPApplication.java +++ b/trick_source/java/src/main/java/trick/dataproducts/trickdp/TrickDPApplication.java @@ -39,6 +39,7 @@ import org.jdesktop.application.Application; +import trick.common.framework.BaseApplication; import trick.common.TrickApplication; import trick.common.ui.TrickFileFilter; import trick.common.ui.UIUtils; @@ -408,7 +409,7 @@ public void selectFileDevice() { * @param args command line arguments */ public static void main(String[] args) { - Application.launch(TrickDPApplication.class, args); + BaseApplication.launch(TrickDPApplication.class, args); } /** diff --git a/trick_source/java/src/main/java/trick/dataproducts/trickqp/TrickQPApplication.java b/trick_source/java/src/main/java/trick/dataproducts/trickqp/TrickQPApplication.java index 8ff46c199..81de62dbd 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/trickqp/TrickQPApplication.java +++ b/trick_source/java/src/main/java/trick/dataproducts/trickqp/TrickQPApplication.java @@ -40,6 +40,7 @@ import org.jdesktop.application.Application; +import trick.common.framework.BaseApplication; import trick.common.ui.UIUtils; import trick.common.ui.components.CommonTreeNode; import trick.common.ui.panels.DataPanel; @@ -578,7 +579,7 @@ protected void ready() { * @throws MalformedURLException MalformedURLException */ public static void main(String[] args) throws RemoteException, MalformedURLException { - Application.launch(TrickQPApplication.class, args); + BaseApplication.launch(TrickQPApplication.class, args); // save the arguments which will be used for launching the application if (args != null && args.length > 0) { diff --git a/trick_source/java/src/main/java/trick/dre/DreApplication.java b/trick_source/java/src/main/java/trick/dre/DreApplication.java index b090a8465..d2ce8c29e 100644 --- a/trick_source/java/src/main/java/trick/dre/DreApplication.java +++ b/trick_source/java/src/main/java/trick/dre/DreApplication.java @@ -9,7 +9,6 @@ //======================================== import org.jdesktop.application.Application; -import org.jdesktop.application.View; import org.jdesktop.swingx.JXLabel; import org.jdesktop.swingx.JXButton; import org.jdesktop.swingx.JXPanel; @@ -17,6 +16,8 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import trick.common.framework.BaseApplication; +import trick.common.framework.View; import trick.common.ui.UIUtils; import trick.common.ui.components.NumberTextField; import trick.common.ui.panels.ListPanel; @@ -311,7 +312,7 @@ public void addVariables() { * @param args command line arguments */ public static void main(String[] args) { - Application.launch(DreApplication.class, args); + BaseApplication.launch(DreApplication.class, args); } /** diff --git a/trick_source/java/src/main/java/trick/montemonitor/MonteMonitorApplication.java b/trick_source/java/src/main/java/trick/montemonitor/MonteMonitorApplication.java index c58b4865c..e0d832542 100644 --- a/trick_source/java/src/main/java/trick/montemonitor/MonteMonitorApplication.java +++ b/trick_source/java/src/main/java/trick/montemonitor/MonteMonitorApplication.java @@ -31,7 +31,6 @@ import javax.swing.table.DefaultTableModel; import org.jdesktop.application.Application; -import org.jdesktop.application.View; import org.jdesktop.swingx.JXButton; import org.jdesktop.swingx.JXPanel; import org.jdesktop.swingx.JXTable; @@ -41,6 +40,8 @@ import org.jdesktop.swingx.renderer.DefaultTableRenderer; import org.jdesktop.swingx.renderer.LabelProvider; +import trick.common.framework.BaseApplication; +import trick.common.framework.View; import trick.common.RunTimeTrickApplication; /** @@ -473,7 +474,7 @@ protected JMenuBar createMenuBar() { * @param args command line arguments */ public static void main(String[] args) { - Application.launch(MonteMonitorApplication.class, args); + BaseApplication.launch(MonteMonitorApplication.class, args); } /** monitors incoming messages from the Variable Server and updates the display table with new information */ diff --git a/trick_source/java/src/main/java/trick/mtv/MtvApp.java b/trick_source/java/src/main/java/trick/mtv/MtvApp.java index d51d5231f..23d72c976 100644 --- a/trick_source/java/src/main/java/trick/mtv/MtvApp.java +++ b/trick_source/java/src/main/java/trick/mtv/MtvApp.java @@ -20,8 +20,9 @@ import javax.swing.event.TableModelEvent; import org.jdesktop.application.Application; -import org.jdesktop.application.Task; +import trick.common.framework.BaseApplication; +import trick.common.framework.Task; import trick.common.TrickApplication; import trick.common.utils.VariableServerConnection; import trick.mtv.MtvView.Mode; @@ -317,7 +318,7 @@ public void add_my_exit_listener() { // the super's exit dialog always pops up in middle of screen, so add our own exit listener // remove any current exit listener first removeExitListener(exitListener) ; - exitListener = new Application.ExitListener() { + exitListener = new BaseApplication.ExitListener() { public boolean canExit(EventObject e) { return JOptionPane.showConfirmDialog(mtv_view.viewPanel, "Do you really want to exit?", "Confirm Exit", 0) == 0; @@ -581,7 +582,7 @@ protected void shutdown() { * @return the instance of MtvApp */ public static MtvApp getApplication() { - return Application.getInstance(MtvApp.class); + return BaseApplication.getInstance(MtvApp.class); } // MonitorEventsTask ======================================================= @@ -595,7 +596,7 @@ private class MonitorEventsTask extends Task { * * @param app The specified {@link Application} that needs Sim status monitoring. */ - public MonitorEventsTask(Application app) { + public MonitorEventsTask(BaseApplication app) { super(app); } diff --git a/trick_source/java/src/main/java/trick/mtv/MtvView.java b/trick_source/java/src/main/java/trick/mtv/MtvView.java index e02615ae2..bad28dd8b 100644 --- a/trick_source/java/src/main/java/trick/mtv/MtvView.java +++ b/trick_source/java/src/main/java/trick/mtv/MtvView.java @@ -49,10 +49,10 @@ import javax.swing.event.TableModelListener; import javax.swing.table.DefaultTableCellRenderer; -import org.jdesktop.application.Application.ExitListener; -import org.jdesktop.application.FrameView; -import org.jdesktop.application.TaskMonitor; - +import trick.common.framework.BaseApplication.ExitListener; +import trick.common.framework.BaseApplication; +import trick.common.framework.TaskMonitor; +import trick.common.framework.View; import trick.common.TrickApplication; import trick.common.utils.SwingAction; import trick.common.utils.TrickResources; @@ -60,7 +60,7 @@ /** * The application's main frame. */ -public class MtvView extends FrameView { +public class MtvView extends View { public MtvView(TrickApplication app) { super(app); @@ -1254,7 +1254,7 @@ private void initComponents() { fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N fileMenu.setName("fileMenu"); // NOI18N - javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(MtvView.class, this); + javax.swing.ActionMap actionMap = BaseApplication.getInstance().getContext().getActionMap(MtvView.class, this); loadMenuItem.setAction(actionMap.get("load_event")); // NOI18N loadMenuItem.setIcon(resourceMap.getIcon("loadMenuItem.icon")); // NOI18N loadMenuItem.setText(resourceMap.getString("loadMenuItem.text")); // NOI18N diff --git a/trick_source/java/src/main/java/trick/sie/SieApplication.java b/trick_source/java/src/main/java/trick/sie/SieApplication.java index 99e551132..6cc1fd30a 100644 --- a/trick_source/java/src/main/java/trick/sie/SieApplication.java +++ b/trick_source/java/src/main/java/trick/sie/SieApplication.java @@ -52,11 +52,12 @@ import javax.xml.parsers.ParserConfigurationException; import org.jdesktop.application.Application; -import org.jdesktop.application.View; import org.jdesktop.swingx.JXEditorPane; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import trick.common.framework.BaseApplication; +import trick.common.framework.View; import trick.common.TrickApplication; import trick.common.ui.UIUtils; import trick.common.ui.panels.FindBar; @@ -297,7 +298,7 @@ public static void main(String[] args) { if (args.length == 1) { printMatchVarOnScreen(args[0]); } else { - Application.launch(SieApplication.class, args); + BaseApplication.launch(SieApplication.class, args); } } diff --git a/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java b/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java index e373676e2..bcdaf1e05 100644 --- a/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java +++ b/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java @@ -71,8 +71,6 @@ import javax.swing.text.StyledEditorKit; import org.jdesktop.application.Application; -import org.jdesktop.application.Task; -import org.jdesktop.application.View; import org.jdesktop.swingx.JXEditorPane; import org.jdesktop.swingx.JXLabel; import org.jdesktop.swingx.JXPanel; @@ -80,6 +78,9 @@ import org.jdesktop.swingx.JXTitledPanel; import org.jdesktop.swingx.JXTitledSeparator; +import trick.common.framework.BaseApplication; +import trick.common.framework.Task; +import trick.common.framework.View; import trick.common.TrickApplication; import trick.common.ui.UIUtils; import trick.common.ui.components.FontChooser; @@ -703,7 +704,7 @@ protected void printErrorMessage(String err) { * @param args command line arguments */ public static void main(String[] args) { - Application.launch(SimControlApplication.class, args); + BaseApplication.launch(SimControlApplication.class, args); // Arrays.toString(args) converts such as localhost 7000 -r to [localhost, 7000, -r], // so need to remove [, ] and all white spaces. @@ -1467,7 +1468,7 @@ private void setColorStyleAttr(Style st, Color foreground, Color background) { * Inner class for the task of monitoring health status. */ private class MonitorHealthStatusTask extends Task { - public MonitorHealthStatusTask(Application app) { + public MonitorHealthStatusTask(BaseApplication app) { super(app); } @@ -1633,7 +1634,7 @@ private class MonitorSimStatusTask extends Task { * * @param app The specified {@link Application} that needs Sim status monitoring. */ - public MonitorSimStatusTask(Application app) { + public MonitorSimStatusTask(BaseApplication app) { super(app); } diff --git a/trick_source/java/src/main/java/trick/sniffer/SimSnifferApplication.java b/trick_source/java/src/main/java/trick/sniffer/SimSnifferApplication.java index abde93125..735d078cb 100644 --- a/trick_source/java/src/main/java/trick/sniffer/SimSnifferApplication.java +++ b/trick_source/java/src/main/java/trick/sniffer/SimSnifferApplication.java @@ -20,12 +20,13 @@ import javax.swing.table.DefaultTableModel; import org.jdesktop.application.Application; -import org.jdesktop.application.View; import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.decorator.EnabledHighlighter; import org.jdesktop.swingx.decorator.HighlighterFactory; import org.jdesktop.swingx.decorator.PatternPredicate; +import trick.common.framework.BaseApplication; +import trick.common.framework.View; import trick.common.TrickApplication; /** @@ -324,7 +325,7 @@ protected JMenuBar createMenuBar() { * @param args command line arguments */ public static void main(String[] args) { - Application.launch(SimSnifferApplication.class, args); + BaseApplication.launch(SimSnifferApplication.class, args); } } diff --git a/trick_source/java/src/main/java/trick/tv/TVApplication.java b/trick_source/java/src/main/java/trick/tv/TVApplication.java index 388dd860e..dcaf5c0d4 100644 --- a/trick_source/java/src/main/java/trick/tv/TVApplication.java +++ b/trick_source/java/src/main/java/trick/tv/TVApplication.java @@ -82,7 +82,6 @@ import joptsimple.OptionSpec; import org.jdesktop.application.Application; -import org.jdesktop.application.View; import org.jdesktop.swingx.JXButton; import org.jdesktop.swingx.JXFrame; import org.jdesktop.swingx.JXLabel; @@ -90,6 +89,8 @@ import org.jdesktop.swingx.JXTextField; import org.xml.sax.InputSource; +import trick.common.framework.BaseApplication; +import trick.common.framework.View; import trick.common.RunTimeTrickApplication; import trick.common.TrickApplication; import trick.common.utils.UnitType; @@ -2303,7 +2304,7 @@ public InvalidVariableNameException(String description) { * @param args arguments */ public static void main(String[] args) { - Application.launch(TVApplication.class, args); + BaseApplication.launch(TVApplication.class, args); } } From 9ebf9e5cdd09031fa79af4736f7093091b672f8d Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Tue, 18 Jun 2024 17:02:32 -0500 Subject: [PATCH 10/23] Started implementing BaseApplication --- .../trick/common/framework/AppContext.java | 6 + .../common/framework/BaseApplication.java | 271 ++++++++++++++++-- .../java/trick/common/framework/Session.java | 5 + .../java/trick/common/framework/View.java | 4 + 4 files changed, 261 insertions(+), 25 deletions(-) diff --git a/trick_source/java/src/main/java/trick/common/framework/AppContext.java b/trick_source/java/src/main/java/trick/common/framework/AppContext.java index d0eac36a1..3da6fe8f6 100644 --- a/trick_source/java/src/main/java/trick/common/framework/AppContext.java +++ b/trick_source/java/src/main/java/trick/common/framework/AppContext.java @@ -4,6 +4,8 @@ //======================================== package trick.common.framework; +import java.awt.Component; + import javax.swing.ActionMap; import trick.common.framework.Session; @@ -29,4 +31,8 @@ public Session getLocalStorage() { public TaskService getTaskService() { return null; } + + public void addComponent(Component c) { + + } } diff --git a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java index 66b56fe8e..a5f71dd5a 100644 --- a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java +++ b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java @@ -4,14 +4,35 @@ //======================================== package trick.common.framework; -import java.awt.Window; import java.awt.event.ActionEvent; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.HierarchyEvent; +import java.awt.event.HierarchyListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.Component; +import java.awt.Container; +import java.awt.Frame; +import java.awt.Window; + +import java.beans.Beans; + +import java.lang.IllegalAccessException; +import java.lang.InstantiationException; +import java.lang.NoSuchMethodException; import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +import java.util.concurrent.CopyOnWriteArrayList; import java.util.EventObject; import java.util.List; +import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFrame; +import javax.swing.JRootPane; +import javax.swing.RootPaneContainer; import trick.common.framework.AppContext; import trick.common.framework.View; @@ -25,13 +46,25 @@ public abstract class BaseApplication { // -- PUBLIC ----------------------------- // -- PRIVATE ---------------------------- + private View mainView; + private List exitListeners; + private final AppContext context; + private final SetUpCloseOperations MAIN_FRAME_SETUP = (Component c) -> initMainFrameClose(); + private final SetUpCloseOperations WINDOW_SETUP = (Component c) -> initWindowClose(c); + + private static BaseApplication application = null; + + private static final String INITIALIZATION_MARKER="BaseApplication.initRootPaneContainer"; + private static final String WINDOW_STATE_NORMAL_BOUNDS = "WindowState.normalBounds"; + // -- PROTECTED -------------------------- //======================================== // Constructors //======================================== protected BaseApplication() { + exitListeners = new CopyOnWriteArrayList(); context = new AppContext(); } @@ -43,20 +76,15 @@ public static void launch(Class c, String[] args) { } - // public static BaseApplication getInstance() { - // return null; - // } - - public static T getInstance(Class appClass) { - return null; - } - public void show() { } public void show(JDialog d) { - + if(d != null) { + initRootPaneContainer(d); + d.setVisible(true); + } } public void show(View v) { @@ -65,16 +93,20 @@ public void show(View v) { public void exit() { exit(null); } - public void exit(ActionEvent event) { + public void exit(final EventObject event) { } - public void addExitListener(ExitListener e) { + public void addExitListener(ExitListener listener) { + exitListeners.add(listener); + } + public void removeExitListener(ExitListener listener) { + exitListeners.remove(listener); } - public void removeExitListener(ExitListener e) { - + public void saveSession(Window win) { + } //======================================== @@ -82,26 +114,61 @@ public void removeExitListener(ExitListener e) { //======================================== protected void configureWindow(Window root) { - + if (root != null) + context.addComponent(root); } //======================================== // Private Methods //======================================== - private static create(Class appClass) { - T app = createInstanceOf(appClass); - AppContext ctx = app.getContext(); + private static T create(Class appClass) { + T app; + // AppContext ctx; + + // Create an instance of + try { + app = createInstanceOf(appClass); + } catch (Exception e) { + System.err.println(e.getMessage()); + return null; + } + + // ctx = app.getContext(); + + // TODO: Set up Look and Feel + + return app; + } + + private void initRootPaneContainer(RootPaneContainer c) { + SetUpCloseOperations closeOps = WINDOW_SETUP; + if(c == getMainFrame()) closeOps = MAIN_FRAME_SETUP; + + Component root = c.getRootPane().getParent(); + + try { initializeOnce(c); } + catch(IllegalArgumentException ignored) { return; } + + configureWindow(safe_cast(root, Window.class)); + closeOps.setupClose(root); + handleContainerBounds(root); + reloadContainerState(root); + centerWindow(root); + } //======================================== // Helper Methods //======================================== - private static createInstanceOf(Class cls) { + private static T createInstanceOf(Class cls) throws NoSuchMethodException, + InstantiationException, + IllegalAccessException, + InvocationTargetException { Constructor clsCtor = cls.getDeclaredConstructor(); - if(!canAccess(clsCtor)) { + if(!clsCtor.canAccess(null)) { try { clsCtor.setAccessible(true); } catch (SecurityException UNUSED) { } } @@ -109,24 +176,161 @@ private static createInstanceOf(Class cls) { return clsCtor.newInstance(); } + private String getSessionFileName(Window w) { + return null; + } + + private static boolean appIsLaunched() { return application != null; } + + private void initializeOnce(RootPaneContainer c) { + JComponent rootPane = c.getRootPane(); + Object prop = rootPane.getClientProperty(INITIALIZATION_MARKER); + + if (prop != null) + throw new IllegalArgumentException("Container already initialized."); + + rootPane.putClientProperty(rootPane, Boolean.TRUE); + } + + private T safe_cast(Object o, Class c) { + try { return c.cast(o); } + catch (ClassCastException e) { return null; } + } + + private void initMainFrameClose() { + JFrame mf = getMainFrame(); + + mf.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + exit(e); + } + }); + + mf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + } + + private void initWindowClose(Component c) { + Window window = safe_cast(c, Window.class); + window.addHierarchyListener(new HierarchyListener() { + @Override + public void hierarchyChanged(HierarchyEvent event) { + boolean showing_changed = (event.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0; + if (showing_changed) { + Window secondaryWindow = safe_cast(event.getSource(), Window.class); + if(secondaryWindow != null && !secondaryWindow.isShowing()) { + saveSession(secondaryWindow); + } + } + } + }); + } + + private void handleContainerBounds(Component comp) { + Window wind = safe_cast(comp, Window.class); + + if(safe_cast(comp, JFrame.class) != null) { + handleJFrameBounds(comp); + } + + if (wind != null) { + boolean bounds_not_set = !comp.isValid() + || comp.getWidth() == 0 + || comp.getHeight() == 0; + String filename = getSessionFileName(wind); + + if (bounds_not_set) wind.pack(); + + try { + if(filename != null) { + context.getSessionStorage().restore(comp, filename); + } + } catch (Exception e) { + // TODO: handle exception + } + } + } + + private void handleJFrameBounds(Component comp) { + comp.addComponentListener(new ComponentListener() { + @Override + public void componentResized(ComponentEvent e) { + JFrame frame = safe_cast(e.getComponent(), JFrame.class); + boolean both_not_maxxed = (frame.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0; + if (both_not_maxxed) { + JRootPane rootPane = frame.getRootPane(); + rootPane.putClientProperty(WINDOW_STATE_NORMAL_BOUNDS, frame.getBounds()); + } + } + + @Override + public void componentMoved(ComponentEvent e) {} + + @Override + public void componentHidden(ComponentEvent e) {} + + @Override + public void componentShown(ComponentEvent e) {} + }); + } + + private void reloadContainerState(Component c) { + + } + + private void centerWindow(Component c) { + + } + //======================================== // Getters/Setters //======================================== + public static BaseApplication getInstance() throws IllegalStateException { + return getInstance(GenericApplication.class); + } + + public static T getInstance(Class appClass) throws IllegalStateException { + if (Beans.isDesignTime() && application == null) { + application = create(appClass); + } + + if (appIsLaunched()) { + return appClass.cast(application); + } else { + throw new IllegalStateException("Application did not launch..."); + } + } + public JFrame getMainFrame() { - return null; + if(mainView != null) + return mainView.getFrame(); + else + return null; + } + + public void setMainFrame(JFrame nFrame) { + if(mainView != null) + mainView.setFrame(nFrame); } public View getMainView() { - return null; + return mainView; } - public AppContext getContext() { - return null; + public void setMainView(View nView) { + mainView = nView; + } + + public final AppContext getContext() { + return context; } public ExitListener[] getExitListeners() { - return null; + int size = exitListeners.size(); + ExitListener[] el_array = exitListeners.toArray(new ExitListener[size]); + + return el_array; } //======================================== @@ -149,4 +353,21 @@ public abstract class ExitListener { public abstract boolean canExit(EventObject e); public abstract void willExit(EventObject e); } + + private class GenericApplication extends BaseApplication { + public GenericApplication() { + super(); + } + + @Override + protected void initialize(String[] args) { /* UNUSED */ } + + @Override + protected void startup() { /* UNUSED */ } + + } + + private interface SetUpCloseOperations { + public void setupClose(Component c); + } } diff --git a/trick_source/java/src/main/java/trick/common/framework/Session.java b/trick_source/java/src/main/java/trick/common/framework/Session.java index 46fa5338d..47f677d40 100644 --- a/trick_source/java/src/main/java/trick/common/framework/Session.java +++ b/trick_source/java/src/main/java/trick/common/framework/Session.java @@ -4,6 +4,7 @@ //======================================== package trick.common.framework; +import java.awt.Component; import java.io.File; import trick.common.framework.PropertySupport; @@ -16,4 +17,8 @@ public void setDirectory(File f) { public void putProperty(Class c, PropertySupport p) { } + + public void restore(Component c, String filename) { + + } } diff --git a/trick_source/java/src/main/java/trick/common/framework/View.java b/trick_source/java/src/main/java/trick/common/framework/View.java index d96c85f11..88310fc2e 100644 --- a/trick_source/java/src/main/java/trick/common/framework/View.java +++ b/trick_source/java/src/main/java/trick/common/framework/View.java @@ -36,6 +36,10 @@ public JFrame getFrame() { return null; } + public void setFrame(JFrame f) { + + } + public BaseApplication getApplication() { return null; } From 31a938ed57e9fc4dd6b20b274575e947f2046d93 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Wed, 19 Jun 2024 13:17:31 -0500 Subject: [PATCH 11/23] Further BaseApplication implementation --- .../common/framework/BaseApplication.java | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java index a5f71dd5a..d9574a296 100644 --- a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java +++ b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java @@ -126,6 +126,17 @@ private static T create(Class appClass) { T app; // AppContext ctx; + // TODO: Set up System property + /* if (!Beans.isDesignTime()) { + + try { + System.setProperty("java.net.useSystemProxies", "true"); + } catch (SecurityException ignoreException) { + // Unsigned apps can't set this property. + } + } + */ + // Create an instance of try { app = createInstanceOf(appClass); @@ -135,8 +146,47 @@ private static T create(Class appClass) { } // ctx = app.getContext(); + + // TODO: Add platform info to resource map + /* ResourceMap appResourceMap = ctx.getResourceMap(); + final PlatformType platform = AppHelper.getPlatform(); + appResourceMap.putResource(ResourceMap.KEY_PLATFORM, platform); + + //Generic registration with the Mac OS X application menu + if (PlatformType.OS_X.equals(platform)) { + try { + OSXAdapter.setQuitHandler(application, Application.class.getDeclaredMethod("handleQuit", (Class[])null)); + } catch (Exception e) { + logger.log(Level.SEVERE, "Cannot set Mac Os X specific handler for Quit event", e); + } + } + */ // TODO: Set up Look and Feel + /* if (!Beans.isDesignTime()) { + String key = "Application.lookAndFeel"; + String lnfResource = appResourceMap.getString(key); + String lnf = (lnfResource == null) ? "system" : lnfResource; + try { + if (lnf.equalsIgnoreCase("system")) { + String name = UIManager.getSystemLookAndFeelClassName(); + UIManager.setLookAndFeel(name); + } else if (lnf.equalsIgnoreCase("nimbus")) { + for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } else if (!lnf.equalsIgnoreCase("default")) { + UIManager.setLookAndFeel(lnf); + } + } catch (Exception e) { + String s = "Couldn't set LookandFeel " + key + " = \"" + lnfResource + "\""; + logger.log(Level.WARNING, s, e); + } + } + */ return app; } @@ -177,7 +227,9 @@ private static T createInstanceOf(Class cls) throws NoSuchMethodExceptio } private String getSessionFileName(Window w) { - return null; + if(w == null) return null; + + return window.getName() + ".session.xml"; } private static boolean appIsLaunched() { return application != null; } From 9f8ee484e91cf34b77be732240ccc1d56e6b8227 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Mon, 1 Jul 2024 07:49:01 -0500 Subject: [PATCH 12/23] Basic SimControlPanel Implementation --- .../java/trick/common/TrickApplication.java | 45 +-- .../trick/common/framework/AppContext.java | 63 +++- .../common/framework/BaseApplication.java | 338 ++++++++++++++---- .../java/trick/common/framework/Session.java | 5 + .../trick/common/framework/SwingToolbox.java | 46 +++ .../java/trick/common/framework/Task.java | 213 ++++++++++- .../trick/common/framework/TaskEvent.java | 20 ++ .../trick/common/framework/TaskListener.java | 23 ++ .../trick/common/framework/TaskService.java | 48 ++- .../java/trick/common/framework/View.java | 114 +++++- .../trickqp/utils/VarListPanel.java | 2 +- .../simcontrol/SimControlApplication.java | 6 + 12 files changed, 811 insertions(+), 112 deletions(-) create mode 100644 trick_source/java/src/main/java/trick/common/framework/SwingToolbox.java create mode 100644 trick_source/java/src/main/java/trick/common/framework/TaskEvent.java create mode 100644 trick_source/java/src/main/java/trick/common/framework/TaskListener.java diff --git a/trick_source/java/src/main/java/trick/common/TrickApplication.java b/trick_source/java/src/main/java/trick/common/TrickApplication.java index 325c74964..e2bf5f6a3 100644 --- a/trick_source/java/src/main/java/trick/common/TrickApplication.java +++ b/trick_source/java/src/main/java/trick/common/TrickApplication.java @@ -147,13 +147,13 @@ public abstract class TrickApplication extends BaseApplication implements Proper } 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.isEmpty()) { + if (trick_home == null || trick_home.isEmpty()) { trick_home = System.getProperty("user.home") + java.io.File.separator + "trick"; } @@ -274,8 +274,6 @@ public static int getPopupInvoker() { return popupInvokerType; } - public TrickResources getResourceMap() { return resourceMap; } - public static TrickApplication getInstance() { return the_trick_app; } //======================================== @@ -371,40 +369,6 @@ public static String getResourcePath(Class app) { return ""; } } - - private TrickResources parseResources(Class app) throws IOException, FileNotFoundException { - TrickResources prop; - File resource; - String path; - - if(app.getSimpleName().equals("TrickApplication")) { - prop = new TrickResources(); - } else { - Class superApp = app.getSuperclass(); - prop = new TrickResources(parseResources(superApp)); - } - - path = getResourcePath(app); - resource = new File(path); - prop.loadProperties(resource); - - int filePos = path.lastIndexOf("/") + 1; - path = path.substring(0, filePos); - if(prop.getProperty("PATH") != null) - path += ";" + prop.getProperty("PATH"); - - prop.setProperty("PATH", path); - - return prop; - } - - protected void parseResources() { - try { - resourceMap = parseResources(this.getClass()); - } catch(IOException ioe) { - System.err.println(ioe.getMessage()); - } - } /** @@ -414,6 +378,7 @@ protected void parseResources() { */ @Override protected void initialize(String[] args) { + System.out.println("INITIALIZE"); // the name of this application applicationName = getContext().getApplicationClass().getSimpleName(); @@ -423,7 +388,7 @@ protected void initialize(String[] args) { // register property for JToggleButton class so that its state can be saved getContext().getSessionStorage().putProperty(JToggleButton.class, this); - parseResources(); + resourceMap = getContext().getResourceMap(); createActionMap(); // Load any saved user settable properties from properties file @@ -461,6 +426,8 @@ public void willExit(EventObject e) {} */ @Override protected void startup() { + System.out.println("STARTUP"); + String defaultValue = Boolean.toString(false); boolean savedExitProperty = Boolean.valueOf(trickProperties.getProperty( "confirmExit", defaultValue)); diff --git a/trick_source/java/src/main/java/trick/common/framework/AppContext.java b/trick_source/java/src/main/java/trick/common/framework/AppContext.java index 3da6fe8f6..f3c891dac 100644 --- a/trick_source/java/src/main/java/trick/common/framework/AppContext.java +++ b/trick_source/java/src/main/java/trick/common/framework/AppContext.java @@ -5,27 +5,50 @@ package trick.common.framework; import java.awt.Component; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; import javax.swing.ActionMap; +import trick.common.TrickApplication; +import trick.common.framework.BaseApplication; import trick.common.framework.Session; import trick.common.framework.TaskService; +import trick.common.utils.TrickResources; public class AppContext { + + private final Class appClass; + private TrickResources resources = null; + private Session session; + + public AppContext(Class appClass) { + this.appClass = appClass; + session = new Session(); + } + public Class getApplicationClass() { - return null; + return appClass; } public ActionMap getActionMap(Class c, Object o) { return null; } + public TrickResources getResourceMap() { + if (resources == null) + parseResources(); + + return resources; + } + public Session getSessionStorage() { - return null; + return session; } public Session getLocalStorage() { - return null; + return session; } public TaskService getTaskService() { @@ -35,4 +58,38 @@ public TaskService getTaskService() { public void addComponent(Component c) { } + + private TrickResources parseResources(Class app) throws IOException, FileNotFoundException { + TrickResources prop; + File resource; + String path; + + if(app.getSimpleName().equals("TrickApplication")) { + prop = new TrickResources(); + } else { + Class superApp = app.getSuperclass(); + prop = new TrickResources(parseResources(superApp)); + } + + path = TrickApplication.getResourcePath(app); + resource = new File(path); + prop.loadProperties(resource); + + int filePos = path.lastIndexOf("/") + 1; + path = path.substring(0, filePos); + if(prop.getProperty("PATH") != null) + path += ";" + prop.getProperty("PATH"); + + prop.setProperty("PATH", path); + + return prop; + } + + private void parseResources() { + try { + resources = parseResources(appClass); + } catch(IOException ioe) { + System.err.println(ioe.getMessage()); + } + } } diff --git a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java index d9574a296..baa15f669 100644 --- a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java +++ b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java @@ -9,32 +9,48 @@ import java.awt.event.ComponentListener; import java.awt.event.HierarchyEvent; import java.awt.event.HierarchyListener; +import java.awt.event.PaintEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.awt.ActiveEvent; import java.awt.Component; import java.awt.Container; +import java.awt.Dimension; +import java.awt.EventQueue; import java.awt.Frame; +import java.awt.Point; +import java.awt.Toolkit; import java.awt.Window; import java.beans.Beans; - +import java.beans.PropertyChangeSupport; +import java.io.IOException; import java.lang.IllegalAccessException; import java.lang.InstantiationException; import java.lang.NoSuchMethodException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; - +import java.security.InvalidParameterException; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.EventObject; import java.util.List; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFrame; +import javax.swing.JPanel; import javax.swing.JRootPane; import javax.swing.RootPaneContainer; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.UIManager.LookAndFeelInfo; +import javax.swing.event.SwingPropertyChangeSupport; import trick.common.framework.AppContext; +import trick.common.framework.SwingToolbox; +import trick.common.framework.Task; import trick.common.framework.View; public abstract class BaseApplication { @@ -50,22 +66,26 @@ public abstract class BaseApplication { private List exitListeners; private final AppContext context; - private final SetUpCloseOperations MAIN_FRAME_SETUP = (Component c) -> initMainFrameClose(); - private final SetUpCloseOperations WINDOW_SETUP = (Component c) -> initWindowClose(c); + private final SetUpCloseOperations MAIN_FRAME_SETUP = (Container c) -> initMainFrameClose(); + private final SetUpCloseOperations WINDOW_SETUP = (Container c) -> initWindowClose(c); private static BaseApplication application = null; + private static final Logger logger = Logger.getLogger(BaseApplication.class.getName()); private static final String INITIALIZATION_MARKER="BaseApplication.initRootPaneContainer"; private static final String WINDOW_STATE_NORMAL_BOUNDS = "WindowState.normalBounds"; // -- PROTECTED -------------------------- + protected boolean ready; + protected PropertyChangeSupport changeSupport; //======================================== // Constructors //======================================== protected BaseApplication() { exitListeners = new CopyOnWriteArrayList(); - context = new AppContext(); + context = new AppContext(getClass()); + changeSupport = new SwingPropertyChangeSupport(this, true); } //======================================== @@ -73,11 +93,8 @@ protected BaseApplication() { //======================================== public static void launch(Class c, String[] args) { - - } - - public void show() { - + Runnable doCreateAndShowGUI = new GUIDisplayRunner(c, args); + SwingUtilities.invokeLater(doCreateAndShowGUI); } public void show(JDialog d) { @@ -88,13 +105,22 @@ public void show(JDialog d) { } public void show(View v) { - + Component comp = v.getRootPane().getParent(); + initRootPaneContainer((RootPaneContainer) comp); + ((Window) comp).setVisible(true); } public void exit() { exit(null); } public void exit(final EventObject event) { + Runnable exitHandler = new ExitHandler(event); + if (SwingUtilities.isEventDispatchThread()) { + exitHandler.run(); + } else { + try { SwingUtilities.invokeAndWait(exitHandler); } + catch (Exception ignore) {} + } } public void addExitListener(ExitListener listener) { @@ -106,6 +132,17 @@ public void removeExitListener(ExitListener listener) { } public void saveSession(Window win) { + String filename = SwingToolbox.getSessionFileName(win); + Session storage = context.getLocalStorage(); + + if(filename == null) throw new InvalidParameterException("Null Window"); + + try { + storage.save(win, filename); + } catch (IOException e) { + String msg = "couldnt save session to '" + filename + "'"; + logger.log(Level.WARNING, msg, e); + } } @@ -114,8 +151,11 @@ public void saveSession(Window win) { //======================================== protected void configureWindow(Window root) { - if (root != null) - context.addComponent(root); + context.addComponent(root); + } + + protected void end() { + Runtime.getRuntime().exit(0); } //======================================== @@ -123,7 +163,6 @@ protected void configureWindow(Window root) { //======================================== private static T create(Class appClass) { - T app; // AppContext ctx; // TODO: Set up System property @@ -138,22 +177,25 @@ private static T create(Class appClass) { */ // Create an instance of + T app; + try { app = createInstanceOf(appClass); } catch (Exception e) { System.err.println(e.getMessage()); return null; } - - // ctx = app.getContext(); + + AppContext ctx = app.getContext(); // TODO: Add platform info to resource map /* ResourceMap appResourceMap = ctx.getResourceMap(); final PlatformType platform = AppHelper.getPlatform(); appResourceMap.putResource(ResourceMap.KEY_PLATFORM, platform); + */ - //Generic registration with the Mac OS X application menu - if (PlatformType.OS_X.equals(platform)) { + //TODO: Generic registration with the Mac OS X application menu + /* if (PlatformType.OS_X.equals(platform)) { try { OSXAdapter.setQuitHandler(application, Application.class.getDeclaredMethod("handleQuit", (Class[])null)); } catch (Exception e) { @@ -162,31 +204,36 @@ private static T create(Class appClass) { } */ - // TODO: Set up Look and Feel - /* if (!Beans.isDesignTime()) { - String key = "Application.lookAndFeel"; - String lnfResource = appResourceMap.getString(key); - String lnf = (lnfResource == null) ? "system" : lnfResource; - try { - if (lnf.equalsIgnoreCase("system")) { - String name = UIManager.getSystemLookAndFeelClassName(); - UIManager.setLookAndFeel(name); - } else if (lnf.equalsIgnoreCase("nimbus")) { - for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { - if ("Nimbus".equals(info.getName())) { - UIManager.setLookAndFeel(info.getClassName()); - break; - } + // Set up Look and Feel + String lnfKey = "Application.lookAndFeel", + lnfVal, lnfName; + + if (!Beans.isDesignTime()) { + lnfVal = ctx.getResourceMap().getString(lnfKey); + lnfVal = (lnfVal == null) ? "system" : lnfVal; + lnfName = lnfVal; + + try { + if (lnfVal.equalsIgnoreCase("system")) { + lnfName = UIManager.getSystemLookAndFeelClassName(); + } else if (lnfVal.equalsIgnoreCase("nimbus")) { + for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + lnfName = info.getClassName(); + break; } - } else if (!lnf.equalsIgnoreCase("default")) { - UIManager.setLookAndFeel(lnf); } - } catch (Exception e) { - String s = "Couldn't set LookandFeel " + key + " = \"" + lnfResource + "\""; - logger.log(Level.WARNING, s, e); } + + if (!lnfVal.equalsIgnoreCase("default")) + UIManager.setLookAndFeel(lnfName); + + } catch (Exception e) { + String s = "Couldn't set LookandFeel " + lnfKey + " = \"" + lnfVal + "\""; + logger.log(Level.WARNING, s, e); } - */ + } + return app; } @@ -195,16 +242,21 @@ private void initRootPaneContainer(RootPaneContainer c) { SetUpCloseOperations closeOps = WINDOW_SETUP; if(c == getMainFrame()) closeOps = MAIN_FRAME_SETUP; - Component root = c.getRootPane().getParent(); + Container root = c.getRootPane().getParent(); + Window window = safe_cast(root, Window.class); try { initializeOnce(c); } catch(IllegalArgumentException ignored) { return; } - configureWindow(safe_cast(root, Window.class)); closeOps.setupClose(root); handleContainerBounds(root); - reloadContainerState(root); - centerWindow(root); + + if (window != null) { + configureWindow(window); + reloadContainerState(window); + centerWindow(window); + } + } @@ -226,12 +278,6 @@ private static T createInstanceOf(Class cls) throws NoSuchMethodExceptio return clsCtor.newInstance(); } - private String getSessionFileName(Window w) { - if(w == null) return null; - - return window.getName() + ".session.xml"; - } - private static boolean appIsLaunched() { return application != null; } private void initializeOnce(RootPaneContainer c) { @@ -278,7 +324,7 @@ public void hierarchyChanged(HierarchyEvent event) { }); } - private void handleContainerBounds(Component comp) { + private void handleContainerBounds(Container comp) { Window wind = safe_cast(comp, Window.class); if(safe_cast(comp, JFrame.class) != null) { @@ -289,7 +335,7 @@ private void handleContainerBounds(Component comp) { boolean bounds_not_set = !comp.isValid() || comp.getWidth() == 0 || comp.getHeight() == 0; - String filename = getSessionFileName(wind); + String filename = SwingToolbox.getSessionFileName(wind); if (bounds_not_set) wind.pack(); @@ -303,7 +349,7 @@ private void handleContainerBounds(Component comp) { } } - private void handleJFrameBounds(Component comp) { + private void handleJFrameBounds(Container comp) { comp.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent e) { @@ -326,12 +372,44 @@ public void componentShown(ComponentEvent e) {} }); } - private void reloadContainerState(Component c) { - + private void reloadContainerState(Window w) { + String filename; + + if((filename = SwingToolbox.getSessionFileName(w)) != null) { + try { + Session session = context.getSessionStorage(); + session.restore(w, filename); + } catch (Exception e) { + String msg = "Failed to restore session [%s]"; + logger.log(Level.WARNING, String.format(msg, filename), e); + } + } } - private void centerWindow(Component c) { + private void centerWindow(Window w) { + Point defLoc = SwingToolbox.defaultLocation(w), + actLoc = w.getLocation(); + + if (!w.isLocationByPlatform() && actLoc.equals(defLoc)) { + Dimension screenDim = w.getToolkit().getScreenSize(), + windowDim = w.getSize(); + double widthRatio = screenDim.getWidth() / windowDim.getWidth(), + heightRatio = screenDim.getHeight() / windowDim.getHeight(); + + if(widthRatio > 1.25 && heightRatio > 1.25) { + Component owner = w.getOwner(); + + if (owner == null && getMainFrame() != w) { + owner = getMainFrame(); + } + + w.setLocationRelativeTo(owner); + } + } + } + private void waitForReady() { + new WaitTillFree().execute(); } //======================================== @@ -367,6 +445,9 @@ public void setMainFrame(JFrame nFrame) { } public View getMainView() { + if (mainView == null) { + mainView = new View(this); + } return mainView; } @@ -389,14 +470,12 @@ public ExitListener[] getExitListeners() { // Undefined Methods //======================================== - protected abstract void initialize(String[] args); - - protected abstract void startup(); - + protected void initialize(String[] args) {} protected void ready() {} - protected void shutdown() {} + protected abstract void startup(); + //======================================== // Inner Classes //======================================== @@ -420,6 +499,143 @@ protected void startup() { /* UNUSED */ } } private interface SetUpCloseOperations { - public void setupClose(Component c); + public void setupClose(Container c); + } + + private static class GUIDisplayRunner implements Runnable { + private final Class appClass; + private final String[] args; + + public GUIDisplayRunner(Class c, String[] args) { + this.appClass = c; + this.args = args; + } + + @Override + public void run() { + try { + application = create(appClass); + application.initialize(args); + application.startup(); + application.waitForReady(); + } catch (Exception e) { + String msg = appClass.getName() + " failed to launch"; + logger.log(Level.SEVERE, msg, e); + throw new Error(msg, e); + } + } + } + + private class ExitHandler implements Runnable { + private final EventObject event; + + public ExitHandler(EventObject ev) { + event = ev; + } + + @Override + public void run() { + if(allowedToExit()) { + try { + exitAll(); + shutdown(); + } catch (Exception e) { + logger.log(Level.WARNING, "Unexpected shutdown error", e); + } finally { + end(); + } + } + } + + private boolean allowedToExit() { + for (ExitListener exitListener : exitListeners) + if (!exitListener.canExit(event)) + return false; + + return true; + } + + private void exitAll() { + for (ExitListener exitListener : exitListeners) { + try { + exitListener.willExit(event); + } catch (Exception e) { + logger.log(Level.WARNING, "ExitListener.willExit() failed", e); + } + } + } + } + + private void waitForEmptyQueue(JPanel panel) { + EventQueue Q = Toolkit.getDefaultToolkit().getSystemEventQueue(); + boolean emptyQ = false; + + while(!emptyQ) { + System.out.println("Waiting..."); + QueueEvent e = new QueueEvent(panel); + + Q.postEvent(e); + + synchronized(e) { + System.out.println("\tSynched"); + while(!e.isDispatched()) { + try { e.wait(); } + catch (InterruptedException ignored) {} + } + System.out.println("\tDispatched"); + + emptyQ = e.isQueueEmpty(); + } + } + + System.out.println("Queue Empty!"); + } + + private class WaitTillFree extends Task { + // private boolean emptyQ = false; + private final JPanel panel; + + WaitTillFree() { + super(BaseApplication.this); + + panel = new JPanel(); + } + + @Override + protected Void doInBackground() { + waitForEmptyQueue(panel); + return null; + } + + @Override + protected void finished() { + ready = true; + ready(); + } + + + } + + private class QueueEvent extends PaintEvent implements ActiveEvent { + + private boolean dispatched = false; + private boolean empty = false; + + QueueEvent(Component c) { + super(c, PaintEvent.UPDATE, null); + } + + @Override + public void dispatch() { + EventQueue Q = Toolkit.getDefaultToolkit().getSystemEventQueue(); + synchronized(this) { + empty = Q.peekEvent() == null; + dispatched = true; + notifyAll(); + } + } + + synchronized boolean isDispatched() { return dispatched; } + synchronized boolean isQueueEmpty() { return empty; } } } diff --git a/trick_source/java/src/main/java/trick/common/framework/Session.java b/trick_source/java/src/main/java/trick/common/framework/Session.java index 47f677d40..809223ba0 100644 --- a/trick_source/java/src/main/java/trick/common/framework/Session.java +++ b/trick_source/java/src/main/java/trick/common/framework/Session.java @@ -6,6 +6,7 @@ import java.awt.Component; import java.io.File; +import java.io.IOException; import trick.common.framework.PropertySupport; @@ -18,6 +19,10 @@ public void putProperty(Class c, PropertySupport p) { } + public void save(Component c, String filename) throws IOException { + + } + public void restore(Component c, String filename) { } diff --git a/trick_source/java/src/main/java/trick/common/framework/SwingToolbox.java b/trick_source/java/src/main/java/trick/common/framework/SwingToolbox.java new file mode 100644 index 000000000..59f639f9e --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/SwingToolbox.java @@ -0,0 +1,46 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework; + +import java.awt.Component; +import java.awt.GraphicsConfiguration; +import java.awt.Insets; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Window; + +import javax.swing.JPopupMenu; +import javax.swing.RootPaneContainer; + +public final class SwingToolbox { + + public static Point defaultLocation(Window window) { + GraphicsConfiguration gc = window.getGraphicsConfiguration(); + Rectangle bounds = gc.getBounds(); + Insets insets = window.getToolkit().getScreenInsets(gc); + int x = bounds.x + insets.left; + int y = bounds.y + insets.top; + return new Point(x, y); + } + + public static RootPaneContainer findRootPaneContainer(Component root) { + while (root != null) { + if (root instanceof RootPaneContainer) { + return (RootPaneContainer) root; + } else if (root instanceof JPopupMenu && root.getParent() == null) { + root = ((JPopupMenu) root).getInvoker(); + } else { + root = root.getParent(); + } + } + return null; + } + + public static String getSessionFileName(Window w) { + if(w == null) return null; + + return w.getName() + ".session.xml"; + } +} diff --git a/trick_source/java/src/main/java/trick/common/framework/Task.java b/trick_source/java/src/main/java/trick/common/framework/Task.java index b1f64288d..35db76926 100644 --- a/trick_source/java/src/main/java/trick/common/framework/Task.java +++ b/trick_source/java/src/main/java/trick/common/framework/Task.java @@ -4,24 +4,231 @@ //======================================== package trick.common.framework; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.security.InvalidParameterException; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.ExecutionException; + +import javax.swing.SwingUtilities; import javax.swing.SwingWorker; +import trick.common.framework.TaskEvent; +import trick.common.framework.TaskListener; import trick.common.framework.BaseApplication; +import trick.common.utils.TrickResources; public abstract class Task extends SwingWorker { + public static final String PROP_DESCRIPTION = "description"; + public static final String PROP_INPUTBLOCKER = "inputBlocker"; + public static final String PROP_MESSAGE = "message"; + public static final String PROP_TASKSERVICE = "taskService"; + public static final String PROP_TITLE = "title"; + public static final String PROP_USERCANCANCEL = "userCanCancel"; + public static final String PROP_COMPLETED = "completed"; + public static final String PROP_DONE = "done"; + public static final String PROP_STARTED = "started"; + + private static final Logger logger = Logger.getLogger(Task.class.getName()); + + private final BaseApplication application; + private final TrickResources resourceMap; + + private List> taskListeners; + private long messageTime, taskStart, taskDone; + private String title, description, message; + private boolean progressProperty; + + public Task(BaseApplication app) { + this.application = app; + this.resourceMap = application.getContext().getResourceMap(); + taskListeners = new CopyOnWriteArrayList>(); + initTask(); } // protected abstract Void doInBackground(); protected abstract void finished(); - protected void succeeded(Void ignored) { - - } + protected void cancelled() {} + protected void succeeded(T result) {} + protected void interrupted(InterruptedException e) {} + + protected void failed(Throwable cause) { + String msg = String.format("%s failed: %s", this, cause); + logger.log(Level.SEVERE, msg, cause); + } protected final void setProgress(float percentage) { + if (percentage < 0.0f || percentage > 1.0f) { + String msg = String.format("'%f' is not a valid percentage", percentage); + throw new InvalidParameterException(msg); + } + + setProgress(Math.round(percentage * 100.0f)); + + } + + // TODO: Re-Write This + private void initTask() { + if (resourceMap != null) { + title = resourceMap.getString(PROP_TITLE); + description = resourceMap.getString(PROP_DESCRIPTION); + message = resourceMap.getString(PROP_MESSAGE); + if (message != null) { + messageTime = System.currentTimeMillis(); + } + } + addPropertyChangeListener(new StatePCL()); + // taskListeners = new CopyOnWriteArrayList>(); + } + + // TODO: Rewrite this + private void fireDoInBackgroundListeners() { + TaskEvent event = new TaskEvent(this, null); + for (TaskListener listener : taskListeners) { + listener.doInBackground(event); + } + } + + // TODO: Rewrite this + private void fireSucceededListeners(T result) { + TaskEvent event = new TaskEvent(this, result); + for (TaskListener listener : taskListeners) { + listener.succeeded(event); + } + } + + // TODO: Rewrite this + private void fireCancelledListeners() { + TaskEvent event = new TaskEvent(this, null); + for (TaskListener listener : taskListeners) { + listener.cancelled(event); + } + } + + // TODO: Rewrite this + private void fireInterruptedListeners(InterruptedException e) { + TaskEvent event = new TaskEvent(this, e); + for (TaskListener listener : taskListeners) { + listener.interrupted(event); + } + } + + // TODO: Rewrite this + private void fireFailedListeners(Throwable e) { + TaskEvent event = new TaskEvent(this, e); + for (TaskListener listener : taskListeners) { + listener.failed(event); + } + } + + // TODO: Rewrite this + private void fireFinishedListeners() { + TaskEvent event = new TaskEvent(this, null); + for (TaskListener listener : taskListeners) { + listener.finished(event); + } + } + + // TODO: Rewrite this + private void fireCompletionListeners() { + try { + if (isCancelled()) { + fireCancelledListeners(); + } else { + try { + fireSucceededListeners(get()); + } catch (InterruptedException e) { + fireInterruptedListeners(e); + } catch (ExecutionException e) { + fireFailedListeners(e.getCause()); + } + } + } finally { + fireFinishedListeners(); + } + } + + private class StatePCL implements PropertyChangeListener { + @Override + public void propertyChange(PropertyChangeEvent e) { + if(eventIs(e, "state")) { + StateValue state = (StateValue) e.getNewValue(); + + switch (state) { + case STARTED: taskBegun(); break; + case DONE: taskEnded(); break; + default: break; + } + } else if(eventIs(e, "progress")) { + synchronized (Task.this) { + progressProperty = true; + } + } + } + + private boolean eventIs(PropertyChangeEvent event, String name) { + return name.equals(event.getPropertyName()); + } + + private void taskBegun() { + synchronized (Task.this) { + taskStart = System.currentTimeMillis(); + } + firePropertyChange(PROP_STARTED, false, true); + fireDoInBackgroundListeners(); + } + + private void taskEnded() { + synchronized (Task.this) { + taskDone = System.currentTimeMillis(); + } + + try { + removePropertyChangeListener(this); + firePropertyChange(PROP_DONE, false, true); + } finally { + SwingUtilities.invokeLater(new TaskCleanup()); + } + } + } + + // TODO: Re-Write this too + private class TaskCleanup implements Runnable { + @Override + public void run () { + try { + handleEndState(); + } finally { + handleFinish(); + } + } + + private void handleEndState() { + if(isCancelled()) { + cancelled(); + } else try { + succeeded(get()); + } catch (InterruptedException e) { + interrupted(e); + } catch (ExecutionException e) { + failed(e.getCause()); + } + } + private void handleFinish() { + finished(); + try { + fireCompletionListeners(); + } finally { + firePropertyChange(PROP_COMPLETED, false, true); + } + } } } diff --git a/trick_source/java/src/main/java/trick/common/framework/TaskEvent.java b/trick_source/java/src/main/java/trick/common/framework/TaskEvent.java new file mode 100644 index 000000000..346cd5c72 --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/TaskEvent.java @@ -0,0 +1,20 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework; + +import java.util.EventObject; + +public class TaskEvent extends EventObject { + private final T value; + + public final T getValue() { + return value; + } + + public TaskEvent(Task src, T val) { + super(src); + value = val; + } +} diff --git a/trick_source/java/src/main/java/trick/common/framework/TaskListener.java b/trick_source/java/src/main/java/trick/common/framework/TaskListener.java new file mode 100644 index 000000000..e6af5f634 --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/TaskListener.java @@ -0,0 +1,23 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework; + +import trick.common.framework.TaskEvent; + +public interface TaskListener { + + public void doInBackground(TaskEvent event); + + public void finished(TaskEvent event); + + public void cancelled(TaskEvent event); + + public void interrupted(TaskEvent event); + + public void succeeded(TaskEvent event); + + public void failed(TaskEvent event); + +} diff --git a/trick_source/java/src/main/java/trick/common/framework/TaskService.java b/trick_source/java/src/main/java/trick/common/framework/TaskService.java index e5e902d9d..d35d2a202 100644 --- a/trick_source/java/src/main/java/trick/common/framework/TaskService.java +++ b/trick_source/java/src/main/java/trick/common/framework/TaskService.java @@ -4,8 +4,54 @@ //======================================== package trick.common.framework; -public class TaskService { +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import trick.common.framework.Task; + +public class TaskService extends ThreadPoolExecutor { + private String name; + + public TaskService(String name) { + super(3,10,1L, TimeUnit.SECONDS, new LinkedBlockingQueue()); + + this.name = name; + + } + public void execute(Task t) { + /** + * // Input Validation + * if (task == null) { + * throw new IllegalArgumentException("null task"); + * } + * if (!task.isPending() || (task.getTaskService() != null)) { + * throw new IllegalArgumentException("task has already been executed"); + * } + * + * // Setup for task execution + * task.setTaskService(this); + * // TBD: what if task has already been submitted? + * task.addPropertyChangeListener(taskPCL); + * + * // Add Task to Queue + * List> oldTaskList, newTaskList; + * synchronized (tasks) { + * oldTaskList = tasks.getList(); + * tasks.addLast(task); + * newTaskList = tasks.getList(); + * } + * firePropertyChange(new TaskPropertyChangeEvent(oldTaskList, newTaskList, null, task)); + * + * maybeBlockTask(task); + * executorService.execute(task); + */ + } + + public final String getName() { return name; } + + private void maybeBlockTask(Task task) { } diff --git a/trick_source/java/src/main/java/trick/common/framework/View.java b/trick_source/java/src/main/java/trick/common/framework/View.java index 88310fc2e..4dd0a2fab 100644 --- a/trick_source/java/src/main/java/trick/common/framework/View.java +++ b/trick_source/java/src/main/java/trick/common/framework/View.java @@ -4,43 +4,149 @@ //======================================== package trick.common.framework; +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Image; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JMenuBar; +import javax.swing.JPanel; +import javax.swing.JRootPane; import javax.swing.JToolBar; +import javax.swing.border.Border; import trick.common.framework.BaseApplication; +import trick.common.utils.TrickResources; public class View { - public View(BaseApplication app) { + private BaseApplication app; + + private JRootPane rootPane; + private JFrame frame; + private JComponent component, statusBar, toolBarPanel; + private JMenuBar menuBar; + private List toolBars = Collections.emptyList(); + + + public View(BaseApplication app) { + this.app = app; } public void setComponent(JComponent c) { + JComponent old = component; + component = c; + + replaceComponent(old, component, BorderLayout.CENTER); + // TODO: Fire Property Change } public void setMenuBar(JMenuBar m) { + // JMenuBar old = menuBar; + menuBar = m; + + getRootPane().setJMenuBar(m); + // TODO: Fire Property Change + } + + public JToolBar getToolBar() { + return (toolBars.size() == 0) ? null : toolBars.get(0); } public void setToolBar(JToolBar t) { + JToolBar old = getToolBar(); + List tools = null; + + if (t != null) + tools = Collections.singletonList(t); + + setToolBars(tools); + // TODO: Fire Property Change + } + + public void setToolBars(List l) { + if (l == null) + l = Collections.emptyList(); + + List old = toolBars; + toolBars = Collections.unmodifiableList(new ArrayList(l)); + + JComponent oldPanel = toolBarPanel, newPanel = null; + if (toolBars.size() == 1) { + newPanel = toolBars.get(0); + } else if(toolBars.size() > 1) { + newPanel = new JPanel(); + for (JComponent jToolBar : toolBars) { + newPanel.add(jToolBar); + } + } + + replaceComponent(oldPanel, newPanel, BorderLayout.NORTH); + + // TODO: Fire Property Change } public void setStatusBar(JComponent c) { + JComponent old = statusBar; + statusBar = c; + replaceComponent(old, statusBar, BorderLayout.SOUTH); + + // TODO: Fire Property Change } public JFrame getFrame() { - return null; + if (frame == null) { + TrickResources resources = app.getContext().getResourceMap(); + + String title = resources.getString("Application.title"); + ImageIcon icon = resources.getImageIcon("Application.icon"); + + frame = new JFrame(title); + frame.setName("mainFrame"); + + if (icon != null) { + Image img = icon.getImage(); + frame.setIconImage(img); + } + } + + return frame; + } + + public JRootPane getRootPane() { + return getFrame().getRootPane(); } public void setFrame(JFrame f) { - + if (f == null) + throw new IllegalArgumentException("null JFrame"); + + if (frame != null) + throw new IllegalStateException("frame already set"); + + frame = f; } public BaseApplication getApplication() { - return null; + return app; + } + + private void replaceComponent(JComponent oldC, JComponent newC, Object constraint) { + Container contentPane = getRootPane().getContentPane(); + + if (oldC != null) + contentPane.remove(oldC); + + if (newC != null) + contentPane.add(newC, constraint); } } diff --git a/trick_source/java/src/main/java/trick/dataproducts/trickqp/utils/VarListPanel.java b/trick_source/java/src/main/java/trick/dataproducts/trickqp/utils/VarListPanel.java index d07baa404..45783f75b 100644 --- a/trick_source/java/src/main/java/trick/dataproducts/trickqp/utils/VarListPanel.java +++ b/trick_source/java/src/main/java/trick/dataproducts/trickqp/utils/VarListPanel.java @@ -171,7 +171,7 @@ public Component getListCellRendererComponent(JList list, Object value, } TrickApplication app = TrickApplication.getInstance(); - TrickResources resourceMap = app.getResourceMap(); + TrickResources resourceMap = app.getContext().getResourceMap(); if (varObj.getDisplay()==DisplayType.HIDDEN) { // Hide these using a blank filler component: diff --git a/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java b/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java index bcdaf1e05..0a99a9f22 100644 --- a/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java +++ b/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java @@ -45,6 +45,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; @@ -605,6 +606,7 @@ protected void initialize(String[] args) { @Override protected void ready() { super.ready(); + System.out.println("!!!READY START!!!"); logoImagePanel.start(); @@ -635,9 +637,13 @@ protected void ready() { printSendHS(); } + System.out.println("!!!Get Sim State!!!"); scheduleGetSimState(); + System.out.println("!!!Status Monitors!!!"); startStatusMonitors(); + System.out.println("!!!READY START!!!"); + } /** From db019d1ab1156bf653aa22cc932890b82ec8acd1 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Tue, 9 Jul 2024 15:59:59 -0500 Subject: [PATCH 13/23] Removed extraneous print statements --- .../java/src/main/java/trick/common/TrickApplication.java | 3 --- .../main/java/trick/common/framework/BaseApplication.java | 7 +------ .../main/java/trick/simcontrol/SimControlApplication.java | 4 ---- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/trick_source/java/src/main/java/trick/common/TrickApplication.java b/trick_source/java/src/main/java/trick/common/TrickApplication.java index e2bf5f6a3..26d7fa994 100644 --- a/trick_source/java/src/main/java/trick/common/TrickApplication.java +++ b/trick_source/java/src/main/java/trick/common/TrickApplication.java @@ -378,7 +378,6 @@ public static String getResourcePath(Class app) { */ @Override protected void initialize(String[] args) { - System.out.println("INITIALIZE"); // the name of this application applicationName = getContext().getApplicationClass().getSimpleName(); @@ -426,8 +425,6 @@ public void willExit(EventObject e) {} */ @Override protected void startup() { - System.out.println("STARTUP"); - String defaultValue = Boolean.toString(false); boolean savedExitProperty = Boolean.valueOf(trickProperties.getProperty( "confirmExit", defaultValue)); diff --git a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java index baa15f669..0f6455773 100644 --- a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java +++ b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java @@ -270,7 +270,7 @@ private static T createInstanceOf(Class cls) throws NoSuchMethodExceptio InvocationTargetException { Constructor clsCtor = cls.getDeclaredConstructor(); - if(!clsCtor.canAccess(null)) { + if(!clsCtor.isAccessible()) { try { clsCtor.setAccessible(true); } catch (SecurityException UNUSED) { } } @@ -571,24 +571,19 @@ private void waitForEmptyQueue(JPanel panel) { boolean emptyQ = false; while(!emptyQ) { - System.out.println("Waiting..."); QueueEvent e = new QueueEvent(panel); Q.postEvent(e); synchronized(e) { - System.out.println("\tSynched"); while(!e.isDispatched()) { try { e.wait(); } catch (InterruptedException ignored) {} } - System.out.println("\tDispatched"); emptyQ = e.isQueueEmpty(); } } - - System.out.println("Queue Empty!"); } private class WaitTillFree extends Task { diff --git a/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java b/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java index 0a99a9f22..3293a9858 100644 --- a/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java +++ b/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java @@ -606,7 +606,6 @@ protected void initialize(String[] args) { @Override protected void ready() { super.ready(); - System.out.println("!!!READY START!!!"); logoImagePanel.start(); @@ -637,12 +636,9 @@ protected void ready() { printSendHS(); } - System.out.println("!!!Get Sim State!!!"); scheduleGetSimState(); - System.out.println("!!!Status Monitors!!!"); startStatusMonitors(); - System.out.println("!!!READY START!!!"); } From 21d0c50ae76d3a7afaffd48cc5c980ee47f3ed25 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Thu, 11 Jul 2024 01:34:28 -0500 Subject: [PATCH 14/23] Fixed issue with Menu Bar names --- .../java/src/main/java/trick/common/TrickApplication.java | 3 ++- .../main/java/trick/common/framework/BaseApplication.java | 8 ++++---- .../java/src/main/java/trick/common/framework/View.java | 7 ++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/trick_source/java/src/main/java/trick/common/TrickApplication.java b/trick_source/java/src/main/java/trick/common/TrickApplication.java index 26d7fa994..b8914a4b6 100644 --- a/trick_source/java/src/main/java/trick/common/TrickApplication.java +++ b/trick_source/java/src/main/java/trick/common/TrickApplication.java @@ -550,7 +550,8 @@ protected JButton createButton(String actionName, boolean showText) { * @return A {@link JMenu} with specified name and action names for its menu items. */ protected JMenu createMenu(String menuName, String[] actionNames) { - JMenu menu = new JMenu(); + String menuText = getContext().getResourceMap().getString(menuName + ".text"); + JMenu menu = new JMenu(menuText); menu.setName(menuName); buildMenu(menu, actionNames); return menu; diff --git a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java index 0f6455773..d40522b2c 100644 --- a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java +++ b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java @@ -105,8 +105,8 @@ public void show(JDialog d) { } public void show(View v) { - Component comp = v.getRootPane().getParent(); - initRootPaneContainer((RootPaneContainer) comp); + RootPaneContainer comp = (RootPaneContainer) v.getRootPane().getParent(); + initRootPaneContainer(comp); ((Window) comp).setVisible(true); } @@ -291,8 +291,8 @@ private void initializeOnce(RootPaneContainer c) { } private T safe_cast(Object o, Class c) { - try { return c.cast(o); } - catch (ClassCastException e) { return null; } + if(c.isInstance(o)) return c.cast(o); + else return null; } private void initMainFrameClose() { diff --git a/trick_source/java/src/main/java/trick/common/framework/View.java b/trick_source/java/src/main/java/trick/common/framework/View.java index 4dd0a2fab..9e6c61b85 100644 --- a/trick_source/java/src/main/java/trick/common/framework/View.java +++ b/trick_source/java/src/main/java/trick/common/framework/View.java @@ -56,6 +56,11 @@ public void setMenuBar(JMenuBar m) { // TODO: Fire Property Change } + public JMenuBar getMenuBar() { + // JMenuBar old = menuBar; + return menuBar; + } + public JToolBar getToolBar() { return (toolBars.size() == 0) ? null : toolBars.get(0); } @@ -140,7 +145,7 @@ public BaseApplication getApplication() { return app; } - private void replaceComponent(JComponent oldC, JComponent newC, Object constraint) { + private void replaceComponent(JComponent oldC, JComponent newC, String constraint) { Container contentPane = getRootPane().getContentPane(); if (oldC != null) From 2c7c496c24b45cdfc330cacfadd7513a5b469f2d Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Tue, 16 Jul 2024 10:28:27 -0400 Subject: [PATCH 15/23] Replaced Mnemonic signifiers --- .../resources/TrickApplication.properties | 10 +-- .../DataProductsApplication.properties | 12 ++-- .../resources/TrickDPApplication.properties | 42 ++++++------ .../resources/TrickQPApplication.properties | 66 +++++++++---------- .../dre/resources/DreApplication.properties | 14 ++-- .../SimControlApplication.properties | 18 ++--- .../SimSnifferApplication.properties | 4 +- 7 files changed, 83 insertions(+), 83 deletions(-) diff --git a/trick_source/java/src/main/resources/trick/common/resources/TrickApplication.properties b/trick_source/java/src/main/resources/trick/common/resources/TrickApplication.properties index c6018bc93..ac6bd3f78 100644 --- a/trick_source/java/src/main/resources/trick/common/resources/TrickApplication.properties +++ b/trick_source/java/src/main/resources/trick/common/resources/TrickApplication.properties @@ -21,7 +21,7 @@ trick.logo = trick.gif sie.resource.file = S_sie.resource ## File menu - can be used/override in any subclass -fileMenu.text = File +fileMenu.text = &File exitConfirmation.Action.text = Show Exit Confirmation Prompt exitConfirmation.Action.shortDescription = Turn On/Off popup box that verifies \ @@ -29,11 +29,11 @@ if the user really wants to close this application. ## Help menu -helpContents.Action.text = Help Contents +helpContents.Action.text = &Help Contents helpContents.Action.shortDescription = Show Help Contents ## About -showAboutBox.Action.text = About... +showAboutBox.Action.text = &About... showAboutBox.Action.shortDescription = Show the application's about box dialog closeAboutBox.Action.text = OK @@ -59,7 +59,7 @@ homepageLabel.text = Homepage: homepageTextField.text = ${Application.homepage} ## Look and Feel -lookAndFeel.Action.text = Look and Feel +lookAndFeel.Action.text = &Look and Feel lookAndFeel.Action.ShortDescription = Change Look and Feel ## Specify certain action icons here so that they can be put in common @@ -86,7 +86,7 @@ openDR.Action.icon = fileopen.gif # saveDR action icon for DreApplication saveDR.Action.icon = filesave.gif -quit.Action.text = Exit +quit.Action.text = Quit quit.Action.shortDescription = Quit Application treeNodeClosed.icon = firefox_folder_closed.gif diff --git a/trick_source/java/src/main/resources/trick/dataproducts/resources/DataProductsApplication.properties b/trick_source/java/src/main/resources/trick/dataproducts/resources/DataProductsApplication.properties index 166bde852..417e5d15c 100644 --- a/trick_source/java/src/main/resources/trick/dataproducts/resources/DataProductsApplication.properties +++ b/trick_source/java/src/main/resources/trick/dataproducts/resources/DataProductsApplication.properties @@ -6,27 +6,27 @@ Application.title = Data Products mainFrame.title = Data Products -singlePlot.Action.text = Single Plot... +singlePlot.Action.text = &Single Plot... singlePlot.Action.shortDescription = Show Single Plot singlePlot.Action.icon = plot_single.gif -comparisonPlot.Action.text = Comparison Plot... +comparisonPlot.Action.text = &Comparison Plot... comparisonPlot.Action.shortDescription = Show Comparison Plot comparisonPlot.Action.icon = plot_coplot.gif -errorPlot.Action.text = Error Plot... +errorPlot.Action.text = &Error Plot... errorPlot.Action.shortDescription = Show Error Plot errorPlot.Action.icon = plot_error.gif -contrastPlot.Action.text = Contrast Plot... +contrastPlot.Action.text = Co&ntrast Plot... contrastPlot.Action.shortDescription = Contrast Plot: Show Both Comparison and Error Plots contrastPlot.Action.icon = plot_contrast.gif -tabularData.Action.text = Table... +tabularData.Action.text = &Table... tabularData.Action.shortDescription = Show Tabular Data tabularData.Action.icon = table_callback1.gif -tabularErrorData.Action.text = Table Error... +tabularErrorData.Action.text = Table Err&or... tabularErrorData.Action.shortDescription = Show Tabular Error Data tabularErrorData.Action.icon = table_error_callback.gif diff --git a/trick_source/java/src/main/resources/trick/dataproducts/trickdp/resources/TrickDPApplication.properties b/trick_source/java/src/main/resources/trick/dataproducts/trickdp/resources/TrickDPApplication.properties index dab67e7f6..a06c724ea 100644 --- a/trick_source/java/src/main/resources/trick/dataproducts/trickdp/resources/TrickDPApplication.properties +++ b/trick_source/java/src/main/resources/trick/dataproducts/trickdp/resources/TrickDPApplication.properties @@ -8,58 +8,58 @@ Application.description = Trick Data Products Application mainFrame.title = Trick DP # Menu Bar -sessionMenu.text = Session -simsRunsMenu.text = Sims/Runs -dataProductMenu.text = Data Product -settingsMenu.text = Settings -actionsMenu.text = Actions -helpMenu.text = Help +sessionMenu.text = &Session +simsRunsMenu.text = Sims/&Runs +dataProductMenu.text = &Data Product +settingsMenu.text = Se&ttings +actionsMenu.text = &Actions +helpMenu.text = &Help # Menu items ## Session menu -newSession.Action.text = New... +newSession.Action.text = &New... newSession.Action.shortDescription = Start a New Session -openSession.Action.text = Open... +openSession.Action.text = &Open... openSession.Action.shortDescription = Open an Existing Session -##convertSession.Action.text = Convert... +##convertSession.Action.text = &Convert... ##convertSession.Action.shortDescription = Convert Session File to XML Format -saveSession.Action.text = Save... +saveSession.Action.text = &Save... saveSession.Action.shortDescription = Save Current Session -refreshSession.Action.text = Refresh... +refreshSession.Action.text = R&efresh... refreshSession.Action.shortDescription = Refresh Current Session -#propertiesSession.Action.text = Properties... +#propertiesSession.Action.text = &Properties... #propertiesSession.Action.shortDescription = Show Properties of Current Session ## Sims/Runs menu -importSimDir.Action.text = Import Sim Dir... +importSimDir.Action.text = Import &Sim Dir... importSimDir.Action.shortDescription = Import Sim Directory to Current Session -addRunDir.Action.text = Add Run Dir... +addRunDir.Action.text = Add &Run Dir... addRunDir.Action.shortDescription = Add a Run Directory to Current Session ## Data Product menu -addDP.Action.text = Add DP... +addDP.Action.text = &Add DP... addDP.Action.shortDescription = Add a Data Product file to Current Session -editSelectedDP.Action.text = Edit DP... +editSelectedDP.Action.text = &Edit DP... editSelectedDP.Action.shortDescription = Open Quickplot to edit the Selected Data Product from DP Selections -editRightClickedDP.Action.text = Edit DP... +editRightClickedDP.Action.text = &Edit DP... editRightClickedDP.Action.shortDescription = Open Quickplot to edit the Selected Data Product file -filterDP.Action.text = Filter... +filterDP.Action.text = &Filter... filterDP.Action.shortDescription = Filter the Displayed Data Product files ## Settings -plotDestination.Action.text = Destination +plotDestination.Action.text = &Destination plotDestination.Action.shortDescritpion = The Destination for Plotting @@ -76,11 +76,11 @@ gnuErrorPlot.Action.text = GNUplot Postscript Error Plot... gnuErrorPlot.Action.shortDescription = Show GNU Postscript Error Plot gnuErrorPlot.Action.icon = ps_error.gif -quickPlot.Action.text = Quickplot... +quickPlot.Action.text = &Quickplot... quickPlot.Action.shortDescription = Quick Plot quickPlot.Action.icon = quickplot.gif -createPDF.Action.text = Create PDF Booklet... +createPDF.Action.text = Create &PDF Booklet... createPDF.Action.shortDescription = Create PDF Booklet... createPDF.Action.icon = adobe_pdf.gif diff --git a/trick_source/java/src/main/resources/trick/dataproducts/trickqp/resources/TrickQPApplication.properties b/trick_source/java/src/main/resources/trick/dataproducts/trickqp/resources/TrickQPApplication.properties index 363a996e2..417ef5776 100644 --- a/trick_source/java/src/main/resources/trick/dataproducts/trickqp/resources/TrickQPApplication.properties +++ b/trick_source/java/src/main/resources/trick/dataproducts/trickqp/resources/TrickQPApplication.properties @@ -7,14 +7,14 @@ Application.description = Trick Quick Plotting Application mainFrame.title = Trick QP # Menu Bar -varsMenu.text = Vars -runsMenu.text = Runs -plotsMenu.text = Plots -tablesMenu.text = Tables -programsMenu.text = Programs -settingsMenu.text = Settings -actionsMenu.text = Actions -helpMenu.text = Help +varsMenu.text = &Vars +runsMenu.text = &Runs +plotsMenu.text = &Plots +tablesMenu.text = &Tables +programsMenu.text = Pro&grams +settingsMenu.text = &Settings +actionsMenu.text = &Actions +helpMenu.text = &Help searchVar.Action.text = Search @@ -25,51 +25,51 @@ searchVar.Action.shortDescription = Search Variables (all variables return if le # Menu items ## File menu -newDP.Action.text = New DP... +newDP.Action.text = &New DP... newDP.Action.shortDescription = Start a New DP -openDP.Action.text = Open DP... +openDP.Action.text = &Open DP... openDP.Action.shortDescription = Open an Existing DP File # May add later -#convertDP.Action.text = Convert CP... +#convertDP.Action.text = Conver&t CP... #convertDP.Action.shortDescription = Convert Old DP File to XML Format -refreshDP.Action.text = Refresh... +refreshDP.Action.text = &Refresh... refreshDP.Action.shortDescription = Refresh DP -saveDP.Action.text = Save... +saveDP.Action.text = &Save... saveDP.Action.shortDescription = Save Current DP -saveAsDP.Action.text = Save As... +saveAsDP.Action.text = Save &As... saveAsDP.Action.shortDescription = Save Current DP As # No need -##propertiesDP.Action.text = Properties... +##propertiesDP.Action.text = &Properties... ##propertiesDP.Action.shortDescription = Show Properties of Current DP ## Vars menu -addVar.Action.text = Add Var +addVar.Action.text = &Add Var addVar.Action.shortDescription = Add Selected Variables -expandVar.Action.text = Expand Var +expandVar.Action.text = &Expand Var expandVar.Action.shortDescription = Expand Selected Variables / All -contractVar.Action.text = Contract Var +contractVar.Action.text = &Contract Var contractVar.Action.shortDescription = Contract Selected Variables / All -changeUnits.Action.text = Change Units... +changeUnits.Action.text = Change &Units... changeUnits.Action.shortDescription = Change Units ## Runs menu -addRun.Action.text = Add Run... +addRun.Action.text = &Add Run... addRun.Action.shortDescription = Add Run Directories -removeRun.Action.text = Remove Run +removeRun.Action.text = &Remove Run removeRun.Action.shortDescription = Remove Selected Run Directories ## Plots menu -newPage.Action.text = New Page +newPage.Action.text = &New Page newPage.Action.shortDescription =Add a New Page removeAllPages.Action.text = Remove All Pages @@ -81,33 +81,33 @@ removeAllPages.Action.shortDescription = Remove All Pages ##removePlotFromPage.Action.text = Remove Plots From Selected Page ##removePlotFromPage.Action.shortDescription = Remove All Plots From Selected Pages -newPlot.Action.text = New Plot +newPlot.Action.text = New &Plot newPlot.Action.shortDescription = Add a New Plot -newCurve.Action.text = New Curve +newCurve.Action.text = New &Curve newCurve.Action.shortDescription = Add a New Curve -newVarcase.Action.text = New Varcase +newVarcase.Action.text = New &Varcase newVarcase.Action.shortDescription = Add One Variable Group Option for the Curve ## Tables menu -newTable.Action.text = New Table +newTable.Action.text = &New Table newTable.Action.shortDescription =Add a New Table -newColumn.Action.text = New Column +newColumn.Action.text = New &Column newColumn.Action.shortDescription = Add a New Column to Table removeTable.Action.text = Remove All Tables removeTable.Action.shortDescription = Remove All Tables ## Programs menu -newProgram.Action.text = New Program +newProgram.Action.text = &New Program newProgram.Action.shortDescription =Add a New Program removeAllPrograms.Action.text = Remove All Programs removeAllPrograms.Action.shortDescription =Remove All Programs -newProgramOutput.Action.text = New Output... +newProgramOutput.Action.text = New &Output... newProgramOutput.Action.shortDescription = Add an Output ##removeSelectedTable.Action.text = Remove Selected (table/variable) @@ -120,17 +120,17 @@ newProgramOutput.Action.shortDescription = Add an Output ## Actions menu -selectFunction.Action.text = Function +selectFunction.Action.text = &Function selectFunction.Action.shortDescription = Select a Function selectFunction.Action.icon = function.gif -subtractFunction.Action.text = Subtract (A-B) +subtractFunction.Action.text = &Subtract (A-B) subtractFunction.Action.shortDescription = Subtract -reverseSubtractFunction.Action.text = Subtract (B-A) +reverseSubtractFunction.Action.text = &Subtract (B-A) reverseSubtractFunction.Action.shortDescription = Subtract -cancelFunction.Action.text = Cancel +cancelFunction.Action.text = &Cancel cancelFunction.Action.shortDescription = Cancel diff --git a/trick_source/java/src/main/resources/trick/dre/resources/DreApplication.properties b/trick_source/java/src/main/resources/trick/dre/resources/DreApplication.properties index 70081e2a1..55e493554 100644 --- a/trick_source/java/src/main/resources/trick/dre/resources/DreApplication.properties +++ b/trick_source/java/src/main/resources/trick/dre/resources/DreApplication.properties @@ -6,14 +6,14 @@ Application.title = Dre mainFrame.title = Data Recording Editor # Menu Bar -optionsMenu.text = Options +optionsMenu.text = &Options # Menu items ## File menu -openDR.Action.text = Open... +openDR.Action.text = &Open... openDR.Action.shortDescription = Open a dre file -saveDR.Action.text = Save... +saveDR.Action.text = &Save... saveDR.Action.shortDescription = Save a dre file @@ -42,18 +42,18 @@ removeAll.Action.text = Remove All addVariables.Action.text = Add ## Options pane -#formatGroup.title = Format +#formatGroup.title = &Format #formatGroup.collapsed = true #formatGroup.scrollOnExpand = true -#freqGroup.title = How Frequent +#freqGroup.title = &How Frequent #freqGroup.collapsed = true #freqGroup.scrollOnExpand = true -#precisionGroup.title = Single Precision +#precisionGroup.title = &Single Precision #precisionGroup.collapsed = true #precisionGroup.scrollOnExpand = true -#bufferingGroup.title = Buffering +#bufferingGroup.title = &Buffering #bufferingGroup.collapsed = true #bufferingGroup.scrollOnExpand = true diff --git a/trick_source/java/src/main/resources/trick/simcontrol/resources/SimControlApplication.properties b/trick_source/java/src/main/resources/trick/simcontrol/resources/SimControlApplication.properties index cc35fa397..87c64763a 100644 --- a/trick_source/java/src/main/resources/trick/simcontrol/resources/SimControlApplication.properties +++ b/trick_source/java/src/main/resources/trick/simcontrol/resources/SimControlApplication.properties @@ -10,30 +10,30 @@ mainFrame.title = Sim Control showStatusFont.Action.text = Font... showStatusFont.Action.shortDescription = Show Status Pane Font -saveStatusMsgs.Action.text = Save Status Msgs... +saveStatusMsgs.Action.text = &Save Status Msgs... saveStatusMsgs.Action.shortDescription = Save Status Messages -clearStatusMsgs.Action.text = Clear Status Msgs... +clearStatusMsgs.Action.text = &Clear Status Msgs... clearStatusMsgs.Action.shortDescription = Clear Status Messages -startTV.Action.text = Start Trick View +startTV.Action.text = Start Trick &View startTV.Action.shortDescription = Start Trick View (TV) startTV.Action.icon = tv_22x22.png -startMTV.Action.text = Start Event/Malfunction Trick View +startMTV.Action.text = Start &Event/Malfunction Trick View startMTV.Action.shortDescription = Start Event/Malfunction Trick View (MTV) startMTV.Action.icon = mtv_22x22.png -freezeAt.Action.text = Freeze At... +freezeAt.Action.text = Freeze &At... freezeAt.Action.shortDescription = Freeze At -freezeIn.Action.text = Freeze In... +freezeIn.Action.text = Freeze &In... freezeIn.Action.shortDescription = Freeze In -checkpointObjects.Action.text = Checkpoint Objects... +checkpointObjects.Action.text = Checkpoint &Objects... checkpointObjects.Action.shortDescription = Checkpoint the specified objects -throttle.Action.text = Throttle... +throttle.Action.text = &Throttle... throttle.Action.shortDescription = Throttle throttle.Action.icon = throttle_22x22.png @@ -70,4 +70,4 @@ lite.Action.text = Lite lite.Action.shortDescription = Lite/Full # Resource for menu -actionsMenu.text = Actions +actionsMenu.text = &Actions diff --git a/trick_source/java/src/main/resources/trick/sniffer/resources/SimSnifferApplication.properties b/trick_source/java/src/main/resources/trick/sniffer/resources/SimSnifferApplication.properties index c9038de35..d9e643e78 100644 --- a/trick_source/java/src/main/resources/trick/sniffer/resources/SimSnifferApplication.properties +++ b/trick_source/java/src/main/resources/trick/sniffer/resources/SimSnifferApplication.properties @@ -7,9 +7,9 @@ Application.icon = nose.gif mainFrame.title = Sim Sniffer # Resources for the @Actions defined in SimSnifferApplication -launchSimControlPanel.Action.text = Launch Sim Control Panel +launchSimControlPanel.Action.text = Launch Sim &Control Panel launchSimControlPanel.Action.shortDescription = Launch the Sim Control Panel and connect it to the selected simulation. -launchTrickView.Action.text = Launch Trick View +launchTrickView.Action.text = Launch Trick &View launchTrickView.Action.shortDescription = Launch Trick View and connect it to the selected simulation. From be6784da7bffdde5ab0159cf51aabbec0802009a Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Tue, 16 Jul 2024 12:49:04 -0400 Subject: [PATCH 16/23] Fixed mnemonics --- .../java/trick/common/TrickApplication.java | 5 ++- .../java/trick/common/utils/TrickAction.java | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/trick_source/java/src/main/java/trick/common/TrickApplication.java b/trick_source/java/src/main/java/trick/common/TrickApplication.java index b8914a4b6..34a539e2b 100644 --- a/trick_source/java/src/main/java/trick/common/TrickApplication.java +++ b/trick_source/java/src/main/java/trick/common/TrickApplication.java @@ -551,8 +551,11 @@ protected JButton createButton(String actionName, boolean showText) { */ protected JMenu createMenu(String menuName, String[] actionNames) { String menuText = getContext().getResourceMap().getString(menuName + ".text"); - JMenu menu = new JMenu(menuText); + JMenu menu = new JMenu(); menu.setName(menuName); + + TrickAction.configureMnemonic(menu, menuText); + buildMenu(menu, actionNames); return menu; } diff --git a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java index c33fac2ac..ba1dfa9c3 100644 --- a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java +++ b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java @@ -1,11 +1,13 @@ package trick.common.utils; import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; import java.io.File; import java.lang.reflect.Method; import java.util.Properties; import javax.swing.AbstractAction; +import javax.swing.AbstractButton; import javax.swing.Action; import javax.swing.ImageIcon; @@ -63,6 +65,8 @@ private void applyProperties() { props.getString(SHORT_DESCRIPTION_PROPERTY)); putValue(Action.LONG_DESCRIPTION, props.getString(LONG_DESCRIPTION_PROPERTY)); + + configureMnemonic(this, props.getString(TEXT_PROPERTY)); if((iconValue = props.getIcon(ICON_PROPERTY)) != null) { putValue(Action.SMALL_ICON , iconValue); @@ -77,6 +81,35 @@ private void applyProperties() { } } } + + public static void configureMnemonic(Object target, String text) { + String name; + int mnemIndex, mnemKey; + + name = text; + mnemIndex = name.indexOf("&"); + mnemIndex = mnemIndex < 0 ? name.indexOf("_") : mnemIndex; + + if (mnemIndex < 0) return; + + name = name.substring(0, mnemIndex) + name.substring(mnemIndex + 1); + + mnemKey = KeyEvent.getExtendedKeyCodeForChar(name.charAt(mnemIndex)); + + if(target instanceof Action) { + Action act = (Action) target; + + act.putValue(Action.NAME, name); + act.putValue(Action.MNEMONIC_KEY, mnemKey); + act.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, mnemIndex); + } else if(target instanceof AbstractButton) { + AbstractButton but = (AbstractButton) target; + + but.setText(name); + but.setMnemonic(mnemKey); + but.setDisplayedMnemonicIndex(mnemIndex); + } + } private ImageIcon getIcon(String fileName) { String iconPath; From c197586d3a86366736696d2896ab3a9a51466a8f Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Wed, 24 Jul 2024 11:41:42 -0400 Subject: [PATCH 17/23] Got MTV to pop up --- .../java/trick/common/TrickApplication.java | 20 +------- .../trick/common/framework/AppContext.java | 48 ++++++++++++++++++- .../common/framework/BaseApplication.java | 7 +-- .../java/trick/common/utils/TrickAction.java | 24 +++------- 4 files changed, 55 insertions(+), 44 deletions(-) diff --git a/trick_source/java/src/main/java/trick/common/TrickApplication.java b/trick_source/java/src/main/java/trick/common/TrickApplication.java index 34a539e2b..34789597d 100644 --- a/trick_source/java/src/main/java/trick/common/TrickApplication.java +++ b/trick_source/java/src/main/java/trick/common/TrickApplication.java @@ -338,24 +338,6 @@ public static String arrayToString(String[] arr, String separator) { return result.toString(); } - protected void createActionMap() { - if(actionMap == null) actionMap = new ActionMap(); - - Class appClass = this.getClass(); - - for (Method man : appClass.getMethods()) { - if (isSwingAction(man)) { - String name = man.getName(); - TrickResources actProp = TrickAction.extractProperties(resourceMap, name); - actionMap.put(man.getName(), new TrickAction(actProp, this, man)); - } - } - } - - private boolean isSwingAction(Method man) { - return man.getAnnotation(SwingAction.class) != null; - } - public static String getResourcePath(Class app) { String canon = app.getCanonicalName(); canon = "/" + canon.replace(".", "/") + ".properties"; @@ -388,7 +370,7 @@ protected void initialize(String[] args) { getContext().getSessionStorage().putProperty(JToggleButton.class, this); resourceMap = getContext().getResourceMap(); - createActionMap(); + actionMap = getContext().getActionMap(this.getClass(), this); // Load any saved user settable properties from properties file trickProperties = new Properties(); diff --git a/trick_source/java/src/main/java/trick/common/framework/AppContext.java b/trick_source/java/src/main/java/trick/common/framework/AppContext.java index f3c891dac..fad35a223 100644 --- a/trick_source/java/src/main/java/trick/common/framework/AppContext.java +++ b/trick_source/java/src/main/java/trick/common/framework/AppContext.java @@ -8,6 +8,8 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.lang.reflect.Method; +import java.util.HashMap; import javax.swing.ActionMap; @@ -15,17 +17,23 @@ import trick.common.framework.BaseApplication; import trick.common.framework.Session; import trick.common.framework.TaskService; +import trick.common.utils.SwingAction; +import trick.common.utils.TrickAction; import trick.common.utils.TrickResources; public class AppContext { private final Class appClass; + private final HashMap actionMaps; private TrickResources resources = null; + private TaskService service; private Session session; public AppContext(Class appClass) { this.appClass = appClass; session = new Session(); + service = new TaskService("default"); + actionMaps = new HashMap(); } public Class getApplicationClass() { @@ -33,7 +41,35 @@ public Class getApplicationClass() { } public ActionMap getActionMap(Class c, Object o) { - return null; + if(c == null) { + throw new IllegalArgumentException("Null Class"); + } + + if(o == null) { + throw new IllegalArgumentException("Null Object"); + } + + if(!c.isAssignableFrom(o.getClass())) { + throw new IllegalArgumentException("Given Object isn't an instance of the given Class"); + } + + ActionMap actionMap = actionMaps.get(o); + + if(actionMap == null) { + actionMap = new ActionMap(); + + for (Method man : c.getMethods()) { + if (isSwingAction(man)) { + String name = man.getName(); + TrickResources actProp = TrickAction.extractProperties(getResourceMap(), name); + actionMap.put(man.getName(), new TrickAction(actProp, o, man)); + } + } + + actionMaps.put(o, actionMap); + } + + return actionMap; } public TrickResources getResourceMap() { @@ -52,9 +88,13 @@ public Session getLocalStorage() { } public TaskService getTaskService() { - return null; + return service; } + /** + * Add the properties of the given component and any of its children to the resources + */ + // TODO: Implement this public void addComponent(Component c) { } @@ -92,4 +132,8 @@ private void parseResources() { System.err.println(ioe.getMessage()); } } + + private boolean isSwingAction(Method man) { + return man.getAnnotation(SwingAction.class) != null; + } } diff --git a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java index d40522b2c..feacc9799 100644 --- a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java +++ b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java @@ -417,7 +417,7 @@ private void waitForReady() { //======================================== public static BaseApplication getInstance() throws IllegalStateException { - return getInstance(GenericApplication.class); + return getInstance(BaseApplication.class); } public static T getInstance(Class appClass) throws IllegalStateException { @@ -433,10 +433,7 @@ public static T getInstance(Class appClass) throw } public JFrame getMainFrame() { - if(mainView != null) - return mainView.getFrame(); - else - return null; + return getMainView().getFrame(); } public void setMainFrame(JFrame nFrame) { diff --git a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java index ba1dfa9c3..a231b472e 100644 --- a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java +++ b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java @@ -15,11 +15,11 @@ public class TrickAction extends AbstractAction { private TrickResources props; - private TrickApplication invoker; + private Object invoker; private Method man; - public TrickAction(TrickResources p, TrickApplication target, Method m) { + public TrickAction(TrickResources p, Object target, Method m) { props = new TrickResources(p); invoker = target; man = m; @@ -57,16 +57,17 @@ public String toString() { } private void applyProperties() { - String propValue; + String name = props.getString(TEXT_PROPERTY); ImageIcon iconValue; - putValue(Action.NAME, props.getString(TEXT_PROPERTY)); + putValue(Action.NAME, name); putValue(Action.SHORT_DESCRIPTION, props.getString(SHORT_DESCRIPTION_PROPERTY)); putValue(Action.LONG_DESCRIPTION, props.getString(LONG_DESCRIPTION_PROPERTY)); - configureMnemonic(this, props.getString(TEXT_PROPERTY)); + if(name != null && !name.isEmpty()) + configureMnemonic(this, name); if((iconValue = props.getIcon(ICON_PROPERTY)) != null) { putValue(Action.SMALL_ICON , iconValue); @@ -111,19 +112,6 @@ public static void configureMnemonic(Object target, String text) { } } - private ImageIcon getIcon(String fileName) { - String iconPath; - - if(fileName.indexOf("/") >= 0) { - iconPath = fileName; - } else { - iconPath = invoker.getResourcePath(invoker.getClass()); - int finalSlash = iconPath.lastIndexOf("/") + 1; - iconPath = iconPath.substring(0, finalSlash) + fileName; - } - return new ImageIcon(iconPath); - } - private static String resolveFilePath(String PATH, String fileName) { String paths[] = PATH.split(";"); String resolvedName; From 2662562f9d62a2f015b77590423d731117c4dd69 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Wed, 24 Jul 2024 13:23:54 -0400 Subject: [PATCH 18/23] Tagged methods for implementation and fixed status messages --- .../java/trick/common/framework/Session.java | 4 ++ .../java/trick/common/framework/Task.java | 15 +++++ .../trick/common/framework/TaskMonitor.java | 2 + .../trick/common/framework/TaskService.java | 55 ++++++++++--------- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/trick_source/java/src/main/java/trick/common/framework/Session.java b/trick_source/java/src/main/java/trick/common/framework/Session.java index 809223ba0..bc9332791 100644 --- a/trick_source/java/src/main/java/trick/common/framework/Session.java +++ b/trick_source/java/src/main/java/trick/common/framework/Session.java @@ -11,18 +11,22 @@ import trick.common.framework.PropertySupport; public class Session { + // TODO: Implement this public void setDirectory(File f) { } + // TODO: Implement this public void putProperty(Class c, PropertySupport p) { } + // TODO: Implement this public void save(Component c, String filename) throws IOException { } + // TODO: Implement this public void restore(Component c, String filename) { } diff --git a/trick_source/java/src/main/java/trick/common/framework/Task.java b/trick_source/java/src/main/java/trick/common/framework/Task.java index 35db76926..38e035309 100644 --- a/trick_source/java/src/main/java/trick/common/framework/Task.java +++ b/trick_source/java/src/main/java/trick/common/framework/Task.java @@ -52,6 +52,21 @@ public Task(BaseApplication app) { initTask(); } + // TODO: Implement this + public boolean isPending() { + return true; + } + + // TODO: Implement this + public TaskService getTaskService() { + return null; + } + + // TODO: Implement this + public void setTaskService(TaskService serv) { + + } + // protected abstract Void doInBackground(); protected abstract void finished(); protected void cancelled() {} diff --git a/trick_source/java/src/main/java/trick/common/framework/TaskMonitor.java b/trick_source/java/src/main/java/trick/common/framework/TaskMonitor.java index 3a075c477..5f31af178 100644 --- a/trick_source/java/src/main/java/trick/common/framework/TaskMonitor.java +++ b/trick_source/java/src/main/java/trick/common/framework/TaskMonitor.java @@ -9,10 +9,12 @@ import trick.common.framework.AppContext; public class TaskMonitor { + // TODO: Implement this public TaskMonitor(AppContext context) { } + // TODO: Implement this public void addPropertyChangeListener(PropertyChangeListener listener) { } diff --git a/trick_source/java/src/main/java/trick/common/framework/TaskService.java b/trick_source/java/src/main/java/trick/common/framework/TaskService.java index d35d2a202..8443f51fc 100644 --- a/trick_source/java/src/main/java/trick/common/framework/TaskService.java +++ b/trick_source/java/src/main/java/trick/common/framework/TaskService.java @@ -20,37 +20,38 @@ public TaskService(String name) { } - public void execute(Task t) { - /** - * // Input Validation - * if (task == null) { - * throw new IllegalArgumentException("null task"); - * } - * if (!task.isPending() || (task.getTaskService() != null)) { - * throw new IllegalArgumentException("task has already been executed"); - * } - * - * // Setup for task execution - * task.setTaskService(this); - * // TBD: what if task has already been submitted? - * task.addPropertyChangeListener(taskPCL); - * - * // Add Task to Queue - * List> oldTaskList, newTaskList; - * synchronized (tasks) { - * oldTaskList = tasks.getList(); - * tasks.addLast(task); - * newTaskList = tasks.getList(); - * } - * firePropertyChange(new TaskPropertyChangeEvent(oldTaskList, newTaskList, null, task)); - * - * maybeBlockTask(task); - * executorService.execute(task); - */ + // TODO: Rewrite this + public void execute(Task task) { + // Input Validation + if (task == null) { + throw new IllegalArgumentException("null task"); + } + if (!task.isPending() || (task.getTaskService() != null)) { + throw new IllegalArgumentException("task has already been executed"); + } + + // Setup for task execution + task.setTaskService(this); + // TBD: what if task has already been submitted? + // task.addPropertyChangeListener(taskPCL); + + // TODO: Add Task to Queue + // List> oldTaskList, newTaskList; + // synchronized (tasks) { + // oldTaskList = tasks.getList(); + // tasks.addLast(task); + // newTaskList = tasks.getList(); + // } + // firePropertyChange(new TaskPropertyChangeEvent(oldTaskList, newTaskList, null, task)); + + maybeBlockTask(task); + super.execute(task); + } public final String getName() { return name; } + // TODO: Implement this private void maybeBlockTask(Task task) { } From 52d4cda37c8ca2317fb32eee25ae9e4a844e0f21 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Mon, 29 Jul 2024 11:16:45 -0400 Subject: [PATCH 19/23] Implemented InputBlocker and associated classes --- .../trick/common/framework/AppContext.java | 2 +- .../common/framework/BaseApplication.java | 15 +--- .../java/trick/common/framework/View.java | 1 - .../common/framework/{ => task}/Task.java | 15 +++- .../framework/{ => task}/TaskEvent.java | 2 +- .../framework/{ => task}/TaskListener.java | 4 +- .../framework/{ => task}/TaskMonitor.java | 2 +- .../framework/{ => task}/TaskService.java | 22 +++++- .../framework/task/utils/BlockingTarget.java | 79 +++++++++++++++++++ .../framework/task/utils/InputBlocker.java | 53 +++++++++++++ .../java/src/main/java/trick/mtv/MtvApp.java | 2 +- .../java/src/main/java/trick/mtv/MtvView.java | 2 +- .../simcontrol/SimControlApplication.java | 2 +- 13 files changed, 173 insertions(+), 28 deletions(-) rename trick_source/java/src/main/java/trick/common/framework/{ => task}/Task.java (94%) rename trick_source/java/src/main/java/trick/common/framework/{ => task}/TaskEvent.java (89%) rename trick_source/java/src/main/java/trick/common/framework/{ => task}/TaskListener.java (84%) rename trick_source/java/src/main/java/trick/common/framework/{ => task}/TaskMonitor.java (91%) rename trick_source/java/src/main/java/trick/common/framework/{ => task}/TaskService.java (74%) create mode 100644 trick_source/java/src/main/java/trick/common/framework/task/utils/BlockingTarget.java create mode 100644 trick_source/java/src/main/java/trick/common/framework/task/utils/InputBlocker.java diff --git a/trick_source/java/src/main/java/trick/common/framework/AppContext.java b/trick_source/java/src/main/java/trick/common/framework/AppContext.java index fad35a223..1d7816900 100644 --- a/trick_source/java/src/main/java/trick/common/framework/AppContext.java +++ b/trick_source/java/src/main/java/trick/common/framework/AppContext.java @@ -16,7 +16,7 @@ import trick.common.TrickApplication; import trick.common.framework.BaseApplication; import trick.common.framework.Session; -import trick.common.framework.TaskService; +import trick.common.framework.task.TaskService; import trick.common.utils.SwingAction; import trick.common.utils.TrickAction; import trick.common.utils.TrickResources; diff --git a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java index feacc9799..d7acc617f 100644 --- a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java +++ b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java @@ -50,7 +50,7 @@ import trick.common.framework.AppContext; import trick.common.framework.SwingToolbox; -import trick.common.framework.Task; +import trick.common.framework.task.Task; import trick.common.framework.View; public abstract class BaseApplication { @@ -482,19 +482,6 @@ public abstract class ExitListener { public abstract void willExit(EventObject e); } - private class GenericApplication extends BaseApplication { - public GenericApplication() { - super(); - } - - @Override - protected void initialize(String[] args) { /* UNUSED */ } - - @Override - protected void startup() { /* UNUSED */ } - - } - private interface SetUpCloseOperations { public void setupClose(Container c); } diff --git a/trick_source/java/src/main/java/trick/common/framework/View.java b/trick_source/java/src/main/java/trick/common/framework/View.java index 9e6c61b85..f7d26de46 100644 --- a/trick_source/java/src/main/java/trick/common/framework/View.java +++ b/trick_source/java/src/main/java/trick/common/framework/View.java @@ -27,7 +27,6 @@ public class View { private BaseApplication app; - private JRootPane rootPane; private JFrame frame; private JComponent component, statusBar, toolBarPanel; private JMenuBar menuBar; diff --git a/trick_source/java/src/main/java/trick/common/framework/Task.java b/trick_source/java/src/main/java/trick/common/framework/task/Task.java similarity index 94% rename from trick_source/java/src/main/java/trick/common/framework/Task.java rename to trick_source/java/src/main/java/trick/common/framework/task/Task.java index 38e035309..587e26a0d 100644 --- a/trick_source/java/src/main/java/trick/common/framework/Task.java +++ b/trick_source/java/src/main/java/trick/common/framework/task/Task.java @@ -2,7 +2,7 @@ //======================================== // Package //======================================== -package trick.common.framework; +package trick.common.framework.task; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -13,12 +13,16 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutionException; +import javax.swing.Action; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; -import trick.common.framework.TaskEvent; -import trick.common.framework.TaskListener; +import trick.common.framework.task.TaskEvent; +import trick.common.framework.task.TaskListener; +import trick.common.framework.task.utils.BlockingTarget; +import trick.common.framework.task.utils.InputBlocker; import trick.common.framework.BaseApplication; +import trick.common.utils.TrickAction; import trick.common.utils.TrickResources; public abstract class Task extends SwingWorker { @@ -67,6 +71,11 @@ public void setTaskService(TaskService serv) { } + // TODO: Implement this + public InputBlocker getInputBlocker() { + return null; + } + // protected abstract Void doInBackground(); protected abstract void finished(); protected void cancelled() {} diff --git a/trick_source/java/src/main/java/trick/common/framework/TaskEvent.java b/trick_source/java/src/main/java/trick/common/framework/task/TaskEvent.java similarity index 89% rename from trick_source/java/src/main/java/trick/common/framework/TaskEvent.java rename to trick_source/java/src/main/java/trick/common/framework/task/TaskEvent.java index 346cd5c72..193d15ca7 100644 --- a/trick_source/java/src/main/java/trick/common/framework/TaskEvent.java +++ b/trick_source/java/src/main/java/trick/common/framework/task/TaskEvent.java @@ -2,7 +2,7 @@ //======================================== // Package //======================================== -package trick.common.framework; +package trick.common.framework.task; import java.util.EventObject; diff --git a/trick_source/java/src/main/java/trick/common/framework/TaskListener.java b/trick_source/java/src/main/java/trick/common/framework/task/TaskListener.java similarity index 84% rename from trick_source/java/src/main/java/trick/common/framework/TaskListener.java rename to trick_source/java/src/main/java/trick/common/framework/task/TaskListener.java index e6af5f634..efa7762af 100644 --- a/trick_source/java/src/main/java/trick/common/framework/TaskListener.java +++ b/trick_source/java/src/main/java/trick/common/framework/task/TaskListener.java @@ -2,9 +2,9 @@ //======================================== // Package //======================================== -package trick.common.framework; +package trick.common.framework.task; -import trick.common.framework.TaskEvent; +import trick.common.framework.task.TaskEvent; public interface TaskListener { diff --git a/trick_source/java/src/main/java/trick/common/framework/TaskMonitor.java b/trick_source/java/src/main/java/trick/common/framework/task/TaskMonitor.java similarity index 91% rename from trick_source/java/src/main/java/trick/common/framework/TaskMonitor.java rename to trick_source/java/src/main/java/trick/common/framework/task/TaskMonitor.java index 5f31af178..4f3f21cc2 100644 --- a/trick_source/java/src/main/java/trick/common/framework/TaskMonitor.java +++ b/trick_source/java/src/main/java/trick/common/framework/task/TaskMonitor.java @@ -2,7 +2,7 @@ //======================================== // Package //======================================== -package trick.common.framework; +package trick.common.framework.task; import java.beans.PropertyChangeListener; diff --git a/trick_source/java/src/main/java/trick/common/framework/TaskService.java b/trick_source/java/src/main/java/trick/common/framework/task/TaskService.java similarity index 74% rename from trick_source/java/src/main/java/trick/common/framework/TaskService.java rename to trick_source/java/src/main/java/trick/common/framework/task/TaskService.java index 8443f51fc..6b31807c3 100644 --- a/trick_source/java/src/main/java/trick/common/framework/TaskService.java +++ b/trick_source/java/src/main/java/trick/common/framework/task/TaskService.java @@ -2,13 +2,16 @@ //======================================== // Package //======================================== -package trick.common.framework; +package trick.common.framework.task; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import trick.common.framework.Task; +import javax.swing.SwingUtilities; + +import trick.common.framework.task.Task; +import trick.common.framework.task.utils.InputBlocker; public class TaskService extends ThreadPoolExecutor { private String name; @@ -53,7 +56,22 @@ public void execute(Task task) { // TODO: Implement this private void maybeBlockTask(Task task) { + final InputBlocker blocker = task.getInputBlocker(); + + if(blocker == null ^ !blocker.willBlock()) { + return; + } + + if(SwingUtilities.isEventDispatchThread()) { + blocker.block(); + } else { + Runnable blockerRunnable = new Runnable() { + @Override + public void run() { blocker.block(); } + }; + SwingUtilities.invokeLater(blockerRunnable); + } } } diff --git a/trick_source/java/src/main/java/trick/common/framework/task/utils/BlockingTarget.java b/trick_source/java/src/main/java/trick/common/framework/task/utils/BlockingTarget.java new file mode 100644 index 000000000..b5a0b44a8 --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/task/utils/BlockingTarget.java @@ -0,0 +1,79 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework.task.utils; + +import java.awt.Component; + +import javax.swing.Action; + +public abstract class BlockingTarget { + private final Object target; + + public BlockingTarget(Object t) { target = t; } + + public abstract void setBlocked(boolean state); + + public enum Scope { + NONE, + ACTION, + COMPONENT, + WINDOW, + APPLICATION + } + + private static void validateScope(Scope s, Object o) { + switch (s) { + case ACTION: + if (!(o instanceof Action)) + throw new IllegalArgumentException("target isn't an Action"); + break; + + case COMPONENT: + case WINDOW: + if (!(o instanceof Component)) + throw new IllegalArgumentException("target isn't a Component"); + break; + + default: + } + } + + public static BlockingTarget ScopedTarget(Object target, Scope scope) { + validateScope(scope, target); + + switch (scope) { + case ACTION: + return new BlockingTarget(target) { + @Override + public void setBlocked(boolean state) { + Action act = (Action) target; + act.setEnabled(!state); + } + }; + + case COMPONENT: + return new BlockingTarget(target) { + @Override + public void setBlocked(boolean state) { + Component comp = (Component) target; + comp.setEnabled(!state); + } + }; + + case WINDOW: + case APPLICATION: + return new BlockingTarget(target) { + @Override + public void setBlocked(boolean state) { + // showBusyGlassPane + // showBlockingDialog + } + }; + + default: + return null; + } + } +} \ No newline at end of file diff --git a/trick_source/java/src/main/java/trick/common/framework/task/utils/InputBlocker.java b/trick_source/java/src/main/java/trick/common/framework/task/utils/InputBlocker.java new file mode 100644 index 000000000..44cd70c63 --- /dev/null +++ b/trick_source/java/src/main/java/trick/common/framework/task/utils/InputBlocker.java @@ -0,0 +1,53 @@ + +//======================================== +// Package +//======================================== +package trick.common.framework.task.utils; + +import java.awt.Component; + +import javax.swing.Action; + +import trick.common.framework.task.Task; +import trick.common.framework.task.TaskEvent; +import trick.common.framework.task.TaskListener; +import trick.common.framework.BaseApplication; +import trick.common.utils.TrickAction; +import trick.common.utils.TrickResources; + +public class InputBlocker { + private final Task task; + private final BlockingTarget target; + private final TrickAction action; + + public InputBlocker(Task t, BlockingTarget b, TrickAction a) { + validateTask(t); + + task = t; + target = b; + action = a; + } + + // TODO: Implement this + public boolean willBlock() { + return target != null; + } + + public void block() { + target.setBlocked(true); + } + + public void unblock() { + target.setBlocked(false); + + } + + private static void validateTask(Task t) { + if (t == null) + throw new IllegalArgumentException("task null"); + else if (t.getTaskService() != null) + throw new IllegalStateException("task currently being executed"); + } + +} + diff --git a/trick_source/java/src/main/java/trick/mtv/MtvApp.java b/trick_source/java/src/main/java/trick/mtv/MtvApp.java index 23d72c976..2e76c21a9 100644 --- a/trick_source/java/src/main/java/trick/mtv/MtvApp.java +++ b/trick_source/java/src/main/java/trick/mtv/MtvApp.java @@ -22,7 +22,7 @@ import org.jdesktop.application.Application; import trick.common.framework.BaseApplication; -import trick.common.framework.Task; +import trick.common.framework.task.Task; import trick.common.TrickApplication; import trick.common.utils.VariableServerConnection; import trick.mtv.MtvView.Mode; diff --git a/trick_source/java/src/main/java/trick/mtv/MtvView.java b/trick_source/java/src/main/java/trick/mtv/MtvView.java index bad28dd8b..c31c952ab 100644 --- a/trick_source/java/src/main/java/trick/mtv/MtvView.java +++ b/trick_source/java/src/main/java/trick/mtv/MtvView.java @@ -51,7 +51,7 @@ import trick.common.framework.BaseApplication.ExitListener; import trick.common.framework.BaseApplication; -import trick.common.framework.TaskMonitor; +import trick.common.framework.task.TaskMonitor; import trick.common.framework.View; import trick.common.TrickApplication; import trick.common.utils.SwingAction; diff --git a/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java b/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java index 3293a9858..a6be4e5f0 100644 --- a/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java +++ b/trick_source/java/src/main/java/trick/simcontrol/SimControlApplication.java @@ -80,7 +80,7 @@ import org.jdesktop.swingx.JXTitledSeparator; import trick.common.framework.BaseApplication; -import trick.common.framework.Task; +import trick.common.framework.task.Task; import trick.common.framework.View; import trick.common.TrickApplication; import trick.common.ui.UIUtils; From b503a8b713378e296a8329bb08317cea38ea9c2e Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Thu, 1 Aug 2024 14:23:47 -0400 Subject: [PATCH 20/23] Implemented some of the Task methods --- .../trick/common/framework/task/Task.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/trick_source/java/src/main/java/trick/common/framework/task/Task.java b/trick_source/java/src/main/java/trick/common/framework/task/Task.java index 587e26a0d..12c81d6df 100644 --- a/trick_source/java/src/main/java/trick/common/framework/task/Task.java +++ b/trick_source/java/src/main/java/trick/common/framework/task/Task.java @@ -6,6 +6,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.lang.Thread.State; import java.security.InvalidParameterException; import java.util.List; import java.util.logging.Level; @@ -46,7 +47,8 @@ public abstract class Task extends SwingWorker { private long messageTime, taskStart, taskDone; private String title, description, message; private boolean progressProperty; - + private InputBlocker blocker; + private TaskService service; public Task(BaseApplication app) { this.application = app; @@ -55,25 +57,25 @@ public Task(BaseApplication app) { initTask(); } - - // TODO: Implement this + public boolean isPending() { - return true; + return getState() == StateValue.PENDING; } - // TODO: Implement this public TaskService getTaskService() { - return null; + return service; } - // TODO: Implement this public void setTaskService(TaskService serv) { - + service = serv; } - // TODO: Implement this public InputBlocker getInputBlocker() { - return null; + return blocker; + } + + public void setInputBlocker(InputBlocker block) { + blocker = block; } // protected abstract Void doInBackground(); @@ -178,6 +180,7 @@ private void fireCompletionListeners() { } } + // TODO: Rewrite this private class StatePCL implements PropertyChangeListener { @Override public void propertyChange(PropertyChangeEvent e) { From 3f9d7a2732a48a82f64bfa36314d79200a1b9814 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Mon, 5 Aug 2024 12:02:16 -0400 Subject: [PATCH 21/23] transfer to pc --- .../trick/common/framework/AppContext.java | 27 ++++++++++++++++++- .../common/framework/BaseApplication.java | 2 +- .../SimControlApplication.properties | 2 ++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/trick_source/java/src/main/java/trick/common/framework/AppContext.java b/trick_source/java/src/main/java/trick/common/framework/AppContext.java index 1d7816900..fd4e83404 100644 --- a/trick_source/java/src/main/java/trick/common/framework/AppContext.java +++ b/trick_source/java/src/main/java/trick/common/framework/AppContext.java @@ -5,6 +5,7 @@ package trick.common.framework; import java.awt.Component; +import java.awt.Container; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -12,6 +13,7 @@ import java.util.HashMap; import javax.swing.ActionMap; +import javax.swing.JMenu; import trick.common.TrickApplication; import trick.common.framework.BaseApplication; @@ -95,8 +97,31 @@ public TaskService getTaskService() { * Add the properties of the given component and any of its children to the resources */ // TODO: Implement this - public void addComponent(Component c) { + public void injectComponents(Component root) { + if (root == null) { + throw new IllegalArgumentException("null component. can't inject"); + } + + injectProperties(root); + + if(root instanceof JMenu) + injectComponents(((JMenu) root).getMenuComponents()); + else if(root instanceof Container) + injectComponents(((Container) root).getComponents()); + } + + private void injectComponents(Component[] components) { + for (Component component : components) { + injectComponents(component); + } + } + private void injectProperties(Component component) { + if (component == null) { + throw new IllegalArgumentException("null component. can't inject properties"); + } + + } private TrickResources parseResources(Class app) throws IOException, FileNotFoundException { diff --git a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java index d7acc617f..e60612cf3 100644 --- a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java +++ b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java @@ -151,7 +151,7 @@ public void saveSession(Window win) { //======================================== protected void configureWindow(Window root) { - context.addComponent(root); + context.injectComponents(root); } protected void end() { diff --git a/trick_source/java/src/main/resources/trick/simcontrol/resources/SimControlApplication.properties b/trick_source/java/src/main/resources/trick/simcontrol/resources/SimControlApplication.properties index 87c64763a..2ad5aa72e 100644 --- a/trick_source/java/src/main/resources/trick/simcontrol/resources/SimControlApplication.properties +++ b/trick_source/java/src/main/resources/trick/simcontrol/resources/SimControlApplication.properties @@ -71,3 +71,5 @@ lite.Action.shortDescription = Lite/Full # Resource for menu actionsMenu.text = &Actions + +throttleMenuItem.text = Hello World \ No newline at end of file From 9f07b8b827c13017a0bb5c23dca9e619d899988e Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Wed, 7 Aug 2024 15:01:54 -0400 Subject: [PATCH 22/23] Fixed menu items not registering properties --- .../java/trick/common/TrickApplication.java | 4 - .../trick/common/framework/AppContext.java | 90 ++++++++++++++++++- .../common/framework/BaseApplication.java | 2 +- .../java/trick/common/utils/TrickAction.java | 11 ++- 4 files changed, 95 insertions(+), 12 deletions(-) diff --git a/trick_source/java/src/main/java/trick/common/TrickApplication.java b/trick_source/java/src/main/java/trick/common/TrickApplication.java index 34789597d..38182e2f7 100644 --- a/trick_source/java/src/main/java/trick/common/TrickApplication.java +++ b/trick_source/java/src/main/java/trick/common/TrickApplication.java @@ -532,12 +532,8 @@ protected JButton createButton(String actionName, boolean showText) { * @return A {@link JMenu} with specified name and action names for its menu items. */ protected JMenu createMenu(String menuName, String[] actionNames) { - String menuText = getContext().getResourceMap().getString(menuName + ".text"); JMenu menu = new JMenu(); menu.setName(menuName); - - TrickAction.configureMnemonic(menu, menuText); - buildMenu(menu, actionNames); return menu; } diff --git a/trick_source/java/src/main/java/trick/common/framework/AppContext.java b/trick_source/java/src/main/java/trick/common/framework/AppContext.java index 1d7816900..226627afa 100644 --- a/trick_source/java/src/main/java/trick/common/framework/AppContext.java +++ b/trick_source/java/src/main/java/trick/common/framework/AppContext.java @@ -5,13 +5,20 @@ package trick.common.framework; import java.awt.Component; +import java.awt.Container; +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Method; import java.util.HashMap; +import java.util.logging.Logger; import javax.swing.ActionMap; +import javax.swing.JMenu; import trick.common.TrickApplication; import trick.common.framework.BaseApplication; @@ -28,6 +35,7 @@ public class AppContext { private TrickResources resources = null; private TaskService service; private Session session; + private static final Logger logger = Logger.getLogger(AppContext.class.getName()); public AppContext(Class appClass) { this.appClass = appClass; @@ -95,8 +103,88 @@ public TaskService getTaskService() { * Add the properties of the given component and any of its children to the resources */ // TODO: Implement this - public void addComponent(Component c) { + public void injectComponents(Component root) { + if (root == null) { + throw new IllegalArgumentException("null component. can't inject"); + } + + injectProperties(root); + + if(root instanceof JMenu) + injectComponents(((JMenu) root).getMenuComponents()); + else if(root instanceof Container) + injectComponents(((Container) root).getComponents()); + } + + private void injectComponents(Component[] components) { + for (Component component : components) { + injectComponents(component); + } + } + + private void injectProperties(Component component) { + if (component == null) { + throw new IllegalArgumentException("null component. can't inject properties"); + } + String compName = component.getName(); + + if(compName != null && resourceExists(compName)) { + PropertyDescriptor[] pds = getComponentProperties(component); + if (pds != null && pds.length > 0) { + for (String key : resources.stringPropertyNames()) { + int index = key.lastIndexOf("."); + String keyComponent = (index < 0) ? null : key.substring(0, index); + + if (compName.equals(keyComponent)) { + index++; + + if (index == key.length()) { + String msg = "component resource does not have a property name"; + logger.warning(msg); + } else { + String propertyName = key.substring(index); + + for (PropertyDescriptor pd : pds) { + String pd_name = pd.getName(); + if (pd_name.equals(propertyName)) { + injectProperty(component, pd, key); + return; + } + } + + String msg = String.format("Component '%s' does not have a Property '%s'.", compName, propertyName); + logger.warning(msg); + } + } + } + } + } + } + + private void injectProperty(Component comp, PropertyDescriptor pd, String key) { + // System.out.println("Injecting: " + key + " with " + resources.getString(key)); + TrickAction.configureMnemonic(comp, resources.getString(key)); + } + + private PropertyDescriptor[] getComponentProperties(Component comp) { + try { + BeanInfo info = Introspector.getBeanInfo(comp.getClass()); + return info.getPropertyDescriptors(); + } catch(IntrospectionException ie) { + String msg = "introspection failed"; + System.err.println(msg); + return null; + } + } + + private boolean resourceExists(String name) { + for(String key : resources.stringPropertyNames()) { + int index = key.lastIndexOf("."); + if(index >= 0 && name.equals(key.substring(0, index))) + return true; + } + return false; } private TrickResources parseResources(Class app) throws IOException, FileNotFoundException { diff --git a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java index d7acc617f..e60612cf3 100644 --- a/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java +++ b/trick_source/java/src/main/java/trick/common/framework/BaseApplication.java @@ -151,7 +151,7 @@ public void saveSession(Window win) { //======================================== protected void configureWindow(Window root) { - context.addComponent(root); + context.injectComponents(root); } protected void end() { diff --git a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java index a231b472e..354c21488 100644 --- a/trick_source/java/src/main/java/trick/common/utils/TrickAction.java +++ b/trick_source/java/src/main/java/trick/common/utils/TrickAction.java @@ -85,17 +85,16 @@ private void applyProperties() { public static void configureMnemonic(Object target, String text) { String name; - int mnemIndex, mnemKey; + int mnemIndex = -1, mnemKey = KeyEvent.VK_UNDEFINED; name = text; mnemIndex = name.indexOf("&"); mnemIndex = mnemIndex < 0 ? name.indexOf("_") : mnemIndex; - if (mnemIndex < 0) return; - - name = name.substring(0, mnemIndex) + name.substring(mnemIndex + 1); - - mnemKey = KeyEvent.getExtendedKeyCodeForChar(name.charAt(mnemIndex)); + if (mnemIndex >= 0) { + name = name.substring(0, mnemIndex) + name.substring(mnemIndex + 1); + mnemKey = KeyEvent.getExtendedKeyCodeForChar(name.charAt(mnemIndex)); + } if(target instanceof Action) { Action act = (Action) target; From f88e5fba6f1dc80e7d7fd4222d2569e05a3d28e3 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Thu, 8 Aug 2024 11:08:19 -0400 Subject: [PATCH 23/23] A bit of code cleanup --- .../java/src/main/java/trick/common/framework/AppContext.java | 1 - 1 file changed, 1 deletion(-) diff --git a/trick_source/java/src/main/java/trick/common/framework/AppContext.java b/trick_source/java/src/main/java/trick/common/framework/AppContext.java index 226627afa..454b87e55 100644 --- a/trick_source/java/src/main/java/trick/common/framework/AppContext.java +++ b/trick_source/java/src/main/java/trick/common/framework/AppContext.java @@ -102,7 +102,6 @@ public TaskService getTaskService() { /** * Add the properties of the given component and any of its children to the resources */ - // TODO: Implement this public void injectComponents(Component root) { if (root == null) { throw new IllegalArgumentException("null component. can't inject");