-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFrame.java
More file actions
553 lines (472 loc) · 17.4 KB
/
Copy pathMainFrame.java
File metadata and controls
553 lines (472 loc) · 17.4 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
package quest;
/*
* This file contains main function of QUEST.
* It initializes all all panel object used in tabbed pane.
*/
import iisc.dsl.picasso.server.PicassoException;
import iisc.dsl.picasso.server.query.Query;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.TextAttribute;
import java.io.File;
import java.net.URL;
import java.util.Arrays;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.panayotis.gnuplot.swing.JPlot;
public class MainFrame implements ActionListener, ChangeListener, WindowListener
{
AllObjects allObjects;
JFrame frame;
JTabbedPane allTabs;
JPanel listPanel;
JButton btnEnter;
JTextArea queryInputTextArea;
JTextField path;
JCheckBox chkBoxPicasso;
public boolean tabbedPaneOpenFirstTime[];
public MainFrame()
{
/*
* AllObject is initialized.
*/
allObjects = new AllObjects();
allObjects.setMainFrameObj(this);
/*
* Database connection object is created.
*/
ConnectDB connectDBObj = new ConnectDB(allObjects);
connectDBObj.connectDB();
/*
* Getting resolution of screen
*/
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
QUESTConstants.SCREEN_WIDTH = screenSize.getWidth();
QUESTConstants.SCREEN_HEIGHT = screenSize.getHeight();
/*
* Based on screen resolution other components' size is decided.
*/
QUESTConstants.HEAD_PANEL_HEIGHT = (int)QUESTConstants.SCREEN_HEIGHT / 17;
QUESTConstants.INPUT_PANEL_HEIGHT = (int)QUESTConstants.SCREEN_HEIGHT / 25;
QUESTConstants.STATUS_PANEL_HEIGHT = (int)QUESTConstants.SCREEN_HEIGHT / 34;
QUESTConstants.STATUS_PANEL_FONT_SIZE = QUESTConstants.STATUS_PANEL_HEIGHT/2;
}
public static void main(String args[])
{
/* show splash screen before main window */
// try
// {
// UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
// }
// catch (Exception e) {
// System.out.println("Unable to load required look and feel");
// }
// new SplashScreen().setVisible(true);
MainFrame obj = new MainFrame();
obj.mainFrame();
}
void mainFrame()
{
int headPanelFont;
headPanelFont = (int)(QUESTConstants.HEAD_PANEL_HEIGHT * 0.4);
URL dslurl;
URL iiscurl = null;
Image dslLogoImage=null;
Image iiscLogoImage=null;
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
e.printStackTrace();
}
/*
* path of DSL and IISc logo is given.
*/
try
{
dslurl = getClass().getClassLoader().getResource("images/DSLLogo.png");
iiscurl = getClass().getClassLoader().getResource("images/iisc_logo.jpeg");
dslLogoImage = ImageIO.read(new File(dslurl.getPath()));
dslLogoImage = dslLogoImage.getScaledInstance(-1, QUESTConstants.HEAD_PANEL_HEIGHT, Image.SCALE_SMOOTH);
iiscLogoImage = ImageIO.read(new File(iiscurl.getPath()));
iiscLogoImage = iiscLogoImage.getScaledInstance(-1, QUESTConstants.HEAD_PANEL_HEIGHT, Image.SCALE_SMOOTH);
}
catch (Exception e)
{
e.printStackTrace();
}
JLabel dsl;
JLabel iisc;
dsl=new JLabel(new ImageIcon(dslLogoImage));
iisc=new JLabel(new ImageIcon(iiscLogoImage));
JLabel nameLabel = new JLabel("QUEST (QUery Execution without Selectivity esTimation)");
nameLabel.setFont(new Font(QUESTConstants.TEXT_FONT, Font.BOLD, headPanelFont));
nameLabel.setForeground(Color.WHITE);
nameLabel.setToolTipText("QUEST for PostgreSQL9.3.4");
/*
* head panel is top panel that contains two logo and QUEST title.
*/
JPanel headPanel = new JPanel();
headPanel.setBackground(new Color(QUESTConstants.backgroundColor1));
headPanel.setPreferredSize(new Dimension(100,QUESTConstants.HEAD_PANEL_HEIGHT)); //for demo
// headPanel.setPreferredSize(new Dimension(100,60));
headPanel.setLayout(new BoxLayout(headPanel, BoxLayout.X_AXIS));
headPanel.add(dsl);
headPanel.add(Box.createGlue());
headPanel.add(nameLabel);
headPanel.add(Box.createGlue());
headPanel.add(iisc);
btnEnter = QUESTUtility.createButton("Start Quest", QUESTConstants.BUTTON_FONT_SIZE);
btnEnter.addActionListener(this);
btnEnter.setEnabled(true);
chkBoxPicasso = new JCheckBox("Picasso");
chkBoxPicasso.setSelected(true);
/*
* list panel contains two input buttons and list for selectivities.
*/
listPanel = new JPanel();
listPanel.setPreferredSize(new Dimension(150, 300));
// listPanel.setMaximumSize(listPanel.getPreferredSize());
listPanel.setBackground(new Color(QUESTConstants.backgroundColor2));
listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.Y_AXIS));
listPanel.add(Box.createGlue());
listPanel.add(btnEnter);
listPanel.add(Box.createGlue());
listPanel.add(chkBoxPicasso);
/*
* query input text is initialized.
*/
queryInputTextArea = new JTextArea("Enter SQL query",5,100);
queryInputTextArea.setFont(new Font("Serif", Font.PLAIN, 22));
queryInputTextArea.setLineWrap(true);
queryInputTextArea.selectAll();
// String str_query = "select \n" +
// "n_name,\n" +
// "sum(l_extendedprice * (1 - l_discount)) as revenue \n"+
// "from \n" +
// "customer, orders, lineitem, supplier, nation, region \n"+
// "where \n" +
// "c_custkey = o_custkey \n"+
// "and l_orderkey = o_orderkey \n"+
// "and l_suppkey = s_suppkey \n" +
// "and c_nationkey = s_nationkey \n" +
// "and s_nationkey = n_nationkey \n" +
// "and n_regionkey = r_regionkey \n" +
// "and (r_name='ASIA' or r_name='AFRICA') \n"+
// "and o_orderdate >= date '1994-01-01' \n" +
// "and o_orderdate < date '1994-01-01' + interval '1 year' \n"+
// "and l_shipdate <= l_receiptdate \n" +
// "and l_commitdate <= l_shipdate + integer '90' \n"+
// "and l_extendedprice <= 20000 \n" +
// "and substring(c_name from 1 for 4) = 'Cust' \n" +
// "and c_acctbal <=4500 \n" +
// "group by \n" +
// "n_name \n" +
// "order by \n" +
// "revenue desc";
String str_query = "select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue from customer, orders, lineitem, supplier, nation, region where c_custkey = o_custkey" +
" and l_orderkey = o_orderkey and l_suppkey = s_suppkey and c_nationkey = s_nationkey and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = 'ASIA' " +
" and o_orderdate >= '1994-01-01' and o_orderdate < '1995-01-01' and c_acctbal :varies and s_acctbal :varies group by n_name order by revenue desc";
queryInputTextArea.setText(str_query);
JScrollPane queryInputScrollPanel = new JScrollPane(queryInputTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
queryInputScrollPanel.setMaximumSize(new Dimension(1500, 600));
/*
* query panel top panel that contains list panel and query input text area.
*/
JPanel queryPanel = new JPanel();
queryPanel.setBackground(new Color(QUESTConstants.backgroundColor2));
queryPanel.setLayout(new BorderLayout());
queryPanel.add(BorderLayout.WEST, listPanel);
queryPanel.add(BorderLayout.CENTER, queryInputScrollPanel);
allTabs = new JTabbedPane();
Border roundedBorder = new LineBorder(Color.BLACK, 2, true);
allTabs.setBorder(roundedBorder);
NativeOptimizerPanel natOptObj = new NativeOptimizerPanel(allObjects);
CostDiagramPanel costDigObj = new CostDiagramPanel(allObjects);
BouquetPanel bouquetPanelObj = new BouquetPanel(allObjects);
PerformanceComparisionPanel execResultPanelObj = new PerformanceComparisionPanel(allObjects);
JPanel bouquetPanel = new JPanel();
bouquetPanel.setLayout(new BorderLayout());
allTabs.addTab("Query Input", queryPanel);
allTabs.addTab(" ", new JPanel());
allTabs.addTab("Native Sub-optimality", natOptObj.mainPanel);
allTabs.addTab(" ", new JPanel());
allTabs.addTab("Bouquet Identification", costDigObj.mainPanel);
allTabs.addTab("Bouquet Execution", bouquetPanelObj.mainPanel);
allTabs.addTab("Performance Comparison", execResultPanelObj.mainPanel);
allTabs.setEnabledAt(QUESTConstants.EMPTY_PANE1, false);
allTabs.setEnabledAt(QUESTConstants.NATIVE_PANE, false);
allTabs.setEnabledAt(QUESTConstants.EMPTY_PANE2, false);
allTabs.setEnabledAt(QUESTConstants.BOUQUET_IDNT_PANE, false);
allTabs.setEnabledAt(QUESTConstants.BOUQUET_PANE, false);
allTabs.setEnabledAt(QUESTConstants.RESULT_PANE, false);
allTabs.setFont(new Font("Arial",Font.BOLD,14)); // set from 18 to 14 to handle laptop resolution issue
allTabs.addChangeListener(this);
tabbedPaneOpenFirstTime = new boolean[QUESTConstants.TOTAL_PANE];
Arrays.fill(tabbedPaneOpenFirstTime, true);
frame = new JFrame("QUEST");
/* added by rajmohan in july 2014 */
/* gives default focus of window to textarea at startup so that query
* can be entered easily */
frame.addWindowListener( new WindowAdapter()
{
public void windowActivated(WindowEvent e)
{
queryInputTextArea.requestFocus();
}
}
);
frame.setLayout(new BorderLayout());
frame.add(BorderLayout.NORTH, headPanel);
frame.add(BorderLayout.CENTER, allTabs);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
if(QUESTConstants.MAXIMISE_WINDOW)
// frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
else
frame.setSize(QUESTConstants.FRAME_WIDTH, QUESTConstants.FRAME_HEIGHT);
/* sets Logo Image for Main window */
if(iiscurl != null)
frame.setIconImage((new ImageIcon(iiscurl)).getImage()); /* added by rajmohan in july 2014 */
frame.addWindowListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == btnEnter)
{
ConnectDB connectDBObj = allObjects.getConnectDBObj();
if(connectDBObj.connection != null)
{
if(chkBoxPicasso.isSelected())
{
JOptionPane.showConfirmDialog(null,"in picasso mode","hi", JOptionPane.OK_CANCEL_OPTION);
String rawQuery = queryInputTextArea.getText();
// String query = str.replaceAll("[\\t\\n\\r]+", " ");
ContoursIdentification.invokeContourGenerator(allObjects, rawQuery);
// ContoursIdentificationFullBlown.invokeContourGenerator(allObjects, rawQuery);
// if(ContoursIdentificationLightWeight.PLOT_REQUIRED)
// {
// JFrame jf = new JFrame();
//
// jf.getContentPane().add(new JButton("I am here!"));
// JPlot jplot = new JPlot(ContoursIdentification.p);
// jplot.plot();
// jf.getContentPane().add(jplot);
// jf.pack();
// jf.setLocationRelativeTo(null);
// jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// jf.setVisible(true);
// }
}
else
{
boolean is_query_valid = analyse_query();
if(is_query_valid)
{
Chooser frame = new Chooser();
check_bouquet_validity(frame.fileName);
}
}
}
else
{
int result = JOptionPane.showConfirmDialog(null,"Restart server and click ok to try again","Error: Server connection failed", JOptionPane.OK_CANCEL_OPTION);
if(result == JOptionPane.OK_OPTION)
{
connectDBObj = new ConnectDB(allObjects);
connectDBObj.connectDB();
}
}
}
}
/* added by Rajmohan in july 2014 */
/* analyses whether given query is valid by checking in PostgreSQL DB */
private boolean analyse_query()
{
String str = queryInputTextArea.getText();
String query = str.replaceAll("[\\t\\n\\r]+", " ");
if(query.equalsIgnoreCase("Enter SQL query") || query.equals(""))
{
JOptionPane.showMessageDialog(new JFrame(), "Please enter the query", "Warning", JOptionPane.WARNING_MESSAGE);
}
else
{
/*
* BouquetData contains all data related to bouquet such as dimension, resolution apkt packet etc.
*/
BouquetData bouquetDataObj = new BouquetData();
allObjects.setBouquetDataObj(bouquetDataObj);
bouquetDataObj.setQuery(query);
/*
* Here
*/
ParseQuery parseQueryObj = new ParseQuery();
boolean successful = parseQueryObj.parseQuery(query, allObjects);
if(successful)
{
// JScrollPane listScrollPane = parseQueryObj.listScrollPanel;
// listScrollPane.setMaximumSize(new Dimension(430,400));
listPanel.revalidate();
allTabs.setEnabledAt(QUESTConstants.EMPTY_PANE1, false);
allTabs.setEnabledAt(QUESTConstants.NATIVE_PANE, false);
allTabs.setEnabledAt(QUESTConstants.EMPTY_PANE2, false);
allTabs.setEnabledAt(QUESTConstants.BOUQUET_IDNT_PANE, false);
allTabs.setEnabledAt(QUESTConstants.BOUQUET_PANE, false);
allTabs.setEnabledAt(QUESTConstants.RESULT_PANE, false);
Arrays.fill(tabbedPaneOpenFirstTime, true);
return true;
}
else
{
JOptionPane.showMessageDialog(new JFrame(), "Invalid Query", "Error", JOptionPane.ERROR_MESSAGE);
}
}
return false;
}
/* added by Rajmohan in july 2014 */
/* Checks whether valid bouquet .apkt file is chosen. If not shows error message */
private void check_bouquet_validity(String bouPath)
{
if(bouPath!=null && !bouPath.equals("") && bouPath.toLowerCase().contains(".apkt"))
{
int index = bouPath.indexOf('.');
bouPath = bouPath.substring(0, index);
BouquetData bouquetDataObj = allObjects.getBouquetDataObj();
bouquetDataObj.setBouquetLocation(bouPath);
try
{
BouquetDriver bouquetDriverObj = new BouquetDriver(allObjects);
boolean result = bouquetDriverObj.readBouquetData(allObjects);
if(result)
{
allTabs.setEnabledAt(QUESTConstants.NATIVE_PANE, true);
if(!bouPath.endsWith("dummy")) // do not enable Bouquet Identification in this case
allTabs.setEnabledAt(QUESTConstants.BOUQUET_IDNT_PANE, true);
allTabs.setEnabledAt(QUESTConstants.BOUQUET_PANE, false);
allTabs.setEnabledAt(QUESTConstants.RESULT_PANE, false);
int dimension = bouquetDataObj.getDimension();
double queryValues[]= new double [dimension];
queryValues[0]=2400;
queryValues[1]=20000;
bouquetDataObj.setQueryValues(queryValues);
/* this enables modifiying query at run time easily
* added by rajmohan on aug 23, 2014 */
tabbedPaneOpenFirstTime[QUESTConstants.NATIVE_PANE] = true;
tabbedPaneOpenFirstTime[QUESTConstants.BOUQUET_IDNT_PANE] = true;
tabbedPaneOpenFirstTime[QUESTConstants.BOUQUET_PANE] = true;
tabbedPaneOpenFirstTime[QUESTConstants.RESULT_PANE] = true;
}
else
{
JOptionPane.showMessageDialog(new JFrame(),
"Packets having more than two error prone selectivities. QUEST execute query for two error prone selectivity.",
"Warning",
JOptionPane.WARNING_MESSAGE);
}
}
catch(Exception ex)
{
System.out.println("Execption occured in findBouquet:");
ex.printStackTrace();
}
}
else
{
JOptionPane.showMessageDialog(new JFrame(),
"Invalid File Path.",
"Warning",
JOptionPane.WARNING_MESSAGE);
}
}
public void stateChanged(ChangeEvent e)
{
if(allTabs.getSelectedIndex() == QUESTConstants.NATIVE_PANE)
{
if(tabbedPaneOpenFirstTime[QUESTConstants.NATIVE_PANE])
{
NativeOptimizerPanel nativeOptimizerPanelObj = allObjects.getNativeOptimizerPanelObj();
nativeOptimizerPanelObj.addComponentsToPanel(allObjects);
tabbedPaneOpenFirstTime[QUESTConstants.NATIVE_PANE] = false;
}
}
if(allTabs.getSelectedIndex() == QUESTConstants.BOUQUET_IDNT_PANE)
{
if(tabbedPaneOpenFirstTime[QUESTConstants.BOUQUET_IDNT_PANE])
{
CostDiagramPanel costDigObj = allObjects.getCostDiagramPanelObj();
costDigObj.addComponentsToPanel(allObjects);
tabbedPaneOpenFirstTime[QUESTConstants.BOUQUET_IDNT_PANE] = false;
}
}
else if(allTabs.getSelectedIndex() == QUESTConstants.BOUQUET_PANE)
{
if(tabbedPaneOpenFirstTime[QUESTConstants.BOUQUET_PANE])
{
BouquetPanel bouquetPanelObj = allObjects.getBouquetPanelObj();
bouquetPanelObj.initializePanel(allObjects);
bouquetPanelObj.addComponentsToPanel(allObjects);
tabbedPaneOpenFirstTime[QUESTConstants.BOUQUET_PANE] = false;
}
}
else if(allTabs.getSelectedIndex() == QUESTConstants.RESULT_PANE)
{
if(tabbedPaneOpenFirstTime[QUESTConstants.RESULT_PANE])
{
PerformanceComparisionPanel execResultPanelObj = allObjects.getExecutionResultPanelObj();
execResultPanelObj.showResultBarGraph();
tabbedPaneOpenFirstTime[QUESTConstants.RESULT_PANE] = false;
}
}
}
public void windowClosing(WindowEvent e)
{
/* When Quest is exiting, disconnect DB */
ConnectDB connectDBObj = allObjects.getConnectDBObj();
if(connectDBObj.connection != null)
connectDBObj.disconnectDB();
}
public void windowDeactivated(WindowEvent e)
{
}
public void windowDeiconified(WindowEvent e)
{
}
public void windowIconified(WindowEvent e)
{
}
public void windowOpened(WindowEvent e)
{
}
public void windowActivated(WindowEvent e)
{
}
public void windowClosed(WindowEvent e)
{
}
}
/* FILE OPEN DIALOG : To choose apkt file */
class Chooser extends JFrame
{
JFileChooser chooser;
String fileName;
public Chooser()
{
chooser = new JFileChooser();
/* added by rajmohan on july 31, 2014 */
/* Sets this apkt file selected by default. Makes it easy to choose apkt file in nearby dirs too */
chooser.setSelectedFile(new File("/home/dsladmin/quest/picasso/packets/"));
chooser.setDialogTitle("Select bouquet apkt file");
int r = chooser.showOpenDialog(new JFrame());
if (r == JFileChooser.APPROVE_OPTION)
{
fileName = chooser.getSelectedFile().getPath();
}
}
}