001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.propertyeditors.css;
042:
043: import org.netbeans.modules.visualweb.propertyeditors.css.model.FontModel;
044: import java.awt.event.ActionEvent;
045: import java.awt.event.ActionListener;
046: import java.util.ArrayList;
047: import java.util.List;
048: import java.util.StringTokenizer;
049: import javax.swing.DefaultListModel;
050: import javax.swing.JButton;
051: import javax.swing.JDialog;
052: import org.openide.DialogDescriptor;
053: import org.openide.DialogDisplayer;
054: import org.openide.util.NbBundle;
055:
056: /**
057: * Font Family Editor Dialog
058: * @author Winston Prakash
059: * Jeff Hoffman (HIE design)
060: */
061: public class FontFamilyEditorDialog extends javax.swing.JPanel {
062: private JDialog dialog;
063: private DialogDescriptor dlg = null;
064: private String okString = NbBundle.getMessage(
065: FontFamilyEditorDialog.class, "OK");
066: private String cancelString = NbBundle.getMessage(
067: FontFamilyEditorDialog.class, "CANCEL");
068:
069: private JButton okButton = new JButton(okString);
070: private JButton cancelButton = new JButton(cancelString);
071:
072: DefaultListModel fontFamilies = null;
073: DefaultListModel selectedFonts = new DefaultListModel();
074: DefaultListModel availableFonts = new DefaultListModel();
075:
076: FontModel fontModel = new FontModel();
077:
078: int currentIndex = 1;
079:
080: //String selectedAvailableFont = null;
081: //String selectedFont = null;
082:
083: /** Creates new form TestPanel */
084: public FontFamilyEditorDialog(DefaultListModel fontFamilies,
085: int currIndex) {
086: initComponents();
087: currentIndex = currIndex;
088: this .fontFamilies = fontFamilies;
089: fontFaceList.setModel(fontFamilies);
090: fontFaceList.setSelectedIndex(currentIndex);
091: fontSelectionCombo.setModel(fontModel.getFontSelectionList());
092: fontSelectionCombo.setSelectedIndex(0);
093: availableFonts = fontModel.getFontList();
094: availableFontList.setModel(availableFonts);
095: selectedFontList.setModel(selectedFonts);
096: availableFontList.setSelectedIndex(0);
097: }
098:
099: public void showDialog() {
100: // Add a listener to the dialog's buttons
101: ActionListener listener = new ActionListener() {
102: public void actionPerformed(ActionEvent evt) {
103: Object o = evt.getSource();
104: Object[] option = dlg.getOptions();
105:
106: if (o == option[0]) {
107: // Set the selected Font Familt
108: dialog.hide();
109: // Dismiss the dialog
110: dialog.hide();
111: }
112: }
113: };
114: dlg = new DialogDescriptor(this , NbBundle.getMessage(
115: FontFamilyEditorDialog.class,
116: "FONT_FAMILY_EDITOR_TITLE"), true, listener);
117: dlg.setOptions(new Object[] { okButton, cancelButton });
118: dlg.setClosingOptions(new Object[] { cancelButton });
119: //dlg.setHelpCtx(new HelpCtx("projrave_ui_elements_server_nav_add_datasourcedb")); // NOI18N
120:
121: dialog = (JDialog) DialogDisplayer.getDefault().createDialog(
122: dlg);
123: dialog.setResizable(true);
124: dialog.pack();
125: dialog.show();
126: }
127:
128: public int getSelectedIndex() {
129: return currentIndex;
130: }
131:
132: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
133: private void initComponents() {
134: java.awt.GridBagConstraints gridBagConstraints;
135:
136: currentFontFamilyPanel = new javax.swing.JPanel();
137: fontFamilyScroll = new javax.swing.JScrollPane();
138: fontFaceList = new javax.swing.JList();
139: newDeleteButtonPanel = new javax.swing.JPanel();
140: newButton = new javax.swing.JButton();
141: deleteButton = new javax.swing.JButton();
142: currentFontFamiliesLabel = new javax.swing.JLabel();
143: fontFamilyEditor = new javax.swing.JPanel();
144: availableFontScroll = new javax.swing.JScrollPane();
145: availableFontList = new javax.swing.JList();
146: selectedFontScroll = new javax.swing.JScrollPane();
147: selectedFontList = new javax.swing.JList();
148: availableLabel = new javax.swing.JLabel();
149: selectedLabel = new javax.swing.JLabel();
150: addRemoveButtonPanel = new javax.swing.JPanel();
151: addButton = new javax.swing.JButton();
152: removeButton = new javax.swing.JButton();
153: upDownPanel = new javax.swing.JPanel();
154: upButton = new javax.swing.JButton();
155: downButton = new javax.swing.JButton();
156: fontSelectionCombo = new javax.swing.JComboBox();
157:
158: setLayout(new java.awt.BorderLayout(5, 5));
159:
160: setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5,
161: 5));
162: currentFontFamilyPanel.setLayout(new java.awt.GridBagLayout());
163:
164: fontFaceList
165: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
166: fontFaceList
167: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
168: public void valueChanged(
169: javax.swing.event.ListSelectionEvent evt) {
170: fontFaceListValueChanged(evt);
171: }
172: });
173:
174: fontFamilyScroll.setViewportView(fontFaceList);
175: fontFaceList
176: .getAccessibleContext()
177: .setAccessibleDescription(
178: java.util.ResourceBundle
179: .getBundle(
180: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
181: .getString(
182: "FONT_FAMILY_LIST_ACCESS_DESC"));
183:
184: gridBagConstraints = new java.awt.GridBagConstraints();
185: gridBagConstraints.gridx = 0;
186: gridBagConstraints.gridy = 1;
187: gridBagConstraints.gridwidth = 3;
188: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
189: gridBagConstraints.weightx = 1.0;
190: gridBagConstraints.weighty = 1.0;
191: currentFontFamilyPanel
192: .add(fontFamilyScroll, gridBagConstraints);
193:
194: newDeleteButtonPanel.setLayout(new java.awt.GridLayout(0, 1, 0,
195: 5));
196:
197: newButton
198: .setMnemonic(java.util.ResourceBundle
199: .getBundle(
200: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
201: .getString("NEW_FONT_BUTTON_MNEMONIC")
202: .charAt(0));
203: newButton.setText(org.openide.util.NbBundle.getMessage(
204: FontFamilyEditorDialog.class, "NEW"));
205: newButton.setMargin(new java.awt.Insets(2, 10, 2, 10));
206: newButton
207: .addActionListener(new java.awt.event.ActionListener() {
208: public void actionPerformed(
209: java.awt.event.ActionEvent evt) {
210: newButtonActionPerformed(evt);
211: }
212: });
213:
214: newDeleteButtonPanel.add(newButton);
215: newButton
216: .getAccessibleContext()
217: .setAccessibleDescription(
218: java.util.ResourceBundle
219: .getBundle(
220: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
221: .getString(
222: "ADD_FONT_FAMILY_ACCESS_DESC"));
223:
224: deleteButton
225: .setMnemonic(java.util.ResourceBundle
226: .getBundle(
227: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
228: .getString("DELETE_FONT_BUTTON_MNEMONIC")
229: .charAt(0));
230: deleteButton.setText(org.openide.util.NbBundle.getMessage(
231: FontFamilyEditorDialog.class, "DELETE"));
232: deleteButton.setMargin(new java.awt.Insets(2, 10, 2, 10));
233: deleteButton
234: .addActionListener(new java.awt.event.ActionListener() {
235: public void actionPerformed(
236: java.awt.event.ActionEvent evt) {
237: deleteButtonActionPerformed(evt);
238: }
239: });
240:
241: newDeleteButtonPanel.add(deleteButton);
242: deleteButton
243: .getAccessibleContext()
244: .setAccessibleDescription(
245: java.util.ResourceBundle
246: .getBundle(
247: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
248: .getString(
249: "DELETE_FONT_FAMILY_ACCESS_DESC"));
250:
251: gridBagConstraints = new java.awt.GridBagConstraints();
252: gridBagConstraints.gridx = 3;
253: gridBagConstraints.gridy = 1;
254: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
255: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
256: currentFontFamilyPanel.add(newDeleteButtonPanel,
257: gridBagConstraints);
258:
259: currentFontFamiliesLabel
260: .setDisplayedMnemonic(java.util.ResourceBundle
261: .getBundle(
262: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
263: .getString("CURRENT_FONTS").charAt(0));
264: currentFontFamiliesLabel.setLabelFor(fontFaceList);
265: currentFontFamiliesLabel.setText(org.openide.util.NbBundle
266: .getMessage(FontFamilyEditorDialog.class,
267: "CURRENT_FONTS"));
268: gridBagConstraints = new java.awt.GridBagConstraints();
269: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
270: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
271: currentFontFamilyPanel.add(currentFontFamiliesLabel,
272: gridBagConstraints);
273:
274: add(currentFontFamilyPanel, java.awt.BorderLayout.CENTER);
275:
276: fontFamilyEditor.setLayout(new java.awt.GridBagLayout());
277:
278: availableFontScroll.setPreferredSize(new java.awt.Dimension(
279: 200, 138));
280: availableFontList
281: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
282: public void valueChanged(
283: javax.swing.event.ListSelectionEvent evt) {
284: availableFontListValueChanged(evt);
285: }
286: });
287:
288: availableFontScroll.setViewportView(availableFontList);
289: availableFontList
290: .getAccessibleContext()
291: .setAccessibleName(
292: java.util.ResourceBundle
293: .getBundle(
294: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
295: .getString(
296: "AVAILABLE_FONT_LIST_ACCESS_NAME"));
297: availableFontList
298: .getAccessibleContext()
299: .setAccessibleDescription(
300: java.util.ResourceBundle
301: .getBundle(
302: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
303: .getString(
304: "AVAILABLE_FONT_LIST_ACCESS_DESC"));
305:
306: gridBagConstraints = new java.awt.GridBagConstraints();
307: gridBagConstraints.gridx = 0;
308: gridBagConstraints.gridy = 3;
309: gridBagConstraints.gridwidth = 2;
310: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
311: gridBagConstraints.weighty = 1.0;
312: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 10);
313: fontFamilyEditor.add(availableFontScroll, gridBagConstraints);
314:
315: selectedFontScroll.setPreferredSize(new java.awt.Dimension(200,
316: 130));
317: selectedFontList
318: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
319: public void valueChanged(
320: javax.swing.event.ListSelectionEvent evt) {
321: selectedFontListValueChanged(evt);
322: }
323: });
324:
325: selectedFontScroll.setViewportView(selectedFontList);
326: selectedFontList
327: .getAccessibleContext()
328: .setAccessibleDescription(
329: java.util.ResourceBundle
330: .getBundle(
331: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
332: .getString(
333: "SELECTED_FONT_LIST_ACCESS_DESC"));
334:
335: gridBagConstraints = new java.awt.GridBagConstraints();
336: gridBagConstraints.gridx = 3;
337: gridBagConstraints.gridy = 3;
338: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
339: gridBagConstraints.weightx = 1.0;
340: gridBagConstraints.weighty = 1.0;
341: gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
342: fontFamilyEditor.add(selectedFontScroll, gridBagConstraints);
343:
344: availableLabel.setLabelFor(fontSelectionCombo);
345: availableLabel.setText(org.openide.util.NbBundle.getMessage(
346: FontFamilyEditorDialog.class, "AVAILABLE"));
347: gridBagConstraints = new java.awt.GridBagConstraints();
348: gridBagConstraints.gridx = 0;
349: gridBagConstraints.gridy = 2;
350: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
351: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
352: fontFamilyEditor.add(availableLabel, gridBagConstraints);
353:
354: selectedLabel.setLabelFor(selectedFontList);
355: selectedLabel.setText(org.openide.util.NbBundle.getMessage(
356: FontFamilyEditorDialog.class, "SELECTED"));
357: gridBagConstraints = new java.awt.GridBagConstraints();
358: gridBagConstraints.gridx = 3;
359: gridBagConstraints.gridy = 2;
360: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
361: gridBagConstraints.weightx = 1.0;
362: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
363: fontFamilyEditor.add(selectedLabel, gridBagConstraints);
364: selectedLabel
365: .getAccessibleContext()
366: .setAccessibleDescription(
367: java.util.ResourceBundle
368: .getBundle(
369: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
370: .getString(
371: "SELECTED_FONT_LIST_ACCESS_DESC"));
372:
373: addRemoveButtonPanel.setLayout(new java.awt.GridLayout(2, 1, 0,
374: 5));
375:
376: addButton
377: .setMnemonic(java.util.ResourceBundle
378: .getBundle(
379: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
380: .getString("ADD_FONT_BUTTON_MNEMONIC")
381: .charAt(0));
382: addButton.setText(">");
383: addButton.setToolTipText(org.openide.util.NbBundle.getMessage(
384: FontFamilyEditorDialog.class, "Add_selected_fonts"));
385: addButton.setMargin(new java.awt.Insets(2, 10, 2, 10));
386: addButton
387: .addActionListener(new java.awt.event.ActionListener() {
388: public void actionPerformed(
389: java.awt.event.ActionEvent evt) {
390: addButtonActionPerformed(evt);
391: }
392: });
393:
394: addRemoveButtonPanel.add(addButton);
395: addButton
396: .getAccessibleContext()
397: .setAccessibleName(
398: java.util.ResourceBundle
399: .getBundle(
400: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
401: .getString("ADD_FONT_ACCESS_NAME"));
402:
403: removeButton
404: .setMnemonic(java.util.ResourceBundle
405: .getBundle(
406: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
407: .getString("REMOVE_FONT_BUTTON_MNEMONIC")
408: .charAt(0));
409: removeButton.setText("<");
410: removeButton.setToolTipText(org.openide.util.NbBundle
411: .getMessage(FontFamilyEditorDialog.class,
412: "Remove_selected_fonts"));
413: removeButton.setMargin(new java.awt.Insets(2, 10, 2, 10));
414: removeButton
415: .addActionListener(new java.awt.event.ActionListener() {
416: public void actionPerformed(
417: java.awt.event.ActionEvent evt) {
418: removeButtonActionPerformed(evt);
419: }
420: });
421:
422: addRemoveButtonPanel.add(removeButton);
423: removeButton
424: .getAccessibleContext()
425: .setAccessibleName(
426: java.util.ResourceBundle
427: .getBundle(
428: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
429: .getString("REMOVE_FONT_ACCESS_NAME"));
430:
431: gridBagConstraints = new java.awt.GridBagConstraints();
432: gridBagConstraints.gridx = 2;
433: gridBagConstraints.gridy = 3;
434: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
435: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
436: fontFamilyEditor.add(addRemoveButtonPanel, gridBagConstraints);
437:
438: upDownPanel.setLayout(new java.awt.GridLayout(0, 1, 0, 5));
439:
440: upButton
441: .setMnemonic(java.util.ResourceBundle
442: .getBundle(
443: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
444: .getString("UP_FONT_BUTTON_MNEMONIC").charAt(0));
445: upButton.setText(org.openide.util.NbBundle.getMessage(
446: FontFamilyEditorDialog.class, "UP"));
447: upButton.setMargin(new java.awt.Insets(2, 10, 2, 10));
448: upButton.addActionListener(new java.awt.event.ActionListener() {
449: public void actionPerformed(java.awt.event.ActionEvent evt) {
450: upButtonActionPerformed(evt);
451: }
452: });
453:
454: upDownPanel.add(upButton);
455: upButton
456: .getAccessibleContext()
457: .setAccessibleDescription(
458: java.util.ResourceBundle
459: .getBundle(
460: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
461: .getString("MOVE_FONT_UP_ACCESS_NAME"));
462:
463: downButton
464: .setMnemonic(java.util.ResourceBundle
465: .getBundle(
466: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
467: .getString("DOWN_FONT_BUTTON_MNEMONIC").charAt(
468: 0));
469: downButton.setText(org.openide.util.NbBundle.getMessage(
470: FontFamilyEditorDialog.class, "DOWN"));
471: downButton.setMargin(new java.awt.Insets(2, 10, 2, 10));
472: downButton
473: .addActionListener(new java.awt.event.ActionListener() {
474: public void actionPerformed(
475: java.awt.event.ActionEvent evt) {
476: downButtonActionPerformed(evt);
477: }
478: });
479:
480: upDownPanel.add(downButton);
481: downButton
482: .getAccessibleContext()
483: .setAccessibleDescription(
484: java.util.ResourceBundle
485: .getBundle(
486: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
487: .getString("MOVE_FONT_DOWN_ACCESS_NAME"));
488:
489: gridBagConstraints = new java.awt.GridBagConstraints();
490: gridBagConstraints.gridx = 4;
491: gridBagConstraints.gridy = 3;
492: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
493: gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
494: fontFamilyEditor.add(upDownPanel, gridBagConstraints);
495:
496: fontSelectionCombo
497: .addItemListener(new java.awt.event.ItemListener() {
498: public void itemStateChanged(
499: java.awt.event.ItemEvent evt) {
500: fontSelectionComboItemStateChanged(evt);
501: }
502: });
503:
504: gridBagConstraints = new java.awt.GridBagConstraints();
505: gridBagConstraints.gridx = 1;
506: gridBagConstraints.gridy = 2;
507: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
508: gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 10);
509: fontFamilyEditor.add(fontSelectionCombo, gridBagConstraints);
510: fontSelectionCombo
511: .getAccessibleContext()
512: .setAccessibleDescription(
513: java.util.ResourceBundle
514: .getBundle(
515: "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
516: .getString(
517: "AVAILABLE_FONT_COMBO_ACCESS_DESC"));
518:
519: add(fontFamilyEditor, java.awt.BorderLayout.SOUTH);
520:
521: }// </editor-fold>//GEN-END:initComponents
522:
523: private void downButtonActionPerformed(
524: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downButtonActionPerformed
525: if (selectedFonts.getSize() > 0) {
526: int index = selectedFontList.getSelectedIndex();
527: if ((index >= 0) && index < selectedFonts.getSize()) {
528: Object currentObject = selectedFonts.get(index);
529: Object prevObject = selectedFonts.get(index + 1);
530: selectedFonts.setElementAt(currentObject, index + 1);
531: selectedFonts.setElementAt(prevObject, index);
532: selectedFontList.setSelectedIndex(index + 1);
533: resetFontFamilySet();
534: }
535: }
536: }//GEN-LAST:event_downButtonActionPerformed
537:
538: private void upButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upButtonActionPerformed
539: if (selectedFonts.getSize() > 0) {
540: int index = selectedFontList.getSelectedIndex();
541: if (index > 0) {
542: Object currentObject = selectedFonts.get(index);
543: Object prevObject = selectedFonts.get(index - 1);
544: selectedFonts.setElementAt(currentObject, index - 1);
545: selectedFonts.setElementAt(prevObject, index);
546: selectedFontList.setSelectedIndex(index - 1);
547: resetFontFamilySet();
548: }
549: }
550: }//GEN-LAST:event_upButtonActionPerformed
551:
552: private void deleteButtonActionPerformed(
553: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
554: int index = fontFaceList.getSelectedIndex();
555: if (index == 0)
556: return;
557: fontFamilies.remove(index);
558: if (!fontFamilies.isEmpty()) {
559: if (index == fontFamilies.getSize())
560: index--;
561: fontFaceList.setSelectedIndex(index);
562: }
563: }//GEN-LAST:event_deleteButtonActionPerformed
564:
565: private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
566: fontFamilies.insertElementAt(" ", 1);
567: fontFaceList.setSelectedIndex(1);
568: }//GEN-LAST:event_newButtonActionPerformed
569:
570: private void selectedFontListValueChanged(
571: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_selectedFontListValueChanged
572: if (!evt.getValueIsAdjusting()) {
573: //selectedFont = (String)selectedFontList.getSelectedValue();
574: int index = selectedFontList.getSelectedIndex();
575: if (index == 0) {
576: upButton.setEnabled(false);
577: } else {
578: upButton.setEnabled(true);
579: }
580: if (index == selectedFonts.getSize() - 1) {
581: downButton.setEnabled(false);
582: } else {
583: downButton.setEnabled(true);
584: }
585: }
586: }//GEN-LAST:event_selectedFontListValueChanged
587:
588: private void availableFontListValueChanged(
589: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_availableFontListValueChanged
590: if (!evt.getValueIsAdjusting()) {
591: //selectedAvailableFont = (String)availableFontList.getSelectedValue();
592: }
593: }//GEN-LAST:event_availableFontListValueChanged
594:
595: private void removeButtonActionPerformed(
596: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
597: Object[] selections = selectedFontList.getSelectedValues();
598: for (int i = 0; i < selections.length; i++) {
599: if (selectedFonts.contains(selections[i])) {
600: selectedFonts.removeElement(selections[i]);
601: }
602: }
603: if (!selectedFonts.isEmpty()) {
604: selectedFontList.setSelectedIndex(0);
605: } else {
606: removeButton.setEnabled(false);
607: upButton.setEnabled(false);
608: downButton.setEnabled(false);
609: }
610: resetFontFamilySet();
611: }//GEN-LAST:event_removeButtonActionPerformed
612:
613: private void fontFaceListValueChanged(
614: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_fontFaceListValueChanged
615: if (!evt.getValueIsAdjusting()) {
616: currentIndex = fontFaceList.getSelectedIndex();
617: selectedFonts.removeAllElements();
618: // Do not show the <NOT SET> in the selected fonts
619: if (currentIndex != 0) {
620: addButton.setEnabled(true);
621: deleteButton.setEnabled(true);
622: upButton.setEnabled(true);
623: downButton.setEnabled(true);
624: String selectedFontSet = (String) fontFaceList
625: .getSelectedValue();
626: if ((selectedFontSet != null)
627: && !selectedFontSet.trim().equals("")) {
628: StringTokenizer st = new StringTokenizer(
629: selectedFontSet, ",");
630: while (st.hasMoreTokens()) {
631: String fontName = st.nextToken();
632: if (!fontName.trim().equals("")) {
633: fontName = fontName.replaceAll("'", "");
634: selectedFonts.addElement(fontName);
635: }
636: }
637: }
638: if (!selectedFonts.isEmpty()) {
639: removeButton.setEnabled(true);
640: selectedFontList.setSelectedIndex(0);
641: }
642: } else {
643: addButton.setEnabled(false);
644: removeButton.setEnabled(false);
645: deleteButton.setEnabled(false);
646: upButton.setEnabled(false);
647: downButton.setEnabled(false);
648: }
649: }
650: }//GEN-LAST:event_fontFaceListValueChanged
651:
652: private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
653: Object[] selections = availableFontList.getSelectedValues();
654: for (int i = 0; i < selections.length; i++) {
655: if (!selectedFonts.contains(selections[i])) {
656: selectedFonts.addElement(selections[i]);
657: selectedFontList.setSelectedValue(selections[i], true);
658: }
659: }
660: removeButton.setEnabled(true);
661: resetFontFamilySet();
662: }//GEN-LAST:event_addButtonActionPerformed
663:
664: private void fontSelectionComboItemStateChanged(
665: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fontSelectionComboItemStateChanged
666: fontSelectionCombo.getSelectedIndex();
667: switch (fontSelectionCombo.getSelectedIndex()) {
668: case 0:
669: availableFonts = fontModel.getFontList();
670: //availableFontList.setModel(fontModel.getFontList());
671: break;
672: case 1:
673: availableFonts = fontModel.getFontFamilyList();
674: //availableFontList.setModel(fontModel.getFontFamilyList());
675: break;
676: case 2:
677: availableFonts = fontModel.getWebFontList();
678: //availableFontList.setModel(fontModel.getWebFontList());
679: break;
680: }
681: availableFontList.setModel(availableFonts);
682: availableFontList.setSelectedIndex(0);
683: }//GEN-LAST:event_fontSelectionComboItemStateChanged
684:
685: private void resetFontFamilySet() {
686: String fontSet = "";
687: for (int i = 0; i < selectedFonts.size(); i++) {
688: String fontName = ((String) selectedFonts.get(i)).trim();
689: // If the font name has spaces then quote it as per CSS spec.
690: if (fontName.indexOf(" ") != -1) {
691: fontName = "\'" + fontName + "\'";
692: }
693: fontSet += fontName;
694: if (i < selectedFonts.size() - 1)
695: fontSet += ",";
696: }
697: // Otherwise List does not display the empty line
698: if (fontSet.equals(""))
699: fontSet = " ";
700: fontFamilies.setElementAt(fontSet, currentIndex);
701: }
702:
703: // Variables declaration - do not modify//GEN-BEGIN:variables
704: private javax.swing.JButton addButton;
705: private javax.swing.JPanel addRemoveButtonPanel;
706: private javax.swing.JList availableFontList;
707: private javax.swing.JScrollPane availableFontScroll;
708: private javax.swing.JLabel availableLabel;
709: private javax.swing.JLabel currentFontFamiliesLabel;
710: private javax.swing.JPanel currentFontFamilyPanel;
711: private javax.swing.JButton deleteButton;
712: private javax.swing.JButton downButton;
713: private javax.swing.JList fontFaceList;
714: private javax.swing.JPanel fontFamilyEditor;
715: private javax.swing.JScrollPane fontFamilyScroll;
716: private javax.swing.JComboBox fontSelectionCombo;
717: private javax.swing.JButton newButton;
718: private javax.swing.JPanel newDeleteButtonPanel;
719: private javax.swing.JButton removeButton;
720: private javax.swing.JList selectedFontList;
721: private javax.swing.JScrollPane selectedFontScroll;
722: private javax.swing.JLabel selectedLabel;
723: private javax.swing.JButton upButton;
724: private javax.swing.JPanel upDownPanel;
725: // End of variables declaration//GEN-END:variables
726:
727: }
|