View Javadoc

1   /*
2    * $Id$
3    *
4    * The contents of this file are subject to the Mozilla Public License 
5    * Version 1.1 (the "License"); you may not use this file except in 
6    * compliance with the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/ 
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis, 
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
11   * for the specific language governing rights and limitations under the License.
12   *
13   * The Original Code is XML Hammer code. (org.xmlhammer.*)
14   *
15   * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
16   * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
17   * All Rights Reserved.
18   *
19   * Contributor(s): Edwin Dankert <edankert@gmail.com>
20   */
21  
22  
23  package org.xmlhammer.gui.preferences;
24  
25  import javax.swing.Box;
26  import javax.swing.ImageIcon;
27  import javax.swing.JLabel;
28  import javax.swing.JPanel;
29  import javax.swing.JTextField;
30  import javax.swing.JTextPane;
31  import javax.swing.border.EmptyBorder;
32  
33  import org.bounce.FormLayout;
34  import org.bounce.image.ImageLoader;
35  import org.xmlhammer.model.preferences.ExternalApplication;
36  
37  /***
38   * Put comment...
39   * 
40   * @version $Revision$, $Date$
41   * @author Edwin Dankert <edankert@gmail.com>
42   */
43  
44  public class ExternalApplicationPreferencesPanel extends PreferencesPanel {
45      private static final long serialVersionUID = -4140066420809363167L;
46      private static final ImageIcon EDITOR_ICON = ImageLoader.get().getImage("/org/xmlhammer/gui/icons/obj16/write_obj.gif");
47      private static final ImageIcon OPEN_ICON = ImageLoader.get().getImage("/org/xmlhammer/gui/icons/obj16/file_obj.gif");
48  
49      private JTextField browserExtensionsField = null;
50      private JTextField editorCommandField = null;
51      private JTextField defaultCommandField = null;
52  	
53  	/***
54  	 * @param name
55  	 */
56  	public ExternalApplicationPreferencesPanel() {
57  		this(false);
58  	}
59  
60  	/***
61  	 * @param name
62  	 */
63  	public ExternalApplicationPreferencesPanel(boolean project) {
64  		super("External Applications", "preferences.external", project);
65  
66          JPanel preferences = new JPanel( new FormLayout( 5, 2));
67          
68          browserExtensionsField = new JTextField();
69          
70          preferences.add(new JLabel("Browser Extensions:"), FormLayout.LEFT);
71          preferences.add(browserExtensionsField, FormLayout.RIGHT_FILL);
72  
73          preferences.add(Box.createVerticalStrut(10), FormLayout.FULL);
74  
75          JTextPane label = new JTextPane();
76          label.setBorder(new EmptyBorder(5,40,5,20));
77          label.setText("The following patterns will be replaced when evaluating a command:\n" +
78                        "${file} - replaced with the current selected file\n" +
79                        "${line} - replaced with the line for an error\n" +
80                        "${column} - replaced with the column for an error");
81          label.setEditable(false);
82          label.setBackground(this.getBackground());
83  
84  //        preferences.add(new JLabel(), FormLayout.LEFT);
85          preferences.add(label, FormLayout.FULL);
86  
87          preferences.add(Box.createVerticalStrut(10), FormLayout.FULL);
88  
89          editorCommandField = new JTextField();
90  
91          JLabel editorLabel = new JLabel( "Editor Command:");
92          editorLabel.setIcon(EDITOR_ICON);
93  //        editorLabel.setHorizontalTextPosition(JLabel.LEFT);
94          preferences.add(editorLabel, FormLayout.LEFT);
95          preferences.add(editorCommandField, FormLayout.RIGHT_FILL);
96  
97          defaultCommandField = new JTextField();
98  
99          JLabel openLabel = new JLabel( "Open Command:");
100         openLabel.setIcon(OPEN_ICON);
101 //        openLabel.setHorizontalTextPosition(JLabel.LEFT);
102         preferences.add(openLabel, FormLayout.LEFT);
103         preferences.add(defaultCommandField, FormLayout.RIGHT_FILL);
104 
105         setCenterPane(preferences);
106     }
107 	
108 	public void setExternalApplication(ExternalApplication external) {
109 		browserExtensionsField.setText(external.getBrowserExtensions() == null ? "" : external.getBrowserExtensions());
110         defaultCommandField.setText(external.getDefaultCommand() == null ? "" : external.getDefaultCommand());
111         editorCommandField.setText(external.getEditorCommand() == null ? "" : external.getEditorCommand());
112 	}
113 	
114 	public ExternalApplication getExternalApplication() {
115         ExternalApplication external = new ExternalApplication();
116 		external.setBrowserExtensions(browserExtensionsField.getText());
117         external.setDefaultCommand(defaultCommandField.getText());
118         external.setEditorCommand(editorCommandField.getText());
119 		
120 		return external;
121 	}
122 	
123 	public void setEnabled( boolean enabled) {
124 	}
125 }