Browse Source

reportpane

master
esoe 2 years ago
parent
commit
c86c893753
  1. 19
      src/main/java/ru/egspt/AccessPane.java
  2. 53
      src/main/java/ru/egspt/App.java
  3. 31
      src/main/java/ru/egspt/BaseControls.java
  4. 1
      src/main/java/ru/egspt/Data.java
  5. 35
      src/main/java/ru/egspt/ReportPane.java
  6. 29
      src/main/java/ru/egspt/ReportTableModel.java
  7. 44
      src/main/java/ru/egspt/TagControls.java
  8. 42
      src/main/java/ru/egspt/TagPane.java
  9. 2
      src/main/java/ru/egspt/UserListModel.java
  10. BIN
      target/classes/ru/egspt/AccessPane.class
  11. BIN
      target/classes/ru/egspt/App.class
  12. BIN
      target/classes/ru/egspt/BaseControls.class
  13. BIN
      target/classes/ru/egspt/ReportPane.class
  14. BIN
      target/classes/ru/egspt/ReportTableModel.class
  15. BIN
      target/classes/ru/egspt/TagControls.class
  16. BIN
      target/classes/ru/egspt/TagPane.class
  17. BIN
      target/classes/ru/egspt/UserListModel.class

19
src/main/java/ru/egspt/AccessPane.java

@ -2,11 +2,9 @@ package ru.egspt; @@ -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 { @@ -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 { @@ -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 { @@ -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);
}
}

53
src/main/java/ru/egspt/App.java

@ -8,16 +8,17 @@ import javax.swing.WindowConstants; @@ -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{ @@ -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( "Работает подготовщик отчетов по результатам тестирования пользователей ..." );

31
src/main/java/ru/egspt/BaseControls.java

@ -2,23 +2,26 @@ package ru.egspt; @@ -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();
}
}

1
src/main/java/ru/egspt/Data.java

@ -1,4 +1,3 @@ @@ -1,4 +1,3 @@
package ru.egspt;
public class Data extends UserListModel{
}

35
src/main/java/ru/egspt/ReportPane.java

@ -11,11 +11,23 @@ import javax.swing.border.LineBorder; @@ -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{ @@ -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;
}
}

29
src/main/java/ru/egspt/ReportTableModel.java

@ -6,16 +6,8 @@ public class ReportTableModel extends AbstractTableModel{ @@ -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{ @@ -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

44
src/main/java/ru/egspt/TagControls.java

@ -2,38 +2,30 @@ package ru.egspt; @@ -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();
}
}

42
src/main/java/ru/egspt/TagPane.java

@ -1,12 +1,10 @@ @@ -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{ @@ -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{ @@ -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);
}
}

2
src/main/java/ru/egspt/UserListModel.java

@ -4,7 +4,7 @@ import java.sql.ResultSet; @@ -4,7 +4,7 @@ import java.sql.ResultSet;
import java.util.ArrayList;
public class UserListModel {
private ArrayList<User> users;
private ArrayList<User> users = new ArrayList<>();
public UserListModel(){
}
/**

BIN
target/classes/ru/egspt/AccessPane.class

Binary file not shown.

BIN
target/classes/ru/egspt/App.class

Binary file not shown.

BIN
target/classes/ru/egspt/BaseControls.class

Binary file not shown.

BIN
target/classes/ru/egspt/ReportPane.class

Binary file not shown.

BIN
target/classes/ru/egspt/ReportTableModel.class

Binary file not shown.

BIN
target/classes/ru/egspt/TagControls.class

Binary file not shown.

BIN
target/classes/ru/egspt/TagPane.class

Binary file not shown.

BIN
target/classes/ru/egspt/UserListModel.class

Binary file not shown.
Loading…
Cancel
Save