ludc
2024-09-14 36c2449aec5b51e5ed4e5c6841154b746060e09a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
/*
 * 此类主要是实现生命周期模板的创建功能,以及对已经创建好的生命周期模板的各种操作,主要用的了jgraph的相关知识。
 * */
package com.vci.client.omd.lifecycle.ui;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.HeadlessException;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.TableColumnModel;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
 
import org.dom4j.DocumentException;
import org.jgraph.JGraph;
import org.jgraph.event.GraphModelEvent;
import org.jgraph.event.GraphModelListener;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphLayoutCache;
 
import com.vci.mw.InvocationUtility;
import com.vci.client.omd.lifecycle.LifeCycleStart;
import com.vci.client.omd.lifecycle.itf.InterLCy;
import com.vci.client.omd.lifecycle.pubimpl.InterLCyManager;
import com.vci.client.omd.lifecycle.pubimpl.LifeCycleTransitionEvents;
import com.vci.client.ui.image.BundleImage;
import com.vci.client.ui.util.PostorderEnumeration;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.lcm.Bound;
import com.vci.corba.omd.lcm.LifeCycle;
import com.vci.corba.omd.lcm.TransitionVO;
import com.vci.corba.omd.lcm.TransitionVOEvent;
 
public class LifeCyclePanel extends JPanel {
 
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
 
    private static LifeCyclePanel lifecycleUI = null;
 
    // private ImageIcon imageIcon = null;
 
    // private String imageName = "";
 
    // static boolean isNoPressSaveTransitionEvents = false;
 
    //private boolean door = false;
    /**
     * 跃迁事件全局变量
     */
 
    // private List<Map<String, List<TransitionVOEvent>>> transitionevents_maps =
    // get_transitionevents_maps_instance();
    private Map<String, List<TransitionVOEvent>> mapTransitionEvents;
 
    // 用户设置跃迁事件的跃迁对象集合
    private List<TransitionVO> transitionVOs = getTransitionVOListInstance();
 
    // 跃迁事件集合
    private List<TransitionVOEvent> transationEvents = null;
 
    //private List<TransitionVO> transitionVOs;
 
    private JTable tableEvent = null;
 
    private LifeCycleTableModel eventTableModel = null;
 
    //private JScrollPane s_pan = null;
 
    private JButton deleteTansitionEventButton = null, addTansitionEventButton = null, saveTansitionEventButton = null;// ,
    // selectedLcStartState = null;
 
    //private JPanel northJPanel = null;
 
    //private JPanel westJPanel;// = new JPanel();
    // add by caill start 2016.3.31
    // 创建westCenterJPanel用来盛放splitPane,创建splitPane用来分割生命周期和状态区域
    //private JPanel westCenterJPanel;// = new JPanel();
    private JSplitPane splitPane;// = new JSplitPane(JSplitPane.VERTICAL_SPLIT);;
    // add by caill end
 
    //private JPanel westTopJPanel;// = new JPanel();
    private JTextField textField;// = new JTextField();
    private JButton btnSelect;// = new JButton("定位");
 
    //private JPanel eastJpanel;// = new JPanel();
 
    private String[] eventKeys;// = LifeCycleTransitionEvents.get_lce_events_keys();
 
    private JPanel mainPanel;// = new JPanel();
 
    // private JPanel panelBase;
    private int editingFlag = 0;
    //private JPanel jp1;
    //private JPanel eastJPanel1;// = new JPanel();
    // private static JPanel eastJPanel2 = new JPanel();
    private JButton addButton;
    private JButton modifyButton;
    private JButton deleteButton;
    private JButton checkButton;
    private JButton saveButton;
    private JButton cancelButton;
 
    private JTextField textFieldName;// = new JTextField(45);
    private JTextField textFieldTag;// = new JTextField(45);
    private JComboBox lc_startState;// = new JComboBox();
    private JTextField textFieldFromStatus;// = new JTextField(45);
    private JTextField textFieldToStatus;// = new JTextField(45);
    private JTextField textFieldEdgeName;// = new JTextField(45);
    private JTextField textFieldEdgeType;// = new JTextField(45);
    private JTextArea textFieldDescription;// = new JTextArea(5, 45);
 
//    private DefaultGraphCell[] cellsBounds = null;
//    private DefaultGraphCell[] cellsRoutes = null;
//    private DefaultGraphCell[] cellsLifecyles = null;
 
    // ArrayList<DefaultGraphCell> cells = new ArrayList<DefaultGraphCell>();
    // ArrayList<DefaultEdge> cells1 = new ArrayList<DefaultEdge>();
    // Map<String, String> map = new HashMap<String, String>();
    // 定义滚动条用于存放tree
    //private JScrollPane scrollPane;// = new JScrollPane();
 
    //private JScrollPane jScrollPane;// = new JScrollPane(lcGraph);
    //private WestJpanel wj;// = new WestJpanel();
    //private JScrollPane weScrollPane;// = new JScrollPane(wj);
 
    //private JScrollPane westsPane;// = new JScrollPane();
    //private JScrollPane eastsScrollPane;// = new JScrollPane();
    // 定义一棵树
    private JTree treeLifeCycle;
    // private String nodeName = null;
    //Point point = new Point(0, 0);
    //Point newPoint = new Point(0, 0);
 
    private JButton btnExp;
 
    private JButton btnImp;
 
    private LifeCycleGraph lcGraph;// = (LifeCycleGraph) new LifeCycleGraph();
 
    Dimension dimScreen = Toolkit.getDefaultToolkit().getScreenSize();
 
    public static LifeCyclePanel getInstance() {
        if (lifecycleUI == null) {
            lifecycleUI = new LifeCyclePanel();
            return lifecycleUI;
        }
//        flushed();// add by caill 2016.3.31初始化时刷新左侧导航栏的数据
//        eastJPanel1.removeAll();
//        eastJPanel1.updateUI();
//        eastJPanel1.add(lifecycleUI.createBaseInfoPanel(), BorderLayout.CENTER);
        // selectedLcStartState.setEnabled(false);
        return lifecycleUI;
    }
 
    // 构造器,用于初始化首先要执行的操作
    protected LifeCyclePanel() {
        initComponent();
        //createLifeCycleTree();
        saveListeneradd();
        addListeneradd();
        addListenerdelete();
        addListenermodify();
        addListenercancel();
        // add by guo 起始状态发生改变的时候,后面的按钮中的图片也跟着改变
        addListenerStartStateChanged();
        // 跃迁监听事件
        addTransationListener();
        deleteTransationListener();
        saveTransationListener();
        // 查看使用范围事件
        addListenner();
        btnExp.addActionListener(new ExpActionListener());
        btnImp.addActionListener(new ImpActionListener());
    }
 
    public LifeCycleGraph getGraph() {
        return lcGraph;
    }
 
    private void addListenerStartStateChanged() {
        // TODO Auto-generated method stub
        lc_startState.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                // TODO Auto-generated method stub
                if (e.getStateChange() == ItemEvent.DESELECTED) {
                    List<Bound> bounds = ImageSelectDialog.getInstance().getbounds();
                    String selectedName = (String) lc_startState.getSelectedItem();
                    for (Bound bound : bounds) {
                        if (bound.name.equals(selectedName)) {
                            // String imageiconName = bound.cellicon;
                            // ImageIcon icon = new BundleImage().createImageIcon(imageiconName);
                            // selectedLcStartState.setIcon(icon);
                            return;
                        }
                    }
                }
            }
        });
    }
 
    private void initVars() {
        // imageIcon = null;
        // isNoPressSaveTransitionEvents = false;
        //door = false;
        // transitionevents_maps = get_transitionevents_maps_instance();
 
        mapTransitionEvents = new HashMap<String, List<TransitionVOEvent>>();
 
        transitionVOs = getTransitionVOListInstance();
        transationEvents = null;
        //transitionVOs = null;
        tableEvent = null;
        eventTableModel = null;
        deleteTansitionEventButton = null;
        addTansitionEventButton = null;
        saveTansitionEventButton = null;
        // selectedLcStartState = null;
        splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
 
        textField = new JTextField();
        btnSelect = new JButton("定位");
 
        eventKeys = LifeCycleTransitionEvents.get_lce_events_keys();
        // lifecycleUI = null;
        //jp1 = null;
 
        textFieldName = new JTextField(45);
        textFieldTag = new JTextField(45);
        lc_startState = new JComboBox();
        lc_startState.setEditable(false);
        textFieldFromStatus = new JTextField(45);
        textFieldToStatus = new JTextField(45);
        textFieldEdgeName = new JTextField(45);
        textFieldEdgeType = new JTextField(45);
        textFieldDescription = new JTextArea(5, 45);
//        cellsBounds = null;
//        cellsRoutes = null;
//        cellsLifecyles = null;
        //WestJpanel wj = new WestJpanel();
 
 
        treeLifeCycle = null;
        // nodeName = null;
        lcGraph = (LifeCycleGraph) new LifeCycleGraph();
        dimScreen = Toolkit.getDefaultToolkit().getScreenSize();
    }
 
//    public static void cleanInstance() {
//        initVars();
//        lifecycleUI = null;
//    }
 
//    public List<Map<String, List<TransitionVOEvent>>> get_transitionevents_maps_instance() {
//        if (transitionevents_maps == null) {
//            transitionevents_maps = new ArrayList<Map<String, List<TransitionVOEvent>>>();
//        }
//        return transitionevents_maps;
//    }
 
    public List<TransitionVO> getTransitionVOListInstance() {
        if (transitionVOs == null) {
            transitionVOs = new ArrayList<TransitionVO>();
        }
        return transitionVOs;
    }
 
    // 页面布局,首次进入的时候所看到的页面
    public void initComponent() {
        initVars();
 
        mainPanel = new JPanel();
 
        //door = false;
        setLayout(new BorderLayout());
        JPanel northJPanel = new JPanel();
        FlowLayout fl = (FlowLayout) northJPanel.getLayout();
        fl.setAlignment(FlowLayout.CENTER);
        this.add(northJPanel, BorderLayout.PAGE_START);
        addButton = new JButton("创建");
        modifyButton = new JButton("修改");
        deleteButton = new JButton("删除");
        checkButton = new JButton("查看使用范围");
        saveButton = new JButton("保存");
        cancelButton = new JButton("取消");
        btnExp = new JButton("导出");
        btnImp = new JButton("导入");
 
        deleteTansitionEventButton = new JButton("删除");
        addTansitionEventButton = new JButton("添加");
        saveTansitionEventButton = new JButton("保存");
 
        JScrollPane jScrollPane = new JScrollPane(lcGraph);
        northJPanel.add(addButton);
        northJPanel.add(modifyButton);
        northJPanel.add(deleteButton);
        northJPanel.add(checkButton);
        northJPanel.add(saveButton);
        northJPanel.add(cancelButton);
        northJPanel.add(btnExp);
        northJPanel.add(btnImp);
        saveButton.setEnabled(false);
        cancelButton.setEnabled(false);
        deleteTansitionEventButton.setEnabled(false);
        addTansitionEventButton.setEnabled(false);
        // System.out.println("265");
        saveTansitionEventButton.setEnabled(false);
        mainPanel.setBorder(BorderFactory.createTitledBorder("生命周期模板"));
        mainPanel.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.anchor = GridBagConstraints.NORTH;
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 3.0;
        gbc.weighty = 3.0;
        gbc.gridheight = 1;
        gbc.fill = GridBagConstraints.BOTH;
        // westJPanel1.setBackground(Color.WHITE);
        // scrollPane.setViewportView(treeLifeCycle);
        // westJPanel1.add(scrollPane,BorderLayout.WEST);
        gbc.gridy = 1;
        // gbc.fill = GridBagConstraints.BOTH;
        gbc.weighty = 1.0;
        gbc.weightx = 0.5;
 
        // add by caill start
        // 搜索框的设置
        GridBagConstraints gb = new GridBagConstraints();
        gb.gridx = 0;
        gb.gridy = 0;
        gb.weightx = 0.7;
        gb.weighty = 0;
        gb.fill = GridBagConstraints.HORIZONTAL;
 
        JPanel westTopJPanel = new JPanel();
        westTopJPanel.setLayout(new GridBagLayout());
        westTopJPanel.add(textField, gb);
        westTopJPanel.add(btnSelect);
 
        // add by caill start 2016.3.31重新布置左侧导航栏的结构
        JPanel westJPanel = new JPanel();
        westJPanel.add(westTopJPanel, BorderLayout.NORTH);
        
        JPanel westCenterJPanel = new JPanel();
        westCenterJPanel.setLayout(new GridBagLayout());
        GridBagConstraints gbct = new GridBagConstraints();
        gbct.gridx = 0;
        gbct.gridy = 0;
        gbct.weightx = 1.0;
        gbct.weighty = 1.0;
        gbct.fill = GridBagConstraints.BOTH;
        westJPanel.add(westCenterJPanel, BorderLayout.CENTER);
        splitPane.setOneTouchExpandable(true);
        
        JScrollPane scrollPane = new JScrollPane();
        createLifeCycleTree();
        scrollPane.setViewportView(treeLifeCycle);
        splitPane.setTopComponent(scrollPane);
        
        JScrollPane weScrollPane = new JScrollPane(new WestJpanel());
        splitPane.setBottomComponent(weScrollPane);
 
        splitPane.setDividerLocation(dimScreen.height / 4);
        westCenterJPanel.add(splitPane, gbct);
        // add by caill end
 
        // 为定位按钮增加点击事件
        btnSelect.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // e.getSource();
                String test = textField.getText().trim();
                DefaultTreeModel model = (DefaultTreeModel) treeLifeCycle.getModel();
                model.reload();
                TreeNode root = (TreeNode) model.getRoot();
                PostorderEnumeration enumeration = new PostorderEnumeration(root);
                while (enumeration.hasMoreElements()) {
                    DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration.nextElement();
                    if (element.getUserObject() instanceof LifeCycleWrapper) {
                        LifeCycleWrapper wrapper = (LifeCycleWrapper) element.getUserObject();
 
                        if (wrapper != null && wrapper.getLC() != null && wrapper.getLC().name.equals(test)) {
                            TreeNode[] path = element.getPath();
                            TreePath treePath = new TreePath(path);
                            treeLifeCycle.setSelectionPath(treePath);
                            return;
                        }
                        ;
                    }
                }
                if (test.equals("")) {
                    JOptionPane.showMessageDialog(com.vci.client.LogonApplication.frame, "请输入生命周期", "提示",
                            JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(com.vci.client.LogonApplication.frame,
                            "{ " + test + " }生命周期不存在", "提示", JOptionPane.INFORMATION_MESSAGE);
                }
 
            }
 
        });
        // 为定位框添加事件
        textField.addActionListener(new ActionListener() {
 
            @Override
            public void actionPerformed(ActionEvent e) {
 
                JTextField text = (JTextField) e.getSource();
                String test = text.getText().trim();
                DefaultTreeModel model = (DefaultTreeModel) treeLifeCycle.getModel();
                model.reload();
                TreeNode root = (TreeNode) model.getRoot();
                PostorderEnumeration enumeration = new PostorderEnumeration(root);
 
                while (enumeration.hasMoreElements()) {
                    DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration.nextElement();
                    if (element.getUserObject() instanceof LifeCycleWrapper) {
                        LifeCycleWrapper wrapper = (LifeCycleWrapper) element.getUserObject();
 
                        if (wrapper != null && wrapper.getLC() != null && wrapper.getLC().name.equals(test)) {
                            TreeNode[] path = element.getPath();
                            TreePath treePath = new TreePath(path);
                            treeLifeCycle.setSelectionPath(treePath);
                            return;
                        }
                        ;
                    }
                }
                if (test.equals("")) {
                    JOptionPane.showMessageDialog(com.vci.client.LogonApplication.frame, "请输入生命周期", "提示",
                            JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(com.vci.client.LogonApplication.frame,
                            "{ " + test + " }生命周期不存在", "提示", JOptionPane.INFORMATION_MESSAGE);
                }
 
            }
 
        });
 
        // add by caill end
 
        // add by caill start 2016.3.31重新设置左侧导航栏各panel的高度
        scrollPane.setPreferredSize(new Dimension(dimScreen.width / 6, dimScreen.height / 4));
        westTopJPanel.setPreferredSize(new Dimension(dimScreen.width / 6 - 5, dimScreen.height / 40));
        westCenterJPanel.setPreferredSize(new Dimension(dimScreen.width / 6 - 5,
                (dimScreen.height - dimScreen.height / 40 - dimScreen.height / 5)));
 
        westJPanel.setPreferredSize(new Dimension(dimScreen.width / 6, dimScreen.height));
 
        JScrollPane westsPane = new JScrollPane();
        westsPane.setPreferredSize(new Dimension(dimScreen.width / 6, dimScreen.height));
        // add by caill end
        westsPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);// 将左侧导航栏最底部水平的滚动条去掉
        westsPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);// 将左侧导航栏最外面的垂直的滚动条去掉
 
        westsPane.setViewportView(westJPanel);
 
        westsPane.repaint();
 
        this.add(westsPane, BorderLayout.LINE_START);
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.weightx = 8.0;
        gbc.gridheight = 2;
 
        jScrollPane.setPreferredSize(new Dimension(dimScreen.width * (5 / 6), dimScreen.height));
        mainPanel.add(jScrollPane, gbc);
        mainPanel.setPreferredSize(new Dimension(dimScreen.width * (5 / 6), dimScreen.height));
        gbc.gridx = 2;
        gbc.gridy = 0;
        gbc.weightx = 2.0;
        gbc.gridheight = 1;
        gbc.fill = GridBagConstraints.BOTH;
        
        //JPanel eastJPanel1 = new JPanel();
        // eastJPanel1.setBackground(Color.white);
        // eastJPanel1.setPreferredSize(new Dimension(dimScreen.width / 3,
        // dimScreen.height / 4));
 
        //eastJPanel1.setPreferredSize(new Dimension(dimScreen.width / 4, 220));
        // eastJPanel1.setBorder(BorderFactory.createEtchedBorder(1));
        // textFieldName.setText("");
        // textFieldTag.setText("");
        // textFieldDescription.setText("");
        // eastJPanel1.removeAll();
        // eastJPanel1.updateUI();
        // createBaseInfoPanel().setPreferredSize(new Dimension(dimScreen.width/6,
        // dimScreen.height/4));
 
        JPanel panel = createBaseInfoPanel();
        panel.setPreferredSize(new Dimension(dimScreen.width / 4 - 10, 220));
        //eastJPanel1.add(panel, BorderLayout.CENTER);
        // mainPanel.add(eastJPanel1, gbc);
        gbc.gridy = 1;
        gbc.fill = GridBagConstraints.BOTH;
        // eastJPanel2.setBackground(Color.white);
        // eastJPanel2.setBorder(BorderFactory.createEtchedBorder(1));
        // eastJPanel2.add(lcGraph.eastJPanelUI());
        // eastJPanel2.setPreferredSize(new Dimension(dimScreen.width/3,
        // dimScreen.height*(3/4)));
        // eastJpanel.add(eastJPanel1, BorderLayout.NORTH);
        JPanel eastJpanel = new JPanel();
        eastJpanel.add(panel, BorderLayout.NORTH);
        eastJpanel.add(initEastJPanelUI(), BorderLayout.SOUTH);
 
        eastJpanel.setPreferredSize(new Dimension(dimScreen.width / 4 - 5, 0));// .height));
 
        JScrollPane eastsScrollPane = new JScrollPane();
        eastsScrollPane.setPreferredSize(new Dimension(dimScreen.width / 4, 0));// dimScreen.height));
 
        eastsScrollPane.setViewportView(eastJpanel);
 
        eastsScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        eastsScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
 
        this.add(mainPanel, BorderLayout.CENTER);
        this.add(eastsScrollPane, BorderLayout.LINE_END);
        clearLifeCycleInfo();
//        textFieldName.setText("");
//        textFieldTag.setText("");
//        textFieldFromStatus.setText("");
//        textFieldToStatus.setText("");
//        textFieldEdgeName.setText("");
//        textFieldEdgeType.setText("");
//        textFieldDescription.setText("");
 
        setModifyState(false);
//        textFieldName.setEditable(false);
//        textFieldTag.setEditable(false);
//        textFieldDescription.setEditable(false);
//        textFieldFromStatus.setEditable(false);
//        textFieldToStatus.setEditable(false);
//        textFieldEdgeName.setEditable(false);
//        textFieldEdgeType.setEditable(false);
//        lc_startState.setEditable(false);
        // selectedLcStartState.setEnabled(false);
 
    }
 
    // 右下角的显示页面,为跃迁的显示做准备
    private JPanel initEastJPanelUI() {
        JPanel newJpaJPanel = new JPanel();
        JPanel jp1 = new JPanel();
        jp1.setLayout(new GridBagLayout());
        jp1.setBorder(BorderFactory.createTitledBorder(""));
 
        GridBagConstraints g = new GridBagConstraints();
        g.anchor = GridBagConstraints.WEST;
        g.insets = new Insets(10, 5, 0, 5);
        g.gridx = 0;
        g.gridy = 0;
        JLabel jl4 = new JLabel("起始状态");
        jl4.setBounds(10, 5, 0, 5);
        jp1.add(jl4, g);
        // jp1.add(getStartStateJcombox(),g);
 
        GridBagConstraints g1 = new GridBagConstraints();
        g1.insets = new Insets(10, 5, 0, 5);
        g1.gridx = 1;
        g1.gridy = 0;
        g1.gridwidth = GridBagConstraints.REMAINDER;
        jp1.add(textFieldFromStatus, g1);
 
        g.insets = new Insets(10, 5, 0, 5);
        g.gridx = 0;
        g.gridy = 1;
        JLabel jl5 = new JLabel("目标状态");
        jp1.add(jl5, g);
        g.gridx = 1;
        g.gridy = 1;
        jp1.add(textFieldToStatus, g);
 
        g.gridx = 0;
        g.gridy = 2;
        JLabel jl6 = new JLabel("名称");
        jp1.add(jl6, g);
        g.gridx = 1;
        g.gridy = 2;
        jp1.add(textFieldEdgeName, g);
 
        g.gridx = 0;
        g.gridy = 3;
        JLabel jl7 = new JLabel("类型");
        jp1.add(jl7, g);
        g.gridx = 1;
        g.gridy = 3;
        jp1.add(textFieldEdgeType, g);
 
        JPanel jPanel = new JPanel();
        JPanel jpBtn = new JPanel();
        jPanel.setLayout(new BorderLayout());
 
        jpBtn.add(addTansitionEventButton);
        jpBtn.add(deleteTansitionEventButton);
        jpBtn.add(saveTansitionEventButton);
 
        jPanel.add(jpBtn, BorderLayout.NORTH);
 
        eventTableModel = new LifeCycleTableModel(10);
        tableEvent = new JTable(eventTableModel);
        tableEvent.setRowHeight(25);
        JComboBox com = new JComboBox(eventKeys);
        TableColumnModel tcm = tableEvent.getColumnModel();
        tcm.getColumn(0).setCellEditor(new DblclickCellEditor(com, tableEvent));
        JScrollPane s_pan = new JScrollPane(tableEvent);
        jPanel.add(s_pan, BorderLayout.CENTER);
        newJpaJPanel.setLayout(new BorderLayout());
        newJpaJPanel.add(jp1, BorderLayout.NORTH);
        newJpaJPanel.add(jPanel, BorderLayout.CENTER);
 
        return newJpaJPanel;
    }
    
    
    private void setModifyState(boolean modify) {
        // 什么周期模板功能按钮
        addButton.setEnabled(!modify);
        modifyButton.setEnabled(!modify);
        deleteButton.setEnabled(!modify);
        saveButton.setEnabled(modify);
        cancelButton.setEnabled(modify);
        
        textFieldName.setEditable(modify);
        textFieldTag.setEditable(modify);
        textFieldDescription.setEditable(modify);
        lc_startState.setEnabled(modify);
        
        textFieldFromStatus.setEditable(false);
        textFieldToStatus.setEditable(false);
        textFieldEdgeName.setEditable(false);
        textFieldEdgeType.setEditable(false);
 
        // 设置图形区可编辑状态
        lcGraph.setMoveable(modify);
        lcGraph.setEdgeLabelsMovable(modify);
        lcGraph.setEditable(modify);
        lcGraph.setCloneable(modify);
        lcGraph.setInvokesStopCellEditing(modify);
        lcGraph.setJumpToDefaultPort(modify);
        
        if (!modify)
            setEventModify(false);
    }
    
    private void setEventModify(boolean modify) {
        // 状态迁移事件编辑功能按钮
        deleteTansitionEventButton.setEnabled(modify);
        addTansitionEventButton.setEnabled(modify);
        saveTansitionEventButton.setEnabled(modify);
        
        tableEvent.setEnabled(modify);
    }
    
    private void clearLifeCycleInfo() {
        textFieldName.setText("");
        textFieldTag.setText("");
        textFieldDescription.setText("");
        
        lcGraph.getModel().remove(lcGraph.getRoots());
        lcGraph.updateUI();
        lcGraph.refresh();
        lcGraph.setOo(null);
        lcGraph.setCloneable(true);
        lcGraph.setInvokesStopCellEditing(true);
        lcGraph.setJumpToDefaultPort(true);
        
        clearEventInfo();
        
        clear();
    }
 
    private void clearEventInfo() {
        textFieldFromStatus.setText("");
        textFieldToStatus.setText("");
        textFieldEdgeName.setText("");
        textFieldEdgeType.setText("");
        
        if (eventTableModel.getRowCount() > 0) {
            eventTableModel.removeRows(0, eventTableModel.getRowCount());
            tableEvent.updateUI();
        }        
    }
 
    /*
     * 初始化生命周期模板信息到界面
     */
    private void initLifeCycleInfo(LifeCycle lc) {
        try {
            textFieldName.setText(lc.name);
            textFieldTag.setText(lc.tag);
            textFieldDescription.setText(lc.description);
    
            lcGraph.refreshGraph(lc);
    
            initTransitionEventMap(lc);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
    
    // 返回按钮的监听器,执行返回操作后界面将重置
    public void addListenercancel() {
        cancelButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int n = JOptionPane.showConfirmDialog(saveButton, "您确认要执行返回操作?");
                if (n == JOptionPane.YES_OPTION) {
                    
                    clearLifeCycleInfo();
                    
                    LifeCycle selLC = lifeCycleTreeSelection();
                    
//                    textFieldName.setText("");
//                    textFieldTag.setText("");
//                    textFieldFromStatus.setText("");
//                    textFieldToStatus.setText("");
//                    textFieldEdgeName.setText("");
//                    textFieldEdgeType.setText("");
//                    textFieldDescription.setText("");
                    // lc_startState.setText("");
//                    if (eventTableModel.getRowCount() > 0) {
//                        eventTableModel.removeRows(0, eventTableModel.getRowCount());
//                        tableEvent.updateUI();
//                    }
                    // eastJPanel2.removeAll();
                    // eastJPanel2.updateUI();
//                    lcGraph.getModel().remove(lcGraph.getRoots());
//                    lcGraph.updateUI();
//                    lcGraph.refresh();
//                    lcGraph.setOo(null);
//                    lcGraph.setCloneable(true);
//                    lcGraph.setInvokesStopCellEditing(true);
//                    lcGraph.setJumpToDefaultPort(true);
 
                    setModifyState(false);
                    
                    initLifeCycleInfo(selLC);
//                    //door = false;
//                    addButton.setEnabled(true);
//                    modifyButton.setEnabled(true);
//                    deleteButton.setEnabled(true);
//                    checkButton.setEnabled(true);
//                    saveButton.setEnabled(false);
//                    cancelButton.setEnabled(false);
//                    // selectedLcStartState.setEnabled(false);
//                    textFieldName.setEditable(false);
//                    textFieldTag.setEditable(false);
//                    textFieldDescription.setEditable(false);
//                    textFieldFromStatus.setEditable(false);
//                    textFieldToStatus.setEditable(false);
//                    textFieldEdgeName.setEditable(false);
//                    textFieldEdgeType.setEditable(false);
//                    lc_startState.setEnabled(false);
                    
                    editingFlag = 0;
 
                } else if (n == JOptionPane.NO_OPTION) {
                    return;
                }
            }
 
        });
    }
 
    // 修改按钮的监听器,主要任务是提示操作人员是否执行修改操作并且将修改后的数据存入XML文件和重置界面
    public void addListenermodify() {
        modifyButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                //door = false;
                editingFlag = 2;
                LifeCycle selectedLC = lifeCycleTreeSelection();
                if (selectedLC != null) {
                    // String nodeName = selectedLC.name;
 
                    ArrayList<InterLCy> interLcyList = InterLCyManager.getInstance().getInterLCyList();
                    if (interLcyList == null || interLcyList.size() == 0) {
                        textFieldName.setEditable(true);
                    }
//                    textFieldName.setEditable(false); // add by caill 2016.1.12无论生命周期有没有被引用,其名称都不可以被更改。
//                    if (eventTableModel.getRowCount() > 0) {
//                        eventTableModel.removeRows(0, eventTableModel.getRowCount());
//                        tableEvent.updateUI();
//                    }
//                    
                    setModifyState(true);
 
//                    textFieldTag.setEditable(true);
//                    textFieldDescription.setEditable(true);
//                    lc_startState.setEnabled(true);
                    // selectedLcStartState.setEnabled(true);
                    // textFieldName.setEnabled(true);
                    // textFieldTag.setEnabled(true);
                    // textFieldDescription.setEnabled(true);
                    // startStateComboBox.setEnabled(true);
//                    textFieldFromStatus.setEditable(false);
//                    textFieldToStatus.setEditable(false);
//                    textFieldEdgeName.setEditable(false);
//                    textFieldEdgeType.setEditable(false);
 
//                    lcGraph.setMoveable(true);
//                    lcGraph.setEdgeLabelsMovable(true);
//                    lcGraph.setEditable(true);
//                    lcGraph.setCloneable(true);
//                    lcGraph.setInvokesStopCellEditing(true);
//                    lcGraph.setJumpToDefaultPort(true);
 
//                    if (eventTableModel.getRowCount() > 0) {
//                        eventTableModel.removeRows(0, eventTableModel.getRowCount());
//                        tableEvent.updateUI();
//                    }
 
//                    addButton.setEnabled(false);
//                    modifyButton.setEnabled(false);
//                    deleteButton.setEnabled(false);
//                    checkButton.setEnabled(false);
//                    saveButton.setEnabled(true);
//                    cancelButton.setEnabled(true);
//                    deleteTansitionEventButton.setEnabled(true);
//                    addTansitionEventButton.setEnabled(true);
//                    saveTansitionEventButton.setEnabled(true);
                    initlc_startState();
                    lc_startState.setSelectedItem(selectedLC.startState);
                } else {
                    JOptionPane.showMessageDialog(null, "请先选中要修改的项");
                }
 
            }
 
        });
    }
 
    // 为delete按钮添加监听器
    public void addListenerdelete() {
        deleteButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                LifeCycle selectedLC = lifeCycleTreeSelection();
                Object[] options = { "Yes", "No" };
                int n = JOptionPane.showOptionDialog(getInstance(), "确认是否删除生命周期规则\"" + selectedLC.name + "\"",
                        "生命周期规则删除", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
 
                if (n != JOptionPane.YES_OPTION) {
                    return;
                }
                try {
                    if (selectedLC != null) {
                        //door = false;
                        String nodeName = selectedLC.name;
                        try {
                            ArrayList<InterLCy> interLcyList = InterLCyManager.getInstance().getInterLCyList();
                            for (InterLCy lcy : interLcyList) {
                                ArrayList<String> usedNameList = lcy.getUsedNameList(nodeName);
                                if (usedNameList != null && usedNameList.size() > 0) {
                                    JOptionPane.showMessageDialog(null, "该生命周期已被使用不允许删除");
                                    return;
                                }
                            }
 
                            LifeCycleStart.getService().deleteLifeCycle(selectedLC);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
 
//                        lcGraph.getModel().remove(lcGraph.getRoots());
//                        lcGraph.updateUI();
//                        lcGraph.refresh();
//                        lcGraph.setOo(null);
//
//                        lcGraph.setMoveable(true);
//                        lcGraph.setEdgeLabelsMovable(true);
//                        lcGraph.setEditable(true);
//                        lcGraph.setCloneable(true);
//                        lcGraph.setInvokesStopCellEditing(true);
//                        lcGraph.setJumpToDefaultPort(true);
//
//                        if (eventTableModel.getRowCount() > 0) {
//                            eventTableModel.removeRows(0, eventTableModel.getRowCount());
//                            tableEvent.updateUI();
//                        }
 
                        clearLifeCycleInfo();
                        
                        setModifyState(false);
                        
//                        textFieldName.setText("");
//                        textFieldTag.setText("");
//                        textFieldFromStatus.setText("");
//                        textFieldToStatus.setText("");
//                        textFieldEdgeName.setText("");
//                        textFieldEdgeType.setText("");
//                        textFieldDescription.setText("");
                        
//
//                        textFieldName.setEditable(false);
//                        textFieldTag.setEditable(false);
//                        textFieldDescription.setEditable(false);
//                        textFieldFromStatus.setEditable(false);
//                        textFieldToStatus.setEditable(false);
//                        textFieldEdgeName.setEditable(false);
//                        textFieldEdgeType.setEditable(false);
//                        lc_startState.setEditable(false);
//                        // selectedLcStartState.setEnabled(false);
//                        deleteTansitionEventButton.setEnabled(false);
//                        addTansitionEventButton.setEnabled(false);
//                        // System.out.println("627");
//                        saveTansitionEventButton.setEnabled(false);
//
//                        addButton.setEnabled(true);
//                        modifyButton.setEnabled(true);
//                        deleteButton.setEnabled(true);
//                        checkButton.setEnabled(true);
//                        saveButton.setEnabled(false);
//                        cancelButton.setEnabled(false);
                        
                        // 删除树节点
                        TreePath treePath = treeLifeCycle.getSelectionPath();
                        treeLifeCycle.removeSelectionPath(treePath);
                        
//                        createLifeCycleTree();
//                        scrollPane.setViewportView(treeLifeCycle);
//                        scrollPane.updateUI();
 
                    } else {
                        JOptionPane.showMessageDialog(null, "请先选中要删除的项");
                    }
                } catch (HeadlessException e) {
                    e.printStackTrace();
                }
            }
 
        });
    }
 
    public void clear() {
 
        if (transationEvents != null) {
//            for (int i = 0; i < transationEvents.size(); i++) {
//                TransitionVOEvent tVoEvent = transationEvents.get(i);
//                tVoEvent = null;
//            }
            transationEvents.clear();
            transationEvents = null;
        }
 
        if (transitionVOs != null) {
//            for (int i = 0; i < transitionVOs.size(); i++) {
//                TransitionVO tVo_Events = transitionVOs.get(i);
//                tVo_Events = null;
//            }
            transitionVOs.clear();
            transitionVOs = null;
        }
 
//        if (transitionVOs != null) {
////            for (int i = 0; i < transitionVOs.size(); i++) {
////                TransitionVO tVo = transitionVOs.get(i);
////                tVo = null;
////            }
//            transitionVOs.clear();
//            transitionVOs = null;
//        }
 
        mapTransitionEvents.clear();
//        if (transitionevents_maps != null) {
//            for (int i = 0; i < transitionevents_maps.size(); i++) {
//                Map<String, List<TransitionVOEvent>> map = transitionevents_maps.get(i);
//                map = null;
//            }
//            transitionevents_maps = null;
//        }
 
    }
 
    public boolean used(String name) {
        try {
            LifeCycle lc = LifeCycleStart.getService().getLifeCycle(name);
            if (lc != null && !lc.name.equals("")) {
                return true;
            }
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
 
        return false;
    }
 
    public boolean isMatchesEnglish(String name) {
        if (!name.matches("[a-z A-Z]*")) {
            // JOptionPane.showMessageDialog(this, "生命周期名称只能为英文字母", "注意",
            // JOptionPane.WARNING_MESSAGE);
            return false;
        }
        return true;
    }
 
    public boolean check() {
        String name = textFieldName.getText();
        if (name.equals("")) {
            JOptionPane.showMessageDialog(this, "请输入生命周期名称", "注意", JOptionPane.WARNING_MESSAGE);
            return false;
        }
 
        if (!isMatchesEnglish(name)) {
            JOptionPane.showMessageDialog(this, "生命周期名称只能为英文字母", "注意", JOptionPane.WARNING_MESSAGE);
            return false;
        }
 
        if (used(name)) {
            JOptionPane.showMessageDialog(this, "该生命周期名称已经存在", "请更换", JOptionPane.WARNING_MESSAGE);
            return false;
        }
 
        if (lc_startState.getSelectedItem() == null || lc_startState.getSelectedItem().toString() == "") {
            JOptionPane.showMessageDialog(null, "请选择开始状态");
            return false;
        }
        return true;
 
    }
 
    // 为save按钮添加监听器
    public void saveListeneradd() {
        saveButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Object[] o = lcGraph.getOo();
                List<Bound> bounds = null;
                List<TransitionVO> routes = null;
                if (editingFlag != 2) {
                    try {
                        if (!check()) {
                            return;
                        }
                        LifeCycle lifeCycle = new LifeCycle();
                        lifeCycle.name = textFieldName.getText();
                        lifeCycle.tag = textFieldTag.getText();
                        lifeCycle.description = textFieldDescription.getText();
                        lifeCycle.startState = lc_startState.getSelectedItem().toString();
                        bounds = new ArrayList<Bound>();
                        routes = new ArrayList<TransitionVO>();
                        // int j = 0;
                        // int k = 0;
                        for (int i = 0; i < o.length; ++i) {
                            if (o[i] instanceof DefaultEdge) {
                                DefaultEdge edge = (DefaultEdge) o[i];
                                DefaultPort s = (DefaultPort) edge.getSource();
                                DefaultGraphCell ps = (DefaultGraphCell) s.getParent();
                                DefaultPort t = (DefaultPort) edge.getTarget();
                                DefaultGraphCell pt = (DefaultGraphCell) t.getParent();
                                
                                String startName = ps.toString();
                                String endName = pt.toString();
                                String routeName = edge.getUserObject().toString();
 
                                TransitionVO route = new TransitionVO();
                                route.source = startName;
                                route.connect = routeName;
                                route.destination = endName;
 
                                List<TransitionVOEvent> transitionVOEvents = null;
//                                    if (transitionevents_maps != null && transitionevents_maps.size() > 0) {
//                                        for (int m = 0; m < transitionevents_maps.size(); m++) {
//                                            Map<String, List<TransitionVOEvent>> map = transitionevents_maps.get(m);
//                                            String key = getKey(map);
//                                            if (key == null) {
//                                                continue;
//                                            }
//                                            if (key.equals(routeName)) {
//                                                transitionVOEvents = map.get(key);
//                                                break;
//                                            }
//                                        }
//                                    }
 
                                if (mapTransitionEvents.containsKey(routeName)) {
                                    transitionVOEvents = mapTransitionEvents.get(routeName);
                                }
 
                                if (transitionVOEvents != null && transitionVOEvents.size() > 0) {
                                    TransitionVOEvent[] tVoEvents = (TransitionVOEvent[]) transitionVOEvents
                                            .toArray(new TransitionVOEvent[0]);
                                    route.transitionVOEvents = tVoEvents;
                                } else {
                                    route.transitionVOEvents = new TransitionVOEvent[0];
                                }
 
                                routes.add(route);
 
                            } else if (o[i] instanceof DefaultGraphCell && !(o[i] instanceof DefaultPort)) {
                                DefaultGraphCell ci = (DefaultGraphCell) o[i];
                                double dx = GraphConstants.getBounds(ci.getAttributes()).getX();
 
                                double dy = GraphConstants.getBounds(ci.getAttributes()).getY();
 
                                double dw = GraphConstants.getBounds(ci.getAttributes()).getWidth();
 
                                double dh = GraphConstants.getBounds(ci.getAttributes()).getHeight();
 
                                String icon = "";
 
                                Icon icn = GraphConstants.getIcon(ci.getAttributes());
                                if (icn != null) {
                                    icn.toString().replace("\\", "/");
                                    icon = icon.substring(icon.lastIndexOf("/") + 1);
                                }
 
                                Bound b = new Bound();
                                b.name = ci.toString();
                                b.cellx = dx + "";
                                b.celly = dy + "";
                                b.cellw = dw + "";
                                b.cellh = dh + "";
                                b.cellicon = icon;
                                bounds.add(b);
                            } else {
                                System.out.println("此数据类型暂不支持");
                            }
                        }
 
                        lifeCycle.bounds = ((Bound[]) bounds.toArray(new Bound[0]));
                        lifeCycle.routes = ((TransitionVO[]) routes.toArray(new TransitionVO[0]));
                        String userName = InvocationUtility.getInvocation().userName;
                        lifeCycle.creator = userName;
                        lifeCycle.modifier = userName;
                        LifeCycleStart.getService().addLifeCycle(lifeCycle);
                        // 保存成功后清内存
//                        clear();
//                        lcGraph.getModel().remove(lcGraph.getRoots());
//                        lcGraph.updateUI();
//                        lcGraph.refresh();
//                        lcGraph.setOo(null);
//
//                        lcGraph.setCloneable(true);
//                        lcGraph.setInvokesStopCellEditing(true);
//                        lcGraph.setJumpToDefaultPort(true);
 
                        //door = false;
//                        clearLifeCycleInfo();
//                        textFieldName.setText("");
//                        textFieldTag.setText("");
//                        textFieldFromStatus.setText("");
//                        textFieldToStatus.setText("");
//                        textFieldEdgeName.setText("");
//                        textFieldEdgeType.setText("");
//                        textFieldDescription.setText("");
                        // lc_startState.setText("");
                        
                        setModifyState(false);
                        
//                        textFieldName.setEditable(false);
//                        textFieldTag.setEditable(false);
//                        textFieldDescription.setEditable(false);
//                        textFieldFromStatus.setEditable(false);
//                        textFieldToStatus.setEditable(false);
//                        textFieldEdgeName.setEditable(false);
//                        textFieldEdgeType.setEditable(false);
//                        // selectedLcStartState.setEnabled(false);
//                        addButton.setEnabled(true);
//                        modifyButton.setEnabled(true);
//                        deleteButton.setEnabled(true);
//                        checkButton.setEnabled(true);
//                        saveButton.setEnabled(false);
//                        cancelButton.setEnabled(false);
//                        // selectedLcStartState.setEnabled(false);
//                        deleteTansitionEventButton.setEnabled(false);
//                        addTansitionEventButton.setEnabled(false);
//                        // System.out.println("934");
//                        saveTansitionEventButton.setEnabled(false);
 
                        /**
                         * createTree(); westJPanel.add(scrollPane,BorderLayout.CENTER);
                         * westJPanel.updateUI();
                         */
 
                        DefaultMutableTreeNode nodeRoot = (DefaultMutableTreeNode)treeLifeCycle.getModel().getRoot();
                        if (nodeRoot != null) {
                            nodeRoot.add(new DefaultMutableTreeNode(new LifeCycleWrapper(lifeCycle)));
                        }
                        
                        treeLifeCycle.updateUI();
//                        createLifeCycleTree();
//                        scrollPane.updateUI();
//                        // add by caill start 2016.3.31 将刷新后的生命周期panel放入splitPane的上部(创建)
//                        splitPane.setTopComponent(scrollPane);
//                        splitPane.updateUI();
//                        // add by caill end
 
                        editingFlag = 0;
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                } else {
                    try {
                        LifeCycle selectedLC = lifeCycleTreeSelection();
                        if (selectedLC == null) {
                            JOptionPane.showMessageDialog(getThis(), "请选择生命周期", "请选择生命周期", JOptionPane.WARNING_MESSAGE);
                            return;
                        }
                        selectedLC.tag = textFieldTag.getText();
                        selectedLC.description = textFieldDescription.getText();
                        selectedLC.startState = lc_startState.getSelectedItem().toString();
                        bounds = new ArrayList<Bound>();
                        routes = new ArrayList<TransitionVO>();
 
                        for (int i = 0; i < o.length; ++i) {
                            if (o[i] instanceof DefaultEdge) {
                                DefaultEdge w = (DefaultEdge) o[i];
                                DefaultPort s = (DefaultPort) w.getSource();
                                DefaultGraphCell ps = (DefaultGraphCell) s.getParent();
                                DefaultPort t = (DefaultPort) w.getTarget();
                                DefaultGraphCell pt = (DefaultGraphCell) t.getParent();
                                String startName = ps.toString();
                                String endName = pt.toString();
                                String routeName = w.getUserObject().toString();
                                TransitionVO route = new TransitionVO();
 
                                route.source = startName;
                                route.connect = routeName;
                                route.destination = endName;
 
                                List<TransitionVOEvent> tVOEvents = null;
//                                    if (transitionevents_maps != null && transitionevents_maps.size() > 0) {
//                                        for (int m = 0; m < transitionevents_maps.size(); m++) {
//                                            Map<String, List<TransitionVOEvent>> map = transitionevents_maps.get(m);
//                                            String key = getKey(map);
//                                            if (key == null) {
//                                                continue;
//                                            }
//                                            if (key.equals(routeName)) {
//                                                transitionVOEvents = map.get(key);
//                                                break;
//                                            }
//                                        }
                                if (mapTransitionEvents.containsKey(routeName)) {
                                    tVOEvents = mapTransitionEvents.get(routeName);
                                }
 
                                if (tVOEvents != null && tVOEvents.size() > 0) {
                                    TransitionVOEvent[] tVoEvents = tVOEvents.toArray(new TransitionVOEvent[0]);
                                    route.transitionVOEvents = tVoEvents;
                                } else {
                                    route.transitionVOEvents = new TransitionVOEvent[0];
                                }
 
                                routes.add(route);
                            } else if (o[i] instanceof DefaultGraphCell && !(o[i] instanceof DefaultPort)) {
                                DefaultGraphCell ci = (DefaultGraphCell) o[i];
                                double dx = GraphConstants.getBounds(ci.getAttributes()).getX();
 
                                double dy = GraphConstants.getBounds(ci.getAttributes()).getY();
 
                                double dw = GraphConstants.getBounds(ci.getAttributes()).getWidth();
 
                                double dh = GraphConstants.getBounds(ci.getAttributes()).getHeight();
 
                                String icon = "";
 
                                Icon icn = GraphConstants.getIcon(ci.getAttributes());
                                if (icn != null) {
                                    icn.toString().replace("\\", "/");
                                    icon = icon.substring(icon.lastIndexOf("/") + 1);
                                }
 
                                Bound b = new Bound();
                                b.name = ci.toString();
                                b.cellx = dx + "";
                                b.celly = dy + "";
                                b.cellw = dw + "";
                                b.cellh = dh + "";
                                b.cellicon = icon;
                                bounds.add(b);
                            } else {
                                System.out.println("此数据类型暂不支持");
                            }
                        }
 
                        selectedLC.bounds = ((Bound[]) bounds.toArray(new Bound[0]));
                        selectedLC.routes = ((TransitionVO[]) routes.toArray(new TransitionVO[0]));
                        selectedLC.modifier = InvocationUtility.getInvocation().userName;
                        LifeCycleStart.getService().modifyLifeCycle(selectedLC);
 
//                        lcGraph.getModel().remove(lcGraph.getRoots());
//                        lcGraph.updateUI();
//                        lcGraph.refresh();
//                        lcGraph.setOo(null);
                        
                        setModifyState(false);
                        
//                        addButton.setEnabled(true);
//                        modifyButton.setEnabled(true);
//                        deleteButton.setEnabled(true);
//                        checkButton.setEnabled(true);
//                        saveButton.setEnabled(false);
//                        cancelButton.setEnabled(false);
//                        // selectedLcStartState.setEnabled(false);
//                        deleteTansitionEventButton.setEnabled(false);
//                        addTansitionEventButton.setEnabled(false);
//                        // System.out.println("1109");
//                        saveTansitionEventButton.setEnabled(false);
 
                        //door = false;
//                        clearLifeCycleInfo();
//                        textFieldName.setText("");
//                        textFieldTag.setText("");
//                        textFieldFromStatus.setText("");
//                        textFieldToStatus.setText("");
//                        textFieldEdgeName.setText("");
//                        textFieldEdgeType.setText("");
//                        textFieldDescription.setText("");
//                        textFieldName.setEditable(false);
//                        textFieldTag.setEditable(false);
//                        textFieldDescription.setEditable(false);
//                        textFieldFromStatus.setEditable(false);
//                        textFieldToStatus.setEditable(false);
//                        textFieldEdgeName.setEditable(false);
//                        textFieldEdgeType.setEditable(false);
//                        lc_startState.setEditable(false);
 
                        /**
                         * createTree(); westJPanel.add(scrollPane,BorderLayout.CENTER);
                         * westJPanel.updateUI();
                         */
                        treeLifeCycle.updateUI();
                        
//                        createLifeCycleTree();
//                        scrollPane.setViewportView(treeLifeCycle);
//                        // add by caill start 2016.3.31 将刷新后的生命周期panel放入splitPane的上部(修改)
//                        scrollPane.updateUI();
//                        splitPane.setTopComponent(scrollPane);
//                        splitPane.updateUI();
//                        // add by caill end
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            }
        });
    }
 
    /***
     * 
     * @param map
     * @return
     */
    public String getKey(Map<String, List<TransitionVOEvent>> map) {
        String key = null;
        Iterator iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            key = (String) entry.getKey();
        }
        return key;
    }
 
    // 为add按钮添加监听器
    public void addListeneradd() {
        addButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //door = false;
                editingFlag = 1;
                clearLifeCycleInfo();
//                textFieldName.setText("");
//                textFieldTag.setText("");
//                textFieldDescription.setText("");
//                textFieldFromStatus.setText("");
//                textFieldToStatus.setText("");
//                textFieldEdgeName.setText("");
//                textFieldEdgeType.setText("");
//                textFieldName.setEditable(true);
//                textFieldTag.setEditable(true);
//                textFieldDescription.setEditable(true);
//                lc_startState.setEditable(false);
//
//                textFieldFromStatus.setEditable(false);
//                textFieldToStatus.setEditable(false);
//                textFieldEdgeName.setEditable(false);
//                textFieldEdgeType.setEditable(false);
 
//                eastJPanel1.removeAll();
//                eastJPanel1.updateUI();
//                eastJPanel1.add(createBaseInfoPanel(), BorderLayout.CENTER);
//                removeALLData();
//
//                lcGraph.getModel().remove(lcGraph.getRoots());
//                lcGraph.updateUI();
//                lcGraph.refresh();
//                lcGraph.setOo(null);
//
//                lcGraph.setMoveable(true);
//                lcGraph.setEdgeLabelsMovable(true);
//                lcGraph.setEditable(true);
//                lcGraph.setCloneable(true);
//                lcGraph.setInvokesStopCellEditing(true);
//                lcGraph.setJumpToDefaultPort(true);
//
//                if (eventTableModel.getRowCount() > 0) {
//                    eventTableModel.removeRows(0, eventTableModel.getRowCount());
//                    tableEvent.updateUI();
//                }
                
                setModifyState(true);
//                addButton.setEnabled(false);
//                modifyButton.setEnabled(false);
//                deleteButton.setEnabled(false);
//                checkButton.setEnabled(false);
//                saveButton.setEnabled(true);
//                cancelButton.setEnabled(true);
//                deleteTansitionEventButton.setEnabled(true);
//                addTansitionEventButton.setEnabled(true);
//                saveTansitionEventButton.setEnabled(true);
                // selectedLcStartState.setEnabled(true);
 
                initlc_startState();
            }
        });
    }
 
    // 点击添加页面的时候执行的方法,用于显示要添加属性的页面
    public JPanel createBaseInfoPanel() {
        JPanel panelBase = new JPanel();
        panelBase.setBorder(BorderFactory.createEtchedBorder());
        panelBase.setLayout(new GridBagLayout());
        GridBagConstraints g = new GridBagConstraints();
        g.anchor = GridBagConstraints.WEST;
        g.insets = new Insets(10, 5, 0, 5);
        g.gridx = 0;
        g.gridy = 0;
        JLabel labelName = new JLabel("名称");
        panelBase.add(labelName, g);
 
        GridBagConstraints g1 = new GridBagConstraints();
        g1.insets = new Insets(10, 5, 0, 5);
        g.gridx = 1;
        g.gridy = 0;
        g1.gridwidth = GridBagConstraints.REMAINDER;
        panelBase.add(textFieldName, g);
        // 限定文本框的有效输入长度为50
        textFieldName.setDocument(new PlainDocument() {
            public void insertString(int offs, String str, javax.swing.text.AttributeSet a)
                    throws BadLocationException {
                String text = textFieldName.getText();
                if (text.length() + str.length() > 50) {
                    Toolkit.getDefaultToolkit().beep();
                    JOptionPane.showMessageDialog(null, "名称不能超过50个字符");
                    return;
                }
                super.insertString(offs, str, a);
            }
        });
 
        g.gridx = 0;
        g.gridy = 1;
        JLabel jl2 = new JLabel("标签");
        panelBase.add(jl2, g);
        g.gridx = 1;
        g.gridy = 1;
        panelBase.add(textFieldTag, g);
 
        g.gridx = 0;
        g.gridy = 2;
        JLabel startStateLabel = new JLabel("起始状态");
        panelBase.add(startStateLabel, g);
        g.gridx = 1;
        g.gridy = 2;
        lc_startState.setPreferredSize(textFieldTag.getPreferredSize());
        panelBase.add(lc_startState, g);
//        g.gridx = 2;
//        g.gridy = 2;
//         selectedLcStartState = new JButton("选择");
//         panelBase.add(selectedLcStartState, g);
 
//        selectedLcStartState.addActionListener(new ActionListener() {
//            public void actionPerformed(ActionEvent e) {
//                ImageSelectDialog dialog = null;
//                dialog = ImageSelectDialog.getInstance();
//                dialog.setVisible(true);
//                imageURL = dialog.getImageName();
//                List<Bound> bounds = dialog.getbounds();
//                for (Bound bound : bounds) {
//                    if (bound != null) {
//                        String str1 = bound.cellicon.trim();
//                        String str2 = imageURL.trim();
//                        if (str1.equals(str2)) {
//                        imageName = bound.name;
//                        imageURL = bound.cellicon;
//                        //add by guo选择按钮的图片进行修改
//                        ImageIcon icon= new BundleImage().createImageIcon(imageURL);
//                        selectedLcStartState.setIcon(icon);
//                        }
//                    }
//                }
//                updateImageUILocal();
//             }
//         });
        g.gridx = 0;
        g.gridy = 3;
        JLabel jl3 = new JLabel("描述");
        panelBase.add(jl3, g);
        g.gridx = 1;
        g.gridy = 3;
 
        textFieldDescription.setDocument(new PlainDocument() {
            public void insertString(int offs, String str, javax.swing.text.AttributeSet a)
                    throws BadLocationException {
                String text = textFieldDescription.getText();
                if (text.length() + str.length() > 255) {
                    Toolkit.getDefaultToolkit().beep();
                    JOptionPane.showMessageDialog(null, "名称不能超过255个字符");
                    return;
                }
                super.insertString(offs, str, a);
            }
        });
        panelBase.add(new JScrollPane(textFieldDescription), g);
        return panelBase;
    }
 
//    public void updateImageUILocal() {
//        lc_startState.setSelectedItem(imageName);
//    }
 
    // 树节点被选中时调用的方法,用于解析XML文件
    public LifeCycle lifeCycleTreeSelection() {
        try {
//            this.mapTransitionEvents.clear();
//            deleteTansitionEventButton.setEnabled(false);
//            addTansitionEventButton.setEnabled(false);
//            // System.out.println("1557");
//            saveTansitionEventButton.setEnabled(false);
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeLifeCycle.getLastSelectedPathComponent();
            if (node != null) {
                Object userObject = node.getUserObject();
                if (userObject instanceof LifeCycleWrapper) {
                    return ((LifeCycleWrapper) userObject).getLC();
                }
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
 
    }
 
    // 新建一棵树用于显示所有的状态名称
    public void createLifeCycleTree() {
        // Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("生命周期模板列表");
        try {
            LifeCycle[] lcs = LifeCycleStart.getService().getLifeCycles();
            for (LifeCycle lc : lcs) {
                node1.add(new DefaultMutableTreeNode(new LifeCycleWrapper(lc)));
            }
        } catch (VCIError e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        treeLifeCycle = new JTree(node1);
        treeLifeCycle.setCellRenderer(new LifeCycleTreeCellRenderer());
        //scrollPane.setViewportView(treeLifeCycle);
 
        treeLifeCycle.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent mouseevent) {
                LifeCycle lc = lifeCycleTreeSelection();
                clearLifeCycleInfo();
//                removeALLData();
                
                editingFlag = 0;
                setModifyState(false);
                
//                try {
//                    eastJPanel1.removeAll();
//                    eastJPanel1.updateUI();
//                    eastJPanel1.add(createBaseInfoPanel(), BorderLayout.CENTER);
                    // eastJPanel2.add(lcGraph.eastJPanelUI());
                    
//                    textFieldName.setEditable(false);
//                    textFieldTag.setEditable(false);
//                    textFieldDescription.setEditable(false);
//                    textFieldFromStatus.setEditable(false);
//                    textFieldToStatus.setEditable(false);
//                    textFieldEdgeName.setEditable(false);
//                    textFieldEdgeType.setEditable(false);
//                    lc_startState.setEnabled(false);
                    
                    if (lc != null) {
                        initLifeCycleInfo(lc);
//                        textFieldName.setText(lc.name);
//                        textFieldTag.setText(lc.tag);
//                        textFieldDescription.setText(lc.description);
//
//                        lcGraph.refreshGraph(lc);
//
//                        initTransitionEventMap(lc);
                    }
//                    addButton.setEnabled(true);
//                    modifyButton.setEnabled(true);
//                    deleteButton.setEnabled(true);
//                    checkButton.setEnabled(true);
//                    saveButton.setEnabled(false);
//                    cancelButton.setEnabled(false);
//                    deleteTansitionEventButton.setEnabled(false);
//                    addTansitionEventButton.setEnabled(false);
//                    // System.out.println("1472");
//                    saveTansitionEventButton.setEnabled(false);
                    
                    
//                } catch (DocumentException e) {
//                    e.printStackTrace();
//                }
            }
 
        });
        
    }
    
    private void initTransitionEventMap(LifeCycle lc) {
        // TODO Auto-generated method stub
        mapTransitionEvents.clear();
        
        for(TransitionVO tvo : lc.routes) {
            //tvo.connect
            if (tvo.transitionVOEvents != null && tvo.transitionVOEvents.length > 0) {
                List<TransitionVOEvent> lstTVE = new ArrayList<TransitionVOEvent>();
                for (TransitionVOEvent tvoE : tvo.transitionVOEvents) {
                    lstTVE.add(tvoE);
                }
                mapTransitionEvents.put(tvo.connect,  lstTVE);
            }
        }
    }
 
    // 定义jgraph页面的相关属性
    class LifeCycleGraph extends JGraph {
        /**
         * 
         */
 
        private static final long serialVersionUID = 1L;
        private ArrayList<DefaultGraphCell> cells;
        //private DefaultPort port00, port01;
        private DefaultGraphCell cell1;
        //private DefaultGraphCell cell2;
        //private DefaultEdge edges;
        private JGraph graph = this;
        //private int q = 0;
        private int edgeCount = 0;
        // 设置一个静态的数组用于存放当前jgraph页面得到的组件
        private Object[] oo;
 
        public LifeCycleGraph() {
            this.setModel(new DefaultGraphModel());
//            GraphLayoutCache graphLayoutCache = new GraphLayoutCache(this.getModel(), new LifeCycelCellViewFactory());
//            this.setGraphLayoutCache(graphLayoutCache);
            initLifeCycleGraph();
        }
 
        private JGraph initLifeCycleGraph() {
            this.getModel().remove(this.getRoots());
            this.getModel().remove(this.getRoots());
            
            this.updateUI();
            {
                this.setGridEnabled(true);
                this.setGridVisible(true);
            }
            this.setDropEnabled(true);
 
            graph.addMouseListener(new MyMouse());
            graph.getModel().addGraphModelListener(new GraphModelListener() {
 
                @Override
                public void graphChanged(GraphModelEvent arg0) {
                    // TODO Auto-generated method stub
                    setOo(graph.getRoots());
                    lcGraph.getCells();
                    Object[] ll = arg0.getChange().getInserted();
                    if (arg0.getChange().getInserted() != null) {
                        if (ll.length == 1) {
                            DefaultGraphCell defau = (DefaultGraphCell) ll[0];
                            List<DefaultGraphCell> cells1 = cells;
                            k: for (int i = 0; i < cells1.size(); i++) {
                                if (defau.equals(cells1.get(i))) {
                                    cells1.remove(i);
                                    break k;
                                }
                            }
                            for (int k1 = 0; k1 < cells1.size(); k1++) {
                                DefaultGraphCell dfdf = cells1.get(k1);
                                if (defau.getUserObject().toString().equals(dfdf.getUserObject().toString())) {
                                    JOptionPane.showMessageDialog(null, "不能选择重复的状态!");
                                    Object[] objcet = new Object[1];
                                    objcet[0] = defau;
                                    graph.getModel().remove(objcet);
                                }
                            }
 
                        }
                    }
                    lcGraph.getCells();
                }
            });
            graph.addMouseMotionListener(new MyMouseListener());
            
            // 添加键盘事件,当点击键盘的delete键的时候删除指定的组件
            graph.addKeyListener(new KeyAdapter() {
                public void keyPressed(KeyEvent e1) {
 
                    if (e1.getKeyCode() == 127 && graph.getSelectionCell() instanceof DefaultEdge) {
                        graph.getModel().remove(graph.getSelectionCells());
                    } else if (e1.getKeyCode() == 127 && graph.getSelectionCell() instanceof DefaultGraphCell) {
 
                        if (graph.getSelectionCell() instanceof DefaultGraphCell) {
                            DefaultGraphCell dgc = (DefaultGraphCell) graph.getSelectionCell();
                            Object[] os = graph.getRoots();
                            List list = new ArrayList();
                            for (int i = 0; i < os.length; i++) {
                                if (!(os[i] instanceof DefaultPort)) {
                                    if (os[i] instanceof DefaultEdge) {
                                        list.add(os[i]);
                                    }
                                }
                            }
                            for (int j1 = 0; j1 < list.size(); j1++) {
                                DefaultEdge dfe = (DefaultEdge) list.get(j1);
                                Object[] dd = new Object[1];
                                dd[0] = dfe;
                                if (dgc.getChildren().contains(dfe.getSource())) {
                                    graph.getModel().remove(dd);
                                    graph.refresh();
                                    graph.updateUI();
                                } else if (dgc.getChildren().contains(dfe.getTarget())) {
                                    graph.getModel().remove(dd);
                                    graph.refresh();
                                    graph.updateUI();
                                }
                            }
 
                            graph.getModel().remove(graph.getSelectionCells());
                        }
                    }
                }
            });
 
            graph.refresh();
            graph.setMoveBelowZero(false);
            return graph;
        }
 
        public Object[] getOo() {
            return oo;
        }
 
        public void setOo(Object[] oo) {
            lcGraph.oo = oo;
        }
 
        public Map<String, DefaultGraphCell> getCells(LifeCycle lc, List<DefaultGraphCell> lstCell) {
            try {
                // cellsBounds = new DefaultGraphCell[lc.bounds.length];
                double x, y, w, h;
                String cellicon = null, name = null;
                // Map<String, DefaultGraphCell> map = null;
                // List<Map<String, DefaultGraphCell>> list = null;
                Map<String, DefaultGraphCell> map = new HashMap<String, DefaultGraphCell>();
 
                // list = new ArrayList<Map<String, DefaultGraphCell>>();
                for (int i = 0; i < lc.bounds.length; i++) {
                    DefaultGraphCell cell = new DefaultGraphCell(lc.bounds[i].name);
                    x = Double.parseDouble(lc.bounds[i].cellx);
                    y = Double.parseDouble(lc.bounds[i].celly);
                    w = Double.parseDouble(lc.bounds[i].cellw);
                    h = Double.parseDouble(lc.bounds[i].cellh);
                    cellicon = lc.bounds[i].cellicon;
                    name = lc.bounds[i].name;
 
                    GraphConstants.setBounds(cell.getAttributes(), new Rectangle2D.Double(x, y, w, h));
                    GraphConstants.setBorderColor(cell.getAttributes(), Color.black);
                    GraphConstants.setLineWidth(cell.getAttributes(), 2.0f);
                    GraphConstants.setOpaque(cell.getAttributes(), true);
                    GraphConstants.setEditable(cell.getAttributes(), false);
 
                    ImageIcon imageIcon = null;
                    if (!cellicon.startsWith("http://")) {
                        imageIcon = new BundleImage().createImageIcon(cellicon);
                    }
 
                    else {
                        URL url = null;
                        try {
                            url = new URL(cellicon);
                        } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        if (url == null) {
                            continue;
                        }
                        imageIcon = new ImageIcon(url);
                    }
 
                    // selectedLcStartState.setIcon(imageIcon);
 
                    GraphConstants.setIcon(cell.getAttributes(), imageIcon);
                    DefaultPort fp = new DefaultPort();
                    cell.add(fp);
                    map.put(name, cell);
                    lstCell.add(cell);
                    // list.add(map);
                }
                return map;
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
            return null;
        }
 
        public String getKey(Map<String, DefaultGraphCell> map) {
            String key = null;
            Iterator iterator = map.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry entry = (Map.Entry) iterator.next();
                key = (String) entry.getKey();
            }
            return key;
        }
 
//        public DefaultGraphCell[] arraycat(DefaultGraphCell[] dgc1, DefaultGraphCell[] dgc2) {
//            try {
//                int len1 = 0;
//                int len2 = 0;
//                if (dgc1 != null)
//                    len1 = dgc1.length;
//                if (dgc2 != null)
//                    len2 = dgc2.length;
//                if (len1 + len2 > 0)
//                    cellsLifecyles = new DefaultGraphCell[len1 + len2];
//                if (len1 > 0)
//                    System.arraycopy(dgc1, 0, cellsLifecyles, 0, len1);
//                if (len2 > 0)
//                    System.arraycopy(dgc2, 0, cellsLifecyles, len1, len2);
//                return cellsLifecyles;
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//            return null;
//        }
 
        // 点击左边树的时候的显示页面
        public void refreshGraph(LifeCycle lc) throws DocumentException {
            try {
                this.graph.getModel().remove(getRoots());
                //door = true;
 
                List<DefaultGraphCell> lstCell = new ArrayList<DefaultGraphCell>();
                // selectedLcStartState.setEnabled(false);
                Map<String, DefaultGraphCell> mapCell = getCells(lc, lstCell);// cellsBounds);
                DefaultGraphCell cell = null;
                TransitionVO[] routes = lc.routes;
 
                edgeCount = 0;
                if (routes != null && routes.length > 0) {
                    // cellsRoutes = new DefaultGraphCell[routes.length];
                    for (int i = 0; i < routes.length; i++) {
                        DefaultEdge edge = new DefaultEdge();
                        edge.setUserObject(routes[i].connect);
                        String source = routes[i].source;
                        String destination = routes[i].destination;
 
                        if (mapCell.containsKey(source)) {
                            cell = mapCell.get(source);
                            edge.setSource(cell.getChildAt(0));
                        }
 
                        if (mapCell.containsKey(destination)) {
                            cell = mapCell.get(destination);
                            edge.setTarget(cell.getChildAt(0));
                        }
//                        for (Map<String, DefaultGraphCell> map : list) {
//                            if (source.equals(getKey(map))) {
//                                cell = map.get(source);
//                                edge.setSource(cell.getChildAt(0));
//
//                            }
//                            if (destination.equals(getKey(map))) {
//                                cell = map.get(destination);
//                                edge.setTarget(cell.getChildAt(0));
//                            }
//
//                        }
                        // cellsRoutes[i] = edge;
                        lstCell.add(edge);
                        edgeCount++;
                        
                        int arrow = GraphConstants.ARROW_CLASSIC;
                        GraphConstants.setLineEnd(edge.getAttributes(), arrow);
                        GraphConstants.setEndFill(edge.getAttributes(), true);
                        GraphConstants.setLineWidth(edge.getAttributes(), 2.0f);
                        GraphConstants.setDisconnectable(edge.getAttributes(), false);
 
                    }
 
                }
                // add by caill start 2016.3.28 当状态之间没有
                // routes时,要把cellsRoutes置空,否则cellsRoutes会保留之前节点的值,影响后面的程序
//                if (routes == null || routes.length == 0) {
//                    cellsRoutes = null;
//                }
                // add by caill end
                // DefaultGraphCell[] cellsLifecyles = arraycat(cellsBounds, cellsRoutes);
 
                // if (cellsLifecyles != null && cellsLifecyles.length > 0 && cellsBounds.length
                // > 0) { // add by caill
                // 2016.3.28将此处的&&
                // cellsRoutes.length
                // >
                // 0判断条件去掉,因为单个节点时允许cellsRoutes为空
 
                GraphLayoutCache glc = this.graph.getGraphLayoutCache();
                for (DefaultGraphCell cellLifecyle : lstCell) {
                    glc.insert(cellLifecyle);
                }
                // }
                // 清内存
//                clearDefaultGraphCells(cellsBounds);
//                clearDefaultGraphCells(cellsRoutes);
//                clearDefaultGraphCells(cellsLifecyles);
 
                setOo(this.graph.getRoots());
                this.graph.setMoveable(false);
                lcGraph.setEdgeLabelsMovable(false);
                lcGraph.setEditable(false);
//                eastJpanel.removeAll();
//                eastJpanel.updateUI();
//                eastJpanel.add(eastJPanel1, BorderLayout.NORTH);
//                eastJpanel.add(lcGraph.eastJPanelUI(), BorderLayout.SOUTH);
                lc_startState.setSelectedItem(lc.startState);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
 
        public void clearDefaultGraphCells(DefaultGraphCell[] defaultGraphCells) {
            if (defaultGraphCells != null) {
                for (int i = 0; i < defaultGraphCells.length; i++) {
                    // DefaultGraphCell defaultGraphCell = defaultGraphCells[i];
                    defaultGraphCells[i] = null;
                }
 
                defaultGraphCells = null;
            }
        }
 
        // 得到当前页面的所有cell,当页面有所改变的时候将这些cell更新进去
        public void getCells() {
            cells = new ArrayList<DefaultGraphCell>();
            Object[] o2 = graph.getRoots();
            for (int i = 0; i < o2.length; i++) {
                if (!(o2[i] instanceof DefaultPort)) {
                    if ((o2[i] instanceof DefaultGraphCell) && !(o2[i] instanceof DefaultEdge)) {
                        DefaultGraphCell dgf1 = (DefaultGraphCell) o2[i];
                        cells.add(dgf1);
                    }
                }
            }
            initlc_startState();
        }
 
        // private int kuan = 0;
 
        // 自定义鼠标事件,当鼠标移动到cell上面的时候改变光标形状并且可以操作
        class MyMouseListener implements MouseMotionListener {
            int x1 = 0, y1 = 0;
 
            @Override
            public void mouseDragged(MouseEvent e) {
            }
 
            @Override
            public void mouseMoved(MouseEvent e) {
 
                flushed(); // add by caill 2016.3.31在中间区域移动鼠标时刷新左侧导航栏内的数据
                graph.refresh();
                x1 = e.getX();
                y1 = e.getY();
                if (cells != null) {
                    k: for (int i = 0; i < cells.size(); i++) {
                        if (cells.get(i) == null) {
                            break;
                        }
                        DefaultGraphCell cell = cells.get(i);
                        if (cell instanceof DefaultGraphCell) {
                            Rectangle2D rec = GraphConstants.getBounds(cell.getAttributes());
                            Point point = new Point((int) rec.getCenterX(), (int) rec.getCenterY());
                            java.awt.Rectangle rect = new java.awt.Rectangle(point.x - 10, point.y - 10, 20, 20);
                            if (rect.contains(x1, y1)) {
                                e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                                graph.setMoveable(false);
                                break k;
                            } else {
                                graph.setMoveable(true);
                                e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                            }
                        }
                    }
                    graph.refresh();
                }
            }
 
        }
 
        // 自定义鼠标事件,为连线做好准备工作
        class MyMouse implements MouseListener {
            int x1 = 0, y1 = 0;
 
            protected void updateField() {
                graph.refresh();
                graph.updateUI();
            }
 
            // 点击鼠标事件,鼠标点击的时候执行的动作
            @Override
            public void mouseClicked(MouseEvent e) {
 
                flushed(); // add by caill 2016.3.31在中间区域点击鼠标时刷新左侧导航栏内的数据
                lcGraph.setCloneable(true);
                lcGraph.setInvokesStopCellEditing(true);
                lcGraph.setJumpToDefaultPort(true);
//                addTansitionEventButton.setEnabled(false);
//                // System.out.println("1929");
//                deleteTansitionEventButton.setEnabled(false);
//                saveTansitionEventButton.setEnabled(false);
 
                clearEventInfo();
                
                Object cell = graph.getSelectionCell();
                if (cell == null) {
                    setEventModify(false);
                    return;
                }
                // 判断选中组件是否为线,如果为线则在响应区域显示跃迁信息
                // if (!(graph.getSelectionCell() instanceof DefaultPort)) {
                if (cell instanceof DefaultEdge) {
 
//                        if (door == true) {
//                            addTansitionEventButton.setEnabled(false);
//                            // System.out.println("1940");
//                            deleteTansitionEventButton.setEnabled(false);
//                            saveTansitionEventButton.setEnabled(false);
//                        } else {
//                            // System.out.println("addTansitionEventButton.setEnabled(true);");
//                            addTansitionEventButton.setEnabled(true);
//                            deleteTansitionEventButton.setEnabled(true);
//                            saveTansitionEventButton.setEnabled(true);
//                        }
 
                    if (editingFlag != 0) {
                        setEventModify(true);
                    } else {
                        setEventModify(false);
                    }
                    LifeCycle selectedLC = null;
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeLifeCycle.getLastSelectedPathComponent();
                    if (node != null) {
                        Object userObject = node.getUserObject();
                        if (userObject instanceof LifeCycleWrapper) {
                            selectedLC = ((LifeCycleWrapper) userObject).getLC();
                        }
                    }
                    DefaultEdge selectedge = (DefaultEdge) graph.getSelectionCell();
                    // 得到界面内的所有组件
//                        DefaultPort dfps = (DefaultPort) selectedge.getSource();
//                        DefaultPort dfpt = (DefaultPort) selectedge.getTarget();
                    textFieldEdgeName.setText(selectedge.getUserObject().toString());
                    textFieldEdgeType.setText("DefaultEdge");
                    
                    // 得到选中线的源点和目的点
                    DefaultPort p1 = (DefaultPort) selectedge.getSource();
                    DefaultPort p2 = (DefaultPort) selectedge.getTarget();
                    String dp1 = p1.getParent().toString();
                    String dp2 = p2.getParent().toString();
                    textFieldFromStatus.setText(dp1);
                    textFieldToStatus.setText(dp2);
                    
                    
                    Object obj = selectedge.getUserObject();
                    if (obj == null)
                        return;
                    
                    String name = obj.toString();
                    if (mapTransitionEvents.containsKey(name)) {
                        List<TransitionVOEvent> lstEvent = mapTransitionEvents.get(name);
                        
                        if (lstEvent != null) {
                            for (TransitionVOEvent tvoEvent : lstEvent) {
                                eventTableModel.addRow(tvoEvent.id);
                            }
                            tableEvent.updateUI();
                        }
                    }
 
//                        textFieldName.setEditable(false);
//                        textFieldTag.setEditable(true);
//                        textFieldDescription.setEditable(true);
//                        lc_startState.setEditable(false);
//
//                        textFieldFromStatus.setEditable(false);
//                        textFieldToStatus.setEditable(false);
//                        textFieldEdgeName.setEditable(false);
//                        textFieldEdgeType.setEditable(false);
                    // startStateComboBox.setEnabled(false);
//                    LifeCyle[] lifeCyles = null;
//                    TransitionVOEvent[] transitionVOEvents = null;
//                    TransitionVO[] transitionVOs = null;
//                    try {
//                        lifeCyles = LifeCycleStart.getService().getLifeCyles();
//                    } catch (VCIError e2) {
//                        // TODO Auto-generated catch block
//                        e2.printStackTrace();
//                    }
//                    List<TransitionVOEvent> tVoEvents = null;
//                    if (lifeCyles == null || lifeCyles.length == 0) {
////                            if (transitionevents_maps != null && transitionevents_maps.size() > 0) {
////                                for (int m = 0; m < transitionevents_maps.size(); m++) {
////                                    Map<String, List<TransitionVOEvent>> map = transitionevents_maps.get(m);
////                                    String key = getKey(map);
////                                    if (key == null) {
////                                        continue;
////                                    }
////                                    if (key.equals(selectedge.getUserObject().toString())) {
////                                        tVoEvents = map.get(key);
////                                        break;
////                                    }
////                                }
////                            }
//
//                        String key = selectedge.getUserObject().toString();
//                        if (mapTransitionEvents.containsKey(key)) {
//                            tVoEvents = mapTransitionEvents.get(key);
//                        }
//
//                        if (tVoEvents != null) {
//                            for (TransitionVOEvent tVoEvent : tVoEvents) {
//                                eventTableModel.addRow(tVoEvent.id);
//                                tableEvent.updateUI();
//                            }
//                        }
//                    } else {
//                        if (selectedLC != null) {
//                            transitionVOs = selectedLC.routes;
//                            for (TransitionVO tVo : transitionVOs) {
//                                if (tVo.source.equals(dp1) && tVo.destination.equals(dp2)) {
//                                    transitionVOEvents = tVo.transitionVOEvents;
//                                    for (TransitionVOEvent tVoEvent : transitionVOEvents) {
//                                        eventTableModel.addRow(tVoEvent.id);
//                                        tableEvent.updateUI();
//                                    }
//                                }
//                            }
//                        }
//                    }
 
                    // }
 
                }
            }
 
 
            /***
             * 
             * @param map
             * @return
             */
            public String getKey(Map<String, List<TransitionVOEvent>> map) {
                String key = null;
                Iterator iterator = map.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry entry = (Map.Entry) iterator.next();
                    key = (String) entry.getKey();
                    // System.out.println(entry.getKey());
                }
                return key;
            }
 
            // 设置鼠标按下事件,当鼠标按下的时候开始画线
            @Override
            public void mousePressed(MouseEvent e) {
 
                flushed(); // add by caill 2016.3.31在中间区域按下鼠标时刷新左侧导航栏内的数据
                x1 = e.getX();
                y1 = e.getY();
                Point point1 = new Point(x1, y1);
                if (cells == null)
                    return;
 
                for (int i = 0; i < cells.size(); i++) {
                    if (cells.get(i) == null) {
                        continue;
                    }
                    // 在cell中规定一片区域,当鼠标移动到这片区域的时候变成手的形状
                    DefaultGraphCell cell = cells.get(i);
                    Rectangle2D rect = GraphConstants.getBounds(cell.getAttributes());
//                    Point point = new Point((int) rec.getCenterX(),
//                            (int) rec.getCenterY());
//                    double dx = GraphConstants.getBounds(
//                            cell.getAttributes()).getX();
//
//                    double dy = GraphConstants.getBounds(
//                            cell.getAttributes()).getY();
//
//                    double dw = GraphConstants.getBounds(
//                            cell.getAttributes()).getWidth();
//
//                    double dh = GraphConstants.getBounds(
//                            cell.getAttributes()).getHeight();
//
//                    Rectangle rect = new Rectangle();
//                    rect.setRect(dx, dy, dw, dh);
 
                    if (rect.contains(point1)) {
                        DefaultPort port00 = new DefaultPort();
                        Point2D point2d = new Point2D.Double((GraphConstants.PERMILLE / 2),
                                (GraphConstants.PERMILLE / 2));
                        GraphConstants.setOffset(port00.getAttributes(), point2d);
                        cell.add(port00);
                        cell1 = cell;
                        break;
                    }
                }
            }
 
            // 鼠标释放的时候执行的动作
            @Override
            public void mouseReleased(MouseEvent e) {
 
                flushed(); // add by caill 2016.3.31在中间区域释放鼠标时刷新左侧导航栏内的数据
                x1 = e.getX();
                y1 = e.getY();
                if (cells == null || cell1 == null)
                    return;
 
                // System.out.println(String.format("鼠标位置:x=%d, y=%d", x1, y1));
                Rectangle2D rec1 = GraphConstants.getBounds(cell1.getAttributes());
                Point point1 = new Point((int) rec1.getCenterX(), (int) rec1.getCenterY());
 
                for (int i = 0; i < cells.size(); i++) {
                    DefaultGraphCell cell = cells.get(i);
                    if (cell == null || cell == cell1)
                        continue;
 
                    // System.out.println("Cell: " + cell.toString());
 
                    Rectangle2D rect = GraphConstants.getBounds(cell.getAttributes());
                    Point point = new Point((int) rect.getCenterX(), (int) rect.getCenterY());
 
//                    double dx = GraphConstants.getBounds(cell.getAttributes()).getX();
//
//                    double dy = GraphConstants.getBounds(cell.getAttributes()).getY();
//
//                    double dw = GraphConstants.getBounds(cell.getAttributes()).getWidth();
//
//                    double dh = GraphConstants.getBounds(cell.getAttributes()).getHeight();
//
//                    Rectangle rect = new Rectangle();
//                    rect.setRect(dx, dy, dh, dw);
 
                    // System.out.println("Cell Rectangle = " + rect);
 
                    if (!rect.contains(x1, y1))
                        continue;
 
                    if (cell instanceof DefaultGraphCell) {
                        // System.out.println("创建连线");
 
                        DefaultPort port00 = new DefaultPort(point1);
                        DefaultPort port01 = new DefaultPort(point);
 
                        DefaultEdge edge = new DefaultEdge();
                        GraphConstants.setLabelAlongEdge(edge.getAttributes(), true);
 
                        cell1.add(port00);
                        DefaultGraphCell cell2 = cell;
                        cell2.add(port01);
                        edge.setSource(port00);
                        GraphConstants.setOpaque(edge.getAttributes(), false);
                        int arrow = GraphConstants.ARROW_CLASSIC;
                        GraphConstants.setLineEnd(edge.getAttributes(), arrow);
                        GraphConstants.setEndFill(edge.getAttributes(), true);
                        GraphConstants.setLineWidth(edge.getAttributes(), 2.0f);
                        edge.setTarget(port01);
                        
                        if (edge.getUserObject() == null) {
                            edge.setUserObject("line" + edgeCount);
                            edgeCount++;
                        } else {
                            String lineName = edge.getUserObject().toString();
//                            if (lineName != null) {
//                                edges.setUserObject(lineName);
//                            } else {
                            if (lineName == null) {
                                edge.setUserObject("line" + edgeCount);
                                edgeCount++;
                            }
                        }
 
                        cell2 = null;
                        graph.getGraphLayoutCache().insert(edge);
                        setOo(graph.getRoots());
                    }
                    break;
                }
            }
 
            // 鼠标进入的时候执行的动作
            @Override
            public void mouseEntered(MouseEvent e) {
                // TODO Auto-generated method stub
 
            }
 
            // 鼠标退出的时候执行的动作
            @Override
            public void mouseExited(MouseEvent e) {
            }
 
        }
 
    }
 
    /**
     * added by zhouhui
     */
    private void addListenner() {
        /**
         * 查看使用范围
         */
        checkButton.addActionListener(new ActionListener() {
 
            @Override
            public void actionPerformed(ActionEvent e) {
                //door = false;
                LifeCycle selectedLC = lifeCycleTreeSelection();
                if (selectedLC == null) {
                    JOptionPane.showMessageDialog(null, "请选中要查看的生命周期", "无生命周期", JOptionPane.WARNING_MESSAGE);
                    return;
                }
                String name = selectedLC.name;
                if (name == null || name.equals("") || name.equals("生命周期模板列表")) {
                    JOptionPane.showMessageDialog(null, "请选中要查看的生命周期", "无生命周期", JOptionPane.WARNING_MESSAGE);
                    return;
                }
                UsedToDialog usedToDialog = new UsedToDialog(name);
                usedToDialog.setVisible(true);
            }
        });
    }
 
    /***
     * 
     * @param map
     * @return
     */
    public String getListImageKey(Map<String, String> map) {
        String key = null;
        Iterator iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            key = (String) entry.getKey();
        }
        return key;
    }
 
    /**
     * 跃迁事件
     */
    public void addTransationListener() {
        addTansitionEventButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                addData();
            }
        });
    }
 
    public void deleteTransationListener() {
        deleteTansitionEventButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                removeData();
            }
        });
    }
 
    public void saveTransationListener() {
        saveTansitionEventButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // isNoPressSaveTransitionEvents = true;
                save_transitionevents();
                JOptionPane.showMessageDialog(null, "保存成功");
                // //保存完了,清除表格数据
                //removeALLData();
 
            }
        });
    }
 
    private void addData() {
        eventTableModel.addRow("");
        tableEvent.updateUI();
    }
 
    private void removeData() {
        Object[] options = { "Yes", "No" };
        int option = JOptionPane.showOptionDialog(getInstance(), "确认是否删除跃迁事件", "跃迁事件删除", JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
        if (option != JOptionPane.YES_OPTION) {
            return;
        }
        int row = tableEvent.getSelectedRow();
        eventTableModel.removeRow(row);
        tableEvent.updateUI();
    }
 
//    private void removeALLData() {
//        eventTableModel.removeRows(0, eventTableModel.getRowCount());
//        tableEvent.updateUI();
//    }
 
    // 将跃迁对象绑定跃迁事件,返回保存生命周期前的跃迁对象集合
    public void save_transitionevents() {
        try {
            // Map<String, List<TransitionVOEvent>> map = new HashMap<String,
            // List<TransitionVOEvent>>();
            List<TransitionVOEvent> transitionevents = new ArrayList<TransitionVOEvent>();
            int row = eventTableModel.getRowCount();
            for (int i = 0; i < row; i++) {
                TransitionVOEvent transitionevent = new TransitionVOEvent();
                String key = (String) eventTableModel.getValueAt(i, 0);
                String value = LifeCycleTransitionEvents.getlce_events_valuebykey(key);
                transitionevent.id = key;
                transitionevent.name = value;
                transitionevents.add(transitionevent);
            }
 
            DefaultEdge selectedge = (DefaultEdge) lcGraph.getSelectionCell();
            String transition_name = selectedge.getUserObject().toString();
            mapTransitionEvents.put(transition_name, transitionevents);
 
//            map.put(transition_name, transitionevents);
//            transitionevents_maps = get_transitionevents_maps_instance();
//            Iterator<Map<String, List<TransitionVOEvent>>> transitioneventes = transitionevents_maps.iterator();
//            if (transitioneventes.hasNext()) {
//                Map<String, List<TransitionVOEvent>> transitionevent = transitioneventes.next();
//                if (transitionevent.containsKey(transition_name)) {
//                    transitioneventes.remove();
//                }
//            }
//            transitionevents_maps.add(map);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
 
    public void initlc_startState() {
        lc_startState.removeAllItems();
        List<Bound> bounds = new ArrayList<Bound>();
        Object[] o = lcGraph.getOo();
        if (o == null) {
            return;
        }
        for (int i = 0; i < o.length; i++) {
            if (o[i] instanceof DefaultGraphCell) {
                Bound bound = new Bound();
                DefaultGraphCell ci = (DefaultGraphCell) o[i];
                lc_startState.addItem(ci.toString());
            }
        }
    }
 
    public LifeCyclePanel getThis() {
        return this;
    }
 
    public List<LifeCycle> getSelectedLCs() {
        TreePath[] selectionPaths = treeLifeCycle.getSelectionPaths();
        // 未选中, 返回
        if (selectionPaths == null || selectionPaths.length == 0) {
            return null;
        }
        // 选中根节点, 返回
        if (selectionPaths.length == 1 && !(((DefaultMutableTreeNode) selectionPaths[0].getLastPathComponent())
                .getUserObject() instanceof LifeCycleWrapper)) {
            return null;
        }
        List<LifeCycle> list = new ArrayList<LifeCycle>();
        for (TreePath path : selectionPaths) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            Object obj = node.getUserObject();
            if (obj instanceof LifeCycleWrapper) {
                list.add(((LifeCycleWrapper) obj).getLC());
            }
        }
        return list;
    }
 
    // add by caill start 2016.3.31 刷新左侧导航栏内的“状态”的数据,但不改变JSplitpanel中间分隔线的位置
    public void flushed() {
        splitPane.remove(splitPane.getBottomComponent());
        JScrollPane scrollPane2 = new JScrollPane(new WestJpanel());
        //scrollPane.setPreferredSize(new Dimension(dimScreen.width / 6, scrollPane.getHeight()));// JSplitPanel分隔线位置是可以变化的,所以scrollPane的高度是动态变化的
        scrollPane2.setPreferredSize(new Dimension(dimScreen.width / 6, scrollPane2.getHeight()));
        splitPane.setBottomComponent(scrollPane2);
        ;// add by caill 2016.3.29将状态栏的scrollpanel2放到splitPane中
        splitPane.updateUI();
    }
    // add by caill end
}