BrightSide Workbench Full Report + Source Code
GanttResource.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.zkoss.svg;
20 
21 import org.turro.string.Strings;
22 import org.turro.i18n.I_;
23 
28 public class GanttResource extends Svg {
29 
30  static private final int
31  RULE_SPAN = 40,
32  RULE_HEIGHT = 10,
33  ITEM_INIT = 40,
34  ITEM_HEIGHT = 20,
35  ITEM_SPAN = 30;
36 
37  private GanttResourceData data;
38  private int taskPanelWidth = 300, hoursPanelWidth;
39  private GanttMeasure measure;
40 
42  return data;
43  }
44 
45  public void setData(GanttResourceData data) {
46  this.data = data;
47  }
48 
49  public void rule(int units) {
50  String nunit = I_.byKey(measure.toString());
51  setForceStyle("font-size:10px");
52  text(nunit, taskPanelWidth - (nunit.length() * GanttResourceData.CHAR_PIXELS) - 5, RULE_HEIGHT + 6);
53  line(taskPanelWidth, 15, taskPanelWidth + (units * RULE_SPAN), 15, "#000", "1px");
54  for(int i = 0; i <= units; i++) {
55  line(taskPanelWidth + (i * RULE_SPAN), 15, taskPanelWidth + (i * RULE_SPAN), 20, "#000", "1px");
56  setForceStyle("font-size:10px");
57  text("" + i, taskPanelWidth + (i * RULE_SPAN) - 5, RULE_HEIGHT);
58  }
59  }
60 
61  @Override
62  public void startComposing(String onUserEvent, String width, String height, double scale) {
64  taskPanelWidth = data.getMaxNameLenght() * GanttResourceData.CHAR_PIXELS;
65  int maxUnits = (int) Math.ceil(measure.convert(data.getMaxHoursLenght()));
66  hoursPanelWidth = maxUnits * RULE_SPAN;
67 
68  if(width == null) {
69  width = "" + ((taskPanelWidth + (maxUnits * RULE_SPAN) + 20) * scale);
70  }
71  if(height == null) {
72  height = "" + (((data.size() * ITEM_SPAN) + RULE_HEIGHT + 20 + 28) * scale);
73  }
74  super.startComposing(onUserEvent, width, height, scale);
75 
76  startTag("n:g", new String[] {
77  "style='stroke:none'",
78  "font-size='13px'",
79  "font-style='normal'",
80  "font-family='Ubuntu'"
81  });
82 
83  rule(maxUnits);
84 
85  int lastType = -1;
86  int typeChange = 0;
87  int count = 0;
88  for(GanttResourceItem gi : data) {
89  count++;
90  gi.setPosition(count);
91  int x1 = (int) taskPanelWidth;
92  int dx2a = (int) (RULE_SPAN * measure.convert(gi.getExpected()));
93  int dx2b = (int) (RULE_SPAN * measure.convert(gi.getVariable()));
94  int y1 = (ITEM_SPAN * (gi.getPosition() - 1)) + ITEM_INIT + (typeChange * 14);
95  int dy2 = ITEM_HEIGHT;
96  if(!Strings.isBlank(gi.getUniqueId())) {
97  if(lastType != -1 && lastType != gi.getType()) {
98  typeChange++;
99  line(5, y1, 5 + taskPanelWidth + hoursPanelWidth, y1, "#dde", "3px");
100  y1 += (typeChange * 14);
101  }
102  lastType = gi.getType();
103  setForceStyle("cursor:pointer;");
104  setClickElementData("1:" + gi.getType() + ":" + gi.getUniqueId());
105  text(Strings.truncateAndWarn(gi.getName(), GanttResourceData.MAX_NAME_LENGTH), 15, y1 + 15);
106  setForceStyle("cursor:pointer;");
107  setClickElementData("1:" + gi.getType() + ":" + gi.getUniqueId());
108  shadowedRoundRectangle(x1, y1, dx2a, dy2, "#ff5555", 1, null);
109  setForceStyle("cursor:pointer;");
110  setClickElementData("2:" + gi.getType() + ":" + gi.getUniqueId());
111  shadowedRoundRectangle(x1 + dx2a, y1, dx2b, dy2, "#55ff55", 1, null);
112  }
113  }
114  }
115 }
static String byKey(String key)
Definition: I_.java:83
void setData(GanttResourceData data)
void startComposing(String onUserEvent, String width, String height, double scale)
void shadowedRoundRectangle(int x, int y, int width, int height, String fill, double opacity, String tooltip)
Definition: Svg.java:275
void setForceStyle(String forceStyle)
Definition: Svg.java:282
HTMLGenerator startTag(String tag, String[] attributes)
Definition: Svg.java:310
void setClickElementData(String clickElementData)
Definition: Svg.java:290
void line(int x1, int y1, int x2, int y2, String stroke, String strokeWidth)
Definition: Svg.java:108
void text(String text, int x, int y)
Definition: Svg.java:198
static GanttMeasure chooseMeasure(double hours)
double convert(double hours)