berry/colorChart/jython/colorTabbedPane.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.04
 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 colorTabbedPane.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 javax.swing import JTabbedPane
 30: from javax.swing import JPanel
 31: from javax.swing import JSplitPane
 32: from pawt import colors
 33: 
 34: class TIPS():
 35:     colorNames = [e for e in dir(colors) if not e.startswith("_")]
 36: 
 37:     def __init__(self, master):
 38: 
 39:         def canvasPane():
 40:             self.canvas = \
 41:             pane = JPanel(
 42:                 preferredSize = (100,100),
 43:                 )
 44:             return pane
 45: 
 46:         def controlPane():
 47:             pane = JTabbedPane(
 48:                 preferredSize = (250, 100),
 49:                 stateChanged = Command(self),
 50:                 )
 51:             for name in self.colorNames:
 52:                 pane.addTab(name, None)
 53:             return pane
 54: 
 55:         comp = canvasPane()
 56: 
 57:         def splitPane():
 58:             pane = JSplitPane(
 59:                 orientation = JSplitPane.HORIZONTAL_SPLIT,
 60:                 leftComponent  = controlPane(),
 61:                 rightComponent = comp, #canvasPane(),
 62:                 dividerLocation = 250,
 63:                 )
 64:             return pane        
 65: 
 66:         master.contentPane = splitPane()
 67:         master.pack()
 68: 
 69:     ## ----------------------------------------
 70:     def _update(self, value):
 71:         self.canvas.background = getattr(colors, value)
 72: 
 73: ## ----------------------------------------
 74: class Command:
 75:     def __init__(self, client):
 76:         self.client = client
 77:         
 78:     def __call__(self, e):                  # ListSelectionListener
 79:         comp = e.source
 80:         value = comp.getTitleAt(comp.selectedIndex)
 81:         self.client._update(value)
 82: 
 83: ## ----------------------------------------
 84: from javax.swing import JFrame
 85: 
 86: def tips():
 87:     frame = JFrame(
 88:         title = "color: JTabbedPane",
 89:         locationRelativeTo = None,
 90:         defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
 91:         )
 92:     TIPS(master = frame)
 93:     frame.visible = True
 94: 
 95: ## ----------------------------------------
 96: from __init__ import *
 97: ##tips = TIPS.tips
 98: 
 99: if __name__=='__main__':
100:     inform()
101:     testmod()
102: 
103: ## ========================================