-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSouthPanel.java
262 lines (236 loc) · 7.65 KB
/
SouthPanel.java
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/**
* The Responder class manage south panel
*
* @author omid mahyar and pouyan hesabi *
* @version 1.0 (1398/04/06)
*/
public class SouthPanel extends JPanel {
private IconForButton playIcon;
private IconForButton stopIcon;
private IconForButton nextIcon;
private IconForButton previousIcon;
private static VolumeJSlider volumeIcon;
private int songNameIsAlive = 0;
private int movingbarAlive = 0;
JLabel totalTime;
JLabel songTime = new JLabel("0:00");
Timer timer;
private Label songName, songArtist;
MovingBarJslider movingBarIcon;
JButton jButton;
String timeValue;
int counter2, counter, movingBarsize, firstTime = 0;
private IconForButton addTofavorite = new IconForButton("icons/heart.png");
// JButton addTofavorite=new JButton("+ favorite");
public SouthPanel() {
this.setBackground(Color.black);
this.setPreferredSize(new Dimension(500, 100));
this.setLayout(new FlowLayout());
this.add(addTofavorite);
previousIcon = new IconForButton("icons/previous.png");
this.add(previousIcon);
playIcon = new IconForButton("icons/play.png");
this.add(playIcon);
nextIcon = new IconForButton("icons/next.png");
this.add(nextIcon);
stopIcon = new IconForButton("icons/stop.png");
this.add(stopIcon);
volumeIcon = new VolumeJSlider(1, 100, 50);
volumeIcon.setPreferredSize(new Dimension(80, 20));
VolumeListener volumeListener = new VolumeListener();
volumeIcon.addMouseListener(volumeListener);
this.add(volumeIcon);
}
/**
* stopd moving bar when stop button clicked
*/
public void stopMovingBar() {
timer.stop();
movingBarIcon.setValue(0);
}
/**
* stopd moving bar when pause button clicked
*/
public void stopMovingBar2() {
timer.stop();
}
/**
* creating moving bar and add to south panel
*
* @param size a integer who size of moving bar
*/
public void addMovingBar(int size) {
int min = size / 60;
int sec = size % 60;
String jlabelText = min + ":" + sec;
totalTime = new JLabel(jlabelText);
totalTime.setForeground(Color.GREEN);
movingBarIcon = new MovingBarJslider(1, size, 1);
movingBarIcon.setPreferredSize(new Dimension(700, 20));
songTime.setForeground(Color.GREEN);
this.add(songTime);
this.add(movingBarIcon);
this.add(totalTime);
movingbarAlive = 1;
}
/**
* resume moving bar move when resume button clicked
*/
public void resumeMovingBar() {
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent ae) {
counter2++;
int min = counter2 / 60;
int sec = counter2 % 60;
if (counter2 < 10)
timeValue = "00:0" + counter2;
else if (counter2 < 60)
timeValue = "00:" + counter2;
else if (counter2 < 70)
timeValue = "0" + min + ":" + "0" + sec;
else if (counter2 < 600)
timeValue = "0" + min + ":" + sec;
else
timeValue = min + ":" + sec;
songTime.setText(timeValue);
movingBarIcon.setValue(counter2);
if (counter2 > movingBarsize) {
timer.stop();
}
}
};
timer = new Timer(1000, listener);
timer.start();
}
/**
* manage moving bar move
*
* @param start value of stating moving bar
* @param size a integer who size of moving bar
*/
public void moveMovingBar(int start, int size) {
counter = start;
firstTime = 0;
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent ae) {
movingBarsize = size;
counter++;
int min = counter / 60;
int sec = counter % 60;
if (counter < 10)
timeValue = "00:0" + counter;
else if (counter < 60)
timeValue = "00:" + counter;
else if (counter < 70)
timeValue = "0" + min + ":" + "0" + sec;
else if (counter < 600)
timeValue = "0" + min + ":" + sec;
else
timeValue = min + ":" + sec;
songTime.setText(timeValue);
movingBarIcon.setValue(counter);
if (counter > size) {
timer.stop();
}
}
};
timer = new Timer(1000, listener);
timer.start();
}
/**
* paused moving bar when pause button clicked
*/
public void pauseMovingBar() {
if (firstTime == 0)
counter2 = counter;
timer.stop();
firstTime++;
}
/**
* removing moving bar wheen new song played
*/
public void removeMovingBar() {
if (movingbarAlive == 1) {
timer.stop();
this.remove(totalTime);
this.remove(movingBarIcon);
this.remove(songTime);
}
}
/**
* removing artwork wheen new song played
*/
public void removeArtwork() {
if (songNameIsAlive == 1) {
this.remove(songName);
this.remove(jButton);
this.remove(songArtist);
}
songNameIsAlive = 0;
}
/**
* adding moving bar wheen new song played
*
* @param song a Song who adding artwork
*/
public void addArtwork(Song song) {
songNameIsAlive = 1;
Image temp = new ImageIcon(song.getImageData()).getImage().getScaledInstance(60, 60, Image.SCALE_DEFAULT);
jButton = new JButton();
jButton.setBorderPainted(false);
jButton.setFocusPainted(false);
jButton.setIcon(new ImageIcon(temp));
jButton.setBackground(Color.GREEN);
this.add(jButton);
songArtist = new Label(song.getArtistName());
songArtist.setForeground(Color.GREEN);
this.add(songArtist, FlowLayout.LEFT);
songName = new Label(song.getName());
songName.setForeground(Color.GREEN);
this.add(songName, FlowLayout.LEFT);
// jButton=new JButton("123");
// this.add(jButton,FlowLayout.LEFT);
this.setVisible(false);
this.setVisible(true);
}
public IconForButton getStopIcon() {
return stopIcon;
}
public IconForButton getPlayIcon() {
return playIcon;
}
public IconForButton getNextIcon() {
return nextIcon;
}
public IconForButton getPreviousIcon() {
return previousIcon;
}
public IconForButton getAddTofavorite() {
return addTofavorite;
}
private static class VolumeListener implements MouseListener {
@Override
public void mouseClicked(MouseEvent e) {
Audio.setMasterOutputVolume(((float) volumeIcon.getValue() / 100));
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
Audio.setMasterOutputVolume(((float) volumeIcon.getValue() / 100));
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
}
}