KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: MenuCG.java,v 1.4 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.wings.SMenu;
20 import org.wings.SMenuItem;
21 import org.wings.io.Device;
22
23 public class MenuCG extends org.wings.plaf.css.MenuCG {
24
25     /* (non-Javadoc)
26      * @see org.wings.plaf.css.MenuCG#writeListAttributes(org.wings.io.Device, org.wings.SMenu)
27      */

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