Пример #1
0
  public FoldersPanel(PreferencesDialog parent) {
    super(parent, Translator.get("prefs_dialog.folders_tab"));

    setLayout(new BorderLayout());

    // Startup folders panel
    YBoxPanel startupFolderPanel = new YBoxPanel();
    startupFolderPanel.setBorder(
        BorderFactory.createTitledBorder(Translator.get("prefs_dialog.startup_folders")));

    // Last folders or custom folders selections
    lastFoldersRadioButton =
        new PrefRadioButton(Translator.get("prefs_dialog.last_folder")) {
          public boolean hasChanged() {
            return !(isSelected()
                    ? MuPreferences.STARTUP_FOLDERS_LAST
                    : MuPreferences.STARTUP_FOLDERS_CUSTOM)
                .equals(
                    MuConfigurations.getPreferences().getVariable(MuPreference.STARTUP_FOLDERS));
          }
        };
    customFoldersRadioButton =
        new PrefRadioButton(Translator.get("prefs_dialog.custom_folder")) {
          public boolean hasChanged() {
            return !(isSelected()
                    ? MuPreferences.STARTUP_FOLDERS_CUSTOM
                    : MuPreferences.STARTUP_FOLDERS_LAST)
                .equals(
                    MuConfigurations.getPreferences().getVariable(MuPreference.STARTUP_FOLDERS));
          }
        };
    startupFolderPanel.add(lastFoldersRadioButton);
    startupFolderPanel.addSpace(5);
    startupFolderPanel.add(customFoldersRadioButton);

    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(lastFoldersRadioButton);
    buttonGroup.add(customFoldersRadioButton);

    customFoldersRadioButton.addItemListener(this);

    // Custom folders specification
    JLabel leftFolderLabel = new JLabel(Translator.get("prefs_dialog.left_folder"));
    leftFolderLabel.setAlignmentX(LEFT_ALIGNMENT);

    JLabel rightFolderLabel = new JLabel(Translator.get("prefs_dialog.right_folder"));
    rightFolderLabel.setAlignmentX(LEFT_ALIGNMENT);

    // Panel that contains the text field and button for specifying custom left folder
    XBoxPanel leftCustomFolderSpecifyingPanel = new XBoxPanel(5);
    leftCustomFolderSpecifyingPanel.setAlignmentX(LEFT_ALIGNMENT);

    // Create a path field with auto-completion capabilities
    leftCustomFolderTextField = new PrefFilePathFieldWithDefaultValue(true);
    leftCustomFolderTextField.addKeyListener(this);
    leftCustomFolderSpecifyingPanel.add(leftCustomFolderTextField);

    leftCustomFolderButton = new JButton("...");
    leftCustomFolderButton.addActionListener(this);
    leftCustomFolderSpecifyingPanel.add(leftCustomFolderButton);

    // Panel that contains the text field and button for specifying custom right folder
    XBoxPanel rightCustomFolderSpecifyingPanel = new XBoxPanel(5);
    rightCustomFolderSpecifyingPanel.setAlignmentX(LEFT_ALIGNMENT);

    // Create a path field with auto-completion capabilities
    rightCustomFolderTextField = new PrefFilePathFieldWithDefaultValue(false);
    rightCustomFolderTextField.addKeyListener(this);
    rightCustomFolderSpecifyingPanel.add(rightCustomFolderTextField);

    rightCustomFolderButton = new JButton("...");
    rightCustomFolderButton.addActionListener(this);
    rightCustomFolderSpecifyingPanel.add(rightCustomFolderButton);

    JPanel container = new JPanel(new SpringLayout());
    container.add(leftFolderLabel);
    container.add(leftCustomFolderSpecifyingPanel);
    container.add(rightFolderLabel);
    container.add(rightCustomFolderSpecifyingPanel);

    // Lay out the panel.
    SpringUtilities.makeCompactGrid(
        container, 2, 2, // rows, cols
        20, 6, // initX, initY
        6, 6); // xPad, yPad

    startupFolderPanel.add(container);

    if (MuConfigurations.getPreferences()
        .getVariable(MuPreference.STARTUP_FOLDERS, "")
        .equals(MuPreferences.STARTUP_FOLDERS_LAST)) {
      lastFoldersRadioButton.setSelected(true);
      setCustomFolderComponentsEnabled(false);
    } else customFoldersRadioButton.setSelected(true);

    // --------------------------------------------------------------------------------------------------------------

    YBoxPanel northPanel = new YBoxPanel();
    northPanel.add(startupFolderPanel);
    northPanel.addSpace(5);

    showHiddenFilesCheckBox =
        new PrefCheckBox(Translator.get("prefs_dialog.show_hidden_files")) {
          public boolean hasChanged() {
            return isSelected()
                != MuConfigurations.getPreferences()
                    .getVariable(
                        MuPreference.SHOW_HIDDEN_FILES, MuPreferences.DEFAULT_SHOW_HIDDEN_FILES);
          }
        };
    showHiddenFilesCheckBox.setSelected(
        MuConfigurations.getPreferences()
            .getVariable(MuPreference.SHOW_HIDDEN_FILES, MuPreferences.DEFAULT_SHOW_HIDDEN_FILES));
    northPanel.add(showHiddenFilesCheckBox);

    // Mac OS X-only options
    if (OsFamily.MAC_OS_X.isCurrent()) {
      // Monitor showHiddenFilesCheckBox state to disable 'show .DS_Store files' option
      // when 'Show hidden files' is disabled, as .DS_Store files are hidden files
      showHiddenFilesCheckBox.addItemListener(this);

      showDSStoreFilesCheckBox =
          new PrefCheckBox(Translator.get("prefs_dialog.show_ds_store_files")) {
            public boolean hasChanged() {
              return isSelected()
                  != MuConfigurations.getPreferences()
                      .getVariable(
                          MuPreference.SHOW_DS_STORE_FILES,
                          MuPreferences.DEFAULT_SHOW_DS_STORE_FILES);
            }
          };
      showDSStoreFilesCheckBox.setSelected(
          MuConfigurations.getPreferences()
              .getVariable(
                  MuPreference.SHOW_DS_STORE_FILES, MuPreferences.DEFAULT_SHOW_DS_STORE_FILES));
      showDSStoreFilesCheckBox.setEnabled(showHiddenFilesCheckBox.isSelected());
      // Shift the check box to the right to indicate that it is a sub-option
      northPanel.add(showDSStoreFilesCheckBox, 20);
    }

    if (OsFamily.MAC_OS_X.isCurrent() || OsFamily.WINDOWS.isCurrent()) {
      showSystemFoldersCheckBox =
          new PrefCheckBox(Translator.get("prefs_dialog.show_system_folders")) {
            public boolean hasChanged() {
              return isSelected()
                  != MuConfigurations.getPreferences()
                      .getVariable(
                          MuPreference.SHOW_SYSTEM_FOLDERS,
                          MuPreferences.DEFAULT_SHOW_SYSTEM_FOLDERS);
            }
          };
      showSystemFoldersCheckBox.setSelected(
          MuConfigurations.getPreferences()
              .getVariable(
                  MuPreference.SHOW_SYSTEM_FOLDERS, MuPreferences.DEFAULT_SHOW_SYSTEM_FOLDERS));
      northPanel.add(showSystemFoldersCheckBox);
    }

    compactSizeCheckBox =
        new PrefCheckBox(Translator.get("prefs_dialog.compact_file_size")) {
          public boolean hasChanged() {
            return isSelected()
                != MuConfigurations.getPreferences()
                    .getVariable(
                        MuPreference.DISPLAY_COMPACT_FILE_SIZE,
                        MuPreferences.DEFAULT_DISPLAY_COMPACT_FILE_SIZE);
          }
        };
    compactSizeCheckBox.setSelected(
        MuConfigurations.getPreferences()
            .getVariable(
                MuPreference.DISPLAY_COMPACT_FILE_SIZE,
                MuPreferences.DEFAULT_DISPLAY_COMPACT_FILE_SIZE));
    northPanel.add(compactSizeCheckBox);

    followSymlinksCheckBox =
        new PrefCheckBox(Translator.get("prefs_dialog.follow_symlinks_when_cd")) {
          public boolean hasChanged() {
            return isSelected()
                != MuConfigurations.getPreferences()
                    .getVariable(
                        MuPreference.CD_FOLLOWS_SYMLINKS,
                        MuPreferences.DEFAULT_CD_FOLLOWS_SYMLINKS);
          }
        };
    followSymlinksCheckBox.setSelected(
        MuConfigurations.getPreferences()
            .getVariable(
                MuPreference.CD_FOLLOWS_SYMLINKS, MuPreferences.DEFAULT_CD_FOLLOWS_SYMLINKS));
    northPanel.add(followSymlinksCheckBox);

    showTabHeaderCheckBox =
        new PrefCheckBox(Translator.get("prefs_dialog.show_tab_header")) {
          public boolean hasChanged() {
            return isSelected()
                != MuConfigurations.getPreferences()
                    .getVariable(
                        MuPreference.SHOW_TAB_HEADER, MuPreferences.DEFAULT_SHOW_TAB_HEADER);
          }
        };
    showTabHeaderCheckBox.setSelected(
        MuConfigurations.getPreferences()
            .getVariable(MuPreference.SHOW_TAB_HEADER, MuPreferences.DEFAULT_SHOW_TAB_HEADER));
    northPanel.add(showTabHeaderCheckBox);

    add(northPanel, BorderLayout.NORTH);

    lastFoldersRadioButton.addDialogListener(parent);
    customFoldersRadioButton.addDialogListener(parent);
    rightCustomFolderTextField.addDialogListener(parent);
    leftCustomFolderTextField.addDialogListener(parent);
    showHiddenFilesCheckBox.addDialogListener(parent);
    compactSizeCheckBox.addDialogListener(parent);
    followSymlinksCheckBox.addDialogListener(parent);
    showTabHeaderCheckBox.addDialogListener(parent);
    if (OsFamily.MAC_OS_X.isCurrent()) {
      showDSStoreFilesCheckBox.addDialogListener(parent);
    }
    if (OsFamily.MAC_OS_X.isCurrent() || OsFamily.WINDOWS.isCurrent()) {
      showSystemFoldersCheckBox.addDialogListener(parent);
    }
  }