Example usage for com.jgoodies.binding.adapter PreferencesAdapter PreferencesAdapter

List of usage examples for com.jgoodies.binding.adapter PreferencesAdapter PreferencesAdapter

Introduction

In this page you can find the example usage for com.jgoodies.binding.adapter PreferencesAdapter PreferencesAdapter.

Prototype

public PreferencesAdapter(Preferences prefs, String key, Object defaultValue) 

Source Link

Document

Constructs a PreferencesAdapter on the given Preferences using the specified key and default value, all which must be non- null .

Usage

From source file:com.salas.bb.whatshot.Dialog.java

License:Open Source License

/**
 * Creates search dialog./*  www  .  j a  v  a2  s. c  o  m*/
 *
 * @param owner     dialog's parent frame.
 * @param engine    engine to use.
 * @param set       guides set to pick the guides from.
 * @param listener  selection listener.
 */
public Dialog(Frame owner, Engine engine, final GuidesSet set, ActionListener listener) {
    super(owner, Strings.message("whatshot.dialog.title"));
    guidesSet = set;

    pnlProgress = new ProgressPanel(Strings.message("whatshot.inprogress"));
    scrollPanel = buildResultsPanel();

    setModal(false);

    // Only unread selector
    Preferences prefs = Application.getUserPreferences();
    ValueModel mdlOnlyUnread = new PreferencesAdapter(prefs, PROP_WH_UNREAD_ONLY, false);
    chOnlyUnread = ComponentsFactory.createCheckBox(Strings.message("whatshot.unreadonly"),
            new ToggleButtonAdapter(mdlOnlyUnread));

    // Time options
    ValueModel mdlTimeOption = new AbstractConverter(
            new PreferencesAdapter(prefs, PROP_WH_TIME_OPTION, TimeOption.THIS_WEEK.getCode())) {
        public Object convertFromSubject(Object o) {
            return TimeOption.fromCode((Integer) o);
        }

        public void setValue(Object o) {
            TimeOption to = (TimeOption) o;
            subject.setValue(to.getCode());
        }
    };
    cbTimeOptions = new JComboBox(new ComboBoxAdapter(TimeOption.OPTIONS, mdlTimeOption));

    // Starz selector
    ValueModel mdlStarz = new PreferencesAdapter(prefs, PROP_WH_STARZ, 1);
    starz = new StarsSelectionComponent(new BoundedRangeAdapter(mdlStarz, 0, 1, 5));

    // Make toolbar fonts smaller
    UifUtilities.smallerFont(chOnlyUnread);
    UifUtilities.smallerFont(cbTimeOptions);

    // Setup button
    btnSetup = new JButton(Strings.message("whatshot.setup"));
    btnSetup.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            SetupDialog sd = new SetupDialog(GlobalModel.SINGLETON.getUserPreferences());
            sd.open();
        }
    });

    UifUtilities.smallerFont(btnSetup);

    // Results model and list
    model = new ListModel(engine, mdlStarz, mdlOnlyUnread, mdlTimeOption);
    onSetupChange();

    itemsList = new ResultsList(model) {
        @Override
        protected ResultGroupPanel createGroupPanel(ResultGroup group) {
            return new ResultGroupPanel(group.getName(), group.getName(), GROUP_COLOR_1, GROUP_COLOR_2);
        }
    };
    itemsList.addActionListener(listener);

    // Start populating
    SwingWorker scanner = model.scan();
    scanner.addPropertyChangeListener(new ScannerListener());
    scanner.execute();
}

From source file:de.dal33t.powerfolder.PreferencesEntry.java

License:Open Source License

/**
 * Constructs a preferences adapter which is directly bound to the
 * preferences entry.// w w  w.j av  a 2 s . co m
 *
 * @param controller
 *            the controller
 * @return the model bound to the pref entry.
 */
public ValueModel getModel(Controller controller) {
    Reject.ifNull(controller, "Controller is null");
    return new PreferencesAdapter(controller.getPreferences(), preferencesKey, getDefaultValue(controller));
}