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.

FrameContainer.java 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Copyright (c) 2006-2007 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 uk.org.ownage.dmdirc;
  23. import java.awt.Color;
  24. import java.beans.PropertyVetoException;
  25. import javax.swing.ImageIcon;
  26. import javax.swing.JInternalFrame;
  27. import javax.swing.event.InternalFrameEvent;
  28. import javax.swing.event.InternalFrameListener;
  29. import uk.org.ownage.dmdirc.commandparser.CommandWindow;
  30. import uk.org.ownage.dmdirc.identities.ConfigManager;
  31. import uk.org.ownage.dmdirc.logger.ErrorLevel;
  32. import uk.org.ownage.dmdirc.logger.Logger;
  33. import uk.org.ownage.dmdirc.ui.MainFrame;
  34. /**
  35. * Standard interface for all objects that contain an innerframe. Provides
  36. * methods for interfacing with the frame via the owner.
  37. * @author chris
  38. */
  39. public abstract class FrameContainer implements InternalFrameListener {
  40. /** The colour of our frame's notifications. */
  41. protected Color notification = Color.BLACK;
  42. /** The icon being used for this container's frame. */
  43. protected ImageIcon imageIcon;
  44. /**
  45. * Returns the internal frame associated with this object.
  46. * @return The internal frame associated with this object
  47. */
  48. public abstract CommandWindow getFrame();
  49. /**
  50. * Returns a string identifier for this object/its frame.
  51. * @return String identifier
  52. */
  53. public abstract String toString();
  54. /**
  55. * Closes this container (and it's associated frame).
  56. */
  57. public abstract void close();
  58. /**
  59. * Returns the server instance associated with this container.
  60. * @return the associated server connection
  61. */
  62. public abstract Server getServer();
  63. /**
  64. * Retrieves the icon used by the query frame.
  65. * @return The query frame's icon
  66. */
  67. public ImageIcon getIcon() {
  68. return imageIcon;
  69. }
  70. /**
  71. * Formats the specified arguments using the supplied message type, and
  72. * outputs to the main text area.
  73. * @param messageType the message type to use
  74. * @param args the arguments to pass
  75. */
  76. public void addLine(final String messageType, final Object... args) {
  77. getFrame().addLine(messageType, args);
  78. }
  79. /**
  80. * Returns the config manager for this container.
  81. * @return the associated config manager
  82. */
  83. public ConfigManager getConfigManager() {
  84. return getServer().getConfigManager();
  85. }
  86. /**
  87. * Requests that this object's frame be activated.
  88. */
  89. public void activateFrame() {
  90. MainFrame.getMainFrame().setActiveFrame((JInternalFrame) getFrame());
  91. }
  92. /**
  93. * Clears any outstanding notifications this frame has set.
  94. */
  95. protected void clearNotification() {
  96. MainFrame.getMainFrame().getFrameManager().clearNotification(this);
  97. notification = Color.BLACK;
  98. }
  99. /**
  100. * Sends a notification to the frame manager if this frame isn't active.
  101. */
  102. public void sendNotification() {
  103. sendNotification(Color.RED);
  104. }
  105. /**
  106. * Sends a notification to the frame manager if this fame isn't active.
  107. * @param colour The colour to use for the notification
  108. */
  109. public void sendNotification(final Color colour) {
  110. final JInternalFrame activeFrame = MainFrame.getMainFrame().getActiveFrame();
  111. if (activeFrame != null && !activeFrame.equals(getFrame())) {
  112. MainFrame.getMainFrame().getFrameManager().showNotification(this, colour);
  113. notification = colour;
  114. }
  115. }
  116. /**
  117. * Retrieves the current notification colour of this channel.
  118. * @return This channel's notification colour
  119. */
  120. public Color getNotification() {
  121. return notification;
  122. }
  123. /**
  124. * Determines if the specified frame is owned by this object.
  125. * @param target JInternalFrame to check ownership of
  126. * @return True iff frame is owned by this container, false otherwise
  127. */
  128. public boolean ownsFrame(final JInternalFrame target) {
  129. return getFrame().equals(target);
  130. }
  131. /**
  132. * Invoked when a internal frame has been opened.
  133. * @param internalFrameEvent frame opened event
  134. */
  135. public void internalFrameOpened(final InternalFrameEvent internalFrameEvent) {
  136. final boolean pref = getServer().getConfigManager().getOptionBool("ui", "maximisewindows");
  137. if (pref || MainFrame.getMainFrame().getMaximised()) {
  138. try {
  139. ((JInternalFrame) getFrame()).setMaximum(true);
  140. } catch (PropertyVetoException ex) {
  141. Logger.error(ErrorLevel.WARNING, "Unable to maximise window", ex);
  142. }
  143. }
  144. }
  145. /**
  146. * Invoked when an internal frame is in the process of being closed.
  147. * @param internalFrameEvent frame closing event
  148. */
  149. public void internalFrameClosing(final InternalFrameEvent internalFrameEvent) {
  150. close();
  151. }
  152. /**
  153. * Invoked when an internal frame has been closed.
  154. * @param internalFrameEvent frame closed event
  155. */
  156. public void internalFrameClosed(final InternalFrameEvent internalFrameEvent) {
  157. //Ignore.
  158. }
  159. /**
  160. * Invoked when an internal frame is iconified.
  161. * @param internalFrameEvent frame iconified event
  162. */
  163. public void internalFrameIconified(final InternalFrameEvent internalFrameEvent) {
  164. //Ignore.
  165. }
  166. /**
  167. * Invoked when an internal frame is de-iconified.
  168. * @param internalFrameEvent frame deiconified event
  169. */
  170. public void internalFrameDeiconified(final InternalFrameEvent internalFrameEvent) {
  171. //Ignore.
  172. }
  173. /**
  174. * Invoked when an internal frame is activated.
  175. * @param internalFrameEvent frame activation event
  176. */
  177. public void internalFrameActivated(final InternalFrameEvent internalFrameEvent) {
  178. if (MainFrame.getMainFrame().getMaximised()) {
  179. try {
  180. ((JInternalFrame) getFrame()).setMaximum(true);
  181. } catch (PropertyVetoException ex) {
  182. Logger.error(ErrorLevel.WARNING, "Unable to maximise window", ex);
  183. }
  184. }
  185. MainFrame.getMainFrame().getFrameManager().setSelected(this);
  186. getServer().setActiveFrame(this);
  187. clearNotification();
  188. }
  189. /**
  190. * Invoked when an internal frame is de-activated.
  191. * @param internalFrameEvent frame deactivation event
  192. */
  193. public void internalFrameDeactivated(final InternalFrameEvent internalFrameEvent) {
  194. //Ignore.
  195. }
  196. }