KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > css > visual > ui > FontFamilyEditorDialog


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * FontFamilyEditorDialog.java
22  *
23  * Created on October 18, 2004, 3:47 PM
24  */

25
26 package org.netbeans.modules.css.visual.ui;
27
28 import org.netbeans.modules.css.visual.model.FontModel;
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.awt.event.ActionListener JavaDoc;
31 import java.util.StringTokenizer JavaDoc;
32 import javax.swing.DefaultListModel JavaDoc;
33 import javax.swing.JButton JavaDoc;
34 import javax.swing.JDialog JavaDoc;
35 import org.openide.DialogDescriptor;
36 import org.openide.DialogDisplayer;
37 import org.openide.util.NbBundle;
38
39 /**
40  * Font Family Editor Dialog
41  * @author Winston Prakash
42  * @version 1.0
43  */

44 public class FontFamilyEditorDialog extends javax.swing.JPanel JavaDoc {
45     private JDialog JavaDoc dialog;
46     private DialogDescriptor dlg = null;
47     private String JavaDoc okString = NbBundle.getMessage(FontFamilyEditorDialog.class, "OK");
48     private String JavaDoc cancelString = NbBundle.getMessage(FontFamilyEditorDialog.class, "CANCEL");
49
50     private JButton JavaDoc okButton = new JButton JavaDoc(okString);
51     private JButton JavaDoc cancelButton = new JButton JavaDoc(cancelString);
52
53     DefaultListModel JavaDoc fontFamilies = null;
54     DefaultListModel JavaDoc selectedFonts = new DefaultListModel JavaDoc();
55     DefaultListModel JavaDoc availableFonts = new DefaultListModel JavaDoc();
56
57     FontModel fontModel = new FontModel();
58
59     int currentIndex = 1;
60
61     /** Creates new form TestPanel */
62     public FontFamilyEditorDialog(DefaultListModel JavaDoc fontFamilies, int currIndex) {
63         initComponents();
64         currentIndex = currIndex;
65         this.fontFamilies = fontFamilies;
66         fontFaceList.setModel(fontFamilies);
67         fontFaceList.setSelectedIndex(currentIndex);
68         fontSelectionCombo.setModel(fontModel.getFontSelectionList());
69         fontSelectionCombo.setSelectedIndex(0);
70         availableFonts = fontModel.getFontList();
71         availableFontList.setModel(availableFonts);
72         selectedFontList.setModel(selectedFonts);
73         availableFontList.setSelectedIndex(0);
74     }
75
76     public void showDialog(){
77         // Add a listener to the dialog's buttons
78
ActionListener JavaDoc listener = new ActionListener JavaDoc() {
79             public void actionPerformed(ActionEvent JavaDoc evt) {
80                 Object JavaDoc o = evt.getSource();
81                 Object JavaDoc[] option = dlg.getOptions();
82
83                 if (o == option[0]) {
84                     // Set the selected Font Familt
85
//dialog.hide();
86
// Dismiss the dialog
87
dialog.setVisible(false);
88                 }
89             }
90         };
91         dlg = new DialogDescriptor(this, NbBundle.getMessage(FontFamilyEditorDialog.class, "FONT_FAMILY_EDITOR_TITLE"), true, listener);
92         dlg.setOptions(new Object JavaDoc[] { okButton, cancelButton });
93         dlg.setClosingOptions(new Object JavaDoc[] {cancelButton});
94         //dlg.setHelpCtx(new HelpCtx("projrave_ui_elements_server_nav_add_datasourcedb")); // NOI18N
95

96         dialog = (JDialog JavaDoc) DialogDisplayer.getDefault().createDialog(dlg);
97         dialog.setResizable(true);
98         dialog.pack();
99         dialog.setVisible(true);
100     }
101
102     public int getSelectedIndex(){
103         return currentIndex;
104     }
105
106     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
107
private void initComponents() {
108         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
109
110         currentFontFamilyPanel = new javax.swing.JPanel JavaDoc();
111         fontFamilyScroll = new javax.swing.JScrollPane JavaDoc();
112         fontFaceList = new javax.swing.JList JavaDoc();
113         newDeleteButtonPanel = new javax.swing.JPanel JavaDoc();
114         newButton = new javax.swing.JButton JavaDoc();
115         deleteButton = new javax.swing.JButton JavaDoc();
116         currentFontFamiliesLabel = new javax.swing.JLabel JavaDoc();
117         fontFamilyEditor = new javax.swing.JPanel JavaDoc();
118         availableFontScroll = new javax.swing.JScrollPane JavaDoc();
119         availableFontList = new javax.swing.JList JavaDoc();
120         selectedFontScroll = new javax.swing.JScrollPane JavaDoc();
121         selectedFontList = new javax.swing.JList JavaDoc();
122         availableLabel = new javax.swing.JLabel JavaDoc();
123         selectedLabel = new javax.swing.JLabel JavaDoc();
124         addRemoveButtonPanel = new javax.swing.JPanel JavaDoc();
125         addButton = new javax.swing.JButton JavaDoc();
126         removeButton = new javax.swing.JButton JavaDoc();
127         upDownPanel = new javax.swing.JPanel JavaDoc();
128         upButton = new javax.swing.JButton JavaDoc();
129         downButton = new javax.swing.JButton JavaDoc();
130         fontSelectionCombo = new javax.swing.JComboBox JavaDoc();
131
132         setLayout(new java.awt.BorderLayout JavaDoc(5, 5));
133
134         setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
135         currentFontFamilyPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
136
137         fontFaceList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
138         fontFaceList.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
139             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
140                 fontFaceListValueChanged(evt);
141             }
142         });
143
144         fontFamilyScroll.setViewportView(fontFaceList);
145         fontFaceList.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "CURRENT_FONTS"));
146         fontFaceList.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("FONT_FAMILY_LIST_ACCESS_DESC"));
147
148         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
149         gridBagConstraints.gridx = 0;
150         gridBagConstraints.gridy = 1;
151         gridBagConstraints.gridwidth = 3;
152         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
153         gridBagConstraints.weightx = 1.0;
154         gridBagConstraints.weighty = 1.0;
155         currentFontFamilyPanel.add(fontFamilyScroll, gridBagConstraints);
156
157         newDeleteButtonPanel.setLayout(new java.awt.GridLayout JavaDoc(0, 1, 0, 5));
158
159         newButton.setMnemonic(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "FONT_FAMILY_NEW_BUTTON_MNEMONIC").charAt(0));
160         newButton.setText(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "NEW"));
161         newButton.setMargin(new java.awt.Insets JavaDoc(2, 10, 2, 10));
162         newButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
163             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
164                 newButtonActionPerformed(evt);
165             }
166         });
167
168         newDeleteButtonPanel.add(newButton);
169         newButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("ADD_FONT_FAMILY_ACCESS_DESC"));
170
171         deleteButton.setMnemonic(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "FONT_FAMILY_DELETE_BUTTON_MNEMONIC").charAt(0));
172         deleteButton.setText(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "DELETE"));
173         deleteButton.setMargin(new java.awt.Insets JavaDoc(2, 10, 2, 10));
174         deleteButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
175             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
176                 deleteButtonActionPerformed(evt);
177             }
178         });
179
180         newDeleteButtonPanel.add(deleteButton);
181         deleteButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("DELETE_FONT_FAMILY_ACCESS_DESC"));
182
183         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
184         gridBagConstraints.gridx = 3;
185         gridBagConstraints.gridy = 1;
186         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
187         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
188         currentFontFamilyPanel.add(newDeleteButtonPanel, gridBagConstraints);
189
190         currentFontFamiliesLabel.setLabelFor(fontFaceList);
191         currentFontFamiliesLabel.setText(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "CURRENT_FONTS"));
192         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
193         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
194         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
195         currentFontFamilyPanel.add(currentFontFamiliesLabel, gridBagConstraints);
196
197         add(currentFontFamilyPanel, java.awt.BorderLayout.CENTER);
198
199         fontFamilyEditor.setLayout(new java.awt.GridBagLayout JavaDoc());
200
201         availableFontScroll.setPreferredSize(new java.awt.Dimension JavaDoc(200, 138));
202         availableFontList.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
203             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
204                 availableFontListValueChanged(evt);
205             }
206         });
207
208         availableFontScroll.setViewportView(availableFontList);
209         availableFontList.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("AVAILABLE_FONT_LIST_ACCESS_NAME"));
210         availableFontList.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("AVAILABLE_FONT_LIST_ACCESS_DESC"));
211
212         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
213         gridBagConstraints.gridx = 0;
214         gridBagConstraints.gridy = 3;
215         gridBagConstraints.gridwidth = 2;
216         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
217         gridBagConstraints.weighty = 1.0;
218         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 10);
219         fontFamilyEditor.add(availableFontScroll, gridBagConstraints);
220
221         selectedFontScroll.setPreferredSize(new java.awt.Dimension JavaDoc(200, 130));
222         selectedFontList.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
223             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
224                 selectedFontListValueChanged(evt);
225             }
226         });
227
228         selectedFontScroll.setViewportView(selectedFontList);
229         selectedFontList.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "SELECTED"));
230         selectedFontList.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("SELECTED_FONT_LIST_ACCESS_DESC"));
231
232         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
233         gridBagConstraints.gridx = 3;
234         gridBagConstraints.gridy = 3;
235         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
236         gridBagConstraints.weightx = 1.0;
237         gridBagConstraints.weighty = 1.0;
238         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
239         fontFamilyEditor.add(selectedFontScroll, gridBagConstraints);
240
241         availableLabel.setLabelFor(fontSelectionCombo);
242         availableLabel.setText(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "AVAILABLE"));
243         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
244         gridBagConstraints.gridx = 0;
245         gridBagConstraints.gridy = 2;
246         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
247         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
248         fontFamilyEditor.add(availableLabel, gridBagConstraints);
249
250         selectedLabel.setLabelFor(selectedFontList);
251         selectedLabel.setText(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "SELECTED"));
252         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
253         gridBagConstraints.gridx = 3;
254         gridBagConstraints.gridy = 2;
255         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
256         gridBagConstraints.weightx = 1.0;
257         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
258         fontFamilyEditor.add(selectedLabel, gridBagConstraints);
259         selectedLabel.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("SELECTED_FONT_LIST_ACCESS_DESC"));
260
261         addRemoveButtonPanel.setLayout(new java.awt.GridLayout JavaDoc(2, 1, 0, 5));
262
263         addButton.setText(">");
264         addButton.setToolTipText(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "Add_selected_fonts"));
265         addButton.setMargin(new java.awt.Insets JavaDoc(2, 10, 2, 10));
266         addButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
267             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
268                 addButtonActionPerformed(evt);
269             }
270         });
271
272         addRemoveButtonPanel.add(addButton);
273         addButton.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("ADD_FONT_ACCESS_NAME"));
274
275         removeButton.setText("<");
276         removeButton.setToolTipText(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "Remove_selected_fonts"));
277         removeButton.setMargin(new java.awt.Insets JavaDoc(2, 10, 2, 10));
278         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
279             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
280                 removeButtonActionPerformed(evt);
281             }
282         });
283
284         addRemoveButtonPanel.add(removeButton);
285         removeButton.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("REMOVE_FONT_ACCESS_NAME"));
286
287         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
288         gridBagConstraints.gridx = 2;
289         gridBagConstraints.gridy = 3;
290         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
291         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
292         fontFamilyEditor.add(addRemoveButtonPanel, gridBagConstraints);
293
294         upDownPanel.setLayout(new java.awt.GridLayout JavaDoc(0, 1, 0, 5));
295
296         upButton.setMnemonic(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "FONT_FAMILY_UP_BUTTON_MNEMONIC").charAt(0));
297         upButton.setText(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "UP"));
298         upButton.setMargin(new java.awt.Insets JavaDoc(2, 10, 2, 10));
299         upButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
300             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
301                 upButtonActionPerformed(evt);
302             }
303         });
304
305         upDownPanel.add(upButton);
306         upButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("MOVE_FONT_UP_ACCESS_NAME"));
307
308         downButton.setMnemonic(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "FONT_FAMILY_DOWN_BUTTON_MNEMONIC").charAt(0));
309         downButton.setText(org.openide.util.NbBundle.getMessage(FontFamilyEditorDialog.class, "DOWN"));
310         downButton.setMargin(new java.awt.Insets JavaDoc(2, 10, 2, 10));
311         downButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
312             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
313                 downButtonActionPerformed(evt);
314             }
315         });
316
317         upDownPanel.add(downButton);
318         downButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("MOVE_FONT_DOWN_ACCESS_NAME"));
319
320         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
321         gridBagConstraints.gridx = 4;
322         gridBagConstraints.gridy = 3;
323         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
324         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
325         fontFamilyEditor.add(upDownPanel, gridBagConstraints);
326
327         fontSelectionCombo.addItemListener(new java.awt.event.ItemListener JavaDoc() {
328             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
329                 fontSelectionComboItemStateChanged(evt);
330             }
331         });
332
333         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
334         gridBagConstraints.gridx = 1;
335         gridBagConstraints.gridy = 2;
336         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
337         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 0, 10);
338         fontFamilyEditor.add(fontSelectionCombo, gridBagConstraints);
339         fontSelectionCombo.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("AVAILABLE_FONT_COMBO_ACCESS_DESC"));
340
341         add(fontFamilyEditor, java.awt.BorderLayout.SOUTH);
342
343     }// </editor-fold>//GEN-END:initComponents
344

345     private void downButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_downButtonActionPerformed
346
if (selectedFonts.getSize() > 0){
347             int index = selectedFontList.getSelectedIndex();
348             if((index >= 0) && index < selectedFonts.getSize()){
349                 Object JavaDoc currentObject = selectedFonts.get(index);
350                 Object JavaDoc prevObject = selectedFonts.get(index+1);
351                 selectedFonts.setElementAt(currentObject, index+1);
352                 selectedFonts.setElementAt(prevObject, index);
353                 selectedFontList.setSelectedIndex(index+1);
354                 resetFontFamilySet();
355             }
356         }
357     }//GEN-LAST:event_downButtonActionPerformed
358

359     private void upButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_upButtonActionPerformed
360
if (selectedFonts.getSize() > 0){
361             int index = selectedFontList.getSelectedIndex();
362             if(index > 0){
363                 Object JavaDoc currentObject = selectedFonts.get(index);
364                 Object JavaDoc prevObject = selectedFonts.get(index-1);
365                 selectedFonts.setElementAt(currentObject, index-1);
366                 selectedFonts.setElementAt(prevObject, index);
367                 selectedFontList.setSelectedIndex(index-1);
368                 resetFontFamilySet();
369             }
370         }
371     }//GEN-LAST:event_upButtonActionPerformed
372

373     private void deleteButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_deleteButtonActionPerformed
374
int index = fontFaceList.getSelectedIndex();
375         if (index == 0) return;
376         fontFamilies.remove(index);
377         if(!fontFamilies.isEmpty()){
378             if (index == fontFamilies.getSize()) index--;
379             fontFaceList.setSelectedIndex(index);
380         }
381     }//GEN-LAST:event_deleteButtonActionPerformed
382

383     private void newButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_newButtonActionPerformed
384
fontFamilies.insertElementAt(" ", 1);
385         fontFaceList.setSelectedIndex(1);
386     }//GEN-LAST:event_newButtonActionPerformed
387

388     private void selectedFontListValueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_selectedFontListValueChanged
389
if (!evt.getValueIsAdjusting()) {
390             //selectedFont = (String)selectedFontList.getSelectedValue();
391
int index = selectedFontList.getSelectedIndex();
392             if(index == 0) {
393                 upButton.setEnabled(false);
394             }else{
395                 upButton.setEnabled(true);
396             }
397             if(index == selectedFonts.getSize()-1) {
398                 downButton.setEnabled(false);
399             }else{
400                 downButton.setEnabled(true);
401             }
402         }
403     }//GEN-LAST:event_selectedFontListValueChanged
404

405     private void availableFontListValueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_availableFontListValueChanged
406
if (!evt.getValueIsAdjusting()) {
407             //selectedAvailableFont = (String)availableFontList.getSelectedValue();
408
}
409     }//GEN-LAST:event_availableFontListValueChanged
410

411     private void removeButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeButtonActionPerformed
412
Object JavaDoc[] selections = selectedFontList.getSelectedValues();
413         for(int i=0; i< selections.length ;i++){
414             if (selectedFonts.contains(selections[i])){
415                 selectedFonts.removeElement(selections[i]);
416             }
417         }
418         if(!selectedFonts.isEmpty()) {
419             selectedFontList.setSelectedIndex(0);
420         }else{
421             removeButton.setEnabled(false);
422             upButton.setEnabled(false);
423             downButton.setEnabled(false);
424         }
425         resetFontFamilySet();
426     }//GEN-LAST:event_removeButtonActionPerformed
427

428     private void fontFaceListValueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_fontFaceListValueChanged
429
if (!evt.getValueIsAdjusting()) {
430             currentIndex = fontFaceList.getSelectedIndex();
431             selectedFonts.removeAllElements();
432             // Do not show the <NOT SET> in the selected fonts
433
if(currentIndex != 0){
434                 addButton.setEnabled(true);
435                 deleteButton.setEnabled(true);
436                 upButton.setEnabled(true);
437                 downButton.setEnabled(true);
438                 String JavaDoc selectedFontSet = (String JavaDoc)fontFaceList.getSelectedValue();
439                 if((selectedFontSet != null) && !selectedFontSet.trim().equals("")) {
440                     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(selectedFontSet,",");
441                     while(st.hasMoreTokens()){
442                         String JavaDoc fontName = st.nextToken();
443                         if(!fontName.trim().equals("")){
444                             fontName = fontName.replaceAll("'","");
445                             selectedFonts.addElement(fontName);
446                         }
447                     }
448                 }
449                 if (!selectedFonts.isEmpty()) {
450                     removeButton.setEnabled(true);
451                     selectedFontList.setSelectedIndex(0);
452                 }
453             }else{
454                 addButton.setEnabled(false);
455                 removeButton.setEnabled(false);
456                 deleteButton.setEnabled(false);
457                 upButton.setEnabled(false);
458                 downButton.setEnabled(false);
459             }
460         }
461     }//GEN-LAST:event_fontFaceListValueChanged
462

463     private void addButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addButtonActionPerformed
464
Object JavaDoc[] selections = availableFontList.getSelectedValues();
465         for(int i=0; i< selections.length ;i++){
466             if (!selectedFonts.contains(selections[i])){
467                 selectedFonts.addElement(selections[i]);
468                 selectedFontList.setSelectedValue(selections[i],true);
469             }
470         }
471         removeButton.setEnabled(true);
472         resetFontFamilySet();
473     }//GEN-LAST:event_addButtonActionPerformed
474

475     private void fontSelectionComboItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_fontSelectionComboItemStateChanged
476
fontSelectionCombo.getSelectedIndex();
477         switch(fontSelectionCombo.getSelectedIndex()){
478             case 0:
479                 availableFonts = fontModel.getFontList();
480                 //availableFontList.setModel(fontModel.getFontList());
481
break;
482             case 1:
483                 availableFonts = fontModel.getFontFamilyList();
484                 //availableFontList.setModel(fontModel.getFontFamilyList());
485
break;
486             case 2:
487                 availableFonts = fontModel.getWebFontList();
488                 //availableFontList.setModel(fontModel.getWebFontList());
489
break;
490         }
491         availableFontList.setModel(availableFonts);
492         availableFontList.setSelectedIndex(0);
493     }//GEN-LAST:event_fontSelectionComboItemStateChanged
494

495     private void resetFontFamilySet() {
496         StringBuffer JavaDoc fontSetBuf = new StringBuffer JavaDoc();
497         for(int i = 0; i < selectedFonts.size(); i++){
498             String JavaDoc fontName = ((String JavaDoc) selectedFonts.get(i)).trim();
499             // If the font name has spaces then quote it as per CSS spec.
500
if (fontName.indexOf(" ") != -1){
501                 fontName = "\'" + fontName + "\'";
502             }
503             fontSetBuf.append(fontName);
504             if(i < selectedFonts.size()-1 )fontSetBuf.append(",");
505         }
506         // Otherwise List does not display the empty line
507
if(fontSetBuf.length() == 0) fontSetBuf.append(" ");
508         fontFamilies.setElementAt(fontSetBuf.toString(), currentIndex);
509     }
510     // Variables declaration - do not modify//GEN-BEGIN:variables
511
private javax.swing.JButton JavaDoc addButton;
512     private javax.swing.JPanel JavaDoc addRemoveButtonPanel;
513     private javax.swing.JList JavaDoc availableFontList;
514     private javax.swing.JScrollPane JavaDoc availableFontScroll;
515     private javax.swing.JLabel JavaDoc availableLabel;
516     private javax.swing.JLabel JavaDoc currentFontFamiliesLabel;
517     private javax.swing.JPanel JavaDoc currentFontFamilyPanel;
518     private javax.swing.JButton JavaDoc deleteButton;
519     private javax.swing.JButton JavaDoc downButton;
520     private javax.swing.JList JavaDoc fontFaceList;
521     private javax.swing.JPanel JavaDoc fontFamilyEditor;
522     private javax.swing.JScrollPane JavaDoc fontFamilyScroll;
523     private javax.swing.JComboBox JavaDoc fontSelectionCombo;
524     private javax.swing.JButton JavaDoc newButton;
525     private javax.swing.JPanel JavaDoc newDeleteButtonPanel;
526     private javax.swing.JButton JavaDoc removeButton;
527     private javax.swing.JList JavaDoc selectedFontList;
528     private javax.swing.JScrollPane JavaDoc selectedFontScroll;
529     private javax.swing.JLabel JavaDoc selectedLabel;
530     private javax.swing.JButton JavaDoc upButton;
531     private javax.swing.JPanel JavaDoc upDownPanel;
532     // End of variables declaration//GEN-END:variables
533

534 }
535
Popular Tags