(Container pane)
| 255 | } |
| 256 | |
| 257 | private void createUI(Container pane) { |
| 258 | // If creating the tray icon fails, ignore it. |
| 259 | try { |
| 260 | setupTrayIcon(); |
| 261 | } catch (Exception e) { |
| 262 | LOGGER.warn(e.getMessage()); |
| 263 | } |
| 264 | |
| 265 | EmptyBorder emptyBorder = new EmptyBorder(5, 5, 5, 5); |
| 266 | GridBagConstraints gbc = new GridBagConstraints(); |
| 267 | gbc.fill = GridBagConstraints.HORIZONTAL; |
| 268 | gbc.weightx = 1; |
| 269 | gbc.ipadx = 2; |
| 270 | gbc.gridx = 0; |
| 271 | gbc.weighty = 0; |
| 272 | gbc.ipady = 2; |
| 273 | gbc.gridy = 0; |
| 274 | gbc.anchor = GridBagConstraints.PAGE_START; |
| 275 | |
| 276 | try { |
| 277 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 278 | } catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException |
| 279 | | IllegalAccessException e) { |
| 280 | LOGGER.error("[!] Exception setting system theme:", e); |
| 281 | } |
| 282 | |
| 283 | ripTextfield = new JTextField("", 20); |
| 284 | ripTextfield.addMouseListener(new ContextMenuMouseListener(ripTextfield)); |
| 285 | |
| 286 | // Add keyboard protection of Ctrl+V for pasting. |
| 287 | ripTextfield.addKeyListener(new KeyAdapter() { |
| 288 | @Override |
| 289 | public void keyTyped(KeyEvent e) { |
| 290 | if (e.getKeyChar() == 22) { // ASCII code for Ctrl+V |
| 291 | ContextActionProtections.pasteFromClipboard(ripTextfield); |
| 292 | } |
| 293 | } |
| 294 | }); |
| 295 | |
| 296 | /* |
| 297 | Alternatively, just set this, and use |
| 298 | ((AbstractDocument) ripTextfield.getDocument()).setDocumentFilter(new LengthLimitDocumentFilter(256)); |
| 299 | private static class LengthLimitDocumentFilter extends DocumentFilter { |
| 300 | private final int maxLength; |
| 301 | |
| 302 | public LengthLimitDocumentFilter(int maxLength) { |
| 303 | this.maxLength = maxLength; |
| 304 | } |
| 305 | |
| 306 | @Override |
| 307 | public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { |
| 308 | // if ((fb.getDocument().getLength() + string.length()) <= maxLength) { |
| 309 | super.insertString(fb, offset, string.substring(0, maxLength), attr); |
| 310 | // } |
| 311 | } |
| 312 | |
| 313 | @Override |
| 314 | public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { |
no test coverage detected