1 package com.jbidwatcher.ui;
2 /*
3  * Copyright (c) 2000-2007, CyberFOX Software, Inc. All Rights Reserved.
4  *
5  * Developed by mrs (Morgan Schweers)
6  */
7 
8 import com.jbidwatcher.util.config.JConfig;
9 import com.jbidwatcher.ui.util.JContext;
10 
11 import java.awt.*;
12 import java.awt.event.*;
13 import javax.swing.*;
14 
15 public abstract class JBidContext extends JContext {
16   protected JTable _inTable = null;
17 
JBidContext(JPopupMenu inPop)18   protected JBidContext(JPopupMenu inPop) {
19     super(inPop);
20   }
21 
JBidContext()22   protected JBidContext() { }
23 
setTable(JTable initTable)24   public void setTable(JTable initTable) {
25     _inTable = initTable;
26   }
27 
getPossibleRows()28   protected int[] getPossibleRows() {
29     if(_inTable == null) return null;
30     return _inTable.getSelectedRows();
31   }
32 
getIndexedEntry(int i)33   protected Object getIndexedEntry(int i) {
34     return _inTable.getValueAt(i, -1);
35   }
36 
figureAuction(JTable curTable, int rowPoint)37   private static Object figureAuction(JTable curTable, int rowPoint) {
38     return curTable.getValueAt(rowPoint, -1);
39   }
40 
DoAction(Object src, String actionString, Object whichAuction)41   protected abstract void DoAction(Object src, String actionString, Object whichAuction);
42 
beforePopup(JPopupMenu inPopup, MouseEvent e)43   protected void beforePopup(JPopupMenu inPopup, MouseEvent e) {
44     super.beforePopup(inPopup, e);
45     if(!(e.getComponent() instanceof JComponent)) return;
46     JComponent inComponent = (JComponent)e.getComponent();
47     if(inComponent instanceof JTable) {
48       _inTable = (JTable)inComponent;
49       int row = _inTable.rowAtPoint(e.getPoint());
50       if(!_inTable.isRowSelected(row)) _inTable.setRowSelectionInterval(row, row);
51     }
52   }
53 
internalDoubleClick(MouseEvent e)54   protected void internalDoubleClick(MouseEvent e) {
55     super.internalDoubleClick(e);
56     if(!(e.getComponent() instanceof JComponent)) return;
57     JComponent inComponent = (JComponent) e.getComponent();
58     if(inComponent instanceof JTable) {
59       JTable thisTable = (JTable) inComponent;
60 
61       int rowPoint = thisTable.rowAtPoint(new Point(e.getX(), e.getY()));
62       Object whichAuction = figureAuction(thisTable, rowPoint);
63 
64       DoAction(thisTable, JConfig.queryConfiguration("doubleclick.action", "Update"), whichAuction);
65     }
66   }
67 
resolvePoint()68   public Object resolvePoint() {
69     if(_inTable == null) return null;
70 
71     Point curRow = new Point(getPopupX(), getPopupY());
72     int rowPoint = _inTable.rowAtPoint(curRow);
73     return figureAuction(_inTable, rowPoint);
74   }
75 
actionPerformed(ActionEvent ae)76   public void actionPerformed(ActionEvent ae) {
77     super.actionPerformed(ae);
78 
79     Object whichAuction = resolvePoint();
80     String actionString = ae.getActionCommand();
81 
82     DoAction(ae.getSource(), actionString, whichAuction);
83   }
84 }
85