from ui import Button, RootPanel
import Window

def greet(sender):
    Window.alert("Hello, AJAX!")

from ui import Button, CheckBox, VerticalPanel, HorizontalPanel, HTML, DockPanel, HasAlignment, FlowPanel, HTMLPanel, MenuBar, MenuItem, ScrollPanel, Composite
#from Logger import Logger
import DOM

def makeLabel(caption):
    html = HTML(caption)
    html.setStyleName("ks-layouts-Label")
    return html

class Box(Composite):

    def __init__(self, txt, heading, style, boxwidth):

        self.p = VerticalPanel()
        self.p.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
        self.p.setVerticalAlignment(HasAlignment.ALIGN_TOP)

        self.p.add(makeLabel(heading))
        self.p.add(HTML(txt, true))
        self.p.setStyleName(style)
        self.p.setWidth(boxwidth)

        self.setWidget(self.p)

    def onShow(self):
        pass


class Creativity(Box):

    def __init__(self, boxwidth):

        txt = "<ul class='nodec'>"
        txt += "<li /> <a href='http://allpoetry.com/poets/lkcl'>Allpoetry</a>"
        txt += "<li /><a href='./poems/'>Poems</a>"

        txt += "</ul>"

        Box.__init__(self, txt, 'Creativity', 'ks-creativitybox', boxwidth)

    def onShow(self):
        pass

class Technology(Box):

    def __init__(self, boxwidth):

        txt = "<ul class='nodec'>"
        txt += "<li /> Network protocols"
        txt += "<li /> Secure E-Commerce"
        txt += "<li /> Secure Web hosting"
        txt += "<li /> Complex programming"
        txt += "<li /> Reverse-engineering"
        txt += "<li /> <a href='./amcaius'>Property Key Management</a>"
        txt += "</ul>"

        Box.__init__(self, txt, 'Technology', 'ks-technologybox', boxwidth)

    def onShow(self):
        pass

class Contact(Box):

    def __init__(self, boxwidth):

        txt = "<ul class='nodec'>"
        txt += "<li /><a href='mailto:lkcl@lkcl.net'>lkcl@lkcl.net</a>"
        txt += "<li />Tel: +44 20 8133 8223"
        txt += "<li />Mob: +44 78 66 77 00 79"
        txt += "<li /><a href='skype:lkcl..?chat'>Skype 'lkcl..'</a>"
        txt += "</ul>"

        Box.__init__(self, txt, 'Contact', 'ks-contactbox', boxwidth)

    def onShow(self):
        pass

class More(Box):

    def __init__(self, boxwidth):

        txt = "<ul class='nodec'>"
        txt += "<li /><a href='http://advogato.org/person/lkcl/'>Advogato.org</a>"
        txt += "<li /><a href='http://www.cb1.com/~lkcl/'>CB1 Home page</a>"
        txt += "<li /><a href='http://www.google.com/search?q=Luke+Kenneth+Casson+Leighton&ie=ISO-8859&hl=en&btnG=Google+Search'>Google Search</a>"
        txt += "<li /><a href='http://www.nabble.com/forum/Search.jtp?expand=y&user=1103'>Nabble Search</a>"
        txt += "</ul>"

        Box.__init__(self, txt, 'More...', 'ks-morebox', boxwidth)

    def onShow(self):
        pass

class Links(Box):

    def __init__(self, boxwidth):

        txt = "<ul class='nodec'>"
        txt += "<li /><a href='http://www.linkedin.com/in/lkclnet'>LinkedIn Profile</a>"
        txt += "<li /><a href='./cv.txt'>CV</a>"
        txt += "<li /><a href='./crypto/'>Cryptography</a>"
        txt += "<li /><a href='./reports/index.html'>Hardware Reports</a>"
        txt += "</ul>"

        Box.__init__(self, txt, 'Links', 'ks-linksbox', boxwidth)

    def onShow(self):
        pass

class Spirituality(Box):

    def __init__(self, boxwidth):

        txt = "<ul class='nodec'>"
        txt += "<li /><a href='http://enlightenment.com'>Enlightenment.com</a>"
        txt += "<li /><a href='http://www.iawwai.com'>IawWai</a>"

        txt += "</ul>"

        Box.__init__(self, txt, 'Spirituality', 'ks-spiritualitybox', boxwidth)

    def onShow(self):
        pass

class Fun(Box):

    def __init__(self, boxwidth):

        txt = "<ul class='nodec'>"
        txt += "<li /><a href='http://www.royalskatenight.nl'>Tue Den Haag Skating</a>"
        txt += "<li /><a href='http://www.fridaynightskate.nl'>Fri Amsterdaam Skating</a>"
        txt += "<li /><a href='http://www.skatemarathon.com/results/1999/m100.html'>New York 1999 100km</a>"
        txt += "<li /><a href='http://www.a2a.net/99result/86all.html'>Athens to Atlanta 99, 86m</a>"
        txt += "<li /><a href='http://evenementen.uitslagen.nl/2006/rotterdamonwheels/uitslag.php?on=3&ct=Man&p=2'>Rotterdam 2006 Marathon</a>"
        txt += "<li /><a href='http://shut-up-and-dance.nl'>Wild Parties</a>"
        txt += "</ul>"

        Box.__init__(self, txt, 'Fun', 'ks-funbox', boxwidth)

    def onShow(self):
        pass


    
class Layouts(Composite):
    def __init__(self):

        creativity = Creativity("240px")
        technology = Technology("240px")

        contact = Contact("240px")
        more = More("240px")
        links = Links("240px")

        fun = Fun("240px")
        spirituality = Spirituality("240px")

        width = Window.getClientWidth()

        if width > 800:

            toprow = HorizontalPanel()
            middlerow = HorizontalPanel()
            bottomrow = HorizontalPanel()

        elif width > 640:

            toprow = HorizontalPanel()
            middlerow = VerticalPanel()
            bottomrow = HorizontalPanel()

        else:

            toprow = VerticalPanel()
            middlerow = VerticalPanel()
            bottomrow = VerticalPanel()

        toprow.setSpacing(8)
        toprow.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        toprow.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)

        middlerow.setSpacing(8)
        middlerow.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        middlerow.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)

        bottomrow.setSpacing(8)
        bottomrow.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        bottomrow.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)

        toprow.add( technology, DockPanel.EAST)
        toprow.add( creativity, DockPanel.WEST)

        middlerow.add(more, DockPanel.WEST)
        middlerow.add(contact, DockPanel.CENTER)
        middlerow.add(links, DockPanel.EAST)

        bottomrow.add( spirituality, DockPanel.EAST)
        bottomrow.add( fun, DockPanel.WEST)

        txt = "a squeeze-me site, designed with "
        txt += "<a href='http://pyjamas.pyworks.org'>pyjamas</a>."
        txt += " squish me with your browser"
        txt += " (even to as little as 300 pixels wide!)"
        txt += " and i should still look reasonable,"
        txt += " and not have a horizontal scroll-bar."
        txt += " here's the <a href='./site_code'>source code</a> for this site."
        html = HTML(txt, true)
        html.setStyleName("ks-footer")

        panel = VerticalPanel()
        panel.setSpacing(8)
        panel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
        panel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        
        panel.add(toprow)
        panel.add(middlerow)
        panel.add(bottomrow)
        panel.add(html)
        
        self.setWidget(panel)
        self.setStyleName("ks-layouts")

    def onShow(self):
        pass


class Hello:
    def onModuleLoad(self):
        b = Layouts()
        RootPanel().add(b)
