Beispiel #1
0
  @Override
  protected void createPageContent(JPanel panel) {
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    TitledPaddedPanel commercialUsePanel =
        new TitledPaddedPanel(I18n.tr("Allow commercial use of your work?"));

    // make sure the panel expands horizontally
    commercialUsePanel.add(Box.createHorizontalGlue());

    ButtonGroup bg = new ButtonGroup();
    bg.add(ALLOW_COMMERCIAL_YES);
    bg.add(ALLOW_COMMERCIAL_NO);

    BoxPanel buttonPanel = new BoxPanel();
    commercialUsePanel.add(buttonPanel);
    buttonPanel.add(ALLOW_COMMERCIAL_YES);
    buttonPanel.add(ALLOW_COMMERCIAL_NO);
    panel.add(commercialUsePanel);

    panel.add(Box.createRigidArea(BoxPanel.LINE_GAP));

    TitledPaddedPanel modificationsPanel =
        new TitledPaddedPanel(I18n.tr("Allow modification of your work?"));

    // make sure the panel expands horizontally
    modificationsPanel.add(Box.createHorizontalGlue());

    bg = new ButtonGroup();
    bg.add(ALLOW_MODIFICATIONS_SHAREALIKE);
    bg.add(ALLOW_MODIFICATIONS_YES);
    bg.add(ALLOW_MODIFICATIONS_NO);

    buttonPanel = new BoxPanel();
    modificationsPanel.add(buttonPanel);
    buttonPanel.add(ALLOW_MODIFICATIONS_SHAREALIKE);
    buttonPanel.add(ALLOW_MODIFICATIONS_YES);
    buttonPanel.add(ALLOW_MODIFICATIONS_NO);
    panel.add(modificationsPanel);

    // set defaults
    ALLOW_COMMERCIAL_NO.setSelected(true);
    ALLOW_MODIFICATIONS_NO.setSelected(true);
  }
  /**
   * The constructor create all of the options windows and their components.
   *
   * @param treeManager the <tt>OptionsTreeManager</tt> instance to use for constructing the main
   *     panels and adding elements
   * @param paneManager the <tt>OptionsPaneManager</tt> instance to use for constructing the main
   *     panels and adding elements
   */
  public OptionsConstructor(
      final OptionsTreeManager treeManager, final OptionsPaneManager paneManager) {
    TREE_MANAGER = treeManager;
    PANE_MANAGER = paneManager;
    final String title = I18n.tr("Options");
    final boolean shouldBeModal = !OSUtils.isMacOSX();

    DIALOG = new JDialog(GUIMediator.getAppFrame(), title, shouldBeModal);
    DIALOG.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    GUIUtils.addHideAction((JComponent) DIALOG.getContentPane());

    if (UISettings.UI_OPTIONS_DIALOG_HEIGHT.getValue()
        < UISettings.UI_OPTIONS_DIALOG_HEIGHT.getDefaultValue()) {
      UISettings.UI_OPTIONS_DIALOG_HEIGHT.revertToDefault();
    }

    if (UISettings.UI_OPTIONS_DIALOG_WIDTH.getValue()
        < UISettings.UI_OPTIONS_DIALOG_WIDTH.getDefaultValue()) {
      UISettings.UI_OPTIONS_DIALOG_WIDTH.revertToDefault();
    }

    DialogSizeSettingUpdater.install(
        DIALOG, UISettings.UI_OPTIONS_DIALOG_WIDTH, UISettings.UI_OPTIONS_DIALOG_HEIGHT);

    // most Mac users expect changes to be saved when the window
    // is closed, so save them
    DIALOG.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            try {
              DialogOption answer = null;
              if (OptionsMediator.instance().isDirty()) {
                answer =
                    GUIMediator.showYesNoCancelMessage(
                        I18n.tr(
                            "You have made changes to some of FrostWire's settings. Would you like to save these changes?"));
                if (answer == DialogOption.YES) {
                  OptionsMediator.instance().applyOptions();
                  SettingsGroupManager.instance().save();
                }
              }
              if (answer != DialogOption.CANCEL) {
                DIALOG.dispose();
                OptionsMediator.instance().disposeOptions();
              }
            } catch (IOException ioe) {
              // nothing we should do here.  a message should
              // have been displayed to the user with more
              // information
            }
          }
        });

    PaddedPanel mainPanel = new PaddedPanel();

    Box splitBox = new Box(BoxLayout.X_AXIS);

    BoxPanel treePanel = new BoxPanel(BoxLayout.Y_AXIS);

    BoxPanel filterPanel = new BoxPanel(BoxLayout.X_AXIS);
    treePanel.add(filterPanel);

    filterTextField = new SearchField();
    filterTextField.setPrompt(I18n.tr("Search here"));
    filterTextField.setMinimumSize(new Dimension(100, 27));
    filterTextField.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            filter();
          }
        });
    filterPanel.add(filterTextField);

    filterPanel.add(Box.createHorizontalStrut(2));

    treePanel.add(Box.createVerticalStrut(3));

    Component treeComponent = TREE_MANAGER.getComponent();
    treePanel.add(treeComponent);

    Component paneComponent = PANE_MANAGER.getComponent();

    splitBox.add(treePanel);
    splitBox.add(paneComponent);
    mainPanel.add(splitBox);

    mainPanel.add(Box.createVerticalStrut(17));
    mainPanel.add(new OptionsButtonPanel().getComponent());

    DIALOG.getContentPane().add(mainPanel);

    OptionsTreeNode node = initializePanels();
    PANE_MANAGER.show(node);
  }