余録:worldCup/jython/ex08/wcFrame.py

#! /usr/bin/env python
# coding: utf-8
## ----------------------------------------
##
## (C) Copyright 2000-2010, 小粒ちゃん《監修》小泉ひよ子とタマゴ倶楽部
##
## ----------------------------------------
## History: Swing Example "2010 FIFA World Cup South Africa™"
##      2003/07, Java/Jython
##      2006/07, Jython
##      2008/02, Jython 2.2.1
##      2010/06, Jython 2.5.0
#...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
"""
>>> tips()

>>> ## ----------------------------------------
>>> None
version: #1.0.12abcd
"""
from __init__ import *

## ---------------------------------------- demo: jython
"""
$ cd /Users/sketch/home_sketch/worldCup/jython/
$ jython -i ex08/wcFrame.py

"""
## ----------------------------------------
from javax.swing import ImageIcon
from javax.swing import JFrame
from javax.swing import JLabel
from javax.swing import JList
from javax.swing import JPanel
from javax.swing import JScrollPane
from javax.swing import JSplitPane

class TopPanel(JPanel):

    groups = {
        "A": [                          # Group A
            {"rsa": "South Africa"},
            {"mex": "Mexico"},
            {"uru": "Uruguay"},
            {"fra": "France"},
            ],
        "B": [                          # Group B
            {"arg": "Argentina"},
            {"nga": "Nigeria"},
            {"kor": "Korea Republic"},
            {"gre": "Greece"},
            ],
        "C": [                          # Group C
            {"eng": "England"},
            {"usa": "USA"},
            {"alg": "Algeria"},
            {"svn": "Slovenia"},
            ],
        "D": [                          # Group D
            {"ger": "Germany"},
            {"aus": "Australia"},
            {"srb": "Serbia"},
            {"gha": "Ghana"},
            ],
        "E": [                          # Group E
            {"ned": "Netherlands"},
            {"den": "Denmark"},
            {"jpn": "Japan"},
            {"cmr": "Cameroon"},
            ],
        "F": [                          # Group F
            {"ita": "Italy"},
            {"par": "Paraguay"},
            {"nzl": "New Zealand"},
            {"svk": "Slovakia"},
            ],
        "G": [                          # Group G
            {"bra": "Brazil"},
            {"prk": "Korea DPR"},
            {"civ": "Cote d Ivoire"},
            {"por": "Portugal"},
            ],
        "H": [                          # Group H
            {"esp": "Spain"},
            {"sui": "Switzerland"},
            {"hon": "Honduras"},
            {"chi": "Chile"},
            ],
        }

    def __init__(self, master, *args, **keys):
        master.contentPane = self

        def teams():
            return sorted(team
                for group in "ABCDEFGH"
                for teams in self.groups[group] for team in teams)

        def leftComponent():
            listData = teams()
            
            # class javax.swing.JList
            # public javax.swing.JList()
            view = JList(
                listData,   # java.util.Vector
                valueChanged = self,
                )
            comp = JScrollPane(
                viewportView = view,
                preferredSize = (120,150),
                )
            return comp

        def rightComponent():
            view = JLabel(
                icon = ImageIcon("matches/fifa.png"),
                )
            comp = JScrollPane(
                viewportView = view,
                preferredSize = (180,0),
                )
            return comp

        def splitPane():
            comp = JSplitPane(
                orientation = JSplitPane.HORIZONTAL_SPLIT,
                oneTouchExpandable = True,
                dividerLocation = 100,
                leftComponent  = leftComponent(),
                rightComponent = rightComponent(),
                )
            return comp

        comp = splitPane()
        self.add(comp)
        master.pack()

    # interface javax.swing.event.ListSelectionListener
    # public abstract void
    # javax.swing.event.ListSelectionListener.
    #   valueChanged()
    def __call__(self, e):  # javax.swing.event.ListSelectionEvent
        value = e.source.selectedValue
        teamNames = dict*1
        print(":: %s"%teamNames[value])

## ----------------------------------------
def tips():
    global Qt; Qt = \
    frame = JFrame(
        title = "FIFA World Cup #08",
        size = (320,180),
        locationRelativeTo = None,
        defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
        )
    TopPanel(frame)
    frame.visible = True

## ----------------------------------------
if __name__=='__main__':
    inform()
    testmod()

## ========================================

*1:k,v) for group in self.groups.values() for team in group for k,v in team.items(