Exemplo n.º 1
0
  public static void requestFocus(Project project, final boolean useRobot) {
    JFrame frame = WindowManager.getInstance().getFrame(project);

    // the only reliable way I found to bring it to the top
    boolean aot = frame.isAlwaysOnTop();
    frame.setAlwaysOnTop(true);
    frame.setAlwaysOnTop(aot);

    int frameState = frame.getExtendedState();
    if ((frameState & Frame.ICONIFIED) == Frame.ICONIFIED) {
      // restore the frame if it is minimized
      frame.setExtendedState(frameState ^ Frame.ICONIFIED);
    }
    frame.toFront();
    frame.requestFocus();
    if (useRobot && runningOnWindows7()) {
      try {
        // remember the last location of mouse
        final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation();

        // simulate a mouse click on title bar of window
        Robot robot = new Robot();
        robot.mouseMove(frame.getX(), frame.getY());
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

        // move mouse to old location
        robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY());
      } catch (Exception ex) {
        // just ignore exception, or you can handle it as you want
      } finally {
        frame.setAlwaysOnTop(false);
      }
    }
  }
Exemplo n.º 2
0
  /*This method runs the actual playing part of the game. It goes in a loop while game is true and constantly paints the game,
  requests the focus, checks for collisions, and checks if anyone won with a small delay. If game is false, it leaves the loop and the game is done.*/
  public void game() // constantly runs update and paint world
      {
    // Loops while game is true
    while (game) {
      // Paints the game
      paintGame();

      // Requests the focus for listening to key events
      window.requestFocus();

      // Checks if any player has collided with anything
      checkCollision();

      // Checks if any player has won
      checkWin();

      // Sleeps for SPEED milliseconds
      try {
        Thread.sleep(SPEED);
      } // delay
      catch (InterruptedException e) {
      }

      // Checks if window closed. If so, game is false
      if (!isVisible()) {
        game = false;
      }
    }

    // Makes the mode 5 so that it still stays on the game screen after game is done
    mode = 5;

    // Paints the game once more
    paintGame();
  }
Exemplo n.º 3
0
  /**
   * Responsible for creating a {@link GemIdentView.ScrollablePicture ScrollablePicture} object for
   * a given result matrix. If there's not enough RAM it will display exactly how much RAM is needed
   * for the operation.
   *
   * @param name the name of the result matrix
   * @param time the time when the "display" function was invoked by the user
   * @param I the result matrix as a buffered image
   * @param dir the directory where the image is located (if saved somewhere, otherwise null)
   * @param displayImageOnScreen should we pop a JFrame and show it on the screen?
   * @return the {@link GemIdentView.ScrollablePicture ScrollablePicture} object embodying B
   */
  public static ScrollablePicture GenerateScrollablePicElement(
      String name,
      Long time,
      BufferedImage I,
      String dir,
      ConsoleParser consoleParser,
      boolean displayImageOnScreen) {
    ScrollablePicture pic = null;
    try {
      pic = new ScrollablePicture(new ImageIcon(I), 10);
    } catch (Throwable t) {
      long mem = (long) I.getWidth() * (long) I.getHeight();
      double gigs = mem / Math.pow(10, 9);
      NumberFormat format = NumberFormat.getInstance();
      format.setMaximumFractionDigits(2);
      if (consoleParser != null) {
        if (gigs > 1)
          consoleParser.WriteToScreen(
              "out of memory - need " + format.format(gigs) + "G", null, Console.error);
        else {
          double megs = mem / Math.pow(10, 6);
          consoleParser.WriteToScreen(
              "out of memory - need " + format.format(megs) + "M", null, Console.error);
        }
      }
    }

    // display image on screen?
    if (displayImageOnScreen && name != null) {
      JScrollPane view = new JScrollPane(pic);
      view.repaint();
      JFrame frame = new JFrame();
      frame.setSize(KFrame.frameSize);
      frame.add(view);
      frame.setTitle("image \"" + name + "\"");
      frame.setVisible(true);
      frame.setResizable(true);
      frame.repaint();
      frame.requestFocus();
    }
    // did you supply a console parser and a timestamp to display a confirmation?
    if (consoleParser != null && time != null) {
      consoleParser.WriteToScreen(
          "Display completed in " + Run.TimeElapsed(time), null, Console.time);
    }
    // did you supply a directory where the image was saved to?
    if (dir != null && consoleParser != null)
      consoleParser.WriteToScreen("Image located at: " + dir, null, Console.neutral);

    return pic;
  }
Exemplo n.º 4
0
  @Override
  public void run() {

    ventanaPrincipal.setEnabled(false);
    VentanaEspera ventanaEspera = new VentanaEspera(ventanaPrincipal);
    ventanaEspera.setVisible(true);
    uti.subirNuevoExcel(servi);
    ventanaEspera.dispose();
    JOptionPane.showMessageDialog(
        ventanaPrincipal,
        "Servicio guardado correctamente",
        "Servicio",
        JOptionPane.INFORMATION_MESSAGE);
    ventanaPrincipal.setEnabled(true);
    ventanaPrincipal.requestFocus();
  }
Exemplo n.º 5
0
  /** PopUp zur Abfrage der IP-Adresse */
  public static void popUp() {
    ipframe = new JFrame();
    ipframe.setResizable(false);
    ipframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    ipframe.setSize(300, 300);
    ipframe.setVisible(true);
    ipframe.getWindowFocusListeners();

    jpanel = new JPanel();
    jpanel2 = new JPanel();

    ipframe.add(jpanel);

    JLabel label1 = new JLabel("Bitte geben Sie die IP des Servers ein:");
    jpanel.add(label1, BorderLayout.BEFORE_FIRST_LINE);
    label1.setFont(new Font("Arial", Font.PLAIN, 20));
    label1.setBackground(new Color(0, 153, 255));

    jpanel2.add(ip1);
    jpanel2.add(ip2);
    jpanel2.add(ip3);
    jpanel2.add(ip4);
    jpanel.add(jpanel2, BorderLayout.AFTER_LAST_LINE);

    JButton connect = new JButton("Verbinden");
    connect.addActionListener(action);
    jpanel.add(connect, BorderLayout.PAGE_END);

    ipframe.enableInputMethods(true);

    ipframe.toFront();
    ipframe.requestFocus();

    ipframe.setLocation(300, 300);
    ipframe.pack();
  }
Exemplo n.º 6
0
  /**
   * Displays a users profile.
   *
   * @param jid the jid of the user.
   * @param vcard the users vcard.
   * @param parent the parent component, used for location handling.
   */
  public void displayProfile(final String jid, VCard vcard, JComponent parent) {
    VCardViewer viewer = new VCardViewer(jid);

    final JFrame dlg = new JFrame(Res.getString("title.view.profile.for", jid));

    avatarLabel = new JLabel();
    avatarLabel.setHorizontalAlignment(JButton.RIGHT);
    avatarLabel.setBorder(BorderFactory.createBevelBorder(0, Color.white, Color.lightGray));

    // The user should only be able to close this dialog.
    Object[] options = {Res.getString("button.view.profile"), Res.getString("close")};
    final JOptionPane pane =
        new JOptionPane(
            viewer,
            JOptionPane.PLAIN_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION,
            null,
            options,
            options[0]);

    //  mainPanel.add(pane, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
    // GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0));

    dlg.setIconImage(SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_16x16).getImage());

    dlg.pack();
    dlg.setSize(350, 250);
    dlg.setResizable(true);
    dlg.setContentPane(pane);
    dlg.setLocationRelativeTo(parent);

    PropertyChangeListener changeListener =
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent e) {
            if (pane.getValue() instanceof Integer) {
              pane.removePropertyChangeListener(this);
              dlg.dispose();
              return;
            }
            String value = (String) pane.getValue();
            if (Res.getString("close").equals(value)) {
              pane.removePropertyChangeListener(this);
              dlg.dispose();
            } else if (Res.getString("button.view.profile").equals(value)) {
              pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
              SparkManager.getVCardManager().viewFullProfile(jid, pane);
            }
          }
        };

    pane.addPropertyChangeListener(changeListener);

    dlg.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE) {
              dlg.dispose();
            }
          }
        });

    dlg.setVisible(true);
    dlg.toFront();
    dlg.requestFocus();
  }
Exemplo n.º 7
0
 private void KeyUpdate() {
   Frame.requestFocus();
   KH.Update();
   if (KH.Keys[1]) Stop();
   if (KH.Keys[0]) return;
 }
  /**
   * Calling this method will execute the interaction with the given id.
   *
   * @param interactionID The id that specifies the interaction
   * @throws UnknownInteractionException Thrown if interactionID is an unknown id.
   */
  public void interaction(String interactionID) throws UnknownInteractionException {
    // boolean displayAnswer;
    boolean guiBuilded;
    String groupID;
    GroupInfo group;
    Dimension theSize;
    int i;

    if (DEBUG)
      System.out.println("\ninteraction was called\n\tinteractionID=\"" + interactionID + "\"");

    if (!allInteractions.containsKey(interactionID))
      throw (new UnknownInteractionException(
          "Interaction \"" + interactionID + "\" does not exist"));

    if (allInteractions.get(interactionID) instanceof Question) {
      Question aQuestion = (Question) allInteractions.get(interactionID);

      aQuestion.addSubmitListener(this);

      // get group id
      groupID = aQuestion.getGroupID();
      // lookup group infos
      group = (GroupInfo) groupInfos.get(groupID);
      if ((groupID != "") && (group != null)) {
        // if amount of correct questions of group
        // already reached we dont have to
        // continue with this interaction
        if ((group.processed >= group.repeats) && (group.processed != 0) && (group.repeats != 0)) {
          if (DEBUG)
            System.out.println("\t\tNecessary amount of questions of group " + "answered correct.");

          return;
        }
      }

      guiBuilded = aQuestion.getGuiBuilded();
      if (guiBuilded) aQuestion.rebuildQuestion();
      else aQuestion.makeGUI();

      aQuestion.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

      JDialog jdialog = getJDialog(aQuestion.getTitle());
      // theFrame = new JFrame(aQuestion.getTitle());

      aQuestion.setJDialog(jdialog);

      for (i = 0; i < windowListeners.size(); i++)
        jdialog.addWindowListener((WindowListener) (windowListeners.elementAt(i)));

      jdialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
      jdialog.setBackground(new Color(192, 192, 192));
      jdialog.getContentPane().add(aQuestion, BorderLayout.CENTER);
      jdialog.pack();
      theSize = jdialog.getSize();
      jdialog.setSize(350, theSize.height);
      // jdialog.pack();
      jdialog.setLocationRelativeTo(null);
      jdialog.setVisible(true);
      jdialog.requestFocus();
      // theFrame.show();

      // Processing of the interaction will be handled by
      // the event loop.
    } else if (allInteractions.get(interactionID) instanceof Documentation) {
      Documentation doc = (Documentation) allInteractions.get(interactionID);
      doc.makeGUI();
      doc.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

      JFrame theFrame = new JFrame("Documentation");

      theFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

      theFrame.getContentPane().add(doc, BorderLayout.CENTER);

      for (i = 0; i < windowListeners.size(); i++)
        theFrame.addWindowListener((WindowListener) (windowListeners.elementAt(i)));

      theFrame.setSize(400, 500);
      // theFrame.pack();
      theFrame.setLocationRelativeTo(null);
      theFrame.setVisible(true);
      theFrame.requestFocus();
      // theFrame.show();

      // no need to handle anything by the event loop.
    }
    return;
  }
Exemplo n.º 9
0
  // ds enable display
  public void launch()
      throws CZEPGUIException, HeadlessException, SQLException, CZEPMySQLManagerException {
    System.out.println(
        "[" + CLogger.getStamp() + "]<CGUI>(launch) Loading initial application setup");

    // ds allocate a dialog object to display independently
    final JDialog cDialogLoading = new JDialog(m_cFrame, "ZEP: Zero-Effort Procrastination", false);

    // ds set the option panel without any options
    cDialogLoading.setContentPane(
        new JOptionPane(
            "Loading image data please wait",
            JOptionPane.INFORMATION_MESSAGE,
            JOptionPane.DEFAULT_OPTION,
            null,
            new Object[] {},
            null));

    // ds display the dialog
    cDialogLoading.pack();
    cDialogLoading.setVisible(true);
    cDialogLoading.setLocationRelativeTo(null);

    try {
      // ds fetch initial datapool
      m_cLearner.fetchInitialDataPool();

      // ds try to get the image for first display
      _displayInitialImage(m_cLearner.getFirstDataPoint());
    } catch (Exception e) {
      // ds info
      System.out.println(
          "["
              + CLogger.getStamp()
              + "]<CGUI>(launch) Exception: "
              + e.getMessage()
              + " - could not fetch database");

      // ds dispose loading screen
      cDialogLoading.removeAll();
      cDialogLoading.dispose();

      // ds rethrow
      throw new CZEPGUIException("GUI aborted");
    }

    // ds dispose loading screen
    cDialogLoading.removeAll();
    cDialogLoading.dispose();

    // ds register key listener
    m_cFrame.addKeyListener(this);

    // ds display frame for interaction
    m_cFrame.setVisible(true);
    m_cFrame.setLocationRelativeTo(null);

    // ds request focus for key strokes
    m_cFrame.requestFocus();

    // ds initialize with empty string
    String strUsername = "";

    // ds as long as it is not set
    while (strUsername.isEmpty()) {
      // ds show dialog to enter name
      strUsername =
          JOptionPane.showInputDialog(
              m_cFrame,
              "Please enter your desired username: "******"ZEP: Zero-Effort Procrastination",
              JOptionPane.PLAIN_MESSAGE);

      // ds check if null (cancelled by user)
      if (null == strUsername) {
        // ds escape
        throw new CZEPGUIException("cancelled username setting dialog");
      }

      // ds check if already taken
      if (!strUsername.isEmpty() && !m_cMySQLManager.isUserAvailable(strUsername)) {
        // ds inform
        JOptionPane.showMessageDialog(m_cFrame, "Username already taken - please try again");

        // ds keep looping
        strUsername = "";
      }
    }

    // ds username is fine to set
    m_cLearner.setUsername(strUsername);

    // ds set user active
    m_cMySQLManager.setActiveUser(strUsername);

    // ds and log
    System.out.println(
        "[" + CLogger.getStamp() + "]<CGUI>(launch) Login of: [" + strUsername + "] successful");

    // ds log successful launch
    _logMaster("<CGUI>(launch) launched GUI application");

    // ds request focus for key strokes
    m_cFrame.requestFocus();
  }
Exemplo n.º 10
0
  public static void main(String[] args) {
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "What's Wrong ...");
    changeUI(USE_SYSTEM_UI);

    final NLPCanvas canvas = new NLPCanvas();

    // create the filter pipeline
    EdgeTokenFilter edgeTokenFilter = new EdgeTokenFilter();
    EdgeLabelFilter edgeLabelFilter = new EdgeLabelFilter();
    TokenFilter tokenFilter = new TokenFilter();
    EdgeTypeFilter edgeTypeFilter = new EdgeTypeFilter();
    FilterPipeline filterPipeline =
        new FilterPipeline(tokenFilter, edgeTypeFilter, edgeLabelFilter, edgeTokenFilter);

    // set filter of canvas to be the pipeline
    canvas.setFilter(filterPipeline);

    int canvasWidth = 900;
    int canvasHeight = 300;
    int canvasX = 50;
    int canvasY = 50;
    int canvasBottom = canvasHeight + canvasY;

    final CorpusLoader gold = new CorpusLoader("Select Gold");
    final CorpusLoader guess = new CorpusLoader("Select Guess");
    gold.loadProperties(properties);
    guess.loadProperties(properties);

    // Menu
    JMenuBar menuBar = new JMenuBar();
    JMenu file = new JMenu("File");
    JMenuItem exportEps = new JMenuItem("Export EPS");
    final JFileChooser fc = new JFileChooser();
    exportEps.setAccelerator(KeyStroke.getKeyStroke('E', java.awt.event.InputEvent.ALT_MASK));
    exportEps.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int returnVal = fc.showSaveDialog(canvas);
            if (returnVal == JFileChooser.APPROVE_OPTION)
              try {
                canvas.exportToEPS(fc.getSelectedFile());
              } catch (IOException e1) {
                e1.printStackTrace();
              }
          }
        });
    file.add(exportEps);
    file.setMnemonic('F');

    JMenuItem quit = new JMenuItem("Quit");
    // quit.setMnemonic('Q');
    file.add(quit);
    quit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            System.exit(0);
          }
        });

    JMenu window = new JMenu("Window");

    menuBar.add(file);
    menuBar.add(window);

    // Toolbar
    JToolBar toolBar = new JToolBar("Blub");
    toolBar.add(new JButton("Test"));

    // dummy Frame
    // JFrame dummy = new JFrame();
    // dummy.setVisible(false);

    // canvas frame
    JFrame canvasFrame = new JFrame("What's Wrong With My NLP?");
    canvasFrame.setSize(canvasWidth, canvasHeight);
    canvasFrame.getContentPane().setLayout(new BorderLayout());
    canvasFrame.getContentPane().add(new JScrollPane(canvas), BorderLayout.CENTER);
    canvasFrame.setJMenuBar(menuBar);
    // canvasFrame.getContentPane().add(toolBar, BorderLayout.NORTH);
    canvasFrame.setLocation(canvasX, canvasY);
    canvasFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    // window.add(new WindowMenuItem(canvasFrame,"Canvas"));
    // desktop.add(canvasFrame);

    // file selection frame
    final ControllerDialog fileWindow = new ControllerDialog("File Selection", USE_SYSTEM_UI);
    fileWindow
        .getContentPane()
        .setLayout(new BoxLayout(fileWindow.getContentPane(), BoxLayout.Y_AXIS));
    fileWindow.getContentPane().add(gold);
    fileWindow.getContentPane().add(new JSeparator());
    fileWindow.getContentPane().add(guess);
    fileWindow.setLocation(canvasX + 20, canvasBottom + 20);
    fileWindow.pack();
    fileWindow.setVisible(USE_SYSTEM_UI);
    // fileWindow.toBack();
    window.add(new WindowMenuItem(fileWindow));
    // fileFrame.setResizable(false);
    // desktop.add(fileFrame);

    // filter frame
    ControllerDialog filterWindow = new ControllerDialog("Edge Filters", false);
    filterWindow
        .getContentPane()
        .setLayout(new BoxLayout(filterWindow.getContentPane(), BoxLayout.Y_AXIS));
    filterWindow.getContentPane().add(new EdgeTypeFilterPanel(canvas, edgeTypeFilter));
    filterWindow.getContentPane().add(new JSeparator());
    filterWindow
        .getContentPane()
        .add(new DependencyFilterPanel(canvas, edgeLabelFilter, edgeTokenFilter));
    filterWindow.pack();
    filterWindow.setLocation(canvasX + 250, canvasBottom + 15);
    filterWindow.setVisible(USE_SYSTEM_UI);
    window.add(new WindowMenuItem(filterWindow));

    // token filter frame
    ControllerDialog tokenFilterWindow = new ControllerDialog("Token Filters", false);
    tokenFilterWindow
        .getContentPane()
        .setLayout(new BoxLayout(tokenFilterWindow.getContentPane(), BoxLayout.Y_AXIS));
    tokenFilterWindow.getContentPane().add(new TokenFilterPanel(canvas, tokenFilter));
    tokenFilterWindow.pack();
    tokenFilterWindow.setLocation(canvasX + 360, canvasBottom + 230);
    tokenFilterWindow.setVisible(USE_SYSTEM_UI);
    window.add(new WindowMenuItem(tokenFilterWindow));

    // appearance
    ControllerDialog appearance = new ControllerDialog("Appearance", false);
    appearance
        .getContentPane()
        .setLayout(new BoxLayout(appearance.getContentPane(), BoxLayout.Y_AXIS));
    appearance.getContentPane().add(new AppearancePanel(canvas));
    appearance.pack();
    appearance.setLocation(canvasX + 500, canvasBottom + 25);
    appearance.setVisible(USE_SYSTEM_UI);
    window.add(new WindowMenuItem(appearance));

    // description
    ControllerDialog description = new ControllerDialog("Description", true);
    // description.getContentPane().setLayout(new BoxLayout(appearance.getContentPane(),
    // BoxLayout.Y_AXIS));
    JTextArea text = new JTextArea(15, 40);
    description.getContentPane().add(new JScrollPane(text));
    description.pack();
    description.setLocation(canvasX + 700, canvasBottom + 25);
    description.setVisible(USE_SYSTEM_UI);
    canvas.setTextArea(text);
    window.add(new WindowMenuItem(description));

    // navigator
    ControllerDialog navigatorWindow = new ControllerDialog("Search Corpus", USE_SYSTEM_UI);
    navigatorWindow
        .getContentPane()
        .setLayout(new BoxLayout(navigatorWindow.getContentPane(), BoxLayout.Y_AXIS));
    CorpusNavigator navigator = new CorpusNavigator(canvas, gold, guess, edgeTypeFilter);
    navigatorWindow.getContentPane().add(navigator);
    navigatorWindow.pack();
    navigatorWindow.setMinimumSize(navigatorWindow.getSize());
    navigatorWindow.setLocation(canvasX + 800, canvasBottom + 20);
    navigatorWindow.setVisible(USE_SYSTEM_UI);
    window.add(new WindowMenuItem(navigatorWindow, "Navigator"));

    // statusbar
    JPanel statusBar = new JPanel();
    JLabel status = new JLabel("What's Wrong With My NLP version " + VERSION);
    status.setForeground(Color.LIGHT_GRAY);
    statusBar.setLayout(new GridBagLayout());
    statusBar.setBorder(BorderFactory.createEmptyBorder(1, 10, 1, 10));
    statusBar.add(status);
    statusBar.add(navigator.getSpinnerPanel(), new SimpleGridBagConstraints(0, USE_SYSTEM_UI));
    statusBar.add(
        navigator.getSpinnerPanel(), new SimpleGridBagConstraints(1, 0, 1.0, 0.0, EAST, NONE));

    // final preparation of canvas
    canvasFrame.getContentPane().add(statusBar, BorderLayout.SOUTH);
    canvasFrame.setVisible(USE_SYSTEM_UI);
    canvasFrame.requestFocus();
    // canvasFrame.requestFocusInWindow();

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread(
                new Runnable() {
                  public void run() {
                    gold.saveProperties(properties);
                    guess.saveProperties(properties);
                    try {
                      properties.store(
                          new FileOutputStream(System.getProperty("user.home") + "/.whatswrong"),
                          "Whats wrong with you NLP properties");
                    } catch (IOException e) {
                      e.printStackTrace();
                    }
                  }
                }));
  }