avatar

862

Add a Database settings tab, to allow easy configuration of a MySQL database connection. It won't actually work until the restart, which is why I added code to support restart on some platforms. I also need to make sure that it'll load the auction data from one database to the other. Not sure how to do that OTHER than the auctions.xml yet. by mrs, 12 Apr, 2009 06:12 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")) allTabs.add(new JConfigMyJBidwatcherTab());
mrs      143     allTabs.add(new JConfigFilePathTab());
cyberfox 144     allTabs.add(new JConfigWebserverTab());
mrs      145     allTabs.add(new JConfigDatabaseTab());
cyberfox 146 
cyberfox 147     allTabs.add(new JConfigSecurityTab());
mrs      148     allTabs.add(new JConfigAdvancedTab());
cyberfox 149 
cyberfox 150     //  HACKHACK -- Presently all tabs created need to have 3 rows of
cyberfox 151     //  GridLayout.  In general, all tabs have to have the same number
cyberfox 152     //  of rows.  This is likely to suck, in the long run.  For now,
cyberfox 153     //  it's the requirement.  If you have more or less, the display
cyberfox 154     //  either for that tab (if it has less), or for all the others
cyberfox 155     //  (if it has more) will look somewhat wonky.
cyberfox 156 
cyberfox 157     //  Loop over all tabs, and add them to the display.
cyberfox 158     for (JConfigTab allTab : allTabs) {
cyberfox 159       allTab.setOpaque(true);
cyberfox 160       jtpAllTabs.addTab(allTab.getTabName(), allTab);
cyberfox 161     }
cyberfox 162 
cyberfox 163     jtpAllTabs.setSelectedIndex(0);
cyberfox 164     contentPane.add(buildButtonPane(this), BorderLayout.SOUTH);
cyberfox 165 
cyberfox 166     w.addWindowListener(new IconifyingWindowAdapter(w));
cyberfox 167     w.pack();
cyberfox 168     w.setResizable(false);
cyberfox 169     return w;
cyberfox 170   }
cyberfox 171 
cyberfox 172   private class JConfigSecurityTab extends JConfigStubTab {
cyberfox 173     public String getTabName() { return("Security"); }
cyberfox 174   }
cyberfox 175 
cyberfox 176   private final class JConfigMacBrowserTab extends JConfigStubTab {
cyberfox 177     public String getTabName() { return("Browser"); }
cyberfox 178 
cyberfox 179     JConfigMacBrowserTab() {
cyberfox 180       JLabel newLabel = new JLabel("Under MacOSX, the browser does not need to be configured.");
cyberfox 181       setLayout(new BorderLayout());
cyberfox 182       add(newLabel, BorderLayout.CENTER);
cyberfox 183     }
cyberfox 184   }
cyberfox 185 
cyberfox 186   public static class IconifyingWindowAdapter extends WindowAdapter {
cyberfox 187     private final JFrame _window;
cyberfox 188 
cyberfox 189     public IconifyingWindowAdapter(JFrame window) {
cyberfox 190       _window = window;
cyberfox 191     }
cyberfox 192 
cyberfox 193     public void windowIconified(WindowEvent we) {
cyberfox 194       super.windowIconified(we);
mrs      195       if(Platform.supportsTray() && Platform.isTrayEnabled()) {
cyberfox 196         if(JConfig.queryConfiguration("windows.tray", "true").equals("true") &&
cyberfox 197            JConfig.queryConfiguration("windows.minimize", "true").equals("true")) {
cyberfox 198           _window.setVisible(false);
cyberfox 199         }
cyberfox 200       }
cyberfox 201     }
cyberfox 202 
cyberfox 203     public void windowDeiconified(WindowEvent we) {
cyberfox 204       super.windowDeiconified(we);
mrs      205       if(Platform.supportsTray() && Platform.isTrayEnabled()) {
cyberfox 206         if(JConfig.queryConfiguration("windows.tray", "true").equals("true") &&
cyberfox 207            JConfig.queryConfiguration("windows.minimize", "true").equals("true")) {
cyberfox 208           _window.setState(Frame.NORMAL);
cyberfox 209           _window.setVisible(true);
cyberfox 210         }
cyberfox 211       }
cyberfox 212     }
cyberfox 213   }
cyberfox 214 }

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