From 3bb5b0366f82f05d063f97d09c0afc9f22b083cf Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 10 May 2024 17:25:27 +0800 Subject: [PATCH] GUI updates for better scaling --- .../main/java/convex/core/crypto/BIP39.java | 2 +- .../src/main/java/convex/core/data/ABlob.java | 1 - .../src/main/java/convex/core/util/Bits.java | 6 +- .../convex/gui/actor/AccountInfoPanel.java | 2 +- .../main/java/convex/gui/actor/ArgBox.java | 2 +- .../java/convex/gui/actor/OraclePanel.java | 5 +- .../java/convex/gui/actor/ParamLabel.java | 2 +- .../convex/gui/actor/SmartOpComponent.java | 2 +- .../convex/gui/components/ActionButton.java | 1 + .../java/convex/gui/components/CodeLabel.java | 2 +- .../java/convex/gui/components/CodePane.java | 2 +- .../convex/gui/components/DropdownMenu.java | 4 +- .../java/convex/gui/components/Identicon.java | 4 +- .../java/convex/gui/keys/KeyGenPanel.java | 15 +++-- .../java/convex/gui/keys/KeyRingPanel.java | 16 ++--- .../main/java/convex/gui/peer/AboutPanel.java | 2 +- .../java/convex/gui/peer/PeerComponent.java | 2 +- .../java/convex/gui/peer/PeersListPanel.java | 5 +- .../main/java/convex/gui/peer/TorusPanel.java | 5 +- .../java/convex/gui/server/PeerInfoPanel.java | 2 +- .../java/convex/gui/server/StressPanel.java | 2 +- .../convex/gui/tools/MessageFormatPanel.java | 3 +- .../java/convex/gui/utils/SymbolIcon.java | 19 +++--- .../main/java/convex/gui/utils/Toolkit.java | 60 ++++++++++--------- .../java/convex/gui/wallet/WalletApp.java | 2 +- .../java/convex/peer/ConnectionManager.java | 10 ++-- .../src/test/java/examples/IPTest.java | 2 +- .../main/java/convex/restapi/RESTServer.java | 3 +- 28 files changed, 95 insertions(+), 88 deletions(-) diff --git a/convex-core/src/main/java/convex/core/crypto/BIP39.java b/convex-core/src/main/java/convex/core/crypto/BIP39.java index d0a8a0047..0defd216e 100644 --- a/convex-core/src/main/java/convex/core/crypto/BIP39.java +++ b/convex-core/src/main/java/convex/core/crypto/BIP39.java @@ -334,7 +334,7 @@ public static List 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 getWords(String mnemonic) { mnemonic=mnemonic.trim(); diff --git a/convex-core/src/main/java/convex/core/data/ABlob.java b/convex-core/src/main/java/convex/core/data/ABlob.java index 20272ca9b..79f347bf7 100644 --- a/convex-core/src/main/java/convex/core/data/ABlob.java +++ b/convex-core/src/main/java/convex/core/data/ABlob.java @@ -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); diff --git a/convex-core/src/main/java/convex/core/util/Bits.java b/convex-core/src/main/java/convex/core/util/Bits.java index 597b454c2..5689a8665 100644 --- a/convex-core/src/main/java/convex/core/util/Bits.java +++ b/convex-core/src/main/java/convex/core/util/Bits.java @@ -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; @@ -131,6 +131,7 @@ 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); @@ -138,6 +139,7 @@ public static final long hash64(long x) { /** * 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)); diff --git a/convex-gui/src/main/java/convex/gui/actor/AccountInfoPanel.java b/convex-gui/src/main/java/convex/gui/actor/AccountInfoPanel.java index d0bc9bd10..bac7b071d 100644 --- a/convex-gui/src/main/java/convex/gui/actor/AccountInfoPanel.java +++ b/convex-gui/src/main/java/convex/gui/actor/AccountInfoPanel.java @@ -30,7 +30,7 @@ public AccountInfoPanel(StateModel 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()); diff --git a/convex-gui/src/main/java/convex/gui/actor/ArgBox.java b/convex-gui/src/main/java/convex/gui/actor/ArgBox.java index 4b4868f36..0bbd5d1aa 100644 --- a/convex-gui/src/main/java/convex/gui/actor/ArgBox.java +++ b/convex-gui/src/main/java/convex/gui/actor/ArgBox.java @@ -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)); } } diff --git a/convex-gui/src/main/java/convex/gui/actor/OraclePanel.java b/convex-gui/src/main/java/convex/gui/actor/OraclePanel.java index 633095ac9..2df69392b 100644 --- a/convex-gui/src/main/java/convex/gui/actor/OraclePanel.java +++ b/convex-gui/src/main/java/convex/gui/actor/OraclePanel.java @@ -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; @@ -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); diff --git a/convex-gui/src/main/java/convex/gui/actor/ParamLabel.java b/convex-gui/src/main/java/convex/gui/actor/ParamLabel.java index 30c75baa8..3aab0e1b1 100644 --- a/convex-gui/src/main/java/convex/gui/actor/ParamLabel.java +++ b/convex-gui/src/main/java/convex/gui/actor/ParamLabel.java @@ -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); } } diff --git a/convex-gui/src/main/java/convex/gui/actor/SmartOpComponent.java b/convex-gui/src/main/java/convex/gui/actor/SmartOpComponent.java index 26434142a..3d4aa49e2 100644 --- a/convex-gui/src/main/java/convex/gui/actor/SmartOpComponent.java +++ b/convex-gui/src/main/java/convex/gui/actor/SmartOpComponent.java @@ -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 diff --git a/convex-gui/src/main/java/convex/gui/components/ActionButton.java b/convex-gui/src/main/java/convex/gui/components/ActionButton.java index 9dcd829b8..fc1d5b0d3 100644 --- a/convex-gui/src/main/java/convex/gui/components/ActionButton.java +++ b/convex-gui/src/main/java/convex/gui/components/ActionButton.java @@ -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); } diff --git a/convex-gui/src/main/java/convex/gui/components/CodeLabel.java b/convex-gui/src/main/java/convex/gui/components/CodeLabel.java index 00540e399..c284b5e74 100644 --- a/convex-gui/src/main/java/convex/gui/components/CodeLabel.java +++ b/convex-gui/src/main/java/convex/gui/components/CodeLabel.java @@ -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); } diff --git a/convex-gui/src/main/java/convex/gui/components/CodePane.java b/convex-gui/src/main/java/convex/gui/components/CodePane.java index 851e67464..3794dafba 100644 --- a/convex-gui/src/main/java/convex/gui/components/CodePane.java +++ b/convex-gui/src/main/java/convex/gui/components/CodePane.java @@ -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); diff --git a/convex-gui/src/main/java/convex/gui/components/DropdownMenu.java b/convex-gui/src/main/java/convex/gui/components/DropdownMenu.java index e63b068e7..515ba38fd 100644 --- a/convex-gui/src/main/java/convex/gui/components/DropdownMenu.java +++ b/convex-gui/src/main/java/convex/gui/components/DropdownMenu.java @@ -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->{ diff --git a/convex-gui/src/main/java/convex/gui/components/Identicon.java b/convex-gui/src/main/java/convex/gui/components/Identicon.java index a848cd7ba..423ace08e 100644 --- a/convex-gui/src/main/java/convex/gui/components/Identicon.java +++ b/convex-gui/src/main/java/convex/gui/components/Identicon.java @@ -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() { @@ -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); diff --git a/convex-gui/src/main/java/convex/gui/keys/KeyGenPanel.java b/convex-gui/src/main/java/convex/gui/keys/KeyGenPanel.java index 2e754ae12..0233afd32 100644 --- a/convex-gui/src/main/java/convex/gui/keys/KeyGenPanel.java +++ b/convex-gui/src/main/java/convex/gui/keys/KeyGenPanel.java @@ -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 @@ -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) { diff --git a/convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java b/convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java index 0ead0612e..7c01cca21 100644 --- a/convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java +++ b/convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java @@ -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; @@ -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)); @@ -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); @@ -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"); diff --git a/convex-gui/src/main/java/convex/gui/peer/AboutPanel.java b/convex-gui/src/main/java/convex/gui/peer/AboutPanel.java index b45065bc6..d9a07349e 100644 --- a/convex-gui/src/main/java/convex/gui/peer/AboutPanel.java +++ b/convex-gui/src/main/java/convex/gui/peer/AboutPanel.java @@ -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); diff --git a/convex-gui/src/main/java/convex/gui/peer/PeerComponent.java b/convex-gui/src/main/java/convex/gui/peer/PeerComponent.java index 43b2149c2..aa8c2e75f 100644 --- a/convex-gui/src/main/java/convex/gui/peer/PeerComponent.java +++ b/convex-gui/src/main/java/convex/gui/peer/PeerComponent.java @@ -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); diff --git a/convex-gui/src/main/java/convex/gui/peer/PeersListPanel.java b/convex-gui/src/main/java/convex/gui/peer/PeersListPanel.java index add926203..999496df4 100644 --- a/convex-gui/src/main/java/convex/gui/peer/PeersListPanel.java +++ b/convex-gui/src/main/java/convex/gui/peer/PeersListPanel.java @@ -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? @@ -85,6 +83,7 @@ public PeersListPanel(PeerGUI manager) { } }); + toolBar.add(btnConnect); ScrollyList scrollyList = new ScrollyList<>(manager.getPeerList(), peer -> new PeerComponent(peer)); diff --git a/convex-gui/src/main/java/convex/gui/peer/TorusPanel.java b/convex-gui/src/main/java/convex/gui/peer/TorusPanel.java index 7a847acd3..40988f059 100644 --- a/convex-gui/src/main/java/convex/gui/peer/TorusPanel.java +++ b/convex-gui/src/main/java/convex/gui/peer/TorusPanel.java @@ -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; @@ -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); diff --git a/convex-gui/src/main/java/convex/gui/server/PeerInfoPanel.java b/convex-gui/src/main/java/convex/gui/server/PeerInfoPanel.java index 16b457065..51bba5f70 100644 --- a/convex-gui/src/main/java/convex/gui/server/PeerInfoPanel.java +++ b/convex-gui/src/main/java/convex/gui/server/PeerInfoPanel.java @@ -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); diff --git a/convex-gui/src/main/java/convex/gui/server/StressPanel.java b/convex-gui/src/main/java/convex/gui/server/StressPanel.java index 04f047ca8..6e94dc6e0 100644 --- a/convex-gui/src/main/java/convex/gui/server/StressPanel.java +++ b/convex-gui/src/main/java/convex/gui/server/StressPanel.java @@ -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"); diff --git a/convex-gui/src/main/java/convex/gui/tools/MessageFormatPanel.java b/convex-gui/src/main/java/convex/gui/tools/MessageFormatPanel.java index 820b975f7..7c410b4f2 100644 --- a/convex-gui/src/main/java/convex/gui/tools/MessageFormatPanel.java +++ b/convex-gui/src/main/java/convex/gui/tools/MessageFormatPanel.java @@ -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())); @@ -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); diff --git a/convex-gui/src/main/java/convex/gui/utils/SymbolIcon.java b/convex-gui/src/main/java/convex/gui/utils/SymbolIcon.java index 42299ea48..9ed5da9f7 100644 --- a/convex-gui/src/main/java/convex/gui/utils/SymbolIcon.java +++ b/convex-gui/src/main/java/convex/gui/utils/SymbolIcon.java @@ -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; @@ -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); @@ -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); @@ -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; diff --git a/convex-gui/src/main/java/convex/gui/utils/Toolkit.java b/convex-gui/src/main/java/convex/gui/utils/Toolkit.java index 3a7ac9869..7169f5a9f 100644 --- a/convex-gui/src/main/java/convex/gui/utils/Toolkit.java +++ b/convex-gui/src/main/java/convex/gui/utils/Toolkit.java @@ -5,6 +5,8 @@ import java.awt.Desktop; import java.awt.Font; import java.awt.Graphics2D; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; import java.awt.Image; import java.awt.RenderingHints; import java.awt.datatransfer.Clipboard; @@ -55,27 +57,24 @@ @SuppressWarnings("serial") public class Toolkit { - public static final double SCALE=1.4; + public static final float SCALE=getUIScale(); - public static final int ICON_SIZE = (int) (32*SCALE); - public static final int SMALL_ICON_SIZE = (int) (18*SCALE); + public static final int ICON_SIZE = (int) (24*SCALE); + public static final int IDENTICON_SIZE = (int) (14*SCALE); + public static final int SMALL_ICON_SIZE = (int) (16*SCALE); + public static final int MAIN_ICON_SIZE = (int) (64*SCALE); private static Logger log = LoggerFactory.getLogger(Toolkit.class.getName()); - private static final int DEFAULT_FONT_SIZE=(int) (14*SCALE); - - public static Font DEFAULT_FONT = new Font(Font.SANS_SERIF,Font.PLAIN,DEFAULT_FONT_SIZE); - - public static Font MONO_FONT = new Font(Font.MONOSPACED, Font.BOLD, DEFAULT_FONT_SIZE*3/2); - public static Font SMALL_MONO_FONT = new Font(Font.MONOSPACED, Font.PLAIN, DEFAULT_FONT_SIZE); - public static Font SMALL_MONO_BOLD = SMALL_MONO_FONT.deriveFont(Font.BOLD); + public static final float DEFAULT_FONT_SIZE=14; + public static Font DEFAULT_FONT = new Font(Font.SANS_SERIF,Font.PLAIN,(int)DEFAULT_FONT_SIZE); + public static Font MONO_FONT = new Font(Font.MONOSPACED, Font.BOLD, (int)(DEFAULT_FONT_SIZE)); + public static Font BUTTON_FONT = new Font(Font.SANS_SERIF, Font.BOLD, (int)(DEFAULT_FONT_SIZE*1.6)); - public static final int SCREEN_RES=Toolkit.getDefaultToolkit().getScreenResolution(); - public static final int SYMBOL_SIZE = ICON_SIZE; - public static final float SYMBOL_FONT_SIZE= 72.0f * SYMBOL_SIZE / SCREEN_RES; + public static final float SYMBOL_FONT_SIZE= DEFAULT_FONT_SIZE; - public static Font SYMBOL_FONT = new Font(Font.MONOSPACED, Font.BOLD, (int)SYMBOL_FONT_SIZE); + public static Font SYMBOL_FONT = new Font(Font.MONOSPACED, Font.PLAIN, (int)SYMBOL_FONT_SIZE); public static final Color SYMBOL_COLOUR = new Color(100,180,230); @@ -107,11 +106,20 @@ public class Toolkit { } protected static LookAndFeel installFlatLaf() { - System.setProperty("flatlaf.uiScale", Double.toString(SCALE)); + // System.setProperty("flatlaf.uiScale", Double.toString(SCALE)); FlatDarculaLaf laf=new FlatDarculaLaf(); return laf; } + public static float getUIScale() { + GraphicsDevice screen = GraphicsEnvironment + .getLocalGraphicsEnvironment() + .getDefaultScreenDevice(); + Double scale=screen.getDefaultConfiguration().getDefaultTransform().getScaleX(); + System.err.println("UI Scale: "+scale); + return (float)(scale.doubleValue()); + } + // public static final ImageIcon LOCKED_ICON = // scaledIcon(36,"/images/ic_lock_outline_black_36dp.png"); // public static final ImageIcon UNLOCKED_ICON = @@ -127,13 +135,13 @@ protected static LookAndFeel installFlatLaf() { public static final ImageIcon COG = scaledIcon(ICON_SIZE, "/images/cog.png"); public static final ImageIcon REPL_ICON = scaledIcon(ICON_SIZE, "/images/terminal-icon.png"); - public static final ImageIcon TESTNET_ICON = scaledIcon(128, "/images/testnet.png"); - public static final ImageIcon WWW_ICON = scaledIcon(128, "/images/www.png"); - public static final ImageIcon HACKER_ICON = scaledIcon(128, "/images/hacker.png"); - public static final ImageIcon TERMINAL_ICON = scaledIcon(128, "/images/terminal.png"); - public static final ImageIcon ECOSYSTEM_ICON = scaledIcon(128, "/images/ecosystem.png"); - public static final ImageIcon WALLET_ICON = scaledIcon(128, "/images/wallet.png"); - public static final ImageIcon DLFS_ICON = scaledIcon(128, "/images/filesystem.png"); + public static final ImageIcon TESTNET_ICON = scaledIcon(MAIN_ICON_SIZE, "/images/testnet.png"); + public static final ImageIcon WWW_ICON = scaledIcon(MAIN_ICON_SIZE, "/images/www.png"); + public static final ImageIcon HACKER_ICON = scaledIcon(MAIN_ICON_SIZE, "/images/hacker.png"); + public static final ImageIcon TERMINAL_ICON = scaledIcon(MAIN_ICON_SIZE, "/images/terminal.png"); + public static final ImageIcon ECOSYSTEM_ICON = scaledIcon(MAIN_ICON_SIZE, "/images/ecosystem.png"); + public static final ImageIcon WALLET_ICON = scaledIcon(MAIN_ICON_SIZE, "/images/wallet.png"); + public static final ImageIcon DLFS_ICON = scaledIcon(MAIN_ICON_SIZE, "/images/filesystem.png"); @@ -151,16 +159,14 @@ private static void loadFonts() { try { { // Source Code Pro InputStream is = Utils.getResourceAsStream("fonts/SourceCodePro-Regular.ttf"); - MONO_FONT = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(24f); - SMALL_MONO_FONT = MONO_FONT.deriveFont(14f); - SMALL_MONO_BOLD = SMALL_MONO_FONT.deriveFont(Font.BOLD); + MONO_FONT = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(DEFAULT_FONT_SIZE); } { // Material Symbols InputStream is = Utils.getResourceAsStream("fonts/MaterialSymbolsSharp.ttf"); SYMBOL_FONT = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(SYMBOL_FONT_SIZE); } - DEFAULT_FONT=DEFAULT_FONT.deriveFont(14.0f).deriveFont(Font.PLAIN); + DEFAULT_FONT=DEFAULT_FONT.deriveFont(DEFAULT_FONT_SIZE).deriveFont(Font.PLAIN); } catch (Exception e) { System.err.println("PROBLEM LOADING FONTS:"); @@ -364,6 +370,6 @@ public static JComponent withTitledBorder(String title, JComponent comp) { } public static Icon menuIcon(int codePoint) { - return SymbolIcon.get(codePoint,Toolkit.SMALL_ICON_SIZE); + return SymbolIcon.get(codePoint,Toolkit.BUTTON_FONT.getSize()); } } diff --git a/convex-gui/src/main/java/convex/gui/wallet/WalletApp.java b/convex-gui/src/main/java/convex/gui/wallet/WalletApp.java index 6d79dddf0..7fca86291 100644 --- a/convex-gui/src/main/java/convex/gui/wallet/WalletApp.java +++ b/convex-gui/src/main/java/convex/gui/wallet/WalletApp.java @@ -30,7 +30,7 @@ public class WalletApp extends AbstractGUI { protected Convex convex; - protected static final int TAB_ICON_SIZE=60; + protected static final int TAB_ICON_SIZE=Toolkit.ICON_SIZE; /** * Create the application. diff --git a/convex-peer/src/main/java/convex/peer/ConnectionManager.java b/convex-peer/src/main/java/convex/peer/ConnectionManager.java index ab8e3a3c7..95838af15 100644 --- a/convex-peer/src/main/java/convex/peer/ConnectionManager.java +++ b/convex-peer/src/main/java/convex/peer/ConnectionManager.java @@ -660,13 +660,13 @@ protected String getThreadName() { /** * Called to signal a bad / corrupt message from a Peer. - * @param m - * @param message + * @param m Message of concern + * @param reason Reason message considered bad */ - public void alertBadMessage(Message m, String message) { + public void alertBadMessage(Message m, String reason) { // TODO Possibly dump Peer? Send a result indicating bad message? - message=message+" from "+m.getOriginString(); - log.warn(message); + reason=reason+" from "+m.getOriginString(); + log.warn(reason); } /** diff --git a/convex-peer/src/test/java/examples/IPTest.java b/convex-peer/src/test/java/examples/IPTest.java index 0a5d2b81b..75e0e62d4 100644 --- a/convex-peer/src/test/java/examples/IPTest.java +++ b/convex-peer/src/test/java/examples/IPTest.java @@ -18,7 +18,7 @@ public class IPTest { public static final int PORT=6666; private static boolean running=true; - @SuppressWarnings({ "unused", "resource" }) + @SuppressWarnings({ "resource" }) public static void main (String[] args) throws IOException { final Enumeration e = NetworkInterface.getNetworkInterfaces(); while (e.hasMoreElements()) { diff --git a/convex-restapi/src/main/java/convex/restapi/RESTServer.java b/convex-restapi/src/main/java/convex/restapi/RESTServer.java index 8d1febba5..b56d34e66 100644 --- a/convex-restapi/src/main/java/convex/restapi/RESTServer.java +++ b/convex-restapi/src/main/java/convex/restapi/RESTServer.java @@ -96,12 +96,11 @@ protected SslPlugin getSSLPlugin(HashMap config) { return sslPlugin; } - @SuppressWarnings("deprecation") protected void addOpenApiPlugins(JavalinConfig config) { config.registerPlugin(new OpenApiPlugin(pluginConfig -> { pluginConfig.withDefinitionConfiguration((version, definition) -> { - definition.withOpenApiInfo(info -> { + definition.withInfo(info -> { info.setTitle("Convex REST API"); info.setVersion("0.1.1"); });