Skip to content

Commit

Permalink
GUI updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Nov 19, 2024
1 parent f5f7e73 commit a01f021
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
17 changes: 9 additions & 8 deletions convex-gui/src/main/java/convex/gui/MainGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ public MainGUI() {
ActionPanel actionPanel=new ActionPanel();
actionPanel.setLayout(new MigLayout("center,align center,fillx"));

JComponent wallet=createLaunchButton("Wallet",Toolkit.WALLET_ICON,this::launchWallet);
JComponent wallet=createLaunchButton("Wallet",Toolkit.WALLET_ICON,this::launchWallet,"Open a Convex Wallet, connecting to any existing network");
actionPanel.add(wallet);

JComponent testNet=createLaunchButton("Peer Manager",Toolkit.TESTNET_ICON,this::launchTestNet);
JComponent testNet=createLaunchButton("Peer Manager",Toolkit.TESTNET_ICON,this::launchTestNet,"Launch a DevNet with the Peer Manager. This gives you a test network you can use freely for testing and development purposes.");
actionPanel.add(testNet);

JComponent latticeFS=createLaunchButton("Lattice Filesystem",Toolkit.DLFS_ICON,this::launchDLFS);
JComponent latticeFS=createLaunchButton("Lattice Filesystem",Toolkit.DLFS_ICON,this::launchDLFS,"Launch a DLFS file browser. EXPERIMENTAL.");
actionPanel.add(latticeFS);

JComponent terminal=createLaunchButton("Client Terminal",Toolkit.TERMINAL_ICON,this::launchTerminalClient);
JComponent terminal=createLaunchButton("Client Terminal",Toolkit.TERMINAL_ICON,this::launchTerminalClient,"Open a Convex REPL terminal, connecting to any existing network");
actionPanel.add(terminal);

JComponent hacker=createLaunchButton("Hacker Tools",Toolkit.HACKER_ICON,this::launchTools);
JComponent hacker=createLaunchButton("Hacker Tools",Toolkit.HACKER_ICON,this::launchTools,"Open a set of useful tools for hackers and power users.");
actionPanel.add(hacker);

JComponent discord=createLaunchButton("Discord",Toolkit.ECOSYSTEM_ICON,this::launchDiscord);
JComponent discord=createLaunchButton("Discord",Toolkit.ECOSYSTEM_ICON,this::launchDiscord,"Go to the Convex community Discord (opens web browser).");
actionPanel.add(discord);

JComponent www=createLaunchButton("convex.world",Toolkit.WWW_ICON,this::launchWebsite);
JComponent www=createLaunchButton("convex.world",Toolkit.WWW_ICON,this::launchWebsite,"Go to the Convex main website (opens web browser).");
actionPanel.add(www);

add(actionPanel);
Expand Down Expand Up @@ -96,11 +96,12 @@ public void launchWebsite() {
Toolkit.launchBrowser("https://convex.world");
}

public JPanel createLaunchButton(String label, ImageIcon icon, Runnable cmd) {
public JPanel createLaunchButton(String label, ImageIcon icon, Runnable cmd, String tooltip) {
JButton butt=new JButton(icon);
butt.addActionListener(e->{
EventQueue.invokeLater(cmd);
});
butt.setToolTipText(tooltip);

JLabel lab = new JLabel(label);
lab.setHorizontalAlignment(SwingConstants.CENTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,14 @@ public void setText(String text) {
super.setText(text.trim());
}

static AInteger parse(String text, int decimals, boolean exact) {
/**
* Parse a string as an integer amount with the specified number of decimals
* @param text String to parse
* @param decimals Number of decimals in result quantity
* @param exact If true, conversion will require an exact conversion
* @return Integer amount, or null if not convertible
*/
public static AInteger parse(String text, int decimals, boolean exact) {
try {
text=text.trim();
BigDecimal dec=new BigDecimal(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public AccountChooserPanel(Convex convex) {
keyCombo.addItemListener(e->{
if (e.getStateChange()==ItemEvent.DESELECTED) {
// key pair was deselected and/or set to null
convex.setKeyPair(null);
setKeyPair(null);
return;
};
AWalletEntry we=(AWalletEntry)e.getItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import java.awt.BorderLayout;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

import convex.api.Convex;
import convex.core.data.AccountKey;
import convex.core.data.prim.AInteger;
import convex.gui.components.ActionButton;
import convex.gui.components.ActionPanel;
import convex.gui.components.DecimalAmountField;
import convex.gui.utils.SymbolIcon;

@SuppressWarnings("serial")
public class PeerStakePanel extends JPanel {
Expand All @@ -25,7 +31,38 @@ public PeerStakePanel(Convex convex) {
add(ap,BorderLayout.SOUTH);

ap.add(new ActionButton("Refresh", 0xe5d5, e->peerTable.refresh()) );
ap.add(new ActionButton("Set Stake...", 0xf5dc, e->peerTable.refresh()) );
ap.add(new ActionButton("Set Stake...", 0xf5dc, e->{
int row=peerTable.getSelectedRow();
if (row<0) {
JOptionPane.showMessageDialog(this,"Select a peer to set stake on");
return;
}
Object val=peerTable.getValueAt(row, 0);
AccountKey peerKey=AccountKey.parse(val);
if (peerKey!=null) {
Object stk=JOptionPane.showInputDialog(this,
"Enter desired stake for peer "+peerKey,
"Set Peer Stake...",
JOptionPane.QUESTION_MESSAGE,
SymbolIcon.get(0xf56e),
null,
"0.0");
if (!(stk instanceof String)) return;
AInteger amt=DecimalAmountField.parse((String) stk, 9, true);
if (amt==null) {
JOptionPane.showMessageDialog(this,"Input amount not valid. Must be a qantity in Convex Gold, e.g. '1000.01' ");
return;
}
convex.transact("(set-stake "+peerKey+" "+amt+")").thenAcceptAsync(r->{
if (r.isError()) {
SwingUtilities.invokeLater(()->{
JOptionPane.showMessageDialog(this,"Stake setting failed: "+r,"Staking problem",JOptionPane.ERROR_MESSAGE);
});
}
peerTable.refresh();
});
}
}));
}

}

0 comments on commit a01f021

Please sign in to comment.