Skip to content

Commit

Permalink
GUI updates for better scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed May 10, 2024
1 parent 71ecc97 commit 3bb5b03
Show file tree
Hide file tree
Showing 28 changed files with 95 additions and 88 deletions.
2 changes: 1 addition & 1 deletion convex-core/src/main/java/convex/core/crypto/BIP39.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public static List<String> createWords(SecureRandom r, int n) {
/**
* Gets the individual words from a mnemonic String. Will trim and normalise whitespace, convert to lowercase
* @param mnemonic Mnemonic String
* @return
* @return List of words
*/
public static List<String> getWords(String mnemonic) {
mnemonic=mnemonic.trim();
Expand Down
1 change: 0 additions & 1 deletion convex-core/src/main/java/convex/core/data/ABlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ public int read(long offset, ByteBuffer dest) {
* @param count Number of bytes to read. Must be in bounds
* @param dest Destination byte buffer
* @return Number of bytes read
* @throws BufferOverflowException if there is insufficient space in destination buffer
*/
public abstract int read(long offset, long count, ByteBuffer dest);

Expand Down
6 changes: 4 additions & 2 deletions convex-core/src/main/java/convex/core/util/Bits.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public static int leadingOnes(long value) {

/**
* Compute XORShift64 PRNG for a given value
* @param x
* @return
* @param x Input value (state)
* @return PRNG value for x
*/
public static long xorshift64(long x) {
x ^= x << 13;
Expand All @@ -131,13 +131,15 @@ public static long xorshift64(long x) {

/**
* 64-bit salted hash function for hashtables etc.
* @return Hash value using salted hash
*/
public static final long hash64(long x) {
return SALT^xorshift64(x^SALT);
}

/**
* 32-bit salted hash function for hashtables etc.
* @return Hash value using salted hash
*/
public static final int hash32(long x) {
return (int)(SALT^xorshift64(x^SALT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public AccountInfoPanel(StateModel<State> manager, Address address) {
infoArea = new JTextArea();
add(infoArea, BorderLayout.CENTER);
infoArea.setBackground(null);
infoArea.setFont(Toolkit.SMALL_MONO_FONT);
infoArea.setFont(Toolkit.MONO_FONT);

manager.addPropertyChangeListener(e -> {
updateInfo((State) e.getNewValue());
Expand Down
2 changes: 1 addition & 1 deletion convex-gui/src/main/java/convex/gui/actor/ArgBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class ArgBox extends JTextField {

public ArgBox() {
setFont(Toolkit.SMALL_MONO_FONT);
setFont(Toolkit.MONO_FONT);
this.setPreferredSize(new Dimension(300,30));
}
}
5 changes: 3 additions & 2 deletions convex-gui/src/main/java/convex/gui/actor/OraclePanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package convex.gui.actor;

import java.awt.BorderLayout;
import java.awt.Font;
import java.util.function.Consumer;

import javax.swing.JButton;
Expand Down Expand Up @@ -75,8 +76,8 @@ public OraclePanel(ConvexLocal manager) {
table.getColumnModel().getColumn(3).setPreferredWidth(300);

// fonts
table.setFont(Toolkit.SMALL_MONO_FONT);
table.getTableHeader().setFont(Toolkit.SMALL_MONO_FONT);
table.setFont(Toolkit.MONO_FONT);
table.getTableHeader().setFont(Toolkit.MONO_FONT.deriveFont(Font.BOLD));

table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // useful in scroll pane
scrollPane.getViewport().setBackground(null);
Expand Down
2 changes: 1 addition & 1 deletion convex-gui/src/main/java/convex/gui/actor/ParamLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ParamLabel extends JLabel {
public ParamLabel(String text) {
super(" " + text + " ");
this.setHorizontalAlignment(SwingConstants.RIGHT);
this.setFont(Toolkit.SMALL_MONO_FONT);
this.setFont(Toolkit.MONO_FONT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public SmartOpComponent(ActorInvokePanel parent, Address contract, Symbol sym) {
this.parent = parent;
this.sym = sym;

setFont(Toolkit.SMALL_MONO_FONT);
setFont(Toolkit.MONO_FONT);
setLayout(new BorderLayout(0, 0));

// Name and description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ActionButton extends JButton {

public ActionButton(String text, int iconCode, ActionListener action) {
super(text,(iconCode>0)?Toolkit.menuIcon(iconCode):null);
this.setFont(Toolkit.BUTTON_FONT);
this.addActionListener(action);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CodeLabel(String text) {
super(Text.lineCount(text),0);
this.setText(text);
this.setEditable(false);
this.setFont(Toolkit.SMALL_MONO_FONT);
this.setFont(Toolkit.MONO_FONT);

RightCopyMenu.addTo(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CodePane extends BaseTextPane {
public CodePane() {
RightCopyMenu.addTo(this);

setFont(Toolkit.SMALL_MONO_FONT);
setFont(Toolkit.MONO_FONT);
// stop catching focus movement keys, useful for Ctrl+up and down etc
setFocusTraversalKeysEnabled(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
public class DropdownMenu extends BaseImageButton {

private JPopupMenu popupMenu;

public DropdownMenu(JPopupMenu popupMenu) {
super(SymbolIcon.get(0xe8b8, Toolkit.SYMBOL_SIZE));
super(SymbolIcon.get(0xe8b8,Toolkit.ICON_SIZE));
this.popupMenu = popupMenu;
// setIconTextGap(0);
this.addActionListener(e->{
Expand Down
4 changes: 2 additions & 2 deletions convex-gui/src/main/java/convex/gui/components/Identicon.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static ImageIcon createIcon(AArrayBlob hash, int size) {
public Identicon(AArrayBlob a) {
super();
setKey(a);
setFont(Toolkit.SMALL_MONO_FONT);
setFont(Toolkit.MONO_FONT);
setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));

Toolkit.addPopupMenu(this,new JPopupMenu() {
Expand Down Expand Up @@ -128,7 +128,7 @@ public static void main(String... args) {
}

public void setKey(AArrayBlob a) {
ImageIcon icon=createIcon(a, 36);
ImageIcon icon=createIcon(a, Toolkit.IDENTICON_SIZE);
this.setToolTipText(icon.getDescription());

setIcon(icon);
Expand Down
15 changes: 7 additions & 8 deletions convex-gui/src/main/java/convex/gui/keys/KeyGenPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ public class KeyGenPanel extends JPanel {

JSpinner numSpinner;

JButton addWalletButton = new JButton("Add to keyring");
ActionButton addWalletButton;

JPanel formPanel;


static int FONT_SIZE=(int)Toolkit.SCALE*15;
static Font HEX_FONT=Toolkit.SMALL_MONO_FONT.deriveFont((float)FONT_SIZE);
static Font HEX_FONT=Toolkit.MONO_FONT;

/**
* Format a hex string in blocks for digits
Expand Down Expand Up @@ -345,15 +343,16 @@ public KeyGenPanel(PeerGUI manager) {
actionPanel.add(btnNormalise);
}

actionPanel.add(addWalletButton);
addWalletButton.setEnabled(false);
addWalletButton.addActionListener(e -> {
addWalletButton=new ActionButton("Add to keyring",e -> {
String pks = privateKeyArea.getText();
pks = Utils.stripWhiteSpace(pks);
HotWalletEntry we = HotWalletEntry.create(AKeyPair.create(Utils.hexToBytes(pks)));
KeyRingPanel.addWalletEntry(we);
if (manager!=null) manager.switchPanel("Keyring");
});
});
actionPanel.add(addWalletButton);
addWalletButton.setEnabled(false);

}

private void addNote(String s) {
Expand Down
16 changes: 8 additions & 8 deletions convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import convex.core.lang.RT;
import convex.core.lang.Symbols;
import convex.core.lang.ops.Special;
import convex.gui.components.ActionButton;
import convex.gui.components.ActionPanel;
import convex.gui.components.ScrollyList;
import convex.gui.components.Toast;
Expand Down Expand Up @@ -62,10 +63,7 @@ public KeyRingPanel() {
JPanel toolBar = new ActionPanel();

// new wallet button
JButton btnNew = new JButton("New Keypair",Toolkit.menuIcon(0xe145));
btnNew.setToolTipText("Create a new hot wallet keypair. Use for temporary purposes. Remember to save the seed if you want to re-use!");
toolBar.add(btnNew);
btnNew.addActionListener(e -> {
JButton btnNew = new ActionButton("New Keypair",0xe145,e -> {
AKeyPair newKP=AKeyPair.generate();
try {
listModel.addElement(HotWalletEntry.create(newKP));
Expand All @@ -74,12 +72,11 @@ public KeyRingPanel() {
t.printStackTrace();
}
});
btnNew.setToolTipText("Create a new hot wallet keypair. Use for temporary purposes. Remember to save the seed if you want to re-use!");
toolBar.add(btnNew);

// new wallet button
JButton btnImportSeed = new JButton("Import Seed....",Toolkit.menuIcon(0xe890));
btnImportSeed.setToolTipText("Import a key pair using an Ed25519 seed");
toolBar.add(btnImportSeed);
btnImportSeed.addActionListener(e -> {
JButton btnImportSeed = new ActionButton("Import Seed....",0xe890,e -> {
String sd=(String) JOptionPane.showInputDialog(this,"Enter Ed25519 Seed","Import private key",JOptionPane.QUESTION_MESSAGE,Toolkit.menuIcon(0xe890),null,"");
if (sd==null) return;
Blob seed=Blob.parse(sd);
Expand All @@ -93,6 +90,9 @@ public KeyRingPanel() {
t.printStackTrace();
}
});
btnImportSeed.setToolTipText("Import a key pair using an Ed25519 seed");
toolBar.add(btnImportSeed);


add(toolBar, "dock south");

Expand Down
2 changes: 1 addition & 1 deletion convex-gui/src/main/java/convex/gui/peer/AboutPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public AboutPanel(ConvexLocal convex) {
textArea = new JTextArea();
textArea.setEditable(false);
textArea.setBackground(null);
textArea.setFont(Toolkit.SMALL_MONO_FONT);
textArea.setFont(Toolkit.MONO_FONT);

PeerGUI.getStateModel(convex).addPropertyChangeListener(e -> {
updateState(convex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public PeerComponent(ConvexLocal value) {
centralPanel.add(new CodeLabel("0x"+peerKey.toChecksumHex()),"span");

description = new CodeLabel(getPeerDescription());
description.setFont(Toolkit.SMALL_MONO_FONT);
description.setFont(Toolkit.MONO_FONT);
description.setEditable(false);
description.setBorder(null);
description.setBackground(null);
Expand Down
5 changes: 2 additions & 3 deletions convex-gui/src/main/java/convex/gui/peer/PeersListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ public PeersListPanel(PeerGUI manager) {
btnLaunch.setToolTipText("Launch an extra peer for the network. Allocates some stake from genesis account");
toolBar.add(btnLaunch);

JButton btnConnect = new JButton("Connect...");
toolBar.add(btnConnect);
btnConnect.addActionListener(e -> {
JButton btnConnect = new ActionButton("Connect...",0xe157,e -> {
String input = JOptionPane.showInputDialog("Enter host address: ", "localhost:18888");
if (input==null) return; // no result?

Expand All @@ -85,6 +83,7 @@ public PeersListPanel(PeerGUI manager) {
}

});
toolBar.add(btnConnect);

ScrollyList<ConvexLocal> scrollyList = new ScrollyList<>(manager.getPeerList(),
peer -> new PeerComponent(peer));
Expand Down
5 changes: 3 additions & 2 deletions convex-gui/src/main/java/convex/gui/peer/TorusPanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package convex.gui.peer;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

Expand Down Expand Up @@ -33,8 +34,8 @@ public TorusPanel(PeerGUI manager) {

tableModel = new TorusTableModel(manager.getLatestState());
table = new JTable(tableModel);
table.setFont(Toolkit.SMALL_MONO_FONT);
table.getTableHeader().setFont(Toolkit.SMALL_MONO_BOLD);
table.setFont(Toolkit.MONO_FONT);
table.getTableHeader().setFont(Toolkit.MONO_FONT.deriveFont(Font.BOLD));

DefaultTableCellRenderer leftRenderer = new DefaultTableCellRenderer();
leftRenderer.setHorizontalAlignment(JLabel.LEFT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PeerInfoPanel(Convex p) {
textArea.setBackground(null);
textArea.setCaret(new NonUpdatingCaret());
textArea.setColumns(100);
textArea.setFont(Toolkit.SMALL_MONO_FONT);
textArea.setFont(Toolkit.MONO_FONT);

JPanel panel1=new JPanel();
panel1.add(textArea);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public StressPanel(Convex peerView) {
resultArea.setLineWrap(true);
resultArea.setEditable(false);
resultPanel.add(resultArea);
resultArea.setFont(Toolkit.SMALL_MONO_FONT);
resultArea.setFont(Toolkit.MONO_FONT);
}

NumberFormat formatter = new DecimalFormat("#0.000");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public MessageFormatPanel() {
hashLabel.setToolTipText("Hash code of the data object's serilaised representation = Data Object ID");
hashLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10,10,10,10), BorderFactory.createRaisedBevelBorder()));
hashLabel.setBackground(null);
hashLabel.setFont(Toolkit.SMALL_MONO_FONT);
hashLabel.setFont(Toolkit.MONO_FONT);
lowerPanel.add(hashLabel, BorderLayout.SOUTH);
messageArea.getDocument().addDocumentListener(Toolkit.createDocumentListener(() -> updateMessage()));

Expand Down Expand Up @@ -137,7 +137,6 @@ private void updateData() {
messageArea.setText(msg);
}

@SuppressWarnings("null")
private void updateHashLabel(ACell v, Blob b) {
StringBuilder sb=new StringBuilder();
boolean empty=(b==null);
Expand Down
19 changes: 10 additions & 9 deletions convex-gui/src/main/java/convex/gui/utils/SymbolIcon.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package convex.gui.utils;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
Expand All @@ -18,9 +19,8 @@ public SymbolIcon(BufferedImage image) {
super(image);
}

private static final float SCALE_FACTOR=1.3f;

private static SymbolIcon create(int codePoint, int size, int colour) {
private static SymbolIcon create(int codePoint, double dsize, int colour) {
int size=(int)dsize;
BufferedImage image =new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);

char[] c=Character.toChars(codePoint);
Expand All @@ -31,8 +31,8 @@ private static SymbolIcon create(int codePoint, int size, int colour) {
label.setForeground(new Color(colour&0xffffff));

// set font size so we get the correct pixel size
float fontSize= SCALE_FACTOR* 72.0f * size / Toolkit.SCREEN_RES;
label.setFont(Toolkit.SYMBOL_FONT.deriveFont(fontSize));
Font font=Toolkit.SYMBOL_FONT.deriveFont((float)(size));
label.setFont(font);

label.setHorizontalAlignment(JLabel.CENTER);
label.setVerticalAlignment(JLabel.CENTER);
Expand All @@ -48,16 +48,17 @@ private static SymbolIcon create(int codePoint, int size, int colour) {
}

public static SymbolIcon get(int codePoint) {
return get(codePoint,Toolkit.SYMBOL_SIZE,Toolkit.SYMBOL_COLOUR.getRGB());
return get(codePoint,Toolkit.SMALL_ICON_SIZE,Toolkit.SYMBOL_COLOUR.getRGB());
}

public static SymbolIcon get(int codePoint, int size) {
public static SymbolIcon get(int codePoint, double size) {
return get(codePoint,size,Toolkit.SYMBOL_COLOUR.getRGB());
}


public static SymbolIcon get(int codePoint, int size, int colour) {
long id=codePoint+(size*0x100000000L)+(colour*100000000000L);
public static SymbolIcon get(int codePoint, double size, int colour) {
int sz=(int)size;
long id=codePoint+(sz*0x100000000L)+(colour*100000000000L);
SymbolIcon result=cache.get(id);

if (result!=null) return result;
Expand Down
Loading

0 comments on commit 3bb5b03

Please sign in to comment.