BrightSide Workbench Full Report + Source Code
SkillPanel.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.skills;
20 
21 import java.util.Set;
22 import java.util.stream.Collectors;
23 import org.turro.skills.tags.SkillItem;
24 import org.turro.skills.tags.SkillSet;
25 import org.turro.skills.tags.SkillTags;
26 import org.zkoss.zk.ui.event.Event;
27 import org.zkoss.zk.ui.event.Events;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.Div;
30 import org.zkoss.zul.Label;
31 import org.zkoss.zul.Separator;
32 
37 public class SkillPanel extends Div implements AfterCompose {
38 
39  private String entityRoot;
40  private SkillSet skills;
41  private Div allSkills;
42 
43  public SkillPanel() {
44  allSkills = new Div();
45  appendChild(allSkills);
46  appendChild(new Separator("horizontal"));
47  }
48 
49  public String getEntityRoot() {
50  return entityRoot;
51  }
52 
53  public void setEntityRoot(String entityRoot) {
54  this.entityRoot = entityRoot;
55  }
56 
57  public Set<SkillItem> getSelected() {
58  return skills.getSelected();
59  }
60 
61  public void updateSkills() {
62  skills = SkillTags.getAvailables(entityRoot);
63  long maxUsage = skills.getMaxUsage();
64  drawSkills(maxUsage);
65  }
66 
67  private void drawSkills(long maxUsage) {
68  allSkills.getChildren().clear();
69  for(SkillItem skill : skills) {
70  final Label label = new Label(skill.getSkillName());
71  String font = skill.isSelected() ? "bold" : "normal";
72  String color = skill.isSelected() ? "#333" : "#156dc6";
73  label.setStyle("cursor:pointer;font-size:" + (int) (11 +
74  (5 * (double)((double)skill.getUsage() / (double)maxUsage))) +
75  "px;font-weight:" + font + ";color:" + color);
76  label.setAttribute("tag", skill);
77  label.addEventListener(Events.ON_CLICK, (Event event) -> {
78  SkillItem skill1 = (SkillItem) label.getAttribute("tag");
79  skill1.setSelected(!skill1.isSelected());
80  Events.postEvent(new Event(Events.ON_CHANGE, SkillPanel.this));
81  drawSkills(maxUsage);
82  });
83  label.setTooltiptext(SkillTags.getSiblings(entityRoot,
84  Set.of(skill.getSkillName())).stream().map(t -> t.getSkillName())
85  .collect(Collectors.joining(", ")));
86  allSkills.appendChild(label);
87  allSkills.appendChild(new Separator("vertical"));
88  }
89  }
90 
91  @Override
92  public void afterCompose() {
93  updateSkills();
94  }
95 
96 }
Set< SkillItem > getSelected()
Definition: SkillPanel.java:57
void setEntityRoot(String entityRoot)
Definition: SkillPanel.java:53
TreeSet< SkillItem > getSelected()
Definition: SkillSet.java:96
static SkillSet getSiblings(String root, Set< String > skillNames)
Definition: SkillTags.java:70
static SkillSet getAvailables(String root)
Definition: SkillTags.java:42