View Javadoc

1   /*
2    *  Copyright (C) 2003-2005 SINTEF
3    *  Author:  Fredrik Vraalsen (fredrik dot vraalsen at sintef dot no)
4    *  Webpage: http://coras.sourceforge.net/
5    *
6    *  This program is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public License
8    *  as published by the Free Software Foundation; either version 2.1
9    *  of the License, or (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this program; if not, write to the Free
18   *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19   *  02111-1307 USA
20   */
21  package coras.client.ui;
22  
23  import java.awt.Frame;
24  
25  import javax.swing.JDialog;
26  
27  /***
28   * @author fvr
29   *
30   * To change the template for this generated type comment go to
31   * Window - Preferences - Java - Code Generation - Code and Comments
32   */
33  public class SaveVersionDialog extends JDialog {
34  	
35  	public static final int CANCEL = 0;
36  	public static final int SAVE = 1;
37  	public static final int DISCARD = 2;
38  	
39  	private javax.swing.JPanel jContentPane = null;
40  
41  	private javax.swing.JPanel buttonPanel = null;  //
42  	private javax.swing.JButton saveButton = null;  //
43  	private javax.swing.JButton discardButton = null;  //
44  	private javax.swing.JLabel jLabel = null;
45  	private javax.swing.JScrollPane jScrollPane = null;
46  	private javax.swing.JTextArea commentArea = null;  //
47  
48  	protected int result = CANCEL;
49  	
50  	private javax.swing.JButton cancelButton = null;  //
51  	private javax.swing.JLabel promptLabel = null;  //
52  	/***
53  	 * This is the default constructor
54  	 */
55  	public SaveVersionDialog() {
56  		this(null);
57  	}
58  	
59  	public SaveVersionDialog(Frame owner) {
60  		super(owner);
61  		initialize();
62  		if (owner != null) {
63  		    setLocationRelativeTo(owner);
64  		}
65  	}
66  	
67   	public int getResult() {
68  		return result;
69  	}
70  	
71  	public String getComment() {
72  		return commentArea.getText();
73  	}
74  	
75  	public String getPrompt() {
76  	    return promptLabel.getText();
77  	}
78  	
79  	public void setPrompt(String prompt) {
80  	    promptLabel.setText(prompt);
81  	    repaint();
82  	}
83  	
84  	public boolean isDiscardEnabled() {
85  	    return getDiscardButton().isVisible();
86  	}
87  	
88  	public void setDiscardEnabled(boolean enabled) {
89  	    getDiscardButton().setVisible(enabled);
90  	}
91  	
92  	/***
93  	 * This method initializes this
94  	 * 
95  	 * @return void
96  	 */
97  	private void initialize() {
98  		this.setSize(300,200);
99  		this.setContentPane(getJContentPane());
100 		this.setModal(true);
101 		this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
102 		this.setTitle("Save new version");
103 	}
104 	/***
105 	 * This method initializes jContentPane
106 	 * 
107 	 * @return javax.swing.JPanel
108 	 */
109 	private javax.swing.JPanel getJContentPane() {
110 		if(jContentPane == null) {
111 			jContentPane = new javax.swing.JPanel();
112 			java.awt.GridBagConstraints consGridBagConstraints2 = new java.awt.GridBagConstraints();
113 			java.awt.GridBagConstraints consGridBagConstraints3 = new java.awt.GridBagConstraints();
114 			java.awt.GridBagConstraints consGridBagConstraints4 = new java.awt.GridBagConstraints();
115 			java.awt.GridBagConstraints consGridBagConstraints1 = new java.awt.GridBagConstraints();
116 			consGridBagConstraints4.gridx = 0;
117 			consGridBagConstraints4.gridy = 0;
118 			consGridBagConstraints4.insets = new java.awt.Insets(20,0,20,0);
119 			consGridBagConstraints2.gridx = 0;
120 			consGridBagConstraints2.gridy = 1;
121 			consGridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
122 			consGridBagConstraints3.gridx = 0;
123 			consGridBagConstraints3.gridy = 2;
124 			consGridBagConstraints3.weightx = 1.0;
125 			consGridBagConstraints3.weighty = 1.0;
126 			consGridBagConstraints3.fill = java.awt.GridBagConstraints.BOTH;
127 			consGridBagConstraints1.gridx = 0;
128 			consGridBagConstraints1.gridy = 3;
129 			jContentPane.setLayout(new java.awt.GridBagLayout());
130 			jContentPane.add(getButtonPanel(), consGridBagConstraints1);
131 			jContentPane.add(getJLabel(), consGridBagConstraints2);
132 			jContentPane.add(getJScrollPane(), consGridBagConstraints3);
133 			jContentPane.add(getPromptLabel(), consGridBagConstraints4);
134 		}
135 		return jContentPane;
136 	}
137 	/***
138 	 * This method initializes jPanel	
139 	 * 	
140 	 * @return javax.swing.JPanel	
141 	 */    
142 	private javax.swing.JPanel getButtonPanel() {
143 		if (buttonPanel == null) {
144 			buttonPanel = new javax.swing.JPanel();
145 			buttonPanel.add(getSaveButton(), null);
146 			buttonPanel.add(getDiscardButton(), null);
147 			buttonPanel.add(getCancelButton(), null);
148 		}
149 		return buttonPanel;
150 	}
151 	/***
152 	 * This method initializes jButton	
153 	 * 	
154 	 * @return javax.swing.JButton	
155 	 */    
156 	private javax.swing.JButton getSaveButton() {
157 		if (saveButton == null) {
158 			saveButton = new javax.swing.JButton();
159 			saveButton.setText("Save");
160 			saveButton.setMnemonic(java.awt.event.KeyEvent.VK_S);
161 			saveButton.addActionListener(new java.awt.event.ActionListener() { 
162 				public void actionPerformed(java.awt.event.ActionEvent e) {    
163 					result = SAVE;
164 					dispose();
165 				}
166 			});
167 		}
168 		return saveButton;
169 	}
170 	/***
171 	 * This method initializes jButton1	
172 	 * 	
173 	 * @return javax.swing.JButton	
174 	 */    
175 	private javax.swing.JButton getDiscardButton() {
176 		if (discardButton == null) {
177 			discardButton = new javax.swing.JButton();
178 			discardButton.setText("Discard");
179 			discardButton.setMnemonic(java.awt.event.KeyEvent.VK_D);
180 			discardButton.addActionListener(new java.awt.event.ActionListener() { 
181 				public void actionPerformed(java.awt.event.ActionEvent e) {
182 					result = DISCARD;
183 					dispose();
184 				}
185 			});
186 		}
187 		return discardButton;
188 	}
189 	/***
190 	 * This method initializes jLabel	
191 	 * 	
192 	 * @return javax.swing.JLabel	
193 	 */    
194 	private javax.swing.JLabel getJLabel() {
195 		if (jLabel == null) {
196 			jLabel = new javax.swing.JLabel();
197 			jLabel.setText("Version comment:");
198 		}
199 		return jLabel;
200 	}
201 	/***
202 	 * This method initializes jScrollPane	
203 	 * 	
204 	 * @return javax.swing.JScrollPane	
205 	 */    
206 	private javax.swing.JScrollPane getJScrollPane() {
207 		if (jScrollPane == null) {
208 			jScrollPane = new javax.swing.JScrollPane();
209 			jScrollPane.setViewportView(getCommentArea());
210 			jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
211 		}
212 		return jScrollPane;
213 	}
214 	/***
215 	 * This method initializes jTextArea	
216 	 * 	
217 	 * @return javax.swing.JTextArea	
218 	 */    
219 	private javax.swing.JTextArea getCommentArea() {
220 		if (commentArea == null) {
221 			commentArea = new javax.swing.JTextArea();
222 			commentArea.setWrapStyleWord(true);
223 			commentArea.setLineWrap(true);
224 		}
225 		return commentArea;
226 	}
227 	/***
228 	 * This method initializes jButton	
229 	 * 	
230 	 * @return javax.swing.JButton	
231 	 */    
232 	private javax.swing.JButton getCancelButton() {
233 		if (cancelButton == null) {
234 			cancelButton = new javax.swing.JButton();
235 			cancelButton.setText("Cancel");
236 			cancelButton.addActionListener(new java.awt.event.ActionListener() { 
237 				public void actionPerformed(java.awt.event.ActionEvent e) {
238 					result = CANCEL;
239 					dispose();
240 				}
241 			});
242 		}
243 		return cancelButton;
244 	}
245 	/***
246 	 * This method initializes jLabel1	
247 	 * 	
248 	 * @return javax.swing.JLabel	
249 	 */    
250 	private javax.swing.JLabel getPromptLabel() {
251 		if (promptLabel == null) {
252 			promptLabel = new javax.swing.JLabel();
253 			promptLabel.setText("Save changes?");
254 		}
255 		return promptLabel;
256 	}
257 
258     /***
259      * @param name
260      */
261     public void setAssetName(String name) {
262         setTitle("Save " + name);
263         promptLabel.setText("Save " + name + "?");
264         promptLabel.invalidate();
265         validate();
266     }
267 }