123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- /*
- * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.addons.ui_swing.dialogs.prefs;
-
- import com.dmdirc.addons.ui_swing.SwingController;
- import com.dmdirc.config.ConfigManager;
- import com.dmdirc.config.Identity;
- import com.dmdirc.config.IdentityManager;
- import com.dmdirc.config.prefs.PreferencesInterface;
- import com.dmdirc.addons.ui_swing.components.PackingTable;
- import com.dmdirc.interfaces.ConfigChangeListener;
- import com.dmdirc.logger.ErrorLevel;
- import com.dmdirc.logger.Logger;
- import com.dmdirc.updater.UpdateChannel;
- import com.dmdirc.updater.UpdateChecker;
-
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
-
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JComboBox;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
-
- import net.miginfocom.swing.MigLayout;
-
- /**
- * Updates configuration UI.
- */
- public class UpdateConfigPanel extends JPanel implements ActionListener,
- PreferencesInterface, ConfigChangeListener {
-
- /**
- * A version number for this class. It should be changed whenever the class
- * structure is changed (or anything else that would prevent serialized
- * objects being unserialized with the new class).
- */
- private static final long serialVersionUID = 1;
- /** Global checkbox. */
- private JCheckBox enable;
- /** Table scroll pane, */
- private JScrollPane scrollPane;
- /** Component table model. */
- private UpdateTableModel tableModel;
- /** Component table. */
- private PackingTable table;
- /** Check now button. */
- private JButton checkNow;
- /** Update channel. */
- private JComboBox updateChannel;
- /** Swing controller. */
- private SwingController controller;
-
- /**
- * Instantiates a new update config panel.
- *
- * @param controller Swing controller
- */
- public UpdateConfigPanel(final SwingController controller) {
- this.controller = controller;
-
- initComponents();
- addListeners();
- layoutComponents();
- }
-
- /** {@inheritDoc} */
- @Override
- public void save() {
- final Identity identity = IdentityManager.getConfigIdentity();
- identity.setOption("updater", "enable", enable.isSelected());
-
- IdentityManager.getConfigIdentity().setOption("updater", "channel",
- updateChannel.getSelectedItem().toString());
-
- for (int i = 0; i < tableModel.getRowCount(); i++) {
- final String componentName = tableModel.getComponent(i).getName();
- if ((Boolean) tableModel.getValueAt(i, 1)) {
- identity.unsetOption("updater", "enable-" + componentName);
- } else {
- identity.setOption("updater", "enable-" + componentName, false);
- }
- }
- }
-
- /**
- * Initialises the components.
- */
- private void initComponents() {
- final ConfigManager config = IdentityManager.getGlobalConfig();
- enable = new JCheckBox();
- scrollPane = new JScrollPane();
- tableModel = new UpdateTableModel(UpdateChecker.getComponents());
- table = new PackingTable(tableModel, false, scrollPane);
- checkNow = new JButton("Check now");
- checkNow.setEnabled(IdentityManager.getGlobalConfig().getOptionBool(
- "updater", "enable"));
- updateChannel = new JComboBox(new DefaultComboBoxModel(UpdateChannel.
- values()));
-
- enable.setSelected(config.getOptionBool("updater", "enable"));
- UpdateChannel channel = UpdateChannel.NONE;
- try {
- channel = UpdateChannel.valueOf(
- config.getOption("updater", "channel"));
- } catch (IllegalArgumentException e) {
- Logger.userError(ErrorLevel.LOW, "Invalid setting for update "
- + "channel, defaulting to none.");
- }
- updateChannel.setSelectedItem(channel);
- scrollPane.setViewportView(table);
- }
-
- /**
- * Adds the listeners.
- */
- private void addListeners() {
- checkNow.addActionListener(this);
- IdentityManager.getGlobalConfig().addChangeListener("updater",
- "enable", this);
- enable.addActionListener(this);
- }
-
- /**
- * Lays out the components.
- */
- private void layoutComponents() {
- setLayout(new MigLayout("fill, ins 0, hmax " + controller.getPrefsDialog().
- getPanelHeight()));
-
- add(new JLabel("Update checking:"), "split");
- add(enable, "growx");
- add(updateChannel, "growx, pushx, wrap");
- add(scrollPane, "wrap, grow, push");
- add(checkNow, "right");
- }
-
- /**
- * {@inheritDoc}
- *
- * @param e Action event
- */
- @Override
- public void actionPerformed(final ActionEvent e) {
- if (enable == e.getSource()) {
- checkNow.setEnabled(enable.isSelected());
- } else {
- UpdateChecker.checkNow();
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public void configChanged(final String domain, final String key) {
- checkNow.setEnabled(IdentityManager.getGlobalConfig().getOptionBool(
- "updater", "enable"));
- }
- }
|