Skip to content

Commit 3e290cf

Browse files
author
Dmitry
committed
-implement week agenda mode
1 parent 2168f97 commit 3e290cf

File tree

2 files changed

+157
-5
lines changed

2 files changed

+157
-5
lines changed

WEB-INF/src/com/dhtmlx/scheduler/PDFWriter.java

Lines changed: 155 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class PDFWriter {
3737
private double weekEventHeaderHeight = 10;
3838
private double agendaColOneWidth = 200;
3939
private double multidayLineHeight = 14;
40+
private double weekAgendaEventHeight = 20;
4041

4142
private String linePattern = "0";
4243

@@ -47,6 +48,8 @@ public class PDFWriter {
4748

4849
private double monthDayWidth;
4950
private double monthDayHeight;
51+
private double contHeight;
52+
private double contWidth;
5053

5154
private double weekDayWidth;
5255
private double weekDayHeight;
@@ -104,7 +107,11 @@ public void generate(String xml, HttpServletResponse resp)
104107
if (view.compareTo("matrix") == 0) {
105108
this.printMatrix();
106109
} else {
107-
this.printWeek();
110+
if (view.compareTo("week_agenda") == 0) {
111+
this.printWeekAgenda();
112+
} else {
113+
this.printWeek();
114+
}
108115
}
109116
}
110117
}
@@ -185,6 +192,22 @@ private void printWeek() throws Exception {
185192
this.weekBwBordersDraw();
186193
}
187194

195+
private void printWeekAgenda() throws Exception {
196+
this.createPDF(Letter.PORTRAIT);
197+
this.printHeader();
198+
this.printFooter();
199+
SchedulerEvent[] events = this.parser.getEvents();
200+
while (events.length > 0) {
201+
this.weekAgendaContainerDraw();
202+
events = this.weekAgendaEventsDraw(events);
203+
if (events.length > 0) {
204+
this.page = new Page(this.pdf, Letter.PORTRAIT);
205+
this.pages.add(this.page);
206+
this.todayLabelDraw(this.page);
207+
}
208+
}
209+
}
210+
188211
private void printWatermark() throws Exception {
189212
if (watermark == null) return;
190213

@@ -1529,7 +1552,137 @@ private void agendaPagesDraw() throws Exception {
15291552
}
15301553
}
15311554

1555+
1556+
private void weekAgendaContainerDraw() throws Exception {
1557+
String[] cols = this.parser.agendaColsParsing();
1558+
double x = this.offsetLeft;
1559+
double contWidth = (this.pageWidth)/2;
1560+
double contHeight = (this.pageHeight)/3;
1561+
this.contWidth = contWidth;
1562+
this.contHeight = contHeight;
1563+
1564+
1565+
for (int i = 0; i < 3; i++) {
1566+
double y = this.offsetTop + contHeight*i;
1567+
this.weekAgendarDayDraw(cols[i], contWidth, contHeight, x, y);
1568+
}
1569+
x += contWidth;
1570+
for (int i = 0; i < 2; i++) {
1571+
double y = this.offsetTop + contHeight*i;
1572+
this.weekAgendarDayDraw(cols[i + 3], contWidth, contHeight, x, y);
1573+
}
1574+
1575+
double tallContHeight = contHeight/2;
1576+
for (int i = 0; i < 2; i++) {
1577+
double y = this.offsetTop + contHeight*2 + tallContHeight*i;
1578+
this.weekAgendarDayDraw(cols[i + 5], contWidth, tallContHeight, x, y);
1579+
}
1580+
double[] headerLineColor = RGBColor.getColor(this.headerLineColor);
1581+
for (int i = 0; i < 3; i++) {
1582+
double y = this.offsetTop + contHeight*i;
1583+
this.Line(headerLineColor, x, y, x, y + this.monthDayHeaderHeight);
1584+
}
1585+
}
1586+
1587+
private void weekAgendarDayDraw(String name, double width, double height, double x, double y) throws Exception {
1588+
double[] bgColor = RGBColor.getColor(this.bgColor);
1589+
double[] borderColor = RGBColor.getColor(this.lineColor);
1590+
double[] textColor = RGBColor.getColor(this.textColor);
1591+
Box day_cont = new Box();
1592+
day_cont.setSize(width, height);
1593+
day_cont.setPosition(x, y);
1594+
day_cont.setFillShape(false);
1595+
day_cont.setPattern(this.linePattern);
1596+
day_cont.setColor(bgColor);
1597+
day_cont.drawOn(this.page);
1598+
1599+
this.Line(borderColor, 0, 0, width, 0, day_cont);
1600+
this.Line(borderColor, 0, 0, 0, height, day_cont);
1601+
this.Line(borderColor, width, 0, width, height, day_cont);
1602+
this.Line(borderColor, 0, height, width, height, day_cont);
1603+
1604+
Box label_cont = new Box();
1605+
label_cont.setSize(width, this.monthDayHeaderHeight);
1606+
label_cont.setPosition(0, 0);
1607+
label_cont.setFillShape(true);
1608+
label_cont.setPattern(this.linePattern);
1609+
label_cont.setColor(bgColor);
1610+
label_cont.placeIn(day_cont, 0, 0);
1611+
label_cont.drawOn(this.page);
1612+
1613+
TextLine txt = new TextLine(this.f1, name);
1614+
x = this.cellOffset + (width - cellOffset - this.f1.stringWidth(name))/2;
1615+
y = (this.monthDayHeaderHeight + this.f1.getSize()) / 2;
1616+
txt.setPosition(x, y);
1617+
txt.placeIn(label_cont);
1618+
txt.setColor(textColor);
1619+
txt.drawOn(this.page);
1620+
}
1621+
1622+
private SchedulerEvent[] weekAgendaEventsDraw(SchedulerEvent[] events) throws Exception {
1623+
double[] borderColor = RGBColor.getColor(this.lineColor);
1624+
double[] textColor = RGBColor.getColor(this.textColor);
1625+
int[] offsets = new int[7];
1626+
for (int i = 0; i < offsets.length; i++)
1627+
offsets[i] = 0;
1628+
ArrayList<SchedulerEvent> rest = new ArrayList<SchedulerEvent>();
1629+
1630+
for (int i = 0; i < events.length; i++) {
1631+
SchedulerEvent event = events[i];
1632+
int day = event.getDay();
1633+
double cont_height = (day < 5) ? this.contHeight : this.contHeight/2;
1634+
double cont_width = this.contWidth;
1635+
double x;
1636+
switch (day) {
1637+
case 0:
1638+
case 2:
1639+
case 4:
1640+
x = this.offsetLeft;
1641+
break;
1642+
default:
1643+
x = this.offsetLeft + cont_width;
1644+
break;
1645+
}
1646+
double cont_start_y = this.offsetTop + Math.floor(day/2)*this.contHeight - (day > 5 ? cont_height : 0);
1647+
double offset = offsets[day]*this.weekAgendaEventHeight;
1648+
double y = cont_start_y + this.monthDayHeaderHeight+ offset;
1649+
1650+
if (cont_start_y + cont_height < y + this.weekAgendaEventHeight) {
1651+
rest.add(event);
1652+
continue;
1653+
}
1654+
1655+
Box ev = new Box();
1656+
ev.setSize(contWidth, this.weekAgendaEventHeight);
1657+
ev.setPosition(x, y);
1658+
ev.setFillShape(false);
1659+
ev.setPattern(this.linePattern);
1660+
ev.setColor(borderColor);
1661+
ev.drawOn(this.page);
1662+
1663+
this.f1.setSize(9);
1664+
String text = event.getText();
1665+
TextLine txt = new TextLine(this.f1, text);
1666+
x = this.cellOffset;
1667+
y = (this.weekAgendaEventHeight + this.f1.getSize()) / 2;
1668+
txt.setPosition(x, y);
1669+
txt.placeIn(ev);
1670+
txt.setColor(textColor);
1671+
txt.drawOn(this.page);
1672+
offsets[day]++;
1673+
}
1674+
SchedulerEvent[] events_list = new SchedulerEvent[rest.size()];
1675+
for (int i = 0; i < rest.size(); i++)
1676+
events_list[i] = rest.get(i);
1677+
return events_list;
1678+
}
1679+
15321680
private void todayLabelDraw() throws Exception {
1681+
Page p1 = this.pages.get(0);
1682+
this.todayLabelDraw(p1);
1683+
}
1684+
1685+
private void todayLabelDraw(Page p1) throws Exception {
15331686
this.f1.setSize(10);
15341687
double[] textColor = RGBColor.getColor(this.textColor);
15351688
String today = this.parser.getTodatLabel();
@@ -1538,10 +1691,9 @@ private void todayLabelDraw() throws Exception {
15381691
double today_y = this.offsetTop - this.cellOffset;
15391692
todayText.setPosition(today_x, today_y);
15401693
todayText.setColor(textColor);
1541-
Page p1 = this.pages.get(0);
15421694
todayText.drawOn(p1);
15431695
}
1544-
1696+
15451697
private int getEventIndex(SchedulerEvent[] events, int day, int week,
15461698
int month) throws IOException {
15471699
for (int i = 0; i < events.length; i++) {

WEB-INF/src/com/dhtmlx/scheduler/XMLParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public String[][] monthRowsParsing() {
7373
return this.rows;
7474
}
7575

76-
public void eventsParsing() {
76+
public void eventsParsing() {
7777
NodeList n1 = this.root.getElementsByTagName("event");
7878
if ((n1 != null)&&(n1.getLength() > 0)) {
7979
for (int i = 0; i < n1.getLength(); i++) {
@@ -156,7 +156,7 @@ public String[] agendaColsParsing() {
156156
}
157157
return cols;
158158
}
159-
159+
160160
public String getMode() {
161161
return this.mode;
162162
}

0 commit comments

Comments
 (0)