aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/dictaccregwizz/ProgressPanel.java
blob: 7d46fa507a852251d02e95424f90c24687652a6f (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
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.java.sip.communicator.plugin.dictaccregwizz;

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

import javax.swing.*;

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

/**
 * Panel showing the current status of the search of the strategies
 *
 * @author ROTH Damien
 */
public class ProgressPanel
    extends TransparentPanel
    implements ActionListener
{
    /**
     * Serial version UID.
     */
    private static final long serialVersionUID = 0L;

    private JPanel rightPanel;

    private JLabel messageLabel;
    private JLabel progressLabel;
    private JButton cancelButton;

    private int currentStep;
    private int totalSteps;

    private boolean isBuild;

    private ThreadManager searchThread;

    /**
     * Create an instance of <tt>ProgressPanel</tt>
     * @param searchThread The thread manager
     */
    public ProgressPanel(ThreadManager searchThread)
    {
        super(new BorderLayout());

        // Element creation
        this.messageLabel = new JLabel(" ");
        this.progressLabel = new JLabel(" ");
        this.cancelButton
            = new JButton(Resources.getString("service.gui.CANCEL"));
        this.cancelButton.addActionListener(this);

        // Right panel init
        this.rightPanel = new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
        this.rightPanel.add(this.progressLabel);
        this.rightPanel.add(this.cancelButton);

        this.searchThread = searchThread;

        init();
        this.totalSteps = ThreadManager.NB_STEPS;
    }

    /**
     * Init the values
     */
    private void init()
    {
        this.isBuild = false;
        this.currentStep = 1;

        this.add(this.messageLabel, BorderLayout.CENTER);
    }

    /**
     * Build the UI
     */
    private void build()
    {
        if (this.isBuild)
        {
            return;
        }

        this.add(this.messageLabel, BorderLayout.CENTER);
        this.add(this.rightPanel, BorderLayout.EAST);

        this.isBuild = true;
    }

    /**
     * Move to the next step without updating the message
     */
    public void nextStep()
    {
        nextStep(this.messageLabel.getText());
    }

    /**
     * Mode to the next step with a new message
     * @param message Message
     */
    public void nextStep(String message)
    {
        if (this.currentStep > this.totalSteps)
        {
            finish();
        }

        build();
        this.messageLabel.setText(message);
        this.progressLabel.setText(currentStep + "/" + totalSteps);

        this.currentStep++;
    }

    /**
     * Informs the end of the progress. Remove all the components and
     * reset the values
     */
    public void finish()
    {
        // Remove all elements
        this.removeAll();

        // Re-init the panel
        this.messageLabel.setText(" ");
        this.progressLabel.setText(" ");
        init();

        this.repaint();
        this.validate();
    }

    public void actionPerformed(ActionEvent arg0)
    {
        this.searchThread.cancel();
        this.finish();
    }
}