-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumTableView.java
More file actions
148 lines (104 loc) · 5.03 KB
/
Copy pathSumTableView.java
File metadata and controls
148 lines (104 loc) · 5.03 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
import javax.swing.*;
import javax.swing.event.TableModelEvent;
import javax.swing.table.AbstractTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseWheelEvent;
public class SumTableView extends JPanel {
private JScrollPane totalScrollPane;
private JScrollPane MMUTScrollPane;
private RXTable totalsTable;
private JTable MMUTTable;// material manopera utilaj transport
private TaskView parent;
public SumTableView(TaskView parent) {
this.parent = parent;
this.setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS));
TaskTableCreator taskTableCreator = new TaskTableCreator(parent.getMyModel());
String[] columns = Finals.SUM_TOTAL_TABLE_HEADER;
String[][] data = taskTableCreator.getSumTotalT();
String [] MMUTColumns = Finals.SUM_MMUT_TABLE_HEADER;
String[][] MMUTData = taskTableCreator.getSumMMUTT();
totalsTable = new RXTable(data,columns);
totalsTable.setSelectAllForEdit(true);
totalsTable.getTableHeader().setReorderingAllowed(false);
totalsTable.setRowSelectionAllowed(false);
SumsTableModel stm = new SumsTableModel(data,columns);
totalsTable.setModel(stm);//bellitom azt hogy csak a szrozokat lehet editalni
//jelezd a valtozasokat a szorzokon
Action action = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
TableCellListener tcl = (TableCellListener)e.getSource();
amplifiersEdited(tcl.getColumn(), (String)tcl.getNewValue());
}
};
TableCellListener tcl = new TableCellListener(totalsTable, action);
MMUTTable = new JTable(MMUTData,MMUTColumns);
MMUTTable.getTableHeader().setReorderingAllowed(false);
MMUTTable.setRowSelectionAllowed(false);
//set the editing of cells in mmutable to false
MMUTTableModel mmutTableModel = new MMUTTableModel(MMUTData,MMUTColumns);
MMUTTable.setModel(mmutTableModel);
//MMUTTable.setDefaultEditor(Object.class, null);
//
// https://stackoverflow.com/questions/7433602/how-to-center-in-jtable-cell-a-value
JTableUtilities.setCellsAlignment(totalsTable, SwingConstants.CENTER,stm);
JTableUtilities.setCellsAlignment(MMUTTable, SwingConstants.CENTER,mmutTableModel);
totalScrollPane = new JScrollPane(totalsTable){
@Override
protected void processMouseWheelEvent(MouseWheelEvent e) {
//https://stackoverflow.com/questions/12911506/why-jscrollpane-does-not-react-to-mouse-wheel-events
if (!isWheelScrollingEnabled()) {
if (getParent() != null)
getParent().dispatchEvent(
SwingUtilities.convertMouseEvent(this, e, getParent()));
return;
}
super.processMouseWheelEvent(e);
}
};
totalScrollPane.setWheelScrollingEnabled(false); ;
MMUTScrollPane = new JScrollPane(MMUTTable){
@Override
protected void processMouseWheelEvent(MouseWheelEvent e) {
//https://stackoverflow.com/questions/12911506/why-jscrollpane-does-not-react-to-mouse-wheel-events
if (!isWheelScrollingEnabled()) {
if (getParent() != null)
getParent().dispatchEvent(
SwingUtilities.convertMouseEvent(this, e, getParent()));
return;
}
super.processMouseWheelEvent(e);
}
};
MMUTScrollPane.setWheelScrollingEnabled(false); ;
totalsTable.setFillsViewportHeight(true);
totalsTable.setPreferredScrollableViewportSize(new Dimension(600,450));
// totalsTable.getModel().addTableModelListener(e -> {
// System.out.println(e.getFirstRow() + " " + e.getColumn() + " " + e.getType());
//
// });
MMUTTable.setFillsViewportHeight(true);
MMUTTable.setPreferredScrollableViewportSize(new Dimension(600,450));
totalsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
TableColumnAdjuster tca = new TableColumnAdjuster(totalsTable);
tca.adjustColumns();
MMUTTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tca = new TableColumnAdjuster(MMUTTable);
tca.adjustColumns();
int numOfRows = totalsTable.getRowCount() + 2;
int rowHeight = totalsTable.getRowHeight();
int width = 559;
int height = numOfRows * rowHeight * 2 + 10;
totalScrollPane.setPreferredSize(new Dimension(width,height));
MMUTScrollPane.setPreferredSize(new Dimension(width,100));
this.setPreferredSize(new Dimension(width,height));
//this.setBackground(Color.BLACK);
this.add(MMUTScrollPane);
this.add(totalScrollPane);
}
public void amplifiersEdited(int amplifierIndex, String data){
parent.amplifiersEdited(amplifierIndex,data);
}
}