1: #! /usr/bin/env python
2: # coding: utf-8
3: ## ----------------------------------------
4: ##
5: ## (C) Copyright 2000-2010, 小粒ちゃん《監修》小泉ひよ子とタマゴ倶楽部
6: ##
7: ## ----------------------------------------
8: #...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
9: """
10: >>> tips()
11:
12: >>> ## ----------------------------------------
13: >>> None
14: version: #1.0.02a
15: """
16: ## ---------------------------------------- demo: jython
17: """
18: _jython=/Users/sketch/book/java_useBetter_1/_jython
19:
20: cd /Users/sketch/book/java_useBetter_1/berry/colorChart/jython/
21: JYTHONPATH=$_jython jython -i colorRadioButton.py
22: ============================================================
23: Version: 2.5.0 (Release_2_5_0:6476, Jun 16 2009, 13:33:26)
24: Module : colorRadioButton.py
25: Date : Wed Oct 6 15:00:09 2010
26: ============================================================
27: """
28: ## ----------------------------------------
29: from java.awt import BorderLayout
30: from java.awt import Color
31: from java.awt import GridLayout
32: from javax.swing import ButtonGroup
33: from javax.swing import JPanel
34: from javax.swing import JRadioButton
35: from javax.swing import JSplitPane
36:
37: class TIPS():
38: colorNames = "red","green","blue",
39:
40: def __init__(self, master):
41:
42: def canvasPane():
43: self.canvas = \
44: pane = JPanel(
45: preferredSize = (100,100),
46: )
47: return pane
48:
49: def controlPane():
50: pane = JPanel(
51: layout = GridLayout(0,1), # GridLayout(rows=,columns=)
52: preferredSize = (150,100),
53: )
54: group = ButtonGroup()
55: for e in self.colorNames:
56: comp = JRadioButton(
57: text = e,
58: actionPerformed = Command(self),
59: )
60: group.add(comp)
61: pane.add(comp)
62: return pane
63:
64: def splitPane():
65: pane = JSplitPane(
66: orientation = JSplitPane.HORIZONTAL_SPLIT,
67: leftComponent = controlPane(),
68: rightComponent = canvasPane(),
69: dividerLocation = 100,
70: )
71: return pane
72:
73: master.contentPane = splitPane()
74: master.pack()
75:
76: ## ----------------------------------------
77: def _update(self, value):
78: self.canvas.background = getattr(Color, value)
79:
80: ## ----------------------------------------
81: class Command:
82: def __init__(self, client):
83: self.client = client
84:
85: def __call__(self, e):
86: value = e.source.text
87: self.client._update(value)
88:
89: ## ----------------------------------------
90: from javax.swing import JFrame
91:
92: def tips():
93: frame = JFrame(
94: title = "color: JRadioButton",
95: locationRelativeTo = None,
96: defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
97: )
98: TIPS(master = frame)
99: frame.visible = True
100:
101: ## ----------------------------------------
102: from __init__ import *
103: ##tips = TIPS.tips
104:
105: if __name__=='__main__':
106: inform()
107: testmod()
108:
109: ## ========================================