Skip to content

Commit

Permalink
More GUI updates, better wallet layout
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Apr 29, 2024
1 parent af3550f commit 913f273
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public class AccountChooserPanel extends JPanel {
public AccountChooserPanel(Convex convex) {
this.convex=convex;

MigLayout layout = new MigLayout("insets 10 10 10 10,fill");
MigLayout layout = new MigLayout("insets 10 10 10 10");
setLayout(layout);

{
JPanel mp=new JPanel();
mp.setLayout(new MigLayout());

// Account selection
mp.add(new JLabel("Account:"));
Expand Down Expand Up @@ -89,19 +90,19 @@ public AccountChooserPanel(Convex convex) {
add(mp,"dock west");
}


// Blank space
add(new JPanel(),"growx");

// Mode selection
{
JPanel mp=new JPanel();
mp.setLayout(new MigLayout());
mp.setBorder(null);
modeCombo = new JComboBox<String>();
modeCombo.setToolTipText("Use Transact to execute transactions (uses Convex Coins).\n\n"
+ "Use Query to compute results without changing on-chain state (free).");
+ "Use Query to compute results without changing on-chain state (free).\n\n"
//+ "Use Prepare to run transaction with advanced options."
);
modeCombo.addItem("Transact");
modeCombo.addItem("Query");
// modeCombo.addItem("Prepare...");
if (convex.getKeyPair()==null) modeCombo.setSelectedItem("Query");
mp.add(modeCombo);
add(mp,"dock east");
Expand Down
22 changes: 22 additions & 0 deletions convex-gui/src/main/java/convex/gui/components/CodePane.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package convex.gui.components;

import java.awt.Color;

import javax.swing.JTextPane;

@SuppressWarnings("serial")
public class CodePane extends JTextPane {

public CodePane() {
RightCopyMenu.addTo(this);

// stop catching focus movement keys, useful for Ctrl+up and down etc
setFocusTraversalKeysEnabled(false);

setBackground(Color.BLACK);
}

@Override public boolean getScrollableTracksViewportWidth() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public PeerComponent(ConvexLocal value) {

// Convex Button
JButton button = new BaseImageButton(Toolkit.CONVEX);
button.setFocusable(false);
button.addActionListener(e -> {
launchPeerWindow(this.convex);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public QRCodePanel(String data, int scale) {
image=createQR(data,scale);

this.setLayout(new MigLayout());
this.setPreferredSize(new Dimension(image.getWidth(),image.getHeight()));
this.setMinimumSize(new Dimension(image.getWidth(),image.getHeight()));
}

public static BufferedImage createQR(String data,int scale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static class ScrollablePanel extends JPanel implements Scrollable {

@Override
public Dimension getPreferredScrollableViewportSize() {
return new Dimension(800, 600);
return getPreferredSize();
}

@Override
Expand Down Expand Up @@ -74,7 +74,7 @@ public ScrollyList(ListModel<E> model, Function<E, Component> builder) {
this.model = model;
this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

listPanel.setLayout(new MigLayout("wrap 1","[fill,grow]"));
listPanel.setLayout(new MigLayout("wrap 1"));
setViewportView(listPanel);
getViewport().setBackground(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ public Component getListCellRendererComponent(JList<? extends AWalletEntry> list
AWalletEntry entry= (AWalletEntry)value;
if (entry!=null) {
AccountKey pubKey=entry.getPublicKey();
setText(pubKey.toHexString(12)+"...");
setText(pubKey.toHexString(16)+"...");
setIcon(Identicon.createIcon(entry.getIdenticonData(),21));
} else {
setText("<none>");
setText("<no key pair set>");
setIcon(Identicon.createIcon(Blobs.empty(),21));
}
return this;
Expand Down
4 changes: 2 additions & 2 deletions convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void addWalletEntry(AWalletEntry we) {
public KeyRingPanel() {
setLayout(new MigLayout());

// Scrollable list of wallet entrues
// Scrollable list of wallet entries
walletList = new ScrollyList<AWalletEntry>(listModel, we -> new WalletComponent(we));
add(walletList, "dock center");

Expand Down Expand Up @@ -80,7 +80,7 @@ public KeyRingPanel() {
AKeyPair newKP=AKeyPair.create(seed);
listModel.addElement(HotWalletEntry.create(newKP));
} catch (Exception t) {
Toast.display(this,"Exception importing seedt: "+t.getMessage(),Color.RED);
Toast.display(this,"Exception importing seed: "+t.getMessage(),Color.RED);
t.printStackTrace();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public WalletComponent(AWalletEntry initialWalletEntry) {

infoLabel = new CodeLabel(getInfoString());
cPanel.add(infoLabel,"dock center");
add(cPanel,"dock center"); // add to MigLayout
//add(cPanel,"dock center"); // add to MigLayout
add(cPanel); // add to MigLayout

//////////// Buttons
buttons = new JPanel();
Expand Down
91 changes: 49 additions & 42 deletions convex-gui/src/main/java/convex/gui/peer/windows/REPLPanel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package convex.gui.peer.windows;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
Expand All @@ -25,6 +25,7 @@
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
Expand Down Expand Up @@ -52,14 +53,15 @@
import convex.core.util.Utils;
import convex.gui.components.AccountChooserPanel;
import convex.gui.components.ActionPanel;
import convex.gui.components.RightCopyMenu;
import convex.gui.components.CodePane;
import convex.gui.utils.CVXHighlighter;
import net.miginfocom.swing.MigLayout;

@SuppressWarnings("serial")
public class REPLPanel extends JPanel {

JTextPane inputArea;
JTextPane outputArea;
CodePane inputArea;
CodePane outputArea;
private JButton btnClear;
private JButton btnInfo;
private JCheckBox btnResults;
Expand All @@ -76,11 +78,12 @@ public class REPLPanel extends JPanel {
private Font INPUT_FONT=new Font("Monospaced", Font.PLAIN, 30);
private Color DEFAULT_OUTPUT_COLOR=Color.LIGHT_GRAY;

private JPanel panel_1;
private JPanel actionPanel;

private AccountChooserPanel execPanel;

private final Convex convex;
private JSplitPane splitPane;

private static final Logger log = LoggerFactory.getLogger(REPLPanel.class.getName());

Expand Down Expand Up @@ -128,7 +131,7 @@ protected void handleError(ACell code, ACell msg, AVector<AString> trace) {
}
}

private void addOutput(JTextPane pane, String text) {
private void addOutput(JTextComponent pane, String text) {
addOutput(pane,text,DEFAULT_OUTPUT_COLOR);
}

Expand All @@ -140,7 +143,7 @@ private void addOutputWithHighlight(JTextPane pane, String text) {
if (end>start) updateHighlight(pane,start,end-start);
}

private void addOutput(JTextPane pane, String text, Color c) {
private void addOutput(JTextComponent pane, String text, Color c) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

Expand All @@ -166,57 +169,54 @@ public REPLPanel(Convex convex) {
this.convex=convex;
execPanel=new AccountChooserPanel(convex);

setLayout(new BorderLayout(0, 0));
setLayout(new MigLayout());

// TOP Account Chooser
// Set up account chooser panel
add(execPanel, BorderLayout.NORTH);
add(execPanel, "dock north");

// Split pane for main GUI elements
// MAIN SPLIT PANE for main GUI elements

JSplitPane splitPane = new JSplitPane();
splitPane.setResizeWeight(0.8);
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setResizeWeight(0.7);
splitPane.setOneTouchExpandable(true);
splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
add(splitPane, BorderLayout.CENTER);
add(splitPane, "dock center");

outputArea = new JTextPane();
//outputArea.setRows(15);
outputArea = new CodePane();
outputArea.setEditable(false);
//outputArea.setLineWrap(true);
outputArea.setFont(OUTPUT_FONT);
RightCopyMenu.addTo(outputArea);
//outputArea.setForeground(Color.GREEN);
outputArea.setBackground(new Color(10,10,10));
outputArea.setToolTipText("This area shows a log of output from transaction execution");
outputArea.setToolTipText("Output from transaction execution");
//DefaultCaret caret = (DefaultCaret)(outputArea.getCaret());
//caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
splitPane.setLeftComponent(new JScrollPane(outputArea));
splitPane.setLeftComponent(wrapScrollPane(outputArea));

inputArea = new JTextPane();
inputArea = new CodePane();
inputArea.setFont(INPUT_FONT);
inputArea.getDocument().addDocumentListener(inputListener);
inputArea.addKeyListener(inputListener);
inputArea.setBackground(Color.BLACK);
inputArea.setToolTipText("Input commands here. Press Enter at the end of input to send.");
RightCopyMenu.addTo(inputArea);
inputArea.setToolTipText("Input commands here (Press Enter at the end of input to send)");
//inputArea.setForeground(Color.GREEN);

splitPane.setRightComponent(new JScrollPane(inputArea));
splitPane.setRightComponent(wrapScrollPane(inputArea));

// stop ctrl+arrow losing focus
setFocusTraversalKeysEnabled(false);
inputArea.setFocusTraversalKeysEnabled(false);


panel_1 = new ActionPanel();
add(panel_1, BorderLayout.SOUTH);
// BOTTOM ACTION PANEL

actionPanel = new ActionPanel();
add(actionPanel, "dock south");

btnClear = new JButton("Clear");
panel_1.add(btnClear);
btnClear.addActionListener(e -> outputArea.setText(""));
actionPanel.add(btnClear);
btnClear.addActionListener(e -> {
outputArea.setText("");
});

btnInfo = new JButton("Connection Info");
panel_1.add(btnInfo);
actionPanel.add(btnInfo);
btnInfo.addActionListener(e -> {
StringBuilder sb=new StringBuilder();
if (convex instanceof ConvexRemote) {
Expand All @@ -237,20 +237,20 @@ public REPLPanel(Convex convex) {

btnTX=new JCheckBox("Show transaction");
btnTX.setToolTipText("Tick to show full transaction details.");
panel_1.add(btnTX);
actionPanel.add(btnTX);

btnResults=new JCheckBox("Full Results");
btnResults.setToolTipText("Tick to show full Result record returned from peer.");
panel_1.add(btnResults);
actionPanel.add(btnResults);

btnTiming=new JCheckBox("Show Timing");
btnTiming.setToolTipText("Tick to receive execution time report after each transaction.");
panel_1.add(btnTiming);
actionPanel.add(btnTiming);

btnCompile=new JCheckBox("Precompile");
btnCompile.setToolTipText("Tick to compile code before sending transaction. Usually reduces juice costs.");
btnCompile.setSelected(convex.getLocalServer()!=null); // default: only do this if local
panel_1.add(btnCompile);
actionPanel.add(btnCompile);


// Get initial focus in REPL input area
Expand All @@ -261,6 +261,11 @@ public void componentShown(ComponentEvent ce) {
});
}

private Component wrapScrollPane(CodePane codePane) {
JScrollPane scrollPane=new JScrollPane(codePane);
return scrollPane;
}

private AKeyPair getKeyPair() {
return execPanel.getConvex().getKeyPair();
}
Expand All @@ -283,16 +288,16 @@ private void sendMessage(String s) {
AList<ACell> forms = Reader.readAll(s);
ACell code = (forms.count()==1)?forms.get(0):forms.cons(Symbols.DO);
Future<Result> future;
String mode = execPanel.getMode();

if (btnCompile.isSelected()) {
ACell compileStep=List.of(Symbols.COMPILE,List.of(Symbols.QUOTE,code));
Result cr=convex.querySync(compileStep);
code=cr.getValue();
}

long start=Utils.getCurrentTimestamp();
String mode = execPanel.getMode();

long start=Utils.getCurrentTimestamp();
if (mode.equals("Query")) {
Address qaddr=getAddress();
if (qaddr == null) {
Expand All @@ -303,7 +308,9 @@ private void sendMessage(String s) {
} else if (mode.equals("Transact")) {
Address address = getAddress();
convex.setAddress(address);
convex.setKeyPair(getKeyPair());
AKeyPair kp=getKeyPair();
if (kp==null) throw new IllegalStateException("Can't transact without a valid key pair");
convex.setKeyPair(kp);
ATransaction trans = Invoke.create(address,0, code);
SignedData<ATransaction> strans=convex.prepareTransaction(trans);

Expand All @@ -314,7 +321,7 @@ private void sendMessage(String s) {

future = convex.transact(strans);
} else {
throw new Error("Unrecognosed REPL mode: " + mode);
throw new Exception("Unrecognosed REPL mode: " + mode);
}
log.trace("Sent message");

Expand All @@ -323,8 +330,8 @@ private void sendMessage(String s) {
addOutput(outputArea," PARSE ERROR: "+e.getMessage(),Color.RED);
} catch (TimeoutException t) {
addOutput(outputArea," TIMEOUT waiting for result",Color.RED);
} catch (Throwable t) {
addOutput(outputArea," SEND ERROR: ",Color.RED);
} catch (Exception t) {
addOutput(outputArea," ERROR: ",Color.RED);
addOutput(outputArea,t.getMessage() + "\n");
t.printStackTrace();
}
Expand Down
Loading

0 comments on commit 913f273

Please sign in to comment.