1 package com.jbidwatcher.ui;
2 
3 /*
4  * Copyright (c) 2000-2007, CyberFOX Software, Inc. All Rights Reserved.
5  *
6  * Developed by mrs (Morgan Schweers)
7  */
8 
9 import com.jbidwatcher.ui.config.JConfigTab;
10 import com.jbidwatcher.ui.util.*;
11 import com.jbidwatcher.util.config.JConfig;
12 
13 import javax.swing.*;
14 import java.awt.*;
15 
16 public class SnipeDialog extends BasicDialog {
17   private JTextField snipeAmount;
18   private JCheckBox subtractShipping;
19   private JLabel auctionInfo;
20   String mInitialValue="";
21 
SnipeDialog(String initial)22   public SnipeDialog(String initial) {
23     super(null, "Sniping", true, JMouseAdapter.getCurrentGraphicsConfiguration());
24     if(initial != null && initial.length() != 0) mInitialValue = initial;
25     construct();
26   }
27 
SnipeDialog()28   public SnipeDialog() {
29     super(null, "Sniping", true, JMouseAdapter.getCurrentGraphicsConfiguration());
30     construct();
31   }
32 
construct()33   private void construct() {
34     setBasicContentPane(new JPanel(new SpringLayout()));
35 
36     addBehavior();
37     setupUI();
38     //  JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
39   }
40 
onOK()41   protected void onOK() {
42     dispose();
43   }
44 
onCancel()45   protected void onCancel() {
46     setVisible(false);
47   }
48 
getAmount()49   public String getAmount() { return snipeAmount.getText().replace(',','.'); }
subtractShipping()50   public boolean subtractShipping() { return subtractShipping.isSelected(); }
51 
setPrompt(String prompt)52   public void setPrompt(String prompt) {
53     auctionInfo.setText(prompt);
54     auctionInfo.setVisible(true);
55     auctionInfo.invalidate();
56     getBasicContentPane().validate();
57     validate();
58   }
59 
clear()60   public void clear() {
61     getRootPane().setDefaultButton(getButtonOK());
62     snipeAmount.setText(mInitialValue);
63   }
64 
setupUI()65   private void setupUI() {
66     auctionInfo = new JLabel();
67     auctionInfo.setText("Auction Information");
68     //  The top section is the auction info.
69     getBasicContentPane().add(auctionInfo);
70 
71     JPanel inputPane = new JPanel();
72     inputPane.setLayout(new BoxLayout(inputPane, BoxLayout.Y_AXIS));
73 
74     snipeAmount = new JTextField(10);
75     snipeAmount.setText(mInitialValue);
76 
77     subtractShipping = new JCheckBox();
78     subtractShipping.setSelected(JConfig.queryConfiguration("snipe.subtract_shipping", "false").equals("true"));
79     subtractShipping.setText("Auto-subtract shipping and insurance (p/p)");
80 
81     JPanel promptPane = new JPanel(new SpringLayout());
82     JLabel snipeLabel;
83     promptPane.add(snipeLabel = new JLabel("How much do you wish to snipe?", JLabel.TRAILING));
84     snipeLabel.setLabelFor(snipeAmount);
85     promptPane.add(snipeAmount);
86     SpringUtilities.makeCompactGrid(promptPane, 1, 2, 6, 6, 6, 3);
87     getBasicContentPane().add(promptPane);
88     getBasicContentPane().add(subtractShipping);
89 
90     JPanel bottomPanel = new JPanel();
91     bottomPanel.setLayout(new BorderLayout());
92     bottomPanel.add(JConfigTab.makeLine(getButtonOK(), getButtonCancel()), BorderLayout.EAST);
93     getBasicContentPane().add(bottomPanel);
94     SpringUtilities.makeCompactGrid(getBasicContentPane(), 4, 1, 6, 6, 6, 6);
95   }
96 }
97