@Test
 public void should_Ignore_Children_Of_Shared_Invisible_Frame() {
   JDialog dialog = dialog().createNew();
   addToImplicitlyIgnoredMap(dialog);
   ignore(filter, dialog.getOwner());
   assertThat(allIgnored()).containsOnly(dialog);
   assertThatNoComponentsAreImplicitlyIgnored();
 }
  /**
   * @return <code>true</code> if and only if the <code>component</code> represents modal context.
   * @throws IllegalArgumentException if <code>component</code> is <code>null</code>.
   */
  public static boolean isModalContext(@NotNull Component component) {
    Window window;
    if (component instanceof Window) {
      window = (Window) component;
    } else {
      window = SwingUtilities.getWindowAncestor(component);
    }

    if (window instanceof IdeFrameImpl) {
      final Component pane = ((IdeFrameImpl) window).getGlassPane();
      if (pane instanceof IdeGlassPaneEx) {
        return ((IdeGlassPaneEx) pane).isInModalContext();
      }
    }

    if (window instanceof JDialog) {
      final JDialog dialog = (JDialog) window;
      if (!dialog.isModal()) {
        final Window owner = dialog.getOwner();
        return owner != null && isModalContext(owner);
      }
    }

    if (window instanceof JFrame) {
      return false;
    }

    boolean isMainFrame = window instanceof IdeFrameImpl;
    boolean isFloatingDecorator = window instanceof FloatingDecorator;

    boolean isPopup = !(component instanceof JFrame) && !(component instanceof JDialog);
    if (isPopup) {
      if (component instanceof JWindow) {
        JBPopup popup =
            (JBPopup) ((JWindow) component).getRootPane().getClientProperty(JBPopup.KEY);
        if (popup != null) {
          return popup.isModalContext();
        }
      }
    }

    return !isMainFrame && !isFloatingDecorator;
  }
Esempio n. 3
0
  public void actionPerformed(ActionEvent ae) {
    JDialog saveDialog = new JDialog(MainFrame.getInstance(), "Save Termbank as CSV", true);
    MainFrame.getGuiRoots().add(saveDialog);
    saveDialog.setLayout(new BorderLayout());
    SliderPanel sliderPanel = new SliderPanel(termbank, "save", true, null);
    saveDialog.add(sliderPanel, BorderLayout.CENTER);

    JPanel chooserPanel = new JPanel();
    chooserPanel.setLayout(new BoxLayout(chooserPanel, BoxLayout.Y_AXIS));
    chooserPanel.add(new JSeparator());

    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter filter =
        new FileNameExtensionFilter("CSV files", Utilities.EXTENSION_CSV);
    chooser.setFileFilter(filter);
    chooser.setApproveButtonText("Save");
    chooser.addActionListener(
        new CsvFileSelectionActionListener(chooser, termbank, sliderPanel, saveDialog, Mode.SAVE));
    chooserPanel.add(chooser);
    saveDialog.add(chooserPanel, BorderLayout.SOUTH);
    saveDialog.pack();
    saveDialog.setLocationRelativeTo(saveDialog.getOwner());
    saveDialog.setVisible(true);
  }
Esempio n. 4
0
  /**
   * Method for displaying the TaskFrame to the user. Creates the frame when first run, and fills it
   * with the information about the specified {@link task}.
   *
   * @param parent The parent of the taskFrame so that it can load in the correct position.
   * @param task The {@link task} that needs to be displayed to the user.
   */
  public void showDialog(Component parent, Task task) {
    Frame owner;

    if (parent instanceof Frame) {
      owner = (Frame) parent;
    } else {
      owner = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
    }

    // if dialog showed for the first time, create the dialog, adding the
    // TaskFrame as part of it.
    if (dialog == null || dialog.getOwner() != owner) {
      dialog = new JDialog(owner, true);
      dialog.add(this);
      dialog.getRootPane().setDefaultButton(closeButton);
      dialog.pack();
      dialog.setResizable(false);
    }

    this.task = task;
    taskElementsTable.setModel(new TaskElementTableModel(task));

    taskTopPanel.getStartDate().setText(task.getStartDate().toString());
    taskTopPanel.getEndDate().setText(task.getEndDate().toString());
    taskTopPanel.getStatus().setText(task.getStatus().toString());

    if (task.getStatus() != TaskStatus.ALLOCATED) {
      completeButton.setEnabled(false);
    } else {
      completeButton.setEnabled(true);
    }

    dialog.setLocationRelativeTo(parent);
    dialog.setTitle("Tasker - " + task.getTitle());
    dialog.setVisible(true);
  }
Esempio n. 5
0
        @Override
        public void actionPerformed(ActionEvent evt) {
          final JDialog authPanel =
              new JDialog(getWindow(SubtitlePanel.this), ModalityType.APPLICATION_MODAL);
          authPanel.setTitle("Login");
          authPanel.setLocation(getOffsetLocation(authPanel.getOwner()));

          JPanel osdbGroup = new JPanel(new MigLayout("fill, insets panel"));
          osdbGroup.setBorder(new TitledBorder("OpenSubtitles"));
          osdbGroup.add(new JLabel("Username:"******"gap rel");
          final JTextField osdbUser = new JTextField(12);
          osdbGroup.add(osdbUser, "growx, wrap rel");

          osdbGroup.add(new JLabel("Password:"******"gap rel");
          final JPasswordField osdbPass = new JPasswordField(12);
          osdbGroup.add(osdbPass, "growx, wrap unrel");

          // restore values
          String[] osdbAuth = WebServices.getLogin(WebServices.LOGIN_OPENSUBTITLES);
          osdbUser.setText(osdbAuth[0]);
          // osdbPass.setText(osdbAuth[1]); // password is stored as MD5 hash so we can't restore it

          if (osdbUser.getText().isEmpty()) {
            osdbGroup.add(
                new LinkButton(
                    "Register Account",
                    "Register to increase your download quota",
                    WebServices.OpenSubtitles.getIcon(),
                    URI.create("http://www.opensubtitles.org/en/newuser")),
                "spanx 2, tag left");
          } else {
            osdbGroup.add(
                new LinkButton(
                    "Upgrade Account",
                    "Upgrade to increase your download quota",
                    WebServices.OpenSubtitles.getIcon(),
                    URI.create("http://www.opensubtitles.org/en/support")),
                "spanx 2, tag left");
          }

          JRootPane container = authPanel.getRootPane();
          container.setLayout(new MigLayout("fill, insets dialog"));
          container.removeAll();

          container.add(osdbGroup, "growx, wrap");

          Action ok =
              new AbstractAction("OK", ResourceManager.getIcon("dialog.continue")) {

                @Override
                public void actionPerformed(ActionEvent evt) {
                  authPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                  boolean approved = true;

                  try {
                    if (osdbUser.getText().length() > 0 && osdbPass.getPassword().length > 0) {
                      final OpenSubtitlesClient osdb =
                          new OpenSubtitlesClient(getApplicationName(), getApplicationVersion());
                      osdb.setUser(osdbUser.getText(), md5(new String(osdbPass.getPassword())));
                      osdb.login();

                      // do some status checks in background (since OpenSubtitles can be really
                      // really slow)
                      WebServices.requestThreadPool.submit(
                          () -> {
                            try {
                              // check download quota for the current user
                              Map<?, ?> limits =
                                  (Map<?, ?>) osdb.getServerInfo().get("download_limits");
                              log.log(
                                  Level.INFO,
                                  String.format(
                                      "Your daily download quota is at %s of %s.",
                                      limits.get("client_24h_download_count"),
                                      limits.get("client_24h_download_limit")));

                              // logout from test session
                              osdb.logout();
                            } catch (Exception e) {
                              debug.warning(e.getMessage());
                            }
                          });
                    } else if (osdbUser.getText().isEmpty()) {
                      WebServices.setLogin(
                          WebServices.LOGIN_OPENSUBTITLES, null, null); // delete login details
                    }
                  } catch (Exception e) {
                    log.log(Level.WARNING, "OpenSubtitles: " + e.getMessage());
                    approved = false;
                  }

                  authPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                  if (approved) {
                    WebServices.setLogin(
                        WebServices.LOGIN_OPENSUBTITLES,
                        osdbUser.getText(),
                        new String(osdbPass.getPassword()));
                    authPanel.setVisible(false);
                  }
                }
              };
          Action cancel =
              new AbstractAction("Cancel", ResourceManager.getIcon("dialog.cancel")) {

                @Override
                public void actionPerformed(ActionEvent evt) {
                  authPanel.setVisible(false);
                }
              };
          container.add(new JButton(cancel), "tag cancel, split 2");
          container.add(new JButton(ok), "tag ok");

          authPanel.pack();
          authPanel.setVisible(true);
        }
  void invoke(Page page) {

    pageCheckBox.page = page;
    page.deselect();
    createContentPane();

    if (needNewDialog(dialog, page)) {
      String s = Modeler.getInternationalText("CustomizeCheckBoxDialogTitle");
      dialog = ModelerUtilities.getChildDialog(page, s != null ? s : "Customize check box", true);
      dialog.setContentPane(contentPane);
      dialog.pack();
      dialog.setLocationRelativeTo(dialog.getOwner());
      dialog.addWindowListener(
          new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
              cancel = true;
              dialog.setVisible(false);
            }

            public void windowActivated(WindowEvent e) {
              nameField.selectAll();
              nameField.requestFocusInWindow();
            }
          });
    }

    modelComboBox.removeItemListener(modelSelectionListener);
    modelComboBox.removeAllItems();
    actionComboBox.removeItemListener(actionSelectionListener);

    // add legacy MD models to the model list
    final ComponentPool componentPool = page.getComponentPool();
    synchronized (componentPool) {
      for (ModelCanvas mc : componentPool.getModels()) {
        if (mc.isUsed()) {
          modelComboBox.addItem(mc.getMdContainer().getModel());
        }
      }
    }

    // add target models to the model list
    for (Class c : ModelCommunicator.targetClass) {
      Map map = page.getEmbeddedComponent(c);
      if (map != null && !map.isEmpty()) {
        for (Object o : map.keySet()) {
          modelComboBox.addItem(map.get(o));
        }
      }
    }

    if (pageCheckBox.isTargetClass()) {
      if (pageCheckBox.modelID != -1) {
        try {
          Object o =
              page.getEmbeddedComponent(
                  Class.forName(pageCheckBox.modelClass), pageCheckBox.modelID);
          if (o != null) modelComboBox.setSelectedItem(o);
        } catch (ClassNotFoundException e) {
          e.printStackTrace();
        }
      } else {
        BasicModel m = (BasicModel) modelComboBox.getSelectedItem();
        if (m instanceof Embeddable) pageCheckBox.setModelID(((Embeddable) m).getIndex());
      }
    } else {
      if (pageCheckBox.modelID != -1) {
        ModelCanvas mc = componentPool.get(pageCheckBox.modelID);
        modelComboBox.setSelectedItem(mc.getMdContainer().getModel());
      } else {
        BasicModel m = (BasicModel) modelComboBox.getSelectedItem();
        pageCheckBox.setModelID(componentPool.getIndex(m));
      }
    }
    modelComboBox.addItemListener(modelSelectionListener);

    fillActionComboBox();
    if (pageCheckBox.getAction() != null) actionComboBox.setSelectedItem(pageCheckBox.getAction());
    actionComboBox.addItemListener(actionSelectionListener);

    String t = pageCheckBox.getText();
    nameField.setText(
        t != null
            ? t
            : (actionComboBox.getSelectedItem() != null
                ? actionComboBox.getSelectedItem().toString()
                : null));
    uidField.setText(pageCheckBox.getUid());
    imageSelectedField.setText(pageCheckBox.getImageFileNameSelected());
    imageDeselectedField.setText(pageCheckBox.getImageFileNameDeselected());
    toolTipField.setText(pageCheckBox.getToolTipText());
    transparentCheckBox.setSelected(pageCheckBox.isTransparent());
    disabledAtRunCheckBox.setSelected(pageCheckBox.disabledAtRun);
    disabledAtScriptCheckBox.setSelected(pageCheckBox.disabledAtScript);
    bgComboBox.setColor(pageCheckBox.getBackground());
    autoSizeCheckBox.setSelected(pageCheckBox.autoSize);
    if (pageCheckBox.isPreferredSizeSet()) {
      widthField.setValue(pageCheckBox.getWidth());
      heightField.setValue(pageCheckBox.getHeight());
    }
    widthField.setEnabled(!pageCheckBox.autoSize);
    heightField.setEnabled(!pageCheckBox.autoSize);
    okButton.setEnabled(modelComboBox.getItemCount() > 0 && actionComboBox.getItemCount() > 0);

    setScriptArea();

    dialog.setVisible(true);
  }