-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableCalendar.java
More file actions
144 lines (119 loc) · 3.88 KB
/
TableCalendar.java
File metadata and controls
144 lines (119 loc) · 3.88 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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Notes;
import java.awt.Dimension;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JScrollPane;
import javax.swing.JTable;
/**
*
* @author pokus
*/
public class TableCalendar {
private JTable table;
private MyCalendar mc;
private JScrollPane scroll;
private int acMonth, acYear;
private String[] names = {"Po", "Út", "St", "Čt", "Pá", "So", "Ne"};
private Window w;
private int prevMonth;
public TableCalendar(final Window w){
this.w = w;
mc = new MyCalendar();
acMonth = mc.getMonth();
acYear = mc.getYear();
table = new JTable(mc.getMonth(acYear, acMonth), names);
prevMonth = acMonth;
table.setEnabled(true);
table.setShowGrid(false);
table.setCellSelectionEnabled(true);
colorTable(table, mc.getDay());
scroll = new JScrollPane(table);
scroll.setPreferredSize(new Dimension(200, 120));
table.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
w.clearTask();
w.setTaskText();
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
}
public JScrollPane getCalendar(){
return scroll;
}
public JScrollPane getNextMonthCalendar(){
acMonth = (acMonth + 1) % 12;
table = new JTable(mc.getMonth(acYear, acMonth), names);
table.setEnabled(true);
table.setShowGrid(false);
table.setCellSelectionEnabled(true);
scroll = new JScrollPane(table);
scroll.setPreferredSize(new Dimension(200, 120));
colorTable(table, mc.getDay());
return scroll;
}
public int getMonth(){
int tmp = acMonth - 1;
while(tmp < 0){
tmp += 12;
}
if(prevMonth == 11 && tmp == 0){
acYear--;
} else if(prevMonth == 0 && tmp == 11){
acYear++;
}
return (tmp % 12);
}
public int getYear(){
return acYear;
}
public JScrollPane getPrevMonthCalendar(){
acMonth = (acMonth - 1) % 12;
table = new JTable(mc.getMonth(acYear, acMonth), names);
table.setEnabled(true);
table.setShowGrid(false);
table.setCellSelectionEnabled(true);
scroll = new JScrollPane(table);
scroll.setPreferredSize(new Dimension(200, 120));
colorTable(table, mc.getDay());
return scroll;
}
public final void colorTable(JTable table, int today){
Object o = new Integer(today);
for (int i = 0; i < table.getRowCount(); i++) {
for (int j = 0; j < table.getColumnCount(); j++) {
if(table.getValueAt(i, j) != null && table.getValueAt(i, j).equals(o)){
table.changeSelection(i, j, false, false);
return;
}
}
}
}
public String getSelectedDate(){
int col = table.getSelectedColumn();
int row = table.getSelectedRow();
StringBuilder sb = new StringBuilder();
sb.append(String.valueOf(table.getValueAt(row, col)));
sb.append(".");
sb.append(String.valueOf(getMonth()));
sb.append(".");
sb.append(String.valueOf(getYear()));
return sb.toString();
}
}