001    /*
002     * LogPanel.java
003     *
004     * Created on May 22, 2003, 12:41 PM
005     *
006     * This file is part of the STAR Scheduler.
007     * Copyright (c) 2002-2006 STAR Collaboration - Brookhaven National Laboratory
008     *
009     * STAR Scheduler is free software; you can redistribute it and/or modify
010     * it under the terms of the GNU General Public License as published by
011     * the Free Software Foundation; either version 2 of the License, or
012     * (at your option) any later version.
013     *
014     * STAR Scheduler is distributed in the hope that it will be useful,
015     * but WITHOUT ANY WARRANTY; without even the implied warranty of
016     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017     * GNU General Public License for more details.
018     *
019     * You should have received a copy of the GNU General Public License
020     * along with STAR Scheduler; if not, write to the Free Software
021     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
022     */
023    
024    package gov.bnl.star.offline.scheduler.config;
025    
026    /**
027     *
028     * @author  Gabriele Carcassi
029     */
030    public class StatisticsPanel extends javax.swing.JPanel implements WizardPanel {
031        
032        /** Creates new form LogPanel */
033        public StatisticsPanel() {
034            initComponents();
035        }
036        
037        /** This method is called from within the constructor to
038         * initialize the form.
039         * WARNING: Do NOT modify this code. The content of this method is
040         * always regenerated by the Form Editor.
041         */
042        private void initComponents() {//GEN-BEGIN:initComponents
043            java.awt.GridBagConstraints gridBagConstraints;
044    
045            instructions = new javax.swing.JTextArea();
046            statSwitchLabel = new javax.swing.JLabel();
047            statSwitch = new javax.swing.JComboBox();
048            dbURLLabel = new javax.swing.JLabel();
049            dbURL = new javax.swing.JTextField();
050            dbUserLabel = new javax.swing.JLabel();
051            dbUsername = new javax.swing.JTextField();
052            dbPasswordLabel = new javax.swing.JLabel();
053            password = new javax.swing.JTextField();
054    
055            setLayout(new java.awt.GridBagLayout());
056    
057            instructions.setEditable(false);
058            instructions.setLineWrap(true);
059            instructions.setText("The scheduler can write the statistics about the usage to a database\nstastics - on or off to turn on and off statistics\nURL/username/password - used to tell the JDBC driver which DB to use");
060            instructions.setWrapStyleWord(true);
061            instructions.setFocusable(false);
062            instructions.setOpaque(false);
063            gridBagConstraints = new java.awt.GridBagConstraints();
064            gridBagConstraints.gridwidth = 4;
065            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
066            gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
067            gridBagConstraints.weightx = 1.0;
068            gridBagConstraints.insets = new java.awt.Insets(5, 5, 15, 5);
069            add(instructions, gridBagConstraints);
070    
071            statSwitchLabel.setText("switch*");
072            gridBagConstraints = new java.awt.GridBagConstraints();
073            gridBagConstraints.gridx = 0;
074            gridBagConstraints.gridy = 1;
075            gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
076            gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
077            add(statSwitchLabel, gridBagConstraints);
078    
079            statSwitch.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "", "on", "off" }));
080            statSwitch.addItemListener(new java.awt.event.ItemListener() {
081                public void itemStateChanged(java.awt.event.ItemEvent evt) {
082                    comboChange(evt);
083                }
084            });
085    
086            gridBagConstraints = new java.awt.GridBagConstraints();
087            gridBagConstraints.gridx = 1;
088            gridBagConstraints.gridy = 1;
089            gridBagConstraints.gridwidth = 3;
090            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
091            gridBagConstraints.weightx = 1.0;
092            gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
093            add(statSwitch, gridBagConstraints);
094    
095            dbURLLabel.setText("JDBC URL");
096            gridBagConstraints = new java.awt.GridBagConstraints();
097            gridBagConstraints.gridx = 0;
098            gridBagConstraints.gridy = 2;
099            gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
100            gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
101            add(dbURLLabel, gridBagConstraints);
102    
103            dbURL.addKeyListener(new java.awt.event.KeyAdapter() {
104                public void keyTyped(java.awt.event.KeyEvent evt) {
105                    textChange(evt);
106                }
107            });
108    
109            gridBagConstraints = new java.awt.GridBagConstraints();
110            gridBagConstraints.gridx = 1;
111            gridBagConstraints.gridy = 2;
112            gridBagConstraints.gridwidth = 3;
113            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
114            gridBagConstraints.weightx = 1.0;
115            gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
116            add(dbURL, gridBagConstraints);
117    
118            dbUserLabel.setText("username");
119            gridBagConstraints = new java.awt.GridBagConstraints();
120            gridBagConstraints.gridx = 0;
121            gridBagConstraints.gridy = 3;
122            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
123            gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
124            add(dbUserLabel, gridBagConstraints);
125    
126            dbUsername.addKeyListener(new java.awt.event.KeyAdapter() {
127                public void keyTyped(java.awt.event.KeyEvent evt) {
128                    textChange(evt);
129                }
130            });
131    
132            gridBagConstraints = new java.awt.GridBagConstraints();
133            gridBagConstraints.gridx = 1;
134            gridBagConstraints.gridy = 3;
135            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
136            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
137            gridBagConstraints.weightx = 1.0;
138            gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
139            add(dbUsername, gridBagConstraints);
140    
141            dbPasswordLabel.setText("password");
142            gridBagConstraints = new java.awt.GridBagConstraints();
143            gridBagConstraints.gridx = 2;
144            gridBagConstraints.gridy = 3;
145            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
146            gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
147            add(dbPasswordLabel, gridBagConstraints);
148    
149            password.addKeyListener(new java.awt.event.KeyAdapter() {
150                public void keyTyped(java.awt.event.KeyEvent evt) {
151                    textChange(evt);
152                }
153            });
154    
155            gridBagConstraints = new java.awt.GridBagConstraints();
156            gridBagConstraints.gridx = 3;
157            gridBagConstraints.gridy = 3;
158            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
159            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
160            gridBagConstraints.weightx = 1.0;
161            gridBagConstraints.weighty = 1.0;
162            gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
163            add(password, gridBagConstraints);
164    
165        }//GEN-END:initComponents
166    
167        private void textChange(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textChange
168            firePropertyChange("ready", oldReady, isReady());
169            oldReady = isReady();
170        }//GEN-LAST:event_textChange
171    
172        private void comboChange(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboChange
173            firePropertyChange("ready", oldReady, isReady());
174            oldReady = isReady();
175        }//GEN-LAST:event_comboChange
176    
177        private boolean oldReady;
178        public String getTitle() {
179            return "Statistics";
180        }    
181        
182        public boolean isReady() {
183            if (statSwitch.getSelectedIndex() == 2) return true;
184            if (statSwitch.getSelectedIndex() == 0) return false;
185            if ("".equals(dbURL.getText())) return false;
186            return true;
187        }
188        
189        public void addProperties(java.util.Map schedulerProperties) {
190            schedulerProperties.put("statistics", statSwitch.getSelectedItem());
191            schedulerProperties.put("statistics.URL", dbURL.getText());
192            schedulerProperties.put("statistics.username", dbUsername.getText());
193            schedulerProperties.put("statistics.password", password.getText());
194        }
195        
196        // Variables declaration - do not modify//GEN-BEGIN:variables
197        private javax.swing.JLabel dbPasswordLabel;
198        private javax.swing.JTextField dbURL;
199        private javax.swing.JLabel dbURLLabel;
200        private javax.swing.JLabel dbUserLabel;
201        private javax.swing.JTextField dbUsername;
202        private javax.swing.JTextArea instructions;
203        private javax.swing.JTextField password;
204        private javax.swing.JComboBox statSwitch;
205        private javax.swing.JLabel statSwitchLabel;
206        // End of variables declaration//GEN-END:variables
207        
208    }