avatar

956

Better integration between JBidwatcher and My JBidwatcher. by mrs, 17 Jun, 2009 01:25 AM
Diff this changeset:
JConfigFrame.java
mrs      1   package com.jbidwatcher.ui.config;
cyberfox 2   /*
cyberfox 3    * Copyright (c) 2000-2007, CyberFOX Software, Inc. All Rights Reserved.
cyberfox 4    *
cyberfox 5    * Developed by mrs (Morgan Schweers)
cyberfox 6    */
cyberfox 7   
cyberfox 8   import com.jbidwatcher.platform.Platform;
mrs      9   import com.jbidwatcher.util.config.*;
mrs      10  import com.jbidwatcher.util.Constants;
mrs      11  import com.jbidwatcher.ui.util.JBidFrame;
mrs      12  import com.jbidwatcher.ui.util.OptionUI;
mrs      13  import com.jbidwatcher.auction.server.ebay.*;
cyberfox 14  
cyberfox 15  import java.awt.*;
cyberfox 16  import java.awt.event.ActionEvent;
cyberfox 17  import java.awt.event.ActionListener;
cyberfox 18  import java.awt.event.WindowAdapter;
cyberfox 19  import java.awt.event.WindowEvent;
cyberfox 20  import java.util.List;
cyberfox 21  import java.util.ArrayList;
cyberfox 22  
cyberfox 23  import javax.swing.JButton;
cyberfox 24  import javax.swing.JFrame;
cyberfox 25  import javax.swing.JPanel;
cyberfox 26  import javax.swing.JTabbedPane;
cyberfox 27  import javax.swing.JLabel;
cyberfox 28  
cyberfox 29  /**
cyberfox 30   * Implements the "Configure" frames. This holds all the configuration options.
cyberfox 31   *
cyberfox 32   * @version $Revision: 1.38 $
cyberfox 33   */
cyberfox 34  public class JConfigFrame implements ActionListener {
cyberfox 35    private JFrame mainFrame;
cyberfox 36    private boolean buttonPressed = false;
cyberfox 37    private List<JConfigTab> allTabs;
cyberfox 38    private static int cfgCount = 1;
cyberfox 39  
cyberfox 40    public void spinWait() {
cyberfox 41      while(!buttonPressed) {
cyberfox 42        try { //noinspection MultiplyOrDivideByPowerOfTwo,BusyWait
mrs      43          Thread.sleep(Constants.ONE_SECOND/2);
cyberfox 44        } catch(InterruptedException ignored) {
cyberfox 45          //  We don't care that we caught an exception, just that we woke up.
cyberfox 46        }
cyberfox 47      }
cyberfox 48    }
cyberfox 49  
mrs      50    public JConfigFrame() {
mrs      51      mainFrame = createConfigFrame();
mrs      52      Rectangle rec = OptionUI.findCenterBounds(mainFrame.getPreferredSize());
cyberfox 53      mainFrame.setLocation(rec.x, rec.y);
cyberfox 54      show();
cyberfox 55    }
cyberfox 56  
cyberfox 57    public final void show() {
cyberfox 58      for (JConfigTab jct : allTabs) {
cyberfox 59        jct.updateValues();
cyberfox 60      }
cyberfox 61      mainFrame.setState(Frame.NORMAL);
cyberfox 62      mainFrame.setVisible(true);
cyberfox 63    }
cyberfox 64  
cyberfox 65    private void applyAll() {
cyberfox 66      for (JConfigTab jct : allTabs) {
cyberfox 67        jct.apply();
cyberfox 68      }
cyberfox 69    }
cyberfox 70  
cyberfox 71    private void cancelAll() {
cyberfox 72      for (JConfigTab jct : allTabs) {
cyberfox 73        jct.cancel();
cyberfox 74      }
cyberfox 75    }
cyberfox 76  
cyberfox 77    public void actionPerformed(ActionEvent ae) {
cyberfox 78      String actionString = ae.getActionCommand();
cyberfox 79  
cyberfox 80      if(actionString.equals("Save")) {
cyberfox 81        applyAll();
cyberfox 82        JConfig.updateComplete();
cyberfox 83        JConfig.saveConfiguration();
cyberfox 84      } else if(actionString.equals("Cancel")) {
cyberfox 85        cancelAll();
cyberfox 86      }
cyberfox 87  
cyberfox 88      mainFrame.setVisible(false);
cyberfox 89      buttonPressed = true;
cyberfox 90    }
cyberfox 91  
cyberfox 92    public static JPanel buildButtonPane(ActionListener al) {
cyberfox 93      JPanel tp = new JPanel();
cyberfox 94  
cyberfox 95      JButton cancelButton = new JButton("Cancel");
cyberfox 96      cancelButton.setToolTipText("Cancel any changes made.");
cyberfox 97      JButton saveButton = new JButton("Save");
cyberfox 98      saveButton.setToolTipText("Apply changes and save settings.");
cyberfox 99  
cyberfox 100     tp.add(cancelButton, BorderLayout.WEST);
cyberfox 101     tp.add(  saveButton, BorderLayout.CENTER);
cyberfox 102 
cyberfox 103     cancelButton.addActionListener(al);
cyberfox 104     saveButton.addActionListener(al);
cyberfox 105 
cyberfox 106     return(tp);
cyberfox 107   }
cyberfox 108 
cyberfox 109   private static void anotherConfig() {
cyberfox 110     cfgCount++;
cyberfox 111   }
cyberfox 112 
mrs      113   private JFrame createConfigFrame() {
cyberfox 114     JTabbedPane jtpAllTabs = new JTabbedPane();
cyberfox 115     final JFrame w;
cyberfox 116 
cyberfox 117     if(cfgCount == 2) {
mrs      118       w = new JBidFrame("Configuration Manager (2)");
cyberfox 119     } else {
cyberfox 120       anotherConfig();
mrs      121       w = new JBidFrame("Configuration Manager");
cyberfox 122     }
cyberfox 123 
cyberfox 124     Container contentPane = w.getContentPane();
cyberfox 125     contentPane.setLayout(new BorderLayout());
cyberfox 126     contentPane.add(jtpAllTabs, BorderLayout.CENTER);
cyberfox 127 
cyberfox 128     allTabs = new ArrayList<JConfigTab>();
cyberfox 129 
cyberfox 130     //  Add all non-server-specific tabs here.
cyberfox 131     allTabs.add(new JConfigGeneralTab());
mrs      132     allTabs.add(new JConfigEbayTab(Constants.EBAY_DISPLAY_NAME, Constants.SITE_CHOICES));
cyberfox 133 
cyberfox 134     //  Stub the browser tab under MacOSX, so they don't try to use it.
cyberfox 135     if(Platform.isMac()) {
cyberfox 136       allTabs.add(new JConfigMacBrowserTab());
cyberfox 137     } else {
cyberfox 138       allTabs.add(new JConfigBrowserTab());
cyberfox 139     }
mrs      140     allTabs.add(new JConfigFirewallTab());
cyberfox 141     allTabs.add(new JConfigSnipeTab());
mrs      142 //    if(JConfig.queryConfiguration("allow.my_jbidwatcher", "false").equals("true"))
mrs      143       allTabs.add(new JConfigMyJBidwatcherTab());
mrs      144     allTabs.add(new JConfigFilePathTab());
cyberfox 145     allTabs.add(new JConfigWebserverTab());
mrs      146     allTabs.add(new JConfigDatabaseTab());
cyberfox 147 
cyberfox 148     allTabs.add(new JConfigSecurityTab());
mrs      149     allTabs.add(new JConfigAdvancedTab());
cyberfox 150 
cyberfox 151     //  HACKHACK -- Presently all tabs created need to have 3 rows of
cyberfox 152     //  GridLayout.  In general, all tabs have to have the same number
cyberfox 153     //  of rows.  This is likely to suck, in the long run.  For now,
cyberfox 154     //  it's the requirement.  If you have more or less, the display
cyberfox 155     //  either for that tab (if it has less), or for all the others
cyberfox 156     //  (if it has more) will look somewhat wonky.
cyberfox 157 
cyberfox 158     //  Loop over all tabs, and add them to the display.
cyberfox 159     for (JConfigTab allTab : allTabs) {
cyberfox 160       allTab.setOpaque(true);
cyberfox 161       jtpAllTabs.addTab(allTab.getTabName(), allTab);
cyberfox 162     }
cyberfox 163 
cyberfox 164     jtpAllTabs.setSelectedIndex(0);
cyberfox 165     contentPane.add(buildButtonPane(this), BorderLayout.SOUTH);
cyberfox 166 
cyberfox 167     w.addWindowListener(new IconifyingWindowAdapter(w));
cyberfox 168     w.pack();
cyberfox 169     w.setResizable(false);
cyberfox 170     return w;
cyberfox 171   }
cyberfox 172 
cyberfox 173   private class JConfigSecurityTab extends JConfigStubTab {
cyberfox 174     public String getTabName() { return("Security"); }
cyberfox 175   }
cyberfox 176 
cyberfox 177   private final class JConfigMacBrowserTab extends JConfigStubTab {
cyberfox 178     public String getTabName() { return("Browser"); }
cyberfox 179 
cyberfox 180     JConfigMacBrowserTab() {
cyberfox 181       JLabel newLabel = new JLabel("Under MacOSX, the browser does not need to be configured.");
cyberfox 182       setLayout(new BorderLayout());
cyberfox 183       add(newLabel, BorderLayout.CENTER);
cyberfox 184     }
cyberfox 185   }
cyberfox 186 
cyberfox 187   public static class IconifyingWindowAdapter extends WindowAdapter {
cyberfox 188     private final JFrame _window;
cyberfox 189 
cyberfox 190     public IconifyingWindowAdapter(JFrame window) {
cyberfox 191       _window = window;
cyberfox 192     }
cyberfox 193 
cyberfox 194     public void windowIconified(WindowEvent we) {
cyberfox 195       super.windowIconified(we);
mrs      196       if(Platform.supportsTray() && Platform.isTrayEnabled()) {
cyberfox 197         if(JConfig.queryConfiguration("windows.tray", "true").equals("true") &&
cyberfox 198            JConfig.queryConfiguration("windows.minimize", "true").equals("true")) {
cyberfox 199           _window.setVisible(false);
cyberfox 200         }
cyberfox 201       }
cyberfox 202     }
cyberfox 203 
cyberfox 204     public void windowDeiconified(WindowEvent we) {
cyberfox 205       super.windowDeiconified(we);
mrs      206       if(Platform.supportsTray() && Platform.isTrayEnabled()) {
cyberfox 207         if(JConfig.queryConfiguration("windows.tray", "true").equals("true") &&
cyberfox 208            JConfig.queryConfiguration("windows.minimize", "true").equals("true")) {
cyberfox 209           _window.setState(Frame.NORMAL);
cyberfox 210           _window.setVisible(true);
cyberfox 211         }
cyberfox 212       }
cyberfox 213     }
cyberfox 214   }
cyberfox 215 }

Check out the code: svn co jbidwatcher/trunk/src/com/jbidwatcher/ui/config/JConfigFrame.java