-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatePickerSample.java
171 lines (138 loc) · 4.21 KB
/
DatePickerSample.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
import org.jdatepicker.impl.JDatePanelImpl;
import org.jdatepicker.impl.JDatePickerImpl;
import org.jdatepicker.impl.SqlDateModel;
import javax.swing.*;
import javax.swing.JFormattedTextField.AbstractFormatter;
import javax.swing.text.DateFormatter;
import javax.swing.text.TableView.TableRow;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
public class DatePickerSample extends JFrame implements ActionListener{
public static JDatePickerImpl datePicker;
public static String date="";
public static JButton button;
public static JFrame frame;
public static SimpleDateFormat format;
public static Calendar cal;
public static Main m;
public static String asu_id="";
public static String name="";
public static JDialog d;
public static String time;
public static HashMap<String,String> newMembers = new HashMap<>();
public static int count = 6;
DatePickerSample()
{
frame = new JFrame("Select Date");
SqlDateModel model = new SqlDateModel();
model.setSelected(true);
Properties p = new Properties();
p.put("text.day","Day");
p.put("text.month", "Month");
p.put("text.year", "Year");
button = new JButton("Submit");
button.setBounds(50,80,80,30);
JDatePanelImpl panel = new JDatePanelImpl(model,p);
datePicker = new JDatePickerImpl(panel,new AbstractFormatter() {
@Override
public Object stringToValue(String text) throws ParseException {
// TODO Auto-generated method stub
return null;
}
@Override
public String valueToString(Object value) throws ParseException {
// TODO Auto-generated method stub
if(value!=null)
{
cal = (Calendar) value;
format = new SimpleDateFormat("dd-MMM-yyyy");
String strDate = format.format(cal.getTime());
return strDate;
}
return "";
}
});
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
date = format.format(cal.getTime());
ScatterPlot.Finaldate = date;
frame.dispose();
FillColumn();
}
});
datePicker.setBounds(50, 30, 110, 30);
frame.add(datePicker);
frame.add(button);
frame.setLayout(new BorderLayout());
frame.setSize(300, 300);
frame.setVisible(true);
}
public static void FillColumn()
{
int count = Main.table.getRowCount();
Object[] obj = new Object[count];
for(int i = 0;i<count;i++)
{
obj[i]="0";
}
Main.tableModel.addColumn(date, obj);
Logic();
}
public static void Logic()
{
ScatterPlot.finalPlotvalues = new ArrayList<>();
for(Map.Entry<String,String> it: m.map.entrySet())
{
boolean flag = false;
for(int i =0;i<m.list.size();i++)
{
String[] current = m.list.get(i);
asu_id = current[current.length-1];
name = it.getKey();
time = it.getValue();
if(it.getKey().equals(asu_id))
{
m.tableModel.setValueAt(it.getValue(), i, count);
ScatterPlot.finalPlotvalues.add(time);
flag = true;
break;
}
}
if(flag == false)
{
newMembers.put(name,time);
}
}
int hashMap_size = m.map.size();
int newMembers_size = newMembers.size();
int totalLoadedUsers = hashMap_size - newMembers_size;
StringBuilder sb = new StringBuilder();
int finalTime =0;
if(newMembers_size!=0) {
for(Map.Entry<String,String> iterator: newMembers.entrySet())
{
String name = iterator.getKey();
int time = Integer.valueOf(iterator.getValue());
name = name + ", connected for " + Integer.toString(time) +" minute ; ";
sb.append(name);
}
JOptionPane.showMessageDialog(frame,"Data Loaded for "+ totalLoadedUsers+" users in the roaster\n" + newMembers_size + " additional attendee(s) were found!\n" + sb.toString());
}
count++;
newMembers = new HashMap<>();
Main.map = new HashMap<>();
ScatterPlot.createDataset();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}