001: package net.xoetrope.builder.editor;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Dimension;
005: import java.awt.GridLayout;
006: import java.awt.Rectangle;
007: import java.awt.event.ActionEvent;
008: import java.awt.event.ActionListener;
009: import javax.swing.JButton;
010: import javax.swing.JDialog;
011: import javax.swing.JPanel;
012: import javax.swing.JScrollPane;
013: import javax.swing.JTree;
014: import javax.swing.border.EmptyBorder;
015: import javax.swing.event.TreeSelectionEvent;
016: import javax.swing.event.TreeSelectionListener;
017: import javax.swing.tree.DefaultMutableTreeNode;
018: import javax.swing.tree.TreePath;
019:
020: import net.xoetrope.builder.editor.helper.XTableModelHelper;
021: import net.xoetrope.xui.XProjectManager;
022: import net.xoetrope.xui.data.XBaseModel;
023:
024: /**
025: * <p>Title: Xui</p>
026: * <p>Description: </p>
027: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003</p>
028: * <p>Company: Xoetrope Ltd.</p>
029: * @author not attributable
030: * @version 1.0
031: */
032:
033: public class XEditorDataManager extends JDialog implements
034: TreeSelectionListener, ActionListener {
035: private DefaultMutableTreeNode topNode;
036: private JTree dataTree;
037: private JScrollPane dataPane;
038: private JPanel mainPanel, pnlControls;
039: private JButton btnAdd, btnSave, btnCancel;
040:
041: public XEditorDataManager() {
042: mainPanel = new JPanel(new BorderLayout());
043: mainPanel.setBorder(new EmptyBorder(0, 0, 0, 0));
044: getContentPane().add(mainPanel);
045: pnlControls = new JPanel(new GridLayout(1, 3));
046: pnlControls.setPreferredSize(new Dimension(230, 100));
047: pnlControls.setBorder(new EmptyBorder(0, 0, 0, 0));
048: // mainPanel.add( pnlControls, BorderLayout.SOUTH );
049: btnAdd = new JButton("Add dataset");
050: pnlControls.add(btnAdd);
051: btnAdd.addActionListener(this );
052:
053: btnSave = new JButton("Save");
054: pnlControls.add(btnSave);
055: btnSave.addActionListener(this );
056:
057: btnCancel = new JButton("Cancel");
058: pnlControls.add(btnCancel);
059: btnCancel.addActionListener(this );
060:
061: setModal(true);
062: setSize(400, 400);
063: createTreeComp();
064: }
065:
066: public void centerScreen(Rectangle parentRect) {
067: double x = parentRect.getWidth() - getSize().getWidth();
068: double y = parentRect.getHeight() - getSize().getHeight();
069: setLocation((int) x, (int) y);
070: }
071:
072: public void valueChanged(TreeSelectionEvent evt) {
073:
074: }
075:
076: public void createTreeComp() {
077: XBaseModel model = (XBaseModel) XProjectManager.getModel();
078: topNode = new DefaultMutableTreeNode("Data");
079: dataTree = new JTree(topNode);
080: dataTree.setFont(XuiDefaults.defaultFont);
081: // dataTree.setCellRenderer( new XStyleCellRenderer());
082: dataTree.setScrollsOnExpand(true);
083: createTree();
084: dataTree.addTreeSelectionListener(this );
085: // dataTree.addMouseListener( this );
086: dataPane = new JScrollPane(dataTree);
087: dataPane.setBorder(new EmptyBorder(0, 0, 0, 0));
088: dataTree.setBorder(new EmptyBorder(0, 0, 0, 0));
089: mainPanel.add(dataPane, BorderLayout.CENTER);
090: }
091:
092: private DefaultMutableTreeNode createTree() {
093: topNode.removeAllChildren();
094: DefaultMutableTreeNode root = null;
095: DefaultMutableTreeNode subroot = null;
096:
097: TreePath path = new TreePath(topNode);
098: return topNode;
099: }
100:
101: private void addData() {
102: XBaseModel model = (XBaseModel) XProjectManager.getModel();
103: XBaseModel rowdata = (XBaseModel) XTableModelHelper
104: .addRow(model);
105: XTableModelHelper.addData(rowdata, "event", "alert");
106: XTableModelHelper.addData(rowdata, "Control", "");
107: XTableModelHelper.addData(rowdata, "cmd", "info");
108: XTableModelHelper.addData(rowdata, "hash", "");
109: XTableModelHelper.addData(rowdata, "tag", "");
110: XTableModelHelper.addData(rowdata, "frame", "");
111: }
112:
113: public void actionPerformed(ActionEvent ae) {
114: if (ae.getSource().equals(btnAdd)) {
115: addData();
116: }
117: }
118: }
|