public ToolbarDragDrop(GuiTestApp parent) {
    this.parent = parent;

    KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    fm.addKeyEventDispatcher(
        new KeyEventDispatcher() {
          public boolean dispatchKeyEvent(KeyEvent e) {

            if (e.getID() == KeyEvent.KEY_RELEASED && e.getKeyCode() == KeyEvent.VK_TAB) {

              if (dragging) {

                Thread t =
                    new Thread() {
                      public void run() {
                        draggedTile.rotate();
                      }
                    };

                t.start();
              }
            }

            return false;
          }
        });
  }
  public void createController() {
    controller = new MegaMekController();
    KeyboardFocusManager kbfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    kbfm.addKeyEventDispatcher(controller);

    KeyBindParser.parseKeyBindings(controller);
  }
Exemple #3
0
  public mainWindow(Controller c, RandomEventGenerator r, Safety s) {

    // use system look and feel
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      // do nothing
    }

    view = new ElevatorSimView();
    safety = s;
    controller = c;
    randomEventGen = r;
    simStarted = false;

    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    initComponents();

    setGUIEnabled(false);

    SimViewPanel.add(view.getCanvas(), BorderLayout.CENTER);
    this.validate();

    AlgorithmDescBox.setText(controller.getAlgorithmDesc(0));

    doc = MsgBox.getStyledDocument();

    Style style = MsgBox.addStyle("Faults", null);
    StyleConstants.setForeground(style, Color.red);
    StyleConstants.setItalic(style, true);
    StyleConstants.setBold(style, true);

    style = MsgBox.addStyle("Passengers", null);
    StyleConstants.setForeground(style, new Color(0, 204, 204));
    StyleConstants.setItalic(style, true);

    style = MsgBox.addStyle("Normal", null);

    style = MsgBox.addStyle("Elevators", null);
    StyleConstants.setForeground(style, new Color(51, 255, 0));
    StyleConstants.setBold(style, true);

    style = MsgBox.addStyle("Emergs", null);
    StyleConstants.setForeground(style, Color.red);
    StyleConstants.setBold(style, true);

    style = MsgBox.addStyle("Maintenance", null);
    StyleConstants.setForeground(style, Color.ORANGE);
    StyleConstants.setBold(style, true);

    // Hijack the keyboard manager
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new KeyDispatcher(this));

    // add window listener
    this.addWindowListener(new mainWindowListener());
  }
  protected void redispatchKeyEvents(final JTextComponent textComponent, KeyEvent firstKeyEvent) {
    if (textComponent.hasFocus()) {
      return;
    }
    final KeyboardFocusManager currentKeyboardFocusManager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    class KeyEventQueue implements KeyEventDispatcher, FocusListener {
      LinkedList events = new LinkedList();

      public boolean dispatchKeyEvent(KeyEvent e) {
        events.add(e);
        return true;
      }

      public void focusGained(FocusEvent e) {
        e.getComponent().removeFocusListener(this);
        currentKeyboardFocusManager.removeKeyEventDispatcher(this);
        final Iterator iterator = events.iterator();
        while (iterator.hasNext()) {
          final KeyEvent ke = (KeyEvent) iterator.next();
          ke.setSource(textComponent);
          textComponent.dispatchEvent(ke);
        }
      }

      public void focusLost(FocusEvent e) {}
    };
    final KeyEventQueue keyEventDispatcher = new KeyEventQueue();
    currentKeyboardFocusManager.addKeyEventDispatcher(keyEventDispatcher);
    textComponent.addFocusListener(keyEventDispatcher);
    if (firstKeyEvent == null) {
      return;
    }
    if (firstKeyEvent.getKeyChar() == KeyEvent.CHAR_UNDEFINED) {
      switch (firstKeyEvent.getKeyCode()) {
        case KeyEvent.VK_HOME:
          textComponent.setCaretPosition(0);
          break;
        case KeyEvent.VK_END:
          textComponent.setCaretPosition(textComponent.getDocument().getLength());
          break;
      }
    } else {
      textComponent.selectAll(); // to enable overwrite
      // redispath all key events
      textComponent.dispatchEvent(firstKeyEvent);
    }
  }
Exemple #5
0
  public void setVisible(boolean b) {
    KeyboardFocusManager keyboardFocusManager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (b) {
      keyboardFocusManager.addKeyEventDispatcher(keyManager);
    } else {
      keyboardFocusManager.removeKeyEventDispatcher(keyManager);
    }
    super.setVisible(b);

    Window owner = getOwner();
    if (owner != null) {
      owner.requestFocus();
      if (lastFocusOwner != null) {
        lastFocusOwner.requestFocusInWindow();
      }
    }
  }
Exemple #6
0
  /**
   * Create a new paddle.
   *
   * @param world The world the paddle will be added to.
   * @param y The height of the paddle (starts centered on the x)
   * @param mode The keys that will move this paddle
   */
  public Paddle(World world, int y, MovementMode mode) {
    Mode = mode;

    // Respond to the keyboard
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(this);

    // Add the physics body
    BodyDef bd = new BodyDef();
    bd.type = BodyType.DYNAMIC;
    bd.position.set(world.Bounds.width / 2, y);
    bd.linearDamping = 0.0f;
    bd.angularDamping = 0.01f;

    FixtureDef fd = new FixtureDef();
    fd.shape = new PolygonShape();
    ((PolygonShape) fd.shape).setAsBox(SIZE.width / 2, SIZE.height / 2);
    fd.density = 0.1f;
    fd.friction = 0.0f;
    fd.restitution = 1.0f;

    j2dBody = world.j2dWorld.createBody(bd);
    j2dBody.createFixture(fd);
    j2dBody.setUserData(this);

    // Limit it to only x movement
    BodyDef gbd = new BodyDef();
    gbd.type = BodyType.STATIC;
    bd.position.set(world.Bounds.width / 2, y);

    PrismaticJointDef pjd = new PrismaticJointDef();
    pjd.collideConnected = true;
    pjd.initialize(
        j2dBody, world.j2dWorld.createBody(gbd), j2dBody.getWorldCenter(), new Vec2(1.0f, 0.0f));
    world.j2dWorld.createJoint(pjd);
  }
Exemple #7
0
    @Override
    public void run() {
      // TODO spravit krajsie

      final JFrame frame = new JFrame("ViDA");
      GUI.frame = frame;
      frame.setLayout(null);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      graphLoader = new JFileChooser("./");
      graphSaver = new JFileChooser("./");

      menu = new JMenuBar();
      Menu.init();

      for (int i = 0; i < Menu.menuItems.length; i++) {
        final JMenu item = new JMenu(Menu.menuItems[i]);
        menu.add(item);
        for (int j = 0; j < Menu.allMenuItems[i].length; ++j) {
          if (Menu.allMenuItems[i][j].equals("--")) {
            item.addSeparator();
          } else {
            final JMenuItem meno = new JMenuItem(Menu.allMenuItems[i][j]);
            item.add(meno);
            final int fi = i;
            final int fj = j;
            meno.addActionListener(
                new ActionListener() {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    Menu.performAction(fi, fj);
                  }
                });
          }
        }
      }

      popupInformation = new PopupPanel(informationPanel.scrollPanel);
      gkl.addMouseListener(KeyEvent.VK_I, popupInformation);
      popupZoomWindow = new PopupPanel(zoomWindow.canvas);

      layeredPane = new JLayeredPane();
      frame.add(layeredPane);
      // layeredPane.setLayout(null);
      layeredPane.add(menu);
      layeredPane.add(player.graph.canvas);
      layeredPane.add(informationPanel.scrollPanel);
      layeredPane.add(zoomWindow.canvas);
      layeredPane.add(popupInformation);
      layeredPane.add(popupZoomWindow);
      frame.add(controls.panel);

      layeredPane.setComponentZOrder(menu, 0);
      layeredPane.setComponentZOrder(player.graph.canvas, 1);
      layeredPane.setComponentZOrder(informationPanel.scrollPanel, 0);
      layeredPane.setComponentZOrder(zoomWindow.canvas, 0);
      layeredPane.setComponentZOrder(popupInformation, 0);
      layeredPane.setComponentZOrder(popupZoomWindow, 0);

      informationPanel.scrollPanel.setVisible(false);
      zoomWindow.canvas.setVisible(false);

      KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
      manager.addKeyEventDispatcher(gkl);

      frame.addWindowListener(
          new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
              saveApp();
            }
          });
      frame.addComponentListener(
          new ComponentAdapter() {
            public void componentResized(ComponentEvent e) {
              refreshLayout();
            }
          });

      frame.setSize(CONST.windowWidth, CONST.windowHeight);
      frame.setVisible(true);
      int dw = frame.getWidth() - frame.getContentPane().getWidth();
      int dh = frame.getHeight() - frame.getContentPane().getHeight();
      System.out.println("frame " + dw + " " + dh);
      frame.setMinimumSize(new Dimension(CONST.minWindowWidth + dw, CONST.minWindowHeight + dh));
      gRepaint();
    }
 /** Register us as KeyEventDispatcher and property "managingFocus" listeners. */
 private void addTraversingOutListeners(KeyboardFocusManager kfm) {
   kfm.addKeyEventDispatcher(this);
   kfm.addPropertyChangeListener("managingFocus", this);
 }
Exemple #9
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));

    // CommandManager handles (keyboard) input and dispatches events to the
    // drone
    System.out.println("CCPanel.KeyEventDispatcher: grab the whole keyboard input from now on ...");
    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;
          }
        });

    VideoManager vm = ardrone.getVideoManager();
    vm.setImageListener(this);
    NavDataManager m = ardrone.getNavDataManager();
    m.setStateListener(this);
    m.setAttitudeListener(this);
    m.setBatteryListener(this);
  }
 private void do_key() {
   KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
   manager.addKeyEventDispatcher(new MyDispatcher());
 }
Exemple #11
0
 /**
  * initialize the KeyEventDispatcher
  *
  * @param player the current player
  */
 public static void initializeKeyDispatchController(Player player) {
   // Sets it so that all keyboard events go to the CommandController
   KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
   keyEventDispatcher = new KeyCommandController(player);
   manager.addKeyEventDispatcher(keyEventDispatcher);
 }
Exemple #12
0
 private void setGlobalKeyboardHandler() {
   final KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
   manager.addKeyEventDispatcher(this);
 }