Example usage for java.awt.event AWTEventListener AWTEventListener

List of usage examples for java.awt.event AWTEventListener AWTEventListener

Introduction

In this page you can find the example usage for java.awt.event AWTEventListener AWTEventListener.

Prototype

AWTEventListener

Source Link

Usage

From source file:Main.java

public Main() {
    label = new JLabel("Waiting...");
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(label);//ww w .  j a  va  2 s  .  c  o  m
    frame.setSize(200, 200);
    frame.setVisible(true);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        int count;

        @Override
        public void eventDispatched(AWTEvent event) {
            Object source = event.getSource();
            if (source instanceof Component) {
                Component comp = (Component) source;
                Window win = null;
                if (comp instanceof Window) {
                    win = (Window) comp;
                } else {
                    win = SwingUtilities.windowForComponent(comp);
                }
                if (win == frame) {
                    timer.restart();
                    label.setText("Interrupted..." + (++count));
                }
            }
        }
    }, AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK
            | AWTEvent.MOUSE_WHEEL_EVENT_MASK);

    timer = new Timer(5000, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            frame.dispose();
        }
    });
    timer.start();
}

From source file:com.haulmont.cuba.desktop.sys.DesktopToolTipManager.java

protected DesktopToolTipManager() {
    closeTimer = new Timer(CLOSE_TIME, null);
    closeTimer.setRepeats(false);// w w  w .  ja v a2  s .  com
    closeTimer.addActionListener(e -> {
        if (window != null) {
            window.hide();
            window = null;
            tooltipShowing = false;
            toolTipWindow.removeMouseListener(DesktopToolTipManager.this);
            component.removeMouseListener(DesktopToolTipManager.this);
        }
    });

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        protected MouseEvent event;

        @Override
        public void eventDispatched(AWTEvent e) {
            if (!tooltipShowing) {
                return;
            }
            event = (MouseEvent) e;
            if (event.getID() == MouseEvent.MOUSE_PRESSED) {
                if (event.getComponent() != null && event.getComponent().isShowing()) {
                    if (!isPointInComponent(event.getLocationOnScreen(), toolTipWindow))
                        hideTooltip();
                } else
                    hideTooltip();
            }
        }
    }, AWTEvent.MOUSE_EVENT_MASK);
}

From source file:com.hp.alm.ali.idea.content.taskboard.TaskBoardPanel.java

public TaskBoardPanel(final Project project) {
    super(new BorderLayout());

    this.project = project;

    status = new EntityStatusPanel(project);
    queue = new QueryQueue(project, status, false);

    entityService = project.getComponent(EntityService.class);
    entityService.addEntityListener(this);
    sprintService = project.getComponent(SprintService.class);
    sprintService.addListener(this);

    loadTasks();/*w  w  w  .  j  a v  a2s  .  co  m*/

    header = new Header();
    columnHeader = new ColumnHeader();

    content = new Content();
    add(content, BorderLayout.NORTH);

    header.assignedTo.reload();

    // force mouse-over task as visible (otherwise events are captured by the overlay and repaint quirks)
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (isShowing() && event.getID() == MouseEvent.MOUSE_MOVED) {
                MouseEvent m = (MouseEvent) event;
                TaskPanel currentPanel = locateContainer(m, TaskPanel.class);
                if (currentPanel != null) {
                    if (forcedTaskPanel == currentPanel) {
                        return;
                    } else if (forcedTaskPanel != null) {
                        forcedTaskPanel.removeForcedMatch(this);
                    }
                    forcedTaskPanel = currentPanel;
                    forcedTaskPanel.addForcedMatch(this);
                } else if (forcedTaskPanel != null) {
                    forcedTaskPanel.removeForcedMatch(this);
                    forcedTaskPanel = null;
                }
            }
        }
    }, AWTEvent.MOUSE_MOTION_EVENT_MASK);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (isShowing()) {
                MouseEvent m = (MouseEvent) event;
                switch (event.getID()) {
                case MouseEvent.MOUSE_PRESSED:
                case MouseEvent.MOUSE_RELEASED:
                    // implement backlog item popup
                    if (m.isPopupTrigger()) {
                        final BacklogItemPanel itemPanel = locateContainer(m, BacklogItemPanel.class);
                        if (itemPanel != null) {
                            ActionPopupMenu popupMenu = ActionUtil.createEntityActionPopup("taskboard");
                            Point p = SwingUtilities.convertPoint(m.getComponent(), m.getPoint(), itemPanel);
                            popupMenu.getComponent().show(itemPanel, p.x, p.y);
                        }
                    }
                    break;

                case MouseEvent.MOUSE_CLICKED:
                    // implement backlog item double click
                    if (m.getClickCount() > 1) {
                        BacklogItemPanel itemPanel = locateContainer(m, BacklogItemPanel.class);
                        if (itemPanel != null) {
                            Entity backlogItem = itemPanel.getItem();
                            Entity workItem = new Entity(backlogItem.getPropertyValue("entity-type"),
                                    Integer.valueOf(backlogItem.getPropertyValue("entity-id")));
                            AliContentFactory.loadDetail(project, workItem, true, true);
                        }
                    }
                }
            }

        }
    }, AWTEvent.MOUSE_EVENT_MASK);
}

From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java

/**
 * Creates new form MapFrame//w w  w .  java2 s . c  o  m
 */
DSWorkbenchMainFrame() {
    initComponents();
    setAlwaysOnTop(false);
    if (!GlobalOptions.isMinimal()) {
        setTitle("DS Workbench " + Constants.VERSION + Constants.VERSION_ADDITION);
    } else {
        setTitle("DS Workbench Mini " + Constants.VERSION + Constants.VERSION_ADDITION);
    }

    jExportDialog.pack();
    jAddROIDialog.pack();

    JOutlookBar outlookBar = new JOutlookBar();
    outlookBar.addBar("Navigation", jNavigationPanel);
    outlookBar.addBar("Information", jInformationPanel);
    outlookBar.addBar("Karte", jMapPanel);
    outlookBar.addBar("ROI", jROIPanel);
    outlookBar.setVisibleBar(1);
    jSettingsScrollPane.setViewportView(outlookBar);

    mAbout = new AboutDialog(this, true);
    mAbout.pack();
    chooser.setDialogTitle("Speichern unter...");
    chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() {

        @Override
        public boolean accept(File f) {
            return (f != null) && (f.isDirectory() || f.getName().endsWith(".png"));
        }

        @Override
        public String getDescription() {
            return "PNG Image (*.png)";
        }
    });

    chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() {

        @Override
        public boolean accept(File f) {
            return (f != null) && (f.isDirectory() || f.getName().endsWith(".jpeg"));
        }

        @Override
        public String getDescription() {
            return "JPEG Image (*.jpeg)";
        }
    });

    //Schedule Backup
    new Timer("BackupTimer", true).schedule(new BackupTask(), 60 * 10000, 60 * 10000);

    //give focus to map panel if mouse enters map
    jMapPanelHolder.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            jMapPanelHolder.requestFocusInWindow();
        }
    });

    getContentPane().setBackground(Constants.DS_BACK);
    pack();
    capabilityInfoPanel1.addActionListener(MapPanel.getSingleton());

    // <editor-fold defaultstate="collapsed" desc=" Add global KeyListener ">
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

        @Override
        public void eventDispatched(AWTEvent event) {
            if (event.getID() == KeyEvent.KEY_PRESSED) {
                KeyEvent e = (KeyEvent) event;
                if (DSWorkbenchMainFrame.getSingleton().isActive()) {
                    //move shortcuts
                    if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                        scroll(0.0, 2.0);
                    } else if (e.getKeyCode() == KeyEvent.VK_UP) {
                        scroll(0.0, -2.0);
                    } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                        scroll(-2.0, 0.0);
                    } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                        scroll(2.0, 0.0);
                    } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //shot minimap tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_AXE);
                    } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack axe tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_RAM);
                    } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack ram tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_SNOB);
                    } else if ((e.getKeyCode() == KeyEvent.VK_4) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack snob tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_SPY);
                    } else if ((e.getKeyCode() == KeyEvent.VK_5) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack sword tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_LIGHT);
                    } else if ((e.getKeyCode() == KeyEvent.VK_6) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack light tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_HEAVY);
                    } else if ((e.getKeyCode() == KeyEvent.VK_7) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack heavy tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_SWORD);
                    } else if ((e.getKeyCode() == KeyEvent.VK_S) && e.isControlDown() && !e.isAltDown()) {
                        //search frame shortcut
                        DSWorkbenchSearchFrame.getSingleton()
                                .setVisible(!DSWorkbenchSearchFrame.getSingleton().isVisible());
                    }
                }

                //misc shortcuts
                if ((e.getKeyCode() == KeyEvent.VK_0) && e.isAltDown()) {
                    //no tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_DEFAULT);
                } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //measure tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_MEASURE);
                } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //mark tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_MARK);
                } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //tag tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_TAG);
                } else if ((e.getKeyCode() == KeyEvent.VK_4) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //attack ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SUPPORT);
                } else if ((e.getKeyCode() == KeyEvent.VK_5) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //attack ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SELECTION);
                } else if ((e.getKeyCode() == KeyEvent.VK_6) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //attack ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_RADAR);
                } else if ((e.getKeyCode() == KeyEvent.VK_7) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //attack ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_INGAME);
                } else if ((e.getKeyCode() == KeyEvent.VK_8) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //res ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SEND_RES_INGAME);
                } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isControlDown() && !e.isShiftDown()
                        && !e.isAltDown()) {
                    //move minimap tool shortcut
                    MinimapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_MOVE);
                } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isControlDown() && !e.isShiftDown()
                        && !e.isAltDown()) {
                    //zoom minimap tool shortcut
                    MinimapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ZOOM);
                } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isControlDown() && !e.isShiftDown()
                        && !e.isAltDown()) {
                    //shot minimap tool shortcut
                    MinimapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SHOT);
                } else if ((e.getKeyCode() == KeyEvent.VK_T) && e.isControlDown() && !e.isShiftDown()
                        && !e.isAltDown()) {
                    //search time shortcut
                    ClockFrame.getSingleton().setVisible(!ClockFrame.getSingleton().isVisible());
                } else if ((e.getKeyCode() == KeyEvent.VK_S) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    planMapshot();
                } else if (e.getKeyCode() == KeyEvent.VK_F2) {
                    DSWorkbenchAttackFrame.getSingleton()
                            .setVisible(!DSWorkbenchAttackFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F3) {
                    DSWorkbenchMarkerFrame.getSingleton()
                            .setVisible(!DSWorkbenchMarkerFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F4) {
                    DSWorkbenchTroopsFrame.getSingleton()
                            .setVisible(!DSWorkbenchTroopsFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F5) {
                    DSWorkbenchRankFrame.getSingleton()
                            .setVisible(!DSWorkbenchRankFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F6) {
                    DSWorkbenchFormFrame.getSingleton()
                            .setVisible(!DSWorkbenchFormFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F7) {
                    if (ServerSettings.getSingleton().isChurch()) {
                        DSWorkbenchChurchFrame.getSingleton()
                                .setVisible(!DSWorkbenchChurchFrame.getSingleton().isVisible());
                    }
                } else if (e.getKeyCode() == KeyEvent.VK_F8) {
                    DSWorkbenchConquersFrame.getSingleton()
                            .setVisible(!DSWorkbenchConquersFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F9) {
                    DSWorkbenchNotepad.getSingleton()
                            .setVisible(!DSWorkbenchNotepad.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F10) {
                    DSWorkbenchTagFrame.getSingleton()
                            .setVisible(!DSWorkbenchTagFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F11) {
                    DSWorkbenchStatsFrame.getSingleton()
                            .setVisible(!DSWorkbenchStatsFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F12) {
                    DSWorkbenchSettingsDialog.getSingleton().setVisible(true);
                } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 1
                    centerROI(0);
                } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 2
                    centerROI(1);
                } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 3
                    centerROI(2);
                } else if ((e.getKeyCode() == KeyEvent.VK_4) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 4
                    centerROI(3);
                } else if ((e.getKeyCode() == KeyEvent.VK_5) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 5
                    centerROI(4);
                } else if ((e.getKeyCode() == KeyEvent.VK_6) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 6
                    centerROI(5);
                } else if ((e.getKeyCode() == KeyEvent.VK_7) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 7
                    centerROI(6);
                } else if ((e.getKeyCode() == KeyEvent.VK_8) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 8
                    centerROI(7);
                } else if ((e.getKeyCode() == KeyEvent.VK_9) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 9
                    centerROI(8);
                } else if ((e.getKeyCode() == KeyEvent.VK_0) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 10
                    centerROI(9);
                } else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                    jMapPanelHolder.requestFocusInWindow();
                    MapPanel.getSingleton().setSpaceDown(true);
                } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
                    jMapPanelHolder.requestFocusInWindow();
                    MapPanel.getSingleton().setShiftDown(true);
                }
            } else if (event.getID() == KeyEvent.KEY_RELEASED) {
                KeyEvent e = (KeyEvent) event;
                if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                    MapPanel.getSingleton().setSpaceDown(false);
                } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
                    MapPanel.getSingleton().setShiftDown(false);
                }
            }
        }
    }, AWTEvent.KEY_EVENT_MASK);
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Load UI Icons ">
    try {
        jOnlineLabel.setIcon(new ImageIcon("./graphics/icons/online.png"));
        jEnableClipboardWatchButton.setIcon(new ImageIcon("./graphics/icons/watch_clipboard.png"));
        jCenterIngameButton
                .setIcon(new ImageIcon(DSWorkbenchMainFrame.class.getResource("/res/ui/center_ingame.png")));
        jRefreshButton.setIcon(new ImageIcon("./graphics/icons/refresh.png"));
        jCenterCoordinateIngame.setIcon(new ImageIcon("./graphics/icons/center.png"));
    } catch (Exception e) {
        logger.error("Failed to load status icon(s)", e);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Check for desktop support ">
    if (!Desktop.isDesktopSupported()) {
        jCenterIngameButton.setEnabled(false);
        jCenterCoordinateIngame.setEnabled(false);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Restore last map position ">
    try {
        String x = GlobalOptions.getSelectedProfile().getProperty("last.x");
        String y = GlobalOptions.getSelectedProfile().getProperty("last.y");
        centerPosition(Double.parseDouble(x), Double.parseDouble(y));
    } catch (Exception e) {
        centerPosition(ServerSettings.getSingleton().getMapDimension().getCenterX(),
                ServerSettings.getSingleton().getMapDimension().getCenterY());
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Restore other settings ">
    jShowMapPopup.setSelected(GlobalOptions.getProperties().getBoolean("show.map.popup"));
    jShowMouseOverInfo.setSelected(GlobalOptions.getProperties().getBoolean("show.mouseover.info"));
    jIncludeSupport.setSelected(GlobalOptions.getProperties().getBoolean("include.support"));
    jHighlightTribeVillages.setSelected(GlobalOptions.getProperties().getBoolean("highlight.tribes.villages"));
    jShowRuler.setSelected(GlobalOptions.getProperties().getBoolean("show.ruler"));
    jDisplayChurch.setSelected(GlobalOptions.getProperties().getBoolean("show.church"));
    jDisplayWatchtower.setSelected(GlobalOptions.getProperties().getBoolean("show.watchtower"));
    jDisplayChurch.setEnabled(ServerSettings.getSingleton().isChurch());
    jDisplayWatchtower.setEnabled(ServerSettings.getSingleton().isWatchtower());
    ServerSettings.getSingleton().addListener(new ServerSettingsListener() {
        @Override
        public void fireServerSettingsChanged() {
            jDisplayChurch.setEnabled(ServerSettings.getSingleton().isChurch());
            jDisplayWatchtower.setEnabled(ServerSettings.getSingleton().isWatchtower());
        }
    });
    int r = GlobalOptions.getProperties().getInt("radar.size");
    int hour = r / 60;
    jHourField.setText(Integer.toString(hour));
    jMinuteField.setText(Integer.toString(r - hour * 60));
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Skin Setup">
    DefaultComboBoxModel gpModel = new DefaultComboBoxModel(GlobalOptions.getAvailableSkins());
    jGraphicPacks.setModel(gpModel);
    String skin = GlobalOptions.getProperty("default.skin");
    if (gpModel.getIndexOf(skin) != -1) {
        jGraphicPacks.setSelectedItem(skin);
    } else {
        jGraphicPacks.setSelectedItem("default");
    }
    //</editor-fold>

    minZoom = GlobalOptions.getProperties().getDouble("map.zoom.min");
    maxZoom = GlobalOptions.getProperties().getDouble("map.zoom.max");
    dZoomInOutFactor = GlobalOptions.getProperties().getDouble("map.zoom.in.out.factor");

    mNotificationHideThread = new NotificationHideThread();
    mNotificationHideThread.start();
    SystrayHelper.installSystrayIcon();
    //update online state
    onlineStateChanged();
    restoreProperties();
}

From source file:com.brainflow.application.toplevel.Brainflow.java

private void initializeToolBar() {

    CommandGroup mainToolbarGroup = new CommandGroup("main-toolbar");
    mainToolbarGroup.bind(getApplicationFrame());

    ToggleGroup interpToggleGroup = new ToggleGroup("toggle-interp-group");
    interpToggleGroup.bind(getApplicationFrame());

    OpenImageCommand openImageCommand = new OpenImageCommand();
    openImageCommand.bind(getApplicationFrame());

    SnapshotCommand snapshotCommand = new SnapshotCommand();
    snapshotCommand.bind(getApplicationFrame());

    CreateAxialViewCommand axialCommand = new CreateAxialViewCommand();
    axialCommand.bind(getApplicationFrame());
    axialCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CreateSagittalViewCommand sagittalCommand = new CreateSagittalViewCommand();
    sagittalCommand.bind(getApplicationFrame());
    sagittalCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CreateCoronalViewCommand coronalCommand = new CreateCoronalViewCommand();
    coronalCommand.bind(getApplicationFrame());
    coronalCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CreateVerticalOrthogonalCommand vertCommand = new CreateVerticalOrthogonalCommand();
    vertCommand.bind(getApplicationFrame());
    vertCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CreateHorizontalOrthogonalCommand horizCommand = new CreateHorizontalOrthogonalCommand();
    horizCommand.bind(getApplicationFrame());
    horizCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CreateTriangularOrthogonalCommand triCommand = new CreateTriangularOrthogonalCommand();
    triCommand.bind(getApplicationFrame());
    triCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CommandGroup orthoGroup = new CommandGroup("ortho-view-group");
    orthoGroup.bind(getApplicationFrame());

    final NextSliceCommand nextSliceCommand = new NextSliceCommand();
    nextSliceCommand.bind(getApplicationFrame());
    nextSliceCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    final PreviousSliceCommand previousSliceCommand = new PreviousSliceCommand();
    previousSliceCommand.bind(getApplicationFrame());
    previousSliceCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent event) {
            if (event.getID() == KeyEvent.KEY_PRESSED) {
                KeyEvent ke = (KeyEvent) event;
                if (ke.getKeyCode() == KeyEvent.VK_LEFT) {
                    previousSliceCommand.execute();
                } else if (ke.getKeyCode() == KeyEvent.VK_RIGHT) {
                    nextSliceCommand.execute();
                }/*from w  w  w.j a va  2 s  . co  m*/

            }

        }
    }, AWTEvent.KEY_EVENT_MASK);

    PageBackSliceCommand pageBackSliceCommand = new PageBackSliceCommand();
    pageBackSliceCommand.bind(getApplicationFrame());
    pageBackSliceCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    PageForwardSliceCommand pageForwardSliceCommand = new PageForwardSliceCommand();
    pageForwardSliceCommand.bind(getApplicationFrame());
    pageForwardSliceCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    IncreaseContrastCommand increaseContrastCommand = new IncreaseContrastCommand();
    increaseContrastCommand.bind(getApplicationFrame());
    increaseContrastCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    DecreaseContrastCommand decreaseContrastCommand = new DecreaseContrastCommand();
    decreaseContrastCommand.bind(getApplicationFrame());
    decreaseContrastCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    ToggleCommand nearest = new NearestInterpolationToggleCommand();
    nearest.bind(getApplicationFrame());
    decreaseContrastCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    ToggleCommand linear = new LinearInterpolationToggleCommand();
    linear.bind(getApplicationFrame());

    ToggleCommand cubic = new CubicInterpolationToggleCommand();
    cubic.bind(getApplicationFrame());

    ToggleCommand toggleAxisLabelCommand = new ToggleAxisLabelCommand();
    toggleAxisLabelCommand.bind(getApplicationFrame());

    JToolBar mainToolbar = mainToolbarGroup.createToolBar();
    //ActionCommand increaseContrastCommand = new IncreaseContrastCommand();
    //increaseContrastCommand.bind(brainFrame);
    //mainToolbar.add(increaseContrastCommand.getActionAdapter());

    //ActionCommand decreaseContrastCommand = new DecreaseContrastCommand();
    //decreaseContrastCommand.bind(brainFrame);
    //mainToolbar.add(decreaseContrastCommand.getActionAdapter());

    brainFrame.getContentPane().add(mainToolbar, BorderLayout.NORTH);

    //InputMap map = documentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    //for (KeyStroke ks : map.keys()) {
    //    System.out.println("key : " + ks);
    //}

}

From source file:brainflow.app.toplevel.BrainFlow.java

private void initializeToolBar() {

    CommandGroup mainToolbarGroup = new CommandGroup("main-toolbar");

    mainToolbarGroup.bind(getApplicationFrame());

    ToggleGroup interpToggleGroup = new ToggleGroup("toggle-interp-group");
    interpToggleGroup.bind(getApplicationFrame());

    bindCommand(new OpenImageCommand(), true);
    bindCommand(new SnapshotCommand(), true);
    bindCommand(new NewCanvasCommand(), true);

    bindCommand(new CreateAxialViewCommand(), true);
    bindCommand(new CreateSagittalViewCommand(), true);

    bindCommand(new CreateCoronalViewCommand(), true);
    bindCommand(new CreateMontageViewCommand(), true);
    bindCommand(new CreateVerticalOrthogonalCommand(), true);

    bindCommand(new CreateHorizontalOrthogonalCommand(), true);
    bindCommand(new CreateTriangularOrthogonalCommand(), true);

    CommandGroup orthoGroup = new CommandGroup("ortho-view-group");
    orthoGroup.bind(getApplicationFrame());

    final NextSliceCommand nextSliceCommand = new NextSliceCommand();
    bindCommand(nextSliceCommand, false);

    final PreviousSliceCommand previousSliceCommand = new PreviousSliceCommand();
    bindCommand(previousSliceCommand, false);

    bindCommand(new PageBackSliceCommand(), true);
    bindCommand(new PageForwardSliceCommand(), true);

    bindCommand(new IncreaseContrastCommand(), true);
    bindCommand(new DecreaseContrastCommand(), true);

    bindCommand(new NearestInterpolationToggleCommand(), true);
    bindCommand(new LinearInterpolationToggleCommand(), true);
    bindCommand(new CubicInterpolationToggleCommand(), true);
    bindCommand(new ToggleAxisLabelCommand(), true);
    bindCommand(new ToggleCrossCommand(), true);

    //JToolBar mainToolbar = mainToolbarGroup.createToolBar();
    final CommandBar mainToolbar = new CommandBar();
    // for nimbus look and feel
    mainToolbar.setPaintBackground(false);
    // for nimbus look and feel

    mainToolbar.setBorder(new EmptyBorder(0, 0, 0, 0));
    final ButtonFactory buttonFactory = createToolBarButtonFactory();

    mainToolbarGroup.visitMembers(new GroupVisitor() {
        @Override//w w  w . j  av  a2  s .c  o  m
        public void visit(ActionCommand actionCommand) {
            JideButton jb = new JideButton(actionCommand.getActionAdapter());
            jb.setButtonStyle(JideButton.TOOLBAR_STYLE);
            jb.setText("");
            mainToolbar.add(jb);
        }

        @Override
        public void visit(CommandGroup commandGroup) {
            JComponent jc = commandGroup.createButton(buttonFactory);
            mainToolbar.add(jc);
        }
    });

    mainToolbar.setKey("toolbar");
    brainFrame.getDockableBarManager().addDockableBar(mainToolbar);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent event) {

            if (event.getID() == KeyEvent.KEY_PRESSED) {

                KeyEvent ke = (KeyEvent) event;
                Component comp = ke.getComponent();
                if (ke.getKeyCode() == KeyEvent.VK_LEFT) {
                    ImageView view = BrainFlow.get().getSelectedView();

                    if (/*view.hasFocus() || */ parentIsImageView(comp)) {
                        previousSliceCommand.execute();
                    }
                } else if (ke.getKeyCode() == KeyEvent.VK_RIGHT) {
                    ImageView view = BrainFlow.get().getSelectedView();

                    if ( /*view.hasFocus() */ parentIsImageView(comp)) {
                        nextSliceCommand.execute();
                    } else {
                        System.out.println("no focus");
                    }
                }

            }

        }
    }, AWTEvent.KEY_EVENT_MASK);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent event) {
            if (event.getID() == MouseEvent.MOUSE_RELEASED) {
                MouseEvent me = (MouseEvent) event;
                if (me.isPopupTrigger()) {
                    showActionMenu(me);
                }
            }

        }
    }, AWTEvent.MOUSE_EVENT_MASK);

}

From source file:op.FrmMain.java

public FrmMain() {
    initPhase = true;/*from   w  w  w  .j  av a  2 s  . co m*/
    initComponents();

    if (OPDE.isTraining()) {
        pnlMainMessage.setBackground(SYSConst.mediumorchid2.brighter().brighter());
    }

    //        pbTimeout.setToolTipText(SYSTools.xx("opde.mainframe.pbTimeout.tooltip"));
    // for the timeout function
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (OPDE.getLogin() != null) {
                displayManager.touch();
            }
        }
    }, AWTEvent.MOUSE_MOTION_EVENT_MASK);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (OPDE.getLogin() != null) {
                displayManager.touch();
            }
        }
    }, AWTEvent.KEY_EVENT_MASK);

    currentVisiblePanel = null;
    currentResident = null;
    lblWait.setText(SYSTools.xx("misc.msg.wait"));
    lblWait.setVisible(false);
    listOfNursingrecords = new ArrayList<CollapsiblePane>();
    btnHelp.setToolTipText(SYSTools.xx("opde.mainframe.btnHelp.tooltip"));

    iconPanels = Collections.synchronizedMap(new HashMap<Resident, JPanel>());

    if (OPDE.isDebug()) {
        setSize(1366, 768);
    } else {
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    }

    setTitle(SYSTools.getWindowTitle(""));

    displayManager = new DisplayManager(pbMsg, lblMainMsg, lblSubMsg, pnlIcons, pbTimeout, new Closure() {
        @Override
        public void execute(Object o) {
            OPDE.debug("TIMEOUT");
            logout();
            showLogin();
        }
    });
    displayManager.start();

    printProcessor = new PrintProcessor();
    printProcessor.start();

    // StatusBar Setup
    final LabelStatusBarItem label = new LabelStatusBarItem("Line");
    label.setText(OPDE.getUrl() + " [Build " + OPDE.getAppInfo().getBuildnum() + "]" + " [JVM "
            + System.getProperty("java.version") + "]");
    if (OPDE.isCustomUrl()) {
        label.setForeground(Color.RED);
    }
    label.setFont(new Font("Arial", Font.PLAIN, 14));
    statusBar.add(label, JideBoxLayout.FLEXIBLE);
    labelUSER = new LabelStatusBarItem("Line");
    labelUSER.setText("--");
    labelUSER.setAlignment(JLabel.CENTER);
    labelUSER.setFont(new Font("Arial", Font.PLAIN, 14));
    statusBar.add(labelUSER, JideBoxLayout.FLEXIBLE);
    final TimeStatusBarItem time = new TimeStatusBarItem();
    time.setFont(new Font("Arial", Font.PLAIN, 14));
    time.setUpdateInterval(10000);
    time.setTextFormat(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT));
    time.setAlignment(JLabel.CENTER);
    statusBar.add(time, JideBoxLayout.FLEXIBLE);
    final MemoryStatusBarItem gc = new MemoryStatusBarItem();
    gc.setFont(new Font("Arial", Font.PLAIN, 14));
    statusBar.add(gc, JideBoxLayout.FLEXIBLE);

    btnResetSplitpane.setToolTipText(SYSTools.xx("opde.mainframe.btnSplitReset.tooltip"));

    initPhase = false;

    //        JDialog dlg = new JDialog(this, false);
    //
    //        JPanel pnl = new JPanel();
    //        pnl.setLayout(new VerticalLayout());
    //
    //        for (float f = 0.0f; f <= 1.0; f = f + 0.01f){
    //            JLabel lbl = new JLabel(Float.toString(f));
    //            lbl.setForeground(GUITools.blend(Color.red, Color.WHITE, f));
    //            pnl.add(lbl);
    //        }
    //
    //        dlg.setContentPane(new JScrollPane(pnl));
    //
    //        dlg.pack();
    //        dlg.setVisible(true);

}

From source file:org.apache.cayenne.modeler.CayenneModelerFrame.java

/** Initializes main toolbar. */
protected void initToolbar() {
    JToolBar toolBar = new JToolBar();

    toolBar.add(getAction(NewProjectAction.class).buildButton());
    toolBar.add(getAction(OpenProjectAction.class).buildButton());
    toolBar.add(getAction(SaveAction.class).buildButton());

    toolBar.addSeparator();/* w w  w  . j  a va  2  s.  c o  m*/
    toolBar.add(getAction(RemoveAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(CutAction.class).buildButton());
    toolBar.add(getAction(CopyAction.class).buildButton());
    toolBar.add(getAction(PasteAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(UndoAction.class).buildButton());
    toolBar.add(getAction(RedoAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(CreateNodeAction.class).buildButton());
    toolBar.add(getAction(CreateDataMapAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(CreateDbEntityAction.class).buildButton());
    toolBar.add(getAction(CreateProcedureAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(CreateObjEntityAction.class).buildButton());
    toolBar.add(getAction(CreateEmbeddableAction.class).buildButton());
    toolBar.add(getAction(CreateQueryAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(NavigateBackwardAction.class).buildButton());
    toolBar.add(getAction(NavigateForwardAction.class).buildButton());

    JPanel east = new JPanel(new BorderLayout()); // is used to place search feature
    // components the most right on a
    // toolbar
    final JTextField findField = new JTextField(10);
    findField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() != KeyEvent.VK_ENTER) {
                findField.setBackground(Color.white);
            }
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyTyped(KeyEvent e) {
        }

    });
    findField.setAction(getAction(FindAction.class));
    JLabel findLabel = new JLabel("Search:");
    findLabel.setLabelFor(findField);
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

        public void eventDispatched(AWTEvent event) {

            if (event instanceof KeyEvent) {

                if (((KeyEvent) event).getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
                        && ((KeyEvent) event).getKeyCode() == KeyEvent.VK_F) {
                    findField.requestFocus();
                }
            }
        }

    }, AWTEvent.KEY_EVENT_MASK);

    JPanel box = new JPanel(); // is used to place label and text field one after
    // another
    box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
    box.add(findLabel);
    box.add(findField);
    east.add(box, BorderLayout.EAST);
    toolBar.add(east);

    getContentPane().add(toolBar, BorderLayout.NORTH);
}

From source file:org.sikuli.ide.SikuliIDE.java

private void initShortcutKeys() {
    final int scMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        private boolean isKeyNextTab(java.awt.event.KeyEvent ke) {
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_TAB
                    && ke.getModifiers() == InputEvent.CTRL_MASK) {
                return true;
            }//from  ww  w. j av  a2s . c  o m
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_CLOSE_BRACKET
                    && ke.getModifiers() == (InputEvent.META_MASK | InputEvent.SHIFT_MASK)) {
                return true;
            }
            return false;
        }

        private boolean isKeyPrevTab(java.awt.event.KeyEvent ke) {
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_TAB
                    && ke.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK)) {
                return true;
            }
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_OPEN_BRACKET
                    && ke.getModifiers() == (InputEvent.META_MASK | InputEvent.SHIFT_MASK)) {
                return true;
            }
            return false;
        }

        public void eventDispatched(AWTEvent e) {
            java.awt.event.KeyEvent ke = (java.awt.event.KeyEvent) e;
            //Debug.log(ke.toString());
            if (ke.getID() == java.awt.event.KeyEvent.KEY_PRESSED) {
                if (isKeyNextTab(ke)) {
                    nextTab();
                } else if (isKeyPrevTab(ke)) {
                    prevTab();
                }
            }
        }
    }, AWTEvent.KEY_EVENT_MASK);

}

From source file:org.tinymediamanager.ui.MainWindow.java

/**
 * Initialize the contents of the frame.
 *///from ww  w  .j  a  va 2s  . co  m
private void initialize() {
    // set the logo
    setIconImages(LOGOS);
    setBounds(5, 5, 1100, 727);
    // do nothing, we have our own windowClosing() listener
    // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    getContentPane().setLayout(new BorderLayout(0, 0));

    JLayeredPane content = new JLayeredPane();
    content.setLayout(new FormLayout(
            new ColumnSpec[] { ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("right:270px"), },
            new RowSpec[] { RowSpec.decode("fill:max(500px;default):grow"), }));
    getContentPane().add(content, BorderLayout.CENTER);

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default:grow") },
            new RowSpec[] { RowSpec.decode("fill:max(500px;default):grow") }));
    content.add(mainPanel, "1, 1, 3, 1, fill, fill");
    content.setLayer(mainPanel, 1);

    JTabbedPane tabbedPane = VerticalTextIcon.createTabbedPane(JTabbedPane.LEFT);
    tabbedPane.setTabPlacement(JTabbedPane.LEFT);
    mainPanel.add(tabbedPane, "1, 1, fill, fill");
    // getContentPane().add(tabbedPane, "1, 2, fill, fill");

    panelStatusBar = new StatusBar();
    getContentPane().add(panelStatusBar, BorderLayout.SOUTH);

    panelMovies = new MoviePanel();
    VerticalTextIcon.addTab(tabbedPane, BUNDLE.getString("tmm.movies"), panelMovies); //$NON-NLS-1$

    panelMovieSets = new MovieSetPanel();
    VerticalTextIcon.addTab(tabbedPane, BUNDLE.getString("tmm.moviesets"), panelMovieSets); //$NON-NLS-1$

    panelTvShows = new TvShowPanel();
    VerticalTextIcon.addTab(tabbedPane, BUNDLE.getString("tmm.tvshows"), panelTvShows); //$NON-NLS-1$

    // shutdown listener - to clean database connections safely
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            closeTmm();
        }
    });

    MessageManager.instance.addListener(TmmUIMessageCollector.instance);

    // mouse event listener for context menu
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent arg0) {
            if (arg0 instanceof MouseEvent && MouseEvent.MOUSE_RELEASED == arg0.getID()
                    && arg0.getSource() instanceof JTextComponent) {
                MouseEvent me = (MouseEvent) arg0;
                JTextComponent tc = (JTextComponent) arg0.getSource();
                if (me.isPopupTrigger() && tc.getComponentPopupMenu() == null) {
                    TextFieldPopupMenu.buildCutCopyPaste().show(tc, me.getX(), me.getY());
                }
            }
        }
    }, AWTEvent.MOUSE_EVENT_MASK);

    // temp info for users using Java 6
    if (SystemUtils.IS_JAVA_1_6) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JOptionPane.showMessageDialog(MainWindow.this, BUNDLE.getString("tmm.java6")); //$NON-NLS-1$
            }
        });
    }

    // inform user is MI could not be loaded
    if (Platform.isLinux() && StringUtils.isBlank(MediaInfo.version())) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JOptionPane.showMessageDialog(MainWindow.this, BUNDLE.getString("mediainfo.failed.linux")); //$NON-NLS-1$
            }
        });
    }
}