View Javadoc

1   /*
2    * $HeadURL: $
3    * $Date: $
4    * $Revision: $
5    * $Author: $
6    * 
7    * Copyright (c) 2005 MindTree Consulting Ltd. 
8    * 
9    * This file is part of Insight.
10   * 
11   * Insight is free software: you can redistribute it and/or modify it under the 
12   * terms of the GNU General Public License as published by the Free Software 
13   * Foundation, either version 3 of the License, or (at your option) any later 
14   * version.
15   * 
16   * Insight is distributed in the hope that it will be useful, but 
17   * WITHOUT ANY WARRANTY; without even the implied warranty of 
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
19   * Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public License along with 
22   * Insight.  If not, see <http://www.gnu.org/licenses/>.
23   */
24  package com.mindtree.techworks.insight.gui.preferences;
25  
26  import java.awt.GridLayout;
27  import java.awt.event.ActionEvent;
28  import java.awt.event.ActionListener;
29  import java.util.Enumeration;
30  
31  import javax.swing.BorderFactory;
32  import javax.swing.ButtonGroup;
33  import javax.swing.JCheckBox;
34  import javax.swing.JLabel;
35  import javax.swing.JPanel;
36  import javax.swing.JRadioButton;
37  
38  import com.mindtree.techworks.insight.InsightConstants;
39  import com.mindtree.techworks.insight.download.Fileset;
40  
41  /**
42  *
43  * The <code>FilesetsUIPanel</code> displays the UI for editing 
44  * global file set preferences.
45  *
46  * @see com.mindtree.techworks.insight.preferences.model.Preference
47  * @see com.mindtree.techworks.insight.gui.preferences.AbstractPreferencesUIPanel
48  *
49  * @author  Regunath B
50  * @version 1.0, 05/04/01
51  */
52  public class FilesetsUIPanel extends AbstractPreferencesUIPanel implements ActionListener {
53  	
54  	/**
55  	 * Used for object serialization
56  	 */
57  	private static final long serialVersionUID = -46917056193251251L;
58  	
59  	/**
60  	 * Constant for attribute Ids  
61  	 */
62  	private static final String SHOW_FILE_SETS = "showFilesetsOnLoad";
63  	private static final String FILE_SET_TYPE = "filesetType";
64  	private static final String TAIL_OPTION = "tailOption";
65  	
66  	/**
67  	 * Constant for 'true' and 'false' boolean value
68  	 */
69  	private static final String TRUE = "true";
70  	private static final String FALSE = "false";	
71  	
72  	/**
73  	 * The display widgets
74  	 */
75  	private JCheckBox tailopt;
76  	private JCheckBox showFileset;
77  	private JRadioButton localButton;
78  	private JRadioButton ftpButton;
79  	private JRadioButton sftpButton;
80  	private JRadioButton httpButton;
81  	private ButtonGroup bg;
82  
83  	/**
84  	 * No args constructor
85  	 */
86  	public FilesetsUIPanel() {
87  	}
88  
89  	/**
90  	 * ActionListener interface method implementation
91  	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
92  	 */
93  	public void actionPerformed(ActionEvent e) {
94  		checkEnable();
95  	}
96  
97  	/**
98  	 *  Overriden super class method
99  	 * @see com.mindtree.techworks.insight.gui.preferences.AbstractPreferencesUIPanel#initializeDisplay()
100 	 */
101 	protected void initializeDisplay() {
102 		//add a Check Box for tailing option
103 		this.tailopt = new JCheckBox(InsightConstants.getLiteral("ENABLE_TAILING"));
104 		tailopt.addActionListener(this);
105 		this.addComponent(tailopt,0,0,0,0,1,1);
106 		
107 		this.showFileset = new JCheckBox(InsightConstants.getLiteral("SHOW_FILESETS"));
108 		showFileset.addActionListener(this);
109 		addComponent(showFileset,0,1,0,0,1,1);
110 		
111 		JPanel panel = new JPanel();
112 		panel.setLayout(new GridLayout(3,1));
113 		panel.setBorder(BorderFactory.createTitledBorder(InsightConstants.getLiteral("FILESET_TYPE")));		
114 		
115 		bg = new ButtonGroup();
116 		this.localButton = new JRadioButton(InsightConstants.getLiteral("LOCAL_FILESETS"));
117 		localButton.setActionCommand(String.valueOf(Fileset.LOCAL_FILESET));
118 		bg.add(localButton);
119 		panel.add(localButton);
120 		
121 		this.ftpButton = new JRadioButton(InsightConstants.getLiteral("FTP_FILESETS"));
122 		ftpButton.setActionCommand(String.valueOf(Fileset.FTP_FILESET));
123 		bg.add(ftpButton);
124 		panel.add(ftpButton);
125 
126 		this.sftpButton = new JRadioButton(InsightConstants.getLiteral("SFTP_FILESETS"));
127 		sftpButton.setActionCommand(String.valueOf(Fileset.SFTP_FILESET));
128 		bg.add(sftpButton);
129 		panel.add(sftpButton);
130 		
131 		this.httpButton = new JRadioButton(InsightConstants.getLiteral("HTTP_FILESETS"));
132 		httpButton.setActionCommand(String.valueOf(Fileset.HTTP_FILESET));
133 		bg.add(httpButton);
134 		panel.add(httpButton);
135 		
136 		addComponent(panel,0,2,1,0,1,1);	
137 		// add an empty label to dock components to the top
138 		addComponent(new JLabel(),0,3,1,1,1,1);	
139 				
140 		//check or uncheck the CheckBoxes depending on the preference attribute value 
141 		this.tailopt.setSelected(this.preference.getPreferenceAttributeById(TAIL_OPTION).getValue().equalsIgnoreCase(TRUE));
142 		this.showFileset.setSelected(this.preference.getPreferenceAttributeById(SHOW_FILE_SETS).getValue().equals(TRUE));
143 		checkEnable();
144 	}
145 	
146 	/**
147 	 *  Overriden super class method
148 	 * @see com.mindtree.techworks.insight.gui.preferences.AbstractPreferencesUIPanel#setPreferenceValues()
149 	 */
150 	protected  void setPreferenceValues() {
151 		this.preference.getPreferenceAttributeById(SHOW_FILE_SETS).setValue(this.showFileset.isSelected() ? TRUE: FALSE);
152 		this.preference.getPreferenceAttributeById(TAIL_OPTION).setValue(this.tailopt.isSelected()?TRUE:FALSE);
153 		Enumeration buttons = bg.getElements();
154 		while(buttons.hasMoreElements()) {
155 			JRadioButton button = (JRadioButton)buttons.nextElement();
156 			if (button.isSelected()) {
157 				this.preference.getPreferenceAttributeById(FILE_SET_TYPE).setValue(button.getActionCommand());
158 				break;
159 			}
160 		}
161 	}
162 
163 	/**
164 	 * Helper method to check enable/disable of default fileset selection
165 	 */
166 	private void checkEnable() {
167 		this.localButton.setEnabled(this.showFileset.isSelected());
168 		this.ftpButton.setEnabled(this.showFileset.isSelected());
169 		this.sftpButton.setEnabled(this.showFileset.isSelected());
170 		this.httpButton.setEnabled(this.showFileset.isSelected());
171 		
172 		int type = Integer.parseInt(this.preference.getPreferenceAttributeById(FILE_SET_TYPE).getValue());
173 		this.localButton.setSelected(type == Fileset.LOCAL_FILESET);
174 		this.ftpButton.setSelected(type == Fileset.FTP_FILESET);
175 		this.sftpButton.setSelected(type == Fileset.SFTP_FILESET);
176 		this.httpButton.setSelected(type == Fileset.HTTP_FILESET);			
177 	}
178 
179 }