BrightSide Workbench Full Report + Source Code
GroupboxArrow.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.layout;
20 
21 import org.zkoss.zk.ui.Component;
22 import org.zkoss.zk.ui.event.Event;
23 import org.zkoss.zk.ui.event.EventListener;
24 import org.zkoss.zk.ui.event.Events;
25 import org.zkoss.zul.Caption;
26 import org.zkoss.zul.Div;
27 
32 public abstract class GroupboxArrow extends org.zkoss.zul.Groupbox {
33 
34  private Caption caption;
35  private Div div;
36 
37  public GroupboxArrow() {
38  setMold("3d");
39  setSclass("gbarrow");
40  caption = new Caption();
41  appendChild(caption);
42  div = new Div();
43  caption.appendChild(div);
44  div.setSclass("open-true");
45  addEventListener(Events.ON_OPEN, new EventListener<Event>() {
46  @Override
47  public void onEvent(Event event) throws Exception {
48  div.setSclass("open-" + GroupboxArrow.this.isOpen());
49  fillContent(GroupboxArrow.this.isOpen());
50  }
51  });
52  }
53 
54  public void setCaption(Component comp) {
55  div.appendChild(comp);
56  }
57 
58  @Override
59  public void setOpen(boolean open) {
60  super.setOpen(open);
61  div.setSclass("open-" + open);
62  fillContent(isOpen());
63  }
64 
65  private void fillContent(boolean open) {
66  if(open && getChildren().size() == 1) {
67  doFillContent();
68  }
69  }
70 
71  protected abstract void doFillContent();
72 
73 }