diff --git a/convex-core/src/main/java/convex/core/store/AStore.java b/convex-core/src/main/java/convex/core/store/AStore.java index 4f61c1246..ce300bca9 100644 --- a/convex-core/src/main/java/convex/core/store/AStore.java +++ b/convex-core/src/main/java/convex/core/store/AStore.java @@ -139,4 +139,6 @@ protected ACell decodeImpl(Blob encoding) throws BadFormatException { * @return Stored Ref, or null if not found (may still be in persistent store) */ public abstract Ref checkCache(Hash h); + + public abstract String shortName(); } diff --git a/convex-core/src/main/java/convex/core/store/MemoryStore.java b/convex-core/src/main/java/convex/core/store/MemoryStore.java index dcf616ee8..29efd3d08 100644 --- a/convex-core/src/main/java/convex/core/store/MemoryStore.java +++ b/convex-core/src/main/java/convex/core/store/MemoryStore.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.util.HashMap; +import java.util.Objects; import java.util.function.Consumer; import org.slf4j.Logger; @@ -144,4 +145,9 @@ public void close() { public Ref checkCache(Hash h) { return refForHash(h); } + + @Override + public String shortName() { + return "Memory Store "+Objects.toIdentityString(this); + } } diff --git a/convex-core/src/main/java/convex/core/text/Text.java b/convex-core/src/main/java/convex/core/text/Text.java index 627f73bc4..d8d9d54b6 100644 --- a/convex-core/src/main/java/convex/core/text/Text.java +++ b/convex-core/src/main/java/convex/core/text/Text.java @@ -129,6 +129,32 @@ public static void writeEscapedByte(BlobBuilder sb, byte b) { } } + public static int lineCount(String text) { + if (text==null) return 0; + + int n=1; + for (int i=0; iresult) result=n; + } + } + return result; + } + } diff --git a/convex-core/src/main/java/etch/Etch.java b/convex-core/src/main/java/etch/Etch.java index e12084eba..e88125f34 100644 --- a/convex-core/src/main/java/etch/Etch.java +++ b/convex-core/src/main/java/etch/Etch.java @@ -153,7 +153,7 @@ private Etch(File dataFile) throws IOException { if (!dataFile.exists()) dataFile.createNewFile(); this.data=new RandomAccessFile(dataFile,"rw"); - this.fileName = dataFile.getCanonicalPath(); + this.fileName = dataFile.getName(); // Try to exclusively lock the Etch database file FileChannel fileChannel=this.data.getChannel(); diff --git a/convex-core/src/main/java/etch/EtchStore.java b/convex-core/src/main/java/etch/EtchStore.java index bbcc09c51..3a48cab8a 100644 --- a/convex-core/src/main/java/etch/EtchStore.java +++ b/convex-core/src/main/java/etch/EtchStore.java @@ -311,4 +311,10 @@ public Etch getEtch() { return etch; } + @Override + public String shortName() { + // TODO Auto-generated method stub + return "Etch: "+etch.getFileName(); + } + } diff --git a/convex-gui/pom.xml b/convex-gui/pom.xml index 33555f02c..8d9e86aae 100644 --- a/convex-gui/pom.xml +++ b/convex-gui/pom.xml @@ -137,7 +137,5 @@ ${slf4j.version} test - - \ No newline at end of file diff --git a/convex-gui/src/main/java/convex/gui/components/BaseImageButton.java b/convex-gui/src/main/java/convex/gui/components/BaseImageButton.java new file mode 100644 index 000000000..e662cb81e --- /dev/null +++ b/convex-gui/src/main/java/convex/gui/components/BaseImageButton.java @@ -0,0 +1,13 @@ +package convex.gui.components; + +import javax.swing.Icon; +import javax.swing.JButton; + +@SuppressWarnings("serial") +public class BaseImageButton extends JButton { + + public BaseImageButton(Icon icon) { + super(icon); + this.setAlignmentX(JButton.CENTER_ALIGNMENT); + } +} diff --git a/convex-gui/src/main/java/convex/gui/components/CodeLabel.java b/convex-gui/src/main/java/convex/gui/components/CodeLabel.java index 852843f4d..6eed4f1cd 100644 --- a/convex-gui/src/main/java/convex/gui/components/CodeLabel.java +++ b/convex-gui/src/main/java/convex/gui/components/CodeLabel.java @@ -2,6 +2,7 @@ import javax.swing.JTextArea; +import convex.core.text.Text; import convex.gui.utils.Toolkit; /** @@ -11,8 +12,10 @@ public class CodeLabel extends JTextArea { public CodeLabel(String text) { + super(Text.lineCount(text),Text.columnCount(text)+1); this.setText(text); this.setEditable(false); this.setFont(Toolkit.SMALL_MONO_FONT); + } } diff --git a/convex-gui/src/main/java/convex/gui/components/DropdownMenu.java b/convex-gui/src/main/java/convex/gui/components/DropdownMenu.java index 94889c011..e63b068e7 100644 --- a/convex-gui/src/main/java/convex/gui/components/DropdownMenu.java +++ b/convex-gui/src/main/java/convex/gui/components/DropdownMenu.java @@ -1,24 +1,24 @@ package convex.gui.components; -import javax.swing.JButton; import javax.swing.JPopupMenu; +import convex.gui.utils.SymbolIcon; import convex.gui.utils.Toolkit; /** * A dropdown menu that can be used wherever an embedded menu is needed. */ @SuppressWarnings("serial") -public class DropdownMenu extends JButton { +public class DropdownMenu extends BaseImageButton { private JPopupMenu popupMenu; - + public DropdownMenu(JPopupMenu popupMenu) { - super(); + super(SymbolIcon.get(0xe8b8, Toolkit.SYMBOL_SIZE)); this.popupMenu = popupMenu; - this.setIcon(Toolkit.COG); - this.addActionListener(e -> { - popupMenu.show(this, 0, this.getHeight()); + // setIconTextGap(0); + this.addActionListener(e->{ + popupMenu.show(DropdownMenu.this, 0, DropdownMenu.this.getHeight()); }); } diff --git a/convex-gui/src/main/java/convex/gui/components/Identicon.java b/convex-gui/src/main/java/convex/gui/components/Identicon.java index 5839d325b..d78e6420b 100644 --- a/convex-gui/src/main/java/convex/gui/components/Identicon.java +++ b/convex-gui/src/main/java/convex/gui/components/Identicon.java @@ -85,6 +85,7 @@ public static ImageIcon createIcon(AArrayBlob hash, int size) { public Identicon(AArrayBlob a) { super(); setKey(a); + setFont(Toolkit.SMALL_MONO_FONT); setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null)); Toolkit.addPopupMenu(this,new JPopupMenu() { diff --git a/convex-gui/src/main/java/convex/gui/components/PeerComponent.java b/convex-gui/src/main/java/convex/gui/components/PeerComponent.java index 761105c5b..25cff6e45 100644 --- a/convex-gui/src/main/java/convex/gui/components/PeerComponent.java +++ b/convex-gui/src/main/java/convex/gui/components/PeerComponent.java @@ -1,6 +1,5 @@ package convex.gui.components; -import java.awt.BorderLayout; import java.io.IOException; import java.util.concurrent.TimeoutException; @@ -9,7 +8,6 @@ import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JTextArea; -import javax.swing.border.EmptyBorder; import convex.api.Convex; import convex.api.ConvexLocal; @@ -32,6 +30,7 @@ import convex.peer.ConnectionManager; import convex.peer.Server; import etch.EtchStore; +import net.miginfocom.swing.MigLayout; @SuppressWarnings("serial") public class PeerComponent extends BaseListComponent { @@ -63,73 +62,69 @@ public void launchExploreWindow(Convex peer) { public PeerComponent(ConvexLocal value) { this.convex = value; - setLayout(new BorderLayout(0, 0)); + setLayout(new MigLayout()); // setPreferredSize(new Dimension(1000, 90)); - JButton button = new JButton(""); - button.setBorder(null); - add(button, BorderLayout.WEST); - button.setIcon(Toolkit.CONVEX); + // Convex Button + JButton button = new BaseImageButton(Toolkit.CONVEX); button.addActionListener(e -> { launchPeerWindow(this.convex); }); button.setToolTipText("Launch Peer management window"); + add(button, "dock west"); + + // Central area - JPanel panel = new JPanel(); - panel.setBorder(new EmptyBorder(5, 5, 5, 5)); - add(panel); - panel.setLayout(new BorderLayout(0, 0)); - - description = new JTextArea((convex == null) ? "No peer" : convex.toString()); + JPanel centralPanel = new JPanel(); + centralPanel.setLayout(new MigLayout("fill, wrap 2","[][grow]")); + + Server server=convex.getLocalServer(); + AccountKey peerKey=server.getPeerKey(); + Identicon identicon=new Identicon(peerKey); + centralPanel.add(identicon); + centralPanel.add(new CodeLabel("0x"+peerKey.toChecksumHex()),"span"); + + description = new CodeLabel(getPeerDescription()); description.setFont(Toolkit.SMALL_MONO_FONT); description.setEditable(false); description.setBorder(null); description.setBackground(null); - panel.add(description, BorderLayout.CENTER); + centralPanel.add(description, "span 2"); + add(centralPanel,"dock center"); // Setup popup menu for peer JPopupMenu popupMenu = new JPopupMenu(); - Server server=convex.getLocalServer(); - if (server!=null) { - JMenuItem closeButton = new JMenuItem("Shutdown Peer"); - closeButton.addActionListener(e -> { - try { - server.shutdown(); - } catch (Exception e1) { - // ignore - } - }); - popupMenu.add(closeButton); - JMenuItem exploreButton = new JMenuItem("Explore state"); - exploreButton.addActionListener(e -> { - launchExploreWindow(convex); - }); - popupMenu.add(exploreButton); - - if (server.getStore() instanceof EtchStore) { - JMenuItem storeButton = new JMenuItem("Explore Etch store"); - storeButton.addActionListener(e -> { - launchEtchWindow(convex); - }); - popupMenu.add(storeButton); + JMenuItem closeButton = new JMenuItem("Shutdown Peer"); + closeButton.addActionListener(e -> { + try { + server.shutdown(); + } catch (Exception e1) { + // ignore } - - - JMenuItem killConn = new JMenuItem("Kill Connections"); - killConn.addActionListener(e -> { - server.getConnectionManager().closeAllConnections(); - }); - popupMenu.add(killConn); - - } else { - JMenuItem closeButton = new JMenuItem("Close connection"); - closeButton.addActionListener(e -> { - convex.close(); + }); + popupMenu.add(closeButton); + + JMenuItem exploreButton = new JMenuItem("Explore state"); + exploreButton.addActionListener(e -> { + launchExploreWindow(convex); + }); + popupMenu.add(exploreButton); + + if (server.getStore() instanceof EtchStore) { + JMenuItem storeButton = new JMenuItem("Explore Etch store"); + storeButton.addActionListener(e -> { + launchEtchWindow(convex); }); - popupMenu.add(closeButton); + popupMenu.add(storeButton); } + + JMenuItem killConn = new JMenuItem("Kill Connections"); + killConn.addActionListener(e -> { + server.getConnectionManager().closeAllConnections(); + }); + popupMenu.add(killConn); JMenuItem replButton = new JMenuItem("Launch REPL"); replButton.addActionListener(e -> launchPeerWindow(this.convex)); @@ -139,12 +134,13 @@ public PeerComponent(ConvexLocal value) { clientButton.addActionListener(e -> launchClientWindow(convex)); popupMenu.add(clientButton); - JPanel blockView = new BlockViewComponent(convex); - add(blockView, BorderLayout.SOUTH); DropdownMenu dm = new DropdownMenu(popupMenu); - add(dm, BorderLayout.EAST); + add(dm, "dock east"); + + // Block view at bottom + JPanel blockView = new BlockViewComponent(convex); StateModel model=PeerGUI.getStateModel(convex); if (model!=null) { model.addPropertyChangeListener(e->{ @@ -156,6 +152,10 @@ public PeerComponent(ConvexLocal value) { updateDescription(); }); } + add(blockView, "dock south"); + + + updateDescription(); } @@ -187,17 +187,19 @@ public String getPeerDescription() { if (server != null) { State state=server.getPeer().getConsensusState(); AccountKey paddr=server.getPeerKey(); - sb.append("0x"+paddr.toChecksumHex()+"\n"); - sb.append("Local peer on: " + server.getHostAddress() + " with store "+server.getStore()+"\n"); + // sb.append("0x"+paddr.toChecksumHex()+"\n"); + sb.append("Local peer on: " + server.getHostAddress() + " with store "+server.getStore().shortName()+"\n"); PeerStatus ps=state.getPeer(paddr); if (ps!=null) { sb.append("Peer Stake: "+Text.toFriendlyBalance(ps.getPeerStake())); sb.append(" "); sb.append("Delegated Stake: "+Text.toFriendlyBalance(ps.getDelegatedStake())); + sb.append(" "); + } else { + sb.append("Not currently a rgistered peer "); } ConnectionManager cm=server.getConnectionManager(); - sb.append("\n"); sb.append("Connections: "+cm.getConnectionCount()); } else if (convex != null) { sb.append(convex.toString()); diff --git a/convex-gui/src/main/java/convex/gui/keys/WalletComponent.java b/convex-gui/src/main/java/convex/gui/keys/WalletComponent.java index 42cbb5b98..9eddadc56 100644 --- a/convex-gui/src/main/java/convex/gui/keys/WalletComponent.java +++ b/convex-gui/src/main/java/convex/gui/keys/WalletComponent.java @@ -32,7 +32,7 @@ public class WalletComponent extends BaseListComponent { AWalletEntry walletEntry; - JPanel buttons = new JPanel(); + JPanel buttons; private CodeLabel infoLabel; @@ -60,7 +60,9 @@ public WalletComponent(AWalletEntry initialWalletEntry) { add(cPanel,"dock center"); // add to MigLayout //////////// Buttons - + buttons = new JPanel(); + buttons.setLayout(new MigLayout()); + // lock button lockButton = new JButton(""); buttons.add(lockButton); @@ -109,8 +111,7 @@ public WalletComponent(AWalletEntry initialWalletEntry) { }); menu.add(m3); - - DropdownMenu menuButton=new DropdownMenu(menu); + DropdownMenu menuButton=new DropdownMenu(menu); buttons.add(menuButton); // panel of buttons on right diff --git a/convex-gui/src/main/java/convex/gui/utils/Toolkit.java b/convex-gui/src/main/java/convex/gui/utils/Toolkit.java index 5d3aca5b6..e71e37298 100644 --- a/convex-gui/src/main/java/convex/gui/utils/Toolkit.java +++ b/convex-gui/src/main/java/convex/gui/utils/Toolkit.java @@ -54,6 +54,8 @@ @SuppressWarnings("serial") public class Toolkit { + private static final int ICON_SIZE = 48; + private static Logger log = LoggerFactory.getLogger(Toolkit.class.getName()); public static Font DEFAULT_FONT = new JLabel().getFont(); @@ -64,7 +66,7 @@ public class Toolkit { public static final int SCREEN_RES=Toolkit.getDefaultToolkit().getScreenResolution(); - public static final int SYMBOL_SIZE = 32; + public static final int SYMBOL_SIZE = ICON_SIZE; public static final float SYMBOL_FONT_SIZE= 72.0f * SYMBOL_SIZE / SCREEN_RES; public static Font SYMBOL_FONT = new Font(Font.MONOSPACED, Font.BOLD, (int)SYMBOL_FONT_SIZE); @@ -120,14 +122,16 @@ public class Toolkit { // scaledIcon(36,"/images/ic_lock_outline_black_36dp.png"); // public static final ImageIcon UNLOCKED_ICON = // scaledIcon(36,"/images/ic_lock_open_black_36dp.png"); - - public static final ImageIcon LOCKED_ICON = scaledIcon(36, "/images/padlock.png"); - public static final ImageIcon UNLOCKED_ICON = scaledIcon(36, "/images/padlock-open.png"); - public static final ImageIcon WARNING = scaledIcon(36, "/images/ic_priority_high_black_36dp.png"); - public static final ImageIcon CAKE = scaledIcon(36, "/images/ic_cake_black_36dp.png"); - public static final ImageIcon CONVEX = scaledIcon(36, "/images/Convex.png"); - public static final ImageIcon COG = scaledIcon(36, "/images/cog.png"); - public static final ImageIcon REPL_ICON = scaledIcon(36, "/images/terminal-icon.png"); + //public static final ImageIcon LOCKED_ICON = scaledIcon(ICON_SIZE, "/images/padlock.png"); + //public static final ImageIcon UNLOCKED_ICON = scaledIcon(ICON_SIZE, "/images/padlock-open.png"); + + public static final ImageIcon LOCKED_ICON = SymbolIcon.get(0xe897,ICON_SIZE); + public static final ImageIcon UNLOCKED_ICON = SymbolIcon.get(0xe898,ICON_SIZE); + public static final ImageIcon WARNING = scaledIcon(ICON_SIZE, "/images/ic_priority_high_black_36dp.png"); + public static final ImageIcon CAKE = scaledIcon(ICON_SIZE, "/images/ic_cake_black_36dp.png"); + public static final ImageIcon CONVEX = scaledIcon(ICON_SIZE, "/images/Convex.png"); + public static final ImageIcon COG = scaledIcon(ICON_SIZE, "/images/cog.png"); + public static final ImageIcon REPL_ICON = scaledIcon(ICON_SIZE, "/images/terminal-icon.png"); public static final ImageIcon TESTNET_ICON = scaledIcon(128, "/images/testnet.png"); public static final ImageIcon WWW_ICON = scaledIcon(128, "/images/www.png"); diff --git a/convex-peer/src/main/java/convex/api/Convex.java b/convex-peer/src/main/java/convex/api/Convex.java index 5bd0fb0cc..0e671f69c 100644 --- a/convex-peer/src/main/java/convex/api/Convex.java +++ b/convex-peer/src/main/java/convex/api/Convex.java @@ -975,7 +975,7 @@ public AKeyPair getKeyPair() { } /** - * Gets the local Server instance, or null is not a local connection + * Gets the local Server instance, or null if not a local connection * @return Server instance (or null) */ public abstract Server getLocalServer(); diff --git a/convex-peer/src/main/java/convex/net/store/RemoteStore.java b/convex-peer/src/main/java/convex/net/store/RemoteStore.java index 58cbda8f4..e30a5e823 100644 --- a/convex-peer/src/main/java/convex/net/store/RemoteStore.java +++ b/convex-peer/src/main/java/convex/net/store/RemoteStore.java @@ -65,4 +65,10 @@ public Ref checkCache(Hash h) { return null; } + @Override + public String shortName() { + // TODO Auto-generated method stub + return "Remote Store: "+convex.getHostAddress(); + } + }