| 52 | | |
| 53 | | private Spinner spnAPILimitRate; |
| 54 | | |
| 55 | | private Spinner spnTimeLineInterval; |
| 56 | | |
| 57 | | private Spinner spnRepliesInterval; |
| 58 | | |
| 59 | | private Spinner spnDirectMessagesInterval; |
| 60 | | |
| 61 | | private SelectionListener intervalListener = new SelectionListener() { |
| 62 | | |
| 63 | | public void widgetDefaultSelected(SelectionEvent e) { |
| 64 | | widgetSelected(e); |
| 65 | | } |
| 66 | | |
| 67 | | public void widgetSelected(SelectionEvent e) { |
| 68 | | int limit = spnAPILimitRate.getSelection(); |
| 69 | | int f = spnTimeLineInterval.getSelection(); |
| 70 | | int r = spnRepliesInterval.getSelection(); |
| 71 | | int d = spnDirectMessagesInterval.getSelection(); |
| 72 | | if (valid(limit, f, r, d)) { |
| 73 | | return; |
| 74 | | } |
| 75 | | Spinner fixed = (Spinner) e.getSource(); |
| 76 | | while (valid(limit, f, r, d) == false) { |
| 77 | | if (fixed.equals(spnAPILimitRate)) { |
| 78 | | if (f < r && f < d) { |
| 79 | | f++; |
| 80 | | } else if (r < d) { |
| 81 | | r++; |
| 82 | | } else { |
| 83 | | d++; |
| 84 | | } |
| 85 | | } else if (fixed.equals(spnTimeLineInterval)) { |
| 86 | | if (60 / f >= limit) { |
| 87 | | f++; |
| 88 | | } else if (r < d) { |
| 89 | | r++; |
| 90 | | } else { |
| 91 | | d++; |
| 92 | | } |
| 93 | | } else if (fixed.equals(spnRepliesInterval)) { |
| 94 | | if (60 / r >= limit) { |
| 95 | | r++; |
| 96 | | } else if (f < d) { |
| 97 | | f++; |
| 98 | | } else { |
| 99 | | d++; |
| 100 | | } |
| 101 | | } else if (fixed.equals(spnDirectMessagesInterval)) { |
| 102 | | if (60 / d >= limit) { |
| 103 | | d++; |
| 104 | | } else if (f < r) { |
| 105 | | f++; |
| 106 | | } else { |
| 107 | | r++; |
| 108 | | } |
| 109 | | } else { |
| 110 | | System.err.println("!!"); |
| 111 | | } |
| 112 | | } |
| 113 | | |
| 114 | | spnAPILimitRate.setSelection(limit); |
| 115 | | spnTimeLineInterval.setSelection(f); |
| 116 | | spnRepliesInterval.setSelection(r); |
| 117 | | spnDirectMessagesInterval.setSelection(d); |
| 118 | | } |
| 119 | | |
| 120 | | private boolean valid(int limit, int... values) { |
| 121 | | return limit > calcRate(values); |
| 122 | | } |
| 123 | | |
| 124 | | private double calcRate(int[] intervals) { |
| 125 | | double result = 0; |
| 126 | | for (int interval : intervals) { |
| 127 | | result += 60 / interval; |
| 128 | | } |
| 129 | | return result; |
| 130 | | } |
| 131 | | }; |
| 132 | | |
| 133 | | private Combo cmbBaloonDispayType; |
| 147 | | Group account = new Group(composite, SWT.NONE); |
| 148 | | account.setText(Messages.group_account); |
| 149 | | account.setLayout(new GridLayout(2, false)); |
| 150 | | account.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 151 | | |
| 152 | | Label label = new Label(account, SWT.NONE); |
| 153 | | label.setText(Messages.label_username); |
| 154 | | |
| 155 | | txtUsername = new Text(account, SWT.BORDER); |
| 156 | | txtUsername.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 157 | | txtUsername.addFocusListener(new TextSelectionOnFocusAdapter(txtUsername)); |
| 158 | | |
| 159 | | label = new Label(account, SWT.NONE); |
| 160 | | label.setText(Messages.label_password); |
| 161 | | |
| 162 | | txtPassword = new Text(account, SWT.PASSWORD | SWT.BORDER); |
| 163 | | txtPassword.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 164 | | txtPassword.addFocusListener(new TextSelectionOnFocusAdapter(txtPassword)); |
| 165 | | |
| 177 | | Group interval = new Group(composite, SWT.NONE); |
| 178 | | interval.setText(Messages.group_access_interval); |
| 179 | | interval.setLayout(new GridLayout(3, false)); |
| 180 | | interval.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 181 | | |
| 182 | | label = new Label(interval, SWT.NONE); |
| 183 | | label.setText(Messages.label_api_limit_rate); |
| 184 | | spnAPILimitRate = new Spinner(interval, SWT.BORDER); |
| 185 | | spnAPILimitRate.setMinimum(10); |
| 186 | | spnAPILimitRate.setMaximum(99); |
| 187 | | spnAPILimitRate.setIncrement(1); |
| 188 | | label = new Label(interval, SWT.NONE); |
| 189 | | label.setText(Messages.label_times_per_hour); |
| 190 | | |
| 191 | | label = new Label(interval, SWT.NONE); |
| 192 | | label.setText(Messages.label_friend_timeline); |
| 193 | | spnTimeLineInterval = new Spinner(interval, SWT.BORDER); |
| 194 | | spnTimeLineInterval.setMinimum(1); |
| 195 | | spnAPILimitRate.setMaximum(99); |
| 196 | | spnAPILimitRate.setIncrement(1); |
| 197 | | label = new Label(interval, SWT.NONE); |
| 198 | | label.setText(Messages.label_min); |
| 199 | | |
| 200 | | label = new Label(interval, SWT.NONE); |
| 201 | | label.setText(Messages.label_replies); |
| 202 | | spnRepliesInterval = new Spinner(interval, SWT.BORDER); |
| 203 | | spnRepliesInterval.setMinimum(1); |
| 204 | | spnAPILimitRate.setMaximum(99); |
| 205 | | spnAPILimitRate.setIncrement(1); |
| 206 | | label = new Label(interval, SWT.NONE); |
| 207 | | label.setText(Messages.label_min); |
| 208 | | |
| 209 | | label = new Label(interval, SWT.NONE); |
| 210 | | label.setText(Messages.label_direct_messages); |
| 211 | | spnDirectMessagesInterval = new Spinner(interval, SWT.BORDER); |
| 212 | | spnDirectMessagesInterval.setMinimum(1); |
| 213 | | spnAPILimitRate.setMaximum(99); |
| 214 | | spnAPILimitRate.setIncrement(1); |
| 215 | | label = new Label(interval, SWT.NONE); |
| 216 | | label.setText(Messages.label_min); |
| 217 | | |
| 358 | | |
| 359 | | spnAPILimitRate.setSelection(ps.getInt(PreferenceKeys.API_LIMIT_RATE)); |
| 360 | | spnAPILimitRate.addSelectionListener(intervalListener); |
| 361 | | spnTimeLineInterval.setSelection(ps.getInt(PreferenceKeys.INTERVAL_FRIEND_TIMELINE)); |
| 362 | | spnTimeLineInterval.addSelectionListener(intervalListener); |
| 363 | | spnRepliesInterval.setSelection(ps.getInt(PreferenceKeys.INTERVAL_REPLIES)); |
| 364 | | spnRepliesInterval.addSelectionListener(intervalListener); |
| 365 | | spnDirectMessagesInterval.setSelection(ps.getInt(PreferenceKeys.INTERVAL_DIRECT_MESSAGES)); |
| 366 | | spnDirectMessagesInterval.addSelectionListener(intervalListener); |
| 411 | | |
| 412 | | int apiLimitRate = spnAPILimitRate.getSelection(); |
| 413 | | ps.setValue(PreferenceKeys.API_LIMIT_RATE, apiLimitRate); |
| 414 | | |
| 415 | | int timeLineInterval = spnTimeLineInterval.getSelection(); |
| 416 | | ps.setValue(PreferenceKeys.INTERVAL_FRIEND_TIMELINE, timeLineInterval); |
| 417 | | |
| 418 | | int replyInterval = spnRepliesInterval.getSelection(); |
| 419 | | ps.setValue(PreferenceKeys.INTERVAL_REPLIES, replyInterval); |
| 420 | | |
| 421 | | int dmInterval = spnDirectMessagesInterval.getSelection(); |
| 422 | | ps.setValue(PreferenceKeys.INTERVAL_DIRECT_MESSAGES, dmInterval); |