OSDN Git Service

initial commit
[xdf/git-repos.git] / xdf-swing / src / main / java / jp / ac / aiit / xdf / component / swing / attribute / SelectedIndexProcessor.java
1 package jp.ac.aiit.xdf.component.swing.attribute;
2
3 import javax.swing.JComboBox;
4 import javax.swing.JList;
5
6 /**
7  * comboboxやlistのselected属性の為のAttributeProcessor。
8  * @author kodama
9  */
10 public class SelectedIndexProcessor extends SetterAttributeProcessor{
11
12         /**
13          * コンストラクター
14          */
15         public SelectedIndexProcessor(){
16                 super("setSelectedIndex", true);
17         }
18
19         @Override
20         public void invokeSet(Object target, final String name, final Object value) {
21                 final int index = Integer.parseInt(value.toString());
22                 if(target instanceof JComboBox){
23                         final JComboBox t = (JComboBox)target;
24                         if(t.getItemCount() > index){
25                                 super.invokeSet(t, name, value);
26                         } else{
27                                 new Thread(){
28                                         public void run(){
29                                                 while(t.getItemCount() <= index){
30                                                         try{
31                                                                 Thread.sleep(100);
32                                                         } catch(InterruptedException e){
33                                                                 return;
34                                                         }
35                                                 }
36                                                 SelectedIndexProcessor.super.invokeSet(t, name, value);
37                                         }
38                                 }.start();
39                         }
40                 } else if(target instanceof JList){
41                         final JList t = (JList)target;
42                         if(t.getModel().getSize() > index){
43                                 super.invokeSet(t, name, value);
44                         } else{
45                                 new Thread(){
46                                         public void run(){
47                                                 while(t.getModel().getSize() <= index){
48                                                         try{
49                                                                 Thread.sleep(100);
50                                                         } catch(InterruptedException e){
51                                                                 return;
52                                                         }
53                                                 }
54                                                 SelectedIndexProcessor.super.invokeSet(t, name, value);
55                                         }
56                                 }.start();
57                         }
58                 }
59         }
60         
61 }