Show a pretty icon for success/failure, improve the account info recognition, use Id and Key instead of email and password, and clean up the configuration dialog.
| 840 | 936 | |
|---|---|---|
| 20 | 20 | public class JConfigMyJBidwatcherTab extends JConfigTab { |
| 21 | 21 | private JCheckBox mEnable; |
| 22 | 22 | private JTextField mEmail; |
| 23 | private JPasswordField mPassword; | |
| 24 | private JTextField mUserId; | |
| 23 | private JTextField mPassword; | |
| 25 | 24 | private JButton mCreateOrUpdate; |
| 26 | 25 | private final OptionUI mOui = new OptionUI(); |
| 27 | 26 | |
| --- | --- | |
| 33 | 32 | JConfig.setConfiguration("my.jbidwatcher.enabled", Boolean.toString(enabled)); |
| 34 | 33 | |
| 35 | 34 | String email = mEmail.getText(); |
| 36 | char[] rawPassword = mPassword.getPassword(); | |
| 35 | String password = mPassword.getText(); | |
| 37 | 36 | |
| 38 | if(email != null && rawPassword != null) { | |
| 39 | String password = new String(rawPassword); | |
| 40 | if(MyJBidwatcher.getInstance().login(email, password)) { | |
| 41 | JConfig.setConfiguration("my.jbidwatcher.email", email); | |
| 42 | JConfig.setConfiguration("my.jbidwatcher.password", password); | |
| 37 | if(email != null && password != null) { | |
| 38 | if(MyJBidwatcher.getInstance().getAccountInfo()) { | |
| 39 | JConfig.setConfiguration("my.jbidwatcher.id", email); | |
| 40 | JConfig.setConfiguration("my.jbidwatcher.key", password); | |
| 43 | 41 | } |
| 44 | 42 | } |
| 45 | 43 | |
| --- | --- | |
| 47 | 45 | } |
| 48 | 46 | |
| 49 | 47 | public void updateValues() { |
| 50 | String email = JConfig.queryConfiguration("my.jbidwatcher.email", ""); | |
| 51 | String pass = JConfig.queryConfiguration("my.jbidwatcher.password", ""); | |
| 48 | String email = JConfig.queryConfiguration("my.jbidwatcher.id", ""); | |
| 49 | String pass = JConfig.queryConfiguration("my.jbidwatcher.key", ""); | |
| 52 | 50 | boolean enabled = JConfig.queryConfiguration("my.jbidwatcher.enabled", "false").equals("true"); |
| 53 | String id = JConfig.queryConfiguration("my.jbidwatcher.id"); | |
| 51 | // String id = JConfig.queryConfiguration("my.jbidwatcher.id"); | |
| 54 | 52 | |
| 55 | 53 | mEmail.setText(email); |
| 56 | 54 | mPassword.setText(pass); |
| 57 | 55 | mEnable.setSelected(enabled); |
| 58 | 56 | |
| 59 | if(id != null && id.length() != 0) { | |
| 60 | mUserId.setText(id); | |
| 61 | mCreateOrUpdate.setText("Update"); | |
| 62 | } else { | |
| 63 | mUserId.setText(""); | |
| 64 | mCreateOrUpdate.setText("Create"); | |
| 65 | } | |
| 66 | ||
| 67 | 57 | for(ActionListener al : mEnable.getActionListeners()) { |
| 68 | 58 | al.actionPerformed(new ActionEvent(mEnable, ActionEvent.ACTION_PERFORMED, "Redraw")); |
| 69 | 59 | } |
| --- | --- | |
| 74 | 64 | comp.getAccessibleContext().setAccessibleDescription(text); |
| 75 | 65 | } |
| 76 | 66 | |
| 67 | private static final ImageIcon successIcon = new ImageIcon(JConfig.getResource("/icons/status_green_16.png")); | |
| 68 | private static final ImageIcon failIcon = new ImageIcon(JConfig.getResource("/icons/status_red_16.png")); | |
| 69 | ||
| 77 | 70 | private JPanel buildUserSettings() { |
| 78 | 71 | JPanel jp = new JPanel(new BorderLayout()); |
| 79 | 72 | jp.setBorder(BorderFactory.createTitledBorder("My JBidwatcher User Settings")); |
| --- | --- | |
| 89 | 82 | innerPanel.add(emailLabel); |
| 90 | 83 | innerPanel.add(mEmail); |
| 91 | 84 | |
| 92 | mPassword = new JPasswordField(); | |
| 85 | mPassword = new JTextField(); | |
| 93 | 86 | mPassword.addMouseListener(JPasteListener.getInstance()); |
| 94 | setComponentTooltip(mPassword, "Password to use on My JBidwatcher (NOT the same as your eBay password!)"); | |
| 95 | final JLabel passwordLabel = new JLabel("My JBid Password:"); | |
| 87 | setComponentTooltip(mPassword, "My JBidwatcher access key"); | |
| 88 | final JLabel passwordLabel = new JLabel("Access Key:"); | |
| 96 | 89 | passwordLabel.setLabelFor(mPassword); |
| 97 | 90 | innerPanel.add(passwordLabel); |
| 98 | 91 | innerPanel.add(mPassword); |
| 99 | 92 | |
| 100 | innerPanel.add(new JLabel("")); | |
| 101 | final JLabel mWarningMessage = new JLabel("This should not be the same as your eBay password!", JLabel.RIGHT); | |
| 102 | mWarningMessage.setFont(mWarningMessage.getFont().deriveFont(Font.ITALIC | Font.BOLD)); | |
| 103 | 93 | Box button = Box.createHorizontalBox(); |
| 104 | mCreateOrUpdate = new JButton(""); | |
| 94 | final JLabel statusLabel = new JLabel(""); | |
| 95 | mCreateOrUpdate = new JButton("Test Access"); | |
| 105 | 96 | mCreateOrUpdate.addActionListener(new ActionListener() { |
| 106 | 97 | public void actionPerformed(ActionEvent event) { |
| 107 | 98 | String action = event.getActionCommand(); |
| 108 | 99 | if(action == null) return; |
| 109 | 100 | |
| 110 | boolean create = action.equals("Create"); | |
| 111 | boolean update = action.equals("Update"); | |
| 101 | String oldId = JConfig.queryConfiguration("my.jbidwatcher.id"); | |
| 102 | String oldKey= JConfig.queryConfiguration("my.jbidwatcher.key"); | |
| 112 | 103 | |
| 113 | if(create) { | |
| 114 | createNewUser(); | |
| 115 | } else if(update) { | |
| 116 | updateUser(); | |
| 104 | JConfig.setConfiguration("my.jbidwatcher.id", mEmail.getText()); | |
| 105 | JConfig.setConfiguration("my.jbidwatcher.key", mPassword.getText()); | |
| 106 | ||
| 107 | if(MyJBidwatcher.getInstance().getAccountInfo()) { | |
| 108 | statusLabel.setIcon(successIcon); | |
| 109 | statusLabel.setText("success!"); | |
| 117 | 110 | } else { |
| 118 | System.err.println("Unknown action command: " + action); | |
| 111 | statusLabel.setIcon(failIcon); | |
| 112 | statusLabel.setText("failed."); | |
| 119 | 113 | } |
| 114 | ||
| 115 | JConfig.setConfiguration("my.jbidwatcher.id", oldId); | |
| 116 | JConfig.setConfiguration("my.jbidwatcher.key", oldKey); | |
| 120 | 117 | } |
| 121 | 118 | }); |
| 122 | 119 | button.add(mCreateOrUpdate); |
| 123 | button.add(Box.createHorizontalGlue()); | |
| 124 | button.add(mWarningMessage); | |
| 120 | button.add(statusLabel); | |
| 121 | innerPanel.add(new JLabel("")); | |
| 125 | 122 | innerPanel.add(button); |
| 126 | 123 | |
| 127 | mUserId = new JTextField(); | |
| 128 | mUserId.setEditable(false); | |
| 129 | JLabel userIdLabel = new JLabel("My JBidwatcher Id:"); | |
| 130 | userIdLabel.setEnabled(false); | |
| 131 | userIdLabel.setLabelFor(mUserId); | |
| 132 | innerPanel.add(userIdLabel); | |
| 133 | innerPanel.add(mUserId); | |
| 124 | SpringUtilities.makeCompactGrid(innerPanel, 3, 2, 6, 6, 6, 1); | |
| 134 | 125 | |
| 135 | SpringUtilities.makeCompactGrid(innerPanel, 4, 2, 6, 6, 6, 1); | |
| 136 | ||
| 137 | 126 | mEnable = new JCheckBox(); |
| 138 | 127 | mEnable.addActionListener(new ActionListener() { |
| 139 | 128 | public void actionPerformed(ActionEvent event) { |
| --- | --- | |
| 148 | 137 | mPassword.setEditable(selected); |
| 149 | 138 | |
| 150 | 139 | mCreateOrUpdate.setEnabled(selected); |
| 151 | mWarningMessage.setEnabled(selected); | |
| 152 | mUserId.setEnabled(selected); | |
| 153 | 140 | } |
| 154 | 141 | }); |
| 155 | 142 | JLabel enableLabel = new JLabel("Enable My JBidwatcher"); |
| --- | --- | |
| 163 | 150 | |
| 164 | 151 | private void updateUser() { |
| 165 | 152 | final String email = mEmail.getText(); |
| 166 | final String password = new String(mPassword.getPassword()); | |
| 153 | final String password = mPassword.getText(); | |
| 167 | 154 | |
| 168 | 155 | final boolean success = MyJBidwatcher.getInstance().updateAccount(email, password); |
| 169 | 156 | final String message = success ? "Account updated to:\nEmail: " + email + "\nPassword: " + password : "Account update failed."; |
| --- | --- | |
| 178 | 165 | |
| 179 | 166 | private void createNewUser() { |
| 180 | 167 | String email = mEmail.getText(); |
| 181 | String password = new String(mPassword.getPassword()); | |
| 168 | String password = mPassword.getText(); | |
| 182 | 169 | final boolean success = MyJBidwatcher.getInstance().createAccount(email, password); |
| 183 | 170 | |
| 184 | 171 | final JPanel panel = this; |
