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.38
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 colorButton.py
22: ============================================================
23: Version: 2.5.0 (Release_2_5_0:6476, Jun 16 2009, 13:33:26)
24: Module : colorList.py
25: Date : Tue Sep 21 01:20:26 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 JButton
33: from javax.swing import JPanel
34: from javax.swing import JSplitPane
35:
36: class TIPS():
37: colorNames = "red","green","blue",
38:
39: def __init__(self, master):
40:
41: def canvasPane():
42: self.canvas = \
43: pane = JPanel(
44: preferredSize = (100,100),
45: )
46: return pane
47:
48: def controlPane():
49: pane = JPanel(
50: layout = GridLayout(0,1),
51: ## layout = GridLayout(rows=0,columns=1),
52: preferredSize = (150,100),
53: )
54: for e in self.colorNames:
55: comp = JButton(
56: text = e,
57: actionPerformed = Command(self),
58: )
59: pane.add(comp)
60: return pane
61:
62: def splitPane():
63: pane = JSplitPane(
64: orientation = JSplitPane.HORIZONTAL_SPLIT,
65: leftComponent = controlPane(),
66: rightComponent = canvasPane(),
67: dividerLocation = 100,
68: )
69: return pane
70:
71: master.contentPane = splitPane()
72: master.pack()
73:
74: ## ----------------------------------------
75: def _update(self, value):
76: self.canvas.background = getattr(Color, value)
77:
78: ## ----------------------------------------
79: class Command:
80: def __init__(self, client):
81: self.client = client
82:
83: def __call__(self, e):
84: value = e.source.text
85: self.client._update(value)
86:
87: ## ----------------------------------------
88: from javax.swing import JFrame
89:
90: def tips():
91: frame = JFrame(
92: title = "color: JButton",
93: locationRelativeTo = None,
94: defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
95: )
96: TIPS(master = frame)
97: frame.visible = True
98:
99: ## ----------------------------------------
100: from __init__ import *
101: ##tips = TIPS.tips
102:
103: if __name__=='__main__':
104: inform()
105: testmod()
106:
107: ## ========================================