01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.applications.designstudio.components;
16:
17: import java.awt.Component;
18: import java.awt.event.MouseAdapter;
19: import java.awt.event.MouseEvent;
20:
21: import javax.swing.Icon;
22: import javax.swing.JLabel;
23: import javax.swing.JTable;
24: import javax.swing.table.AbstractTableModel;
25: import javax.swing.table.DefaultTableCellRenderer;
26: import javax.swing.table.TableColumn;
27:
28: import com.metaboss.applications.designstudio.Application;
29: import com.metaboss.applications.designstudio.BaseUserObject;
30: import com.metaboss.applications.designstudio.Application.ObjectChangedEvent;
31:
32: /* Fields table class */
33:
34: public class FieldsTable extends JTable {
35: public FieldsTable(AbstractTableModel pModel) {
36: super (pModel);
37:
38: TableColumn lFirstColumn = getColumnModel().getColumn(0);
39: lFirstColumn.setMinWidth(20);
40: lFirstColumn.setMaxWidth(20);
41: lFirstColumn.setCellRenderer(new DefaultTableCellRenderer() {
42: private JLabel mLabel = new JLabel();
43:
44: public Component getTableCellRendererComponent(
45: JTable table, Object value, boolean isSelected,
46: boolean hasFocus, int row, int column) {
47: mLabel.setIcon((Icon) value);
48: return mLabel;
49: }
50: });
51:
52: addMouseListener(new MouseHandler());
53:
54: Application
55: .addObjectChanged(new Application.ObjectChangedListener() {
56: public void onObjectChanged(ObjectChangedEvent event) {
57: switch (event.getEventSource()) {
58: case ObjectChangedEvent.ET_INSERTED:
59: getSelectionModel().setLeadSelectionIndex(
60: getRowCount() - 1);
61: break;
62: }
63: }
64: });
65: }
66:
67: /* Table Mouse Events Handler */
68:
69: public class MouseHandler extends MouseAdapter {
70: public void mousePressed(MouseEvent e) {
71: if (((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0)
72: && e.getClickCount() == 2) {
73: if (getModel() instanceof FieldsModel) {
74: BaseUserObject lField = ((FieldsModel) getModel())
75: .getUserObject(getSelectedRow());
76: if (lField != null)
77: lField.getEditAction().run();
78: }
79: }
80: super.mousePressed(e);
81: }
82: }
83: }
|