Exemplo n.º 1
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;
 }
Exemplo n.º 2
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);
  }