diff --git a/convex-gui/src/main/java/convex/gui/components/ActionButton.java b/convex-gui/src/main/java/convex/gui/components/ActionButton.java new file mode 100644 index 000000000..09fe652d1 --- /dev/null +++ b/convex-gui/src/main/java/convex/gui/components/ActionButton.java @@ -0,0 +1,24 @@ +package convex.gui.components; + +import java.awt.event.ActionListener; + +import javax.swing.JButton; + +import convex.gui.utils.Toolkit; + +/** + * Standard button for actions + */ +@SuppressWarnings("serial") +public class ActionButton extends JButton { + + public ActionButton(String text, int iconCode, ActionListener al) { + super(text,(iconCode>0)?Toolkit.menuIcon(iconCode):null); + this.addActionListener(al); + } + + public ActionButton(String text, ActionListener al) { + super(text); + this.addActionListener(al); + } +} diff --git a/convex-gui/src/main/java/convex/gui/components/BalanceLabel.java b/convex-gui/src/main/java/convex/gui/components/BalanceLabel.java index 50aa483a9..517f43e9e 100644 --- a/convex-gui/src/main/java/convex/gui/components/BalanceLabel.java +++ b/convex-gui/src/main/java/convex/gui/components/BalanceLabel.java @@ -5,6 +5,9 @@ import javax.swing.JMenuItem; import javax.swing.JPopupMenu; +import javax.swing.text.AttributeSet; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; import convex.api.Convex; import convex.core.ErrorCodes; @@ -46,6 +49,13 @@ public BalanceMenu() { public BalanceLabel() { this.setEditable(false); + + AttributeSet attribs = new SimpleAttributeSet(); + attribs=styleContext.addAttribute(attribs, StyleConstants.Alignment, StyleConstants.ALIGN_RIGHT); + attribs=styleContext.addAttribute(attribs, StyleConstants.FontFamily, getFont().getFamily()); + //StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_RIGHT); + //StyleConstants.setFontFamily(attribs, Font.PLAIN); + this.setParagraphAttributes(attribs, true); } public void setBalance(long a) { diff --git a/convex-gui/src/main/java/convex/gui/components/BaseTextPane.java b/convex-gui/src/main/java/convex/gui/components/BaseTextPane.java index 0cf8b5185..101288192 100644 --- a/convex-gui/src/main/java/convex/gui/components/BaseTextPane.java +++ b/convex-gui/src/main/java/convex/gui/components/BaseTextPane.java @@ -15,16 +15,16 @@ */ @SuppressWarnings("serial") public class BaseTextPane extends JTextPane { - private static final StyleContext sc = StyleContext.getDefaultStyleContext(); + protected static final StyleContext styleContext = StyleContext.getDefaultStyleContext(); public void append(String text, Color c, Integer size) { AttributeSet aset = SimpleAttributeSet.EMPTY; if (c!=null) { - aset=sc.addAttribute(aset, StyleConstants.Foreground, c); + aset=styleContext.addAttribute(aset, StyleConstants.Foreground, c); } if (size!=null) { - aset=sc.addAttribute(aset, StyleConstants.FontSize, size); + aset=styleContext.addAttribute(aset, StyleConstants.FontSize, size); } StyledDocument d=getStyledDocument(); diff --git a/convex-gui/src/main/java/convex/gui/components/account/AccountsPanel.java b/convex-gui/src/main/java/convex/gui/components/account/AccountsPanel.java index 8f597161f..ae75f3e60 100644 --- a/convex-gui/src/main/java/convex/gui/components/account/AccountsPanel.java +++ b/convex-gui/src/main/java/convex/gui/components/account/AccountsPanel.java @@ -2,6 +2,7 @@ import java.awt.BorderLayout; +import java.awt.Component; import java.awt.Dimension; import java.awt.Point; import java.awt.datatransfer.Clipboard; @@ -20,6 +21,7 @@ import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellRenderer; import convex.api.Convex; import convex.core.State; @@ -28,7 +30,9 @@ import convex.core.data.Address; import convex.core.util.Utils; import convex.gui.actor.AccountWindow; +import convex.gui.components.ActionButton; import convex.gui.components.ActionPanel; +import convex.gui.components.BalanceLabel; import convex.gui.components.Identicon; import convex.gui.components.models.AccountsTableModel; import convex.gui.components.models.StateModel; @@ -61,6 +65,22 @@ public void setValue(Object value) { setIcon(Identicon.createIcon((AArrayBlob) value,24)); } } + + static class BalanceRenderer extends BalanceLabel implements TableCellRenderer { + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, + int row, int column) { + this.setAlignmentX(RIGHT_ALIGNMENT); + this.setSize(table.getColumnModel().getColumn(column).getWidth(), getHeight()); + if (value==null) { + setBalance(0); + } else { + this.setBalance((Long)value); + } + return this; + } + } public AccountsPanel(Convex convex,StateModel model) { setLayout(new BorderLayout()); @@ -102,10 +122,10 @@ public AccountsPanel(Convex convex,StateModel model) { } { - CellRenderer cr=new CellRenderer(JLabel.RIGHT); + BalanceRenderer cr=new BalanceRenderer(); cr.setToolTipText("Balance of the account in Convex Coins"); table.getColumnModel().getColumn(3).setCellRenderer(cr); - table.getColumnModel().getColumn(3).setPreferredWidth(180); + table.getColumnModel().getColumn(3).setPreferredWidth(200); } { @@ -165,9 +185,7 @@ public void mousePressed(MouseEvent e) { JPanel actionPanel = new ActionPanel(); add(actionPanel, BorderLayout.SOUTH); - JButton btnActor = new JButton("Examine Account..."); - actionPanel.add(btnActor); - btnActor.addActionListener(e -> { + JButton btnActor = new ActionButton("Examine Account...",0xf5e1,e -> { long ix=table.getSelectedRow(); if (ix<0) return; AccountStatus as = tableModel.getEntry(ix); @@ -176,6 +194,7 @@ public void mousePressed(MouseEvent e) { AccountWindow pw = new AccountWindow(convex, model, addr); pw.run(); }); + actionPanel.add(btnActor); // Turn off auto-resize, since we want a scrollable table table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); diff --git a/convex-gui/src/main/java/convex/gui/components/models/AccountsTableModel.java b/convex-gui/src/main/java/convex/gui/components/models/AccountsTableModel.java index b2b1b7711..7d689991e 100644 --- a/convex-gui/src/main/java/convex/gui/components/models/AccountsTableModel.java +++ b/convex-gui/src/main/java/convex/gui/components/models/AccountsTableModel.java @@ -60,7 +60,7 @@ public Object getValueAt(int rowIndex, int columnIndex) { return (seq>=0)?seq:""; } case 3: - return Text.toFriendlyBalance(as.getBalance()); + return as.getBalance(); case 4: { ACell o = as.getHoldings().get(Init.REGISTRY_ADDRESS); if (o == null) return ""; 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 ffeb5f711..2e754ae12 100644 --- a/convex-gui/src/main/java/convex/gui/keys/KeyGenPanel.java +++ b/convex-gui/src/main/java/convex/gui/keys/KeyGenPanel.java @@ -21,6 +21,7 @@ import convex.core.data.Blob; import convex.core.data.Blobs; import convex.core.util.Utils; +import convex.gui.components.ActionButton; import convex.gui.components.ActionPanel; import convex.gui.components.Identicon; import convex.gui.components.RightCopyMenu; @@ -321,29 +322,27 @@ public KeyGenPanel(PeerGUI manager) { JPanel actionPanel = new ActionPanel(); add(actionPanel, BorderLayout.SOUTH); - JButton btnRecreate = new JButton("Generate"); - actionPanel.add(btnRecreate); - btnRecreate.addActionListener(e -> { + JButton btnRecreate = new ActionButton("Generate",0xe5d5,e -> { Integer wc=(Integer) numSpinner.getValue(); mnemonicArea.setText(BIP39.createSecureMnemonic(wc)); updateMnemonic(); }); + actionPanel.add(btnRecreate); numSpinner = new JSpinner(); numSpinner.setModel(new SpinnerNumberModel(12, 3, 30, 1)); actionPanel.add(numSpinner); - JButton btnNewButton = new JButton("Export..."); + JButton btnNewButton = new ActionButton("Export...",0xebbe,e->{}); actionPanel.add(btnNewButton); { // Button to Normalise Mnemonic string - JButton btnNormalise = new JButton("Normalise Mnemonic"); - actionPanel.add(btnNormalise); - btnNormalise.addActionListener(e -> { + JButton btnNormalise = new ActionButton("Normalise Mnemonic",0xf0ff,e -> { String s=mnemonicArea.getText(); mnemonicArea.setText(BIP39.normalise(s)); updateMnemonic(); }); + actionPanel.add(btnNormalise); } actionPanel.add(addWalletButton); 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 12507896b..1cf159e0f 100644 --- a/convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java +++ b/convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java @@ -46,7 +46,7 @@ public static void addWalletEntry(AWalletEntry we) { public KeyRingPanel() { setLayout(new MigLayout()); - JTextArea note=Toolkit.makeNote("This is a list of currentltly loaded crytographic keys. Locked keys cannot be used until unlocked."); + JTextArea note=Toolkit.makeNote("These are currently loaded keys. Locked keys cannot be used until unlocked. Keys that are unlocked are accessible to users with control over the local machine - DO NOT unlock high value keys unless you are confident that your machine is secure."); add(note,"dock north"); // Scrollable list of wallet entries @@ -57,7 +57,7 @@ public KeyRingPanel() { JPanel toolBar = new ActionPanel(); // new wallet button - JButton btnNew = new JButton("New Keypair"); + 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 -> { @@ -71,11 +71,11 @@ public KeyRingPanel() { }); // new wallet button - JButton btnImportSeed = new JButton("Import Seed...."); + 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 -> { - String sd=JOptionPane.showInputDialog("Enter Ed25519 Seed"); + 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); if (seed==null) return; diff --git a/convex-gui/src/main/java/convex/gui/peer/mainpanels/MessageFormatPanel.java b/convex-gui/src/main/java/convex/gui/peer/mainpanels/MessageFormatPanel.java index baea85c87..d3986cc9d 100644 --- a/convex-gui/src/main/java/convex/gui/peer/mainpanels/MessageFormatPanel.java +++ b/convex-gui/src/main/java/convex/gui/peer/mainpanels/MessageFormatPanel.java @@ -88,7 +88,7 @@ public MessageFormatPanel(PeerGUI manager) { buttonPanel = new ActionPanel(); add(buttonPanel, BorderLayout.SOUTH); - clearButton = new JButton("Clear"); + clearButton = new JButton("Clear",Toolkit.menuIcon(0xe835)); clearButton.setToolTipText("Press to clear the input areas"); clearButton.addActionListener(e -> { dataArea.setText(""); diff --git a/convex-gui/src/main/java/convex/gui/peer/mainpanels/TorusPanel.java b/convex-gui/src/main/java/convex/gui/peer/mainpanels/TorusPanel.java index 243cc352a..dd77f65f7 100644 --- a/convex-gui/src/main/java/convex/gui/peer/mainpanels/TorusPanel.java +++ b/convex-gui/src/main/java/convex/gui/peer/mainpanels/TorusPanel.java @@ -13,6 +13,7 @@ import javax.swing.table.TableColumnModel; import convex.core.State; +import convex.gui.components.ActionButton; import convex.gui.components.ActionPanel; import convex.gui.components.models.TorusTableModel; import convex.gui.peer.PeerGUI; @@ -72,11 +73,10 @@ public void mousePressed(MouseEvent e) { JPanel actionPanel = new ActionPanel(); add(actionPanel, BorderLayout.SOUTH); - JButton btnCopy = new JButton("New Token"); - actionPanel.add(btnCopy); - btnCopy.addActionListener(e -> { + JButton btnCopy = new ActionButton("New Token",0xe145,e -> { // TODO:; }); + actionPanel.add(btnCopy); // Turn off auto-resize, since we want a scrollable table table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); diff --git a/convex-gui/src/main/java/convex/gui/peer/windows/state/StateTreePanel.java b/convex-gui/src/main/java/convex/gui/peer/windows/state/StateTreePanel.java index d475e5bc7..151291bf2 100644 --- a/convex-gui/src/main/java/convex/gui/peer/windows/state/StateTreePanel.java +++ b/convex-gui/src/main/java/convex/gui/peer/windows/state/StateTreePanel.java @@ -65,7 +65,8 @@ private static String getString(ACell a) { } else if (a instanceof ACountable) { return Utils.getClass(a).getSimpleName(); } else { - return RT.print(a).toString(); + AString s=RT.print(a); + return (s==null)?"":s.toString(); } }