01: package org.zilonis.tool.ui;
02:
03: import java.awt.BorderLayout;
04: import java.awt.FlowLayout;
05: import java.awt.event.ActionEvent;
06: import java.awt.event.ActionListener;
07: import java.util.Arrays;
08: import java.util.HashMap;
09: import java.util.Set;
10: import java.util.TreeSet;
11:
12: import javax.swing.Box;
13: import javax.swing.DefaultListModel;
14: import javax.swing.JList;
15: import javax.swing.JPanel;
16: import javax.swing.JScrollPane;
17:
18: import org.zilonis.tool.ext.aerith.ui.AerithScrollbarUI;
19: import org.zilonis.tool.ext.aerith.ui.BackgroundTitle;
20:
21: public class WMEPanel extends JPanel {
22:
23: private HashMap<String, WMEMetaData> wmeTemplates = new HashMap<String, WMEMetaData>();
24: private JList list;
25: private ActionButton addFactButton;
26:
27: public WMEPanel() {
28: initComponents();
29: }
30:
31: public void initComponents() {
32: setOpaque(false);
33: //setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 2, 2, 2));
34: setLayout(new BorderLayout());
35: list = new JList();
36: list.setOpaque(false);
37: list.setCellRenderer(new WMEListCellRenderer());
38: list.setPrototypeCellValue("xxx");
39: JScrollPane scrollPane = new JScrollPane(list);
40: scrollPane.setOpaque(false);
41: scrollPane.getViewport().setOpaque(false);
42: scrollPane.getHorizontalScrollBar().setUI(
43: new AerithScrollbarUI());
44: scrollPane.getVerticalScrollBar()
45: .setUI(new AerithScrollbarUI());
46: scrollPane
47: .setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
48: add(scrollPane, BorderLayout.CENTER);
49: add(BorderLayout.NORTH, new BackgroundTitle("Expected Facts"));
50: add(BorderLayout.WEST, Box.createHorizontalStrut(60));
51: add(BorderLayout.EAST, Box.createHorizontalStrut(60));
52: JPanel buttonPanel = new JPanel();
53: buttonPanel.setOpaque(false);
54: buttonPanel.setLayout(new FlowLayout());
55: addFactButton = new ActionButton("Add Fact");
56: addFactButton.setMain(true);
57: buttonPanel.add(addFactButton);
58: add(BorderLayout.SOUTH, buttonPanel);
59: }
60:
61: public void setPanelEventHandler(
62: final AnalysisToolParserEventHandler analysisToolParserEventHandler) {
63: addFactButton.addActionListener(new ActionListener() {
64: public void actionPerformed(ActionEvent event) {
65: AddFactPanel p = new AddFactPanel((WMEMetaData) list
66: .getModel().getElementAt(
67: list.getSelectedIndex()),
68: analysisToolParserEventHandler);
69: JPanel base = new JPanel();
70: base.setOpaque(false);
71: base.setBorder(javax.swing.BorderFactory
72: .createEmptyBorder(130, 30, 30, 30));
73: base.add(p);
74: TransitionManager.setGlassPane(base);
75: base.setVisible(true);
76: }
77: });
78: }
79:
80: public void addWMETemplate(WMEMetaData template) {
81: WMEMetaData old = wmeTemplates.get(template.getClazz());
82: if (old != null) {
83: Set<String> fullList = new TreeSet<String>();
84: fullList.addAll(Arrays.asList(old.getAttribute()));
85: for (String att : template.getAttribute()) {
86: fullList.add(att);
87: }
88: template = new WMEMetaData(template.getClazz(), fullList
89: .toArray(new String[0]));
90: }
91: wmeTemplates.put(template.getClazz(), template);
92: DefaultListModel model = new DefaultListModel();
93: for (WMEMetaData wmeTemplate : wmeTemplates.values()) {
94: model.addElement(wmeTemplate);
95: }
96: list.setModel(model);
97: }
98:
99: }
|