예제 #1
0
 /** {@inheritDoc} */
 @Override
 public void popupYesNoCancel(
     JComponent sourceComponent,
     String title,
     String iconImageUrl,
     String message,
     IAction yesAction,
     IAction noAction,
     IAction cancelAction,
     Map<String, Object> context) {
   int selectedOption =
       JOptionPane.showConfirmDialog(
           SwingUtil.getWindowOrInternalFrame(sourceComponent),
           message,
           title,
           JOptionPane.YES_NO_CANCEL_OPTION,
           JOptionPane.QUESTION_MESSAGE,
           getIconFactory().getIcon(iconImageUrl, getIconFactory().getLargeIconSize()));
   IAction nextAction;
   if (selectedOption == JOptionPane.YES_OPTION) {
     nextAction = yesAction;
   } else if (selectedOption == JOptionPane.NO_OPTION) {
     nextAction = noAction;
   } else {
     nextAction = cancelAction;
   }
   if (nextAction != null) {
     execute(nextAction, context);
   }
 }
예제 #2
0
 /** {@inheritDoc} */
 @Override
 public boolean handleException(Throwable ex, Map<String, Object> context) {
   if (super.handleException(ex, context)) {
     return true;
   }
   String userFriendlyExceptionMessage = computeUserFriendlyExceptionMessage(ex);
   Component sourceComponent = null;
   if (userFriendlyExceptionMessage != null) {
     JOptionPane.showMessageDialog(
         null,
         HtmlHelper.toHtml(
             HtmlHelper.emphasis(HtmlHelper.escapeForHTML(userFriendlyExceptionMessage))),
         getTranslation("error", getLocale()),
         JOptionPane.ERROR_MESSAGE,
         getIconFactory().getErrorIcon(getIconFactory().getLargeIconSize()));
   } else {
     traceUnexpectedException(ex);
     JErrorDialog dialog = JErrorDialog.createInstance(null, this, getLocale());
     dialog.setMessageIcon(getIconFactory().getErrorIcon(getIconFactory().getMediumIconSize()));
     dialog.setTitle(getTranslation("error", getLocale()));
     dialog.setMessage(
         HtmlHelper.toHtml(
             HtmlHelper.emphasis(HtmlHelper.escapeForHTML(ex.getLocalizedMessage()))));
     dialog.setDetails(ex);
     int screenRes = Toolkit.getDefaultToolkit().getScreenResolution();
     dialog.pack();
     dialog.setSize(8 * screenRes, 3 * screenRes);
     SwingUtil.centerOnScreen(dialog);
     dialog.setVisible(true);
   }
   return true;
 }
예제 #3
0
 /** {@inheritDoc} */
 @Override
 public void popupInfo(
     JComponent sourceComponent, String title, String iconImageUrl, String message) {
   JOptionPane.showMessageDialog(
       SwingUtil.getWindowOrInternalFrame(sourceComponent),
       message,
       title,
       JOptionPane.INFORMATION_MESSAGE,
       getIconFactory().getIcon(iconImageUrl, getIconFactory().getLargeIconSize()));
 }
예제 #4
0
 /** {@inheritDoc} */
 @Override
 public boolean disposeModalDialog(JComponent sourceWidget, Map<String, Object> context) {
   if (super.disposeModalDialog(sourceWidget, context)) {
     Window actionWindow = SwingUtil.getVisibleWindow(sourceWidget);
     if (actionWindow instanceof JDialog) {
       actionWindow.dispose();
     }
     transferFocus(context);
     return true;
   }
   return false;
 }
예제 #5
0
  /** {@inheritDoc} */
  @Override
  public void displayDialog(
      JComponent mainView,
      List<Action> actions,
      String title,
      JComponent sourceComponent,
      Map<String, Object> context,
      Dimension dimension,
      boolean reuseCurrent,
      boolean modal) {
    displayModalDialog(mainView, context, reuseCurrent);
    final JDialog dialog;
    Window window = SwingUtil.getVisibleWindow(sourceComponent);
    boolean newDialog = true;
    if (window instanceof JDialog) {
      if (reuseCurrent) {
        dialog = (JDialog) window;
        dialog.getContentPane().removeAll();
        newDialog = false;
      } else {
        dialog = new JDialog((JDialog) window, title, modal);
      }
    } else {
      dialog = new JDialog((Frame) window, title, modal);
    }

    Box buttonBox = new Box(BoxLayout.LINE_AXIS);
    buttonBox.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));

    JButton defaultButton = null;
    for (Action action : actions) {
      JButton actionButton = new JButton();
      SwingUtil.configureButton(actionButton);
      actionButton.setAction(action);
      buttonBox.add(actionButton);
      buttonBox.add(Box.createHorizontalStrut(10));
      if (defaultButton == null) {
        defaultButton = actionButton;
      }
    }
    JPanel actionPanel = new JPanel();
    actionPanel.setLayout(new BorderLayout());
    actionPanel.add(buttonBox, BorderLayout.EAST);

    if (dimension != null) {
      mainView.setPreferredSize(
          new java.awt.Dimension(dimension.getWidth(), dimension.getHeight()));
    }
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(mainView, BorderLayout.CENTER);
    mainPanel.add(actionPanel, BorderLayout.SOUTH);
    dialog.getContentPane().add(mainPanel);
    dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    if (defaultButton != null) {
      dialog.getRootPane().setDefaultButton(defaultButton);
    }
    dialog.pack();
    if (newDialog) {
      SwingUtil.centerInParent(dialog);
    }
    dialog.setVisible(true);
  }