| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ | |||
| 23 | 23 | package processing.app.contrib; | |
| 24 | 24 | ||
| 25 | 25 | import java.awt.Color; | |
| 26 | + import java.awt.Cursor; | ||
| 26 | 27 | import java.awt.Dimension; | |
| 27 | 28 | import java.awt.Font; | |
| 28 | 29 | import java.awt.event.*; | |
@@ -342,8 +343,9 @@ protected void setFilterText(String filter) { | |||
| 342 | 343 | } | |
| 343 | 344 | ||
| 344 | 345 | ||
| 345 | - //TODO: this is causing a lot of bugs as the hint is wrongly firing applyFilter() | ||
| 346 | 346 | class FilterField extends JTextField { | |
| 347 | + Icon searchIcon; | ||
| 348 | + JButton removeFilter; | ||
| 347 | 349 | List<String> filters; | |
| 348 | 350 | JLabel filterLabel; | |
| 349 | 351 | ||
@@ -355,18 +357,41 @@ public FilterField () { | |||
| 355 | 357 | filterLabel.setOpaque(false); | |
| 356 | 358 | ||
| 357 | 359 | setFont(Toolkit.getSansFont(14, Font.PLAIN)); | |
| 358 | - filterLabel.setIcon(Toolkit.getLibIconX("manager/search")); | ||
| 360 | + searchIcon = Toolkit.getLibIconX("manager/search"); | ||
| 361 | + filterLabel.setIcon(searchIcon); | ||
| 362 | + removeFilter = new JButton(Toolkit.getLibIconX("manager/remove")); | ||
| 363 | + removeFilter.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); | ||
| 364 | + removeFilter.setBorderPainted(false); | ||
| 365 | + removeFilter.setContentAreaFilled(false); | ||
| 366 | + removeFilter.setCursor(Cursor.getDefaultCursor()); | ||
| 367 | + removeFilter.addActionListener(new ActionListener() { | ||
| 368 | + @Override | ||
| 369 | + public void actionPerformed(ActionEvent e) { | ||
| 370 | + setText(""); | ||
| 371 | + filterField.requestFocusInWindow(); | ||
| 372 | + } | ||
| 373 | + }); | ||
| 374 | + //searchIcon = new ImageIcon(java.awt.Toolkit.getDefaultToolkit().getImage("NSImage://NSComputerTemplate")); | ||
| 359 | 375 | setOpaque(false); | |
| 360 | 376 | ||
| 361 | 377 | GroupLayout fl = new GroupLayout(this); | |
| 362 | 378 | setLayout(fl); | |
| 363 | - fl.setHorizontalGroup(fl.createSequentialGroup().addComponent(filterLabel)); | ||
| 379 | + fl.setHorizontalGroup(fl | ||
| 380 | + .createSequentialGroup() | ||
| 381 | + .addComponent(filterLabel) | ||
| 382 | + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, | ||
| 383 | + GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) | ||
| 384 | + .addComponent(removeFilter)); | ||
| 385 | + | ||
| 364 | 386 | fl.setVerticalGroup(fl.createSequentialGroup() | |
| 365 | 387 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, | |
| 366 | 388 | GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) | |
| 389 | + .addGroup(fl.createParallelGroup() | ||
| 367 | 390 | .addComponent(filterLabel) | |
| 391 | + .addComponent(removeFilter)) | ||
| 368 | 392 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, | |
| 369 | 393 | GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); | |
| 394 | + removeFilter.setVisible(false); | ||
| 370 | 395 | ||
| 371 | 396 | filters = new ArrayList<String>(); | |
| 372 | 397 | ||
@@ -384,14 +409,17 @@ public void focusGained(FocusEvent focusEvent) { | |||
| 384 | 409 | ||
| 385 | 410 | getDocument().addDocumentListener(new DocumentListener() { | |
| 386 | 411 | public void removeUpdate(DocumentEvent e) { | |
| 412 | + removeFilter.setVisible(!getText().isEmpty()); | ||
| 387 | 413 | applyFilter(); | |
| 388 | 414 | } | |
| 389 | 415 | ||
| 390 | 416 | public void insertUpdate(DocumentEvent e) { | |
| 417 | + removeFilter.setVisible(!getText().isEmpty()); | ||
| 391 | 418 | applyFilter(); | |
| 392 | 419 | } | |
| 393 | 420 | ||
| 394 | 421 | public void changedUpdate(DocumentEvent e) { | |
| 422 | + removeFilter.setVisible(!getText().isEmpty()); | ||
| 395 | 423 | applyFilter(); | |
| 396 | 424 | } | |
| 397 | 425 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments