Exemple #1
0
  public FileDialog(
      String title,
      String description,
      String actionLabel,
      TerminalSize dialogSize,
      boolean showHiddenFilesAndDirs,
      File selectedObject) {
    super(title);
    this.selectedFile = null;
    this.showHiddenFilesAndDirs = showHiddenFilesAndDirs;

    if (selectedObject == null || !selectedObject.exists()) {
      selectedObject = new File("").getAbsoluteFile();
    }
    selectedObject = selectedObject.getAbsoluteFile();

    Panel contentPane = new Panel();
    contentPane.setLayoutManager(new GridLayout(2));

    if (description != null) {
      new Label(description)
          .setLayoutData(
              GridLayout.createLayoutData(
                  GridLayout.Alignment.BEGINNING, GridLayout.Alignment.CENTER, false, false, 2, 1))
          .addTo(contentPane);
    }

    int unitWidth = dialogSize.getColumns() / 3;
    int unitHeight = dialogSize.getRows();

    new FileSystemLocationLabel()
        .setLayoutData(
            GridLayout.createLayoutData(
                GridLayout.Alignment.FILL, GridLayout.Alignment.CENTER, true, false, 2, 1))
        .addTo(contentPane);

    fileListBox = new ActionListBox(new TerminalSize(unitWidth * 2, unitHeight));
    fileListBox
        .withBorder(Borders.singleLine())
        .setLayoutData(
            GridLayout.createLayoutData(
                GridLayout.Alignment.BEGINNING, GridLayout.Alignment.CENTER, false, false))
        .addTo(contentPane);
    directoryListBox = new ActionListBox(new TerminalSize(unitWidth, unitHeight));
    directoryListBox.withBorder(Borders.singleLine()).addTo(contentPane);

    fileBox =
        new TextBox()
            .setLayoutData(
                GridLayout.createLayoutData(
                    GridLayout.Alignment.FILL, GridLayout.Alignment.CENTER, true, false, 2, 1))
            .addTo(contentPane);

    new Separator(Direction.HORIZONTAL)
        .setLayoutData(
            GridLayout.createLayoutData(
                GridLayout.Alignment.FILL, GridLayout.Alignment.CENTER, true, false, 2, 1))
        .addTo(contentPane);

    okButton = new Button(actionLabel, new OkHandler());
    Panels.grid(2, okButton, new Button("Cancel", new CancelHandler()))
        .setLayoutData(
            GridLayout.createLayoutData(
                GridLayout.Alignment.END, GridLayout.Alignment.CENTER, false, false, 2, 1))
        .addTo(contentPane);

    if (selectedObject.isFile()) {
      directory = selectedObject.getParentFile();
      fileBox.setText(selectedObject.getName());
    } else if (selectedObject.isDirectory()) {
      directory = selectedObject;
    }

    reloadViews(directory);
    setComponent(contentPane);
  }