Skip to content

Commit

Permalink
Misc GUI edits
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed May 11, 2024
1 parent 96dc5d6 commit 5ce01cf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Component getListCellRendererComponent(JList<? extends AWalletEntry> list
AWalletEntry entry= (AWalletEntry)value;
if (entry!=null) {
AccountKey pubKey=entry.getPublicKey();
setText(pubKey.toHexString(16)+"...");
setText("0x"+pubKey.toChecksumHex().substring(0,16)+"...");
setIcon(Identicon.createIcon(entry.getIdenticonData(),21));
} else {
setText("<no key pair set>");
Expand Down Expand Up @@ -154,7 +154,7 @@ public static KeyPairCombo create(AKeyPair kp) {
KeyPairModel model=new KeyPairModel();
if (kp!=null) {
AccountKey publicKey=kp.getAccountKey();
AWalletEntry we=Toolkit.getKeyRingEntry(publicKey);
AWalletEntry we=KeyRingPanel.getKeyRingEntry(publicKey);
if (we==null) {
we=new HotWalletEntry(kp);
}
Expand Down
6 changes: 4 additions & 2 deletions convex-gui/src/main/java/convex/gui/keys/KeyGenPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ public KeyGenPanel(PeerGUI manager) {
numSpinner.setModel(new SpinnerNumberModel(12, 3, 30, 1));
actionPanel.add(numSpinner);

JButton btnNewButton = new ActionButton("Export...",0xebbe,e->{});
JButton btnNewButton = new ActionButton("Export...",0xebbe,e->{

});
actionPanel.add(btnNewButton);

{ // Button to Normalise Mnemonic string
Expand All @@ -343,7 +345,7 @@ public KeyGenPanel(PeerGUI manager) {
actionPanel.add(btnNormalise);
}

addWalletButton=new ActionButton("Add to keyring",e -> {
addWalletButton=new ActionButton("Add to keyring",0xe145,e -> {
String pks = privateKeyArea.getText();
pks = Utils.stripWhiteSpace(pks);
HotWalletEntry we = HotWalletEntry.create(AKeyPair.create(Utils.hexToBytes(pks)));
Expand Down
22 changes: 21 additions & 1 deletion convex-gui/src/main/java/convex/gui/keys/KeyRingPanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package convex.gui.keys;

import java.awt.Color;
import java.util.Iterator;
import java.util.concurrent.CompletableFuture;

import javax.swing.DefaultListModel;
Expand All @@ -23,6 +24,7 @@
import convex.core.lang.RT;
import convex.core.lang.Symbols;
import convex.core.lang.ops.Special;
import convex.core.util.Utils;
import convex.gui.components.ActionButton;
import convex.gui.components.ActionPanel;
import convex.gui.components.ScrollyList;
Expand Down Expand Up @@ -114,11 +116,29 @@ public static AWalletEntry findWalletEntry(Convex convex) {
try {
CompletableFuture<ACell> cf=convex.query(Special.forSymbol(Symbols.STAR_KEY)).thenApply(r->r.getValue());
key = RT.ensureAccountKey(cf.get());
AWalletEntry we=Toolkit.getKeyRingEntry(key);
AWalletEntry we=KeyRingPanel.getKeyRingEntry(key);
return we;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

/**
* Gets an entry for the current keyring
* @param address
* @return Wallet Entry, or null if not found
*/
public static AWalletEntry getKeyRingEntry(AccountKey publicKey) {
if (publicKey==null) return null;
DefaultListModel<AWalletEntry> list = getListModel();
Iterator<AWalletEntry> it=list.elements().asIterator();
while (it.hasNext()) {
AWalletEntry we=it.next();
if (Utils.equals(we.getPublicKey(), publicKey)) {
return we;
}
}
return null;
}
}
34 changes: 7 additions & 27 deletions convex-gui/src/main/java/convex/gui/utils/Toolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Iterator;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.InputMap;
Expand All @@ -49,13 +47,12 @@
import com.formdev.flatlaf.FlatDarculaLaf;
import com.formdev.flatlaf.intellijthemes.materialthemeuilite.FlatMaterialOceanicIJTheme;

import convex.core.crypto.wallet.AWalletEntry;
import convex.core.data.AccountKey;
import convex.core.util.Utils;
import convex.gui.keys.KeyRingPanel;

@SuppressWarnings("serial")
public class Toolkit {

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

public static final float SCALE=getUIScale();

Expand All @@ -64,7 +61,6 @@ public class Toolkit {
public static final int SMALL_ICON_SIZE = (int) (16*SCALE);
public static final int MAIN_ICON_SIZE = (int) (64*SCALE);

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

public static final float DEFAULT_FONT_SIZE=14;

Expand Down Expand Up @@ -100,8 +96,10 @@ public class Toolkit {

UIManager.setLookAndFeel(laf);
FlatMaterialOceanicIJTheme.setup();
UIManager.put( "Button.foreground", BUTTON_FG );
System.out.println(UIManager.get("Label.foreground"));

// Override button foreground, too dark by default
UIManager.put( "Button.foreground", UIManager.get("Label.foreground") );
// System.out.println(UIManager.get("Label.foreground"));
} catch (Exception e) {
e.printStackTrace();
log.warn("Unable to set look and feel: {}", e);
Expand All @@ -119,7 +117,7 @@ public static float getUIScale() {
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice();
Double scale=screen.getDefaultConfiguration().getDefaultTransform().getScaleX();
System.err.println("UI Scale: "+scale);
log.debug("UI Scale: "+scale);
return (float)(scale.doubleValue());
}

Expand Down Expand Up @@ -313,24 +311,6 @@ private void maybeDisplayPopupMenu(MouseEvent e) {
});
}

/**
* Gets an entry for the current keyring
* @param address
* @return Wallet Entry, or null if not found
*/
public static AWalletEntry getKeyRingEntry(AccountKey publicKey) {
if (publicKey==null) return null;
DefaultListModel<AWalletEntry> list = KeyRingPanel.getListModel();
Iterator<AWalletEntry> it=list.elements().asIterator();
while (it.hasNext()) {
AWalletEntry we=it.next();
if (Utils.equals(we.getPublicKey(), publicKey)) {
return we;
}
}
return null;
}

public static Border createDialogBorder() {
return createEmptyBorder(20);
}
Expand Down

0 comments on commit 5ce01cf

Please sign in to comment.