@Override public void actionPerformed(ActionEvent ae) { try { String action = ae.getActionCommand(); switch (action) { case "sign": String message = messageField.getText(); if (message.length() == 0) { UIRes.showErrorMessage(this, "Error", "You must enter the message text to sign"); } else { int index = nameField.getSelectedIndex(); ECKey key = BTCLoader.keys.get(index); String signature = key.signMessage(message); signatureField.setText(signature); } break; case "copy": String signature = signatureField.getText(); StringSelection sel = new StringSelection(signature); Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); cb.setContents(sel, null); break; case "done": setVisible(false); dispose(); break; } } catch (ECException exc) { ErrorLog.get().logException("Unable to sign message", exc); } catch (Exception exc) { ErrorLog.get().logException("Exception while processing action event", exc); } }
public SignDialog(JDialog parent) { super(parent, "Sign Message", Dialog.ModalityType.DOCUMENT_MODAL); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); String[] keyLabels = new String[BTCLoader.keys.size()]; int index = 0; for (ECKey key : BTCLoader.keys) { keyLabels[index++] = key.getLabel(); } nameField = new JComboBox<Object>(keyLabels); nameField.setPreferredSize(new Dimension(200, 25)); JPanel namePane = new JPanel(); namePane.add(new JLabel("Key ", JLabel.RIGHT)); namePane.add(nameField); messageField = new JTextArea(10, 70); messageField.setLineWrap(true); messageField.setWrapStyleWord(true); messageField.setFont(nameField.getFont()); scrollPane = new JScrollPane(messageField); JPanel messagePane = new JPanel(); messagePane.add(new JLabel("Message ", JLabel.RIGHT)); messagePane.add(scrollPane); signatureField = new JTextField("", 70); signatureField.setEditable(false); JPanel signaturePane = new JPanel(); signaturePane.add(new JLabel("Signature ", JLabel.RIGHT)); signaturePane.add(signatureField); JPanel buttonPane = new ButtonPane( this, 10, new String[] {"Sign", "sign"}, new String[] {"Copy", "copy"}, new String[] {"Done", "done"}); JPanel contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); contentPane.setOpaque(true); contentPane.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); contentPane.add(namePane); contentPane.add(Box.createVerticalStrut(15)); contentPane.add(messagePane); contentPane.add(Box.createVerticalStrut(15)); contentPane.add(signaturePane); contentPane.add(Box.createVerticalStrut(15)); contentPane.add(buttonPane); setContentPane(contentPane); }
private void editKey(ECKey key, int row) throws BlockStoreException { Address addr = key.toAddress(); while (true) { addr = AddressEditDialog.showDialog(this, addr, false); if (addr == null) break; String label = addr.getLabel(); boolean valid = true; synchronized (BTCLoader.lock) { for (ECKey chkKey : BTCLoader.keys) { if (chkKey == key) continue; if (chkKey.getLabel().compareToIgnoreCase(label) == 0) { JOptionPane.showMessageDialog( this, "Duplicate name specified", "Error", JOptionPane.ERROR_MESSAGE); valid = false; break; } } if (valid) { if (row >= 0) BTCLoader.keys.remove(row); boolean added = false; for (int i = 0; i < BTCLoader.keys.size(); i++) { ECKey chkKey = BTCLoader.keys.get(i); if (chkKey.getLabel().compareToIgnoreCase(label) > 0) { key.setLabel(label); BTCLoader.keys.add(i, key); added = true; break; } } if (!added) { key.setLabel(label); BTCLoader.keys.add(key); } } } if (valid) { if (row >= 0) { BTCLoader.blockStore.setKeyLabel(key); } else { BTCLoader.blockStore.storeKey(key); BTCLoader.bloomFilter.insert(key.getPubKey()); BTCLoader.bloomFilter.insert(key.getPubKeyHash()); Message filterMsg = FilterLoadMessage.buildFilterLoadMessage(null, BTCLoader.bloomFilter); BTCLoader.networkHandler.broadcastMessage(filterMsg); } tableModel.fireTableDataChanged(); break; } } }
@Override public Object getValueAt(int row, int column) { if (row >= BTCLoader.keys.size()) { throw new IndexOutOfBoundsException("Table row " + row + " is not valid"); } Object value; ECKey key = BTCLoader.keys.get(row); switch (column) { case 0: value = key.getLabel(); break; case 1: value = key.toAddress().toString(); break; default: throw new IndexOutOfBoundsException("Table column " + column + " is not valid"); } return value; }