コード例 #1
0
  /** Shows the {@link OpenDialogForm}. */
  public final void show() {
    logger.debug("show", "show the open dialog"); // $NON-NLS-1$ //$NON-NLS-2$

    int x = this.parent.getBounds().x + (this.parent.getWidth() / 2) - (this.gui.getWidth() / 2);
    int y = this.parent.getBounds().y + (this.parent.getHeight() / 2) - (this.gui.getHeight() / 2);
    this.gui.setBounds(x, y, this.gui.getWidth(), this.gui.getHeight());
    this.gui.setVisible(true);
  }
コード例 #2
0
  /** Handles the open event. */
  public final void handleOpen() {
    logger.debug("handleOpen", "handle open"); // $NON-NLS-1$ //$NON-NLS-2$

    if (this.gui.jGTIFileChooser.getUI() instanceof BasicFileChooserUI) {
      BasicFileChooserUI ui = (BasicFileChooserUI) this.gui.jGTIFileChooser.getUI();
      ui.getApproveSelectionAction().actionPerformed(null);
    } else {
      throw new RuntimeException("ui is not a BasicFileChooserUI"); // $NON-NLS-1$
    }
    if ((getSelectedFile() != null) && !getSelectedFile().isDirectory()) {
      this.confirmed = true;
      this.gui.dispose();
    }
  }
コード例 #3
0
  /**
   * Allocates a new {@link OpenDialog}.
   *
   * @param parent The parent {@link JFrame}.
   * @param workingPath The working path.
   */
  public OpenDialog(JFrame parent, String workingPath) {
    logger.debug("OpenDialog", "allocate a new open dialog"); // $NON-NLS-1$ //$NON-NLS-2$
    this.parent = parent;
    this.gui = new OpenDialogForm(this, parent);
    this.gui.jGTIFileChooser.setCurrentDirectory(new File(workingPath));

    // Source files
    FileFilter sourceFileFilter =
        new FileFilter() {

          @Override
          public boolean accept(File file) {
            if (file.isDirectory()) {
              return true;
            }
            for (String current : Machine.AVAILABLE_MACHINES) {
              if (file.getName()
                  .toLowerCase()
                  .matches(".+\\." + current.toLowerCase())) // $NON-NLS-1$
              {
                return true;
              }
            }
            for (String current : Grammar.AVAILABLE_GRAMMARS) {
              if (file.getName()
                  .toLowerCase()
                  .matches(".+\\." + current.toLowerCase())) // $NON-NLS-1$
              {
                return true;
              }
            }
            if (file.getName()
                .toLowerCase()
                .matches(".+\\." + RegexType.REGEX.getFileEnding())) // $NON-NLS-1$
            {
              return true;
            }
            return false;
          }

          @Override
          public String getDescription() {
            StringBuilder result = new StringBuilder();
            result.append(Messages.getString("OpenDialog.FilterFiles")); // $NON-NLS-1$
            result.append(" ("); // $NON-NLS-1$
            for (int i = 0; i < Machine.AVAILABLE_MACHINES.length; i++) {
              result.append("*."); // $NON-NLS-1$
              result.append(Machine.AVAILABLE_MACHINES[i].toLowerCase());
              if (i != Machine.AVAILABLE_MACHINES.length - 1) {
                result.append("; "); // $NON-NLS-1$
              }
            }
            if ((Machine.AVAILABLE_MACHINES.length > 0)
                && (Grammar.AVAILABLE_GRAMMARS.length > 0)) {
              result.append("; "); // $NON-NLS-1$
            }
            for (int i = 0; i < Grammar.AVAILABLE_GRAMMARS.length; i++) {
              result.append("*."); // $NON-NLS-1$
              result.append(Grammar.AVAILABLE_GRAMMARS[i].toLowerCase());
              if (i != Grammar.AVAILABLE_GRAMMARS.length - 1) {
                result.append("; "); // $NON-NLS-1$
              }
            }
            result.append("*."); // $NON-NLS-1$
            result.append(RegexType.REGEX.getFileEnding());
            result.append(")"); // $NON-NLS-1$
            return result.toString();
          }
        };

    // Machine files
    FileFilter machineFileFilter =
        new FileFilter() {

          @Override
          public boolean accept(File file) {
            if (file.isDirectory()) {
              return true;
            }
            for (String current : Machine.AVAILABLE_MACHINES) {
              if (file.getName()
                  .toLowerCase()
                  .matches(".+\\." + current.toLowerCase())) // $NON-NLS-1$
              {
                return true;
              }
            }
            return false;
          }

          @Override
          public String getDescription() {
            StringBuilder result = new StringBuilder();
            result.append(Messages.getString("OpenDialog.FilterFilesMachine")); // $NON-NLS-1$
            result.append(" ("); // $NON-NLS-1$
            for (int i = 0; i < Machine.AVAILABLE_MACHINES.length; i++) {
              result.append("*."); // $NON-NLS-1$
              result.append(Machine.AVAILABLE_MACHINES[i].toLowerCase());
              if (i != Machine.AVAILABLE_MACHINES.length - 1) {
                result.append("; "); // $NON-NLS-1$
              }
            }
            result.append(")"); // $NON-NLS-1$
            return result.toString();
          }
        };

    // Grammar files
    FileFilter grammarFileFilter =
        new FileFilter() {

          @Override
          public boolean accept(File file) {
            if (file.isDirectory()) {
              return true;
            }
            for (String current : Grammar.AVAILABLE_GRAMMARS) {
              if (file.getName()
                  .toLowerCase()
                  .matches(".+\\." + current.toLowerCase())) // $NON-NLS-1$
              {
                return true;
              }
            }
            return false;
          }

          @Override
          public String getDescription() {
            StringBuilder result = new StringBuilder();
            result.append(Messages.getString("OpenDialog.FilterFilesGrammar")); // $NON-NLS-1$
            result.append(" ("); // $NON-NLS-1$
            for (int i = 0; i < Grammar.AVAILABLE_GRAMMARS.length; i++) {
              result.append("*."); // $NON-NLS-1$
              result.append(Grammar.AVAILABLE_GRAMMARS[i].toLowerCase());
              if (i != Grammar.AVAILABLE_GRAMMARS.length - 1) {
                result.append("; "); // $NON-NLS-1$
              }
            }
            result.append(")"); // $NON-NLS-1$
            return result.toString();
          }
        };

    // Grammar files
    FileFilter regexFileFilter =
        new FileFilter() {

          @Override
          public boolean accept(File file) {
            if (file.isDirectory()) {
              return true;
            }

            if (file.getName()
                .toLowerCase()
                .matches(".+\\." + RegexType.REGEX.getFileEnding())) // $NON-NLS-1$
            {
              return true;
            }
            return false;
          }

          @Override
          public String getDescription() {
            StringBuilder result = new StringBuilder();
            result.append(Messages.getString("OpenDialog.FilterFilesRegex")); // $NON-NLS-1$
            result.append(" (*."); // $NON-NLS-1$
            result.append(RegexType.REGEX.getFileEnding());
            result.append(")"); // $NON-NLS-1$
            return result.toString();
          }
        };

    this.gui.jGTIFileChooser.addChoosableFileFilter(sourceFileFilter);
    this.gui.jGTIFileChooser.addChoosableFileFilter(machineFileFilter);
    this.gui.jGTIFileChooser.addChoosableFileFilter(grammarFileFilter);
    this.gui.jGTIFileChooser.addChoosableFileFilter(regexFileFilter);
    this.gui.jGTIFileChooser.setFileFilter(sourceFileFilter);
  }
コード例 #4
0
  /** Closes the {@link OpenDialogForm}. */
  public final void handleCancel() {
    logger.debug("handleCancel", "handle cancel"); // $NON-NLS-1$ //$NON-NLS-2$

    this.confirmed = false;
    this.gui.dispose();
  }