͘ ݅ ̓ ̓͂ ԃ Ŋ
( ъ - ߋ ś)

Allen Hollub ߜ
JavaWorld
͕͟ ΂ :݇ͅ

Bag
΂ ߘ bag ڟ ܗ .˟ ߅ ŋ ڜ
˅ Bag .ˌ collection ߂ ŋ collection ڟ Bag .ߌ
ş ˅ .˜ ΂ ˂ collection
݂ ͂ .˜ ߃ ͘ ˅ Ԗ ˜
.˜ߊ ͕ collection ŗ ݂ ނ ˅


Gang-of-Four-Adapter 陂 ˜ ΂ ˂ Ο ̓͂ ԃ Bag
. 靂 ̓͂ ԃ ߍ collection ߌ Ã ŋ
Bag .˜ ˂ presentation ޅ ̓ ˜߅ ͅ ŗ
闇 ޅ ̓ ˜߅ ͅ ŗ .ŋ ΅ ŗ
.(Visual_Proxy() ߊ͕) ˟ ŋߊ presentation

. ΂ ˂ JPanel ߍ ̈́ .˟ ܗ Bag box
(JPanel) Public Interface bag private К ̈́
̈́ ߘ ˜߅ ͂ ̙ .˜ ΂ ˂
˅ ͟ .ˌ ͅ ˜ˌ ؟͐ public interface ޟ
鋗̈́ bag ޟ łԂ ̓ ˜ˌ ނ operations
.˜ ͂

ߜ ˜߅ swing ˛ ͕ ŗ ڟ Ŋ ߊ ͂ ̈́
霂 ݂ ͂ JComboBox JList ̓ ˛
. ΂ ˂ ComboBox 鋃 Abstract List
ߛ ˜ ͅ Ο ˛ ŗ ڟ UI Delegate ޟ 삇
鐖 ϟ ъ ޟ ԋ ߜ ˛ К Є .˜ ݂ ͘˗
Bag .錂 ߅ ߅ К ڟ ˛ ˟ ߅ .˜ ܛ
闌 ъ ޟߋ .ŋ ̈́ ؟͐ ̙ .˜ ֚ ߇
.˝ ނ ˜ ̈́ ܜ џ ŗ (͟)


ܗ


݂ JBotton JList .ߌ ˟ Drop-down ڟ JcomboBox
.ŋ ş ܃ Ԗ ˜ ߇ ނΛ ͝
韂雜 ŗ ޟ ɟ Â ̈́ ̓͂ ԃ
popup 雜 ߌ ڟ .ŋ ܜ ˜ Ђ ̓
.˜ ΂ ˂



Collection
collection ˅ .ŋ ˂ ͟ ŋ ΂ ˂
韂˅ .( Ԋ) ͘ ΂ add(...) ˜ߌ ˂͕
ߊ͕ .˜͟ ͖ ˅ ˜ ɚ collection
韂 ݚ ߇ߛ ̈́ ŋ ( Ԋ) changed(...)
ߊ ˜߅ ßͅ ޟ˃ .˜ ͟ ˜ џ ܂
.˜̓ ߄

Ԋ ˜ ɚ collection ŗ ş ˅
͘ ˅ ˜ ݂ ͂ ͝ ˅ ޟ .˜ˌ
˝ ނ ̈́ ) designate top(...) ˅ .˜ߊ
listener 陛 Ö͛ ˅ ޟ .˟ ޟ ˟ˇ top ݅
ş ޟ .˜ Ԋ for ̈́
thread ŋ ޗ bag 삇 .˝ ͟ ş ܃ swing
ޟ ߅ .ŋ ͎ ޟߖ ş ߌ ɚ ˂
郂 ނ͕ ŗ ߍ ߊ ŋ ޟ swing ڟ ɚ ̓ ɟ
܂ wing Utilities invoke later ͕ Swing event ͇
Swing ޟ) ͗ ˝ߊ ̈́ ݂ ŋߊ ޟ Swing .ߌ
.(ŋ Active-Object ߘ

swing 陊 łԂ ̓ thread safe ڟ Bag ˟ ߅ ˟
Javautil collection 鋚 ܟ ޟ .͂ thread safe
add() ނ thread ܂ ̓ .˜ thread safe
韂 錂 thread ͘ .ŋ ڂԊ ˜ߊ
threadsafe wrapper
ޟ) Ōߜ ߌ ˜͘ ΂ collections.SynchronizedCollection()
collection ˅ ݂ ˜͘ ΂ Decorator ŗ ڟ
.˜ ΂ ˂

ݚ ̈́ collection ͟ ( Ԋ) changed(...) ˅
˂ ŋߊ ݂ ̈́ swing ŕ ̓ invokelater()




top()
top() . ԋ collection bag ݅ ڟ ͐ Bag
韂 鋗̈́ ԋ߅ combo box ŋ ٟ ̓͂ ŋ
ͅ ݅ ( Ԋ) top ˅ ٟ ˟߅ .˜ Â ˌ
.˜ ActionListeners ͅ Bag .˟ ˟


Visual_Proxy()
.΂ ( ) Visual Proxy(...)
̈́ ŗ ˜ ݟ՜ Ancestor listener
镂 container 雂阜 ̈́ .˜ ̉ ˟Ε
.ˌ ˝ߊ Ε Ο ŋ ߌ

鋟 reference ͟ ŋ ͎ ŋ ͂ ޟ
酖 ) ܛ Ő proxy ŗ ˌ garbage collection
霄 .ߌ container ͇ ˟ ߅ .(˟ џ
К . Proxy ŗ reference ͂ container
JComboBox JList JButton К . ͖ ( Ԋ) ̈́
ActionListener 鈛 .˜ Í ͅ renderer ڟ ΂
͂ ԃ Ԋ) Component Listener ͟ popup
.͗ ˝ߊ џ ˜ ͟ component ˜

霂 ˜ ߌ Í ( Ԋ) install ui() ԋ߅ ̓͂ ԃ
镂 ͘ .ߌ Í Ë ̓͂ ԃ ˜ ڈ ComboBox ˜
ComboBox ւ镅 ̓̓ ܜ ւ ˌ ߇
.ߌ ˂ ComboBox ˌ ͅ

. ͂ ŋ ˌ ͅ΃ ͘ ˌ ͅߗ ܜ ͘

˟ˇ topitem  ݂ ( Ԋ ) changed(...) ˅
.˜ ̓ ͅ





renderer ˛
˜͟ ͖ ː ޟ ( Ԋ) renderer ( Ԋ) model
.ŋ ނ ΂ ˂


ŋ

銂 component Ԋ renderer К ъ ޟͅ Ù
΂ ˂ ̓collection memeber ԃ ͘ .ߌ
Jlable 韒 ˜ (܂) render cell ŗ ̈́
. toString() ˅ ԋ߅ ˌ ˜͘ ΂ ΂
.ߜ ˗ ޟ ˋ ՜ ˟ ˗ ޟ ͘
韝 ͖ collection ˟߅ .ŋ ˂ ˗ ޟ ̓͂
韂 ͂ 韂雜 ̓ .˟ ˂ collection ˜
bag .韜ߊ ͕ visual proxy()
.ŋ ŗ џ ̓ Bag .˟΂ ł ̓ ̈́


Copyright 2001, 2002, IT World / JavaWorld / PC WORLD Iran/International Data Group Inc. All rights reserved.


՜
ޟ ߛ ߊ ՜
:˟ߘ Ùԛ

-
-
-

-
Ë -
ߗ -

-
ߙԛ -
ŋ ˜ -




:ڟͅ ŋ

: ŗ͌ ݂

܃ ś
ś - ͘ ݅ ̓ ̓͂ ԃ Ŋ
ś - ͘ ݅ ̓ ̓͂ ԃ Ŋ
ߋ ś - ͘ ݅ ̓ ̓͂ ԃ Ŋ