-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.java
More file actions
238 lines (209 loc) · 6.79 KB
/
View.java
File metadata and controls
238 lines (209 loc) · 6.79 KB
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package aoop;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.text.NumberFormat;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSlider;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
/**
* View of MVC pattern
* @author Daniel and Erik
*/
public class View extends JFrame
{
public View()
{}
/**
* adds Model of MVC pattern
* @param m model
*/
public void addModel(Model m)
{
this.m = m;
}
/**
* adds Controller of MVC pattern
* @param c Controller
*/
public void addController(Controller c)
{
this.c = c;
}
/**
* Builds view
*/
public void build()
{
/* Initializing components */
toolBar = new ToolBar(m, c);
popup = new JPopupMenu();
apply = new JButton();
wNPopup = new JPopupMenu();
wNSlider = new JSlider();
wNApply = new JButton("Create White Noise");
Menu menu = new Menu(m, c);
JPanel main = new JPanel();
main.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED) );
JButton play = new JButton();
JPanel southPanel = new JPanel();
southPanel.add(play);
/* Configuring frames */
setJMenuBar(menu);
setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setPreferredSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
setTitle("Sound Filtering");
/* setting up scalable filter popup */
apply.setText("apply");
play.addActionListener(c.getPlayListener());
play.setText("PLAY");
scaleSlider = new JSlider();
scaleSlider.setBorder( new CompoundBorder(new TitledBorder("Scale"),
new EmptyBorder(10, 10, 10, 10) )
);
apply.addActionListener(c.getApplyScalableFilterListener(scaleSlider));
popup.add(scaleSlider);
popup.add(apply);
buildKarplusView();
/* setting up create white noise popup */
wNPopup.add(wNSlider);
wNPopup.add(wNApply);
wNSlider.setBorder( new CompoundBorder(
new TitledBorder("Duration"),
new EmptyBorder(10, 10, 10, 10) )
);
wNApply.addActionListener(c.getCreateWhiteNoise(wNSlider));
/*Building new Sound frame */
newSound = buildNewToneFrame();
/* Adding components to frame */
add(toolBar,BorderLayout.NORTH);
add(main, BorderLayout.CENTER);
add(southPanel, BorderLayout.SOUTH);
/* Adding filters to menu */
toolBar.addFilter(new GainFilter());
Filter f = new KarplusStrongFilter();
toolBar.addFilter(f, c.getKarplusStrongfilterListener(f));
pack();
setVisible(true);
}
/**
* Builds frame for creating a tone
* @return
*/
private JFrame buildNewToneFrame()
{
JFrame frame = new JFrame();
JButton create = new JButton("Create sound");
NumberFormat format = NumberFormat.getNumberInstance();
JFormattedTextField dur = new JFormattedTextField(format);
JFormattedTextField freq = new JFormattedTextField(format);
/* sets up the layout */
frame.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
frame.setTitle("New Sound");
create.addActionListener(this.c.getCreateNewToneListener( freq,
dur
));
c.gridx = 0;
c.gridy = 0;
frame.add(new JLabel("frequency"),c);
c.gridx = 1;
c.ipadx = 80;
frame.add(freq,c);
c.gridx = 0;
c.gridy = 1;
c.ipadx = 0;
frame.add(new JLabel("duration"),c);
c.gridx = 1;
c.ipadx = 80;
frame.add(dur,c);
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 2;
frame.add(create,c);
frame.pack();
return frame;
}
/**
* Builds popup for karplus filter
*/
public void buildKarplusView()
{
JSlider karplusLSlider = new JSlider();
JSlider karplusDampSlider = new JSlider();
JButton karplusApply = new JButton("Apply");
kPopup = new JPopupMenu();
karplusLSlider.setBorder( new CompoundBorder(
new TitledBorder("length"),
new EmptyBorder(10, 10, 10, 10) )
);
karplusDampSlider.setBorder( new CompoundBorder(
new TitledBorder("Damping"),
new EmptyBorder(10, 10, 10, 10) )
);
karplusApply.addActionListener( c.getApplyKarplusFilterListener(
karplusLSlider,
karplusDampSlider)
);
kPopup.add(karplusLSlider);
kPopup.add(karplusDampSlider);
kPopup.add(karplusApply);
}
/**
* Shows popup for creating white noise
*/
public void showWhiteNoiseSlider()
{
wNPopup.show(toolBar, 0, 50);
}
/**
* Shows popup for scalable filters
*/
public void showSlider()
{
popup.show(toolBar, 0, 50);
}
/**
* Shows popup for karplus filter
*/
public void showKarplus()
{
kPopup.show(toolBar,0,50);
}
/**
* Shows new Tone frame
*/
public void showNewTone()
{
newSound.setVisible(true);
}
private Model m;
private Controller c;
private JFrame newSound;
private ToolBar toolBar;
private JPopupMenu popup;
private JSlider scaleSlider;
private JSlider wNSlider;
private JButton apply;
private JButton wNApply;
private JPopupMenu kPopup;
private JPopupMenu wNPopup;
public final int FRAME_WIDTH = 640;
public final int FRAME_HEIGHT = 480;
}