001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.gui.preferences;
020
021import icy.gui.frame.progress.AnnounceFrame;
022import icy.gui.main.MainFrame;
023import icy.main.Icy;
024
025import java.awt.event.ActionEvent;
026import java.awt.event.ActionListener;
027
028import javax.swing.Box;
029import javax.swing.BoxLayout;
030import javax.swing.JButton;
031import javax.swing.JCheckBox;
032
033/**
034 * @author Stephane
035 */
036public class WorkspacePreferencePanel extends PreferencePanel
037{
038    /**
039     * 
040     */
041    private static final long serialVersionUID = -4200728138011886705L;
042
043    public static final String NODE_NAME = "Workspace";
044
045    /**
046     * gui
047     */
048    final JCheckBox autoUpdateCheckBox;
049    final JCheckBox autoCheckUpdateCheckBox;
050    private final JButton cleanButton;
051
052    WorkspacePreferencePanel(PreferenceFrame parent)
053    {
054        super(parent, NODE_NAME, PreferenceFrame.NODE_NAME);
055
056        autoUpdateCheckBox = new JCheckBox("Enable auto update");
057        autoUpdateCheckBox.setToolTipText("Enable silent update for workspaces as soon a new version is available");
058        autoUpdateCheckBox.addActionListener(new ActionListener()
059        {
060            @Override
061            public void actionPerformed(ActionEvent e)
062            {
063                if (autoUpdateCheckBox.isSelected())
064                    autoCheckUpdateCheckBox.setSelected(true);
065                autoCheckUpdateCheckBox.setEnabled(!autoUpdateCheckBox.isSelected());
066            }
067        });
068        autoCheckUpdateCheckBox = new JCheckBox("Check for update at startup");
069        autoCheckUpdateCheckBox.setToolTipText("Check for new workspaces version at startup");
070
071        cleanButton = new JButton("Clean workspaces");
072        cleanButton.setToolTipText("Remove missing plugins from workspace description file");
073        cleanButton.addActionListener(new ActionListener()
074        {
075            @Override
076            public void actionPerformed(ActionEvent e)
077            {
078                final MainFrame frame = Icy.getMainInterface().getMainFrame();
079
080                // clean workspaces
081                if (frame != null)
082                    frame.getMainRibbon().cleanWorkspaces();
083
084                new AnnounceFrame("Worspaces cleaned !");
085            }
086        });
087
088        load();
089
090        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
091
092        // mainPanel.add(autoUpdateCheckBox);
093        // mainPanel.add(Box.createVerticalStrut(10));
094        // mainPanel.add(autoCheckUpdateCheckBox);
095        // mainPanel.add(Box.createVerticalStrut(10));
096        mainPanel.add(cleanButton);
097        mainPanel.add(Box.createVerticalStrut(10));
098        mainPanel.add(Box.createVerticalGlue());
099    }
100
101    @Override
102    protected void load()
103    {
104        // autoUpdateCheckBox.setSelected(WorkspacePreferences.getAutomaticUpdate());
105        // autoCheckUpdateCheckBox.setSelected(WorkspacePreferences.getAutomaticCheckUpdate()
106        // || autoUpdateCheckBox.isSelected());
107        autoCheckUpdateCheckBox.setEnabled(!autoUpdateCheckBox.isSelected());
108    }
109
110    @Override
111    protected void save()
112    {
113        // WorkspacePreferences.setAutomaticUpdate(autoUpdateCheckBox.isSelected());
114        // WorkspacePreferences.setAutomaticCheckUpdate(autoCheckUpdateCheckBox.isSelected());
115    }
116
117}