Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

FrameContainerMenuItem.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_swing.framemanager.windowmenu;
  23. import com.dmdirc.FrameContainer;
  24. import com.dmdirc.interfaces.FrameInfoListener;
  25. import com.dmdirc.interfaces.SelectionListener;
  26. import com.dmdirc.ui.IconManager;
  27. import com.dmdirc.ui.WindowManager;
  28. import java.awt.Font;
  29. import java.awt.event.ActionEvent;
  30. import java.awt.event.ActionListener;
  31. import javax.swing.JMenuItem;
  32. import javax.swing.SwingUtilities;
  33. /**
  34. * Action representing a frame.
  35. */
  36. public class FrameContainerMenuItem extends JMenuItem implements FrameInfoListener,
  37. ActionListener, SelectionListener, FrameContainerMenuInterface {
  38. /**
  39. * A version number for this class. It should be changed whenever the class
  40. * structure is changed (or anything else that would prevent serialized
  41. * objects being unserialized with the new class).
  42. */
  43. private static final long serialVersionUID = 1;
  44. /** Wrapped frame. */
  45. private FrameContainer frame;
  46. /** Parent window menu frame manager. */
  47. private final WindowMenuFrameManager manager;
  48. /**
  49. * Instantiates a new FrameContainer menu item wrapping the specified frame.
  50. *
  51. * @param frame Wrapped frame
  52. * @param manager Parent window menu frame manager.
  53. */
  54. public FrameContainerMenuItem(final FrameContainer frame,
  55. final WindowMenuFrameManager manager) {
  56. super(frame.toString(), IconManager.getIconManager().getIcon(frame.
  57. getIcon()));
  58. this.frame = frame;
  59. this.manager = manager;
  60. addActionListener(this);
  61. frame.addFrameInfoListener(this);
  62. }
  63. /** {@inheritDoc} */
  64. @Override
  65. public void iconChanged(final FrameContainer window, final String icon) {
  66. SwingUtilities.invokeLater(new Runnable() {
  67. /** {@inheritDoc} */
  68. @Override
  69. public void run() {
  70. if ((frame != null && window != null) && frame.equals(window)) {
  71. setIcon(IconManager.getIconManager().getIcon(icon));
  72. }
  73. }
  74. });
  75. }
  76. /** {@inheritDoc} */
  77. @Override
  78. public void nameChanged(final FrameContainer window, final String name) {
  79. SwingUtilities.invokeLater(new Runnable() {
  80. /** {@inheritDoc} */
  81. @Override
  82. public void run() {
  83. if ((frame != null && window != null) && frame.equals(window)) {
  84. setText(name);
  85. }
  86. }
  87. });
  88. }
  89. /** {@inheritDoc} */
  90. @Override
  91. public void titleChanged(final FrameContainer window, final String title) {
  92. // Do nothing
  93. }
  94. /**
  95. * {@inheritDoc}
  96. *
  97. * @param e Action event
  98. */
  99. @Override
  100. public void actionPerformed(final ActionEvent e) {
  101. frame.activateFrame();
  102. }
  103. /** {@inheritDoc} */
  104. @Override
  105. public void selectionChanged(final FrameContainer window) {
  106. if (frame.equals(window)) {
  107. setFont(getFont().deriveFont(Font.BOLD));
  108. final FrameContainer parentWindow = window.getParent();
  109. if (parentWindow != null) {
  110. manager.parentSelection(parentWindow);
  111. }
  112. } else {
  113. setFont(getFont().deriveFont(Font.PLAIN));
  114. }
  115. }
  116. /** {@inheritDoc} */
  117. @Override
  118. public FrameContainer getFrame() {
  119. return frame;
  120. }
  121. }