-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddSourceDialog.java
More file actions
222 lines (195 loc) · 9.88 KB
/
AddSourceDialog.java
File metadata and controls
222 lines (195 loc) · 9.88 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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* AddSourceDialog.java
*
* Created on 14 déc. 2013, 19:21:36
*/
package com.masim.ui;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDialog;
import com.masim.core.SourceTYpe;
import com.masim.emissionAgents.SourceConfigInfo;
import com.masim.utils.Location;
import com.masim.utils.Pollutant;
import com.masim.utils.PollutantType;
import com.masim.utils.SimulationFramework;
/**
*Add an emission source.
* @author sabri ghazi
*/
public class AddSourceDialog extends javax.swing.JDialog {
/** Creates new form AddSourceDialog */
public AddSourceDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
setTitle("Adding an Emission Source. ");
initComponents();
btn_OK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SourceConfigInfo sci= new SourceConfigInfo();
sci.setSourceName(txt_sourceName.getText());
double d=Double.parseDouble(spin_EmissionRate.getValue().toString());
sci.setEmisionRate(d);
sci.setMaxEmissionRate(d);
sci.setMinEmissionRate(d/8);
int x=Integer.parseInt(txt_X.getText());
int y=Integer.parseInt(txt_Y.getText());
String pollutant=cbx_Pollutant.getSelectedItem().toString();
Pollutant p= new Pollutant(pollutant, pollutant);
sci.setP(getPollutantFromIndex(cbx_Pollutant.getSelectedIndex()));
Location l= new Location(x, y);
sci.setGeoLocation(l);
sci.setIsLocatedOnCbox(null);
sci.setType(SourceTYpe.Point);
try {
SimulationFramework.AddSource(sci);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
setVisible(false);
}
private PollutantType getPollutantFromIndex(int p) {
// "PM10", "O3", "COx", "SOx", "NOx" }
if(p==0 )
return PollutantType.PM10;
else if(p==1)
return PollutantType.O3;
else if (p==2)
return PollutantType.COx;
else if(p==3)
return PollutantType.SOx;
else
return PollutantType.NOx;
}
});
}
/** This method is called from within the constructor to
* initialise the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
btn_OK = new javax.swing.JButton();
txt_sourceName = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
cbx_Pollutant = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
spin_EmissionRate = new javax.swing.JSpinner();
jLabel3 = new javax.swing.JLabel();
txt_X = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
txt_Y = new javax.swing.JTextField();
SourceTypeList = new javax.swing.JComboBox();
jLabel6 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
SourceTypeList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Point", "Line", "Area" }));
jLabel1.setText("Source Type");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
btn_OK.setText("Ok");
jLabel1.setText("Name");
cbx_Pollutant.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PM10", "O3", "COx", "SOx", "NOx" }));
jLabel2.setText("Pollutant");
jLabel3.setText("Emission Rate");
jLabel4.setText("Located in X =");
jLabel5.setText("Y=");
jLabel6.setText("Source Type (Point,Line or Area)");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(btn_OK)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4)
.addComponent(jLabel3)
.addComponent(jLabel2)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(spin_EmissionRate, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cbx_Pollutant, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txt_sourceName, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(txt_X, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel5)
.addGap(18, 18, 18)
.addComponent(txt_Y, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_sourceName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbx_Pollutant, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(57, 57, 57)
.addComponent(btn_OK))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(spin_EmissionRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_X, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt_Y, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addComponent(jLabel4))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
AddSourceDialog dialog = new AddSourceDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
public javax.swing.JButton btn_OK;
public javax.swing.JComboBox cbx_Pollutant;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
public javax.swing.JSpinner spin_EmissionRate;
public javax.swing.JTextField txt_X;
public javax.swing.JTextField txt_Y;
private javax.swing.JTextField txt_sourceName;
private javax.swing.JComboBox SourceTypeList;
private javax.swing.JLabel jLabel6;
// End of variables declaration//GEN-END:variables
}