예제 #1
0
  @Override
  public void init(WindowBasedTextGUI textGUI) {
    final BasicWindow window = new BasicWindow("Grid layout test");

    final Panel leftPanel = new Panel();

    Panel checkBoxPanel = new Panel();
    for (int i = 0; i < 4; i++) {
      CheckBox checkBox = new CheckBox("Checkbox #" + (i + 1));
      checkBoxPanel.addComponent(checkBox);
    }

    Panel textBoxPanel = new Panel();
    textBoxPanel.addComponent(
        Panels.horizontal(new Label("Normal:   "), new TextBox(new TerminalSize(12, 1), "Text")));
    textBoxPanel.addComponent(
        Panels.horizontal(
            new Label("Password: "******"Text").setMask('*')));

    Panel buttonPanel = new Panel();
    buttonPanel.addComponent(
        new Button(
            "Enable spacing",
            new Runnable() {
              @Override
              public void run() {
                LinearLayout layoutManager = (LinearLayout) leftPanel.getLayoutManager();
                layoutManager.setSpacing(layoutManager.getSpacing() == 0 ? 1 : 0);
              }
            }));

    leftPanel.addComponent(checkBoxPanel.withBorder(Borders.singleLine("CheckBoxes")));
    leftPanel.addComponent(textBoxPanel.withBorder(Borders.singleLine("TextBoxes")));
    leftPanel.addComponent(buttonPanel.withBorder(Borders.singleLine("Buttons")));

    Panel rightPanel = new Panel();
    textBoxPanel = new Panel();
    TextBox readOnlyTextArea = new TextBox(new TerminalSize(16, 8));
    readOnlyTextArea.setReadOnly(true);
    readOnlyTextArea.setText(TestUtils.downloadGPL());
    textBoxPanel.addComponent(readOnlyTextArea);
    rightPanel.addComponent(textBoxPanel.withBorder(Borders.singleLine("Read-only")));
    rightPanel.setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.Fill));

    Panel contentArea = new Panel();
    contentArea.setLayoutManager(new LinearLayout(Direction.VERTICAL));
    contentArea.addComponent(Panels.horizontal(leftPanel, rightPanel));
    contentArea.addComponent(
        new Separator(Direction.HORIZONTAL)
            .setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.Fill)));
    contentArea.addComponent(
        new Button(
                "OK",
                new Runnable() {
                  @Override
                  public void run() {
                    window.close();
                  }
                })
            .setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.Center)));
    window.setComponent(contentArea);
    textGUI.addWindow(window);
  }
예제 #2
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);
  }