From 25e2a2af3e9f13af4b4533ea9ac31acb55a251a1 Mon Sep 17 00:00:00 2001 From: Peter Jakubco Date: Tue, 29 Aug 2023 06:41:12 +0200 Subject: [PATCH] [#314, #342] Fix audio tape GUI --- .../application/gui/ToolbarToggleButton.java | 2 +- .../application/gui/dialogs/AboutDialog.java | 2 +- .../application/gui/dialogs/AutoDialog.java | 2 +- .../application/gui/dialogs/StudioFrame.java | 2 +- .../gui/dialogs/ViewComputerDialog.java | 10 +- .../compiler/as8080/e2e/IncludeTest.java | 20 +-- .../compiler/as8080/e2e/PseudoOrgTest.java | 4 +- .../compiler/asZ80/e2e/IncludeTest.java | 20 +-- .../compiler/asZ80/e2e/PseudoOrgTest.java | 4 +- .../device/abstracttape/gui/TapeGui.java | 4 +- .../device/adm3a/gui/TerminalWindow.java | 6 +- .../audiotape_player/gui/TapePlayerGui.java | 120 +++++++++--------- .../device/vt100/gui/TerminalWindow.java | 6 +- 13 files changed, 99 insertions(+), 103 deletions(-) diff --git a/application/src/main/java/net/emustudio/application/gui/ToolbarToggleButton.java b/application/src/main/java/net/emustudio/application/gui/ToolbarToggleButton.java index c1d36ffd8..6787f7db8 100644 --- a/application/src/main/java/net/emustudio/application/gui/ToolbarToggleButton.java +++ b/application/src/main/java/net/emustudio/application/gui/ToolbarToggleButton.java @@ -34,7 +34,7 @@ public void actionPerformed(ActionEvent actionEvent) { action.accept(actionEvent); } }); - setIcon(new ImageIcon(getClass().getResource(iconResource))); + setIcon(new ImageIcon(ClassLoader.getSystemResource(iconResource))); setToolTipText(tooltipText); setFocusable(false); diff --git a/application/src/main/java/net/emustudio/application/gui/dialogs/AboutDialog.java b/application/src/main/java/net/emustudio/application/gui/dialogs/AboutDialog.java index b4aa55ac5..716164f8a 100644 --- a/application/src/main/java/net/emustudio/application/gui/dialogs/AboutDialog.java +++ b/application/src/main/java/net/emustudio/application/gui/dialogs/AboutDialog.java @@ -51,7 +51,7 @@ private void initComponents() { lblLogo.setBackground(Color.WHITE); lblLogo.setHorizontalAlignment(SwingConstants.CENTER); - lblLogo.setIcon(new ImageIcon(getClass().getResource("/net/emustudio/application/gui/dialogs/logo.png"))); + lblLogo.setIcon(new ImageIcon(ClassLoader.getSystemResource("/net/emustudio/application/gui/dialogs/logo.png"))); lblLogo.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); lblLogo.setDoubleBuffered(true); lblLogo.setFocusable(false); diff --git a/application/src/main/java/net/emustudio/application/gui/dialogs/AutoDialog.java b/application/src/main/java/net/emustudio/application/gui/dialogs/AutoDialog.java index 4d8a1ed0a..94fa053cc 100644 --- a/application/src/main/java/net/emustudio/application/gui/dialogs/AutoDialog.java +++ b/application/src/main/java/net/emustudio/application/gui/dialogs/AutoDialog.java @@ -48,7 +48,7 @@ private void initComponents() { setResizable(false); lblPerforming.setFont(lblPerforming.getFont().deriveFont(lblPerforming.getFont().getStyle() | java.awt.Font.BOLD)); - lblPerforming.setIcon(new ImageIcon(getClass().getResource("/net/emustudio/application/gui/dialogs/motherboard-icon.gif"))); + lblPerforming.setIcon(new ImageIcon(ClassLoader.getSystemResource("/net/emustudio/application/gui/dialogs/motherboard-icon.gif"))); lblPerforming.setText("Running automatic emulation, please wait..."); lblAction.setText("Initializing..."); diff --git a/application/src/main/java/net/emustudio/application/gui/dialogs/StudioFrame.java b/application/src/main/java/net/emustudio/application/gui/dialogs/StudioFrame.java index 7688c7115..2a68d531c 100644 --- a/application/src/main/java/net/emustudio/application/gui/dialogs/StudioFrame.java +++ b/application/src/main/java/net/emustudio/application/gui/dialogs/StudioFrame.java @@ -121,7 +121,7 @@ private void resizeComponents() { } private void initComponents() { - setIconImage(new ImageIcon(getClass().getResource("/net/emustudio/application/gui/favicon16.png")).getImage()); + setIconImage(new ImageIcon(ClassLoader.getSystemResource("/net/emustudio/application/gui/favicon16.png")).getImage()); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); diff --git a/application/src/main/java/net/emustudio/application/gui/dialogs/ViewComputerDialog.java b/application/src/main/java/net/emustudio/application/gui/dialogs/ViewComputerDialog.java index 97a42f34a..f4103a0ee 100644 --- a/application/src/main/java/net/emustudio/application/gui/dialogs/ViewComputerDialog.java +++ b/application/src/main/java/net/emustudio/application/gui/dialogs/ViewComputerDialog.java @@ -161,14 +161,14 @@ private void initComponents() { jToolBar1.setDoubleBuffered(true); buttonGroup1.add(btnCompiler); - btnCompiler.setIcon(new ImageIcon(getClass().getResource("/net/emustudio/application/gui/dialogs/compile.png"))); + btnCompiler.setIcon(new ImageIcon(ClassLoader.getSystemResource("/net/emustudio/application/gui/dialogs/compile.png"))); btnCompiler.setToolTipText("Compiler information"); btnCompiler.setFocusable(false); btnCompiler.addActionListener(this::btnCompilerActionPerformed); jToolBar1.add(btnCompiler); buttonGroup1.add(btnCPU); - btnCPU.setIcon(new ImageIcon(getClass().getResource("/net/emustudio/application/gui/dialogs/cpu.gif"))); + btnCPU.setIcon(new ImageIcon(ClassLoader.getSystemResource("/net/emustudio/application/gui/dialogs/cpu.gif"))); btnCPU.setSelected(true); btnCPU.setToolTipText("CPU information"); btnCPU.setFocusable(false); @@ -176,14 +176,14 @@ private void initComponents() { jToolBar1.add(btnCPU); buttonGroup1.add(btnMemory); - btnMemory.setIcon(new ImageIcon(getClass().getResource("/net/emustudio/application/gui/dialogs/ram.gif"))); + btnMemory.setIcon(new ImageIcon(ClassLoader.getSystemResource("/net/emustudio/application/gui/dialogs/ram.gif"))); btnMemory.setToolTipText("Memory information"); btnMemory.setFocusable(false); btnMemory.addActionListener(this::btnMemoryActionPerformed); jToolBar1.add(btnMemory); buttonGroup1.add(btnDevice); - btnDevice.setIcon(new ImageIcon(getClass().getResource("/net/emustudio/application/gui/dialogs/device.png"))); + btnDevice.setIcon(new ImageIcon(ClassLoader.getSystemResource("/net/emustudio/application/gui/dialogs/device.png"))); btnDevice.setToolTipText("Devices information"); btnDevice.setFocusable(false); btnDevice.addActionListener(this::btnDeviceActionPerformed); @@ -291,7 +291,7 @@ private void initComponents() { jToolBar2.setOrientation(SwingConstants.VERTICAL); jToolBar2.setRollover(true); - btnSaveSchema.setIcon(new ImageIcon(getClass().getResource("/net/emustudio/application/gui/dialogs/document-save.png"))); + btnSaveSchema.setIcon(new ImageIcon(ClassLoader.getSystemResource("/net/emustudio/application/gui/dialogs/document-save.png"))); btnSaveSchema.setToolTipText("Save schema image"); btnSaveSchema.setFocusable(false); btnSaveSchema.setHorizontalTextPosition(SwingConstants.CENTER); diff --git a/plugins/compiler/as-8080/src/test/java/net/emustudio/plugins/compiler/as8080/e2e/IncludeTest.java b/plugins/compiler/as-8080/src/test/java/net/emustudio/plugins/compiler/as8080/e2e/IncludeTest.java index 8efc56cfa..c12dc599a 100644 --- a/plugins/compiler/as-8080/src/test/java/net/emustudio/plugins/compiler/as8080/e2e/IncludeTest.java +++ b/plugins/compiler/as-8080/src/test/java/net/emustudio/plugins/compiler/as8080/e2e/IncludeTest.java @@ -26,7 +26,7 @@ public class IncludeTest extends AbstractCompilerTest { @Test public void testIncludeAndForwardCall() throws Exception { - File includeFile = new File(getClass().getResource("/sample.asm").toURI()); + File includeFile = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); compile( "call sample\n" + "include '" + includeFile.getAbsolutePath() + "'\n" @@ -36,7 +36,7 @@ public void testIncludeAndForwardCall() throws Exception { @Test public void testCallDataInclude() throws Exception { - File includeFile = new File(getClass().getResource("/sample.asm").toURI()); + File includeFile = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); compile( "call sample\n" + "label: db 'hello'\n" + @@ -49,8 +49,8 @@ public void testCallDataInclude() throws Exception { @Test public void testDoubleIncludeAndForwardCall() throws Exception { - File first = new File(getClass().getResource("/sample.asm").toURI()); - File second = new File(getClass().getResource("/sample2.asm").toURI()); + File first = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); + File second = new File(ClassLoader.getSystemResource("/sample2.asm").toURI()); compile( "call sample2\n" + "include '" + first.getAbsolutePath() + "'\n" @@ -64,7 +64,7 @@ public void testDoubleIncludeAndForwardCall() throws Exception { @Test public void testIncludeAndBackwardCall() throws Exception { - File includeFile = new File(getClass().getResource("/sample.asm").toURI()); + File includeFile = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); compile( "include '" + includeFile.getAbsolutePath() + "'\n" + "call sample\n" @@ -77,8 +77,8 @@ public void testIncludeAndBackwardCall() throws Exception { @Test public void testDoubleIncludeAndBackwardCall() throws Exception { - File first = new File(getClass().getResource("/sample.asm").toURI()); - File second = new File(getClass().getResource("/sample2.asm").toURI()); + File first = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); + File second = new File(ClassLoader.getSystemResource("/sample2.asm").toURI()); compile( "include '" + first.getAbsolutePath() + "'\n" + "include '" + second.getAbsolutePath() + "'\n" @@ -92,7 +92,7 @@ public void testDoubleIncludeAndBackwardCall() throws Exception { @Test public void testIncludeAndJMPafter() throws Exception { - File includeFile = new File(getClass().getResource("/sample.asm").toURI()); + File includeFile = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); compile( "jmp next\n" + "include '" + includeFile.getAbsolutePath() + "'\n" @@ -107,8 +107,8 @@ public void testIncludeAndJMPafter() throws Exception { @Test public void testDoubleIncludeAndJMPafter() throws Exception { - File first = new File(getClass().getResource("/sample.asm").toURI()); - File second = new File(getClass().getResource("/sample2.asm").toURI()); + File first = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); + File second = new File(ClassLoader.getSystemResource("/sample2.asm").toURI()); compile( "jmp next\n" + "include '" + first.getAbsolutePath() + "'\n" diff --git a/plugins/compiler/as-8080/src/test/java/net/emustudio/plugins/compiler/as8080/e2e/PseudoOrgTest.java b/plugins/compiler/as-8080/src/test/java/net/emustudio/plugins/compiler/as8080/e2e/PseudoOrgTest.java index 5e55e1391..f8898b90f 100644 --- a/plugins/compiler/as-8080/src/test/java/net/emustudio/plugins/compiler/as8080/e2e/PseudoOrgTest.java +++ b/plugins/compiler/as-8080/src/test/java/net/emustudio/plugins/compiler/as8080/e2e/PseudoOrgTest.java @@ -30,8 +30,8 @@ public class PseudoOrgTest extends AbstractCompilerTest { @Before public void setup() { - sampleFile = Objects.requireNonNull(getClass().getResource("/sample.asm")).getFile(); - sample2File = Objects.requireNonNull(getClass().getResource("/sample2.asm")).getFile(); + sampleFile = Objects.requireNonNull(ClassLoader.getSystemResource("/sample.asm")).getFile(); + sample2File = Objects.requireNonNull(ClassLoader.getSystemResource("/sample2.asm")).getFile(); } diff --git a/plugins/compiler/as-z80/src/test/java/net/emustudio/plugins/compiler/asZ80/e2e/IncludeTest.java b/plugins/compiler/as-z80/src/test/java/net/emustudio/plugins/compiler/asZ80/e2e/IncludeTest.java index ece385942..26e5ab0de 100644 --- a/plugins/compiler/as-z80/src/test/java/net/emustudio/plugins/compiler/asZ80/e2e/IncludeTest.java +++ b/plugins/compiler/as-z80/src/test/java/net/emustudio/plugins/compiler/asZ80/e2e/IncludeTest.java @@ -26,7 +26,7 @@ public class IncludeTest extends AbstractCompilerTest { @Test public void testIncludeAndForwardCall() throws Exception { - File includeFile = new File(getClass().getResource("/sample.asm").toURI()); + File includeFile = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); compile( "call sample\n" + "include '" + includeFile.getAbsolutePath() + "'\n" @@ -39,7 +39,7 @@ public void testIncludeAndForwardCall() throws Exception { @Test public void testCallDataInclude() throws Exception { - File includeFile = new File(getClass().getResource("/sample.asm").toURI()); + File includeFile = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); compile( "call sample\n" + "label: db 'hello'\n" + @@ -52,8 +52,8 @@ public void testCallDataInclude() throws Exception { @Test public void testDoubleIncludeAndForwardCall() throws Exception { - File first = new File(getClass().getResource("/sample.asm").toURI()); - File second = new File(getClass().getResource("/sample2.asm").toURI()); + File first = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); + File second = new File(ClassLoader.getSystemResource("/sample2.asm").toURI()); compile( "call sample2\n" + "include '" + first.getAbsolutePath() + "'\n" @@ -67,7 +67,7 @@ public void testDoubleIncludeAndForwardCall() throws Exception { @Test public void testIncludeAndBackwardCall() throws Exception { - File includeFile = new File(getClass().getResource("/sample.asm").toURI()); + File includeFile = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); compile( "include '" + includeFile.getAbsolutePath() + "'\n" + "call sample\n" @@ -80,8 +80,8 @@ public void testIncludeAndBackwardCall() throws Exception { @Test public void testDoubleIncludeAndBackwardCall() throws Exception { - File first = new File(getClass().getResource("/sample.asm").toURI()); - File second = new File(getClass().getResource("/sample2.asm").toURI()); + File first = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); + File second = new File(ClassLoader.getSystemResource("/sample2.asm").toURI()); compile( "include '" + first.getAbsolutePath() + "'\n" + "include '" + second.getAbsolutePath() + "'\n" @@ -95,7 +95,7 @@ public void testDoubleIncludeAndBackwardCall() throws Exception { @Test public void testIncludeAndJMPafter() throws Exception { - File includeFile = new File(getClass().getResource("/sample.asm").toURI()); + File includeFile = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); compile( "jp next\n" + "include '" + includeFile.getAbsolutePath() + "'\n" @@ -110,8 +110,8 @@ public void testIncludeAndJMPafter() throws Exception { @Test public void testDoubleIncludeAndJMPafter() throws Exception { - File first = new File(getClass().getResource("/sample.asm").toURI()); - File second = new File(getClass().getResource("/sample2.asm").toURI()); + File first = new File(ClassLoader.getSystemResource("/sample.asm").toURI()); + File second = new File(ClassLoader.getSystemResource("/sample2.asm").toURI()); compile( "jp next\n" + "include '" + first.getAbsolutePath() + "'\n" diff --git a/plugins/compiler/as-z80/src/test/java/net/emustudio/plugins/compiler/asZ80/e2e/PseudoOrgTest.java b/plugins/compiler/as-z80/src/test/java/net/emustudio/plugins/compiler/asZ80/e2e/PseudoOrgTest.java index 2c318b16b..198bede0b 100644 --- a/plugins/compiler/as-z80/src/test/java/net/emustudio/plugins/compiler/asZ80/e2e/PseudoOrgTest.java +++ b/plugins/compiler/as-z80/src/test/java/net/emustudio/plugins/compiler/asZ80/e2e/PseudoOrgTest.java @@ -30,8 +30,8 @@ public class PseudoOrgTest extends AbstractCompilerTest { @Before public void setup() { - sampleFile = Objects.requireNonNull(getClass().getResource("/sample.asm")).getFile(); - sample2File = Objects.requireNonNull(getClass().getResource("/sample2.asm")).getFile(); + sampleFile = Objects.requireNonNull(ClassLoader.getSystemResource("/sample.asm")).getFile(); + sample2File = Objects.requireNonNull(ClassLoader.getSystemResource("/sample2.asm")).getFile(); } diff --git a/plugins/device/abstract-tape/src/main/java/net/emustudio/plugins/device/abstracttape/gui/TapeGui.java b/plugins/device/abstract-tape/src/main/java/net/emustudio/plugins/device/abstracttape/gui/TapeGui.java index 76ddbe7d8..aaa31c033 100644 --- a/plugins/device/abstract-tape/src/main/java/net/emustudio/plugins/device/abstracttape/gui/TapeGui.java +++ b/plugins/device/abstract-tape/src/main/java/net/emustudio/plugins/device/abstracttape/gui/TapeGui.java @@ -87,7 +87,7 @@ private void initComponents() { lstTape.setCellRenderer(new TapeCellRenderer(tapeContext)); scrollTape.setViewportView(lstTape); - btnAddFirst.setIcon(new ImageIcon(getClass().getResource("/net/emustudio/plugins/device/abstracttape/gui/go-up.png"))); + btnAddFirst.setIcon(new ImageIcon(ClassLoader.getSystemResource("/net/emustudio/plugins/device/abstracttape/gui/go-up.png"))); btnAddFirst.addActionListener(e -> dialogs .readString("Symbol value:", "Add symbol (on top)") .map(TapeSymbol::guess) @@ -99,7 +99,7 @@ private void initComponents() { } })); - btnAddLast.setIcon(new ImageIcon(getClass().getResource("/net/emustudio/plugins/device/abstracttape/gui/go-down.png"))); + btnAddLast.setIcon(new ImageIcon(ClassLoader.getSystemResource("/net/emustudio/plugins/device/abstracttape/gui/go-down.png"))); btnAddLast.addActionListener(e -> dialogs .readString("Symbol value:", "Add symbol (on bottom)") .map(TapeSymbol::guess) diff --git a/plugins/device/adm3A-terminal/src/main/java/net/emustudio/plugins/device/adm3a/gui/TerminalWindow.java b/plugins/device/adm3A-terminal/src/main/java/net/emustudio/plugins/device/adm3a/gui/TerminalWindow.java index 080881188..30feece43 100644 --- a/plugins/device/adm3A-terminal/src/main/java/net/emustudio/plugins/device/adm3a/gui/TerminalWindow.java +++ b/plugins/device/adm3A-terminal/src/main/java/net/emustudio/plugins/device/adm3a/gui/TerminalWindow.java @@ -69,7 +69,7 @@ public void setDisplayFont(DisplayFont displayFont) { private void initComponents() { JLabel lblBack = new JLabel(); - ImageIcon backgroundImage = new ImageIcon(getClass().getResource(BACKGROUND_IMAGE)); + ImageIcon backgroundImage = new ImageIcon(ClassLoader.getSystemResource(BACKGROUND_IMAGE)); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setTitle("LSI ADM-3A"); @@ -89,13 +89,13 @@ private void initComponents() { JButton btnClear = new JButton(); btnClear.setFocusable(false); - btnClear.setIcon(new ImageIcon(getClass().getResource(CLEAR_SCREEN_ICON))); + btnClear.setIcon(new ImageIcon(ClassLoader.getSystemResource(CLEAR_SCREEN_ICON))); btnClear.setToolTipText("Clear screen"); btnClear.addActionListener(e -> clearScreen()); JButton btnRoll = new JButton(); btnRoll.setFocusable(false); - btnRoll.setIcon(new ImageIcon(getClass().getResource(ROLL_LINE_ICON))); + btnRoll.setIcon(new ImageIcon(ClassLoader.getSystemResource(ROLL_LINE_ICON))); btnRoll.setToolTipText("Roll line up"); btnRoll.addActionListener(e -> rollLine()); diff --git a/plugins/device/audiotape-player/src/main/java/net/emustudio/plugins/device/audiotape_player/gui/TapePlayerGui.java b/plugins/device/audiotape-player/src/main/java/net/emustudio/plugins/device/audiotape_player/gui/TapePlayerGui.java index 176597872..d79a6f530 100644 --- a/plugins/device/audiotape-player/src/main/java/net/emustudio/plugins/device/audiotape_player/gui/TapePlayerGui.java +++ b/plugins/device/audiotape-player/src/main/java/net/emustudio/plugins/device/audiotape_player/gui/TapePlayerGui.java @@ -1,20 +1,21 @@ package net.emustudio.plugins.device.audiotape_player.gui; -import java.awt.*; -import java.awt.event.*; -import java.nio.file.Path; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicReference; -import javax.swing.*; -import javax.swing.border.*; - import net.emustudio.emulib.runtime.interaction.BrowseButton; import net.emustudio.emulib.runtime.interaction.CachedComboBoxModel; import net.emustudio.emulib.runtime.interaction.Dialogs; import net.emustudio.emulib.runtime.interaction.ShortenedString; import net.emustudio.plugins.device.audiotape_player.TapePlaybackController; -import net.miginfocom.swing.*; +import net.miginfocom.swing.MigLayout; + +import javax.swing.*; +import javax.swing.border.TitledBorder; +import java.awt.*; +import java.awt.event.*; +import java.nio.file.Path; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; +// https://stackoverflow.com/questions/25010068/miglayout-push-vs-grow public class TapePlayerGui extends JDialog { private final static String FOLDER_OPEN_ICON = "/net/emustudio/plugins/device/audiotape_player/gui/folder-open.png"; private final static String PLAY_ICON = "/net/emustudio/plugins/device/audiotape_player/gui/media-playback-start.png"; @@ -25,8 +26,8 @@ public class TapePlayerGui extends JDialog { private final JPanel panelTapeInfo = new JPanel(); private final JButton btnBrowse; - private final JButton btnRefresh = new JButton("Refresh"); - private final JButton btnLoad = new JButton("Load"); + private final JButton btnRefresh = new JButton("Refresh", new ImageIcon(ClassLoader.getSystemResource(REFRESH_ICON))); + private final JButton btnLoad = new JButton("Load", new ImageIcon(ClassLoader.getSystemResource(LOAD_ICON))); private final CachedComboBoxModel> cmbDirsModel = new CachedComboBoxModel<>(); private final JComboBox> cmbDirs = new JComboBox<>(cmbDirsModel); private final TapesListModel lstTapesModel = new TapesListModel(); @@ -35,9 +36,9 @@ public class TapePlayerGui extends JDialog { private final AtomicReference> loadedFileName = new AtomicReference<>(); - private final JButton btnPlay = new JButton("Play"); - private final JButton btnStop = new JButton("Stop"); - private final JButton btnEject = new JButton("Eject"); + private final JButton btnPlay = new JButton("Play", new ImageIcon(ClassLoader.getSystemResource(PLAY_ICON))); + private final JButton btnStop = new JButton("Stop", new ImageIcon(ClassLoader.getSystemResource(STOP_ICON))); + private final JButton btnEject = new JButton("Eject", new ImageIcon(ClassLoader.getSystemResource(EJECT_ICON))); private final JTextArea txtFileName = new JTextArea("N/A"); private final JLabel lblStatus = new JLabel("Stopped"); @@ -46,26 +47,27 @@ public class TapePlayerGui extends JDialog { private final TapePlaybackController controller; - public TapePlayerGui(JFrame parent, Dialogs dialogs, TapePlaybackController controller) { - super(parent, "Audio Tape Player"); + public TapePlayerGui(JFrame parent, Dialogs dialogs, TapePlaybackController controller) { + super(parent, "Audio Tape Player"); Objects.requireNonNull(dialogs); this.controller = Objects.requireNonNull(controller); btnBrowse = new BrowseButton(dialogs, "Select Directory", "Select", p -> { ShortenedString ps = new ShortenedString<>(p, Path::toString); - ps.deriveMaxStringLength(cmbDirs, cmbDirs.getWidth()); + ps.deriveMaxStringLength(cmbDirs, cmbDirs.getWidth() - 36); cmbDirsModel.add(ps); cmbDirs.setSelectedIndex(0); + cmbDirs.setMinimumSize(new Dimension(0, 0)); }); - btnBrowse.setIcon(new ImageIcon(getClass().getResource(FOLDER_OPEN_ICON))); + btnBrowse.setIcon(new ImageIcon(ClassLoader.getSystemResource(FOLDER_OPEN_ICON))); btnBrowse.setText(""); btnBrowse.setToolTipText("Select directory"); btnBrowse.setFocusPainted(false); - initComponents(); + initComponents(); setupListeners(); setCassetteState(controller.getState()); - } + } public void addProgramDetail(String program, String detail) { txtEvents.append("\n" + program + ": " + detail); @@ -196,39 +198,34 @@ public void componentResized(ComponentEvent e) { btnEject.addActionListener(e -> controller.stop(true)); } - private void initComponents() { - JPanel panelAvailableTapes = new JPanel(); - JPanel panelDirs = new JPanel(); - JToolBar toolbarAvailableTapes = new JToolBar(); - JPanel panelTape = new JPanel(); + private void initComponents() { + JPanel panelAvailableTapes = new JPanel(); + JPanel panelDirs = new JPanel(); + JToolBar toolbarAvailableTapes = new JToolBar(); + JPanel panelTape = new JPanel(); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, panelAvailableTapes, panelTape); - JLabel lblFileNameLabel = new JLabel("File name:"); - JLabel lblStatusLabel = new JLabel("Status:"); - JScrollPane scrollEvents = new JScrollPane(txtEvents); - JToolBar toolbarTape = new JToolBar(); - JPanel hSpacer1 = new JPanel(null); + JLabel lblFileNameLabel = new JLabel("File name:"); + JLabel lblStatusLabel = new JLabel("Status:"); + JScrollPane scrollEvents = new JScrollPane(txtEvents); + JToolBar toolbarTape = new JToolBar(); + JPanel hSpacer1 = new JPanel(null); JPanel hSpacer2 = new JPanel(null); - Container contentPane = getContentPane(); - contentPane.setLayout(new MigLayout("insets dialog, fill", "[fill]", "[fill]")); + Container contentPane = getContentPane(); + contentPane.setLayout(new MigLayout("insets dialog, fill", "[fill]", "[fill]")); splitPane.setDividerLocation(250); splitPane.setResizeWeight(0.3); splitPane.setDividerLocation(0.3); - panelAvailableTapes.setBorder(new TitledBorder("Available tapes")); - panelAvailableTapes.setLayout(new MigLayout("fill,insets 2", "[fill, grow]")); - - panelDirs.setLayout(new MigLayout("fillx, hidemode 3", "[grow, fill][]", "[]")); - panelDirs.add(cmbDirs); + cmbDirs.setMinimumSize(new Dimension(0, 0)); + panelDirs.setLayout(new MigLayout("fillx", "[fill, grow][]", "[]")); + panelDirs.add(cmbDirs, "cell 0 0"); JToolBar btnBrowseToolBar = new JToolBar(); btnBrowseToolBar.add(btnBrowse); btnBrowseToolBar.setFloatable(false); - panelDirs.add(btnBrowseToolBar); - - btnRefresh.setIcon(new ImageIcon(getClass().getResource(REFRESH_ICON))); - btnLoad.setIcon(new ImageIcon(getClass().getResource(LOAD_ICON))); + panelDirs.add(btnBrowseToolBar, "cell 1 0"); toolbarAvailableTapes.add(btnRefresh); toolbarAvailableTapes.add(hSpacer2); @@ -237,18 +234,13 @@ private void initComponents() { lstTapes.setCellRenderer(new TapesListRenderer()); - panelAvailableTapes.add(panelDirs, "cell 0 0, growx, pushx"); - panelAvailableTapes.add(scrollTapes, "cell 0 1, growy, pushy"); - panelAvailableTapes.add(toolbarAvailableTapes, "cell 0 2"); + panelAvailableTapes.setBorder(new TitledBorder("Available tapes")); + panelAvailableTapes.setLayout(new MigLayout("insets 2", "[grow]", "[][grow][]")); + panelAvailableTapes.add(panelDirs, "cell 0 0, growx"); + panelAvailableTapes.add(scrollTapes, "cell 0 1, grow"); + panelAvailableTapes.add(toolbarAvailableTapes, "cell 0 2, growx"); splitPane.setLeftComponent(panelAvailableTapes); - panelTape.setBorder(new TitledBorder("Audio Tape")); - panelTape.setLayout(new MigLayout("fill,insets 2,debug", "[fill]", "[][][]")); - - btnPlay.setIcon(new ImageIcon(getClass().getResource(PLAY_ICON))); - btnStop.setIcon(new ImageIcon(getClass().getResource(STOP_ICON))); - btnEject.setIcon(new ImageIcon(getClass().getResource(EJECT_ICON))); - toolbarTape.add(btnPlay); toolbarTape.add(btnStop); toolbarTape.addSeparator(); @@ -260,24 +252,28 @@ private void initComponents() { txtFileName.setEditable(false); txtFileName.setLineWrap(true); + txtFileName.setMinimumSize(new Dimension(0, 0)); txtFileName.setBackground(UIManager.getColor("Panel.background")); + lblStatus.setMinimumSize(new Dimension(0, 0)); - panelTapeInfo.setLayout(new MigLayout("fillx, debug","[][fill]", "[][]")); - panelTapeInfo.add(lblFileNameLabel, "cell 0 0,alignx right,growx 0"); + panelTapeInfo.setLayout(new MigLayout("", "[][grow]", "[][]")); + panelTapeInfo.add(lblFileNameLabel, "cell 0 0, alignx right"); panelTapeInfo.add(txtFileName, "cell 1 0, growx"); - panelTapeInfo.add(lblStatusLabel, "cell 0 1,alignx right,growx 0"); - panelTapeInfo.add(lblStatus, "cell 1 1,growx"); + panelTapeInfo.add(lblStatusLabel, "cell 0 1, alignx right"); + panelTapeInfo.add(lblStatus, "cell 1 1, growx"); - panelTape.add(panelTapeInfo, "cell 0 0"); - panelTape.add(scrollEvents, "cell 0 1, growy, pushy"); - panelTape.add(toolbarTape, "cell 0 2"); + panelTape.setBorder(new TitledBorder("Audio Tape")); + panelTape.setLayout(new MigLayout("insets 2", "[grow]", "[][grow][]")); + panelTape.add(panelTapeInfo, "cell 0 0, growx"); + panelTape.add(scrollEvents, "cell 0 1, grow"); + panelTape.add(toolbarTape, "cell 0 2, growx"); splitPane.setRightComponent(panelTape); - contentPane.add(splitPane, "cell 0 0, push, grow"); + contentPane.add(splitPane, "push, grow"); - pack(); - setLocationRelativeTo(getOwner()); + pack(); + setLocationRelativeTo(getOwner()); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getRootPane().registerKeyboardAction(e -> dispose(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); - } + } } diff --git a/plugins/device/vt100-terminal/src/main/java/net/emustudio/plugins/device/vt100/gui/TerminalWindow.java b/plugins/device/vt100-terminal/src/main/java/net/emustudio/plugins/device/vt100/gui/TerminalWindow.java index 7272cdec0..7f28aa67e 100644 --- a/plugins/device/vt100-terminal/src/main/java/net/emustudio/plugins/device/vt100/gui/TerminalWindow.java +++ b/plugins/device/vt100-terminal/src/main/java/net/emustudio/plugins/device/vt100/gui/TerminalWindow.java @@ -44,10 +44,10 @@ public TerminalWindow(JFrame parent, DisplayImpl display, Dialogs dialogs, Keybo this.keyboard = Objects.requireNonNull(keyboard); this.dialogs = Objects.requireNonNull(dialogs); - URL blueIconURL = getClass().getResource( + URL blueIconURL = ClassLoader.getSystemResource( "/net/emustudio/plugins/device/vt100/16_circle_blue.png" ); - URL redIconURL = getClass().getResource( + URL redIconURL = ClassLoader.getSystemResource( "/net/emustudio/plugins/device/vt100/16_circle_red.png" ); @@ -91,7 +91,7 @@ private void initComponents() { lblStatusIcon.setVerticalAlignment(SwingConstants.TOP); btnASCII.setFont(btnASCII.getFont()); - btnASCII.setIcon(new ImageIcon(getClass().getResource("/net/emustudio/plugins/device/vt100/16_ascii.png"))); + btnASCII.setIcon(new ImageIcon(ClassLoader.getSystemResource("/net/emustudio/plugins/device/vt100/16_ascii.png"))); btnASCII.setToolTipText("Input by ASCII code"); btnASCII.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); btnASCII.setEnabled(false);