123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- /*
- * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package uk.org.ownage.dmdirc;
-
- import java.awt.Color;
- import java.beans.PropertyVetoException;
-
- import javax.swing.ImageIcon;
- import javax.swing.JInternalFrame;
- import javax.swing.event.InternalFrameEvent;
- import javax.swing.event.InternalFrameListener;
-
- import uk.org.ownage.dmdirc.commandparser.CommandWindow;
- import uk.org.ownage.dmdirc.identities.ConfigManager;
- import uk.org.ownage.dmdirc.logger.ErrorLevel;
- import uk.org.ownage.dmdirc.logger.Logger;
- import uk.org.ownage.dmdirc.ui.MainFrame;
-
- /**
- * Standard interface for all objects that contain an innerframe. Provides
- * methods for interfacing with the frame via the owner.
- * @author chris
- */
- public abstract class FrameContainer implements InternalFrameListener {
-
- /** The colour of our frame's notifications. */
- protected Color notification = Color.BLACK;
-
- /** The icon being used for this container's frame. */
- protected ImageIcon imageIcon;
-
- /**
- * Returns the internal frame associated with this object.
- * @return The internal frame associated with this object
- */
- public abstract CommandWindow getFrame();
-
- /**
- * Returns a string identifier for this object/its frame.
- * @return String identifier
- */
- public abstract String toString();
-
- /**
- * Closes this container (and it's associated frame).
- */
- public abstract void close();
-
- /**
- * Returns the server instance associated with this container.
- * @return the associated server connection
- */
- public abstract Server getServer();
-
- /**
- * Retrieves the icon used by the query frame.
- * @return The query frame's icon
- */
- public ImageIcon getIcon() {
- return imageIcon;
- }
-
- /**
- * Formats the specified arguments using the supplied message type, and
- * outputs to the main text area.
- * @param messageType the message type to use
- * @param args the arguments to pass
- */
- public void addLine(final String messageType, final Object... args) {
- getFrame().addLine(messageType, args);
- }
-
- /**
- * Returns the config manager for this container.
- * @return the associated config manager
- */
- public ConfigManager getConfigManager() {
- return getServer().getConfigManager();
- }
-
- /**
- * Requests that this object's frame be activated.
- */
- public void activateFrame() {
- MainFrame.getMainFrame().setActiveFrame((JInternalFrame) getFrame());
- }
-
- /**
- * Clears any outstanding notifications this frame has set.
- */
- protected void clearNotification() {
- MainFrame.getMainFrame().getFrameManager().clearNotification(this);
- notification = Color.BLACK;
- }
-
- /**
- * Sends a notification to the frame manager if this frame isn't active.
- */
- public void sendNotification() {
- sendNotification(Color.RED);
- }
-
- /**
- * Sends a notification to the frame manager if this fame isn't active.
- * @param colour The colour to use for the notification
- */
- public void sendNotification(final Color colour) {
- final JInternalFrame activeFrame = MainFrame.getMainFrame().getActiveFrame();
- if (activeFrame != null && !activeFrame.equals(getFrame())) {
- MainFrame.getMainFrame().getFrameManager().showNotification(this, colour);
- notification = colour;
- }
- }
-
- /**
- * Retrieves the current notification colour of this channel.
- * @return This channel's notification colour
- */
- public Color getNotification() {
- return notification;
- }
-
- /**
- * Determines if the specified frame is owned by this object.
- * @param target JInternalFrame to check ownership of
- * @return True iff frame is owned by this container, false otherwise
- */
- public boolean ownsFrame(final JInternalFrame target) {
- return getFrame().equals(target);
- }
-
- /**
- * Invoked when a internal frame has been opened.
- * @param internalFrameEvent frame opened event
- */
- public void internalFrameOpened(final InternalFrameEvent internalFrameEvent) {
- final boolean pref = getServer().getConfigManager().getOptionBool("ui", "maximisewindows");
- if (pref || MainFrame.getMainFrame().getMaximised()) {
- try {
- ((JInternalFrame) getFrame()).setMaximum(true);
- } catch (PropertyVetoException ex) {
- Logger.error(ErrorLevel.WARNING, "Unable to maximise window", ex);
- }
- }
- }
-
- /**
- * Invoked when an internal frame is in the process of being closed.
- * @param internalFrameEvent frame closing event
- */
- public void internalFrameClosing(final InternalFrameEvent internalFrameEvent) {
- close();
- }
-
- /**
- * Invoked when an internal frame has been closed.
- * @param internalFrameEvent frame closed event
- */
- public void internalFrameClosed(final InternalFrameEvent internalFrameEvent) {
- //Ignore.
- }
-
- /**
- * Invoked when an internal frame is iconified.
- * @param internalFrameEvent frame iconified event
- */
- public void internalFrameIconified(final InternalFrameEvent internalFrameEvent) {
- //Ignore.
- }
-
- /**
- * Invoked when an internal frame is de-iconified.
- * @param internalFrameEvent frame deiconified event
- */
- public void internalFrameDeiconified(final InternalFrameEvent internalFrameEvent) {
- //Ignore.
- }
-
- /**
- * Invoked when an internal frame is activated.
- * @param internalFrameEvent frame activation event
- */
- public void internalFrameActivated(final InternalFrameEvent internalFrameEvent) {
- if (MainFrame.getMainFrame().getMaximised()) {
- try {
- ((JInternalFrame) getFrame()).setMaximum(true);
- } catch (PropertyVetoException ex) {
- Logger.error(ErrorLevel.WARNING, "Unable to maximise window", ex);
- }
- }
- MainFrame.getMainFrame().getFrameManager().setSelected(this);
- getServer().setActiveFrame(this);
- clearNotification();
- }
-
- /**
- * Invoked when an internal frame is de-activated.
- * @param internalFrameEvent frame deactivation event
- */
- public void internalFrameDeactivated(final InternalFrameEvent internalFrameEvent) {
- //Ignore.
- }
-
- }
|