public static InputEvent getInputEvent(String actionName) {
    final Shortcut[] shortcuts =
        KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionName);
    KeyStroke keyStroke = null;
    for (Shortcut each : shortcuts) {
      if (each instanceof KeyboardShortcut) {
        keyStroke = ((KeyboardShortcut) each).getFirstKeyStroke();
        if (keyStroke != null) break;
      }
    }

    if (keyStroke != null) {
      return new KeyEvent(
          JOptionPane.getRootFrame(),
          KeyEvent.KEY_PRESSED,
          System.currentTimeMillis(),
          keyStroke.getModifiers(),
          keyStroke.getKeyCode(),
          keyStroke.getKeyChar(),
          KeyEvent.KEY_LOCATION_STANDARD);
    } else {
      return new MouseEvent(
          JOptionPane.getRootFrame(),
          MouseEvent.MOUSE_PRESSED,
          0,
          0,
          0,
          0,
          1,
          false,
          MouseEvent.BUTTON1);
    }
  }
  private static boolean validateOldConfigDir(
      @Nullable File installationHome,
      @Nullable File oldConfigDir,
      @NotNull ConfigImportSettings settings) {
    if (oldConfigDir == null) {
      if (installationHome != null) {
        JOptionPane.showMessageDialog(
            JOptionPane.getRootFrame(),
            ApplicationBundle.message(
                "error.invalid.installation.home",
                installationHome.getAbsolutePath(),
                settings.getProductName(ThreeState.YES)));
      }
      return false;
    }

    if (!oldConfigDir.exists()) {
      JOptionPane.showMessageDialog(
          JOptionPane.getRootFrame(),
          ApplicationBundle.message("error.no.settings.path", oldConfigDir.getAbsolutePath()),
          ApplicationBundle.message("title.settings.import.failed"),
          JOptionPane.WARNING_MESSAGE);
      return false;
    }
    return true;
  }
예제 #3
0
파일: JSheet.java 프로젝트: karlvr/Quaqua
  /**
   * Brings up a sheet with a specified icon, where the initial choice is determined by the {@code
   * initialValue} parameter and the number of choices is determined by the {@code optionType}
   * parameter.
   *
   * <p>If {@code optionType} is {@code YES_NO_OPTION}, or {@code YES_NO_CANCEL_OPTION} and the
   * {@code options} parameter is {@code null}, then the options are supplied by the look and feel.
   *
   * <p>The {@code messageType} parameter is primarily used to supply a default icon from the look
   * and feel.
   *
   * @param parentComponent determines the {@code Frame} in which the dialog is displayed; if {@code
   *     null}, or if the {@code parentComponent} has no {@code Frame}, the sheet is displayed as a
   *     dialog.
   * @param message the {@code Object} to display
   * @param optionType an integer designating the options available on the dialog: {@code
   *     YES_NO_OPTION}, or {@code YES_NO_CANCEL_OPTION}
   * @param messageType an integer designating the kind of message this is, primarily used to
   *     determine the icon from the pluggable Look and Feel: {@code JOptionPane.ERROR_MESSAGE},
   *     {@code JOptionPane.INFORMATION_MESSAGE}, {@code JOptionPane.WARNING_MESSAGE}, {@code
   *     JOptionPane.QUESTION_MESSAGE}, or {@code JOptionPane.PLAIN_MESSAGE}
   * @param icon the icon to display in the dialog
   * @param options an array of objects indicating the possible choices the user can make; if the
   *     objects are components, they are rendered properly; non-{@code String} objects are rendered
   *     using their {@code toString} methods; if this parameter is {@code null}, the options are
   *     determined by the Look and Feel
   * @param initialValue the object that represents the default selection for the dialog; only
   *     meaningful if {@code options} is used; can be {@code null}
   * @param listener The listener for SheetEvents.
   */
  public static void showOptionSheet(
      Component parentComponent,
      Object message,
      int optionType,
      int messageType,
      Icon icon,
      Object[] options,
      Object initialValue,
      SheetListener listener) {

    JOptionPane pane =
        new JOptionPane(message, messageType, optionType, icon, options, initialValue);

    pane.setInitialValue(initialValue);
    pane.setComponentOrientation(
        ((parentComponent == null) ? JOptionPane.getRootFrame() : parentComponent)
            .getComponentOrientation());

    int style = styleFromMessageType(messageType);
    JSheet sheet = createSheet(pane, parentComponent, style);
    pane.selectInitialValue();
    sheet.addSheetListener(listener);
    sheet.show();
    sheet.toFront();
  }
예제 #4
0
 public void handleException(Exception ex) {
   // capture exception
   BrowserLauncherTestApp.updateDebugTextArea(ex, debugTextArea);
   // show message to user
   JOptionPane.showMessageDialog(
       JOptionPane.getRootFrame(), ex.getMessage(), "Error Message", JOptionPane.ERROR_MESSAGE);
 }
예제 #5
0
파일: JSheet.java 프로젝트: karlvr/Quaqua
  /**
   * Prompts the user for input in a sheet where the initial selection, possible selections, and all
   * other options can be specified. The user will able to choose from {@code selectionValues},
   * where {@code null} implies the user can input whatever they wish, usually by means of a {@code
   * JTextField}. {@code initialSelectionValue} is the initial value to prompt the user with. It is
   * up to the UI to decide how best to represent the {@code selectionValues}, but usually a {@code
   * JComboBox}, {@code JList}, or {@code JTextField} will be used.
   *
   * @param parentComponent the parent {@code Component} for the dialog
   * @param message the {@code Object} to display
   * @param messageType the type of message to be displayed: {@code JOptionPane.ERROR_MESSAGE},
   *     {@code JOptionPane.INFORMATION_MESSAGE}, {@code JOptionPane.WARNING_MESSAGE}, {@code
   *     JOptionPane.QUESTION_MESSAGE}, or {@code JOptionPane.PLAIN_MESSAGE}
   * @param icon the {@code Icon} image to display
   * @param selectionValues an array of {@code Object}s that gives the possible selections
   * @param initialSelectionValue the value used to initialize the input field
   * @param listener The listener for SheetEvents.
   */
  public static void showInputSheet(
      Component parentComponent,
      Object message,
      int messageType,
      Icon icon,
      Object[] selectionValues,
      Object initialSelectionValue,
      SheetListener listener) {

    JOptionPane pane =
        new JOptionPane(message, messageType, JOptionPane.OK_CANCEL_OPTION, icon, null, null);

    pane.setWantsInput(true);
    pane.setSelectionValues(selectionValues);
    pane.setInitialSelectionValue(initialSelectionValue);
    pane.setComponentOrientation(
        ((parentComponent == null) ? JOptionPane.getRootFrame() : parentComponent)
            .getComponentOrientation());

    int style = styleFromMessageType(messageType);
    JSheet sheet = createSheet(pane, parentComponent, style);

    pane.selectInitialValue();

    /*
    sheet.addWindowListener(new WindowAdapter() {
    public void windowClosed(WindowEvent evt) {
    sheet.dispose();
    }
    });*/
    sheet.addSheetListener(listener);
    sheet.show();
    sheet.toFront();
  }
예제 #6
0
파일: JSheet.java 프로젝트: karlvr/Quaqua
 /**
  * Returns the specified component's toplevel {@code Frame} or {@code Dialog}.
  *
  * @param parentComponent the {@code Component} to check for a {@code Frame} or {@code Dialog}
  * @return the {@code Frame} or {@code Dialog} that contains the component, or the default frame
  *     if the component is {@code null}, or does not have a valid {@code Frame} or {@code Dialog}
  *     parent
  */
 static Window getWindowForComponent(Component parentComponent) {
   if (parentComponent == null) {
     return JOptionPane.getRootFrame();
   }
   if (parentComponent instanceof Frame || parentComponent instanceof Dialog) {
     return (Window) parentComponent;
   }
   return getWindowForComponent(parentComponent.getParent());
 }
예제 #7
0
 private static void showError(final String title, final String message) {
   if (isHeadless()) {
     //noinspection UseOfSystemOutOrSystemErr
     System.out.println(message);
   } else {
     JOptionPane.showMessageDialog(
         JOptionPane.getRootFrame(), message, title, JOptionPane.ERROR_MESSAGE);
   }
 }
예제 #8
0
 public static Window getWindowForComponent(final Component parentComponent) {
   if (parentComponent == null) {
     return JOptionPane.getRootFrame();
   }
   if (parentComponent instanceof Frame || parentComponent instanceof java.awt.Dialog) {
     return (Window) parentComponent;
   }
   return SwingUtils.getWindowForComponent(parentComponent.getParent());
 }
예제 #9
0
 /**
  * Returns whether the given component is the default Swing hidden frame.
  *
  * @param c the component to check.
  * @return {@code true} if the given component is the default hidden frame, {@code false}
  *     otherwise.
  */
 public static boolean isSharedInvisibleFrame(@Nullable Component c) {
   if (c == null) {
     return false;
   }
   // Must perform an additional check, since applets may have their own version in their
   // AppContext
   return c instanceof Frame
       && (c == JOptionPane.getRootFrame()
           || c.getClass().getName().startsWith(ROOT_FRAME_CLASSNAME));
 }
예제 #10
0
  protected DialogWrapperPeerImpl(
      @NotNull DialogWrapper wrapper,
      @Nullable Project project,
      boolean canBeParent,
      @NotNull DialogWrapper.IdeModalityType ideModalityType) {
    myWrapper = wrapper;
    myTypeAheadCallback = myWrapper.isTypeAheadEnabled() ? new ActionCallback() : null;
    myWindowManager = null;
    Application application = ApplicationManager.getApplication();
    if (application != null && application.hasComponent(WindowManager.class)) {
      myWindowManager = (WindowManagerEx) WindowManager.getInstance();
    }

    Window window = null;
    if (myWindowManager != null) {

      if (project == null) {
        //noinspection deprecation
        project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext());
      }

      myProject = project;

      window = myWindowManager.suggestParentWindow(project);
      if (window == null) {
        Window focusedWindow = myWindowManager.getMostRecentFocusedWindow();
        if (focusedWindow instanceof IdeFrameImpl) {
          window = focusedWindow;
        }
      }
      if (window == null) {
        IdeFrame[] frames = myWindowManager.getAllProjectFrames();
        for (IdeFrame frame : frames) {
          if (frame instanceof IdeFrameImpl && ((IdeFrameImpl) frame).isActive()) {
            window = (IdeFrameImpl) frame;
            break;
          }
        }
      }
    }

    Window owner;
    if (window != null) {
      owner = window;
    } else {
      if (!isHeadless()) {
        owner = JOptionPane.getRootFrame();
      } else {
        owner = null;
      }
    }

    createDialog(owner, canBeParent, ideModalityType);
  }
예제 #11
0
  /**
   * @param parent parent component which is used to calculate heavy weight window ancestor. <code>
   *     parent</code> cannot be <code>null</code> and must be showing.
   */
  protected DialogWrapperPeerImpl(
      @NotNull DialogWrapper wrapper, @NotNull Component parent, boolean canBeParent) {
    myWrapper = wrapper;
    if (!parent.isShowing() && parent != JOptionPane.getRootFrame()) {
      throw new IllegalArgumentException("parent must be showing: " + parent);
    }
    myWindowManager = null;
    Application application = ApplicationManager.getApplication();
    if (application != null && application.hasComponent(WindowManager.class)) {
      myWindowManager = (WindowManagerEx) WindowManager.getInstance();
    }

    Window owner =
        parent instanceof Window
            ? (Window) parent
            : (Window) SwingUtilities.getAncestorOfClass(Window.class, parent);
    if (!(owner instanceof Dialog) && !(owner instanceof Frame)) {
      owner = JOptionPane.getRootFrame();
    }
    createDialog(owner, canBeParent);
  }
 private static void doImport(
     @NotNull File newConfigDir,
     @NotNull File oldConfigDir,
     ConfigImportSettings settings,
     File installationHome) {
   try {
     copy(oldConfigDir, newConfigDir, settings, installationHome);
   } catch (IOException e) {
     JOptionPane.showMessageDialog(
         JOptionPane.getRootFrame(),
         ApplicationBundle.message("error.unable.to.import.settings", e.getMessage()),
         ApplicationBundle.message("title.settings.import.failed"),
         JOptionPane.WARNING_MESSAGE);
   }
 }
예제 #13
0
  protected BaseDialog createDialog(Component parent, String title) {
    BaseDialog dialog;
    Window window =
        (parent == null ? JOptionPane.getRootFrame() : SwingUtilities.windowForComponent(parent));
    if (window instanceof Frame) {
      dialog = new BaseDialog((Frame) window, title, true);
    } else {
      dialog = new BaseDialog((Dialog) window, title, true);
    }
    dialog.setDialogMode(BaseDialog.OK_CANCEL_DIALOG);
    dialog.getBanner().setVisible(false);

    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add("Center", this);
    dialog.pack();
    dialog.setLocationRelativeTo(parent);

    return dialog;
  }
예제 #14
0
    @Override
    public void _setOkBadge(IdeFrame frame, boolean visible) {
      assertIsDispatchThread();

      if (getAppImage() == null) return;

      AppImage img = createAppImage();

      if (visible) {
        Icon okIcon = AllIcons.Mac.AppIconOk512;

        int x = img.myImg.getWidth() - okIcon.getIconWidth();
        int y = 0;

        okIcon.paintIcon(JOptionPane.getRootFrame(), img.myG2d, x, y);
      }

      setDockIcon(img.myImg);
    }