You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PasteDialogFocusTraversalPolicy.java 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.ui_swing.dialogs.paste;
  18. import java.awt.Component;
  19. import java.awt.Container;
  20. import java.awt.FocusTraversalPolicy;
  21. import javax.swing.JButton;
  22. /**
  23. * Focus traversal policy for the paste dialog.
  24. */
  25. public final class PasteDialogFocusTraversalPolicy extends FocusTraversalPolicy {
  26. /** Cancel button. */
  27. private final JButton cancelButton;
  28. /** Edit button. */
  29. private final JButton editButton;
  30. /** Send button. */
  31. private final JButton sendButton;
  32. /**
  33. * Creates a new instance of PasteDialogFocusTraversalPolicy.
  34. *
  35. * @param cancelButton Cancel button
  36. * @param editButton Edit button
  37. * @param sendButton Send button
  38. */
  39. public PasteDialogFocusTraversalPolicy(final JButton cancelButton,
  40. final JButton editButton, final JButton sendButton) {
  41. this.cancelButton = cancelButton;
  42. this.editButton = editButton;
  43. this.sendButton = sendButton;
  44. }
  45. @Override
  46. public Component getComponentAfter(final Container aContainer,
  47. final Component aComponent) {
  48. if (aComponent.equals(cancelButton)) {
  49. return editButton;
  50. } else if (aComponent.equals(editButton)) {
  51. return sendButton;
  52. } else {
  53. return cancelButton;
  54. }
  55. }
  56. @Override
  57. public Component getComponentBefore(final Container aContainer,
  58. final Component aComponent) {
  59. if (aComponent.equals(cancelButton)) {
  60. return sendButton;
  61. } else if (aComponent.equals(editButton)) {
  62. return cancelButton;
  63. } else if (aComponent.equals(sendButton)) {
  64. return editButton;
  65. } else {
  66. return sendButton;
  67. }
  68. }
  69. @Override
  70. public Component getFirstComponent(final Container aContainer) {
  71. return cancelButton;
  72. }
  73. @Override
  74. public Component getLastComponent(final Container aContainer) {
  75. return sendButton;
  76. }
  77. @Override
  78. public Component getDefaultComponent(final Container aContainer) {
  79. return sendButton;
  80. }
  81. }