View Javadoc
1   /**
2    * Metaphase Editor - WYSIWYG HTML Editor Component
3    * Copyright (C) 2010  Rudolf Visagie
4    * Full text of license can be found in com/metaphaseeditor/LICENSE.txt
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * This library 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 library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   * The author can be contacted at metaphase.editor@gmail.com.
21   */
22  
23  package com.metaphaseeditor;
24  
25  import org.openflexo.icon.ImageIconResource;
26  import org.openflexo.rm.ResourceLocator;
27  
28  /**
29   * 
30   * @author Rudolf Visagie
31   */
32  public class DivDialog extends javax.swing.JDialog {
33  
34  	private String divHtml = null;
35  
36  	/** Creates new form DivDialog */
37  	public DivDialog(java.awt.Frame parent, boolean modal) {
38  		super(parent, modal);
39  		initComponents();
40  		setIconImage(new ImageIconResource(ResourceLocator.locateResource("Icons/MetaphaseEditor/icons/metaphase16x16.png")).getImage());
41  
42  		setLocationRelativeTo(null);
43  
44  		languageDirectionComboBox.removeAllItems();
45  		LanguageDirection[] languageDirections = LanguageDirection.values();
46  		for (int i = 0; i < languageDirections.length; i++) {
47  			languageDirectionComboBox.addItem(languageDirections[i]);
48  		}
49  	}
50  
51  	public String showDialog() {
52  		setVisible(true);
53  		return divHtml;
54  	}
55  
56  	/**
57  	 * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this
58  	 * method is always regenerated by the Form Editor.
59  	 */
60  	@SuppressWarnings("unchecked")
61  	// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
62  	private void initComponents() {
63  
64  		mainTabbedPane = new javax.swing.JTabbedPane();
65  		generalPanel = new javax.swing.JPanel();
66  		stylesheetClassesLabel = new javax.swing.JLabel();
67  		stylesheetClassesTextField = new javax.swing.JTextField();
68  		advancedPanel = new javax.swing.JPanel();
69  		idLabel = new javax.swing.JLabel();
70  		idTextField = new javax.swing.JTextField();
71  		languageCodeLabel = new javax.swing.JLabel();
72  		styleLabel = new javax.swing.JLabel();
73  		languageCodeTextField = new javax.swing.JTextField();
74  		styleTextField = new javax.swing.JTextField();
75  		advisoryTitleLabel = new javax.swing.JLabel();
76  		advisoryTitleTextField = new javax.swing.JTextField();
77  		languageDirectionLabel = new javax.swing.JLabel();
78  		languageDirectionComboBox = new javax.swing.JComboBox<>();
79  		okButton = new javax.swing.JButton();
80  		cancelButton = new javax.swing.JButton();
81  
82  		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
83  		setTitle("Create Div");
84  
85  		stylesheetClassesLabel.setText("Stylesheet Classes");
86  
87  		javax.swing.GroupLayout generalPanelLayout = new javax.swing.GroupLayout(generalPanel);
88  		generalPanel.setLayout(generalPanelLayout);
89  		generalPanelLayout.setHorizontalGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
90  				.addGroup(generalPanelLayout.createSequentialGroup().addContainerGap().addComponent(stylesheetClassesLabel)
91  						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
92  						.addComponent(stylesheetClassesTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
93  						.addContainerGap()));
94  		generalPanelLayout.setVerticalGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
95  				.addGroup(generalPanelLayout.createSequentialGroup().addContainerGap()
96  						.addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
97  								.addComponent(stylesheetClassesLabel).addComponent(stylesheetClassesTextField,
98  										javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
99  										javax.swing.GroupLayout.PREFERRED_SIZE))
100 						.addContainerGap(126, Short.MAX_VALUE)));
101 
102 		mainTabbedPane.addTab("General", generalPanel);
103 
104 		idLabel.setText("ID");
105 
106 		languageCodeLabel.setText("Language Code");
107 
108 		styleLabel.setText("Style");
109 
110 		advisoryTitleLabel.setText("Advisory Title");
111 
112 		languageDirectionLabel.setText("Language Direction");
113 
114 		languageDirectionComboBox
115 				.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "None", "Left to Right", "Right to Left" }));
116 
117 		javax.swing.GroupLayout advancedPanelLayout = new javax.swing.GroupLayout(advancedPanel);
118 		advancedPanel.setLayout(advancedPanelLayout);
119 		advancedPanelLayout.setHorizontalGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
120 				.addGroup(advancedPanelLayout.createSequentialGroup().addContainerGap()
121 						.addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
122 								.addGroup(advancedPanelLayout.createSequentialGroup().addComponent(languageDirectionLabel)
123 										.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(
124 												languageDirectionComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 85,
125 												javax.swing.GroupLayout.PREFERRED_SIZE))
126 								.addGroup(advancedPanelLayout.createSequentialGroup().addGroup(advancedPanelLayout
127 										.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(styleLabel)
128 										.addComponent(advisoryTitleLabel).addComponent(idLabel).addComponent(languageCodeLabel))
129 										.addGap(27, 27, 27)
130 										.addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
131 												.addComponent(languageCodeTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 273,
132 														Short.MAX_VALUE)
133 												.addComponent(idTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE)
134 												.addComponent(styleTextField, javax.swing.GroupLayout.Alignment.TRAILING,
135 														javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE)
136 												.addComponent(advisoryTitleTextField, javax.swing.GroupLayout.Alignment.TRAILING,
137 														javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE))))
138 						.addContainerGap()));
139 		advancedPanelLayout.setVerticalGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
140 				.addGroup(advancedPanelLayout.createSequentialGroup().addContainerGap()
141 						.addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(idLabel)
142 								.addComponent(idTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
143 										javax.swing.GroupLayout.PREFERRED_SIZE))
144 						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
145 						.addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
146 								.addComponent(styleLabel).addComponent(styleTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
147 										javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
148 						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
149 						.addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
150 								.addComponent(advisoryTitleTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
151 										javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
152 								.addComponent(advisoryTitleLabel))
153 						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
154 						.addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
155 								.addComponent(languageCodeTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
156 										javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
157 								.addComponent(languageCodeLabel))
158 						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
159 						.addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
160 								.addComponent(languageDirectionComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
161 										javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
162 								.addComponent(languageDirectionLabel))
163 						.addContainerGap(22, Short.MAX_VALUE)));
164 
165 		mainTabbedPane.addTab("Advanced", advancedPanel);
166 
167 		okButton.setText("OK");
168 		okButton.addActionListener(new java.awt.event.ActionListener() {
169 			@Override
170 			public void actionPerformed(java.awt.event.ActionEvent evt) {
171 				okButtonActionPerformed(evt);
172 			}
173 		});
174 
175 		cancelButton.setText("Cancel");
176 		cancelButton.addActionListener(new java.awt.event.ActionListener() {
177 			@Override
178 			public void actionPerformed(java.awt.event.ActionEvent evt) {
179 				cancelButtonActionPerformed(evt);
180 			}
181 		});
182 
183 		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
184 		getContentPane().setLayout(layout);
185 		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
186 				.addComponent(mainTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
187 				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
188 						layout.createSequentialGroup().addContainerGap(254, Short.MAX_VALUE).addComponent(okButton)
189 								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton)
190 								.addContainerGap()));
191 
192 		layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { cancelButton, okButton });
193 
194 		layout.setVerticalGroup(
195 				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
196 						.addGroup(
197 								layout.createSequentialGroup()
198 										.addComponent(mainTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE,
199 												javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
200 										.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
201 										.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
202 												.addComponent(cancelButton).addComponent(okButton))
203 										.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
204 
205 		pack();
206 	}// </editor-fold>//GEN-END:initComponents
207 
208 	private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_okButtonActionPerformed
209 		String id = idTextField.getText();
210 		String stylesheetClasses = stylesheetClassesTextField.getText();
211 		String style = styleTextField.getText();
212 		String advisoryTitle = advisoryTitleTextField.getText();
213 		String languageCode = languageCodeTextField.getText();
214 		LanguageDirection languageDirection = (LanguageDirection) languageDirectionComboBox.getSelectedItem();
215 		StringBuffer buffer = new StringBuffer();
216 		buffer.append("<div");
217 		if (id.length() > 0) {
218 			buffer.append(" id='");
219 			buffer.append(id);
220 			buffer.append("'");
221 		}
222 		if (stylesheetClasses.length() > 0) {
223 			buffer.append(" class='");
224 			buffer.append(stylesheetClasses);
225 			buffer.append("'");
226 		}
227 		if (style.length() > 0) {
228 			buffer.append(" style='");
229 			buffer.append(style);
230 			buffer.append("'");
231 		}
232 		if (advisoryTitle.length() > 0) {
233 			buffer.append(" title='");
234 			buffer.append(advisoryTitle);
235 			buffer.append("'");
236 		}
237 		if (languageCode.length() > 0) {
238 			buffer.append(" lang='");
239 			buffer.append(languageCode);
240 			buffer.append("'");
241 		}
242 		if (languageDirection.getAttrValue() != null) {
243 			buffer.append(" dir='");
244 			buffer.append(languageDirection.getAttrValue());
245 			buffer.append("'");
246 		}
247 		buffer.append(">TODO: modify div contents</div>");
248 		divHtml = buffer.toString();
249 		setVisible(false);
250 	}// GEN-LAST:event_okButtonActionPerformed
251 
252 	private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_cancelButtonActionPerformed
253 		setVisible(false);
254 	}// GEN-LAST:event_cancelButtonActionPerformed
255 
256 	// Variables declaration - do not modify//GEN-BEGIN:variables
257 	private javax.swing.JPanel advancedPanel;
258 	private javax.swing.JLabel advisoryTitleLabel;
259 	private javax.swing.JTextField advisoryTitleTextField;
260 	private javax.swing.JButton cancelButton;
261 	private javax.swing.JPanel generalPanel;
262 	private javax.swing.JLabel idLabel;
263 	private javax.swing.JTextField idTextField;
264 	private javax.swing.JLabel languageCodeLabel;
265 	private javax.swing.JTextField languageCodeTextField;
266 	private javax.swing.JComboBox languageDirectionComboBox;
267 	private javax.swing.JLabel languageDirectionLabel;
268 	private javax.swing.JTabbedPane mainTabbedPane;
269 	private javax.swing.JButton okButton;
270 	private javax.swing.JLabel styleLabel;
271 	private javax.swing.JTextField styleTextField;
272 	private javax.swing.JLabel stylesheetClassesLabel;
273 	private javax.swing.JTextField stylesheetClassesTextField;
274 	// End of variables declaration//GEN-END:variables
275 
276 }