//# 0 errors, 99 messages
//#
/*
    //#DMDircEventQueue.java:1:1: class: com.dmdirc.addons.ui_swing.DMDircEventQueue
    //#DMDircEventQueue.java:1:1: method: com.dmdirc.addons.ui_swing.DMDircEventQueue.com.dmdirc.addons.ui_swing.DMDircEventQueue__static_init
 * Copyright (c) 2006-2009 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 com.dmdirc.addons.ui_swing;

import com.dmdirc.actions.ActionManager;
import com.dmdirc.actions.CoreActionType;
import com.dmdirc.addons.ui_swing.actions.CopyAction;
import com.dmdirc.addons.ui_swing.actions.CutAction;
import com.dmdirc.addons.ui_swing.actions.PasteAction;

import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Point;
import java.awt.Window;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import java.awt.event.WindowEvent;
import javax.swing.JPopupMenu;
import javax.swing.KeyStroke;
import javax.swing.MenuSelectionManager;
import javax.swing.SwingUtilities;
import javax.swing.text.JTextComponent;

/**
 * Custom event queue to add commong functionality to certain components.
 */
public final class DMDircEventQueue extends EventQueue {
    
    /** Swing Controller. */
    private SwingController controller;

    /** 
     * Instantiates the DMDircEventQueue. 
     * 
     * @param controller Swing controller
     */
    public DMDircEventQueue(final SwingController controller) {
        super();
    //#DMDircEventQueue.java:59: method: void com.dmdirc.addons.ui_swing.DMDircEventQueue.com.dmdirc.addons.ui_swing.DMDircEventQueue(SwingController)
    //#input(void com.dmdirc.addons.ui_swing.DMDircEventQueue(SwingController)): controller
    //#input(void com.dmdirc.addons.ui_swing.DMDircEventQueue(SwingController)): this
    //#output(void com.dmdirc.addons.ui_swing.DMDircEventQueue(SwingController)): this.controller
    //#post(void com.dmdirc.addons.ui_swing.DMDircEventQueue(SwingController)): this.controller == controller
    //#post(void com.dmdirc.addons.ui_swing.DMDircEventQueue(SwingController)): init'ed(this.controller)
        
        this.controller = controller;
    }
    //#DMDircEventQueue.java:62: end of method: void com.dmdirc.addons.ui_swing.DMDircEventQueue.com.dmdirc.addons.ui_swing.DMDircEventQueue(SwingController)

    /** {@inheritDoc} */
    @Override
    protected void dispatchEvent(final AWTEvent event) {
        super.dispatchEvent(event);
    //#DMDircEventQueue.java:67: method: void com.dmdirc.addons.ui_swing.DMDircEventQueue.dispatchEvent(AWTEvent)
    //#input(void dispatchEvent(AWTEvent)): com.dmdirc.actions.CoreActionType.CLIENT_KEY_PRESSED
    //#input(void dispatchEvent(AWTEvent)): event
    //#input(void dispatchEvent(AWTEvent)): this
    //#input(void dispatchEvent(AWTEvent)): this.controller
    //#input(void dispatchEvent(AWTEvent)): this.controller.mainFrameCreated
    //#input(void dispatchEvent(AWTEvent)): this.controller.windows
    //#pre[3] (void dispatchEvent(AWTEvent)): (soft) this.controller != null
    //#pre[4] (void dispatchEvent(AWTEvent)): (soft) this.controller.mainFrameCreated != null
    //#pre[5] (void dispatchEvent(AWTEvent)): (soft) this.controller.windows != null
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.awt.event.MouseEvent:isPopupTrigger
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.awt.event.MouseEvent:getComponent
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.awt.event.MouseEvent:getX
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.awt.event.MouseEvent:getY
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:javax.swing.SwingUtilities:getDeepestComponentAt
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:javax.swing.text.JTextComponent:instanceof
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:javax.swing.MenuSelectionManager:defaultManager
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:javax.swing.MenuSelectionManager:getSelectedPath
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:javax.swing.JPopupMenu
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:javax.swing.AbstractAction
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:javax.swing.JPopupMenu:add
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.awt.event.MouseEvent:getPoint
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:javax.swing.SwingUtilities:convertPoint
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:javax.swing.JPopupMenu:show
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.awt.event.KeyEvent:getKeyChar
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.awt.event.KeyEvent:getModifiers
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:javax.swing.KeyStroke:getKeyStroke
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:com.dmdirc.actions.ActionManager:processEvent
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.awt.event.WindowEvent:getSource
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.awt.Window:instanceof
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:hasMainFrame
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.awt.event.WindowEvent:getID
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:addTopLevelWindow
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:delTopLevelWindow
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.util.concurrent.atomic.AtomicBoolean:get
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.lang.Throwable:__curr_excep_obj
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.util.List:add
    //#unanalyzed(void dispatchEvent(AWTEvent)): Effects-of-calling:java.util.List:remove

        if (event instanceof MouseEvent) {
            handleMouseEvent((MouseEvent) event);
        } else if (event instanceof KeyEvent) {
            handleKeyEvent((KeyEvent) event);
        } else if (event instanceof WindowEvent) {
            handleWindowEvent((WindowEvent) event);
        }
    }
    //#DMDircEventQueue.java:76: end of method: void com.dmdirc.addons.ui_swing.DMDircEventQueue.dispatchEvent(AWTEvent)

    /**
     * Handles key events.
     * 
     * @param ke Key event
     */
    private void handleKeyEvent(final KeyEvent ke) {
        switch (ke.getKeyChar()) {
    //#DMDircEventQueue.java:84: method: void com.dmdirc.addons.ui_swing.DMDircEventQueue.handleKeyEvent(KeyEvent)
    //#input(void handleKeyEvent(KeyEvent)): com.dmdirc.actions.CoreActionType.CLIENT_KEY_PRESSED
    //#input(void handleKeyEvent(KeyEvent)): ke
    //#pre[1] (void handleKeyEvent(KeyEvent)): ke != null
    //#presumption(void handleKeyEvent(KeyEvent)): init'ed(com.dmdirc.actions.CoreActionType.CLIENT_KEY_PRESSED)
    //#test_vector(void handleKeyEvent(KeyEvent)): java.awt.event.KeyEvent:getKeyChar(...)@84: {112..123, 61_440..61_451}, {0..111, 124..61_439, 61_452..65_535}
    //#test_vector(void handleKeyEvent(KeyEvent)): java.awt.event.KeyEvent:getModifiers(...)@137: {0}, {-2_147_483_648..-1, 1..4_294_967_295}
            case KeyEvent.VK_F1:
            //Fallthrough
            case KeyEvent.VK_F2:
            //Fallthrough
            case KeyEvent.VK_F3:
            //Fallthrough
            case KeyEvent.VK_F4:
            //Fallthrough
            case KeyEvent.VK_F5:
            //Fallthrough
            case KeyEvent.VK_F6:
            //Fallthrough
            case KeyEvent.VK_F7:
            //Fallthrough
            case KeyEvent.VK_F8:
            //Fallthrough
            case KeyEvent.VK_F9:
            //Fallthrough
            case KeyEvent.VK_F10:
            //Fallthrough
            case KeyEvent.VK_F11:
            //Fallthrough
            case KeyEvent.VK_F12:
            //Fallthrough
            case KeyEvent.VK_F13:
            //Fallthrough
            case KeyEvent.VK_F14:
            //Fallthrough
            case KeyEvent.VK_F15:
            //Fallthrough
            case KeyEvent.VK_F16:
            //Fallthrough
            case KeyEvent.VK_F17:
            //Fallthrough
            case KeyEvent.VK_F18:
            //Fallthrough
            case KeyEvent.VK_F19:
            //Fallthrough
            case KeyEvent.VK_F20:
            //Fallthrough
            case KeyEvent.VK_F21:
            //Fallthrough
            case KeyEvent.VK_F22:
            //Fallthrough
            case KeyEvent.VK_F23:
            //Fallthrough
            case KeyEvent.VK_F24:
                ActionManager.processEvent(CoreActionType.CLIENT_KEY_PRESSED,
    //#DMDircEventQueue.java:132: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.actions.ActionManager:processEvent(ActionType, StringBuffer, Object[])
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.ui_swing.DMDircEventQueue
    //#    method: void handleKeyEvent(KeyEvent)
    //#    unanalyzed callee: void com.dmdirc.actions.ActionManager:processEvent(ActionType, StringBuffer, Object[])
                        null, KeyStroke.getKeyStroke(ke.getKeyChar(),
                        ke.getModifiers()));
                break;
            default:
                if (ke.getModifiers() != 0) {
                    ActionManager.processEvent(CoreActionType.CLIENT_KEY_PRESSED,
    //#DMDircEventQueue.java:138: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.actions.ActionManager:processEvent(ActionType, StringBuffer, Object[])
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.ui_swing.DMDircEventQueue
    //#    method: void handleKeyEvent(KeyEvent)
    //#    unanalyzed callee: void com.dmdirc.actions.ActionManager:processEvent(ActionType, StringBuffer, Object[])
                            null, KeyStroke.getKeyStroke(ke.getKeyChar(),
                            ke.getModifiers()));
                }
                break;
        }
    }
    //#DMDircEventQueue.java:144: end of method: void com.dmdirc.addons.ui_swing.DMDircEventQueue.handleKeyEvent(KeyEvent)

    /**
     * Handles mouse events.
     * 
     * @param me Mouse event
     */
    private void handleMouseEvent(final MouseEvent me) {
        if (!me.isPopupTrigger()) {
    //#DMDircEventQueue.java:152: method: void com.dmdirc.addons.ui_swing.DMDircEventQueue.handleMouseEvent(MouseEvent)
    //#input(void handleMouseEvent(MouseEvent)): me
    //#pre[1] (void handleMouseEvent(MouseEvent)): me != null
    //#presumption(void handleMouseEvent(MouseEvent)): javax.swing.MenuSelectionManager:defaultManager(...)@167 != null
    //#presumption(void handleMouseEvent(MouseEvent)): javax.swing.MenuSelectionManager:getSelectedPath(...)@167 != null
    //#presumption(void handleMouseEvent(MouseEvent)): javax.swing.SwingUtilities:convertPoint(...)@177 != null
    //#unanalyzed(void handleMouseEvent(MouseEvent)): Effects-of-calling:javax.swing.AbstractAction
    //#test_vector(void handleMouseEvent(MouseEvent)): java.awt.event.MouseEvent:getComponent(...)@156: Inverse{null}, Addr_Set{null}
    //#test_vector(void handleMouseEvent(MouseEvent)): java.awt.event.MouseEvent:isPopupTrigger(...)@152: {1}, {0}
    //#test_vector(void handleMouseEvent(MouseEvent)): javax.swing.MenuSelectionManager:getSelectedPath(...).length@167: {0}, {1..+Inf}
            return;
        }

        if (me.getComponent() == null) {
            return;
        }

        final Component comp = SwingUtilities.getDeepestComponentAt(
                me.getComponent(), me.getX(), me.getY());

        if (!(comp instanceof JTextComponent)) {
            return;
        }

        if (MenuSelectionManager.defaultManager().getSelectedPath().length > 0) {
            return;
        }

        final JTextComponent tc = (JTextComponent) comp;
        final JPopupMenu menu = new JPopupMenu();
        menu.add(new CutAction(tc));
        menu.add(new CopyAction(tc));
        menu.add(new PasteAction(tc));

        final Point pt = SwingUtilities.convertPoint(me.getComponent(),
                me.getPoint(), tc);
        menu.show(tc, pt.x, pt.y);
    }
    //#DMDircEventQueue.java:180: end of method: void com.dmdirc.addons.ui_swing.DMDircEventQueue.handleMouseEvent(MouseEvent)

    /**
     * Handles window events
     * 
     * @param windowEvent Window event
     */
    private void handleWindowEvent(final WindowEvent we) {
        if (we.getSource() instanceof Window) {
    //#DMDircEventQueue.java:188: method: void com.dmdirc.addons.ui_swing.DMDircEventQueue.handleWindowEvent(WindowEvent)
    //#input(void handleWindowEvent(WindowEvent)): this
    //#input(void handleWindowEvent(WindowEvent)): this.controller
    //#input(void handleWindowEvent(WindowEvent)): this.controller.mainFrameCreated
    //#input(void handleWindowEvent(WindowEvent)): this.controller.windows
    //#input(void handleWindowEvent(WindowEvent)): we
    //#pre[6] (void handleWindowEvent(WindowEvent)): we != null
    //#pre[2] (void handleWindowEvent(WindowEvent)): (soft) this.controller != null
    //#pre[3] (void handleWindowEvent(WindowEvent)): (soft) this.controller.mainFrameCreated != null
    //#pre[4] (void handleWindowEvent(WindowEvent)): (soft) this.controller.windows != null
    //#unanalyzed(void handleWindowEvent(WindowEvent)): Effects-of-calling:java.util.concurrent.atomic.AtomicBoolean:get
    //#unanalyzed(void handleWindowEvent(WindowEvent)): Effects-of-calling:java.lang.Throwable:__curr_excep_obj
    //#unanalyzed(void handleWindowEvent(WindowEvent)): Effects-of-calling:java.util.List:add
    //#unanalyzed(void handleWindowEvent(WindowEvent)): Effects-of-calling:java.util.List:remove
    //#test_vector(void handleWindowEvent(WindowEvent)): java.awt.event.WindowEvent:getID(...)@190: {-2_147_483_648..199, 201..4_294_967_295}, {200}
    //#test_vector(void handleWindowEvent(WindowEvent)): java.awt.event.WindowEvent:getID(...)@192: {-2_147_483_648..201, 203..4_294_967_295}, {202}
    //#test_vector(void handleWindowEvent(WindowEvent)): java.util.concurrent.atomic.AtomicBoolean:get(...)@114: {0}, {1}
            if (controller.hasMainFrame()) {
                if (we.getID() == WindowEvent.WINDOW_OPENED) {
                    controller.addTopLevelWindow((Window) we.getSource());
                } else if (we.getID() == WindowEvent.WINDOW_CLOSED) {
                    controller.delTopLevelWindow((Window) we.getSource());
                }
            }
        }
    }
    //#DMDircEventQueue.java:197: end of method: void com.dmdirc.addons.ui_swing.DMDircEventQueue.handleWindowEvent(WindowEvent)
}
    //#output(com.dmdirc.addons.ui_swing.DMDircEventQueue__static_init): __Descendant_Table[com/dmdirc/addons/ui_swing/DMDircEventQueue]
    //#output(com.dmdirc.addons.ui_swing.DMDircEventQueue__static_init): __Dispatch_Table.dispatchEvent(Ljava/awt/AWTEvent;)V
    //#output(com.dmdirc.addons.ui_swing.DMDircEventQueue__static_init): __Dispatch_Table.handleKeyEvent(Ljava/awt/event/KeyEvent;)V
    //#output(com.dmdirc.addons.ui_swing.DMDircEventQueue__static_init): __Dispatch_Table.handleMouseEvent(Ljava/awt/event/MouseEvent;)V
    //#output(com.dmdirc.addons.ui_swing.DMDircEventQueue__static_init): __Dispatch_Table.handleWindowEvent(Ljava/awt/event/WindowEvent;)V
    //#post(com.dmdirc.addons.ui_swing.DMDircEventQueue__static_init): __Descendant_Table[com/dmdirc/addons/ui_swing/DMDircEventQueue] == &__Dispatch_Table
    //#post(com.dmdirc.addons.ui_swing.DMDircEventQueue__static_init): __Dispatch_Table.dispatchEvent(Ljava/awt/AWTEvent;)V == &dispatchEvent
    //#post(com.dmdirc.addons.ui_swing.DMDircEventQueue__static_init): __Dispatch_Table.handleKeyEvent(Ljava/awt/event/KeyEvent;)V == &handleKeyEvent
    //#post(com.dmdirc.addons.ui_swing.DMDircEventQueue__static_init): __Dispatch_Table.handleMouseEvent(Ljava/awt/event/MouseEvent;)V == &handleMouseEvent
    //#post(com.dmdirc.addons.ui_swing.DMDircEventQueue__static_init): __Dispatch_Table.handleWindowEvent(Ljava/awt/event/WindowEvent;)V == &handleWindowEvent
    //#DMDircEventQueue.java:: end of method: com.dmdirc.addons.ui_swing.DMDircEventQueue.com.dmdirc.addons.ui_swing.DMDircEventQueue__static_init
    //#DMDircEventQueue.java:: end of class: com.dmdirc.addons.ui_swing.DMDircEventQueue
