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:
042: /*
043: * FontFamilyEditorDialog.java
044: *
045: * Created on October 18, 2004, 3:47 PM
046: */
047:
048: package org.netbeans.modules.css.visual.ui;
049:
050: import org.netbeans.modules.css.visual.model.FontModel;
051: import java.awt.event.ActionEvent;
052: import java.awt.event.ActionListener;
053: import java.util.StringTokenizer;
054: import javax.swing.DefaultListModel;
055: import javax.swing.JButton;
056: import javax.swing.JDialog;
057: import org.openide.DialogDescriptor;
058: import org.openide.DialogDisplayer;
059: import org.openide.util.NbBundle;
060:
061: /**
062: * Font Family Editor Dialog
063: * @author Winston Prakash
064: * @version 1.0
065: */
066: public class FontFamilyEditorDialog extends javax.swing.JPanel {
067: private JDialog dialog;
068: private DialogDescriptor dlg = null;
069: private String closeButtonLabel = NbBundle.getMessage(
070: FontFamilyEditorDialog.class, "Close_Button_Label");
071:
072: private JButton closeButton = new JButton(closeButtonLabel);
073:
074: DefaultListModel fontFamilies = null;
075: DefaultListModel selectedFonts = new DefaultListModel();
076: DefaultListModel availableFonts = new DefaultListModel();
077:
078: FontModel fontModel = new FontModel();
079:
080: int currentIndex = 1;
081:
082: /** Creates new form TestPanel */
083: public FontFamilyEditorDialog(DefaultListModel fontFamilies,
084: int currIndex) {
085: initComponents();
086: currentIndex = currIndex;
087: this .fontFamilies = fontFamilies;
088: fontFaceList.setModel(fontFamilies);
089: fontFaceList.setSelectedIndex(currentIndex);
090: fontSelectionCombo.setModel(fontModel.getFontSelectionList());
091: fontSelectionCombo.setSelectedIndex(0);
092: availableFonts = fontModel.getFontList();
093: availableFontList.setModel(availableFonts);
094: selectedFontList.setModel(selectedFonts);
095: availableFontList.setSelectedIndex(0);
096: }
097:
098: public void showDialog() {
099: // Add a listener to the dialog's buttons
100: ActionListener listener = new ActionListener() {
101: public void actionPerformed(ActionEvent evt) {
102: dialog.setVisible(false);
103: }
104: };
105: dlg = new DialogDescriptor(this , NbBundle.getMessage(
106: FontFamilyEditorDialog.class,
107: "FONT_FAMILY_EDITOR_TITLE"), true, listener);
108: dlg.setOptions(new Object[] { closeButton });
109: dlg.setClosingOptions(new Object[] { closeButton });
110: //dlg.setHelpCtx(new HelpCtx("projrave_ui_elements_server_nav_add_datasourcedb")); // NOI18N
111:
112: dialog = (JDialog) DialogDisplayer.getDefault().createDialog(
113: dlg);
114: dialog.setResizable(true);
115: dialog.pack();
116: dialog.setVisible(true);
117: }
118:
119: public int getSelectedIndex() {
120: return currentIndex;
121: }
122:
123: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
124: private void initComponents() {
125: java.awt.GridBagConstraints gridBagConstraints;
126:
127: currentFontFamilyPanel = new javax.swing.JPanel();
128: fontFamilyScroll = new javax.swing.JScrollPane();
129: fontFaceList = new javax.swing.JList();
130: newDeleteButtonPanel = new javax.swing.JPanel();
131: newButton = new javax.swing.JButton();
132: deleteButton = new javax.swing.JButton();
133: currentFontFamiliesLabel = new javax.swing.JLabel();
134: fontFamilyEditor = new javax.swing.JPanel();
135: availableFontScroll = new javax.swing.JScrollPane();
136: availableFontList = new javax.swing.JList();
137: selectedFontScroll = new javax.swing.JScrollPane();
138: selectedFontList = new javax.swing.JList();
139: availableLabel = new javax.swing.JLabel();
140: selectedLabel = new javax.swing.JLabel();
141: addRemoveButtonPanel = new javax.swing.JPanel();
142: addButton = new javax.swing.JButton();
143: removeButton = new javax.swing.JButton();
144: upDownPanel = new javax.swing.JPanel();
145: upButton = new javax.swing.JButton();
146: downButton = new javax.swing.JButton();
147: fontSelectionCombo = new javax.swing.JComboBox();
148:
149: setLayout(new java.awt.BorderLayout(5, 5));
150:
151: setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5,
152: 5));
153: currentFontFamilyPanel.setLayout(new java.awt.GridBagLayout());
154:
155: fontFaceList
156: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
157: fontFaceList
158: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
159: public void valueChanged(
160: javax.swing.event.ListSelectionEvent evt) {
161: fontFaceListValueChanged(evt);
162: }
163: });
164:
165: fontFamilyScroll.setViewportView(fontFaceList);
166: fontFaceList.getAccessibleContext().setAccessibleName(
167: org.openide.util.NbBundle.getMessage(
168: FontFamilyEditorDialog.class, "CURRENT_FONTS"));
169: fontFaceList.getAccessibleContext().setAccessibleDescription(
170: java.util.ResourceBundle.getBundle(
171: "org/netbeans/modules/css/visual/ui/Bundle")
172: .getString("FONT_FAMILY_LIST_ACCESS_DESC"));
173:
174: gridBagConstraints = new java.awt.GridBagConstraints();
175: gridBagConstraints.gridx = 0;
176: gridBagConstraints.gridy = 1;
177: gridBagConstraints.gridwidth = 3;
178: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
179: gridBagConstraints.weightx = 1.0;
180: gridBagConstraints.weighty = 1.0;
181: currentFontFamilyPanel
182: .add(fontFamilyScroll, gridBagConstraints);
183:
184: newDeleteButtonPanel.setLayout(new java.awt.GridLayout(0, 1, 0,
185: 5));
186:
187: newButton.setMnemonic(org.openide.util.NbBundle.getMessage(
188: FontFamilyEditorDialog.class,
189: "FONT_FAMILY_NEW_BUTTON_MNEMONIC").charAt(0));
190: newButton.setText(org.openide.util.NbBundle.getMessage(
191: FontFamilyEditorDialog.class, "NEW"));
192: newButton.setMargin(new java.awt.Insets(2, 10, 2, 10));
193: newButton
194: .addActionListener(new java.awt.event.ActionListener() {
195: public void actionPerformed(
196: java.awt.event.ActionEvent evt) {
197: newButtonActionPerformed(evt);
198: }
199: });
200:
201: newDeleteButtonPanel.add(newButton);
202: newButton.getAccessibleContext().setAccessibleDescription(
203: java.util.ResourceBundle.getBundle(
204: "org/netbeans/modules/css/visual/ui/Bundle")
205: .getString("ADD_FONT_FAMILY_ACCESS_DESC"));
206:
207: deleteButton.setMnemonic(org.openide.util.NbBundle.getMessage(
208: FontFamilyEditorDialog.class,
209: "FONT_FAMILY_DELETE_BUTTON_MNEMONIC").charAt(0));
210: deleteButton.setText(org.openide.util.NbBundle.getMessage(
211: FontFamilyEditorDialog.class, "DELETE"));
212: deleteButton.setMargin(new java.awt.Insets(2, 10, 2, 10));
213: deleteButton
214: .addActionListener(new java.awt.event.ActionListener() {
215: public void actionPerformed(
216: java.awt.event.ActionEvent evt) {
217: deleteButtonActionPerformed(evt);
218: }
219: });
220:
221: newDeleteButtonPanel.add(deleteButton);
222: deleteButton.getAccessibleContext().setAccessibleDescription(
223: java.util.ResourceBundle.getBundle(
224: "org/netbeans/modules/css/visual/ui/Bundle")
225: .getString("DELETE_FONT_FAMILY_ACCESS_DESC"));
226:
227: gridBagConstraints = new java.awt.GridBagConstraints();
228: gridBagConstraints.gridx = 3;
229: gridBagConstraints.gridy = 1;
230: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
231: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
232: currentFontFamilyPanel.add(newDeleteButtonPanel,
233: gridBagConstraints);
234:
235: currentFontFamiliesLabel.setLabelFor(fontFaceList);
236: currentFontFamiliesLabel.setText(org.openide.util.NbBundle
237: .getMessage(FontFamilyEditorDialog.class,
238: "CURRENT_FONTS"));
239: gridBagConstraints = new java.awt.GridBagConstraints();
240: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
241: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
242: currentFontFamilyPanel.add(currentFontFamiliesLabel,
243: gridBagConstraints);
244:
245: add(currentFontFamilyPanel, java.awt.BorderLayout.CENTER);
246:
247: fontFamilyEditor.setLayout(new java.awt.GridBagLayout());
248:
249: availableFontScroll.setPreferredSize(new java.awt.Dimension(
250: 200, 138));
251: availableFontList
252: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
253: public void valueChanged(
254: javax.swing.event.ListSelectionEvent evt) {
255: availableFontListValueChanged(evt);
256: }
257: });
258:
259: availableFontScroll.setViewportView(availableFontList);
260: availableFontList.getAccessibleContext().setAccessibleName(
261: java.util.ResourceBundle.getBundle(
262: "org/netbeans/modules/css/visual/ui/Bundle")
263: .getString("AVAILABLE_FONT_LIST_ACCESS_NAME"));
264: availableFontList
265: .getAccessibleContext()
266: .setAccessibleDescription(
267: java.util.ResourceBundle
268: .getBundle(
269: "org/netbeans/modules/css/visual/ui/Bundle")
270: .getString(
271: "AVAILABLE_FONT_LIST_ACCESS_DESC"));
272:
273: gridBagConstraints = new java.awt.GridBagConstraints();
274: gridBagConstraints.gridx = 0;
275: gridBagConstraints.gridy = 3;
276: gridBagConstraints.gridwidth = 2;
277: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
278: gridBagConstraints.weighty = 1.0;
279: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 10);
280: fontFamilyEditor.add(availableFontScroll, gridBagConstraints);
281:
282: selectedFontScroll.setPreferredSize(new java.awt.Dimension(200,
283: 130));
284: selectedFontList
285: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
286: public void valueChanged(
287: javax.swing.event.ListSelectionEvent evt) {
288: selectedFontListValueChanged(evt);
289: }
290: });
291:
292: selectedFontScroll.setViewportView(selectedFontList);
293: selectedFontList.getAccessibleContext().setAccessibleName(
294: org.openide.util.NbBundle.getMessage(
295: FontFamilyEditorDialog.class, "SELECTED"));
296: selectedFontList
297: .getAccessibleContext()
298: .setAccessibleDescription(
299: java.util.ResourceBundle
300: .getBundle(
301: "org/netbeans/modules/css/visual/ui/Bundle")
302: .getString(
303: "SELECTED_FONT_LIST_ACCESS_DESC"));
304:
305: gridBagConstraints = new java.awt.GridBagConstraints();
306: gridBagConstraints.gridx = 3;
307: gridBagConstraints.gridy = 3;
308: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
309: gridBagConstraints.weightx = 1.0;
310: gridBagConstraints.weighty = 1.0;
311: gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
312: fontFamilyEditor.add(selectedFontScroll, gridBagConstraints);
313:
314: availableLabel.setLabelFor(fontSelectionCombo);
315: availableLabel.setText(org.openide.util.NbBundle.getMessage(
316: FontFamilyEditorDialog.class, "AVAILABLE"));
317: gridBagConstraints = new java.awt.GridBagConstraints();
318: gridBagConstraints.gridx = 0;
319: gridBagConstraints.gridy = 2;
320: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
321: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
322: fontFamilyEditor.add(availableLabel, gridBagConstraints);
323:
324: selectedLabel.setLabelFor(selectedFontList);
325: selectedLabel.setText(org.openide.util.NbBundle.getMessage(
326: FontFamilyEditorDialog.class, "SELECTED"));
327: gridBagConstraints = new java.awt.GridBagConstraints();
328: gridBagConstraints.gridx = 3;
329: gridBagConstraints.gridy = 2;
330: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
331: gridBagConstraints.weightx = 1.0;
332: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
333: fontFamilyEditor.add(selectedLabel, gridBagConstraints);
334: selectedLabel.getAccessibleContext().setAccessibleDescription(
335: java.util.ResourceBundle.getBundle(
336: "org/netbeans/modules/css/visual/ui/Bundle")
337: .getString("SELECTED_FONT_LIST_ACCESS_DESC"));
338:
339: addRemoveButtonPanel.setLayout(new java.awt.GridLayout(2, 1, 0,
340: 5));
341:
342: addButton.setText(">");
343: addButton.setToolTipText(org.openide.util.NbBundle.getMessage(
344: FontFamilyEditorDialog.class, "Add_selected_fonts"));
345: addButton.setMargin(new java.awt.Insets(2, 10, 2, 10));
346: addButton
347: .addActionListener(new java.awt.event.ActionListener() {
348: public void actionPerformed(
349: java.awt.event.ActionEvent evt) {
350: addButtonActionPerformed(evt);
351: }
352: });
353:
354: addRemoveButtonPanel.add(addButton);
355: addButton.getAccessibleContext().setAccessibleName(
356: java.util.ResourceBundle.getBundle(
357: "org/netbeans/modules/css/visual/ui/Bundle")
358: .getString("ADD_FONT_ACCESS_NAME"));
359:
360: removeButton.setText("<");
361: removeButton.setToolTipText(org.openide.util.NbBundle
362: .getMessage(FontFamilyEditorDialog.class,
363: "Remove_selected_fonts"));
364: removeButton.setMargin(new java.awt.Insets(2, 10, 2, 10));
365: removeButton
366: .addActionListener(new java.awt.event.ActionListener() {
367: public void actionPerformed(
368: java.awt.event.ActionEvent evt) {
369: removeButtonActionPerformed(evt);
370: }
371: });
372:
373: addRemoveButtonPanel.add(removeButton);
374: removeButton.getAccessibleContext().setAccessibleName(
375: java.util.ResourceBundle.getBundle(
376: "org/netbeans/modules/css/visual/ui/Bundle")
377: .getString("REMOVE_FONT_ACCESS_NAME"));
378:
379: gridBagConstraints = new java.awt.GridBagConstraints();
380: gridBagConstraints.gridx = 2;
381: gridBagConstraints.gridy = 3;
382: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
383: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
384: fontFamilyEditor.add(addRemoveButtonPanel, gridBagConstraints);
385:
386: upDownPanel.setLayout(new java.awt.GridLayout(0, 1, 0, 5));
387:
388: upButton.setMnemonic(org.openide.util.NbBundle.getMessage(
389: FontFamilyEditorDialog.class,
390: "FONT_FAMILY_UP_BUTTON_MNEMONIC").charAt(0));
391: upButton.setText(org.openide.util.NbBundle.getMessage(
392: FontFamilyEditorDialog.class, "UP"));
393: upButton.setMargin(new java.awt.Insets(2, 10, 2, 10));
394: upButton.addActionListener(new java.awt.event.ActionListener() {
395: public void actionPerformed(java.awt.event.ActionEvent evt) {
396: upButtonActionPerformed(evt);
397: }
398: });
399:
400: upDownPanel.add(upButton);
401: upButton.getAccessibleContext().setAccessibleDescription(
402: java.util.ResourceBundle.getBundle(
403: "org/netbeans/modules/css/visual/ui/Bundle")
404: .getString("MOVE_FONT_UP_ACCESS_NAME"));
405:
406: downButton.setMnemonic(org.openide.util.NbBundle.getMessage(
407: FontFamilyEditorDialog.class,
408: "FONT_FAMILY_DOWN_BUTTON_MNEMONIC").charAt(0));
409: downButton.setText(org.openide.util.NbBundle.getMessage(
410: FontFamilyEditorDialog.class, "DOWN"));
411: downButton.setMargin(new java.awt.Insets(2, 10, 2, 10));
412: downButton
413: .addActionListener(new java.awt.event.ActionListener() {
414: public void actionPerformed(
415: java.awt.event.ActionEvent evt) {
416: downButtonActionPerformed(evt);
417: }
418: });
419:
420: upDownPanel.add(downButton);
421: downButton.getAccessibleContext().setAccessibleDescription(
422: java.util.ResourceBundle.getBundle(
423: "org/netbeans/modules/css/visual/ui/Bundle")
424: .getString("MOVE_FONT_DOWN_ACCESS_NAME"));
425:
426: gridBagConstraints = new java.awt.GridBagConstraints();
427: gridBagConstraints.gridx = 4;
428: gridBagConstraints.gridy = 3;
429: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
430: gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
431: fontFamilyEditor.add(upDownPanel, gridBagConstraints);
432:
433: fontSelectionCombo
434: .addItemListener(new java.awt.event.ItemListener() {
435: public void itemStateChanged(
436: java.awt.event.ItemEvent evt) {
437: fontSelectionComboItemStateChanged(evt);
438: }
439: });
440:
441: gridBagConstraints = new java.awt.GridBagConstraints();
442: gridBagConstraints.gridx = 1;
443: gridBagConstraints.gridy = 2;
444: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
445: gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 10);
446: fontFamilyEditor.add(fontSelectionCombo, gridBagConstraints);
447: fontSelectionCombo
448: .getAccessibleContext()
449: .setAccessibleDescription(
450: java.util.ResourceBundle
451: .getBundle(
452: "org/netbeans/modules/css/visual/ui/Bundle")
453: .getString(
454: "AVAILABLE_FONT_COMBO_ACCESS_DESC"));
455:
456: add(fontFamilyEditor, java.awt.BorderLayout.SOUTH);
457:
458: }// </editor-fold>//GEN-END:initComponents
459:
460: private void downButtonActionPerformed(
461: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downButtonActionPerformed
462: if (selectedFonts.getSize() > 0) {
463: int index = selectedFontList.getSelectedIndex();
464: if ((index >= 0) && index < selectedFonts.getSize()) {
465: Object currentObject = selectedFonts.get(index);
466: Object prevObject = selectedFonts.get(index + 1);
467: selectedFonts.setElementAt(currentObject, index + 1);
468: selectedFonts.setElementAt(prevObject, index);
469: selectedFontList.setSelectedIndex(index + 1);
470: resetFontFamilySet();
471: }
472: }
473: }//GEN-LAST:event_downButtonActionPerformed
474:
475: private void upButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upButtonActionPerformed
476: if (selectedFonts.getSize() > 0) {
477: int index = selectedFontList.getSelectedIndex();
478: if (index > 0) {
479: Object currentObject = selectedFonts.get(index);
480: Object prevObject = selectedFonts.get(index - 1);
481: selectedFonts.setElementAt(currentObject, index - 1);
482: selectedFonts.setElementAt(prevObject, index);
483: selectedFontList.setSelectedIndex(index - 1);
484: resetFontFamilySet();
485: }
486: }
487: }//GEN-LAST:event_upButtonActionPerformed
488:
489: private void deleteButtonActionPerformed(
490: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
491: int index = fontFaceList.getSelectedIndex();
492: if (index == 0)
493: return;
494: fontFamilies.remove(index);
495: if (!fontFamilies.isEmpty()) {
496: if (index == fontFamilies.getSize())
497: index--;
498: fontFaceList.setSelectedIndex(index);
499: }
500: }//GEN-LAST:event_deleteButtonActionPerformed
501:
502: private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
503: fontFamilies.insertElementAt(" ", 1);
504: fontFaceList.setSelectedIndex(1);
505: }//GEN-LAST:event_newButtonActionPerformed
506:
507: private void selectedFontListValueChanged(
508: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_selectedFontListValueChanged
509: if (!evt.getValueIsAdjusting()) {
510: //selectedFont = (String)selectedFontList.getSelectedValue();
511: int index = selectedFontList.getSelectedIndex();
512: if (index == 0) {
513: upButton.setEnabled(false);
514: } else {
515: upButton.setEnabled(true);
516: }
517: if (index == selectedFonts.getSize() - 1) {
518: downButton.setEnabled(false);
519: } else {
520: downButton.setEnabled(true);
521: }
522: }
523: }//GEN-LAST:event_selectedFontListValueChanged
524:
525: private void availableFontListValueChanged(
526: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_availableFontListValueChanged
527: if (!evt.getValueIsAdjusting()) {
528: //selectedAvailableFont = (String)availableFontList.getSelectedValue();
529: }
530: }//GEN-LAST:event_availableFontListValueChanged
531:
532: private void removeButtonActionPerformed(
533: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
534: Object[] selections = selectedFontList.getSelectedValues();
535: for (int i = 0; i < selections.length; i++) {
536: if (selectedFonts.contains(selections[i])) {
537: selectedFonts.removeElement(selections[i]);
538: }
539: }
540: if (!selectedFonts.isEmpty()) {
541: selectedFontList.setSelectedIndex(0);
542: } else {
543: removeButton.setEnabled(false);
544: upButton.setEnabled(false);
545: downButton.setEnabled(false);
546: }
547: resetFontFamilySet();
548: }//GEN-LAST:event_removeButtonActionPerformed
549:
550: private void fontFaceListValueChanged(
551: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_fontFaceListValueChanged
552: if (!evt.getValueIsAdjusting()) {
553: currentIndex = fontFaceList.getSelectedIndex();
554: selectedFonts.removeAllElements();
555: // Do not show the <NOT SET> in the selected fonts
556: if (currentIndex != 0) {
557: addButton.setEnabled(true);
558: deleteButton.setEnabled(true);
559: upButton.setEnabled(true);
560: downButton.setEnabled(true);
561: String selectedFontSet = (String) fontFaceList
562: .getSelectedValue();
563: if ((selectedFontSet != null)
564: && !selectedFontSet.trim().equals("")) {
565: StringTokenizer st = new StringTokenizer(
566: selectedFontSet, ",");
567: while (st.hasMoreTokens()) {
568: String fontName = st.nextToken();
569: if (!fontName.trim().equals("")) {
570: fontName = fontName.replaceAll("'", "");
571: selectedFonts.addElement(fontName);
572: }
573: }
574: }
575: if (!selectedFonts.isEmpty()) {
576: removeButton.setEnabled(true);
577: selectedFontList.setSelectedIndex(0);
578: }
579: } else {
580: addButton.setEnabled(false);
581: removeButton.setEnabled(false);
582: deleteButton.setEnabled(false);
583: upButton.setEnabled(false);
584: downButton.setEnabled(false);
585: }
586: }
587: }//GEN-LAST:event_fontFaceListValueChanged
588:
589: private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
590: Object[] selections = availableFontList.getSelectedValues();
591: for (int i = 0; i < selections.length; i++) {
592: if (!selectedFonts.contains(selections[i])) {
593: selectedFonts.addElement(selections[i]);
594: selectedFontList.setSelectedValue(selections[i], true);
595: }
596: }
597: removeButton.setEnabled(true);
598: resetFontFamilySet();
599: }//GEN-LAST:event_addButtonActionPerformed
600:
601: private void fontSelectionComboItemStateChanged(
602: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fontSelectionComboItemStateChanged
603: fontSelectionCombo.getSelectedIndex();
604: switch (fontSelectionCombo.getSelectedIndex()) {
605: case 0:
606: availableFonts = fontModel.getFontList();
607: //availableFontList.setModel(fontModel.getFontList());
608: break;
609: case 1:
610: availableFonts = fontModel.getFontFamilyList();
611: //availableFontList.setModel(fontModel.getFontFamilyList());
612: break;
613: case 2:
614: availableFonts = fontModel.getWebFontList();
615: //availableFontList.setModel(fontModel.getWebFontList());
616: break;
617: }
618: availableFontList.setModel(availableFonts);
619: availableFontList.setSelectedIndex(0);
620: }//GEN-LAST:event_fontSelectionComboItemStateChanged
621:
622: private void resetFontFamilySet() {
623: StringBuffer fontSetBuf = new StringBuffer();
624: for (int i = 0; i < selectedFonts.size(); i++) {
625: String fontName = ((String) selectedFonts.get(i)).trim();
626: // If the font name has spaces then quote it as per CSS spec.
627: if (fontName.indexOf(" ") != -1) {
628: fontName = "\'" + fontName + "\'";
629: }
630: fontSetBuf.append(fontName);
631: if (i < selectedFonts.size() - 1)
632: fontSetBuf.append(",");
633: }
634: // Otherwise List does not display the empty line
635: if (fontSetBuf.length() == 0)
636: fontSetBuf.append(" ");
637: fontFamilies.setElementAt(fontSetBuf.toString(), currentIndex);
638: }
639:
640: // Variables declaration - do not modify//GEN-BEGIN:variables
641: private javax.swing.JButton addButton;
642: private javax.swing.JPanel addRemoveButtonPanel;
643: private javax.swing.JList availableFontList;
644: private javax.swing.JScrollPane availableFontScroll;
645: private javax.swing.JLabel availableLabel;
646: private javax.swing.JLabel currentFontFamiliesLabel;
647: private javax.swing.JPanel currentFontFamilyPanel;
648: private javax.swing.JButton deleteButton;
649: private javax.swing.JButton downButton;
650: private javax.swing.JList fontFaceList;
651: private javax.swing.JPanel fontFamilyEditor;
652: private javax.swing.JScrollPane fontFamilyScroll;
653: private javax.swing.JComboBox fontSelectionCombo;
654: private javax.swing.JButton newButton;
655: private javax.swing.JPanel newDeleteButtonPanel;
656: private javax.swing.JButton removeButton;
657: private javax.swing.JList selectedFontList;
658: private javax.swing.JScrollPane selectedFontScroll;
659: private javax.swing.JLabel selectedLabel;
660: private javax.swing.JButton upButton;
661: private javax.swing.JPanel upDownPanel;
662: // End of variables declaration//GEN-END:variables
663:
664: }
|