diff --git a/src/main/java/ru/egspt/AccessPane.java b/src/main/java/ru/egspt/AccessPane.java index 4f7d437..a85df15 100644 --- a/src/main/java/ru/egspt/AccessPane.java +++ b/src/main/java/ru/egspt/AccessPane.java @@ -2,11 +2,9 @@ package ru.egspt; import javax.swing.JPanel; import java.awt.Color; import javax.swing.JButton; -import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; -import javax.swing.WindowConstants; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; @@ -23,7 +21,7 @@ public class AccessPane extends JPanel { private JButton connButton = new JButton("Подключиться"); private JButton DisconnButton = new JButton("Отключиться"); - public AccessPane(Base base, Data data, ReportPane reportPane){ + public AccessPane(App app){ loginField.setText("esoe");//значения по умолчанию linkField.setText("www.egspt.ru");//значения по умолчанию this.add(loginLabel); @@ -34,16 +32,17 @@ public class AccessPane extends JPanel { this.add(linkField); //настройка кнопки connButton this.add(connButton); - connButton.addActionListener(e -> BaseControls.ConnectToServer(base, data, this, reportPane)); + connButton.addActionListener(e -> BaseControls.ConnectToServer(app)); //настройка кнопки отключения от базы this.add(DisconnButton); - DisconnButton.addActionListener(e -> BaseControls.DisconnectFromServer(base)); + DisconnButton.addActionListener(e -> BaseControls.DisconnectFromServer(app)); TitledBorder border = new TitledBorder(new LineBorder(Color.black), "connection to mysql", TitledBorder.CENTER, TitledBorder.CENTER); this.setBorder(border); //this.setBorder(BorderFactory.createTitledBorder("аккаунт сервера базы данных")); this.setSize(320, 240); this.setVisible(true); } + /** * @return the loginField */ @@ -63,15 +62,7 @@ public class AccessPane extends JPanel { return linkField; } public static void main( String[] args ){ - Base base = new Base(); - //Data data; - System.out.println( "Проверка работоспособности класса Account ..." ); - JFrame mainframe = new JFrame("connaction"); - AccessPane acc = new AccessPane(base); - mainframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - mainframe.add(acc); - mainframe.setSize(320, 240); - mainframe.setVisible(true); + } } diff --git a/src/main/java/ru/egspt/App.java b/src/main/java/ru/egspt/App.java index 8ce63a9..4c308ba 100644 --- a/src/main/java/ru/egspt/App.java +++ b/src/main/java/ru/egspt/App.java @@ -8,16 +8,17 @@ import javax.swing.WindowConstants; * Основной класс сборки приложения */ public class App extends JPanel{ - public Base base = new Base(); - public Data data = new Data(); - public ReportPane rp = new ReportPane(); - public AccessPane ap = new AccessPane(base, data, rp); - public TagPane tp = new TagPane(base, new TagModel()); + private Base base = new Base(); + private Data data = new Data(); + private TagModel tagModel = new TagModel(); + private ReportPane reportPane = new ReportPane(this); + private AccessPane accessPane = new AccessPane(this); + private TagPane tagPane = new TagPane(this); public void init(){ - this.add(ap); - this.add(tp); - this.add(rp); + this.add(getAccessPane()); + this.add(getTagPane()); + this.add(getReportPane()); this.setVisible(true); } public void initFrame(){ @@ -27,6 +28,42 @@ public class App extends JPanel{ mainframe.setSize(640, 480); mainframe.setVisible(true); } + /** + * @return the base + */ + public Base getBase() { + return base; + } + /** + * @return the data + */ + public Data getData() { + return data; + } + /** + * @return the tagModel + */ + public TagModel getTagModel() { + return tagModel; + } + /** + * @return the accessPane + */ + public AccessPane getAccessPane() { + return accessPane; + } + /** + * @return the reportPane + */ + public ReportPane getReportPane() { + return reportPane; + } + /** + * @return the tagPane + */ + public TagPane getTagPane() { + return tagPane; + } public static void main( String[] args ) { System.out.println( "Работает подготовщик отчетов по результатам тестирования пользователей ..." ); diff --git a/src/main/java/ru/egspt/BaseControls.java b/src/main/java/ru/egspt/BaseControls.java index 6ae4066..2f1b8cc 100644 --- a/src/main/java/ru/egspt/BaseControls.java +++ b/src/main/java/ru/egspt/BaseControls.java @@ -2,23 +2,26 @@ package ru.egspt; public class BaseControls { // - public static void ConnectToServer(Base base, Data data, AccessPane accessPane, ReportPane reportPane){ + public static void ConnectToServer(App app){ System.out.println("Инициировано событие ConnectToServer ..."); - String link = accessPane.getLinkField().getText(); - base.getAccess().setLink(link); - String login = accessPane.getLoginField().getText(); - base.getAccess().setLogin(login); - String password = String.valueOf(accessPane.getPassField().getPassword()); - base.getAccess().setPassword(password); - base.connect();//подключиться к базе - data.setUsersFromBase(base); - //данные в консоль - //data.getUsersToConsole(data.getUsers()); + String link = app.getAccessPane().getLinkField().getText(); + app.getBase().getAccess().setLink(link); + String login = app.getAccessPane().getLoginField().getText(); + app.getBase().getAccess().setLogin(login); + String password = String.valueOf(app.getAccessPane().getPassField().getPassword()); + app.getBase().getAccess().setPassword(password); + app.getBase().connect();//подключиться к базе + app.getData().setUsersFromBase(app.getBase()); + app.getData().getUsersToConsole(app.getData().getUsers()); //данные в панель отчетов - reportPane.setData(data); + app.getReportPane().init(); + app.getReportPane().setData(app.getData()); + app.getReportPane().setVisible(true); + } - public static void DisconnectFromServer(Base base){ + + public static void DisconnectFromServer(App app){ System.out.println("Инициировано событие DisconnectFromServer ..."); - base.disconnect(); + app.getBase().disconnect(); } } diff --git a/src/main/java/ru/egspt/Data.java b/src/main/java/ru/egspt/Data.java index b5cfe02..2924ac5 100644 --- a/src/main/java/ru/egspt/Data.java +++ b/src/main/java/ru/egspt/Data.java @@ -1,4 +1,3 @@ package ru.egspt; public class Data extends UserListModel{ - } diff --git a/src/main/java/ru/egspt/ReportPane.java b/src/main/java/ru/egspt/ReportPane.java index 7d15aa1..89c1bb9 100644 --- a/src/main/java/ru/egspt/ReportPane.java +++ b/src/main/java/ru/egspt/ReportPane.java @@ -11,11 +11,23 @@ import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; public class ReportPane extends JPanel{ - JPanel controlPane = new JPanel();//панель кнопок - пока не надо - JButton generateXLSXButton = new JButton("create xlsx"); - JButton generateTXTButton = new JButton("create txt"); - JPanel tabPane = new JPanel();//панель таблицы - public ReportPane(){ + private JPanel controlPane = new JPanel();//панель кнопок - пока не надо + private JButton generateXLSXButton = new JButton("create xlsx"); + private JButton generateTXTButton = new JButton("create txt"); + private JPanel tabPane = new JPanel();//панель таблицы + private JTable table; + private ReportTableModel tableModel; + public ReportPane(){} + public ReportPane(App app){ + tableModel = new ReportTableModel(app.getData()); + table = new JTable(tableModel); + table.setPreferredScrollableViewportSize(new Dimension(500, 70)); + table.setFillsViewportHeight(true); + JScrollPane scrollPane = new JScrollPane(table); + tabPane.add(scrollPane); + } + + public void init(){ controlPane.add(generateXLSXButton); controlPane.add(generateTXTButton); this.add(controlPane); @@ -25,10 +37,13 @@ public class ReportPane extends JPanel{ this.setVisible(true); } public void setData(Data data){ - JTable table = new JTable(new ReportTableModel(data)); - table.setPreferredScrollableViewportSize(new Dimension(500, 70)); - table.setFillsViewportHeight(true); - JScrollPane scrollPane = new JScrollPane(table); - tabPane.add(scrollPane); + getTableModel().setData(data); } + /** + * @return the tableModel + */ + public ReportTableModel getTableModel() { + return tableModel; + } + } diff --git a/src/main/java/ru/egspt/ReportTableModel.java b/src/main/java/ru/egspt/ReportTableModel.java index a2a6ce1..ffe18bf 100644 --- a/src/main/java/ru/egspt/ReportTableModel.java +++ b/src/main/java/ru/egspt/ReportTableModel.java @@ -6,16 +6,8 @@ public class ReportTableModel extends AbstractTableModel{ private String[] header = {"id", "login", "mail"}; private Object[][] data; public ReportTableModel(Data data){ - //заполняем модель данными - int i = 0; - while (i < data.getUsers().size()){ - this.data[0][i] = data.getUsers().get(i).getId(); - this.data[1][i] = data.getUsers().get(i).getLogin(); - this.data[2][i] = data.getUsers().get(i).getMail(); - i++; - } + setData(data); } - @Override public int getRowCount() { return getData().length; @@ -37,10 +29,23 @@ public class ReportTableModel extends AbstractTableModel{ return data; } /** - * @param data the data to set + * */ - public void setData(Object[][] data) { - this.data = data; + public void setData(Data data) { + //создаем объект data - инициализация переменной + int row = 0; + row = data.getUsers().size(); + int col = 3;//по количеству заголовков + this.data = new Object[row][col]; + //заполняем модель данными пользователей + int i = 0; + while (i < data.getUsers().size()){ + this.data[i][0] = data.getUsers().get(i).getId(); + this.data[i][1] = data.getUsers().get(i).getLogin(); + this.data[i][2] = data.getUsers().get(i).getMail(); + i++; + this.fireTableDataChanged(); + } } /** * @return the header diff --git a/src/main/java/ru/egspt/TagControls.java b/src/main/java/ru/egspt/TagControls.java index 323dabc..3212917 100644 --- a/src/main/java/ru/egspt/TagControls.java +++ b/src/main/java/ru/egspt/TagControls.java @@ -2,38 +2,30 @@ package ru.egspt; public class TagControls { //добавляем тег в модель - public static void addTag(Base base, TagModel tm, TagPane tp){ + public static void addTag(App app){ //тег в модель - tm.addTag(tp.getCurrentTag()); + app.getTagModel().addTag(app.getTagPane().getCurrentTag()); //обновляем текстовую область - tp.updateTagArea(tm); - //tp.getTagArea().update(tp.getTagArea().getGraphics()); - tp.getCurrentTagField().setText(""); - //выводим пользователей в консоль - UserListModel ul = new UserListModel(); - ul.setUsersFromBase(base); - int i = 0; - while (i < ul.getUsers().size()){ - System.out.println(ul.getUsers().get(i).getLogin()); - i++; - } - } - //добавляем тег в модель - public static void addTag(TagModel tm, TagPane tp){ - //тег в модель - tm.addTag(tp.getCurrentTag()); - //обновляем текстовую область - tp.updateTagArea(tm); - //tp.getTagArea().update(tp.getTagArea().getGraphics()); - tp.getCurrentTagField().setText(""); + app.getTagPane().updateTagArea(app.getTagModel()); + app.getTagPane().getCurrentTagField().setText(""); + //Выводим пользователей в отчет + Data data = new Data(); + data.setUsers(app.getData().getUsersByTag(app.getData().getUsers(), app.getTagModel())); + app.getReportPane().setData(data); + app.getReportPane().getTableModel().fireTableDataChanged(); } //удаляем тег из модели - public static void removeTag(TagModel tm, TagPane tp){ + public static void removeTag(App app){ //удаляем тег из модели - tm.removeTag(tp.getCurrentTag()); + app.getTagModel().removeTag(app.getTagPane().getCurrentTag()); //обновляем текстовую область - tp.updateTagArea(tm); + app.getTagPane().updateTagArea(app.getTagModel()); //tp.getTagArea().update(tp.getTagArea().getGraphics()); - tp.getCurrentTagField().setText(""); + app.getTagPane().getCurrentTagField().setText(""); + //Выводим пользователей в отчет + Data data = new Data(); + data.setUsers(app.getData().getUsersByTag(app.getData().getUsers(), app.getTagModel())); + app.getReportPane().setData(data); + app.getReportPane().getTableModel().fireTableDataChanged(); } } diff --git a/src/main/java/ru/egspt/TagPane.java b/src/main/java/ru/egspt/TagPane.java index f161602..03c5760 100644 --- a/src/main/java/ru/egspt/TagPane.java +++ b/src/main/java/ru/egspt/TagPane.java @@ -1,12 +1,10 @@ package ru.egspt; import javax.swing.JButton; -import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; -import javax.swing.WindowConstants; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; import java.awt.Color; @@ -17,36 +15,18 @@ public class TagPane extends JPanel{ private JButton addTagButton = new JButton("Добавить"); private JButton removeTagButton = new JButton("Удалить"); private JTextArea tagArea = new JTextArea(); - public TagPane(Base base, TagModel tm){ + public TagPane(App app){ this.add(newTagLabel); this.add(CurrentTagField); this.add(addTagButton); - addTagButton.addActionListener(e -> TagControls.addTag(base, tm, this)); + addTagButton.addActionListener(e -> TagControls.addTag(app)); this.add(removeTagButton); - removeTagButton.addActionListener(e -> TagControls.removeTag(tm, this)); + removeTagButton.addActionListener(e -> TagControls.removeTag(app)); //заполняем tagArea tagArea.setText("Перечень тегов:"); int i = 0; - while (i < tm.getTags().size()){ - tagArea.append(tm.getTags().get(i)); - i++; - } - this.add(tagArea); - TitledBorder border = new TitledBorder(new LineBorder(Color.black), "tag-controls", TitledBorder.CENTER, TitledBorder.CENTER); - this.setBorder(border); - } - public TagPane(TagModel tm){ - this.add(newTagLabel); - this.add(CurrentTagField); - this.add(addTagButton); - addTagButton.addActionListener(e -> TagControls.addTag(tm, this)); - this.add(removeTagButton); - removeTagButton.addActionListener(e -> TagControls.removeTag(tm, this)); - //заполняем tagArea - tagArea.setText("Перечень тегов:"); - int i = 0; - while (i < tm.getTags().size()){ - tagArea.append(tm.getTags().get(i)); + while (i < app.getTagModel().getTags().size()){ + tagArea.append(app.getTagModel().getTags().get(i)); i++; } this.add(tagArea); @@ -80,16 +60,4 @@ public class TagPane extends JPanel{ public JTextField getCurrentTagField() { return CurrentTagField; } - public static void main( String[] args ){ - //Base base = new Base(); - //Data data; - TagModel tm = new TagModel(); - System.out.println( "Проверка работоспособности класса TagPane ..." ); - JFrame mainframe = new JFrame("TagPane-test"); - TagPane tp = new TagPane(tm); - mainframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - mainframe.add(tp); - mainframe.setSize(320, 240); - mainframe.setVisible(true); - } } diff --git a/src/main/java/ru/egspt/UserListModel.java b/src/main/java/ru/egspt/UserListModel.java index 58dee03..6979625 100644 --- a/src/main/java/ru/egspt/UserListModel.java +++ b/src/main/java/ru/egspt/UserListModel.java @@ -4,7 +4,7 @@ import java.sql.ResultSet; import java.util.ArrayList; public class UserListModel { - private ArrayList users; + private ArrayList users = new ArrayList<>(); public UserListModel(){ } /** diff --git a/target/classes/ru/egspt/AccessPane.class b/target/classes/ru/egspt/AccessPane.class index ba8412a..f69b8f9 100644 Binary files a/target/classes/ru/egspt/AccessPane.class and b/target/classes/ru/egspt/AccessPane.class differ diff --git a/target/classes/ru/egspt/App.class b/target/classes/ru/egspt/App.class index d00d415..87a1265 100644 Binary files a/target/classes/ru/egspt/App.class and b/target/classes/ru/egspt/App.class differ diff --git a/target/classes/ru/egspt/BaseControls.class b/target/classes/ru/egspt/BaseControls.class index ac62d07..797702d 100644 Binary files a/target/classes/ru/egspt/BaseControls.class and b/target/classes/ru/egspt/BaseControls.class differ diff --git a/target/classes/ru/egspt/ReportPane.class b/target/classes/ru/egspt/ReportPane.class index 8c3f8f4..5c9e198 100644 Binary files a/target/classes/ru/egspt/ReportPane.class and b/target/classes/ru/egspt/ReportPane.class differ diff --git a/target/classes/ru/egspt/ReportTableModel.class b/target/classes/ru/egspt/ReportTableModel.class index e54398c..0710ca6 100644 Binary files a/target/classes/ru/egspt/ReportTableModel.class and b/target/classes/ru/egspt/ReportTableModel.class differ diff --git a/target/classes/ru/egspt/TagControls.class b/target/classes/ru/egspt/TagControls.class index 6185d55..0af4d79 100644 Binary files a/target/classes/ru/egspt/TagControls.class and b/target/classes/ru/egspt/TagControls.class differ diff --git a/target/classes/ru/egspt/TagPane.class b/target/classes/ru/egspt/TagPane.class index ca6bc3a..cd15688 100644 Binary files a/target/classes/ru/egspt/TagPane.class and b/target/classes/ru/egspt/TagPane.class differ diff --git a/target/classes/ru/egspt/UserListModel.class b/target/classes/ru/egspt/UserListModel.class index 86b3de5..7e435d3 100644 Binary files a/target/classes/ru/egspt/UserListModel.class and b/target/classes/ru/egspt/UserListModel.class differ