Beispiel #1
0
  /**
   * Adds default interactions to the specified component.
   *
   * @param comp component
   * @param win parent window
   */
  public static void addInteraction(final Component comp, final Window win) {
    comp.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseEntered(final MouseEvent e) {
            focus(comp);
          }
        });

    if (win instanceof BaseXDialog) {
      // add default keys
      final BaseXDialog d = (BaseXDialog) win;
      comp.addKeyListener(
          new KeyAdapter() {
            @Override
            public void keyPressed(final KeyEvent e) {
              final Object s = e.getSource();
              if (s instanceof BaseXCombo && ((BaseXCombo) s).isPopupVisible()) return;

              // do not key close dialog if button or editor is focused
              if (ENTER.is(e) && !(s instanceof BaseXButton || s instanceof TextPanel)) {
                d.close();
              } else if (ESCAPE.is(e)) {
                // do not cancel dialog if search bar is opened
                boolean close = true;
                if (s instanceof TextPanel) {
                  final SearchBar bar = ((TextPanel) s).getSearch();
                  close = bar == null || !bar.deactivate(true);
                }
                if (close) d.cancel();
              }
            }
          });
      return;
    }

    if (win instanceof GUI) {
      comp.addKeyListener(globalShortcuts((GUI) win));
    } else {
      throw Util.notExpected("Reference to main window expected.");
    }
  }
Beispiel #2
0
 /**
  * Returns the GUI reference of the specified container.
  *
  * @param cont input container
  * @return gui
  */
 private static GUI gui(final Component cont) {
   final Container c = cont.getParent();
   return c == null || c instanceof GUI ? (GUI) c : gui(c);
 }
Beispiel #3
0
 /**
  * Sets the help text for the specified component.
  *
  * @param cont input container
  */
 static void focus(final Component cont) {
   final GUI gui = gui(cont);
   if (gui == null) return;
   if (gui.gopts.get(GUIOptions.MOUSEFOCUS) && cont.isEnabled()) cont.requestFocusInWindow();
 }
Beispiel #4
0
 /**
  * Sets the scaled component height, adopting the original component width.
  *
  * @param comp component
  * @param h height
  */
 public static void setHeight(final Component comp, final int h) {
   comp.setPreferredSize(new Dimension(comp.getPreferredSize().width, (int) (h * scale)));
 }
Beispiel #5
0
 /**
  * Sets the scaled component width, adopting the original component height.
  *
  * @param comp component
  * @param w width
  */
 public static void setWidth(final Component comp, final int w) {
   comp.setPreferredSize(new Dimension((int) (w * scale), comp.getPreferredSize().height));
 }