コード例 #1
0
  /**
   * Makes the options window either visible or not visible depending on the boolean argument.
   *
   * @param visible <tt>boolean</tt> value specifying whether the options window should be made
   *     visible or not visible
   * @param key the unique identifying key of the panel to show
   */
  final void setOptionsVisible(boolean visible, final String key) {
    if (!visible) {
      DIALOG.dispose();
      OptionsMediator.instance().disposeOptions();
    } else {
      GUIUtils.centerOnScreen(DIALOG);
      //  initial tree selection
      if (key == null) TREE_MANAGER.setDefaultSelection();
      else TREE_MANAGER.setSelection(key);

      // make tree component the default component instead of the search field
      TREE_MANAGER.getComponent().requestFocusInWindow();

      DIALOG.setVisible(true);
    }
  }
コード例 #2
0
  /**
   * Adds the specified key and <tt>OptionsPane</tt> to current set of options. This adds this
   * <tt>OptionsPane</tt> to the set of <tt>OptionsPane</tt>s the user can select.
   *
   * @param parentKey the key of the parent node to add the new node to
   */
  private final OptionsTreeNode addOption(
      final String parentKey,
      final String childKey,
      final String label,
      @SuppressWarnings("unchecked") Class<? extends AbstractPaneItem>... clazzes) {
    StringBuilder sb = new StringBuilder();
    sb.append(label);
    sb.append(" ");
    sb.append(extractLabels(clazzes));

    OptionsTreeNode node = TREE_MANAGER.addNode(parentKey, childKey, label, sb.toString());
    node.setClasses(clazzes);
    return node;
  }
コード例 #3
0
 private void filter() {
   TREE_MANAGER.setFilterText(filterTextField.getText());
 }
コード例 #4
0
 /**
  * Adds a parent node to the tree. This node serves navigational purposes only, and so has no
  * corresponding <tt>OptionsPane</tt>. This method allows for multiple tiers of parent nodes, not
  * only top-level parents.
  *
  * @param parentKey the key of the parent node to add this parent node to
  * @param childKey the key of the new parent node that is a child of the <tt>parentKey</tt>
  *     argument
  */
 private final void addGroupTreeNode(final String parentKey, final String childKey, String label) {
   TREE_MANAGER.addNode(parentKey, childKey, label, label);
 }
コード例 #5
0
  /**
   * 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);
  }