avatar

530

Finally eliminated a lot of the nasty tangles of code references (a references b references c references a) in the UI code. It's pretty decently clean now, and in the process the code has been factored out reasonably.

by mrs, 01 Jul, 2008 02:15 AM
529 530  
550550     //  Register the handler for all 'drop' events.
551551     JBWDropHandler.start();
552552     Browser.start();
553     JBidMouse.start();
553554 
554555     inSplash.message("Building Interface");
555556     jtmAuctions = JTabManager.getInstance();
529 530  
44 
55 import javax.swing.*;
66 import java.awt.Color;
7 import java.awt.event.ActionListener;
78 
89 /**
910  * Created by IntelliJ IDEA.
------
1920   private boolean mDeletable = true;
2021   private static JBidContext sFrameContext;
2122   private static JBidContext sTableContext;
22   private static JButton sCornerButton;
23   private static ActionListener sCornerButtonListener;
2324 
2425   public boolean isDeletable() {
2526     return mDeletable;
------
4243     mAuctionList = new Auctions(name);
4344     if(_completed) mAuctionList.setComplete();
4445     if(_selling) mAuctionList.setSelling();
45     mAuctionUI = new AuctionsUIModel(mAuctionList, sTableContext, sFrameContext, sCornerButton);
46     mAuctionUI = new AuctionsUIModel(mAuctionList, sTableContext, sFrameContext, sCornerButtonListener);
4647     mDeletable = deletable;
4748     JTabManager.getInstance().add(name, mAuctionUI.getPanel(), mAuctionUI.getTableSorter());
4849   }
------
5859     sTableContext = tableContext;
5960   }
6061 
61   public static void setCornerButton(JButton cornerButton) {
62     sCornerButton = cornerButton;
62   public static void setCornerButtonListener(ActionListener listener) {
63     sCornerButtonListener = listener;
6364   }
6465 }
523 530  
2323 import javax.swing.table.TableCellRenderer;
2424 import javax.swing.table.TableColumn;
2525 import java.awt.*;
26 import java.awt.event.ActionListener;
2627 import java.awt.dnd.DropTarget;
2728 import java.util.*;
2829 import java.util.List;
------
4748 
4849   /**
4950    * @brief Construct a new UI model for a provided auction list.
50    *
5151    * @param newAuctionList - The auction list to use as a 'backing
5252    * store' for displaying lists of auctions.
53    *
54    * @param tableContextMenu - The context menu to present for this table.
53    *@param tableContextMenu - The context menu to present for this table.
5554    * @param frameContextMenu - The context menu to present for whitespace outside the table.
56    * @param cornerButton - The button to sit above the scrollbar.
55    * @param cornerButtonListener - The button to sit above the scrollbar.
5756    */
58   public AuctionsUIModel(Auctions newAuctionList, JContext tableContextMenu, JContext frameContextMenu, JButton cornerButton) {
57   public AuctionsUIModel(Auctions newAuctionList, JContext tableContextMenu, JContext frameContextMenu, ActionListener cornerButtonListener) {
5958     _dataModel = newAuctionList;
6059 
6160     _targets = new DropTarget[2];
------
8887 
8988     //  This is a button to manage the custom columns for the current tab.
9089     if(JConfig.queryConfiguration("ui.useCornerButton", "true").equals("true")) {
90       JButton cornerButton = new JButton("*");
91       cornerButton.addActionListener(cornerButtonListener);
9192       _scroller.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, cornerButton);
9293     }
9394 
529 530  
3737 
3838   public void loadFilters() {
3939     //  BUGBUG -- Hardcoded for now, make dynamic later (post 0.8 release).
40     _main = new AuctionListHolder("current");
41     _main.setDeletable(false);
42     mList.add(_main);
40     mList.add(_main = new AuctionListHolder("current", false, false, false));
4341     mList.add(new AuctionListHolder("complete", true, false, false));
4442     mList.add(new AuctionListHolder("selling", false, true, false));
4543 
------
5452     } while (tabName != null);
5553   }
5654 
57   public AuctionListHolder addTab(String newTab) {
55   public Auctions addTab(String newTab) {
5856     Color mainBackground = _main.getUI().getBackground();
5957     Properties dispProps = new Properties();
6058     _main.getUI().getColumnWidthsToProperties(dispProps, newTab);
6159     JConfig.addAllToDisplay(dispProps);
6260     AuctionListHolder newList = new AuctionListHolder(newTab, mainBackground);
6361     mList.add(newList);
64     return newList;
62     return newList.getList();
6563   }
6664 
6765   /**  This is a singleton class, it needs an accessor.
------
174172     }
175173 
176174     if (category != null && !category.startsWith("New Search")) {
177       return addTab(category).getList();
175       return addTab(category);
178176     }
179177 
180178     return _main.getList();
------
223221           ae.setSticky(true);
224222           newAuctions = mList.findCategory(destination);
225223           if(newAuctions == null) {
226             AuctionListHolder alh = addTab(destination);
227             newAuctions = alh.getList();
224             newAuctions = addTab(destination);
228225           }
229226         }
230227       }
529 530  
33 import javax.swing.*;
44 import java.awt.event.ActionListener;
55 import java.awt.event.ActionEvent;
6 import java.awt.Component;
67 
78 /**
89  * Created by IntelliJ IDEA.
------
1314  * A simple initializer to inject particular objects into the AuctionListHolder's use.
1415  */
1516 public class Initializer {
16   private static JButton sCornerButton;
17   private static JTabPopupMenu sMenu;
1718 
1819   public static void setup() {
19     sCornerButton = new JButton("*");
20     sCornerButton.addActionListener(new ActionListener() {
20     JTabbedPane tabs = JTabManager.getInstance().getTabs();
21     sMenu = new JTabPopupMenu(tabs);
22     ActionListener cornerButtonListener = new ActionListener() {
2123       public void actionPerformed(ActionEvent e) {
22         JMenu bangMenu = JTabManager.getInstance().getCustomColumnMenu();
23         bangMenu.getPopupMenu().show(sCornerButton, 0, 0);
24         JMenu bangMenu = sMenu.getCustomizeMenu();
25         bangMenu.getPopupMenu().show((Component) e.getSource(), 0, 0);
2426       }
25     });
27     };
28     AuctionListHolder.setCornerButtonListener(cornerButtonListener);
2629 
27     JBidContext tableContextMenu = new JBidMouse();
30     JBidContext tableContextMenu = new JBidTableContext();
2831     JBidContext frameContextMenu = new JBidFrameMouse();
2932 
3033     AuctionListHolder.setFrameContext(frameContextMenu);
3134     AuctionListHolder.setTableContext(tableContextMenu);
32     AuctionListHolder.setCornerButton(sCornerButton);
3335   }
3436 }
24 530  
77 
88 import javax.swing.*;
99 
10 public class JBidFrameMouse extends JBidMouse {
10 public class JBidFrameMouse extends JBidTableContext {
1111   private JPopupMenu constructFramePopup() {
1212     JPopupMenu myPopup = new JPopupMenu();
1313 
528 530  
77 
88 import java.awt.*;
99 import java.awt.event.*;
10 import java.awt.datatransfer.*;
11 import java.awt.datatransfer.Clipboard;
1210 import java.io.*;
1311 import javax.swing.*;
1412 import java.util.*;
------
3533 import com.jbidwatcher.auction.server.AuctionServerManager;
3634 import com.jbidwatcher.auction.AuctionServerInterface;
3735 
38 public class JBidMouse extends JBidContext implements MessageQueue.Listener {
36 public class JBidMouse implements MessageQueue.Listener {
37   private static JTabManager mTabs = JTabManager.getInstance();
3938   private static JConfigFrame jcf = null;
4039   private static SearchFrame _searchFrame = null;
41   private JDropListener _jdl = new JDropListener(null); //  This would fail miserably if we called drop()...
4240   private OptionUI _oui = new OptionUI();
4341   private RSSDialog _rssDialog = null;
4442   private static StringBuffer _colorHelp = null;
------
4644   private static StringBuffer _faqText = null;
4745 
4846   private boolean _in_deleting = false;
49   private JMenu tabMenu = null;
5047   private ScriptManager mScriptFrame;
48   private static JBidMouse sInstance;
5149 
52   public JBidMouse(JPopupMenu inPopup) {
53     super(inPopup);
54     buildMenu(inPopup);
55   }
50   private JBidMouse() { }
5651 
57   public JBidMouse() {
58     buildMenu(localPopup);
59     MQFactory.getConcrete("user").registerListener(this);
60   }
61 
6252   public static void setConfigFrame(JConfigFrame curCfg) {
6353     if(curCfg != null) jcf = curCfg;
6454   }
------
144134     }
145135   }
146136 
147   protected boolean confirmDeletion(Component src, String prompt) {
148     int endResult = JOptionPane.showOptionDialog(src, prompt,
149         "Confirm", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
150         null, null, null);
151 
152     return !(endResult == JOptionPane.CANCEL_OPTION ||
153             endResult == JOptionPane.CLOSED_OPTION);
154 
155   }
156 
157137   private void DoHideShowToolbar() {
158138     MQFactory.getConcrete("Swing").enqueue("TOOLBAR");
159139   }
------
177157 
178158   private void DoShowLastError(Component src, AuctionEntry passedAE) {
179159     AuctionEntry ae = passedAE;
180     int[] rowList = getPossibleRows();
160     int[] rowList = mTabs.getPossibleRows();
181161 
182162     if(ae == null && rowList.length == 0 || rowList.length > 1) {
183163       JOptionPane.showMessageDialog(src, "You must select a single auction to view the error page for.",
------
185165       return;
186166     }
187167 
188     if(ae == null) ae = (AuctionEntry) getIndexedEntry(rowList[0]);
168     if(ae == null) ae = (AuctionEntry) mTabs.getIndexedEntry(rowList[0]);
189169 
190170     StringBuffer wholeStatus = ae.getErrorPage();
191171     Dimension statusBox = new Dimension(756, 444);
------
208188 
209189     ArrayList<AuctionEntry> deleteIds = new ArrayList<AuctionEntry>();
210190     StringBuffer wholeDelete = new StringBuffer();
211     int[] rowList = getPossibleRows();
191     int[] rowList = mTabs.getPossibleRows();
212192 
213193     if(ae == null && rowList.length == 0) {
214194       _in_deleting = false;
------
221201       wholeDelete.append("<table border=0 spacing=0 width=\"100%\">");
222202       wholeDelete.append("<tr><td><u><b>Item Number</b></u></td><td><u><b>Title</b></u></td></tr>");
223203       for(int i = 0; i<rowList.length; i++) {
224         AuctionEntry tempEntry = (AuctionEntry) getIndexedEntry(rowList[i]);
204         AuctionEntry tempEntry = (AuctionEntry) mTabs.getIndexedEntry(rowList[i]);
225205         deleteIds.add(tempEntry);
226206         String color = "FFFFFF";
227207         if( (i % 2) == 1) {
------
245225       statusBox = new Dimension(756, Math.min(372, rowList.length * 30 + 30));
246226     } else {
247227       if(rowList.length == 1) {
248         ae = (AuctionEntry) getIndexedEntry(rowList[0]);
228         ae = (AuctionEntry) mTabs.getIndexedEntry(rowList[0]);
249229       }
250230       if ((ae == null)) {
251231         throw new IllegalArgumentException();
------
315295     }
316296   }
317297 
318   private String getClipboardString() {
319     Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
320     Transferable t = sysClip.getContents(null);
321 
322     ErrorManagement.logDebug("Clipboard: " + sysClip.getName() + ", valid flavors: " + Arrays.toString(t.getTransferDataFlavors()));
323 
324     StringBuffer stBuff = _jdl.getTransferData(t);
325     String clipString;
326     if(stBuff == null) {
327       try {
328         clipString = (String)t.getTransferData(DataFlavor.stringFlavor);
329       } catch(Exception e) {
330         //  Nothing really to do here...
331         clipString = null;
332       }
333     } else {
334       clipString = stBuff.toString();
335     }
336 
337     return clipString;
338   }
339 
340298   private static Pattern digitSearch = Pattern.compile("[0-9]+");
341299 
342300   private void DoPasteFromClipboard() {
343     String auctionId = getClipboardString();
301     String auctionId = Clipboard.getClipboardString();
344302     String original = auctionId;
345303 
346304     if(auctionId.charAt(0) == '<') {
------
408366 
409367     for (int aRowList : rowList) {
410368       try {
411         AuctionEntry ae2 = (AuctionEntry) getIndexedEntry(aRowList);
369         AuctionEntry ae2 = (AuctionEntry) mTabs.getIndexedEntry(aRowList);
412370         if (accum == null) {
413371           accum = ae2.getUSCurBid();
414372           realAccum = getBestBidValue(ae2);
------
450408     return accum.toString();
451409   }
452410 
453   private void DoSendTo(String tab) {
454     int[] rowList = getPossibleRows();
455 
456     if(rowList.length == 0) {
457       JOptionPane.showMessageDialog(null, "No auctions selected to move!", "Error moving listings", JOptionPane.PLAIN_MESSAGE);
458       return;
459     }
460 
461     Category c = Category.findFirstByName(tab);
462 
463     if(c == null) {
464       JOptionPane.showMessageDialog(null, "Cannot locate that tab, something has gone wrong.\nClose and restart JBidwatcher.", "Error moving listings", JOptionPane.PLAIN_MESSAGE);
465       return;
466     }
467 
468     //  Build a temporary table, because the items will vanish out of
469     //  the table when we start refiltering them, and that will mess
470     //  everything up.
471     ArrayList<AuctionEntry> tempTable = new ArrayList<AuctionEntry>(rowList.length);
472     for (int aRowList : rowList) {
473       AuctionEntry moveEntry = (AuctionEntry) getIndexedEntry(aRowList);
474       tempTable.add(moveEntry);
475     }
476 
477     //  Now move all entries in the temporary table to the new tab.
478     for (AuctionEntry moveEntry : tempTable) {
479       moveEntry.setCategory(tab);
480       MQFactory.getConcrete("redraw").enqueue(moveEntry);
481     }
482   }
483 
484411   private void DoAdd(Component src) {
485412     String prompt = "Enter the auction number to add";
486413 
------
506433   }
507434 
508435   private void CancelSnipe(Component src, AuctionEntry ae) {
509     int[] rowList = getPossibleRows();
436     int[] rowList = mTabs.getPossibleRows();
510437     int len = rowList.length;
511438 
512439     if(ae == null && len == 0) {
------
517444 
518445     if(len != 0) {
519446       for (int aRowList : rowList) {
520         AuctionEntry tempEntry = (AuctionEntry) getIndexedEntry(aRowList);
447         AuctionEntry tempEntry = (AuctionEntry) mTabs.getIndexedEntry(aRowList);
521448 
522449         tempEntry.cancelSnipe(false);
523450         MQFactory.getConcrete("redraw").enqueue(tempEntry);
------
549476   }
550477 
551478   private void DoInformation(Component src, AuctionEntry ae) {
552     int[] rowList = getPossibleRows();
479     int[] rowList = mTabs.getPossibleRows();
553480 
554481     int len = rowList.length;
555482     if(ae == null && len == 0) {
------
564491   private void showComplexInformation(int[] rowList) {
565492     StringBuffer prompt = new StringBuffer();
566493     for (int aRowList : rowList) {
567       AuctionEntry stepAE = (AuctionEntry) getIndexedEntry(aRowList);
494       AuctionEntry stepAE = (AuctionEntry) mTabs.getIndexedEntry(aRowList);
568495       prompt.append(stepAE.buildInfoHTML(false)).append("<hr>");
569496     }
570497     Dimension statusBox = new Dimension(480, Math.min(372, rowList.length * 30 + 200));
------
602529     boolean foundDangerousSnipe=false;
603530 
604531     for(int i = 0; i<rowList.length && !foundDangerousSnipe; i++) {
605       AuctionEntry ae1 = (AuctionEntry) getIndexedEntry(rowList[i]);
532       AuctionEntry ae1 = (AuctionEntry) mTabs.getIndexedEntry(rowList[i]);
606533       if(ms != null) {
607534         if(!ms.isSafeToAdd(ae1)) foundDangerousSnipe = true;
608535       }
609536 
610537       for(int j = i + 1; j<rowList.length && !foundDangerousSnipe; j++) {
611         AuctionEntry ae2 = (AuctionEntry) getIndexedEntry(rowList[j]);
538         AuctionEntry ae2 = (AuctionEntry) mTabs.getIndexedEntry(rowList[j]);
612539         if(!MultiSnipe.isSafeMultiSnipe(ae1, ae2)) {
613540           foundDangerousSnipe = true;
614541         }
------
619546   }
620547 
621548   private void DoMultiSnipe(Component src) {
622     int[] rowList = getPossibleRows();
549     int[] rowList = mTabs.getPossibleRows();
623550     Currency baseAllBid = Currency.NoValue();
624551 
625552     //  You must select multiple auctions to make this work.
------
633560     MultiSnipe aeMS = null;
634561     int i;
635562     for(i=0; i<rowList.length; i++) {
636       AuctionEntry tempAE = (AuctionEntry) getIndexedEntry(rowList[i]);
563       AuctionEntry tempAE = (AuctionEntry) mTabs.getIndexedEntry(rowList[i]);
637564       Currency curBid = tempAE.getCurBid();
638565 
639566       if(tempAE.getServer().isDefaultUser()) {
------
753680     }
754681 
755682     for(i=0; i<rowList.length; i++) {
756       AuctionEntry stepAE = (AuctionEntry)getIndexedEntry(rowList[i]);
683       AuctionEntry stepAE = (AuctionEntry)mTabs.getIndexedEntry(rowList[i]);
757684       stepAE.setMultiSnipe(aeMS);
758685       MQFactory.getConcrete("redraw").enqueue(stepAE);
759686     }
------
780707 
781708   private void DoSnipe(Component src, AuctionEntry passedAE) {
782709     AuctionEntry ae = passedAE;
783     int[] rowList = getPossibleRows();
710     int[] rowList = mTabs.getPossibleRows();
784711 
785712     if(rowList.length > 1) {
786713       DoMultiSnipe(src);
787714       return;
788715     }
789716     if(rowList.length == 1) {
790       ae = (AuctionEntry) getIndexedEntry(rowList[0]);
717       ae = (AuctionEntry) mTabs.getIndexedEntry(rowList[0]);
791718     }
792719     if (ae == null) {
793720       JOptionPane.showMessageDialog(src, "You have not chosen an auction to snipe on!",
------
981908 
982909   private void DoShowInBrowser(Component src, AuctionEntry inAuction) {
983910     AuctionEntry ae = inAuction;
984     int[] rowList = getPossibleRows();
911     int[] rowList = mTabs.getPossibleRows();
985912 
986913     if(rowList.length != 0) {
987914 //      Vector<String> multiAuctionIds = new Vector<String>();
988915 //      int i;
989916 //
990917 //      for(i=0; i<rowList.length; i++) {
991 //        AuctionEntry tempEntry = (AuctionEntry) getIndexedEntry(rowList[i]);
918 //        AuctionEntry tempEntry = (AuctionEntry) mTabs.getIndexedEntry(rowList[i]);
992919 //
993920 //        multiAuctionIds.add(tempEntry.getIdentifier());
994921 //      }
995922 //      TODO -- Find another way to do this...
996923 //      JBidProxy.setItems(multiAuctionIds);
997924 
998       ae = (AuctionEntry) getIndexedEntry(rowList[0]);
925       ae = (AuctionEntry) mTabs.getIndexedEntry(rowList[0]);
999926     } else {
1000927       if(ae == null) {
1001928         JOptionPane.showMessageDialog(src, "Cannot launch browser from menu, you must select an auction.", "Menu Error", JOptionPane.PLAIN_MESSAGE);
------
10981025   }
10991026 
11001027   private void DoUpdate(Component src, AuctionEntry inAuction) {
1101     int[] rowList = getPossibleRows();
1028     int[] rowList = mTabs.getPossibleRows();
11021029 
11031030     if(rowList.length != 0) {
11041031       for (int aRowList : rowList) {
1105         AuctionEntry tempEntry = (AuctionEntry) getIndexedEntry(aRowList);
1032         AuctionEntry tempEntry = (AuctionEntry) mTabs.getIndexedEntry(aRowList);
11061033 
11071034         tempEntry.setNeedsUpdate();
11081035         if (tempEntry.isComplete() || tempEntry.isPaused()) {
------
11221049   }
11231050 
11241051   private void DoSetNotEnded(AuctionEntry whichAuction) {
1125     int[] rowList = getPossibleRows();
1052     int[] rowList = mTabs.getPossibleRows();
11261053 
11271054     if (rowList.length != 0) {
11281055       for (int aRowList : rowList) {
1129         AuctionEntry tempEntry = (AuctionEntry) getIndexedEntry(aRowList);
1056         AuctionEntry tempEntry = (AuctionEntry) mTabs.getIndexedEntry(aRowList);
11301057 
11311058         tempEntry.setComplete(false);
11321059         tempEntry.setNeedsUpdate();
------
12831210    */
12841211   private void DoCopySomething(Component src, AuctionEntry passedAE, int action, String fail_msg, String seperator) {
12851212     AuctionEntry ae = passedAE;
1286     int[] rowList = getPossibleRows();
1213     int[] rowList = mTabs.getPossibleRows();
12871214 
12881215     if(ae == null && rowList.length == 0) {
12891216       JOptionPane.showMessageDialog(src, fail_msg, "Error copying", JOptionPane.PLAIN_MESSAGE);
------
12941221       StringBuffer sb = new StringBuffer();
12951222 
12961223       for(int i = 0; i<rowList.length; i++) {
1297         AuctionEntry tempEntry = (AuctionEntry) getIndexedEntry(rowList[i]);
1224         AuctionEntry tempEntry = (AuctionEntry) mTabs.getIndexedEntry(rowList[i]);
12981225 
12991226         if(i != 0) sb.append(seperator);
13001227 
13011228         sb.append(getActionValue(action, tempEntry));
13021229       }
13031230 
1304       com.jbidwatcher.ui.util.Clipboard.setClipboardString(sb.toString());
1231       Clipboard.setClipboardString(sb.toString());
13051232     } else {
13061233       //  Shortcut to not have to create and destroy a Stringbuffer
1307       if(rowList.length == 1) ae = (AuctionEntry) getIndexedEntry(rowList[0]);
1234       if(rowList.length == 1) ae = (AuctionEntry) mTabs.getIndexedEntry(rowList[0]);
13081235 
1309       com.jbidwatcher.ui.util.Clipboard.setClipboardString(getActionValue(action, ae));
1236       Clipboard.setClipboardString(getActionValue(action, ae));
13101237     }
13111238   }
13121239 
------
13911318     _oui.promptWithCheckbox(src, "Cleared " + clearedCount + " deleted entries.", "Clear Complete", "prompt.clear_complete", JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_OPTION);
13921319   }
13931320 
1394   protected void buildMenu(JPopupMenu menu) {
1395     menu.add(makeMenuItem("Snipe")).addActionListener(this);
1396     menu.add(makeMenuItem("Cancel Snipe")).addActionListener(this);
1397     menu.add(new JPopupMenu.Separator());
1398 
1399     menu.add(makeMenuItem("Bid")).addActionListener(this);
1400     menu.add(makeMenuItem("Buy")).addActionListener(this);
1401     menu.add(new JPopupMenu.Separator());
1402 
1403     menu.add(makeMenuItem("Update Auction", "Update")).addActionListener(this);
1404     menu.add(makeMenuItem("Show Information", "Information")).addActionListener(this);
1405     menu.add(makeMenuItem("Show In Browser", "Browse")).addActionListener(this);
1406     //menu.add(makeMenuItem("Add Up Prices", "Sum")).addActionListener(this);
1407     menu.add(new JPopupMenu.Separator());
1408     menu.add(makeMenuItem("Set Shipping", "Shipping")).addActionListener(this);
1409     menu.add(new JPopupMenu.Separator());
1410 
1411     tabMenu = new JMenu("Send To");
1412     menu.add(tabMenu);
1413     JMenu comment = new JMenu("Comment");
1414     comment.add(makeMenuItem("Add", "Add Comment")).addActionListener(this);
1415     comment.add(makeMenuItem("View", "View Comment")).addActionListener(this);
1416     comment.add(makeMenuItem("Remove", "Remove Comment")).addActionListener(this);
1417     menu.add(comment);
1418     JMenu advanced = new JMenu("Advanced");
1419     advanced.add(makeMenuItem("Show Last Error", "ShowError")).addActionListener(this);
1420     advanced.add(makeMenuItem("Mark As Not Ended", "NotEnded")).addActionListener(this);
1421     menu.add(advanced);
1422     menu.add(new JPopupMenu.Separator());
1423 
1424     menu.add(makeMenuItem("Delete")).addActionListener(this);
1425   }
1426 
1427   protected void beforePopup(JPopupMenu jp, MouseEvent e) {
1428     ActionListener tabActions = new ActionListener() {
1429         public void actionPerformed(ActionEvent action) {
1430           String toTab = action.getActionCommand();
1431           DoSendTo(toTab);
1432         }
1433       };
1434     super.beforePopup(jp, e);
1435 
1436     if(tabMenu != null) {
1437       tabMenu.removeAll();
1438 
1439       JTabbedPane tabbedPane = JTabManager.getInstance().getTabs();
1440       String currentTitle = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
1441       List<String> tabs = Category.categories();
1442       if(tabs == null) {
1443         tabMenu.setEnabled(false);
1444       } else {
1445         tabs.remove("selling");
1446         tabs.remove(currentTitle);
1447         tabMenu.setEnabled(true);
1448         for (String tab : tabs) {
1449           tabMenu.add(makeMenuItem(tab)).addActionListener(tabActions);
1450         }
1451       }
1452     }
1453 
1454     /**
1455      * This sucks.  I need to push the generic code up, and leave the auction-specific code here, or
1456      * somehow move all the non-auction-specific functionality to its own class.  This code is broken,
1457      * at the least because it has to use 'instanceof' to work.
1458      */
1459     Object resolvedObject = resolvePoint();
1460     AuctionEntry ae = null;
1461 
1462     if(resolvedObject != null && resolvedObject instanceof AuctionEntry) {
1463       ae = (AuctionEntry) resolvedObject;
1464     }
1465 
1466     int[] rowList = getPossibleRows();
1467 
1468     if(rowList != null && rowList.length != 0) {
1469       if(rowList.length == 1) {
1470         Object firstSelected = getIndexedEntry(rowList[0]);
1471         if(firstSelected != null && firstSelected instanceof AuctionEntry) {
1472           ae = (AuctionEntry) firstSelected;
1473         }
1474       } else {
1475         ae = null;
1476       }
1477     }
1478 
1479     //  Ignored if it wasn't renamed, but otherwise always restore to 'known state'.
1480     rename("Multisnipe", "Snipe");
1481     rename("Edit", "Add");               // Comment
1482 
1483     if(ae != null) {
1484       if(ae.getComment() == null) {
1485         disable("View");
1486         disable("Remove");
1487       } else {
1488         rename("Add", "Edit");
1489       }
1490       if(!ae.isSniped()) disable("Cancel Snipe");
1491       if(!ae.isComplete()) {
1492         disable("Complete");
1493         disable("Mark As Not Ended");
1494       } else {
1495         enable("Mark As Not Ended");
1496       }
1497 
1498       if(ae.isSeller() || ae.isComplete()) {
1499         disable("Buy");
1500         disable("Bid");
1501         disable("Snipe");
1502       }
1503 
1504       if(ae.isFixed()) {
1505         disable("Bid");
1506         disable("Snipe");
1507       }
1508 
1509       if(!ae.isFixed() && ae.getBuyNow().isNull()) {
1510         disable("Buy");
1511       }
1512     }
1513 
1514     if(rowList != null && rowList.length > 1) {
1515       disable("Bid");
1516       disable("Buy");
1517       disable("Show Last Error");
1518       disable("Set Shipping");
1519       disable("Add");
1520       disable("View");
1521       disable("Remove");
1522 
1523       boolean anySniped = false;
1524       boolean anyFixed = false;
1525       boolean anyEnded = false;
1526       boolean anyCurrent = false;
1527       for (int aRowList : rowList) {
1528         Object line = getIndexedEntry(aRowList);
1529         AuctionEntry step = (AuctionEntry) line;
1530         if (step.isSniped()) anySniped = true;
1531         if (step.isFixed()) anyFixed = true;
1532         if (step.isComplete()) anyEnded = true;
1533         if (!step.isComplete()) anyCurrent = true;
1534       }
1535 
1536       if(!anySniped) disable("Cancel Snipe");
1537       if(anyFixed || anyEnded) disable("Snipe");
1538       if(!anyCurrent) enable("Complete");
1539       if(anyEnded) enable("Mark As Not Ended"); else disable("Mark As Not Ended");
1540       rename("Snipe", "Multisnipe");
1541     }
1542 
1543     if(ae == null || ae.getErrorPage() == null) {
1544       disable("Show Last Error");
1545     }
1546   }
1547 
15481321   protected void DoAction(Object src, String actionString, Object whichAuction) {
15491322     DoAction(src, actionString, (AuctionEntry)whichAuction);
15501323   }
------
16141387     else if(actionString.equals("Report Bug")) MQFactory.getConcrete("browse").enqueue("http://jbidwatcher.lighthouseapp.com/projects/8037-jbidwatcher/tickets");
16151388     else ErrorManagement.logDebug('[' + actionString + ']');
16161389   }
1390 
1391   public static void start() {
1392     if (sInstance == null) MQFactory.getConcrete("user").registerListener(sInstance = new JBidMouse());
1393   }
16171394 }
428 530  
1313 import java.awt.*;
1414 import java.awt.dnd.*;
1515 import java.awt.datatransfer.*;
16 import java.awt.datatransfer.Clipboard;
1617 import java.lang.reflect.*;
1718 
1819 public class JDropListener implements DropTargetListener {
355 530  
1818 import java.awt.event.*;
1919 import java.util.ArrayList;
2020 
21 public class JSearchContext extends JBidMouse {
21 public class JSearchContext extends JBidTableContext {
2222   private static SearchInfoDialog _searchDetail = null;
2323 
2424   private void addMenu(JPopupMenu p, String name, String cmd) {
------
160160     doSingle(null, NEW);
161161   }
162162 
163   protected boolean confirmDeletion(Component src, String prompt) {
164     int endResult = JOptionPane.showOptionDialog(src, prompt,
165         "Confirm", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
166         null, null, null);
167 
168     return !(endResult == JOptionPane.CANCEL_OPTION ||
169         endResult == JOptionPane.CLOSED_OPTION);
170   }
171 
163172   private void DoDelete(Searcher chosenSearch) {
164173     Searcher s = chosenSearch;
165174     int[] rows = getPossibleRows();
528 530  
2121 public class JTabManager extends JMouseAdapter {
2222   private JTabbedPane mAuctionTypes;
2323   private Map<String, TableSorter> mNameTableMap = new TreeMap<String, TableSorter>();
24   private JTabPopupMenu mPopupMenu;
2524   private static JTabManager sInstance;
2625 
2726   /**
------
3837     return sInstance;
3938   }
4039 
41   public JTabManager() {
40   private JTabManager() {
4241     mAuctionTypes = new JTabbedPane();
43     mPopupMenu = new JTabPopupMenu(mAuctionTypes);
44     mAuctionTypes.addMouseListener(mPopupMenu);
4542     mAuctionTypes.addChangeListener(new ChangeListener() {
4643       // This method is called whenever the selected tab changes
4744       public void stateChanged(ChangeEvent evt) {
------
5249     });
5350   }
5451 
55   public JMenu getCustomColumnMenu() {
56     return mPopupMenu.getCustomizeMenu();
57   }
58 
5952   public JTabbedPane getTabs() {
6053     return mAuctionTypes;
6154   }
------
154147     return getCurrentTable().getValueAt(i, -1);
155148   }
156149 
157   public void actionPerformed(ActionEvent ae) {
150   public void actionPerformed(ActionEvent event) {
158151     AuctionEntry whichAuction = null;
159     String actionString = ae.getActionCommand();
152     String actionString = event.getActionCommand();
160153     TableSorter chosenTable = getCurrentTable();
161154     boolean isButton = false;
162155 
------
178171       }
179172     }
180173 
181     MQFactory.getConcrete("user").enqueue(new ActionTriple(ae.getSource(), actionString, whichAuction));
174     MQFactory.getConcrete("user").enqueue(new ActionTriple(event.getSource(), actionString, whichAuction));
182175   }
183176 
184177   public void sortDefault() {
529 530  
1919 import java.util.List;
2020 
2121 public class JTabPopupMenu extends JContext {
22   private JTabbedPane _myTabs = null;
22   private JTabbedPane mTabs = null;
2323   private JMenu customize = null;
2424   private JMenuItem _print = null;
2525   private JMenu _deleteSubmenu = null;
------
6464    */
6565   protected void beforePopup(JPopupMenu inPopup, MouseEvent e) {
6666     super.beforePopup(inPopup, e);
67     int curIndex = _myTabs.indexAtLocation(e.getX(), e.getY());
67     int curIndex = mTabs.indexAtLocation(e.getX(), e.getY());
6868     preparePopup(curIndex);
6969   }
7070 
------
100100       menuItemMap.put(s, colMenuItem);
101101     }
102102 
103     if(tabIndex == null) tabIndex = _myTabs.getSelectedIndex();
103     if(tabIndex == null) tabIndex = mTabs.getSelectedIndex();
104104     customize.setEnabled(true);
105     String tabName = _myTabs.getTitleAt(tabIndex);
105     String tabName = mTabs.getTitleAt(tabIndex);
106106     uncheckAll();
107107     setColumnChecks(tabName);
108108   }
------
127127 
128128   public void actionPerformed(ActionEvent ae) {
129129     super.actionPerformed(ae);
130     DoAction(ae.getActionCommand(), _myTabs.getSelectedIndex());
130     DoAction(ae.getActionCommand(), mTabs.getSelectedIndex());
131131   }
132132 
133133   protected JFrame propFrame = null;
------
172172   protected void DoAction(String actionString, int tabIndex) {
173173     if(actionString.equals("Add Tab")) {
174174       OptionUI oui = new OptionUI();
175       String result = oui.promptString(_myTabs.getComponentAt(tabIndex>=0?tabIndex:0), "Enter the name of the tab to add.  Prefer brevity.", "Add New Tab", "");
175       String result = oui.promptString(mTabs.getComponentAt(tabIndex>=0?tabIndex:0), "Enter the name of the tab to add.  Prefer brevity.", "Add New Tab", "");
176176 
177177       if(result == null) return;
178178       result = result.trim();
------
182182       return;
183183     }
184184 
185     String tabName = _myTabs.getTitleAt(tabIndex);
185     String tabName = mTabs.getTitleAt(tabIndex);
186186     if(actionString.charAt(0) == '~') {
187187       boolean result = ListManager.getInstance().toggleField(tabName, actionString.substring(1));
188188       if(tabToProperties != null) {
------
244244         if(removed == null) {
245245           JOptionPane.showMessageDialog(null, "Could not delete tab [" + tabName + "].", "Tab deletion error", JOptionPane.PLAIN_MESSAGE);
246246         } else {
247           JTabManager.getInstance().getTabs().remove(removed);
247           mTabs.remove(removed);
248248         }
249249       }
250250     }
------
256256    * on the tabbed display.
257257    */
258258   public JTabPopupMenu(JTabbedPane inTabs) {
259     _myTabs = inTabs;
259     mTabs = inTabs;
260260     localPopup = new JPopupMenu();
261261     makeTabMenu(localPopup);
262     inTabs.addMouseListener(this);
262263   }
263264 
264265   /**
------
269270    * @param popup - The popup to add the behavior to.
270271    */
271272   public JTabPopupMenu(JTabbedPane inTabs, JPopupMenu popup) {
272     _myTabs = inTabs;
273     mTabs = inTabs;
273274     localPopup = popup;
274275     makeTabMenu(localPopup);
275276   }
416 530  
404404     return _table.getSelectedRows();
405405   }
406406 
407   public JTable getTable() { return _table; }
408 
407409   private class SortMouseAdapter extends MouseAdapter
408410   {
409411     private final JTable mTable;