1 package org.hardcode.juf.ui;
2
3 import java.awt.BorderLayout;
4
5 import javax.swing.DefaultListModel;
6 import javax.swing.JList;
7 import javax.swing.JPanel;
8 import javax.swing.JSplitPane;
9 import javax.swing.JTextArea;
10
11 import org.hardcode.juf.update.Feature;
12 import org.hardcode.juf.update.Update;
13 /***
14 *
15 */
16 public class UpdatePanel extends JPanel {
17
18 private JSplitPane jSplitPane = null;
19 private JList lstUpdates = null;
20 private JTextArea txtUpdate = null;
21
22 private Update[] updates;
23
24 /***
25 * This is the default constructor
26 */
27 public UpdatePanel() {
28 super();
29 initialize();
30 }
31
32 public void setModel(Update[] jupdate){
33 this.updates = jupdate;
34 this.update();
35 }
36
37 private void update(){
38 DefaultListModel model = new DefaultListModel();
39 for (int i = 0; i < updates.length; i++) {
40 model.add(i, updates[i].getComponentName());
41 }
42
43 lstUpdates.setModel(model);
44 }
45
46 public Update[] getSelectedUpdates(){
47 int[] indexes = lstUpdates.getSelectedIndices();
48 Update[] updates = new Update[indexes.length];
49 for (int i = 0; i < updates.length; i++) {
50 updates[i] = this.updates[indexes[i]];
51 }
52
53 return updates;
54 }
55
56 /***
57 * This method initializes this
58 *
59 * @return void
60 */
61 private void initialize() {
62 this.setLayout(new BorderLayout());
63 this.setSize(300,200);
64 this.add(getJSplitPane(), java.awt.BorderLayout.CENTER);
65 }
66 /***
67 * This method initializes jSplitPane
68 *
69 * @return javax.swing.JSplitPane
70 */
71 private JSplitPane getJSplitPane() {
72 if (jSplitPane == null) {
73 jSplitPane = new JSplitPane();
74 jSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
75 jSplitPane.setDividerLocation(70);
76 jSplitPane.setTopComponent(getLstUpdates());
77 jSplitPane.setBottomComponent(getTxtUpdate());
78 }
79 return jSplitPane;
80 }
81 /***
82 * This method initializes lstUpdates
83 *
84 * @return javax.swing.JList
85 */
86 private JList getLstUpdates() {
87 if (lstUpdates == null) {
88 lstUpdates = new JList();
89 lstUpdates.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
90 public void valueChanged(javax.swing.event.ListSelectionEvent e) {
91 int updateIndex = lstUpdates.getSelectedIndex();
92
93 Feature[] caracs = updates[updateIndex].getFeature();
94 StringBuffer str = new StringBuffer();
95 for (int i = 0; i < caracs.length; i++) {
96 str.append(caracs[i].getContent() + "\n");
97 }
98
99 txtUpdate.setText(str.toString());
100 }
101 });
102 }
103 return lstUpdates;
104 }
105 /***
106 * This method initializes txtUpdate
107 *
108 * @return javax.swing.JTextArea
109 */
110 private JTextArea getTxtUpdate() {
111 if (txtUpdate == null) {
112 txtUpdate = new JTextArea();
113 }
114 return txtUpdate;
115 }
116 }