Skip to content

Issue #189 Enhancement: Added GUI scale button to settings #227

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/rars/venus/VenusUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class VenusUI extends JFrame {
private JCheckBoxMenuItem settingsLabel, settingsPopupInput, settingsValueDisplayBase, settingsAddressDisplayBase,
settingsExtended, settingsAssembleOnOpen, settingsAssembleAll, settingsAssembleOpen, settingsWarningsAreErrors,
settingsStartAtMain, settingsProgramArguments, settingsSelfModifyingCode, settingsRV64, settingsDeriveCurrentWorkingDirectory;
private JMenuItem settingsExceptionHandler, settingsEditor, settingsHighlighting, settingsMemoryConfiguration;
private JMenuItem settingsExceptionHandler, settingsEditor, settingsHighlighting, settingsMemoryConfiguration, settingsScaleConfiguration;
private JMenuItem helpHelp, helpAbout;

// components of the toolbar
Expand All @@ -110,7 +110,7 @@ public class VenusUI extends JFrame {
settingsExtendedAction, settingsAssembleOnOpenAction, settingsAssembleOpenAction, settingsAssembleAllAction,
settingsWarningsAreErrorsAction, settingsStartAtMainAction, settingsProgramArgumentsAction,
settingsExceptionHandlerAction, settingsEditorAction, settingsHighlightingAction, settingsMemoryConfigurationAction,
settingsSelfModifyingCodeAction, settingsRV64Action, settingsDeriveCurrentWorkingDirectoryAction;
settingsScaleAction, settingsSelfModifyingCodeAction, settingsRV64Action, settingsDeriveCurrentWorkingDirectoryAction;
private Action helpHelpAction, helpAboutAction;


Expand Down Expand Up @@ -493,6 +493,8 @@ public void handler(boolean value) {
null, null
);

settingsScaleAction = new SettingsScaleAction("Scale GUI", null, "Scale the GUI by a factor of 2 (Relaunches the application)", null, null);

helpHelpAction = new HelpHelpAction("Help", loadIcon("Help22.png"),
"Help", KeyEvent.VK_H, KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), mainUI);
helpAboutAction = new HelpAboutAction("About ...", null,
Expand Down Expand Up @@ -647,6 +649,8 @@ private JMenuBar setUpMenuBar() {
settingsHighlighting = new JMenuItem(settingsHighlightingAction);
settingsExceptionHandler = new JMenuItem(settingsExceptionHandlerAction);
settingsMemoryConfiguration = new JMenuItem(settingsMemoryConfigurationAction);
settingsScaleConfiguration = new JMenuItem(settingsScaleAction);


settings.add(settingsLabel);
settings.add(settingsProgramArguments);
Expand All @@ -669,6 +673,7 @@ private JMenuBar setUpMenuBar() {
settings.add(settingsHighlighting);
settings.add(settingsExceptionHandler);
settings.add(settingsMemoryConfiguration);
settings.add(settingsScaleConfiguration);

helpHelp = new JMenuItem(helpHelpAction);
helpHelp.setIcon(loadIcon("Help16.png"));//"Help16.gif"));
Expand Down Expand Up @@ -837,6 +842,7 @@ private void setMenuStateInitial() {
editFindReplaceAction.setEnabled(false);
editSelectAllAction.setEnabled(false);
settingsMemoryConfigurationAction.setEnabled(true); // added 21 July 2009
settingsScaleAction.setEnabled(true); // added 10 March 2025
runAssembleAction.setEnabled(false);
runGoAction.setEnabled(false);
runStepAction.setEnabled(false);
Expand Down Expand Up @@ -871,6 +877,7 @@ void setMenuStateNotEdited() {
editFindReplaceAction.setEnabled(true);
editSelectAllAction.setEnabled(true);
settingsMemoryConfigurationAction.setEnabled(true);
settingsScaleAction.setEnabled(true);
runAssembleAction.setEnabled(true);
// If assemble-all, allow previous Run menu settings to remain.
// Otherwise, clear them out. DPS 9-Aug-2011
Expand Down Expand Up @@ -907,6 +914,7 @@ void setMenuStateEditing() {
editFindReplaceAction.setEnabled(true);
editSelectAllAction.setEnabled(true);
settingsMemoryConfigurationAction.setEnabled(true); // added 21 July 2009
settingsScaleAction.setEnabled(true); // added 10 March 2025
runAssembleAction.setEnabled(true);
runGoAction.setEnabled(false);
runStepAction.setEnabled(false);
Expand Down Expand Up @@ -940,6 +948,7 @@ void setMenuStateEditingNew() {
editFindReplaceAction.setEnabled(true);
editSelectAllAction.setEnabled(true);
settingsMemoryConfigurationAction.setEnabled(true); // added 21 July 2009
settingsScaleAction.setEnabled(true);
runAssembleAction.setEnabled(false);
runGoAction.setEnabled(false);
runStepAction.setEnabled(false);
Expand Down Expand Up @@ -973,6 +982,7 @@ void setMenuStateRunnable() {
editFindReplaceAction.setEnabled(true);
editSelectAllAction.setEnabled(true);
settingsMemoryConfigurationAction.setEnabled(true); // added 21 July 2009
settingsScaleAction.setEnabled(true); // added 10 March 2025
runAssembleAction.setEnabled(true);
runGoAction.setEnabled(true);
runStepAction.setEnabled(true);
Expand Down Expand Up @@ -1006,6 +1016,7 @@ void setMenuStateRunning() {
editFindReplaceAction.setEnabled(false);
editSelectAllAction.setEnabled(false);
settingsMemoryConfigurationAction.setEnabled(false); // added 21 July 2009
settingsScaleAction.setEnabled(true); // added 10 March 2025
runAssembleAction.setEnabled(false);
runGoAction.setEnabled(false);
runStepAction.setEnabled(false);
Expand Down Expand Up @@ -1039,6 +1050,7 @@ void setMenuStateTerminated() {
editFindReplaceAction.setEnabled(true);
editSelectAllAction.setEnabled(true);
settingsMemoryConfigurationAction.setEnabled(true); // added 21 July 2009
settingsScaleAction.setEnabled(true); // added 10 March 2025
runAssembleAction.setEnabled(true);
runGoAction.setEnabled(false);
runStepAction.setEnabled(false);
Expand Down
111 changes: 111 additions & 0 deletions src/rars/venus/settings/SettingsScaleAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package rars.venus.settings;

import rars.Globals;
import rars.simulator.Simulator;
import rars.util.Binary;
import rars.venus.FileStatus;
import rars.venus.GuiAction;
import rars.venus.VenusUI;
import rars.Launch;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Stream;
import java.net.URI;

/*
Copyright (c) 2003-2009, Pete Sanderson and Kenneth Vollmar

Developed by Pete Sanderson ([email protected])
and Kenneth Vollmar ([email protected])

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

(MIT license, http://www.opensource.org/licenses/mit-license.html)
*/

/**
* Action class for the Settings menu item for text editor settings.
*/
public class SettingsScaleAction extends GuiAction {
/**
* Create a new SettingsEditorAction. Has all the GuiAction parameters.
*/
public SettingsScaleAction(String name, Icon icon, String descrip,
Integer mnemonic, KeyStroke accel) {
super(name, icon, descrip, mnemonic, accel);
}

/**
* When this action is triggered, scale the GUI by a factor of 2.
* This is done by relaunching the GUI.
*/
public void actionPerformed(ActionEvent e) {
try{
// Get the absolute path of the rars jar file
String jar = findJarFile().getAbsolutePath();

// Relaunch the jar with the uiScale set to 2.0
ProcessBuilder processBuilder = new ProcessBuilder(
"java", "-Dsun.java2d.uiScale=2.0", "-jar", jar);
processBuilder.start();
}
catch(Exception ex) {
// Do nothing if the above fails
}
}

/**
* This function is used by actionPerformed to find the absolute path to the rars jar file.
*/
private static File findJarFile() {
try {
// Gets the file location where the original jar was executed
URI uri = Launch.class.getProtectionDomain().getCodeSource().getLocation().toURI();
Path dir = Paths.get(uri);

// Search recursively in subdirectories for "*rars*.jar"
try (Stream<Path> paths = Files.walk(dir)) {
return paths.filter(path -> path.toString().matches("^.*rars.*\\.jar$"))
.map(Path::toFile)
.findFirst()
.orElse(null); // No matching JAR found
}
}
catch (Exception e) {
}
// Return null if the above fails.
return null;
}
}