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 java.awt.GridBagConstraints;
022import java.awt.GridBagLayout;
023import java.awt.Insets;
024
025import javax.swing.JCheckBox;
026import javax.swing.JLabel;
027import javax.swing.JSpinner;
028import javax.swing.SpinnerNumberModel;
029
030import icy.gui.util.LookAndFeelUtil;
031import icy.main.Icy;
032import icy.preferences.CanvasPreferences;
033import icy.preferences.GeneralPreferences;
034
035/**
036 * @author Stephane
037 */
038public class GUICanvasPreferencePanel extends PreferencePanel
039{
040    /**
041     * 
042     */
043    private static final long serialVersionUID = 7070251589085892036L;
044
045    public static final String NODE_NAME = "GUI & Canvas";
046
047    /**
048     * gui
049     */
050    private JCheckBox filteringCheckBox;
051    private JCheckBox invertWheelAxisCheckBox;
052    private JSpinner wheelAxisSensitivity;
053    private JCheckBox alwaysOnTopCheckBox;
054    private JSpinner uiFontSizeSpinner;
055
056    /**
057     * @param parent
058     */
059    GUICanvasPreferencePanel(PreferenceFrame parent)
060    {
061        super(parent, NODE_NAME, PreferenceFrame.NODE_NAME);
062
063        initialize();
064        load();
065    }
066
067    private void initialize()
068    {
069        GridBagLayout gridBagLayout = new GridBagLayout();
070        gridBagLayout.columnWidths = new int[] {0, 80, 4, 0};
071        gridBagLayout.rowHeights = new int[] {23, 0, 0, 0, 0, 0};
072        gridBagLayout.columnWeights = new double[] {1.0, 0.0, 0.0, Double.MIN_VALUE};
073        gridBagLayout.rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
074        mainPanel.setLayout(gridBagLayout);
075
076        alwaysOnTopCheckBox = new JCheckBox("Application window always on top");
077        GridBagConstraints gbc_alwaysOnTopCheckBox = new GridBagConstraints();
078        gbc_alwaysOnTopCheckBox.anchor = GridBagConstraints.NORTHWEST;
079        gbc_alwaysOnTopCheckBox.insets = new Insets(0, 0, 5, 5);
080        gbc_alwaysOnTopCheckBox.gridx = 0;
081        gbc_alwaysOnTopCheckBox.gridy = 0;
082        mainPanel.add(alwaysOnTopCheckBox, gbc_alwaysOnTopCheckBox);
083
084        filteringCheckBox = new JCheckBox("Enable image filtering");
085        filteringCheckBox.setToolTipText("Enable image filtering to improve rendering quality");
086        GridBagConstraints gbc_filteringCheckBox = new GridBagConstraints();
087        gbc_filteringCheckBox.anchor = GridBagConstraints.NORTHWEST;
088        gbc_filteringCheckBox.insets = new Insets(0, 0, 5, 5);
089        gbc_filteringCheckBox.gridx = 0;
090        gbc_filteringCheckBox.gridy = 1;
091        mainPanel.add(filteringCheckBox, gbc_filteringCheckBox);
092
093        invertWheelAxisCheckBox = new JCheckBox("Invert mouse wheel axis");
094        invertWheelAxisCheckBox.setToolTipText("Invert the mouse wheel axis for canvas operation");
095        GridBagConstraints gbc_invertWheelAxisCheckBox = new GridBagConstraints();
096        gbc_invertWheelAxisCheckBox.anchor = GridBagConstraints.NORTHWEST;
097        gbc_invertWheelAxisCheckBox.insets = new Insets(0, 0, 5, 5);
098        gbc_invertWheelAxisCheckBox.gridx = 0;
099        gbc_invertWheelAxisCheckBox.gridy = 2;
100        mainPanel.add(invertWheelAxisCheckBox, gbc_invertWheelAxisCheckBox);
101
102        JLabel label = new JLabel(" GUI font size   ");
103        GridBagConstraints gbc_label = new GridBagConstraints();
104        gbc_label.anchor = GridBagConstraints.WEST;
105        gbc_label.insets = new Insets(0, 0, 5, 5);
106        gbc_label.gridx = 0;
107        gbc_label.gridy = 3;
108        mainPanel.add(label, gbc_label);
109
110        uiFontSizeSpinner = new JSpinner(new SpinnerNumberModel(7, 7, 24, 1));
111        uiFontSizeSpinner.setToolTipText("");
112        GridBagConstraints gbc_uiFontSizeSpinner = new GridBagConstraints();
113        gbc_uiFontSizeSpinner.fill = GridBagConstraints.HORIZONTAL;
114        gbc_uiFontSizeSpinner.insets = new Insets(0, 0, 5, 5);
115        gbc_uiFontSizeSpinner.gridx = 1;
116        gbc_uiFontSizeSpinner.gridy = 3;
117        mainPanel.add(uiFontSizeSpinner, gbc_uiFontSizeSpinner);
118
119        GridBagConstraints gbc_lblMouseWheelSensivity = new GridBagConstraints();
120        gbc_lblMouseWheelSensivity.anchor = GridBagConstraints.WEST;
121        gbc_lblMouseWheelSensivity.insets = new Insets(0, 0, 5, 5);
122        gbc_lblMouseWheelSensivity.gridx = 0;
123        gbc_lblMouseWheelSensivity.gridy = 4;
124        JLabel lblMouseWheelSensivity = new JLabel(" Mouse wheel sensivity");
125        mainPanel.add(lblMouseWheelSensivity, gbc_lblMouseWheelSensivity);
126
127        wheelAxisSensitivity = new JSpinner(new SpinnerNumberModel(5d, 1d, 10d, 0.5d));
128        wheelAxisSensitivity.setToolTipText("Set mouse wheel sensivity for canvas operation (1-10)");
129        GridBagConstraints gbc_wheelAxisSensitivity = new GridBagConstraints();
130        gbc_wheelAxisSensitivity.fill = GridBagConstraints.HORIZONTAL;
131        gbc_wheelAxisSensitivity.insets = new Insets(0, 0, 5, 5);
132        gbc_wheelAxisSensitivity.gridx = 1;
133        gbc_wheelAxisSensitivity.gridy = 4;
134        mainPanel.add(wheelAxisSensitivity, gbc_wheelAxisSensitivity);
135
136        mainPanel.validate();
137    }
138
139    @Override
140    protected void load()
141    {
142        wheelAxisSensitivity.setValue(Double.valueOf(CanvasPreferences.getMouseWheelSensitivity()));
143        invertWheelAxisCheckBox.setSelected(CanvasPreferences.getInvertMouseWheelAxis());
144        filteringCheckBox.setSelected(CanvasPreferences.getFiltering());
145        alwaysOnTopCheckBox.setSelected(GeneralPreferences.getAlwaysOnTop());
146        uiFontSizeSpinner.setValue(Integer.valueOf(GeneralPreferences.getGuiFontSize()));
147    }
148
149    @Override
150    protected void save()
151    {
152        CanvasPreferences.setMouseWheelSensitivity(((Double) wheelAxisSensitivity.getValue()).doubleValue());
153        CanvasPreferences.setInvertMouseWheelAxis(invertWheelAxisCheckBox.isSelected());
154        CanvasPreferences.setFiltering(filteringCheckBox.isSelected());
155
156        boolean booleanValue = alwaysOnTopCheckBox.isSelected();
157        Icy.getMainInterface().setAlwaysOnTop(booleanValue);
158        GeneralPreferences.setAlwaysOnTop(booleanValue);
159
160        int intValue = ((Integer) uiFontSizeSpinner.getValue()).intValue();
161        LookAndFeelUtil.setFontSize(intValue);
162        GeneralPreferences.setGuiFontSize(intValue);
163    }
164}