KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > specifier > dialogs > ObjectInspectorDialog


1 package com.genimen.djeneric.tools.specifier.dialogs;
2
3 import java.awt.BorderLayout JavaDoc;
4 import java.awt.Dimension JavaDoc;
5 import java.awt.Frame JavaDoc;
6 import java.awt.Toolkit JavaDoc;
7 import java.awt.event.ActionEvent JavaDoc;
8 import java.awt.event.ActionListener JavaDoc;
9 import java.util.ArrayList JavaDoc;
10
11 import javax.swing.JButton JavaDoc;
12 import javax.swing.JDialog JavaDoc;
13 import javax.swing.JPanel JavaDoc;
14 import javax.swing.JScrollPane JavaDoc;
15 import javax.swing.JTable JavaDoc;
16 import javax.swing.table.TableCellEditor JavaDoc;
17 import javax.swing.table.TableCellRenderer JavaDoc;
18
19 import com.genimen.djeneric.language.Messages;
20 import com.genimen.djeneric.repository.DjDomain;
21 import com.genimen.djeneric.repository.DjObject;
22 import com.genimen.djeneric.repository.DjProperty;
23 import com.genimen.djeneric.repository.exceptions.DjenericException;
24 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException;
25 import com.genimen.djeneric.ui.DjModelColumn;
26 import com.genimen.djeneric.ui.DjTableModel;
27 import com.genimen.djeneric.ui.Util;
28 import com.genimen.djeneric.util.DjLogger;
29
30 public class ObjectInspectorDialog extends JDialog JavaDoc
31 {
32   private static final long serialVersionUID = 1L;
33   JPanel JavaDoc _buttonPanel = new JPanel JavaDoc();
34   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
35   JPanel JavaDoc _buttonEast = new JPanel JavaDoc();
36   JButton JavaDoc _butOk = new JButton JavaDoc();
37   JScrollPane JavaDoc _scroller = new JScrollPane JavaDoc();
38   JTable JavaDoc _table = new JTable JavaDoc();
39   BorderLayout JavaDoc borderLayout3 = new BorderLayout JavaDoc();
40
41   public ObjectInspectorDialog(Frame JavaDoc owner, DjObject object)
42   {
43     super(owner, object == null ? "Inspect" : object.toString(), true);
44     try
45     {
46       setDefaultCloseOperation(DISPOSE_ON_CLOSE);
47       jbInit();
48
49       if (object != null) _table.setModel(new ChangesTableModel(object));
50       setSize(400, 200);
51
52       Dimension JavaDoc screenSize = Toolkit.getDefaultToolkit().getScreenSize();
53       Dimension JavaDoc frameSize = getSize();
54       setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
55       setVisible(true);
56     }
57     catch (Exception JavaDoc x)
58     {
59       DjLogger.log(x);
60     }
61   }
62
63   public ObjectInspectorDialog()
64   {
65     this(new Frame JavaDoc(), null);
66   }
67
68   private void jbInit() throws Exception JavaDoc
69   {
70     _buttonPanel.setLayout(borderLayout2);
71     _butOk.setText(Messages.getString("global.Ok"));
72     _butOk.addActionListener(new ObjectInspectorDlg__butOk_actionAdapter(this));
73     this.getContentPane().setLayout(borderLayout3);
74     _buttonPanel.add(_buttonEast, java.awt.BorderLayout.EAST);
75     _buttonEast.add(_butOk);
76     _scroller.getViewport().add(_table);
77     this.getContentPane().add(_scroller, java.awt.BorderLayout.CENTER);
78     this.getContentPane().add(_buttonPanel, java.awt.BorderLayout.SOUTH);
79     Util.sizeButtons(_buttonEast);
80
81   }
82
83   public void _butOk_actionPerformed(ActionEvent JavaDoc e)
84   {
85     setVisible(false);
86   }
87 }
88
89 class ObjectInspectorDlg__butOk_actionAdapter implements ActionListener JavaDoc
90 {
91   private ObjectInspectorDialog adaptee;
92
93   ObjectInspectorDlg__butOk_actionAdapter(ObjectInspectorDialog adaptee)
94   {
95     this.adaptee = adaptee;
96   }
97
98   public void actionPerformed(ActionEvent JavaDoc e)
99   {
100     adaptee._butOk_actionPerformed(e);
101   }
102 }
103
104 class ChangesTableModel extends DjTableModel
105 {
106   private static final long serialVersionUID = 1L;
107   private final static int _colCount = 3;
108
109   private final static int IDX_NAME = 0;
110   private final static int IDX_OLD = 1;
111   private final static int IDX_NEW = 2;
112
113   String JavaDoc _propertyNames[];
114   DjObject _object;
115
116   public ChangesTableModel(DjObject object)
117   {
118     _columns = new DjModelColumn[_colCount];
119     _object = object;
120
121     ArrayList JavaDoc changedProps = new ArrayList JavaDoc();
122     for (int i = 0; i < object.getPropertyCount(); i++)
123     {
124       if (object.isPropertyChanged(i)) changedProps.add(object.getProperty(i).getName());
125     }
126     _propertyNames = (String JavaDoc[]) changedProps.toArray(new String JavaDoc[0]);
127
128     _columns[IDX_NAME] = new DjModelColumn(Messages.getString("ObjectInspector.Property"), 60, null);
129     _columns[IDX_OLD] = new DjModelColumn(Messages.getString("ObjectInspector.OldValue"), 60, null);
130     _columns[IDX_NEW] = new DjModelColumn(Messages.getString("ObjectInspector.NewValue"), 60, null);
131     setEditable(false);
132     setInsertable(false);
133     setDeleteable(false);
134   }
135
136   public TableCellEditor JavaDoc getColumnEditor(int column)
137   {
138     return null;
139   }
140
141   public TableCellRenderer JavaDoc getColumnRenderer(int column)
142   {
143     return _columns[column].getCellRenderer();
144   }
145
146   public int getRowCount()
147   {
148     return _propertyNames.length;
149   }
150
151   public int getColumnCount()
152   {
153     return _colCount;
154   }
155
156   public Object JavaDoc getValueAt(int row, int col)
157   {
158     try
159     {
160       if (col == IDX_NAME) return _object.getExtent().getProperty(_propertyNames[row]).getPrompt();
161       if (col == IDX_OLD) return getDspValue(_propertyNames[row], _object.getString(_propertyNames[row]));
162       if (col == IDX_NEW) return getDspValue(_propertyNames[row], _object.getOriginalValueString(_propertyNames[row]));
163       return "Unknown idx: " + col;
164     }
165     catch (Exception JavaDoc x)
166     {
167       DjLogger.log(x);
168       return x.getMessage();
169     }
170   }
171
172   private Object JavaDoc getDspValue(String JavaDoc propName, String JavaDoc value) throws ObjectNotDefinedException
173   {
174     DjProperty prop = _object.getProperty(propName);
175     if (prop.getType() instanceof DjDomain)
176     {
177       DjDomain domain = (DjDomain) prop.getType();
178       String JavaDoc descr = domain.translateCode(value);
179       if (descr != null) value = descr;
180     }
181     return value;
182   }
183
184   public void setValueAt(Object JavaDoc aValue, int rowIndex, int columnIndex)
185   {
186   }
187
188   public int insertRow(int atIdx) throws DjenericException
189   {
190     return 0;
191   }
192
193   public boolean deleteRow(int atIdx) throws DjenericException
194   {
195     return false;
196   }
197 }
198
Popular Tags