Skip to content

Commit

Permalink
added DejaVu font and applied more ui fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tobozo committed Mar 20, 2024
1 parent 159dfb8 commit 5afe25a
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/arduino/ESP32PartitionTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public JFrameArduino() {
JFrame frame = this;

setSize(1024, 640);
setResizable(false);
//setResizable(false);

setLocationRelativeTo(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public JFrameStandalone() {

// Size and display the frame
setSize(800, 564);
setResizable(false);
//setResizable(false);

// Set frame position to the center of the screen
setLocationRelativeTo(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public AboutPanel() {

private void createPanel() {

setFont( UI.defaultFont.deriveFont(Font.PLAIN, 12) );

final String fontFace = "<font face=sans-serif>";
final String boxpadding = "padding-top: 0px;padding-right: 10px;padding-bottom: 10px;padding-left: 10px;";
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/serifpersia/esp32partitiontool/CSVRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ public CSVRow(String values[]) {
offset.setBorder(
BorderFactory.createCompoundBorder(offset.getBorder(), BorderFactory.createEmptyBorder(0, 0, 0, 5)));

enabled.setFont(new Font(Font.MONOSPACED, currFont.getStyle(), currFont.getSize()-1));
size.setFont(new Font(Font.MONOSPACED, currFont.getStyle(), currFont.getSize()));
sizeHex.setFont(new Font(Font.MONOSPACED, currFont.getStyle(), currFont.getSize()));
offset.setFont(new Font(Font.MONOSPACED, currFont.getStyle(), currFont.getSize()));
//Font cellFont = UI.monotypeFont.deriveFont(Font.PLAIN, 12)

enabled.setFont(UI.condensedFont.deriveFont(Font.PLAIN, 13));
size.setFont(UI.monotypeFont.deriveFont(Font.PLAIN, 13));
sizeHex.setFont(UI.monotypeFont.deriveFont(Font.PLAIN, 13));
offset.setFont(UI.monotypeFont.deriveFont(Font.PLAIN, 13));
name.setFont(UI.monotypeFont.deriveFont(Font.PLAIN, 13));
type.setFont(UI.monotypeFont.deriveFont(Font.PLAIN, 13));
subtype.setFont(UI.monotypeFont.deriveFont(Font.PLAIN, 13));


sizeHex.setEditable(false);
offset.setEditable(false);
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/serifpersia/esp32partitiontool/FSPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.swing.*;
import javax.swing.event.*;


@SuppressWarnings("serial")


Expand Down Expand Up @@ -159,7 +160,7 @@ public void createPanel() {
FSGenPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 5));

FSGenLabel.setHorizontalAlignment(SwingConstants.CENTER);
FSGenLabel.setFont(new Font("Tahoma", Font.PLAIN, 18));
FSGenLabel.setFont(UI.defaultFont.deriveFont(Font.PLAIN, 20));

FSGenInnerPanel.setLayout(new BorderLayout(0, 0));

Expand All @@ -168,8 +169,12 @@ public void createPanel() {
FSInnerPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 2, 5));

FSComboLabel.setHorizontalAlignment(SwingConstants.CENTER);
FSComboLabel.setFont(UI.defaultFont.deriveFont(Font.PLAIN, 13));

FSTypesComboBox.setFont(UI.defaultFont.deriveFont(Font.PLAIN, 13));

blockSizeLabel.setHorizontalAlignment(SwingConstants.CENTER);
blockSizeLabel.setFont(UI.defaultFont.deriveFont(Font.PLAIN, 13));

FSBlockSize.setEditable(false);

Expand All @@ -178,8 +183,8 @@ public void createPanel() {
FSUploadPanel.setLayout(new BorderLayout(0, 0));

mergeBoxPanel.setLayout(new BorderLayout(0, 0));
mergeBoxLabel.setFont(new Font("Tahoma", Font.PLAIN, 18));
mergeBoxLabel.setHorizontalAlignment(SwingConstants.CENTER);
mergeBoxLabel.setFont(UI.defaultFont.deriveFont(Font.PLAIN, 20));

mergeButtonsPanel.setLayout(new BorderLayout(0, 0));

Expand All @@ -204,7 +209,7 @@ public void createPanel() {
consoleLogPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
consoleLogPanel.setForeground(Color.WHITE);
consoleLogPanel.setBackground(Color.BLACK);
consoleLogPanel.setFont(new Font("Monospaced", Font.PLAIN, 12)); // Set a monospaced font
consoleLogPanel.setFont(UI.monotypeFont.deriveFont(Font.PLAIN, 13));
consoleLogPanel.setAlignmentY(JPanel.TOP_ALIGNMENT);

//consoleScrollPanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
Expand All @@ -227,7 +232,7 @@ public void emitMessage(String msg, boolean is_error ) {
JTextArea msgArea = new JTextArea(0,0);
msgArea.setForeground(is_error ? Color.RED : Color.WHITE);
msgArea.setBackground(Color.BLACK);
msgArea.setFont(new Font("Monospaced", Font.PLAIN, 12)); // Set a monospaced font
msgArea.setFont(UI.monotypeFont.deriveFont(Font.PLAIN, 13));
msgArea.setEditable(false); // Make the text area read-only
msgArea.setLineWrap(true); // Enable line wrapping
msgArea.setWrapStyleWord(true); // Wrap at word boundaries
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.serifpersia.esp32partitiontool;

import java.awt.*;
import java.io.IOException;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;

import javax.swing.JTextField;
import javax.swing.JFileChooser;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;

import java.lang.Process;
import java.lang.Runtime;
import java.io.*;
import javax.swing.*;




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void createHelpTipPanel() {
helpTipLabel.setVerticalAlignment(JLabel.TOP);
helpTipLabel.setVerticalTextPosition(JLabel.TOP);
helpTipLabel.setIcon(infoIcon);
helpTipLabel.setFont(new Font("Tahoma", Font.PLAIN, 12));
helpTipLabel.setFont( UI.defaultFont.deriveFont(Font.PLAIN, 12) );

helpTipPanel.add(helpTipLabel);

Expand Down
55 changes: 50 additions & 5 deletions src/main/java/com/serifpersia/esp32partitiontool/UI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.serifpersia.esp32partitiontool;

import java.util.ArrayList;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
Expand Down Expand Up @@ -34,7 +35,7 @@ public JButtonIcon( String title, String iconPath) {
//setContentAreaFilled(false);
//setFocusPainted(false);
setOpaque( false );
setPreferredSize( new Dimension( 36, 32 ) );
setPreferredSize( new Dimension( 36, 26 ) );
setToolTipText(" " + title + " ");
} catch (Exception ex) {
setText(" " + title + " ");
Expand Down Expand Up @@ -102,12 +103,47 @@ public void setFrameTitleNeedsSaving(boolean needs_saving) {
private JButton exporCsvBtn;
private JButton helpButton;

static Font defaultFont;
static Font condensedFont;
static Font monotypeFont;
static Font monotypeBoldFont;

private ArrayList<CSVRow> csvRows = new ArrayList<CSVRow>();

private Font loadFont(String fontBaseName, int defaultSize, int fallbackType) { // no path no extension
try {
InputStream is = getClass().getResourceAsStream("/Fonts/"+fontBaseName+".ttf");
Font matchedFont = Font.createFont(Font.TRUETYPE_FONT, is);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(matchedFont);
System.out.printf("Registered font %s size %d type %d\n", fontBaseName, defaultSize, fallbackType);
return matchedFont;
} catch (IOException e) {
e.printStackTrace();
} catch (FontFormatException e) {
e.printStackTrace();
}
System.err.println("Failed to load font " + fontBaseName );
switch( fallbackType ) {
case 0: return new Font("Tahoma", Font.PLAIN, defaultSize);
case 1: return new Font("Monospaced", Font.PLAIN, defaultSize);
case 2: return new Font("Tahoma", Font.BOLD, defaultSize);
case 3: return new Font("Monospaced", Font.BOLD, defaultSize);
default:
System.err.printf("Error font fallbackType %d unsupported\n", fallbackType );
return new Font("Tahoma", Font.PLAIN, defaultSize);
}
}

public UI(JFrame frame, String title) {
// Show tool tips immediately
ToolTipManager.sharedInstance().setInitialDelay(0);

defaultFont = this.loadFont("DejaVuSans", 12, 0);
monotypeFont = this.loadFont("DejaVuSansMono", 12, 1);
monotypeBoldFont = this.loadFont("DejaVuSansMono-Bold", 12, 3);
condensedFont= this.loadFont("DejaVuSansCondensed", 12, 1);

setFrame( frame, title );
setLayout(new BorderLayout(0, 0));
setOpaque(false); // transparent background!
Expand Down Expand Up @@ -136,7 +172,7 @@ public void updateFrame() {
if( settings.hasFSPanel ) {
frame.setSize(1024, 640);
} else {
frame.setSize(800, 564);
frame.setSize(800, 556);
}
fsPanel.setVisible( settings.hasFSPanel );
}
Expand Down Expand Up @@ -249,9 +285,11 @@ public JPanel getTitleCSVRow() {

titleLinePanel.setLayout( new BoxLayout(titleLinePanel, BoxLayout.LINE_AXIS) );
titleLinePanel.setBorder( BorderFactory.createEmptyBorder(5, 0, 5, 0) );
titleLinePanel.setMaximumSize( new Dimension( frame.getSize().width, 24 ) ); // restrict panel height to 24px, inherit width

JLabel enabledLabel = new JLabel("Enable");
enabledLabel.setPreferredSize( new Dimension(50, 12) );
enabledLabel.setFont( condensedFont.deriveFont(Font.BOLD, 13));
enabledLabel.setHorizontalAlignment(SwingConstants.CENTER);
titleLinePanel.add(enabledLabel);

Expand All @@ -264,7 +302,7 @@ public JPanel getTitleCSVRow() {
label.setOpaque(false);
label.setHorizontalAlignment(SwingConstants.CENTER);
final Font currFont = label.getFont();
label.setFont(label.getFont().deriveFont(Font.BOLD, currFont.getSize()));
label.setFont( defaultFont.deriveFont(Font.BOLD, 13) );
remainingTitles.add(label, BorderLayout.NORTH);
}
titleLinePanel.add(remainingTitles);
Expand All @@ -289,7 +327,7 @@ private void createPanels() {

csvGenLabel = new JLabel("Partitions");
csvGenLabel.setOpaque(false);
csvGenLabel.setFont(new Font("Tahoma", Font.PLAIN, 18));
csvGenLabel.setFont(defaultFont.deriveFont(Font.PLAIN, 20));
csvGenLabel.setHorizontalAlignment(SwingConstants.CENTER);
csvGenPanel.add(csvGenLabel, BorderLayout.NORTH);

Expand Down Expand Up @@ -342,14 +380,17 @@ private void createPanels() {

flashSizeFieldSetPanel = new JTransparentPanel();
flashSizeLabel = new JLabel("Flash Size: MB");
flashSizeLabel.setFont(defaultFont.deriveFont(Font.PLAIN, 13));
flashSizeLabel.setHorizontalAlignment(SwingConstants.CENTER);
flashSizeFieldSetPanel.add(flashSizeLabel);
flashSizesComboBox = new JComboBox<>(new String[] { " 4", " 8", "16", "32" });
flashSizesComboBox.setFont(UI.defaultFont.deriveFont(Font.PLAIN, 13));
flashSizeFieldSetPanel.add(flashSizesComboBox);
partitionsUtilButtonsPanel.add(flashSizeFieldSetPanel, BorderLayout.CENTER);

// free space box
partitionFlashFreeSpace = new JLabel("Free Space: not set");
partitionFlashFreeSpace.setFont(defaultFont.deriveFont(Font.PLAIN, 13));
partitionsUtilButtonsPanel.add(partitionFlashFreeSpace, BorderLayout.EAST);

}
Expand Down Expand Up @@ -523,7 +564,8 @@ public void updatePartitionFlashVisual() {

JPanel initialPanel = new JTransparentPanel();
initialPanel.setLayout(new BorderLayout());
JLabel initialLabel = new JLabel("0x9000");
JLabel initialLabel = new JLabel("0x9000 ");
initialLabel.setFont(monotypeBoldFont.deriveFont(Font.PLAIN, 12));
GridBagConstraints gbc = new GridBagConstraints();

initialLabel.setHorizontalAlignment(SwingConstants.CENTER);
Expand Down Expand Up @@ -559,6 +601,7 @@ public void updatePartitionFlashVisual() {

// Set the text color to white
JLabel label = new JLabel(getPartitionSubType(i).getText());
label.setFont(monotypeBoldFont.deriveFont(Font.PLAIN, 12));
label.setForeground(Color.WHITE);
partitionPanel.add(label);
partitionPanel.setToolTipText(partSizeKb+"KB");
Expand All @@ -576,6 +619,7 @@ public void updatePartitionFlashVisual() {
// Set the text color to white
JLabel label = new JLabel("Free Space");
label.setForeground(Color.BLACK);
label.setFont(monotypeBoldFont.deriveFont(Font.PLAIN, 12));
unusedSpacePanel.add(label);

csvpartitionsCenterVisualPanel.add(unusedSpacePanel, gbc);
Expand Down Expand Up @@ -603,6 +647,7 @@ public void updatePartitionFlashVisual() {
partitionPanel.setBackground(partColor);
// Set the text color to white
JLabel label = new JLabel(partSubType);
label.setFont(monotypeBoldFont.deriveFont(Font.PLAIN, 12));
label.setForeground(Color.WHITE);
partitionPanel.add(label);
partitionPanel.setToolTipText(partSizeKb+"KB");
Expand Down
Binary file added src/main/resources/Fonts/DejaVuSans-Bold.ttf
Binary file not shown.
Binary file not shown.
Binary file added src/main/resources/Fonts/DejaVuSans.ttf
Binary file not shown.
Binary file not shown.
Binary file added src/main/resources/Fonts/DejaVuSansCondensed.ttf
Binary file not shown.
Binary file added src/main/resources/Fonts/DejaVuSansMono-Bold.ttf
Binary file not shown.
Binary file added src/main/resources/Fonts/DejaVuSansMono.ttf
Binary file not shown.

0 comments on commit 5afe25a

Please sign in to comment.