Skip to content

Commit

Permalink
[#314] tiny refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vbmacher committed Dec 25, 2023
1 parent e5d8d3b commit 5c0f5e2
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public abstract class Element {
final static int MOUSE_TOLERANCE = 5;
private final static int MIN_WIDTH = 80;
private final static int MIN_HEIGHT = 50;
private final Font pluginNameFont = new Font(Font.DIALOG, Font.BOLD, 13);
private final Font pluginTypeFont = new Font(Font.MONOSPACED, Font.ITALIC, 12);
private final static Font PLUGIN_NAME_FONT = new Font(Font.DIALOG, Font.BOLD, 13);
private final static Font PLUGIN_TYPE_FONT = new Font(Font.MONOSPACED, Font.ITALIC, 12);

private final Color backColor;
private final Color foreColor = new Color(0x909090);
Expand Down Expand Up @@ -101,12 +101,12 @@ public void draw(Graphics2D g) {
g.setColor(foreColor);
}
g.draw3DRect(leftX, topY, getWidth(), getHeight(), true);
g.setFont(pluginNameFont);
g.setFont(PLUGIN_NAME_FONT);
if (!selected) {
g.setColor(Color.BLACK);
}
g.drawString(pluginName, textX, textY);
g.setFont(pluginTypeFont);
g.setFont(PLUGIN_TYPE_FONT);
g.drawString(pluginType.name(), detailsX, detailsY);
}

Expand Down Expand Up @@ -144,9 +144,9 @@ public void setSize(int width, int height) {
*/
public void measure(Graphics g) {
// First measure width and height of text
FontMetrics fm = g.getFontMetrics(pluginNameFont);
FontMetrics fm = g.getFontMetrics(PLUGIN_NAME_FONT);
Rectangle2D r = fm.getStringBounds(pluginName, g);
FontMetrics fm1 = g.getFontMetrics(pluginTypeFont);
FontMetrics fm1 = g.getFontMetrics(PLUGIN_TYPE_FONT);
Rectangle2D r1 = fm1.getStringBounds(pluginType.name(), g);

int tW = (int) Math.max(r.getWidth(), r1.getWidth());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import javax.swing.*;
import java.awt.*;

import static net.emustudio.emulib.runtime.interaction.GuiConstants.FONT_MONOSPACED;
import static net.emustudio.emulib.runtime.interaction.GuiUtils.loadIcon;

public class Constants {
public final static Font MONOSPACED_PLAIN = new Font(Font.MONOSPACED, Font.PLAIN, 12);
public final static Font DRIVE_BUTTON_FONT = new Font("Monospaced", Font.PLAIN, 14);

public final static String DIALOG_TITLE = "MITS 88-DCDD";

public final static Font DRIVE_BUTTON_FONT = FONT_MONOSPACED.deriveFont(14.0f);

public final static ImageIcon ICON_UNSELECTED = loadIcon("/net/emustudio/plugins/device/mits88dcdd/gui/unselected.png");
public final static ImageIcon ICON_SELECTED = loadIcon("/net/emustudio/plugins/device/mits88dcdd/gui/selected.png");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import java.awt.event.KeyEvent;
import java.util.Objects;

import static net.emustudio.emulib.runtime.interaction.GuiConstants.FONT_MONOSPACED;
import static net.emustudio.plugins.device.mits88dcdd.gui.Constants.DIALOG_TITLE;
import static net.emustudio.plugins.device.mits88dcdd.gui.Constants.MONOSPACED_PLAIN;

public class DiskGui extends JDialog {
private final DriveCollection drives;
Expand Down Expand Up @@ -74,7 +74,7 @@ public DiskGui(JFrame parent, DriveCollection drives) {

private static JLabel createMonospacedLabel(String text) {
JLabel label = new JLabel(text);
label.setFont(MONOSPACED_PLAIN);
label.setFont(FONT_MONOSPACED);
return label;
}

Expand Down Expand Up @@ -216,7 +216,7 @@ private void initComponents() {
txtMountedImage.setEditable(false);
txtMountedImage.setBackground(UIManager.getDefaults().getColor("TextField.disabledBackground"));
txtMountedImage.setColumns(20);
txtMountedImage.setFont(MONOSPACED_PLAIN);
txtMountedImage.setFont(FONT_MONOSPACED);
txtMountedImage.setLineWrap(true);
txtMountedImage.setRows(5);
jScrollPane1.setViewportView(txtMountedImage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@

import javax.swing.*;

import static net.emustudio.plugins.device.mits88dcdd.gui.Constants.*;
import static net.emustudio.emulib.runtime.interaction.GuiConstants.FONT_MONOSPACED;
import static net.emustudio.plugins.device.mits88dcdd.gui.Constants.ICON_SELECTED;
import static net.emustudio.plugins.device.mits88dcdd.gui.Constants.ICON_UNSELECTED;

public class DriveButton extends JToggleButton {

public DriveButton(String text, Runnable action) {
super(text, ICON_UNSELECTED);
setToolTipText("Disk is unselected");
setFont(MONOSPACED_PLAIN);
setFont(FONT_MONOSPACED);
setFocusPainted(false);
addActionListener(actionEvent -> action.run());
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.awt.event.KeyEvent;
import java.util.Objects;

import static net.emustudio.plugins.device.mits88sio.gui.Constants.MONOSPACED_PLAIN;
import static net.emustudio.emulib.runtime.interaction.GuiConstants.FONT_MONOSPACED;

public class SettingsDialog extends JDialog {
private final Dialogs dialogs;
Expand Down Expand Up @@ -56,6 +56,7 @@ public class SettingsDialog extends JDialog {
private final JList<String> lstStatusPorts = new JList<>();
private final JSpinner spnInputInterrupt = new JSpinner(new SpinnerNumberModel(0, 0, 7, 1));
private final JSpinner spnOutputInterrupt = new JSpinner(new SpinnerNumberModel(0, 0, 7, 1));

public SettingsDialog(JFrame parent, SioUnitSettings settings, Dialogs dialogs) {
super(parent, true);

Expand Down Expand Up @@ -162,7 +163,7 @@ private void initComponents() {

panelStatusChannel.setBorder(BorderFactory.createTitledBorder("Status channel ports"));

lstStatusPorts.setFont(MONOSPACED_PLAIN);
lstStatusPorts.setFont(FONT_MONOSPACED);
lstStatusPorts.setModel(statusPortsModel);
lstStatusPorts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
srlStatus.setViewportView(lstStatusPorts);
Expand Down Expand Up @@ -198,7 +199,7 @@ private void initComponents() {

panelDataChannel.setBorder(BorderFactory.createTitledBorder("Data channel ports"));

lstDataPorts.setFont(MONOSPACED_PLAIN);
lstDataPorts.setFont(FONT_MONOSPACED);
lstDataPorts.setModel(dataPortsModel);
lstDataPorts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
srlData.setViewportView(lstDataPorts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
import net.emustudio.plugins.device.abstracttape.api.TapeSymbol;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.Objects;

import static net.emustudio.emulib.runtime.interaction.GuiConstants.FONT_MONOSPACED;
import static net.emustudio.emulib.runtime.interaction.GuiUtils.loadIcon;

public class TapeGui extends JDialog {
public static final Font FONT_MONOSPACED = new Font(Font.MONOSPACED, Font.PLAIN, 12);
private static final String ICON_ADD_FIRST = "/net/emustudio/plugins/device/abstracttape/gui/go-up.png";
private static final String ICON_ADD_LAST = "/net/emustudio/plugins/device/abstracttape/gui/go-down.png";

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import javax.swing.border.TitledBorder;
import java.awt.event.KeyEvent;

import static net.emustudio.plugins.memory.ram.gui.Constants.DIALOG_PLAIN;
import static net.emustudio.plugins.memory.ram.gui.Constants.MONOSPACED_PLAIN;
import static net.emustudio.emulib.runtime.interaction.GuiConstants.FONT_COMMON;
import static net.emustudio.emulib.runtime.interaction.GuiConstants.FONT_MONOSPACED;

public class MemoryGui extends JDialog {
private final JTable table;
Expand All @@ -44,7 +44,7 @@ public MemoryGui(JFrame parent, MemoryContextImpl memory, Dialogs dialogs) {

RamTableModel tableModel = new RamTableModel(memory);
this.table = new JTable(tableModel);
this.table.setFont(MONOSPACED_PLAIN);
this.table.setFont(FONT_MONOSPACED);

this.loadImageAction = new LoadImageAction(dialogs, memory, () -> {
table.revalidate();
Expand Down Expand Up @@ -74,7 +74,7 @@ private void initComponents() {
toolBar.addSeparator();
toolBar.add(new ToolbarButton(eraseMemoryAction));

jPanel1.setBorder(BorderFactory.createTitledBorder(null, "Tape content", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, DIALOG_PLAIN));
jPanel1.setBorder(BorderFactory.createTitledBorder(null, "Tape content", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, FONT_COMMON));

table.setGridColor(java.awt.SystemColor.control);
jScrollPane1.setViewportView(table);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.awt.event.KeyEvent;
import java.util.Objects;

import static net.emustudio.plugins.memory.rasp.gui.Constants.MONOSPACED_PLAIN;
import static net.emustudio.emulib.runtime.interaction.GuiConstants.FONT_MONOSPACED;

public class MemoryGui extends JDialog {
private final JTable table;
Expand All @@ -46,7 +46,7 @@ public MemoryGui(JFrame parent, MemoryContextImpl context, ApplicationApi api) {
MemoryContextImpl memory = Objects.requireNonNull(context);
RaspTableModel tableModel = new RaspTableModel(memory);
this.table = new JTable(tableModel);
this.table.setFont(MONOSPACED_PLAIN);
this.table.setFont(FONT_MONOSPACED);

this.loadImageAction = new LoadImageAction(api.getDialogs(), context, () -> {
table.revalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
*/
package net.emustudio.plugins.memory.ssem.gui;

import java.awt.*;

public final class Constants {
public final static Font DEFAULT_FONT = new Font(Font.MONOSPACED, Font.PLAIN, 12);
public final static Font BOLD_FONT = new Font(Font.MONOSPACED, Font.BOLD, 12);

public final static int CHAR_WIDTH = 17;
public final static int TWO_CHARS = 2 * CHAR_WIDTH;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import javax.swing.table.TableCellRenderer;
import java.awt.*;

import static net.emustudio.plugins.memory.ssem.gui.Constants.*;
import static net.emustudio.emulib.runtime.interaction.GuiConstants.FONT_MONOSPACED;
import static net.emustudio.emulib.runtime.interaction.GuiConstants.FONT_MONOSPACED_BOLD;

class MemoryCellRenderer extends JLabel implements TableCellRenderer {
private final static Color COLOR_FORE = Color.BLACK;
Expand All @@ -39,7 +40,7 @@ class MemoryCellRenderer extends JLabel implements TableCellRenderer {
setOpaque(true);
setDoubleBuffered(true);
setBorder(BorderFactory.createEmptyBorder());
setFont(DEFAULT_FONT);
setFont(FONT_MONOSPACED);
setHorizontalAlignment(CENTER);

this.selectedBackground = UIManager.getColor("Table.selectionBackground");
Expand Down Expand Up @@ -75,10 +76,10 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
Color front = COLOR_FORE_UNIMPORTANT;

if (MemoryTableModel.isBitInstruction(column) || MemoryTableModel.isBitLine(column)) {
setFont(BOLD_FONT);
setFont(FONT_MONOSPACED_BOLD);
front = COLOR_FORE;
} else {
setFont(DEFAULT_FONT);
setFont(FONT_MONOSPACED);
}

if (MemoryTableModel.isBitLine(column)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import javax.swing.table.JTableHeader;
import java.awt.*;

import static net.emustudio.plugins.memory.ssem.gui.Constants.DEFAULT_FONT;
import static net.emustudio.emulib.runtime.interaction.GuiConstants.FONT_MONOSPACED;

class MemoryRowHeaderRenderer extends JLabel implements ListCellRenderer<String> {

Expand All @@ -33,7 +33,7 @@ class MemoryRowHeaderRenderer extends JLabel implements ListCellRenderer<String>
setHorizontalAlignment(CENTER);
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(DEFAULT_FONT);
setFont(FONT_MONOSPACED);
setOpaque(true);
setDoubleBuffered(true);
this.setPreferredSize(new Dimension(4 * Constants.CHAR_WIDTH, header.getPreferredSize().height + 3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import static net.emustudio.emulib.runtime.interaction.GuiConstants.FONT_MONOSPACED;
import static net.emustudio.plugins.memory.ssem.gui.Constants.COLUMN_WIDTH;
import static net.emustudio.plugins.memory.ssem.gui.Constants.DEFAULT_FONT;

public class MemoryTable extends JTable {

public MemoryTable(MemoryTableModel tableModel, JScrollPane pm) {
setModel(tableModel);
setFont(DEFAULT_FONT);
setFont(FONT_MONOSPACED);
setCellSelectionEnabled(true);
setFocusCycleRoot(true);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getTableHeader().setFont(DEFAULT_FONT);
getTableHeader().setFont(FONT_MONOSPACED);
setDefaultRenderer(Object.class, new MemoryCellRenderer(getTableHeader(), tableModel, pm, getRowHeight()));
setOpaque(true);

Expand Down

0 comments on commit 5c0f5e2

Please sign in to comment.