diff --git a/convex-gui/src/main/java/convex/gui/components/ConnectPanel.java b/convex-gui/src/main/java/convex/gui/components/ConnectPanel.java index 873a9b8bb..9d50da9df 100644 --- a/convex-gui/src/main/java/convex/gui/components/ConnectPanel.java +++ b/convex-gui/src/main/java/convex/gui/components/ConnectPanel.java @@ -60,7 +60,7 @@ public static Convex tryConnect(JComponent parent,String prompt) { HostCombo.registerGoodConnection(target); AWalletEntry we=KeyRingPanel.findWalletEntry(convex); - if (!we.isLocked()) { + if ((we!=null)&&!we.isLocked()) { convex.setKeyPair(we.getKeyPair()); } return convex; 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 cac1b711a..fad740326 100644 --- a/convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java +++ b/convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java @@ -4,6 +4,7 @@ import javax.swing.DefaultListModel; import javax.swing.JButton; +import javax.swing.JOptionPane; import javax.swing.JPanel; import org.slf4j.Logger; @@ -15,6 +16,7 @@ import convex.core.crypto.wallet.HotWalletEntry; import convex.core.data.AccountKey; import convex.core.data.Address; +import convex.core.data.Blob; import convex.gui.components.ActionPanel; import convex.gui.components.ScrollyList; import convex.gui.components.Toast; @@ -52,13 +54,33 @@ public KeyRingPanel() { // new wallet button JButton btnNew = new JButton("New Keypair"); + 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 -> { AKeyPair newKP=AKeyPair.generate(); try { listModel.addElement(HotWalletEntry.create(newKP)); } catch (Exception t) { - Toast.display(this,"Exception creating account: ",Color.RED); + Toast.display(this,"Error creating key pair: "+t.getMessage(),Color.RED); + t.printStackTrace(); + } + }); + + // new wallet button + JButton btnImportSeed = new JButton("Import Seed...."); + btnImportSeed.setToolTipText("Create a new hot wallet keypair. Use for temporary purposes. Remember to save the seed if you want to re-use!"); + toolBar.add(btnImportSeed); + btnImportSeed.addActionListener(e -> { + String sd=JOptionPane.showInputDialog("Enter Ed25519 Seed"); + if (sd==null) return; + Blob seed=Blob.parse(sd); + if (seed==null) return; + + try { + AKeyPair newKP=AKeyPair.create(seed); + listModel.addElement(HotWalletEntry.create(newKP)); + } catch (Exception t) { + Toast.display(this,"Exception importing seedt: "+t.getMessage(),Color.RED); t.printStackTrace(); } }); diff --git a/convex-gui/src/main/java/convex/gui/utils/SymbolIcon.java b/convex-gui/src/main/java/convex/gui/utils/SymbolIcon.java new file mode 100644 index 000000000..6ed68b4e4 --- /dev/null +++ b/convex-gui/src/main/java/convex/gui/utils/SymbolIcon.java @@ -0,0 +1,66 @@ +package convex.gui.utils; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import java.util.WeakHashMap; + +import javax.swing.ImageIcon; +import javax.swing.JLabel; + +@SuppressWarnings("serial") +public class SymbolIcon extends ImageIcon { + + private static final Color SYMBOL_COLOUR = new Color(150,200,255); + + + private static WeakHashMap cache= new WeakHashMap<>(); + + public SymbolIcon(BufferedImage image) { + super(image); + } + + private static SymbolIcon create(int codePoint, int size) { + BufferedImage image =new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); + + char[] c=Character.toChars(codePoint); + String s=new String(c); + + + JLabel label = new JLabel(s); + label.setForeground(SYMBOL_COLOUR); + + // set font size so we get the correct pixel size + float fontSize= 72.0f * size / Toolkit.SCREEN_RES; + label.setFont(Toolkit.SYMBOL_FONT.deriveFont(fontSize)); + + label.setHorizontalTextPosition(JLabel.CENTER); + label.setVerticalTextPosition(JLabel.CENTER); + + label.setSize(size, size); + + Graphics2D g = image.createGraphics(); + // have antialiasing on for better visuals + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + label.print(g); + + return new SymbolIcon(image); + } + + public static SymbolIcon get(int codePoint) { + return get(codePoint,Toolkit.SYMBOL_SIZE); + } + + public static SymbolIcon get(int codePoint, int size) { + long id=codePoint+size*0x100000000L; + SymbolIcon result=cache.get(id); + + if (result!=null) return result; + + result = create(codePoint,size); + cache.put(id,result); + + 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 1f46327c0..5d3aca5b6 100644 --- a/convex-gui/src/main/java/convex/gui/utils/Toolkit.java +++ b/convex-gui/src/main/java/convex/gui/utils/Toolkit.java @@ -59,11 +59,19 @@ public class Toolkit { public static Font DEFAULT_FONT = new JLabel().getFont(); public static Font MONO_FONT = new Font(Font.MONOSPACED, Font.BOLD, 20); - public static Font SMALL_MONO_FONT = new Font(Font.MONOSPACED, Font.PLAIN, 14); public static Font SMALL_MONO_BOLD = SMALL_MONO_FONT.deriveFont(Font.BOLD); + + + public static final int SCREEN_RES=Toolkit.getDefaultToolkit().getScreenResolution(); + public static final int SYMBOL_SIZE = 32; + public static final float SYMBOL_FONT_SIZE= 72.0f * SYMBOL_SIZE / SCREEN_RES; + + public static Font SYMBOL_FONT = new Font(Font.MONOSPACED, Font.BOLD, (int)SYMBOL_FONT_SIZE); + static { + loadFonts(); try { UIManager.installLookAndFeel("Material", "mdlaf.MaterialLookAndFeel"); Class.forName("mdlaf.MaterialLookAndFeel"); @@ -79,10 +87,6 @@ public class Toolkit { } } - 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); // prefer MaterialLookAndFeel if we have it AbstractMaterialTheme theme = new MaterialOceanicTheme(); @@ -143,6 +147,27 @@ public static ImageIcon scaledIcon(int size, String resourcePath) { return new ImageIcon(image); } + 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); + } + + { // Material Symbols + InputStream is = Utils.getResourceAsStream("fonts/MaterialSymbolsSharp.ttf"); + SYMBOL_FONT = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(SYMBOL_FONT_SIZE); + } + + } catch (Exception e) { + System.err.println("PROBLEM LOADING FONTS:"); + e.printStackTrace(); + } + + } + /** * Scale an image with interpolation / AA for nicer effects * 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 335dce612..bd94e8312 100644 --- a/convex-gui/src/main/java/convex/gui/wallet/WalletApp.java +++ b/convex-gui/src/main/java/convex/gui/wallet/WalletApp.java @@ -34,7 +34,7 @@ public WalletApp(Convex convex) { setLayout(new BorderLayout()); this.add(tabs, BorderLayout.CENTER); - tabs.add("Home", homePanel); + tabs.add("Wallet", new WalletPanel(convex)); tabs.add("Keys", new KeyRingPanel()); tabs.add("QR Links", new QRPanel("Test QR code with a reasonable length string to see what happens",300)); } diff --git a/convex-gui/src/main/java/convex/gui/wallet/WalletPanel.java b/convex-gui/src/main/java/convex/gui/wallet/WalletPanel.java new file mode 100644 index 000000000..6ddf94a3e --- /dev/null +++ b/convex-gui/src/main/java/convex/gui/wallet/WalletPanel.java @@ -0,0 +1,21 @@ +package convex.gui.wallet; + +import javax.swing.JLabel; +import javax.swing.JPanel; + +import convex.api.Convex; +import convex.gui.components.AccountChooserPanel; +import convex.gui.utils.SymbolIcon; +import net.miginfocom.swing.MigLayout; + +@SuppressWarnings("serial") +public class WalletPanel extends JPanel { + + public WalletPanel(Convex convex) { + setLayout(new MigLayout()); + + add(new AccountChooserPanel(convex),"dock north"); + + add(new JLabel(SymbolIcon.get(0xe14a))); + } +} diff --git a/convex-gui/src/main/resources/fonts/MaterialSymbolsSharp.ttf b/convex-gui/src/main/resources/fonts/MaterialSymbolsSharp.ttf new file mode 100644 index 000000000..200407d83 Binary files /dev/null and b/convex-gui/src/main/resources/fonts/MaterialSymbolsSharp.ttf differ