berry/colorChart/jython/colorList.py

  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.19
 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: 
 22: JYTHONPATH=$_jython jython -i colorList.py
 23: 
 24: ============================================================
 25: Version: 2.5.0 (Release_2_5_0:6476, Jun 16 2009, 13:33:26) 
 26: Module : colorList.py
 27: Date   : Tue Sep 21 01:20:26 2010
 28: ============================================================
 29: """
 30: ## ----------------------------------------
 31: from javax.swing import DefaultListModel
 32: from javax.swing import JList
 33: from javax.swing import JPanel
 34: from javax.swing import JScrollPane
 35: from javax.swing import JSplitPane
 36: from pawt import colors
 37: 
 38: class TIPS():
 39:     colorNames = [e for e in dir(colors) if not e.startswith("_")]
 40: 
 41:     def __init__(self, master):
 42: 
 43:         def canvasPane():
 44:             self.canvas = \
 45:             pane = JPanel(
 46:                 preferredSize = (100,100),
 47:                 )
 48:             return pane
 49: 
 50:         def controlPane():
 51:             model = DefaultListModel()
 52:             for e in self.colorNames:
 53:                 model.addElement(e)
 54:             comp = JList(
 55:                 model = model,
 56:                 valueChanged = Command(self),
 57:                 )
 58:             pane = JScrollPane(
 59:                 viewportView = comp,
 60:                 minimumSize = (100,100),
 61:                 preferredSize = (150,100),
 62:                 )
 63:             return pane
 64: 
 65:         def splitPane():
 66:             pane = JSplitPane(
 67:                 orientation = JSplitPane.HORIZONTAL_SPLIT,
 68:                 leftComponent  = controlPane(),
 69:                 rightComponent = canvasPane(),
 70:                 dividerLocation = 150,
 71:                 )
 72:             return pane        
 73: 
 74:         master.contentPane = splitPane()
 75:         master.pack()
 76: 
 77:     ## ----------------------------------------
 78:     def _update(self, value):
 79:         self.canvas.background = getattr(colors, value)
 80: 
 81: ## ----------------------------------------
 82: class Command:
 83:     def __init__(self, client):
 84:         self.client = client
 85:         
 86:     def __call__(self, e):                  # ListSelectionListener
 87:         value = e.source.selectedValue
 88:         self.client._update(value)
 89: 
 90: ## ----------------------------------------
 91: from javax.swing import JFrame
 92: 
 93: def tips():
 94:     frame = JFrame(
 95:         title = "color: JList",
 96:         locationRelativeTo = None,
 97:         defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
 98:         )
 99:     TIPS(master = frame)
100:     frame.visible = True
101: 
102: ## ----------------------------------------
103: from __init__ import *
104: ##tips = TIPS.tips
105: 
106: if __name__=='__main__':
107:     inform()
108:     testmod()
109: 
110: ## ========================================