This repository has been archived by the owner on Sep 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUIManager.java
108 lines (92 loc) · 3.27 KB
/
GUIManager.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template data, choose Tools | Templates
* and open the template in the editor.
*/
package ru.AARomanov1985.weatherviewer;
import java.awt.Dimension;
import java.io.File;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import ru.AARomanov1985.weatherviewer.controller.Controller;
import ru.AARomanov1985.weatherviewer.view.*;
/**
*
* @author raan
*/
public class GUIManager {
private Controller controller = Controller.getInstance();
private GUIManager() {
}
private static GUIManager instance;
public static GUIManager getInstance() {
if (instance == null) {
instance = new GUIManager();
}
return instance;
}
private GlobalWindow generalWindow;
private AboutAppDialog aboutAppDialog = new AboutAppDialog(generalWindow, null, true);
private JTable table;
public GlobalWindow getGeneralWindow() {
return generalWindow;
}
public void drawGeneralWindow() {
new Runnable() {
@Override
public void run() {
if (generalWindow == null) {
generalWindow = new GlobalWindow();
generalWindow.init();
}
}
}.run();
}
public AboutAppDialog getAboutAppDialog() {
return aboutAppDialog;
}
public void drawAboutAppDialog() {
//aboutAppDialog = new AboutAppDialog(generalWindow, null, true);
aboutAppDialog.setVisible(true);
}
public File openFile() {
JFileChooser fch = new JFileChooser();
fch.showOpenDialog(fch);
disableTable();
return fch.getSelectedFile();
}
public void drawTable() {
new Runnable() {
@Override
public void run() {
String[][] data = controller.getData();
String[] columns = controller.getColumns();
if (data != null && columns != null) {
table = new JTable(data, columns);
generalWindow.setPreferredSize(new Dimension(1024, 600));
generalWindow.pack();
generalWindow.setVisible(true);
generalWindow.add(table);
JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVisible(true);
generalWindow.add(scrollPane);
generalWindow.setExtendedState(generalWindow.getExtendedState() | JFrame.MAXIMIZED_BOTH);
generalWindow.repaint();
} else {
System.out.println("Неверный формат");
}
}
}.run();
}
public void disableTable() {
generalWindow.dispose();
drawGeneralWindow();
}
public void drawError(Throwable err) {
JDialog dialog = new ErrorDialog(generalWindow, err.getMessage(), true);
dialog.setVisible(true);
}
}