aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayConfigurationPanel.java
blob: a0160d88d2489673358c0af35b3a1833656d09b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.plugin.generalconfig.autoaway;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;

import net.java.sip.communicator.plugin.generalconfig.*;
import net.java.sip.communicator.plugin.desktoputil.*;

import org.jitsi.service.resources.*;

/**
 * The <tt>ConfigurationForm</tt> that would be added in the user interface
 * configuration window.
 *
 * @author Damien Roth
 */
public class AutoAwayConfigurationPanel
    extends TransparentPanel
{
    /**
     * Serial version UID.
     */
    private static final long serialVersionUID = 0L;

    private JCheckBox enable;

    private JSpinner timer;

    /**
     * Create an instance of <tt>StatusConfigForm</tt>
     */
    public AutoAwayConfigurationPanel()
    {
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

        JPanel pnlSection
            = GeneralConfigPluginActivator.createConfigSectionComponent(
                    Resources.getString("service.gui.STATUS"));

        pnlSection.add(createMainPanel());
        add(pnlSection);

        initValues();
    }

    /**
     * Init the main panel.
     * @return the created component
     */
    private Component createMainPanel()
    {
        ResourceManagementService resources
            = GeneralConfigPluginActivator.getResources();

        enable
            = new SIPCommCheckBox(
                    resources.getI18NString(
                            "plugin.autoaway.ENABLE_CHANGE_STATUS"));
        enable.addActionListener(
                new ActionListener()
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        timer.setEnabled(enable.isSelected());
                        saveData();
                    }
                });

        // Spinner
        timer
            = new JSpinner(
                    new SpinnerNumberModel(
                            Preferences.DEFAULT_TIMER,
                            1,
                            180,
                            1));
        timer.addChangeListener(
                new ChangeListener()
                {
                    public void stateChanged(ChangeEvent e)
                    {
                        saveData();
                    }
                });

        JPanel timerPanel
            = new TransparentPanel(new FlowLayout(FlowLayout.LEFT));

        // Text
        timerPanel.add(
                new JLabel(
                        resources.getI18NString(
                                "plugin.autoaway.AWAY_MINUTES")));
        timerPanel.add(timer);

        try
        {
            // changes that are valid will be saved immediately while typing
            ((DefaultFormatter)((JSpinner.DefaultEditor)timer.getEditor())
                .getTextField().getFormatter()).setCommitsOnValidEdit(true);
        }
        catch(Throwable t)
        {}

        JPanel mainPanel = new TransparentPanel(new BorderLayout(5, 5));

        mainPanel.add(enable, BorderLayout.NORTH);
        mainPanel.add(timerPanel, BorderLayout.WEST);

        return mainPanel;
    }

    /**
     * Init the values of the widgets
     */
    private void initValues()
    {
        boolean enabled = Preferences.isEnabled();

        this.enable.setSelected(enabled);
        this.timer.setEnabled(enabled);

        this.timer.setValue(Preferences.getTimer());
    }

    /**
     * Save data in the configuration file
     */
    private void saveData()
    {
        Preferences.saveData(enable.isSelected(), timer.getValue().toString());
    }
}