java类java.awt.KeyEventDispatcher的实例源码

SwingHacks.java 文件源码 项目:CrococryptFile 阅读 15 收藏 0 点赞 0 评论 0
public static final void makeHTMLButtonSpacable(){
    if(HTML_BUTTONS) return;
    HTML_BUTTONS = true;

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent ke) {
            if(ke.getID() == KeyEvent.KEY_RELEASED) return false;
            if(ke.getKeyCode() != KeyEvent.VK_ENTER && ke.getKeyCode() != KeyEvent.VK_SPACE) return false;

            if(ke.getSource() instanceof JButton){
                JButton jb = (JButton) ke.getSource();
                try {
                    for(MouseListener ml: jb.getMouseListeners())
                        ml.mouseReleased(new MouseEvent(jb, 1, 1, 1, -1, -1, 1, false, MouseEvent.BUTTON1));
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }

            return false;
        }
    });
}
ESCClosableDialog.java 文件源码 项目:arget 阅读 20 收藏 0 点赞 0 评论 0
@Override
protected void dialogInit () {
    super.dialogInit();

    keyDispatcher = new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent (KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                dispose();
                return true;
            }
            return false;
        }
    };
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher);
}
MainInterface.java 文件源码 项目:TASCA 阅读 16 收藏 0 点赞 0 评论 0
private static void addKeyboardShortcutListener() {
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addKeyEventDispatcher(new KeyEventDispatcher() {
    private long lastPressTime = 0;

    @Override
    public boolean dispatchKeyEvent(KeyEvent keyEvent) {

    if(System.currentTimeMillis() - lastPressTime > DELAY_KEY_PRESS) {
        executeShortcut(keyEvent);
        lastPressTime = System.currentTimeMillis();
    }

    return false; //continue to monitor other key events
    }

});
   }
dbfViewer.java 文件源码 项目:xBaseJ 阅读 18 收藏 0 点赞 0 评论 0
public dbfViewerRecordPanel(dbfViewer inParent, dbfTableModel indbfTableModel) throws Exception
{

   sp = new JScrollPane(this);
   parent = inParent;
   tableModel = indbfTableModel;
   setupDBFields();
class KeyDispatcher implements KeyEventDispatcher {


    public boolean dispatchKeyEvent(KeyEvent e) {
        parent.fileChanged = true;
        return false;
    }

   }
   KeyDispatcher keyDispatcher = new KeyDispatcher();
   KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher);


}
VentanaPrincipal.java 文件源码 项目:Sistemas-Multimedia 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Evento que tiene en cuenta cuando presionas alguna tecla. Está desde que
 * se crea la instancia de Ventana principal en funcionamiento.
 *
 * El único funcionamiento por ahora es que al pulsar la tecla ESC se
 * deseleccionan las figuras seleccionadas en una VentanaInterna.
 */
public final void keyboardEvent() {
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_PRESSED) {
                if (e.getKeyCode() == e.VK_ESCAPE) {
                    if (vi != null) {
                        vi.getLienzo().getvShapeSelected().clear();
                        repaint();
                        return true;
                    }
                }
            }
            return false;
        }
    });
}
AutoFindReferenceFrame.java 文件源码 项目:jClipCorn 阅读 17 收藏 0 点赞 0 评论 0
private void initMap() {
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    kfm.addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (! AutoFindReferenceFrame.this.isActive()) return false;

            KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e);

            if (!keyStroke.isOnKeyRelease() && keyStroke.getKeyCode() == KeyEvent.VK_P && keyStroke.getModifiers() == 0) {
                actionIgnore();
                return true;
            } else if (!keyStroke.isOnKeyRelease() && keyStroke.getKeyCode() == KeyEvent.VK_Q && keyStroke.getModifiers() == 0) {
                actionApply();
                return true;
            } else if (!keyStroke.isOnKeyRelease() && keyStroke.getKeyCode() == KeyEvent.VK_I && keyStroke.getModifiers() == 0) {
                actionApplyImDB();
                return true;
            }

            return false;
        }
    });
}
Template.java 文件源码 项目:TrabalhoCrisParte2 阅读 20 收藏 0 点赞 0 评论 0
private void Personalizar() {
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
    .addKeyEventDispatcher(new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
          teclaPressionada(e);
          return false;
        }
  });
}
KeyPressed.java 文件源码 项目:autoNEAT 阅读 45 收藏 0 点赞 0 评论 0
public static void initListener() {
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent ke) {
            synchronized (KeyPressed.class) {
                switch (ke.getID()) {
                    case KeyEvent.KEY_PRESSED:{
                        if (ke.getKeyCode() == KeyEvent.VK_W) {
                            wPressed = false;
                        }
                        if(ke.getKeyCode()  == KeyEvent.VK_P){
                            pPressed = false;
                        }
                    }break;

                    case KeyEvent.KEY_RELEASED:{
                        if (ke.getKeyCode() == KeyEvent.VK_W) {
                            wPressed = !wPressed;
                        }
                        if(ke.getKeyCode()  == KeyEvent.VK_P){
                            pPressed = !pPressed;
                        }
                    }break;
                }
                return false;
            }
        }
    });
}
SwingMain.java 文件源码 项目:chip8 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Creates new form SwingMain
 */
public SwingMain() {
    this.chip8Runner = new Thread(() -> {
        while (true) {
            try {
                if (running) {
                    if (pause == false || step) {
                        step = false;
                        chip8.cycle();
                        ((Chip8Model) jTable1.getModel()).update(chip8);
                    }
                    outputPanel.repaint();
                }
                sleep(1);
            } catch (InterruptedException ex) {
                Logger.getLogger(SwingMain.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    initComponents();
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            switch (e.getID()) {
                case KeyEvent.KEY_PRESSED:
                    Input.press(e.getKeyChar() + "");
                    break;
                case KeyEvent.KEY_RELEASED:
                    Input.unpress();
                    break;
                default:
                    break;
            }
            return false;
        }
    });
}
HotkeyManager.java 文件源码 项目:chatty 阅读 16 收藏 0 点赞 0 评论 0
public HotkeyManager(MainGui main) {
    this.main = main;

    if (Chatty.HOTKEY) {
        try {
            globalHotkeys = new GlobalHotkeySetter(new GlobalHotkeySetter.GlobalHotkeyListener() {

                @Override
                public void onHotkey(Object hotkeyId) {
                    onGlobalHotkey(hotkeyId);
                }
            });
            // If an error occured during initialization, then set to null
            // which means it's not going to be used.
            if (!globalHotkeys.isInitalized()) {
                globalHotkeyErrorWarning = globalHotkeys.getError();
                globalHotkeys = null;
            }
        } catch (NoClassDefFoundError ex) {
            LOGGER.warning("Failed to initialize hotkey setter [" + ex + "]");
            globalHotkeyErrorWarning = "Failed to initialize global hotkeys (jintellitype-xx.jar not found).";
            globalHotkeys = null;
        }
    }

    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    kfm.addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            return applicationKeyTriggered(e);
        }
    });
}
FlashBoulderBalkna.java 文件源码 项目:FlashBalknaSwing 阅读 39 收藏 0 点赞 0 评论 0
public FlashBoulderBalkna() {
    Model.createrModel(configDir, new JavaxWawPlayerProvider());
    hack = this;
    initComponents();
    setLocales();
    reloadTrainings();

    f1 = new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_F1 && e.getID() == KeyEvent.KEY_PRESSED) {
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        TrainingWithCycle tc = getSelectedTraining();
                        Training t = null;
                        Cycle c = null;
                        if (tc != null) {
                            t = tc.t;
                            c = tc.c;
                        }
                        SettingsDialogue d = new SettingsDialogue(t, c);
                        KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(f1);
                        d.setVisible(true);
                        d.dispose();
                        KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(f1);
                    }
                });

                return true;
            }
            return false;
        }
    };
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(f1);

}
HotkeyManager.java 文件源码 项目:Chatty-Twitch-Client 阅读 16 收藏 0 点赞 0 评论 0
public HotkeyManager(MainGui main) {
    this.main = main;

    if (Chatty.HOTKEY) {
        try {
            globalHotkeys = new GlobalHotkeySetter(new GlobalHotkeySetter.GlobalHotkeyListener() {

                @Override
                public void onHotkey(Object hotkeyId) {
                    onGlobalHotkey(hotkeyId);
                }
            });
            // If an error occured during initialization, then set to null
            // which means it's not going to be used.
            if (!globalHotkeys.isInitalized()) {
                globalHotkeys = null;
            }
        } catch (NoClassDefFoundError ex) {
            LOGGER.warning("Failed to initialize hotkey setter [" + ex + "]");
            LOGGER.log(Logging.USERINFO, "Failed to initialize global "
                    + "hotkeys (if you don't use global hotkeys you can "
                    + "just ignore this).");
            globalHotkeys = null;
        }
    }

    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    kfm.addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            return applicationKeyTriggered(e);
        }
    });
}
JSDOMBoxTestSuite.java 文件源码 项目:JSDOMBox 阅读 17 收藏 0 点赞 0 评论 0
/**
 * Create the application
 */
public JSDOMBoxTestSuite() {
    initialize();
    createBrowserContent();

    // Resize Timer initialization
    resizeTimer = new Timer(200, new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            renderBrowserContent();
            frmJsdomboxTestSuite.setVisible(true);
            renderBrowserContent();
        }
    });
    resizeTimer.setRepeats(false);

    // Keyboard Listener
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
        .addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getID() != KeyEvent.KEY_PRESSED)
                return false;

            if (e.getKeyCode() == KeyEvent.VK_LEFT)
                jsdomboxButton.setSelected(true);

            if (e.getKeyCode() == KeyEvent.VK_RIGHT)
                cssboxButton.setSelected(true);

            return false;
        }
    });
}
GoDir.java 文件源码 项目:GoDir 阅读 18 收藏 0 点赞 0 评论 0
private void initResources() {
desktop = Desktop.getDesktop();
kbfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
kbfm.addKeyEventDispatcher(new KeyEventDispatcher() {
    public boolean dispatchKeyEvent(KeyEvent e){
        return handleKeyEvents(e);
        }
    });
}
KeyStatusFactory.java 文件源码 项目:terminal-recall 阅读 16 收藏 0 点赞 0 评论 0
public void waitForSequenceTyped(final int ... keys){
    final boolean [] keyTypeObject  = new boolean[]{false};
    final KeyEventDispatcher dispatcher = new KeyEventDispatcher(){
    private volatile int keyArrayIndex = 0;
    @Override
    public synchronized boolean dispatchKeyEvent(KeyEvent evt) {//one at a time please...
        if(evt.getID()==KeyEvent.KEY_RELEASED){
        if(evt.getKeyCode()==keys[keyArrayIndex]){
            keyArrayIndex++;
            if(keyArrayIndex>=keys.length){
            synchronized(keyTypeObject){
                keyTypeObject[0]=true;
                keyTypeObject.notifyAll();
            }//end sync(keyTypeObject)
            return false;
            }//end if(>keys.length)
        }else keyArrayIndex=0;//!target key
        }//end if(KEY_RELEASED)
        return false;
    }};
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(dispatcher);
    synchronized(keyTypeObject){
        while(!keyTypeObject[0]){
        try{keyTypeObject.wait();}
        catch(InterruptedException e){break;}
        }//end while(!keyTypeObject)
    }//end sync(keyTypeObject)
    KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(dispatcher);
}
Translation.java 文件源码 项目:AgentWorkbench 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Here the key actions will be handled.
 */
private void setKeyListenEvents() {

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent ke) {

            // --- Just listen to KEY_PRESSED-Events --
            if (ke.getID()!=KeyEvent.KEY_PRESSED) {
                return false;
            }

            // --- Close Windows-Event ----------------
            if (ke.getKeyCode() == KeyEvent.VK_ESCAPE) {
                if (jTableDictionary.isEditing()==false) {
                    jButtonClose.doClick(); 
                }
            } 

            // --- CTRL-Events abfangen ---------------
            if (ke.getModifiers() == KeyEvent.CTRL_MASK || ke.getModifiers() == KeyEvent.CTRL_DOWN_MASK) {
                if (ke.getKeyCode()==KeyEvent.VK_S) {
                    jButtonSave.doClick();

                } else if (ke.getKeyCode()==KeyEvent.VK_G) {
                    jButtonGoogleTake.doClick();

                } else if (ke.getKeyCode()==KeyEvent.VK_F) {
                    jButtonFindGap.doClick();

                } else if (ke.getKeyCode()==KeyEvent.VK_UP) {
                    if (jTextFieldSource.hasFocus()==false 
                            & jTextFieldDestination.hasFocus()==false 
                            & jTextAreaGoogle.hasFocus()==false
                            & jTableDictionary.hasFocus()==false) {
                        jButtonPreviousDS.doClick();    
                    }

                } else if (ke.getKeyCode()==KeyEvent.VK_DOWN) {
                    if (jTextFieldSource.hasFocus()==false 
                            & jTextFieldDestination.hasFocus()==false 
                            & jTextAreaGoogle.hasFocus()==false
                            & jTableDictionary.hasFocus()==false) {
                        jButtonNextDS.doClick();    
                    }

                } else if (ke.getKeyCode()==KeyEvent.VK_DELETE) {
                    jButtonDelete.doClick();

                }

            }                   
            return false;
        }
    });
}
HystFrame.java 文件源码 项目:hyst 阅读 19 收藏 0 点赞 0 评论 0
public HystFrame(ToolPrinter[] printers, TransformationPass[] passes)
{
    this.printers = printers;
    availablePasses.addAll(Arrays.asList(passes));

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setTitle("Hyst: Hybrid Model Transformation and Translation Tool");
    addWindowListener(this);

    passNames = new Vector<String>();
    passNames.add("(Select Transformation Pass)");
    passNames.addAll(extractPassNames(passes));

    tabs.add(makeOptionsPanel(), "Options");

    tabs.add(makeOutputPanel(), "Output");

    getContentPane().add(tabs);

    loadFromGuiState(GuiState.load(GUISTATE_FILENAME));

    // default button
    JRootPane rootPane = SwingUtilities.getRootPane(runButton);
    rootPane.setDefaultButton(runButton);

    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new KeyEventDispatcher()
    {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e)
        {
            boolean rv = false;

            if (e.getKeyCode() == KeyEvent.VK_Q && e.isControlDown())
            {
                dispose();
                rv = true;
            }

            return rv;
        }

    });

    pack();
    setLocationRelativeTo(null);
}
CacheViewer.java 文件源码 项目:icedtea-web 阅读 17 收藏 0 点赞 0 评论 0
/**
 * Creates a new instance of the cache viewer.
 *
 * @param config Deployment configuration file.
 */
public CacheViewer(DeploymentConfiguration config) {
    super((Frame) null, dialogTitle, true); // Don't need a parent.
    this.config = config;
    if (config == null) {
        throw new IllegalArgumentException("config: " + config);
    }
    setIconImages(ImageResources.INSTANCE.getApplicationImages());
    /* Prepare for adding components to dialog box */
    Container contentPane = getContentPane();
    contentPane.setLayout(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1;
    c.weighty = 1;
    c.gridx = 0;
    c.gridy = 0;
    topPanel = new CachePane(this, this.config);
    contentPane.add(topPanel, c);

    pack();
    this.topPanel.invokeLaterPopulateTable();

    /* Set focus to default button when first activated */
    WindowAdapter adapter = new WindowAdapter() {
        private boolean gotFocus = false;

        @Override
        public void windowGainedFocus(WindowEvent we) {
            // Once window gets focus, set initial focus
            if (!gotFocus) {
                topPanel.focusOnDefaultButton();
                gotFocus = true;
            }
        }
    };
    addWindowFocusListener(adapter);

    // Add a KeyEventDispatcher to dispatch events when this CacheViewer has focus
    final CacheViewer cacheViewer = this;
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
        /**
         * Dispatches mainly the {@code KeyEvent.VK_ESCAPE} key event to
         * close the {@code CacheViewer} dialog.
         * @return {@code true} after an {@link KeyEvent#VK_ESCAPE
         * VK_ESCAPE} has been processed, otherwise {@code false}
         * @see KeyEventDispatcher
         */
        public boolean dispatchKeyEvent(final KeyEvent keyEvent) {
            // Check if Esc key has been pressed
            if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE &&
                keyEvent.getID() == KeyEvent.KEY_PRESSED) {
                // Exclude this key event from further processing
                keyEvent.consume();
                // Remove this low-level KeyEventDispatcher
                KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this);
                // Post close event to CacheViewer dialog
                Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
                        new WindowEvent(cacheViewer, WindowEvent.WINDOW_CLOSING));
                return true;
            }
            return false;
        }
    });

    initialized = true;
}
JGame.java 文件源码 项目:agshmne 阅读 19 收藏 0 点赞 0 评论 0
public JGame(Game game) {
    this.game = game;
    jregion = new JMapRegion(this.game);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setExtendedState(JFrame.MAXIMIZED_BOTH);

    // Ajout Panneau Final
    Container contentPane = this.getContentPane();
    contentPane.setLayout(new GridBagLayout());
    GridBagConstraints gbcGame = new GridBagConstraints();
    gbcGame.insets = new Insets(5, 5, 5, 5);
    gbcGame.fill = GridBagConstraints.BOTH;
    gbcGame.anchor = GridBagConstraints.CENTER;
    gbcGame.gridheight = 1;
    gbcGame.gridwidth = 1;
    gbcGame.gridy = 0;

    // JPanCharacter : Personnage
    gbcGame.gridx = 0;
    gbcGame.weightx = 0;
    gbcGame.weighty = 0;
    contentPane.add(new JPanCharacter(game.getPlayer()), gbcGame);

    // JPanMain : Carte, Inventaire, Equipement, Magie, Quêtes, Villes, ...
    gbcGame.gridx = 1;
    gbcGame.weightx = 1;
    gbcGame.weighty = 1;
    final JPanMain mainPan = new JPanMain(game, this.jregion);
    contentPane.add(mainPan, gbcGame);

    // JPanRight : Objets à terres et Actions générales
    gbcGame.gridx = 2;
    gbcGame.weightx = 0;
    gbcGame.weighty = 0;
    contentPane.add(new JPanRight(game), gbcGame);
    game.newTurn();

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (mainPan.getJPanTabbed().getSelectedIndex() == JPanTabbed.MAP_PANEL_INDEX && e.getID() == KeyEvent.KEY_PRESSED) {
                switch (e.getKeyCode()) {
                case KeyEvent.VK_LEFT:
                    JGame.this.game.setPosition(new Position(JGame.this.game.getPosition().getX() - 1,
                            JGame.this.game.getPosition().getY()));
                    JGame.this.game.newTurn();
                    return true;
                case KeyEvent.VK_RIGHT:
                    JGame.this.game.setPosition(new Position(JGame.this.game.getPosition().getX() + 1,
                            JGame.this.game.getPosition().getY()));
                    JGame.this.game.newTurn();
                    return true;
                case KeyEvent.VK_UP:
                    JGame.this.game.setPosition(new Position(JGame.this.game.getPosition().getX(),
                            JGame.this.game.getPosition().getY() + 1));
                    JGame.this.game.newTurn();
                    return true;
                case KeyEvent.VK_DOWN:
                    JGame.this.game.setPosition(new Position(JGame.this.game.getPosition().getX(),
                            JGame.this.game.getPosition().getY() - 1));
                    JGame.this.game.newTurn();
                    return true;
                }
            }
            return false;
        }

    });
    this.setFocusable(true);
}
MainFrame.java 文件源码 项目:netbeans-mmd-plugin 阅读 31 收藏 0 点赞 0 评论 0
private void menuFullScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFullScreenActionPerformed

    final AbstractEditor selectedEditor = this.tabPane.getCurrentEditor();
    if (selectedEditor != null) {
      final GraphicsConfiguration gconfig = this.getGraphicsConfiguration();
      if (gconfig != null) {
        final GraphicsDevice device = gconfig.getDevice();
        if (device.isFullScreenSupported()) {
          if (device.getFullScreenWindow() == null) {
            final JLabel label = new JLabel("Opened in full screen");
            final int tabIndex = this.tabPane.getSelectedIndex();
            this.tabPane.setComponentAt(tabIndex, label);
            final JWindow window = new JWindow(Main.getApplicationFrame());
            window.setAlwaysOnTop(true);
            window.setAutoRequestFocus(true);
            window.setContentPane(selectedEditor.getContainerToShow());

            endFullScreenIfActive();

            final KeyEventDispatcher fullScreenEscCatcher = new KeyEventDispatcher() {
              @Override
              public boolean dispatchKeyEvent(@Nonnull final KeyEvent e) {
                if (e.getID() == KeyEvent.KEY_PRESSED && (e.getKeyCode() == KeyEvent.VK_ESCAPE || e.getKeyCode() == KeyEvent.VK_F11)) {
                  endFullScreenIfActive();
                  return true;
                }
                return false;
              }
            };

            if (this.taskToEndFullScreen.compareAndSet(null, new Runnable() {
              @Override
              public void run() {
                try {
                  window.dispose();
                }
                finally {
                  tabPane.setComponentAt(tabIndex, selectedEditor.getContainerToShow());
                  device.setFullScreenWindow(null);
                  KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(fullScreenEscCatcher);
                }
              }
            })) {
              try {
                KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(fullScreenEscCatcher);
                device.setFullScreenWindow(window);
              }
              catch (Exception ex) {
                LOGGER.error("Can't turn on full screen", ex); //NOI18N
                endFullScreenIfActive();
                KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(fullScreenEscCatcher);
              }
            } else {
              LOGGER.error("Unexpected state, processor is not null!"); //NOI18N
            }
          } else {
            LOGGER.warn("Attempt to full screen device which already in full screen!"); //NOI18N
          }
        } else {
          LOGGER.warn("Device doesn's support full screen"); //NOI18N
          DialogProviderManager.getInstance().getDialogProvider().msgWarn(null, "The Device doesn't support full-screen mode!");
        }
      } else {
        LOGGER.warn("Can't find graphics config for the frame"); //NOI18N
      }
    }
  }
ProjectFrame.java 文件源码 项目:frinika 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Grab some keys before the focus manager gets them !!!! TODO discuss this.
 * Maybe better to have a focus panes and grab the keyboard for each of
 * these ?
 */
void overRideKeys() {
    startStop = new StartStopAction(this);
    rewind = new RewindAction(this);
    record = new RecordAction(this);
    warpToLeft = new WarpToLeftAction(this);
    warpToRight = new WarpToRightAction(this);
    final SelectAllAction selectAllAction = new SelectAllAction(this);
    KeyboardFocusManager kbm = KeyboardFocusManager
            .getCurrentKeyboardFocusManager();

    kbm.addKeyEventDispatcher(new KeyEventDispatcher() {

        public boolean dispatchKeyEvent(KeyEvent e) {

            if (!ProjectFrame.this.isActive())
                return false;
            // Let text components have all key hits
            if (e.getSource() instanceof JTextComponent)
                return false;

            switch (e.getKeyCode()) {
            case KeyEvent.VK_SPACE:
                if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                    startStop.actionPerformed(null);
                }
                return true;

            case KeyEvent.VK_HOME:
                if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                    rewind.actionPerformed(null);
                }
                return true;

            case KeyEvent.VK_MULTIPLY:
                if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                    record.actionPerformed(null);
                }
                return true;

            case KeyEvent.VK_NUMPAD1:
                if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                    warpToLeft.actionPerformed(null);
                }
                return true;

            case KeyEvent.VK_NUMPAD2:
                if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                    warpToRight.actionPerformed(null);
                }
                return true;

            case KeyEvent.VK_A:

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

                    if (e.isControlDown()) {
                        return selectAllAction.selectAll(e);
                    }
                }

            default:
                return false;
            }
        }
    });

}
AudioAnalysisTimePanel.java 文件源码 项目:frinika 阅读 18 收藏 0 点赞 0 评论 0
void overrideKeys() {



    kbd.addKeyEventDispatcher(keyDispatcher=new KeyEventDispatcher() {

        public boolean dispatchKeyEvent(KeyEvent e) {

    //      System.out.println(" KEY HIT " + e);

            switch (e.getKeyCode()) {
            case KeyEvent.VK_SPACE:
                if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                    startStop();
                }
                return true;

            case KeyEvent.VK_LEFT:
                if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                    nudge(-1);
                }
                return true;

            case KeyEvent.VK_RIGHT:
                if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                    nudge(1);
                }
                return true;

                //
                // case KeyEvent.VK_HOME:
                // if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                // rewind.actionPerformed(null);
                // }
                // return true;
                //
                // case KeyEvent.VK_MULTIPLY:
                // if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                // record.actionPerformed(null);
                // }
                // return true;
                //
                // case KeyEvent.VK_NUMPAD1:
                // if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                // warpToLeft.actionPerformed(null);
                // }
                // return true;
                //
                // case KeyEvent.VK_NUMPAD2:
                // if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                // warpToRight.actionPerformed(null);
                // }
                // return true;
                //
                // case KeyEvent.VK_A:
                //
                // if ((e.getID() == KeyEvent.KEY_PRESSED)) {
                //
                // if (e.isControlDown()) {
                // return selectAllAction.selectAll(e);
                // }
                // }

            default:
                return false;
            }
        }
    });

}
JXLoginPane.java 文件源码 项目:aibench-project 阅读 16 收藏 0 点赞 0 评论 0
/**
 * Create a {@code JXLoginPane} with the specified {@code LoginService},
 * {@code PasswordStore}, {@code UserNameStore}, and server list.
 * <p>
 * If you do not want to store passwords or user ids, those parameters can
 * be {@code null}. {@code SaveMode} is autoconfigured from passed in store
 * parameters.
 * <p>
 * Setting the server list to {@code null} will unset all of the servers.
 * The server list is guaranteed to be non-{@code null}.
 *
 * @param service
 *            the {@code LoginService} to use for logging in
 * @param passwordStore
 *            the {@code PasswordStore} to use for storing password
 *            information
 * @param userStore
 *            the {@code UserNameStore} to use for storing user information
 * @param servers
 *            a list of servers to authenticate against
 */
public JXLoginPane(LoginService service, PasswordStore passwordStore, UserNameStore userStore, List<String> servers) {
    //init capslock detection support
    if (Boolean.parseBoolean(System.getProperty("swingx.enableCapslockTesting"))) {
        capsOnTest = new CapsOnTest();
        capsOnListener = new KeyEventDispatcher() {
            public boolean dispatchKeyEvent(KeyEvent e) {
                if (e.getID() != KeyEvent.KEY_PRESSED) {
                    return false;
                }
                if (e.getKeyCode() == 20) {
                    setCapsLock(!isCapsLockOn());
                }
                return false;
            }};
        capsOnWinListener = new CapsOnWinListener(capsOnTest);
    } else {
        capsOnTest = null;
        capsOnListener = null;
        capsOnWinListener = null;
        capsLockSupport = false;
    }
    setLoginService(service);
    setPasswordStore(passwordStore);
    setUserNameStore(userStore);
    setServers(servers);


    //create the login and cancel actions, and add them to the action map
    getActionMap().put(LOGIN_ACTION_COMMAND, createLoginAction());
    getActionMap().put(CANCEL_LOGIN_ACTION_COMMAND, createCancelAction());

    //initialize the save mode
    if (passwordStore != null && userStore != null) {
        saveMode = SaveMode.BOTH;
    } else if (passwordStore != null) {
        saveMode = SaveMode.PASSWORD;
    } else if (userStore != null) {
        saveMode = SaveMode.USER_NAME;
    } else {
        saveMode = SaveMode.NONE;
    }

    // #732 set all internal components opacity to false in order to allow top level (frame's content pane) background painter to have any effect.
    setOpaque(false);
    initComponents();
}
dbfViewer.java 文件源码 项目:xBaseJ 阅读 16 收藏 0 点赞 0 评论 0
public dbfTableRecordMemoDialog(dbfViewer inParent, JPanel inFr, dbfTableModel indbfTableModel, int inRow, int inCol)
    {
       super(inParent, "Memo Field", true);
       parent = inParent;
       fr = inFr;
       addWindowListener(this);
       tableModel = indbfTableModel;
       row = inRow;
       col = inCol;
       try {
          Field f = indbfTableModel.getColumnField(inCol);
          setTitle(f.getName());
}
 catch (Exception e1) {System.err.println("Failed to get column name");}

       text.setText((String) tableModel.getValueAt(row, col));
       JScrollPane jsp = new JScrollPane(text);
       jsp.setPreferredSize(new Dimension(230,160));
       jsp.setBorder(BorderFactory.createEtchedBorder());
       this.getContentPane().add("Center", jsp);

       JPanel p =  new JPanel();
       p.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 15));
       p.add(Okay);
       Okay.addActionListener(this);
       this.getContentPane().add("East", p);
       p.add(Cancel);
       Cancel.addActionListener(this);
       this.getContentPane().add("West", p);
       this.pack();

    class KeyDispatcher implements KeyEventDispatcher {


        public boolean dispatchKeyEvent(KeyEvent e) {
            parent.fileChanged = true;
            return false;
        }

       }
       KeyDispatcher keyDispatcher = new KeyDispatcher();
       KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher);
    }
CCPanel.java 文件源码 项目:MarmaraDrone 阅读 18 收藏 0 点赞 0 评论 0
public CCPanel(final ARDrone ardrone)
    {
        super(new GridBagLayout());

        setBackground(Color.BLUE);
        video = new VideoPanel(ardrone);
        battery = new BatteryPanel();
        state = new StatePanel();
        attitude = new AttitudePanel();

        add(video, new GridBagConstraints(0, 0, 1, 1, 0.7, 1, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0, 0));
        add(new JScrollPane(state), new GridBagConstraints(1, 0, 1, 2, 0.3, 1, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.VERTICAL, new Insets(0,0,0,0), 0, 0));

        add(attitude.getPane(), new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0, 0));
//      add(battery, new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0, 0));



        // Drone i�in CommandManager'da kollar� (klavye) giri� ve olaylar g�nderir      
        System.out.println("CCFrame Klavye ayarlar� y�klendi ...");
        KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        manager.addKeyEventDispatcher(new KeyEventDispatcher() {

            private KeyboardCommandManager cmdManager = new KeyboardCommandManager(ardrone, 45);

            public boolean dispatchKeyEvent(KeyEvent e)
            {
                if (e.getID() == KeyEvent.KEY_PRESSED) 
                {
                    cmdManager.keyPressed(e);
                } 
                else if (e.getID() == KeyEvent.KEY_RELEASED) 
                {
                    cmdManager.keyReleased(e);
                }
                return true;
            }
        });

        ardrone.addImageUpdateListener(this);
        ardrone.addNavDataListener(this);
    }
ChitankaKindlet.java 文件源码 项目:chitanka4kindle 阅读 15 收藏 0 点赞 0 评论 0
public void create(KindletContext context) {
    ContextManager.setContext(context);

    // handle the Back key to navigate back in the browsing history
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .addKeyEventDispatcher(new KeyEventDispatcher() {
                public boolean dispatchKeyEvent(KeyEvent key) {
                    if (key.isConsumed()
                            || key.getID() == KeyEvent.KEY_RELEASED)
                        return false;

                    switch (key.getKeyCode()) {
                    case KindleKeyCodes.VK_BACK:
                        ConnectivityManager mgr = ConnectivityManager.getInstance();
                        if (mgr.canGoBack()) {
                            key.consume();
                            mgr.goBack();
                            return true;
                        }
                        break;

                    case KindleKeyCodes.VK_LEFT_HAND_SIDE_TURN_PAGE:
                    case KindleKeyCodes.VK_RIGHT_HAND_SIDE_TURN_PAGE:
                        key.consume();
                        ScreenManager.getCurrentScreen().nextPage();
                        return true;

                    case KindleKeyCodes.VK_TURN_PAGE_BACK:
                        key.consume();
                        ScreenManager.getCurrentScreen().previousPage();
                        return true;

                    case VK_KEYBOARD:
                        ScreenManager.getCurrentScreen().focusOnSearch();
                        return true;
                    }

                    return false;
                }
            });
}
CreateNewDiagramWindow.java 文件源码 项目:Germ 阅读 17 收藏 0 点赞 0 评论 0
public CreateNewDiagramWindow(){
    super(1);

    try{
        setIconImage(ImageIO.read(new File("germ/gui/windows/images/programIcon.png")));
        }catch(Exception ex){}
    Point center = GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getCenterPoint();

    initializeProjects();

    Container container = getContentPane();

    GridBagConstraints c00 = new GridBagConstraints();
    c00.gridx = 0;
    c00.gridy = 0;
    c00.anchor = GridBagConstraints.EAST;
    c00.insets = new Insets(20, 20, 0, 0);

    GridBagConstraints c10 = new GridBagConstraints();
    c10.gridx = 1;
    c10.gridy = 0;
    c10.weightx = 1;
    c10.fill = GridBagConstraints.HORIZONTAL;
    c10.anchor = GridBagConstraints.WEST;
    c10.insets = new Insets(20, 20, 0, 20);

    GridBagConstraints c01 = new GridBagConstraints();
    c01.gridx = 0;
    c01.gridy = 1;
    c01.anchor = GridBagConstraints.EAST;
    c01.insets = new Insets(20, 20, 0, 0);

    GridBagConstraints c11 = new GridBagConstraints();
    c11.gridx = 1;
    c11.gridy = 1;
    c11.weightx = 1;
    c11.fill = GridBagConstraints.HORIZONTAL;
    c11.anchor = GridBagConstraints.WEST;
    c11.insets = new Insets(20, 20, 0, 20);

    GridBagConstraints c2 = new GridBagConstraints();
    c2.gridx = 0;
    c2.gridy = 2;
    c2.gridwidth = 2;
    c2.anchor = GridBagConstraints.CENTER;
    c2.insets = new Insets(35, 0, 10, 0);

    KeyboardFocusManager manager = KeyboardFocusManager
            .getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new KeyEventDispatcher() {
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                escapePressed();
            } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                enterPressed();
            }
            return false;
        }
    });

    container.add(lblNew, c00);
    container.add(cbProjects, c10);
    container.add(lblDiagram, c01);
    container.add(tfNew,c11);
    container.add(okCancelBox, c2);

    this.pack();
    setLocation(center.x - getSize().width / 2, center.y - getSize().height / 2);

}
CCPanel.java 文件源码 项目:MarmaraDrone 阅读 20 收藏 0 点赞 0 评论 0
public CCPanel(final ARDrone ardrone)
    {
        super(new GridBagLayout());

        setBackground(Color.BLUE);
        video = new VideoPanel(ardrone);
        battery = new BatteryPanel();
        state = new StatePanel();
        attitude = new AttitudePanel();

        add(video, new GridBagConstraints(0, 0, 1, 1, 0.7, 1, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0, 0));
        add(new JScrollPane(state), new GridBagConstraints(1, 0, 1, 2, 0.3, 1, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.VERTICAL, new Insets(0,0,0,0), 0, 0));

        add(attitude.getPane(), new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0, 0));
//      add(battery, new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0, 0));



        // Drone i�in CommandManager'da kollar� (klavye) giri� ve olaylar g�nderir      
        System.out.println("CCFrame Klavye ayarlar� y�klendi ...");
        KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        manager.addKeyEventDispatcher(new KeyEventDispatcher() {

            private KeyboardCommandManager cmdManager = new KeyboardCommandManager(ardrone, 45);

            public boolean dispatchKeyEvent(KeyEvent e)
            {
                if (e.getID() == KeyEvent.KEY_PRESSED) 
                {
                    cmdManager.keyPressed(e);
                } 
                else if (e.getID() == KeyEvent.KEY_RELEASED) 
                {
                    cmdManager.keyReleased(e);
                }
                return true;
            }
        });

        ardrone.addImageUpdateListener(this);
        ardrone.addNavDataListener(this);
    }
FocusManager.java 文件源码 项目:javify 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Wraps
 * {@link KeyboardFocusManager#addKeyEventDispatcher(KeyEventDispatcher)}.
 *
 * @param d the dispatcher
 */
public void addKeyEventDispatcher(KeyEventDispatcher d)
{
  wrapped.addKeyEventDispatcher(d);
}
FocusManager.java 文件源码 项目:javify 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Wraps
 * {@link KeyboardFocusManager#removeKeyEventDispatcher(KeyEventDispatcher)}.
 *
 * @param d the key event dispatcher to remove
 */
public void removeKeyEventDispatcher(KeyEventDispatcher d)
{
  wrapped.removeKeyEventDispatcher(d);
}


问题


面经


文章

微信
公众号

扫码关注公众号