Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

FrameContainerMenu.java 4.4KB

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