This removes a menu entry from the menu. @param entry This is the menu entry to remove
(final Entry entry)
| 370 | * @param entry This is the menu entry to remove |
| 371 | */ |
| 372 | public |
| 373 | void remove(final Entry entry) { |
| 374 | // null is passed in when a sub-menu is removing itself from us (because they have already called "remove" and have also |
| 375 | // removed themselves from the menuEntries) |
| 376 | if (entry != null) { |
| 377 | Entry toRemove = null; |
| 378 | |
| 379 | synchronized (menuEntries) { |
| 380 | // access on this object must be synchronized for object visibility |
| 381 | for (Iterator<Entry> iterator = menuEntries.iterator(); iterator.hasNext(); ) { |
| 382 | final Entry entry__ = iterator.next(); |
| 383 | if (entry__ == entry) { |
| 384 | iterator.remove(); |
| 385 | toRemove = entry__; |
| 386 | break; |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | if (toRemove != null) { |
| 391 | final Entry reference = toRemove; |
| 392 | // all ADD/REMOVE events have to be queued on our own dispatch thread, so the execution order of the events can be maintained. |
| 393 | EventDispatch.runLater(()->reference.remove()); |
| 394 | |
| 395 | toRemove = null; |
| 396 | } |
| 397 | |
| 398 | |
| 399 | // now check to see if a spacer is at the TOP of the list (and remove it if so. This is a recursive function. |
| 400 | synchronized (menuEntries) { |
| 401 | // access on this object must be synchronized for object visibility. When it runs recursively, it will correctly remove the entry. |
| 402 | if (!menuEntries.isEmpty()) { |
| 403 | if (menuEntries.get(0) instanceof dorkbox.systemTray.Separator) { |
| 404 | toRemove = menuEntries.get(0); |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | if (toRemove != null) { |
| 409 | remove(toRemove); |
| 410 | toRemove = null; |
| 411 | } |
| 412 | |
| 413 | |
| 414 | // now check to see if a spacer is at the BOTTOM of the list (and remove it if so. This is a recursive function. |
| 415 | synchronized (menuEntries) { |
| 416 | // access on this object must be synchronized for object visibility. When it runs recursively, it will correctly remove the entry. |
| 417 | if (!menuEntries.isEmpty()) { |
| 418 | if (menuEntries.get(menuEntries.size()-1) instanceof dorkbox.systemTray.Separator) { |
| 419 | toRemove = menuEntries.get(menuEntries.size() - 1); |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | if (toRemove != null) { |
| 424 | remove(toRemove); |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | /** |