0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: /*
0043: * FontStyleEditor.java
0044: *
0045: * Created on October 13, 2004, 12:23 PM
0046: */
0047:
0048: package org.netbeans.modules.css.visual.ui;
0049:
0050: import org.netbeans.modules.css.visual.model.CssProperties;
0051: import org.netbeans.modules.css.editor.model.CssRuleContent;
0052: import org.netbeans.modules.css.visual.model.FontModel;
0053: import org.netbeans.modules.css.visual.model.PropertyData;
0054: import org.netbeans.modules.css.visual.model.PropertyWithUnitData;
0055: import org.netbeans.modules.css.visual.model.TextDecorationData;
0056: import org.netbeans.modules.css.visual.model.PropertyData;
0057: import java.awt.BorderLayout;
0058: import java.awt.Dimension;
0059: import java.awt.FontMetrics;
0060: import java.beans.PropertyChangeEvent;
0061: import java.beans.PropertyChangeListener;
0062: import java.util.StringTokenizer;
0063: import javax.swing.DefaultComboBoxModel;
0064: import javax.swing.DefaultListModel;
0065: import javax.swing.SwingUtilities;
0066: import org.netbeans.modules.css.visual.model.Utils;
0067: import org.openide.util.NbBundle;
0068:
0069: /**
0070: * Font Style editor.
0071: * @author Winston Prakash
0072: * @version 1.0
0073: */
0074: public class FontStyleEditor extends StyleEditor {
0075:
0076: ColorSelectionField colorField = new ColorSelectionField();
0077: TextDecorationData textDecorationData = new TextDecorationData();
0078:
0079: FontModel fontModel = new FontModel();
0080: DefaultListModel fontFamilies = fontModel.getFontFamilySetList();
0081:
0082: DefaultListModel fontSizes;
0083: DefaultComboBoxModel fontSizeUnits;
0084: DefaultComboBoxModel fontStyles;
0085: DefaultComboBoxModel fontWeights;
0086: DefaultComboBoxModel fontVariants;
0087:
0088: String temporaryFontSet = null;
0089:
0090: private String currentFontFamily = null;
0091: private String currentFontSize = null;
0092: private String currentFontStyle = null;
0093: private String currentFontWeight = null;
0094: private String currentFontVariant = null;
0095: private String currentFontColor = null;
0096: private String currentFontDecoration = null;
0097:
0098: /** Creates new form FontStyleEditor */
0099: public FontStyleEditor() {
0100: setName("fontStyleEditor"); //NOI18N
0101: setDisplayName(NbBundle.getMessage(FontStyleEditor.class,
0102: "FONT_EDITOR_DISPNAME"));
0103: initComponents();
0104: colorSelectionPanel.add(colorField, BorderLayout.CENTER);
0105: colorField.addPropertyChangeListener("color",
0106: new PropertyChangeListener() {
0107: public void propertyChange(PropertyChangeEvent evt) {
0108: setFontColor();
0109: }
0110: });//NOI18N
0111: initialize();
0112: }
0113:
0114: private void initialize() {
0115: // Set the font family to the GUI
0116: fontModel = new FontModel();
0117: fontFamilies = fontModel.getFontFamilySetList();
0118: fontFaceList.setModel(fontFamilies);
0119:
0120: // Set the font size to the GUI
0121: fontSizes = fontModel.getFontSizeList();
0122: fontSizeList.setModel(fontSizes);
0123:
0124: fontSizeUnits = fontModel.getFontSizeUnitList();
0125: fontSizeUnitCombo.setModel(fontSizeUnits);
0126: fontSizeUnitCombo.setSelectedItem("px");
0127:
0128: // Set the font Style to the GUI
0129: fontStyles = fontModel.getFontStyleList();
0130: fontStyleComboBox.setModel(fontStyles);
0131:
0132: // Set the font Weight to the GUI
0133: fontWeights = fontModel.getFontWeightList();
0134: fontWeightComboBox.setModel(fontWeights);
0135:
0136: // Set the font Variant to the GUI
0137: fontVariants = fontModel.getFontVariantList();
0138: fontVariantComboBox.setModel(fontVariants);
0139:
0140: FontMetrics fontMetrics = fontSizeField
0141: .getFontMetrics(fontSizeField.getFont());
0142: int width = fontMetrics.stringWidth((String) fontSizes.get(0)) + 10;
0143: int height = (fontMetrics.getHeight() + 10) > 25 ? fontMetrics
0144: .getHeight() + 10 : 25;
0145: fontSizeField.setPreferredSize(new Dimension(width, height));
0146: }
0147:
0148: /**
0149: * Set the CSS Properties Values from the CssStyleData data structure
0150: * to the GUI components.
0151: */
0152: protected void setCssPropertyValues(CssRuleContent cssStyleData) {
0153: removeCssPropertyChangeListener();
0154:
0155: String fontFamily = cssStyleData
0156: .getProperty(CssProperties.FONT_FAMILY);
0157: if (fontFamily != null) {
0158: // This is a work around. Since batik parser puts the quotes around
0159: // fonts with out spaces, remove the quotes from those fonts before
0160: // adding it to the list, else the font set will appear doubly - one
0161: // with quotes and one with out quotes.
0162: StringBuffer fontSetBuf = new StringBuffer();
0163: StringTokenizer st = new StringTokenizer(fontFamily.trim(),
0164: ",");
0165: while (st.hasMoreTokens()) {
0166: String fontName = st.nextToken();
0167: if (new StringTokenizer(fontName.trim()).countTokens() == 1) {
0168: fontName = fontName.replaceAll("'", "");
0169: }
0170: fontSetBuf.append(fontName);
0171: if (st.hasMoreTokens())
0172: fontSetBuf.append(",");
0173: }
0174:
0175: if (!fontFamilies.contains(fontSetBuf.toString())) {
0176: // Work around to avoid adding the fonts to the list
0177: // when user edit the font family in the editor
0178: if (temporaryFontSet != null) {
0179: fontFamilies.removeElement(temporaryFontSet);
0180: }
0181: fontFamilies.add(1, fontSetBuf.toString());
0182: temporaryFontSet = fontSetBuf.toString();
0183: }
0184: fontFaceList.setSelectedIndex(fontFamilies
0185: .indexOf(fontSetBuf.toString()));
0186: } else {
0187: fontFaceList.setSelectedIndex(0);
0188: }
0189:
0190: String fontSizeStr = cssStyleData
0191: .getProperty(CssProperties.FONT_SIZE);
0192: if (fontSizeStr != null) {
0193: // First check if absolute relative (large largere etc) font-size identifiers
0194: if (fontSizes.contains(fontSizeStr)) {
0195: fontSizeList.setSelectedIndex(fontSizes
0196: .indexOf(fontSizeStr));
0197: } else {
0198: // Try splitiing in to numerical font size and unit
0199: FontModel.FontSize fontSize = fontModel
0200: .getFontSize(fontSizeStr);
0201: if (fontSize.getValue() != null) {
0202: if (fontSizes.contains(fontSize.getValue())) {
0203: fontSizeList.setSelectedIndex(fontSizes
0204: .indexOf(fontSize.getValue()));
0205: } else {
0206: fontSizeField.setText(fontSize.getValue());
0207: }
0208: } else {
0209: fontSizeList.setSelectedIndex(0);
0210: }
0211: if (fontSizeUnits.getIndexOf(fontSize.getUnit()) != -1) {
0212: fontSizeUnitCombo.setSelectedIndex(fontSizeUnits
0213: .getIndexOf(fontSize.getUnit()));
0214: }
0215: }
0216: } else {
0217: fontSizeList.setSelectedIndex(0);
0218: }
0219:
0220: String fontStyle = cssStyleData
0221: .getProperty(CssProperties.FONT_STYLE);
0222: if (fontStyle != null) {
0223: if (fontStyles.getIndexOf(fontStyle) != -1) {
0224: fontStyleComboBox.setSelectedIndex(fontStyles
0225: .getIndexOf(fontStyle));
0226: } else {
0227: fontStyleComboBox.setSelectedIndex(0);
0228: }
0229: } else {
0230: fontStyleComboBox.setSelectedIndex(0);
0231: }
0232:
0233: String fontWeight = cssStyleData
0234: .getProperty(CssProperties.FONT_WEIGHT);
0235: if (fontWeight != null) {
0236: if (fontWeights.getIndexOf(fontWeight) != -1) {
0237: fontWeightComboBox.setSelectedIndex(fontWeights
0238: .getIndexOf(fontWeight));
0239: } else {
0240: fontWeightComboBox.setSelectedIndex(0);
0241: }
0242: } else {
0243: fontWeightComboBox.setSelectedIndex(0);
0244: }
0245:
0246: String fontVariant = cssStyleData
0247: .getProperty(CssProperties.FONT_VARIANT);
0248: if (fontVariant != null) {
0249: if (fontVariants.getIndexOf(fontVariant) != -1) {
0250: fontVariantComboBox.setSelectedIndex(fontVariants
0251: .getIndexOf(fontVariant));
0252: } else {
0253: fontVariantComboBox.setSelectedIndex(0);
0254: }
0255: } else {
0256: fontVariantComboBox.setSelectedIndex(0);
0257: }
0258:
0259: // Set the Text Decoration the GUI
0260: String textDecoration = cssStyleData
0261: .getProperty(CssProperties.TEXT_DECORATION);
0262: noDecorationCheckbox.setSelected(false);
0263: underlineCheckbox.setSelected(false);
0264: overlineCheckbox.setSelected(false);
0265: strikethroughCheckbox.setSelected(false);
0266: if (textDecoration != null) {
0267: textDecorationData.setDecoration(textDecoration);
0268: if (textDecorationData.noDecorationEnabled()) {
0269: noDecorationCheckbox.setSelected(true);
0270: } else {
0271: underlineCheckbox.setSelected(textDecorationData
0272: .underlineEnabled());
0273: overlineCheckbox.setSelected(textDecorationData
0274: .overlineEnabled());
0275: strikethroughCheckbox.setSelected(textDecorationData
0276: .lineThroughEnabled());
0277: }
0278: }
0279:
0280: // Set the Bckground Color the GUI
0281: String textColor = cssStyleData
0282: .getProperty(CssProperties.COLOR);
0283: if (textColor != null) {
0284: colorField.setColorString(textColor);
0285: } else {
0286: colorField.setColorString(CssRuleContent.NOT_SET);
0287: }
0288:
0289: setCssPropertyChangeListener(cssStyleData);
0290: }
0291:
0292: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
0293: private void initComponents() {
0294: java.awt.GridBagConstraints gridBagConstraints;
0295:
0296: mainPanel = new javax.swing.JPanel();
0297: fontFamilyPanel = new javax.swing.JPanel();
0298: fontFaceScroll = new javax.swing.JScrollPane();
0299: fontFaceList = new javax.swing.JList();
0300: fontChosenField = new javax.swing.JTextField();
0301: fontFamilyButton = new javax.swing.JButton();
0302: fontSizePanel = new javax.swing.JPanel();
0303: fontSizeField = new javax.swing.JTextField();
0304: fontSizeUnitCombo = new javax.swing.JComboBox();
0305: fontSizeScroll = new javax.swing.JScrollPane();
0306: fontSizeList = new javax.swing.JList();
0307: styleMainPanel = new javax.swing.JPanel();
0308: decorationPanel = new javax.swing.JPanel();
0309: underlineCheckbox = new javax.swing.JCheckBox();
0310: strikethroughCheckbox = new javax.swing.JCheckBox();
0311: overlineCheckbox = new javax.swing.JCheckBox();
0312: noDecorationCheckbox = new javax.swing.JCheckBox();
0313: styleLabel = new javax.swing.JLabel();
0314: fontStyleComboBox = new javax.swing.JComboBox();
0315: weightLabel = new javax.swing.JLabel();
0316: fontWeightComboBox = new javax.swing.JComboBox();
0317: variantLabel = new javax.swing.JLabel();
0318: fontVariantComboBox = new javax.swing.JComboBox();
0319: colorLabel = new javax.swing.JLabel();
0320: colorSelectionPanel = new javax.swing.JPanel();
0321:
0322: setLayout(new java.awt.BorderLayout());
0323:
0324: mainPanel.setLayout(new java.awt.BorderLayout());
0325:
0326: fontFamilyPanel.setBorder(javax.swing.BorderFactory
0327: .createEmptyBorder(5, 5, 5, 5));
0328: fontFamilyPanel.setLayout(new java.awt.GridBagLayout());
0329:
0330: fontFaceList
0331: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
0332: fontFaceList.setVisibleRowCount(5);
0333: fontFaceList
0334: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
0335: public void valueChanged(
0336: javax.swing.event.ListSelectionEvent evt) {
0337: fontFaceListValueChanged(evt);
0338: }
0339: });
0340: fontFaceScroll.setViewportView(fontFaceList);
0341: fontFaceList.getAccessibleContext().setAccessibleName(null);
0342: fontFaceList.getAccessibleContext().setAccessibleDescription(
0343: null);
0344:
0345: gridBagConstraints = new java.awt.GridBagConstraints();
0346: gridBagConstraints.gridx = 0;
0347: gridBagConstraints.gridy = 2;
0348: gridBagConstraints.gridwidth = 2;
0349: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0350: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
0351: gridBagConstraints.weightx = 1.0;
0352: gridBagConstraints.weighty = 1.0;
0353: fontFamilyPanel.add(fontFaceScroll, gridBagConstraints);
0354:
0355: fontChosenField.setEditable(false);
0356: fontChosenField.setMargin(new java.awt.Insets(1, 2, 2, 4));
0357: gridBagConstraints = new java.awt.GridBagConstraints();
0358: gridBagConstraints.gridx = 0;
0359: gridBagConstraints.gridy = 1;
0360: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0361: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0362: gridBagConstraints.weightx = 1.0;
0363: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
0364: fontFamilyPanel.add(fontChosenField, gridBagConstraints);
0365: fontChosenField.getAccessibleContext().setAccessibleName(null);
0366: fontChosenField.getAccessibleContext()
0367: .setAccessibleDescription(null);
0368:
0369: fontFamilyButton.setMnemonic(java.util.ResourceBundle
0370: .getBundle("org/netbeans/modules/css/visual/ui/Bundle")
0371: .getString("MNE_EDIT").charAt(0));
0372: fontFamilyButton.setText(org.openide.util.NbBundle.getMessage(
0373: FontStyleEditor.class, "EDIT")); // NOI18N
0374: fontFamilyButton.setMargin(new java.awt.Insets(4, 4, 4, 4));
0375: fontFamilyButton
0376: .addActionListener(new java.awt.event.ActionListener() {
0377: public void actionPerformed(
0378: java.awt.event.ActionEvent evt) {
0379: fontFamilyButtonActionPerformed(evt);
0380: }
0381: });
0382: gridBagConstraints = new java.awt.GridBagConstraints();
0383: gridBagConstraints.gridx = 1;
0384: gridBagConstraints.gridy = 1;
0385: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0386: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0387: gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
0388: fontFamilyPanel.add(fontFamilyButton, gridBagConstraints);
0389: fontFamilyButton.getAccessibleContext()
0390: .setAccessibleDescription(null);
0391:
0392: mainPanel.add(fontFamilyPanel, java.awt.BorderLayout.CENTER);
0393:
0394: fontSizePanel.setBorder(javax.swing.BorderFactory
0395: .createEmptyBorder(5, 5, 5, 5));
0396: fontSizePanel.setLayout(new java.awt.GridBagLayout());
0397:
0398: fontSizeField
0399: .setHorizontalAlignment(javax.swing.JTextField.LEFT);
0400: fontSizeField
0401: .addActionListener(new java.awt.event.ActionListener() {
0402: public void actionPerformed(
0403: java.awt.event.ActionEvent evt) {
0404: fontSizeFieldActionPerformed(evt);
0405: }
0406: });
0407: fontSizeField
0408: .addFocusListener(new java.awt.event.FocusAdapter() {
0409: public void focusLost(java.awt.event.FocusEvent evt) {
0410: fontSizeFieldFocusLost(evt);
0411: }
0412: });
0413: fontSizeField.addKeyListener(new java.awt.event.KeyAdapter() {
0414: public void keyTyped(java.awt.event.KeyEvent evt) {
0415: fontSizeFieldKeyTyped(evt);
0416: }
0417: });
0418: gridBagConstraints = new java.awt.GridBagConstraints();
0419: gridBagConstraints.gridx = 0;
0420: gridBagConstraints.gridy = 1;
0421: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0422: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0423: gridBagConstraints.weightx = 0.5;
0424: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
0425: fontSizePanel.add(fontSizeField, gridBagConstraints);
0426: fontSizeField.getAccessibleContext().setAccessibleName(null);
0427: fontSizeField.getAccessibleContext().setAccessibleDescription(
0428: null);
0429:
0430: fontSizeUnitCombo
0431: .addItemListener(new java.awt.event.ItemListener() {
0432: public void itemStateChanged(
0433: java.awt.event.ItemEvent evt) {
0434: fontSizeUnitComboItemStateChanged(evt);
0435: }
0436: });
0437: gridBagConstraints = new java.awt.GridBagConstraints();
0438: gridBagConstraints.gridx = 1;
0439: gridBagConstraints.gridy = 1;
0440: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
0441: gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
0442: fontSizePanel.add(fontSizeUnitCombo, gridBagConstraints);
0443: fontSizeUnitCombo.getAccessibleContext()
0444: .setAccessibleName(null);
0445: fontSizeUnitCombo.getAccessibleContext()
0446: .setAccessibleDescription(null);
0447:
0448: fontSizeList
0449: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
0450: fontSizeList.setVisibleRowCount(5);
0451: fontSizeList
0452: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
0453: public void valueChanged(
0454: javax.swing.event.ListSelectionEvent evt) {
0455: fontSizeListValueChanged(evt);
0456: }
0457: });
0458: fontSizeScroll.setViewportView(fontSizeList);
0459: fontSizeList.getAccessibleContext().setAccessibleName(null);
0460: fontSizeList.getAccessibleContext().setAccessibleDescription(
0461: null);
0462:
0463: gridBagConstraints = new java.awt.GridBagConstraints();
0464: gridBagConstraints.gridx = 0;
0465: gridBagConstraints.gridy = 2;
0466: gridBagConstraints.gridwidth = 2;
0467: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0468: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
0469: gridBagConstraints.weighty = 1.0;
0470: fontSizePanel.add(fontSizeScroll, gridBagConstraints);
0471:
0472: mainPanel.add(fontSizePanel, java.awt.BorderLayout.EAST);
0473:
0474: styleMainPanel.setLayout(new java.awt.BorderLayout(20, 0));
0475:
0476: decorationPanel.setBorder(javax.swing.BorderFactory
0477: .createEmptyBorder(5, 5, 5, 5));
0478:
0479: underlineCheckbox.setMnemonic(java.util.ResourceBundle
0480: .getBundle("org/netbeans/modules/css/visual/ui/Bundle")
0481: .getString("MNE_FONT_UNDERLINE").charAt(0));
0482: underlineCheckbox.setText(org.openide.util.NbBundle.getMessage(
0483: FontStyleEditor.class, "FONT_UNDERLINE")); // NOI18N
0484: underlineCheckbox.setMargin(new java.awt.Insets(0, 2, 0, 2));
0485: underlineCheckbox
0486: .addItemListener(new java.awt.event.ItemListener() {
0487: public void itemStateChanged(
0488: java.awt.event.ItemEvent evt) {
0489: underlineCheckboxItemStateChanged(evt);
0490: }
0491: });
0492:
0493: strikethroughCheckbox.setMnemonic(java.util.ResourceBundle
0494: .getBundle("org/netbeans/modules/css/visual/ui/Bundle")
0495: .getString("MNE_FONT_STRIKETHROUGH").charAt(0));
0496: strikethroughCheckbox
0497: .setText(org.openide.util.NbBundle.getMessage(
0498: FontStyleEditor.class, "FONT_STRIKETHROUGH")); // NOI18N
0499: strikethroughCheckbox
0500: .setMargin(new java.awt.Insets(0, 2, 0, 2));
0501: strikethroughCheckbox
0502: .addItemListener(new java.awt.event.ItemListener() {
0503: public void itemStateChanged(
0504: java.awt.event.ItemEvent evt) {
0505: strikethroughCheckboxItemStateChanged(evt);
0506: }
0507: });
0508:
0509: overlineCheckbox.setMnemonic(java.util.ResourceBundle
0510: .getBundle("org/netbeans/modules/css/visual/ui/Bundle")
0511: .getString("MNE_FONT_OVERLINE").charAt(0));
0512: overlineCheckbox.setText(org.openide.util.NbBundle.getMessage(
0513: FontStyleEditor.class, "FONT_OVERLINE")); // NOI18N
0514: overlineCheckbox.setMargin(new java.awt.Insets(0, 2, 0, 2));
0515: overlineCheckbox
0516: .addItemListener(new java.awt.event.ItemListener() {
0517: public void itemStateChanged(
0518: java.awt.event.ItemEvent evt) {
0519: overlineCheckboxItemStateChanged(evt);
0520: }
0521: });
0522:
0523: noDecorationCheckbox.setMnemonic(java.util.ResourceBundle
0524: .getBundle("org/netbeans/modules/css/visual/ui/Bundle")
0525: .getString("MNE_NO_DECORATION_1").charAt(0));
0526: noDecorationCheckbox.setText(org.openide.util.NbBundle
0527: .getMessage(FontStyleEditor.class, "NO_DECORATION_1")); // NOI18N
0528: noDecorationCheckbox
0529: .addItemListener(new java.awt.event.ItemListener() {
0530: public void itemStateChanged(
0531: java.awt.event.ItemEvent evt) {
0532: noDecorationCheckboxItemStateChanged(evt);
0533: }
0534: });
0535:
0536: styleLabel.setDisplayedMnemonic(java.util.ResourceBundle
0537: .getBundle("org/netbeans/modules/css/visual/ui/Bundle")
0538: .getString("MNE_FONT_STYLE").charAt(0));
0539: styleLabel.setLabelFor(fontStyleComboBox);
0540: styleLabel.setText(org.openide.util.NbBundle.getMessage(
0541: FontStyleEditor.class, "FONT_STYLE")); // NOI18N
0542:
0543: fontStyleComboBox
0544: .setMinimumSize(new java.awt.Dimension(150, 20));
0545: fontStyleComboBox
0546: .addItemListener(new java.awt.event.ItemListener() {
0547: public void itemStateChanged(
0548: java.awt.event.ItemEvent evt) {
0549: fontStyleComboBoxItemStateChanged(evt);
0550: }
0551: });
0552: fontStyleComboBox
0553: .addFocusListener(new java.awt.event.FocusAdapter() {
0554: public void focusLost(java.awt.event.FocusEvent evt) {
0555: fontStyleComboBoxFocusLost(evt);
0556: }
0557: });
0558:
0559: weightLabel.setDisplayedMnemonic(java.util.ResourceBundle
0560: .getBundle("org/netbeans/modules/css/visual/ui/Bundle")
0561: .getString("MNE_FONT_WEIGHT").charAt(0));
0562: weightLabel.setLabelFor(fontWeightComboBox);
0563: weightLabel.setText(org.openide.util.NbBundle.getMessage(
0564: FontStyleEditor.class, "FONT_WEIGHT")); // NOI18N
0565:
0566: fontWeightComboBox.setMinimumSize(new java.awt.Dimension(150,
0567: 20));
0568: fontWeightComboBox
0569: .addItemListener(new java.awt.event.ItemListener() {
0570: public void itemStateChanged(
0571: java.awt.event.ItemEvent evt) {
0572: fontWeightComboBoxItemStateChanged(evt);
0573: }
0574: });
0575: fontWeightComboBox
0576: .addFocusListener(new java.awt.event.FocusAdapter() {
0577: public void focusLost(java.awt.event.FocusEvent evt) {
0578: fontWeightComboBoxFocusLost(evt);
0579: }
0580: });
0581:
0582: variantLabel.setDisplayedMnemonic(java.util.ResourceBundle
0583: .getBundle("org/netbeans/modules/css/visual/ui/Bundle")
0584: .getString("MNE_FONT_VARIANT").charAt(0));
0585: variantLabel.setLabelFor(fontVariantComboBox);
0586: variantLabel.setText(org.openide.util.NbBundle.getMessage(
0587: FontStyleEditor.class, "FONT_VARIANT")); // NOI18N
0588:
0589: fontVariantComboBox.setMinimumSize(new java.awt.Dimension(150,
0590: 20));
0591: fontVariantComboBox
0592: .addItemListener(new java.awt.event.ItemListener() {
0593: public void itemStateChanged(
0594: java.awt.event.ItemEvent evt) {
0595: fontVariantComboBoxItemStateChanged(evt);
0596: }
0597: });
0598: fontVariantComboBox
0599: .addFocusListener(new java.awt.event.FocusAdapter() {
0600: public void focusLost(java.awt.event.FocusEvent evt) {
0601: fontVariantComboBoxFocusLost(evt);
0602: }
0603: });
0604:
0605: colorLabel.setDisplayedMnemonic(java.util.ResourceBundle
0606: .getBundle("org/netbeans/modules/css/visual/ui/Bundle")
0607: .getString("MNE_FONT_COLOR").charAt(0));
0608: colorLabel.setLabelFor(colorSelectionPanel);
0609: colorLabel.setText(org.openide.util.NbBundle.getMessage(
0610: FontStyleEditor.class, "FONT_COLOR")); // NOI18N
0611:
0612: colorSelectionPanel.setLayout(new java.awt.BorderLayout());
0613:
0614: org.jdesktop.layout.GroupLayout decorationPanelLayout = new org.jdesktop.layout.GroupLayout(
0615: decorationPanel);
0616: decorationPanel.setLayout(decorationPanelLayout);
0617: decorationPanelLayout
0618: .setHorizontalGroup(decorationPanelLayout
0619: .createParallelGroup(
0620: org.jdesktop.layout.GroupLayout.LEADING)
0621: .add(
0622: decorationPanelLayout
0623: .createSequentialGroup()
0624: .add(
0625: decorationPanelLayout
0626: .createParallelGroup(
0627: org.jdesktop.layout.GroupLayout.LEADING)
0628: .add(
0629: decorationPanelLayout
0630: .createSequentialGroup()
0631: .add(
0632: decorationPanelLayout
0633: .createParallelGroup(
0634: org.jdesktop.layout.GroupLayout.LEADING)
0635: .add(
0636: styleLabel,
0637: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0638: 47,
0639: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0640: .add(
0641: fontStyleComboBox,
0642: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0643: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0644: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0645: .addPreferredGap(
0646: org.jdesktop.layout.LayoutStyle.RELATED)
0647: .add(
0648: decorationPanelLayout
0649: .createParallelGroup(
0650: org.jdesktop.layout.GroupLayout.LEADING)
0651: .add(
0652: fontWeightComboBox,
0653: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0654: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0655: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0656: .add(
0657: weightLabel))
0658: .addPreferredGap(
0659: org.jdesktop.layout.LayoutStyle.RELATED)
0660: .add(
0661: decorationPanelLayout
0662: .createParallelGroup(
0663: org.jdesktop.layout.GroupLayout.LEADING)
0664: .add(
0665: variantLabel)
0666: .add(
0667: fontVariantComboBox,
0668: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0669: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0670: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0671: .addPreferredGap(
0672: org.jdesktop.layout.LayoutStyle.RELATED)
0673: .add(
0674: decorationPanelLayout
0675: .createParallelGroup(
0676: org.jdesktop.layout.GroupLayout.LEADING)
0677: .add(
0678: colorSelectionPanel,
0679: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0680: 137,
0681: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0682: .add(
0683: colorLabel)))
0684: .add(
0685: decorationPanelLayout
0686: .createSequentialGroup()
0687: .add(
0688: underlineCheckbox)
0689: .addPreferredGap(
0690: org.jdesktop.layout.LayoutStyle.RELATED)
0691: .add(
0692: overlineCheckbox)
0693: .addPreferredGap(
0694: org.jdesktop.layout.LayoutStyle.RELATED)
0695: .add(
0696: strikethroughCheckbox)
0697: .addPreferredGap(
0698: org.jdesktop.layout.LayoutStyle.RELATED)
0699: .add(
0700: noDecorationCheckbox)))
0701: .addContainerGap(57,
0702: Short.MAX_VALUE)));
0703: decorationPanelLayout
0704: .setVerticalGroup(decorationPanelLayout
0705: .createParallelGroup(
0706: org.jdesktop.layout.GroupLayout.LEADING)
0707: .add(
0708: decorationPanelLayout
0709: .createSequentialGroup()
0710: .add(
0711: decorationPanelLayout
0712: .createParallelGroup(
0713: org.jdesktop.layout.GroupLayout.BASELINE)
0714: .add(styleLabel)
0715: .add(
0716: weightLabel)
0717: .add(
0718: variantLabel)
0719: .add(colorLabel))
0720: .add(
0721: decorationPanelLayout
0722: .createParallelGroup(
0723: org.jdesktop.layout.GroupLayout.LEADING)
0724: .add(
0725: decorationPanelLayout
0726: .createSequentialGroup()
0727: .add(
0728: 6,
0729: 6,
0730: 6)
0731: .add(
0732: decorationPanelLayout
0733: .createParallelGroup(
0734: org.jdesktop.layout.GroupLayout.BASELINE)
0735: .add(
0736: fontWeightComboBox,
0737: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0738: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0739: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0740: .add(
0741: fontVariantComboBox,
0742: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0743: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0744: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0745: .add(
0746: fontStyleComboBox,
0747: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0748: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0749: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
0750: .add(
0751: decorationPanelLayout
0752: .createSequentialGroup()
0753: .addPreferredGap(
0754: org.jdesktop.layout.LayoutStyle.RELATED)
0755: .add(
0756: colorSelectionPanel,
0757: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0758: 23,
0759: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
0760: .addPreferredGap(
0761: org.jdesktop.layout.LayoutStyle.RELATED)
0762: .add(
0763: decorationPanelLayout
0764: .createParallelGroup(
0765: org.jdesktop.layout.GroupLayout.BASELINE)
0766: .add(
0767: underlineCheckbox)
0768: .add(
0769: overlineCheckbox)
0770: .add(
0771: noDecorationCheckbox)
0772: .add(
0773: strikethroughCheckbox))));
0774:
0775: underlineCheckbox.getAccessibleContext()
0776: .setAccessibleDescription(null);
0777: strikethroughCheckbox.getAccessibleContext()
0778: .setAccessibleDescription(null);
0779: overlineCheckbox.getAccessibleContext()
0780: .setAccessibleDescription(null);
0781: noDecorationCheckbox
0782: .getAccessibleContext()
0783: .setAccessibleDescription(
0784: org.openide.util.NbBundle
0785: .getMessage(FontStyleEditor.class,
0786: "FontNoDecorationAccessibleDescription")); // NOI18N
0787: fontStyleComboBox.getAccessibleContext()
0788: .setAccessibleName(null);
0789: fontStyleComboBox.getAccessibleContext()
0790: .setAccessibleDescription(null);
0791: fontWeightComboBox.getAccessibleContext().setAccessibleName(
0792: null);
0793: fontWeightComboBox.getAccessibleContext()
0794: .setAccessibleDescription(null);
0795: variantLabel.getAccessibleContext().setAccessibleDescription(
0796: null);
0797: fontVariantComboBox.getAccessibleContext().setAccessibleName(
0798: null);
0799: fontVariantComboBox.getAccessibleContext()
0800: .setAccessibleDescription(null);
0801:
0802: styleMainPanel.add(decorationPanel,
0803: java.awt.BorderLayout.CENTER);
0804:
0805: mainPanel.add(styleMainPanel, java.awt.BorderLayout.SOUTH);
0806:
0807: add(mainPanel, java.awt.BorderLayout.NORTH);
0808: }// </editor-fold>//GEN-END:initComponents
0809:
0810: private void noDecorationCheckboxItemStateChanged(
0811: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_noDecorationCheckboxItemStateChanged
0812: textDecorationData
0813: .enableNoDecoration((evt.getStateChange() == evt.SELECTED));
0814: if (evt.getStateChange() == evt.SELECTED) {
0815: strikethroughCheckbox.setSelected(false);
0816: overlineCheckbox.setSelected(false);
0817: underlineCheckbox.setSelected(false);
0818: strikethroughCheckbox.setEnabled(false);
0819: overlineCheckbox.setEnabled(false);
0820: underlineCheckbox.setEnabled(false);
0821: } else {
0822: strikethroughCheckbox.setEnabled(true);
0823: overlineCheckbox.setEnabled(true);
0824: underlineCheckbox.setEnabled(true);
0825: }
0826: setTextDecoration();
0827: }//GEN-LAST:event_noDecorationCheckboxItemStateChanged
0828:
0829: private void strikethroughCheckboxItemStateChanged(
0830: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_strikethroughCheckboxItemStateChanged
0831: if (textDecorationData
0832: .enableLineThrough((evt.getStateChange() == evt.SELECTED))) {
0833: setTextDecoration();
0834: }
0835: }//GEN-LAST:event_strikethroughCheckboxItemStateChanged
0836:
0837: private void overlineCheckboxItemStateChanged(
0838: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_overlineCheckboxItemStateChanged
0839: if (textDecorationData
0840: .enableOverline((evt.getStateChange() == evt.SELECTED))) {
0841: setTextDecoration();
0842: }
0843: }//GEN-LAST:event_overlineCheckboxItemStateChanged
0844:
0845: private void underlineCheckboxItemStateChanged(
0846: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_underlineCheckboxItemStateChanged
0847: if (textDecorationData
0848: .enableUnderline((evt.getStateChange() == evt.SELECTED))) {
0849: setTextDecoration();
0850: }
0851: }//GEN-LAST:event_underlineCheckboxItemStateChanged
0852:
0853: private void fontVariantComboBoxItemStateChanged(
0854: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fontVariantComboBoxItemStateChanged
0855: if (evt.getStateChange() != evt.DESELECTED) {
0856: setFontVariant();
0857: }
0858: }//GEN-LAST:event_fontVariantComboBoxItemStateChanged
0859:
0860: private void fontVariantComboBoxFocusLost(
0861: java.awt.event.FocusEvent evt) {//GEN-FIRST:event_fontVariantComboBoxFocusLost
0862: setFontVariant();
0863: }//GEN-LAST:event_fontVariantComboBoxFocusLost
0864:
0865: private void fontWeightComboBoxItemStateChanged(
0866: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fontWeightComboBoxItemStateChanged
0867: if (evt.getStateChange() != evt.DESELECTED) {
0868: setFontWeight();
0869: }
0870: }//GEN-LAST:event_fontWeightComboBoxItemStateChanged
0871:
0872: private void fontWeightComboBoxFocusLost(
0873: java.awt.event.FocusEvent evt) {//GEN-FIRST:event_fontWeightComboBoxFocusLost
0874: setFontWeight();
0875: }//GEN-LAST:event_fontWeightComboBoxFocusLost
0876:
0877: private void fontStyleComboBoxFocusLost(
0878: java.awt.event.FocusEvent evt) {//GEN-FIRST:event_fontStyleComboBoxFocusLost
0879: setFontStyle();
0880: }//GEN-LAST:event_fontStyleComboBoxFocusLost
0881:
0882: private void fontStyleComboBoxItemStateChanged(
0883: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fontStyleComboBoxItemStateChanged
0884: if (evt.getStateChange() != evt.DESELECTED) {
0885: setFontStyle();
0886: }
0887: }//GEN-LAST:event_fontStyleComboBoxItemStateChanged
0888:
0889: private void fontSizeUnitComboItemStateChanged(
0890: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fontSizeUnitComboItemStateChanged
0891: if (evt.getStateChange() != evt.DESELECTED) {
0892: setFontSize();
0893: }
0894: }//GEN-LAST:event_fontSizeUnitComboItemStateChanged
0895:
0896: private void fontSizeFieldActionPerformed(
0897: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontSizeFieldActionPerformed
0898: setFontSize();
0899: }//GEN-LAST:event_fontSizeFieldActionPerformed
0900:
0901: private void fontSizeFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_fontSizeFieldFocusLost
0902: setFontSize();
0903: }//GEN-LAST:event_fontSizeFieldFocusLost
0904:
0905: private void fontSizeFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_fontSizeFieldKeyTyped
0906: SwingUtilities.invokeLater(new Runnable() {
0907: public void run() {
0908: enableFontSizeUnitCombo(Utils.isInteger(fontSizeField
0909: .getText()));
0910: }
0911: });
0912: }//GEN-LAST:event_fontSizeFieldKeyTyped
0913:
0914: private void fontSizeListValueChanged(
0915: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_fontSizeListValueChanged
0916: if (evt.getValueIsAdjusting())
0917: return;
0918: String selectedFontSize = (String) fontSizeList
0919: .getSelectedValue();
0920: fontSizeField.setText(selectedFontSize);
0921: enableFontSizeUnitCombo(Utils.isInteger(selectedFontSize));
0922: setFontSize();
0923: }//GEN-LAST:event_fontSizeListValueChanged
0924:
0925: private void enableFontSizeUnitCombo(final boolean enable) {
0926: SwingUtilities.invokeLater(new Runnable() {
0927: public void run() {
0928: fontSizeUnitCombo.setEnabled(enable);
0929: }
0930: });
0931: }
0932:
0933: private void fontFaceListValueChanged(
0934: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_fontFaceListValueChanged
0935: if (evt.getValueIsAdjusting())
0936: return;
0937: if (fontFaceList.getSelectedValue() != null) {
0938: fontChosenField.setText(fontFaceList.getSelectedValue()
0939: .toString());
0940: setFontFamily();
0941: }
0942: }//GEN-LAST:event_fontFaceListValueChanged
0943:
0944: private void fontFamilyButtonActionPerformed(
0945: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontFamilyButtonActionPerformed
0946: FontFamilyEditorDialog fontFamilyEditor = new FontFamilyEditorDialog(
0947: fontFamilies, fontFaceList.getSelectedIndex());
0948: fontFamilyEditor.showDialog();
0949: fontFaceList.setSelectedIndex(fontFamilyEditor
0950: .getSelectedIndex());
0951: fontChosenField.setText(fontFaceList.getSelectedValue()
0952: .toString());
0953: setFontFamily();
0954: }//GEN-LAST:event_fontFamilyButtonActionPerformed
0955:
0956: private void setFontFamily() {
0957: PropertyData fontFamilyData = new PropertyData();
0958: fontFamilyData.setValue(fontChosenField.getText());
0959: String newValue = fontFamilyData.toString();
0960: cssPropertyChangeSupport().firePropertyChange(
0961: CssProperties.FONT_FAMILY, currentFontFamily, newValue);
0962: currentFontFamily = newValue;
0963: }
0964:
0965: private void setFontSize() {
0966: //XXX Do we need to put some constraints?
0967: PropertyWithUnitData fontSizeData = new PropertyWithUnitData();
0968: fontSizeData.setUnit(fontSizeUnitCombo.getSelectedItem()
0969: .toString());
0970: fontSizeData.setValue(fontSizeField.getText());
0971: String newValue = fontSizeData.toString();
0972: cssPropertyChangeSupport().firePropertyChange(
0973: CssProperties.FONT_SIZE, currentFontSize, newValue);
0974: currentFontSize = newValue;
0975: }
0976:
0977: private void setFontStyle() {
0978: PropertyData fontStyleData = new PropertyData();
0979: fontStyleData.setValue(fontStyleComboBox.getSelectedItem()
0980: .toString());
0981: String newValue = fontStyleData.toString();
0982: cssPropertyChangeSupport().firePropertyChange(
0983: CssProperties.FONT_STYLE, currentFontStyle, newValue);
0984: currentFontStyle = newValue;
0985: }
0986:
0987: private void setFontWeight() {
0988: PropertyData fontWeightData = new PropertyData();
0989: fontWeightData.setValue(fontWeightComboBox.getSelectedItem()
0990: .toString());
0991: String newValue = fontWeightData.toString();
0992: cssPropertyChangeSupport().firePropertyChange(
0993: CssProperties.FONT_WEIGHT, currentFontWeight, newValue);
0994: currentFontWeight = newValue;
0995: }
0996:
0997: private void setFontVariant() {
0998: PropertyData fontVariantData = new PropertyData();
0999: fontVariantData.setValue(fontVariantComboBox.getSelectedItem()
1000: .toString());
1001: String newValue = fontVariantData.toString();
1002: cssPropertyChangeSupport().firePropertyChange(
1003: CssProperties.FONT_VARIANT, currentFontVariant,
1004: newValue);
1005: currentFontVariant = newValue;
1006: }
1007:
1008: private void setFontColor() {
1009: PropertyData fontColorData = new PropertyData();
1010: fontColorData.setValue(colorField.getColorString());
1011: String newValue = fontColorData.toString();
1012: cssPropertyChangeSupport().firePropertyChange(
1013: CssProperties.COLOR, currentFontColor, newValue);
1014: currentFontColor = newValue;
1015: }
1016:
1017: private void setTextDecoration() {
1018: String newValue = textDecorationData.toString();
1019: cssPropertyChangeSupport().firePropertyChange(
1020: CssProperties.TEXT_DECORATION, currentFontDecoration,
1021: newValue);
1022: currentFontDecoration = newValue;
1023: }
1024:
1025: // Variables declaration - do not modify//GEN-BEGIN:variables
1026: private javax.swing.JLabel colorLabel;
1027: private javax.swing.JPanel colorSelectionPanel;
1028: private javax.swing.JPanel decorationPanel;
1029: private javax.swing.JTextField fontChosenField;
1030: private javax.swing.JList fontFaceList;
1031: private javax.swing.JScrollPane fontFaceScroll;
1032: private javax.swing.JButton fontFamilyButton;
1033: private javax.swing.JPanel fontFamilyPanel;
1034: private javax.swing.JTextField fontSizeField;
1035: private javax.swing.JList fontSizeList;
1036: private javax.swing.JPanel fontSizePanel;
1037: private javax.swing.JScrollPane fontSizeScroll;
1038: private javax.swing.JComboBox fontSizeUnitCombo;
1039: private javax.swing.JComboBox fontStyleComboBox;
1040: private javax.swing.JComboBox fontVariantComboBox;
1041: private javax.swing.JComboBox fontWeightComboBox;
1042: private javax.swing.JPanel mainPanel;
1043: private javax.swing.JCheckBox noDecorationCheckbox;
1044: private javax.swing.JCheckBox overlineCheckbox;
1045: private javax.swing.JCheckBox strikethroughCheckbox;
1046: private javax.swing.JLabel styleLabel;
1047: private javax.swing.JPanel styleMainPanel;
1048: private javax.swing.JCheckBox underlineCheckbox;
1049: private javax.swing.JLabel variantLabel;
1050: private javax.swing.JLabel weightLabel;
1051: // End of variables declaration//GEN-END:variables
1052: }
|