KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > plaf > css > msie > PopupMenuCG


1 /*
2  * $Id: PopupMenuCG.java,v 1.3 2005/05/26 13:18:10 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.plaf.css.msie;
15
16
17 import java.io.IOException JavaDoc;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.wings.SMenu;
22 import org.wings.SMenuItem;
23 import org.wings.SPopupMenu;
24 import org.wings.io.Device;
25
26 public class PopupMenuCG extends org.wings.plaf.css.PopupMenuCG {
27     private final transient static Log log = LogFactory.getLog(PopupMenuCG.class);
28
29     /* (non-Javadoc)
30      * @see org.wings.plaf.css.PopupMenuCG#writeListAttributes(org.wings.io.Device, org.wings.SPopupMenu)
31      */

32     protected void writeListAttributes(final Device device, SPopupMenu menu) throws IOException JavaDoc {
33         // calculate max length of children texts for sizing of layer
34
int maxLength = 0;
35         for (int i = 0; i < menu.getMenuComponentCount(); i++) {
36             if (!(menu.getMenuComponent(i) instanceof SMenuItem))
37                 continue;
38             String JavaDoc text = ((SMenuItem)menu.getMenuComponent(i)).getText();
39             if (text != null && text.length() > maxLength) {
40                 maxLength = text.length();
41                 if (menu.getMenuComponent(i) instanceof SMenu) {
42                         maxLength = maxLength + 2; //graphics
43
}
44             }
45         }
46         device.print(" style=\"width:");
47         String JavaDoc stringLength = String.valueOf(maxLength * menu.getWidthScaleFactor());
48         device.print(stringLength.substring(0,stringLength.lastIndexOf('.')+2));
49         device.print("em;\"");
50     }
51 }
52
Popular Tags