Skip to content

Commit

Permalink
GUI tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Aug 30, 2024
1 parent 2e76c63 commit 6155242
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void windowClosing(WindowEvent e) {
setupFrame(frame);
frame.pack();
frame.setVisible(true);
EventQueue.invokeLater(AbstractGUI.this::afterRun);
}
});
}
Expand All @@ -65,6 +66,13 @@ public void setupFrame(JFrame frame) {
frame.getContentPane().add(this,"dock center");
}

/**
* Called after the wallet is run
*/
public void afterRun() {

}

public void waitForClose() {
finished.join();
close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package convex.gui.components;

import java.awt.Color;
import java.io.IOException;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeoutException;

import javax.swing.JComponent;
import javax.swing.JLabel;
Expand Down Expand Up @@ -84,7 +86,7 @@ public static Convex tryConnect(JComponent parent,String prompt) {
} catch (ConnectException e) {
log.info("Failed to connect");
Toast.display(parent, e.getMessage(), Color.RED);
} catch (Exception e) {
} catch (TimeoutException | IOException e) {
Toast.display(parent, e.getMessage(), Color.RED);
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
Expand All @@ -25,6 +24,7 @@
import javax.swing.table.TableCellRenderer;

import convex.api.Convex;
import convex.api.ConvexLocal;
import convex.core.State;
import convex.core.data.AArrayBlob;
import convex.core.data.AccountStatus;
Expand All @@ -38,6 +38,7 @@
import convex.gui.models.AccountsTableModel;
import convex.gui.models.StateModel;
import convex.gui.utils.Toolkit;
import convex.gui.wallet.WalletApp;

/**
* Panel showing account information
Expand Down Expand Up @@ -86,7 +87,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
}
}

public AccountsPanel(Convex convex,StateModel<State> model) {
public AccountsPanel(ConvexLocal convex,StateModel<State> model) {
setLayout(new BorderLayout());


Expand Down Expand Up @@ -197,10 +198,13 @@ public void mousePressed(MouseEvent e) {
}
});

// ============================================
// Actionbuttons at bottom

JPanel actionPanel = new ActionPanel();
add(actionPanel, BorderLayout.SOUTH);

JButton btnActor = new ActionButton("Examine Account...",0xf5e1,e -> {
ActionButton btnActor = new ActionButton("Examine Account...",0xf5e1,e -> {
long ix=table.getSelectedRow();
if (ix<0) return;
AccountStatus as = tableModel.getEntry(ix);
Expand All @@ -210,6 +214,15 @@ public void mousePressed(MouseEvent e) {
pw.run();
});
actionPanel.add(btnActor);

ActionButton btnWallet = new ActionButton("Launch Wallet",0xe89e,e -> {
Convex cv=Convex.connect(convex.getLocalServer());
long ix=table.getSelectedRow();
if (ix<0) return;
cv.setAddress(Address.create(ix));
new WalletApp(cv).run();
});
actionPanel.add(btnWallet);

// Turn off auto-resize, since we want a scrollable table
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Expand Down
4 changes: 2 additions & 2 deletions convex-gui/src/main/java/convex/gui/keys/WalletComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public WalletComponent(AWalletEntry initialWalletEntry) {

// Menu Button
JPopupMenu menu=new JPopupMenu();
JMenuItem m1=new JMenuItem("Edit...");
menu.add(m1);
//JMenuItem m1=new JMenuItem("Edit...");
//menu.add(m1);
JMenuItem m2=new JMenuItem("Show seed...");
m2.addActionListener(e-> {
AKeyPair kp=walletEntry.getKeyPair();
Expand Down
3 changes: 2 additions & 1 deletion convex-gui/src/main/java/convex/gui/utils/Toolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ public class Toolkit {
public static final int SMALL_ICON_SIZE = (int) (16*SCALE);
public static final int MAIN_ICON_SIZE = (int) (72*SCALE);

public static final float DEFAULT_FONT_SIZE=12*SCALE;
public static final float DEFAULT_FONT_SIZE=13*SCALE;

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 BIG_MONO_FONT = new Font(Font.MONOSPACED, Font.BOLD, (int)(DEFAULT_FONT_SIZE*1.5));
public static Font BUTTON_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, (int)(DEFAULT_FONT_SIZE*1.2));

public static final float SYMBOL_FONT_SIZE= DEFAULT_FONT_SIZE;
Expand Down
4 changes: 1 addition & 3 deletions convex-gui/src/main/java/convex/gui/wallet/TokenButton.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package convex.gui.wallet;

import java.awt.Font;

import javax.swing.Icon;
import javax.swing.JLabel;

Expand All @@ -17,7 +15,7 @@ public class TokenButton extends JLabel {
public TokenButton(TokenInfo token) {
Icon icon=getIcon(token);
this.setFocusable(false);
setFont(Toolkit.MONO_FONT.deriveFont(Font.BOLD));
setFont(Toolkit.BIG_MONO_FONT);
setIconTextGap(10);
setText(token.getSymbol());
setIcon(icon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public TokenComponent(Convex convex, TokenInfo token) {

balanceLabel = new BalanceLabel();
balanceLabel.setDecimals(token.getDecimals());
balanceLabel.setFont(Toolkit.MONO_FONT);
balanceLabel.setFont(Toolkit.BIG_MONO_FONT);
balanceLabel.setToolTipText("Account balance for "+token.getSymbol());
add(balanceLabel,"align right");

Expand Down
12 changes: 12 additions & 0 deletions convex-gui/src/main/java/convex/gui/wallet/WalletApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.swing.SwingConstants;

import convex.api.Convex;
import convex.core.crypto.wallet.AWalletEntry;
import convex.dlfs.DLFS;
import convex.gui.components.AbstractGUI;
import convex.gui.components.ConnectPanel;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class WalletApp extends AbstractGUI {
public WalletApp(Convex convex) {
super ("Convex Wallet");
this.convex=convex;

setLayout(new MigLayout("fill"));

add(new AccountOverview(convex),"dock north");
Expand All @@ -59,6 +61,16 @@ public WalletApp(Convex convex) {

this.add(tabs, "dock center");
}

@Override
public void afterRun() {
if (convex.getKeyPair()==null) {
AWalletEntry we=KeyRingPanel.findWalletEntry(convex);
if (we!=null) {
convex.setKeyPair(we.getKeyPair());
}
}
}

private void addTab(String name, SymbolIcon icon, JComponent panel) {
tabs.addTab("", icon, panel);
Expand Down

0 comments on commit 6155242

Please sign in to comment.