1 19 20 25 26 package org.netbeans.modules.css.visual.ui; 27 28 import org.netbeans.modules.css.visual.model.CssProperties; 29 import org.netbeans.modules.css.visual.model.CssStyleData; 30 import org.netbeans.modules.css.visual.model.FontModel; 31 import org.netbeans.modules.css.visual.model.PropertyData; 32 import org.netbeans.modules.css.visual.model.PropertyWithUnitData; 33 import org.netbeans.modules.css.visual.model.TextDecorationData; 34 import org.netbeans.modules.css.visual.model.PropertyData; 35 import java.awt.BorderLayout ; 36 import java.awt.Dimension ; 37 import java.awt.FontMetrics ; 38 import java.beans.PropertyChangeEvent ; 39 import java.beans.PropertyChangeListener ; 40 import java.util.StringTokenizer ; 41 import javax.swing.DefaultComboBoxModel ; 42 import javax.swing.DefaultListModel ; 43 import javax.swing.SwingUtilities ; 44 import org.netbeans.modules.css.visual.model.Utils; 45 import org.openide.util.NbBundle; 46 47 52 public class FontStyleEditor extends StyleEditor implements PropertyChangeListener { 53 54 ColorSelectionField colorField = new ColorSelectionField(); 55 TextDecorationData textDecorationData = new TextDecorationData(); 56 57 FontModel fontModel = new FontModel(); 58 DefaultListModel fontFamilies = fontModel.getFontFamilySetList(); 59 60 DefaultListModel fontSizes; 61 DefaultComboBoxModel fontSizeUnits; 62 DefaultComboBoxModel fontStyles; 63 DefaultComboBoxModel fontWeights; 64 DefaultComboBoxModel fontVariants; 65 66 String temporaryFontSet = null; 67 68 69 public FontStyleEditor() { 70 setName("fontStyleEditor"); setDisplayName(NbBundle.getMessage(FontStyleEditor.class, "FONT_EDITOR_DISPNAME")); 72 initComponents(); 73 colorSelectionPanel.add(colorField,BorderLayout.CENTER); 74 colorField.addPropertyChangeListener(this); 75 initialize(); 76 } 77 78 private void initialize(){ 79 fontModel = new FontModel(); 81 fontFamilies = fontModel.getFontFamilySetList(); 82 fontFaceList.setModel(fontFamilies); 83 84 fontSizes= fontModel.getFontSizeList(); 86 fontSizeList.setModel(fontSizes); 87 88 fontSizeUnits= fontModel.getFontSizeUnitList(); 89 fontSizeUnitCombo.setModel(fontSizeUnits); 90 fontSizeUnitCombo.setSelectedItem("px"); 91 92 fontStyles = fontModel.getFontStyleList(); 94 fontStyleComboBox.setModel(fontStyles); 95 96 fontWeights = fontModel.getFontWeightList(); 98 fontWeightComboBox.setModel(fontWeights); 99 100 fontVariants = fontModel.getFontVariantList(); 102 fontVariantComboBox.setModel(fontVariants); 103 104 FontMetrics fontMetrics = fontSizeField.getFontMetrics(fontSizeField.getFont()); 105 int width = fontMetrics.stringWidth((String ) fontSizes.get(0)) + 10; 106 int height = (fontMetrics.getHeight() + 10) > 25 ? fontMetrics.getHeight() + 10 : 25; 107 fontSizeField.setPreferredSize(new Dimension (width, height)); 108 } 109 110 114 protected void setCssPropertyValues(CssStyleData cssStyleData){ 115 removeCssPropertyChangeListener(); 116 117 String fontFamily = cssStyleData.getProperty(CssProperties.FONT_FAMILY); 118 if(fontFamily != null){ 119 StringBuffer fontSetBuf = new StringBuffer (); 124 StringTokenizer st = new StringTokenizer (fontFamily.trim(),","); 125 while(st.hasMoreTokens()){ 126 String fontName = st.nextToken(); 127 if(new StringTokenizer (fontName.trim()).countTokens() == 1){ 128 fontName = fontName.replaceAll("'",""); 129 } 130 fontSetBuf.append(fontName); 131 if(st.hasMoreTokens()) fontSetBuf.append(","); 132 } 133 134 if(!fontFamilies.contains(fontSetBuf.toString())){ 135 if (temporaryFontSet != null){ 138 fontFamilies.removeElement(temporaryFontSet); 139 } 140 fontFamilies.add(1,fontSetBuf.toString()); 141 temporaryFontSet = fontSetBuf.toString(); 142 } 143 fontFaceList.setSelectedIndex(fontFamilies.indexOf(fontSetBuf.toString())); 144 }else{ 145 fontFaceList.setSelectedIndex(0); 146 } 147 148 String fontSizeStr = cssStyleData.getProperty(CssProperties.FONT_SIZE); 149 if(fontSizeStr != null){ 150 if(fontSizes.contains(fontSizeStr)){ 152 fontSizeList.setSelectedIndex(fontSizes.indexOf(fontSizeStr)); 153 }else{ 154 FontModel.FontSize fontSize = fontModel.getFontSize(fontSizeStr); 156 if(fontSize.getValue()!= null){ 157 if(fontSizes.contains(fontSize.getValue())){ 158 fontSizeList.setSelectedIndex(fontSizes.indexOf(fontSize.getValue())); 159 }else{ 160 fontSizeField.setText(fontSize.getValue()); 161 } 162 }else{ 163 fontSizeList.setSelectedIndex(0); 164 } 165 if(fontSizeUnits.getIndexOf(fontSize.getUnit()) != -1){ 166 fontSizeUnitCombo.setSelectedIndex(fontSizeUnits.getIndexOf(fontSize.getUnit())); 167 } 168 } 169 }else{ 170 fontSizeList.setSelectedIndex(0); 171 } 172 173 String fontStyle = cssStyleData.getProperty(CssProperties.FONT_STYLE); 174 if(fontStyle != null){ 175 if(fontStyles.getIndexOf(fontStyle) != -1){ 176 fontStyleComboBox.setSelectedIndex(fontStyles.getIndexOf(fontStyle)); 177 } else{ 178 fontStyleComboBox.setSelectedIndex(0); 179 } 180 }else{ 181 fontStyleComboBox.setSelectedIndex(0); 182 } 183 184 String fontWeight = cssStyleData.getProperty(CssProperties.FONT_WEIGHT); 185 if(fontWeight != null){ 186 if(fontWeights.getIndexOf(fontWeight) != -1){ 187 fontWeightComboBox.setSelectedIndex(fontWeights.getIndexOf(fontWeight)); 188 }else{ 189 fontWeightComboBox.setSelectedIndex(0); 190 } 191 }else{ 192 fontWeightComboBox.setSelectedIndex(0); 193 } 194 195 String fontVariant = cssStyleData.getProperty(CssProperties.FONT_VARIANT); 196 if(fontVariant != null){ 197 if(fontVariants.getIndexOf(fontVariant) != -1){ 198 fontVariantComboBox.setSelectedIndex(fontVariants.getIndexOf(fontVariant)); 199 } else{ 200 fontVariantComboBox.setSelectedIndex(0); 201 } 202 }else{ 203 fontVariantComboBox.setSelectedIndex(0); 204 } 205 206 String textDecoration = cssStyleData.getProperty(CssProperties.TEXT_DECORATION); 208 noDecorationCheckbox.setSelected(false); 209 underlineCheckbox.setSelected(false); 210 overlineCheckbox.setSelected(false); 211 strikethroughCheckbox.setSelected(false); 212 if(textDecoration != null){ 213 textDecorationData.setDecoration(textDecoration); 214 if (textDecorationData.noDecorationEnabled()){ 215 noDecorationCheckbox.setSelected(true); 216 }else{ 217 underlineCheckbox.setSelected(textDecorationData.underlineEnabled()); 218 overlineCheckbox.setSelected(textDecorationData.overlineEnabled()); 219 strikethroughCheckbox.setSelected(textDecorationData.lineThroughEnabled()); 220 } 221 } 222 223 String textColor = cssStyleData.getProperty(CssProperties.COLOR); 225 if(textColor != null){ 226 colorField.setColorString(textColor); 227 }else{ 228 colorField.setColorString(CssStyleData.NOT_SET); 229 } 230 231 setCssPropertyChangeListener(cssStyleData); 232 } 233 234 235 public void propertyChange(PropertyChangeEvent evt) { 236 setFontColor(); 237 } 238 239 private void initComponents() { 241 java.awt.GridBagConstraints gridBagConstraints; 242 243 mainPanel = new javax.swing.JPanel (); 244 fontFamilyPanel = new javax.swing.JPanel (); 245 fontLabel = new javax.swing.JLabel (); 246 fontFaceScroll = new javax.swing.JScrollPane (); 247 fontFaceList = new javax.swing.JList (); 248 fontChosenField = new javax.swing.JTextField (); 249 fontFamilyButton = new javax.swing.JButton (); 250 fontSizePanel = new javax.swing.JPanel (); 251 sizeLabel = new javax.swing.JLabel (); 252 fontSizeField = new javax.swing.JTextField (); 253 fontSizeUnitCombo = new javax.swing.JComboBox (); 254 fontSizeScroll = new javax.swing.JScrollPane (); 255 fontSizeList = new javax.swing.JList (); 256 styleMainPanel = new javax.swing.JPanel (); 257 stylePanel = new javax.swing.JPanel (); 258 styleLabel = new javax.swing.JLabel (); 259 fontStyleComboBox = new javax.swing.JComboBox (); 260 weightLabel = new javax.swing.JLabel (); 261 fontWeightComboBox = new javax.swing.JComboBox (); 262 variantLabel = new javax.swing.JLabel (); 263 fontVariantComboBox = new javax.swing.JComboBox (); 264 colorLabel = new javax.swing.JLabel (); 265 colorSelectionPanel = new javax.swing.JPanel (); 266 decorationPanel = new javax.swing.JPanel (); 267 decorationLabel = new javax.swing.JLabel (); 268 underlineCheckbox = new javax.swing.JCheckBox (); 269 strikethroughCheckbox = new javax.swing.JCheckBox (); 270 overlineCheckbox = new javax.swing.JCheckBox (); 271 noDecorationCheckbox = new javax.swing.JCheckBox (); 272 errorPanel = new javax.swing.JPanel (); 273 errorLabel = new javax.swing.JLabel (); 274 275 setLayout(new java.awt.BorderLayout ()); 276 277 mainPanel.setLayout(new java.awt.BorderLayout ()); 278 279 fontFamilyPanel.setLayout(new java.awt.GridBagLayout ()); 280 281 fontFamilyPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); 282 fontLabel.setLabelFor(fontChosenField); 283 fontLabel.setText(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "Font_Family")); 284 gridBagConstraints = new java.awt.GridBagConstraints (); 285 gridBagConstraints.gridx = 0; 286 gridBagConstraints.gridy = 0; 287 gridBagConstraints.gridwidth = 2; 288 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 289 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 290 gridBagConstraints.weightx = 1.0; 291 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 292 fontFamilyPanel.add(fontLabel, gridBagConstraints); 293 294 fontFaceList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 295 fontFaceList.addListSelectionListener(new javax.swing.event.ListSelectionListener () { 296 public void valueChanged(javax.swing.event.ListSelectionEvent evt) { 297 fontFaceListValueChanged(evt); 298 } 299 }); 300 301 fontFaceScroll.setViewportView(fontFaceList); 302 fontFaceList.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontFamilyList")); 303 fontFaceList.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontFamilyListAccessibleDescription")); 304 305 gridBagConstraints = new java.awt.GridBagConstraints (); 306 gridBagConstraints.gridx = 0; 307 gridBagConstraints.gridy = 2; 308 gridBagConstraints.gridwidth = 2; 309 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 310 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 311 gridBagConstraints.weightx = 1.0; 312 gridBagConstraints.weighty = 1.0; 313 fontFamilyPanel.add(fontFaceScroll, gridBagConstraints); 314 315 fontChosenField.setEditable(false); 316 fontChosenField.setMargin(new java.awt.Insets (1, 2, 2, 4)); 317 gridBagConstraints = new java.awt.GridBagConstraints (); 318 gridBagConstraints.gridx = 0; 319 gridBagConstraints.gridy = 1; 320 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 321 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 322 gridBagConstraints.weightx = 1.0; 323 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 324 fontFamilyPanel.add(fontChosenField, gridBagConstraints); 325 fontChosenField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "chosenFontsAccessibleName")); 326 fontChosenField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "ChosenFontAccessibleDescription")); 327 328 fontFamilyButton.setMnemonic(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FONT_FAMILY_EDIT_BTN_MNEMONIC").charAt(0)); 329 fontFamilyButton.setText(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "EDIT")); 330 fontFamilyButton.setMargin(new java.awt.Insets (4, 4, 4, 4)); 331 fontFamilyButton.addActionListener(new java.awt.event.ActionListener () { 332 public void actionPerformed(java.awt.event.ActionEvent evt) { 333 fontFamilyButtonActionPerformed(evt); 334 } 335 }); 336 337 gridBagConstraints = new java.awt.GridBagConstraints (); 338 gridBagConstraints.gridx = 1; 339 gridBagConstraints.gridy = 1; 340 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 341 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 342 gridBagConstraints.insets = new java.awt.Insets (0, 5, 5, 0); 343 fontFamilyPanel.add(fontFamilyButton, gridBagConstraints); 344 fontFamilyButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "EditChosenFontsAccessibleDescription")); 345 346 mainPanel.add(fontFamilyPanel, java.awt.BorderLayout.CENTER); 347 348 fontSizePanel.setLayout(new java.awt.GridBagLayout ()); 349 350 fontSizePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); 351 sizeLabel.setLabelFor(fontSizeField); 352 sizeLabel.setText(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FONT_SIZE")); 353 gridBagConstraints = new java.awt.GridBagConstraints (); 354 gridBagConstraints.gridx = 0; 355 gridBagConstraints.gridy = 0; 356 gridBagConstraints.gridwidth = 2; 357 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 358 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 359 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 360 fontSizePanel.add(sizeLabel, gridBagConstraints); 361 362 fontSizeField.setHorizontalAlignment(javax.swing.JTextField.LEFT); 363 fontSizeField.addActionListener(new java.awt.event.ActionListener () { 364 public void actionPerformed(java.awt.event.ActionEvent evt) { 365 fontSizeFieldActionPerformed(evt); 366 } 367 }); 368 fontSizeField.addFocusListener(new java.awt.event.FocusAdapter () { 369 public void focusLost(java.awt.event.FocusEvent evt) { 370 fontSizeFieldFocusLost(evt); 371 } 372 }); 373 fontSizeField.addKeyListener(new java.awt.event.KeyAdapter () { 374 public void keyTyped(java.awt.event.KeyEvent evt) { 375 fontSizeFieldKeyTyped(evt); 376 } 377 }); 378 379 gridBagConstraints = new java.awt.GridBagConstraints (); 380 gridBagConstraints.gridx = 0; 381 gridBagConstraints.gridy = 1; 382 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 383 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 384 gridBagConstraints.weightx = 0.5; 385 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 386 fontSizePanel.add(fontSizeField, gridBagConstraints); 387 fontSizeField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "ChosenFontSizeAccessibleName")); 388 fontSizeField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("ChosenFontSizeAccessibleDescription")); 389 390 fontSizeUnitCombo.addItemListener(new java.awt.event.ItemListener () { 391 public void itemStateChanged(java.awt.event.ItemEvent evt) { 392 fontSizeUnitComboItemStateChanged(evt); 393 } 394 }); 395 396 gridBagConstraints = new java.awt.GridBagConstraints (); 397 gridBagConstraints.gridx = 1; 398 gridBagConstraints.gridy = 1; 399 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 400 gridBagConstraints.insets = new java.awt.Insets (0, 5, 5, 0); 401 fontSizePanel.add(fontSizeUnitCombo, gridBagConstraints); 402 fontSizeUnitCombo.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontSizeUnitListAccessibleName")); 403 fontSizeUnitCombo.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontSizeUnitListAccessibleDescription")); 404 405 fontSizeList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 406 fontSizeList.addListSelectionListener(new javax.swing.event.ListSelectionListener () { 407 public void valueChanged(javax.swing.event.ListSelectionEvent evt) { 408 fontSizeListValueChanged(evt); 409 } 410 }); 411 412 fontSizeScroll.setViewportView(fontSizeList); 413 fontSizeList.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontSizeListAccessibleName")); 414 fontSizeList.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontSizeListAccessibleDesription")); 415 416 gridBagConstraints = new java.awt.GridBagConstraints (); 417 gridBagConstraints.gridx = 0; 418 gridBagConstraints.gridy = 2; 419 gridBagConstraints.gridwidth = 2; 420 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 421 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 422 gridBagConstraints.weighty = 1.0; 423 fontSizePanel.add(fontSizeScroll, gridBagConstraints); 424 425 mainPanel.add(fontSizePanel, java.awt.BorderLayout.EAST); 426 427 styleMainPanel.setLayout(new java.awt.BorderLayout (20, 0)); 428 429 stylePanel.setLayout(new java.awt.GridBagLayout ()); 430 431 stylePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); 432 styleLabel.setLabelFor(fontStyleComboBox); 433 styleLabel.setText(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FONT_STYLE")); 434 gridBagConstraints = new java.awt.GridBagConstraints (); 435 gridBagConstraints.gridx = 0; 436 gridBagConstraints.gridy = 0; 437 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 438 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 439 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 440 stylePanel.add(styleLabel, gridBagConstraints); 441 442 fontStyleComboBox.setMinimumSize(new java.awt.Dimension (150, 20)); 443 fontStyleComboBox.addItemListener(new java.awt.event.ItemListener () { 444 public void itemStateChanged(java.awt.event.ItemEvent evt) { 445 fontStyleComboBoxItemStateChanged(evt); 446 } 447 }); 448 fontStyleComboBox.addActionListener(new java.awt.event.ActionListener () { 449 public void actionPerformed(java.awt.event.ActionEvent evt) { 450 fontStyleComboBoxActionPerformed(evt); 451 } 452 }); 453 fontStyleComboBox.addFocusListener(new java.awt.event.FocusAdapter () { 454 public void focusLost(java.awt.event.FocusEvent evt) { 455 fontStyleComboBoxFocusLost(evt); 456 } 457 }); 458 459 gridBagConstraints = new java.awt.GridBagConstraints (); 460 gridBagConstraints.gridx = 1; 461 gridBagConstraints.gridy = 0; 462 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 463 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 464 gridBagConstraints.insets = new java.awt.Insets (0, 5, 5, 0); 465 stylePanel.add(fontStyleComboBox, gridBagConstraints); 466 fontStyleComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "STYLE_LIST_ACCES_NAME")); 467 fontStyleComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontStyleSelectionAccessibleDescription")); 468 469 weightLabel.setLabelFor(fontWeightComboBox); 470 weightLabel.setText(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FONT_WEIGHT")); 471 gridBagConstraints = new java.awt.GridBagConstraints (); 472 gridBagConstraints.gridx = 0; 473 gridBagConstraints.gridy = 1; 474 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 475 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 476 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 477 stylePanel.add(weightLabel, gridBagConstraints); 478 479 fontWeightComboBox.setMinimumSize(new java.awt.Dimension (150, 20)); 480 fontWeightComboBox.addItemListener(new java.awt.event.ItemListener () { 481 public void itemStateChanged(java.awt.event.ItemEvent evt) { 482 fontWeightComboBoxItemStateChanged(evt); 483 } 484 }); 485 fontWeightComboBox.addActionListener(new java.awt.event.ActionListener () { 486 public void actionPerformed(java.awt.event.ActionEvent evt) { 487 fontWeightComboBoxActionPerformed(evt); 488 } 489 }); 490 fontWeightComboBox.addFocusListener(new java.awt.event.FocusAdapter () { 491 public void focusLost(java.awt.event.FocusEvent evt) { 492 fontWeightComboBoxFocusLost(evt); 493 } 494 }); 495 496 gridBagConstraints = new java.awt.GridBagConstraints (); 497 gridBagConstraints.gridx = 1; 498 gridBagConstraints.gridy = 1; 499 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 500 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 501 gridBagConstraints.insets = new java.awt.Insets (0, 5, 5, 0); 502 stylePanel.add(fontWeightComboBox, gridBagConstraints); 503 fontWeightComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontWeightSelectionAccessibleName")); 504 fontWeightComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontWeightSelectionAccessibleDescription")); 505 506 variantLabel.setLabelFor(fontVariantComboBox); 507 variantLabel.setText(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FONT_VARIANT")); 508 gridBagConstraints = new java.awt.GridBagConstraints (); 509 gridBagConstraints.gridx = 0; 510 gridBagConstraints.gridy = 2; 511 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 512 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 513 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 514 stylePanel.add(variantLabel, gridBagConstraints); 515 variantLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontVariantSelectionAccessibleDescription")); 516 517 fontVariantComboBox.setMinimumSize(new java.awt.Dimension (150, 20)); 518 fontVariantComboBox.addItemListener(new java.awt.event.ItemListener () { 519 public void itemStateChanged(java.awt.event.ItemEvent evt) { 520 fontVariantComboBoxItemStateChanged(evt); 521 } 522 }); 523 fontVariantComboBox.addActionListener(new java.awt.event.ActionListener () { 524 public void actionPerformed(java.awt.event.ActionEvent evt) { 525 fontVariantComboBoxActionPerformed(evt); 526 } 527 }); 528 fontVariantComboBox.addFocusListener(new java.awt.event.FocusAdapter () { 529 public void focusGained(java.awt.event.FocusEvent evt) { 530 fontVariantComboBoxFocusGained(evt); 531 } 532 public void focusLost(java.awt.event.FocusEvent evt) { 533 fontVariantComboBoxFocusLost(evt); 534 } 535 }); 536 537 gridBagConstraints = new java.awt.GridBagConstraints (); 538 gridBagConstraints.gridx = 1; 539 gridBagConstraints.gridy = 2; 540 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 541 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 542 gridBagConstraints.insets = new java.awt.Insets (0, 5, 5, 0); 543 stylePanel.add(fontVariantComboBox, gridBagConstraints); 544 fontVariantComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontVariantSelectionAccessibleName")); 545 fontVariantComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontVariantSelectionAccessibleDescription")); 546 547 colorLabel.setLabelFor(colorSelectionPanel); 548 colorLabel.setText(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FONT_COLOR")); 549 gridBagConstraints = new java.awt.GridBagConstraints (); 550 gridBagConstraints.gridx = 0; 551 gridBagConstraints.gridy = 3; 552 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 553 stylePanel.add(colorLabel, gridBagConstraints); 554 555 colorSelectionPanel.setLayout(new java.awt.BorderLayout ()); 556 557 gridBagConstraints = new java.awt.GridBagConstraints (); 558 gridBagConstraints.gridx = 1; 559 gridBagConstraints.gridy = 3; 560 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 561 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 0); 562 stylePanel.add(colorSelectionPanel, gridBagConstraints); 563 564 styleMainPanel.add(stylePanel, java.awt.BorderLayout.WEST); 565 566 decorationPanel.setLayout(new java.awt.GridBagLayout ()); 567 568 decorationPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); 569 decorationLabel.setText(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FONT_DECORATION")); 570 gridBagConstraints = new java.awt.GridBagConstraints (); 571 gridBagConstraints.gridx = 0; 572 gridBagConstraints.gridy = 0; 573 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 574 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 575 decorationPanel.add(decorationLabel, gridBagConstraints); 576 577 underlineCheckbox.setText(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FONT_UNDERLINE")); 578 underlineCheckbox.setMargin(new java.awt.Insets (0, 2, 0, 2)); 579 underlineCheckbox.addItemListener(new java.awt.event.ItemListener () { 580 public void itemStateChanged(java.awt.event.ItemEvent evt) { 581 underlineCheckboxItemStateChanged(evt); 582 } 583 }); 584 585 gridBagConstraints = new java.awt.GridBagConstraints (); 586 gridBagConstraints.gridx = 1; 587 gridBagConstraints.gridy = 0; 588 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 589 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 590 gridBagConstraints.insets = new java.awt.Insets (0, 5, 5, 0); 591 decorationPanel.add(underlineCheckbox, gridBagConstraints); 592 underlineCheckbox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontUnderlineAccessibleDescription")); 593 594 strikethroughCheckbox.setText(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FONT_STRIKETHROUGH")); 595 strikethroughCheckbox.setMargin(new java.awt.Insets (0, 2, 0, 2)); 596 strikethroughCheckbox.addItemListener(new java.awt.event.ItemListener () { 597 public void itemStateChanged(java.awt.event.ItemEvent evt) { 598 strikethroughCheckboxItemStateChanged(evt); 599 } 600 }); 601 602 gridBagConstraints = new java.awt.GridBagConstraints (); 603 gridBagConstraints.gridx = 1; 604 gridBagConstraints.gridy = 2; 605 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 606 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 607 gridBagConstraints.weightx = 1.0; 608 gridBagConstraints.weighty = 1.0; 609 gridBagConstraints.insets = new java.awt.Insets (0, 5, 5, 0); 610 decorationPanel.add(strikethroughCheckbox, gridBagConstraints); 611 strikethroughCheckbox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontStrikeThroughAccessibleDescription")); 612 613 overlineCheckbox.setText(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FONT_OVERLINE")); 614 overlineCheckbox.setMargin(new java.awt.Insets (0, 2, 0, 2)); 615 overlineCheckbox.addItemListener(new java.awt.event.ItemListener () { 616 public void itemStateChanged(java.awt.event.ItemEvent evt) { 617 overlineCheckboxItemStateChanged(evt); 618 } 619 }); 620 621 gridBagConstraints = new java.awt.GridBagConstraints (); 622 gridBagConstraints.gridx = 1; 623 gridBagConstraints.gridy = 1; 624 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 625 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 626 gridBagConstraints.insets = new java.awt.Insets (0, 5, 5, 0); 627 decorationPanel.add(overlineCheckbox, gridBagConstraints); 628 overlineCheckbox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontOverlineAccessibleDescription")); 629 630 noDecorationCheckbox.setText(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "NO_DECORATION")); 631 noDecorationCheckbox.addItemListener(new java.awt.event.ItemListener () { 632 public void itemStateChanged(java.awt.event.ItemEvent evt) { 633 noDecorationCheckboxItemStateChanged(evt); 634 } 635 }); 636 637 gridBagConstraints = new java.awt.GridBagConstraints (); 638 gridBagConstraints.gridx = 1; 639 gridBagConstraints.gridy = 3; 640 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 641 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 0); 642 decorationPanel.add(noDecorationCheckbox, gridBagConstraints); 643 noDecorationCheckbox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FontStyleEditor.class, "FontNoDecorationAccessibleDescription")); 644 645 styleMainPanel.add(decorationPanel, java.awt.BorderLayout.CENTER); 646 647 mainPanel.add(styleMainPanel, java.awt.BorderLayout.SOUTH); 648 649 add(mainPanel, java.awt.BorderLayout.NORTH); 650 651 errorPanel.setLayout(new java.awt.BorderLayout ()); 652 653 errorPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 10, 1, 1)); 654 errorLabel.setForeground(new java.awt.Color (0, 0, 153)); 655 errorPanel.add(errorLabel, java.awt.BorderLayout.CENTER); 656 657 add(errorPanel, java.awt.BorderLayout.CENTER); 658 659 } 661 private void noDecorationCheckboxItemStateChanged(java.awt.event.ItemEvent evt) { textDecorationData.enableNoDecoration((evt.getStateChange() == evt.SELECTED)); 663 if(evt.getStateChange() == evt.SELECTED){ 664 strikethroughCheckbox.setSelected(false); 665 overlineCheckbox.setSelected(false); 666 underlineCheckbox.setSelected(false); 667 strikethroughCheckbox.setEnabled(false); 668 overlineCheckbox.setEnabled(false); 669 underlineCheckbox.setEnabled(false); 670 }else{ 671 strikethroughCheckbox.setEnabled(true); 672 overlineCheckbox.setEnabled(true); 673 underlineCheckbox.setEnabled(true); 674 } 675 setTextDecoration(); 676 } 678 private void fontVariantComboBoxFocusGained(java.awt.event.FocusEvent evt) { errorLabel.setText(CssStyleData.PREVIEW_NOT_SUPPORTED); 680 } 682 private void strikethroughCheckboxItemStateChanged(java.awt.event.ItemEvent evt) { textDecorationData.enableLineThrough((evt.getStateChange() == evt.SELECTED)); 684 setTextDecoration(); 685 } 687 private void overlineCheckboxItemStateChanged(java.awt.event.ItemEvent evt) { textDecorationData.enableOverline((evt.getStateChange() == evt.SELECTED)); 689 setTextDecoration(); 690 } 692 private void underlineCheckboxItemStateChanged(java.awt.event.ItemEvent evt) { textDecorationData.enableUnderline((evt.getStateChange() == evt.SELECTED)); 694 setTextDecoration(); 695 } 697 private void fontVariantComboBoxItemStateChanged(java.awt.event.ItemEvent evt) { if (evt.getStateChange() != evt.DESELECTED) { 699 setFontVariant(); 700 } 701 } 703 private void fontVariantComboBoxFocusLost(java.awt.event.FocusEvent evt) { errorLabel.setText(""); 705 setFontVariant(); 706 } 708 private void fontVariantComboBoxActionPerformed(java.awt.event.ActionEvent evt) { setFontVariant(); 710 } 712 private void fontWeightComboBoxItemStateChanged(java.awt.event.ItemEvent evt) { if (evt.getStateChange() != evt.DESELECTED) { 714 setFontWeight(); 715 } 716 } 718 private void fontWeightComboBoxActionPerformed(java.awt.event.ActionEvent evt) { setFontWeight(); 720 } 722 private void fontWeightComboBoxFocusLost(java.awt.event.FocusEvent evt) { setFontWeight(); 724 } 726 private void fontStyleComboBoxActionPerformed(java.awt.event.ActionEvent evt) { setFontStyle(); 728 } 730 private void fontStyleComboBoxFocusLost(java.awt.event.FocusEvent evt) { setFontStyle(); 732 } 734 private void fontStyleComboBoxItemStateChanged(java.awt.event.ItemEvent evt) { if (evt.getStateChange() != evt.DESELECTED) { 736 setFontStyle(); 737 } 738 } 740 private void fontSizeUnitComboItemStateChanged(java.awt.event.ItemEvent evt) { if (evt.getStateChange() != evt.DESELECTED) { 742 setFontSize(); 743 } 744 } 746 private void fontSizeFieldActionPerformed(java.awt.event.ActionEvent evt) { setFontSize(); 748 } 750 private void fontSizeFieldFocusLost(java.awt.event.FocusEvent evt) { setFontSize(); 752 } 754 private void fontSizeFieldKeyTyped(java.awt.event.KeyEvent evt) { SwingUtilities.invokeLater(new Runnable (){ 756 public void run(){ 757 enableFontSizeUnitCombo(Utils.isInteger(fontSizeField.getText())); 758 } 759 }); 760 } 762 private void fontSizeListValueChanged(javax.swing.event.ListSelectionEvent evt) { if (evt.getValueIsAdjusting()) return; 764 String selectedFontSize = (String ) fontSizeList.getSelectedValue(); 765 fontSizeField.setText(selectedFontSize); 766 enableFontSizeUnitCombo(Utils.isInteger(selectedFontSize)); 767 setFontSize(); 768 } 770 private void enableFontSizeUnitCombo(final boolean enable){ 771 SwingUtilities.invokeLater(new Runnable (){ 772 public void run(){ 773 fontSizeUnitCombo.setEnabled(enable); 774 } 775 }); 776 } 777 778 private void fontFaceListValueChanged(javax.swing.event.ListSelectionEvent evt) { if (evt.getValueIsAdjusting()) return; 780 if(fontFaceList.getSelectedValue()!= null){ 781 fontChosenField.setText(fontFaceList.getSelectedValue().toString()); 782 setFontFamily(); 783 } 784 } 786 private void fontFamilyButtonActionPerformed(java.awt.event.ActionEvent evt) { FontFamilyEditorDialog fontFamilyEditor = new FontFamilyEditorDialog(fontFamilies, fontFaceList.getSelectedIndex()); 788 fontFamilyEditor.showDialog(); 789 fontFaceList.setSelectedIndex(fontFamilyEditor.getSelectedIndex()); 790 fontChosenField.setText(fontFaceList.getSelectedValue().toString()); 791 setFontFamily(); 792 } 794 795 private void setFontFamily(){ 796 PropertyData fontFamilyData = new PropertyData(); 797 fontFamilyData.setValue(fontChosenField.getText()); 798 cssPropertyChangeSupport.firePropertyChange(CssProperties.FONT_FAMILY, null, fontFamilyData.toString()); 799 } 800 801 private void setFontSize(){ 802 PropertyWithUnitData fontSizeData = new PropertyWithUnitData(); 804 fontSizeData.setUnit(fontSizeUnitCombo.getSelectedItem().toString()); 805 fontSizeData.setValue(fontSizeField.getText()); 806 cssPropertyChangeSupport.firePropertyChange(CssProperties.FONT_SIZE, null, fontSizeData.toString()); 807 } 808 809 private void setFontStyle(){ 810 PropertyData fontStyleData = new PropertyData(); 811 fontStyleData.setValue(fontStyleComboBox.getSelectedItem().toString()); 812 cssPropertyChangeSupport.firePropertyChange(CssProperties.FONT_STYLE, null, fontStyleData.toString()); 813 } 814 815 private void setFontWeight(){ 816 PropertyData fontWeightData = new PropertyData(); 817 fontWeightData.setValue(fontWeightComboBox.getSelectedItem().toString()); 818 cssPropertyChangeSupport.firePropertyChange(CssProperties.FONT_WEIGHT, null, fontWeightData.toString()); 819 } 820 821 private void setFontVariant(){ 822 PropertyData fontVariantData = new PropertyData(); 823 fontVariantData.setValue(fontVariantComboBox.getSelectedItem().toString()); 824 cssPropertyChangeSupport.firePropertyChange(CssProperties.FONT_VARIANT, null, fontVariantData.toString()); 825 } 826 827 private void setFontColor(){ 828 PropertyData fontColorData = new PropertyData(); 829 fontColorData.setValue(colorField.getColorString()); 830 cssPropertyChangeSupport.firePropertyChange(CssProperties.COLOR, null, fontColorData.toString()); 831 } 832 833 private void setTextDecoration(){ 834 cssPropertyChangeSupport.firePropertyChange(CssProperties.TEXT_DECORATION, null, textDecorationData.toString()); 835 } 836 837 838 private javax.swing.JLabel colorLabel; 840 private javax.swing.JPanel colorSelectionPanel; 841 private javax.swing.JLabel decorationLabel; 842 private javax.swing.JPanel decorationPanel; 843 private javax.swing.JLabel errorLabel; 844 private javax.swing.JPanel errorPanel; 845 private javax.swing.JTextField fontChosenField; 846 private javax.swing.JList fontFaceList; 847 private javax.swing.JScrollPane fontFaceScroll; 848 private javax.swing.JButton fontFamilyButton; 849 private javax.swing.JPanel fontFamilyPanel; 850 private javax.swing.JLabel fontLabel; 851 private javax.swing.JTextField fontSizeField; 852 private javax.swing.JList fontSizeList; 853 private javax.swing.JPanel fontSizePanel; 854 private javax.swing.JScrollPane fontSizeScroll; 855 private javax.swing.JComboBox fontSizeUnitCombo; 856 private javax.swing.JComboBox fontStyleComboBox; 857 private javax.swing.JComboBox fontVariantComboBox; 858 private javax.swing.JComboBox fontWeightComboBox; 859 private javax.swing.JPanel mainPanel; 860 private javax.swing.JCheckBox noDecorationCheckbox; 861 private javax.swing.JCheckBox overlineCheckbox; 862 private javax.swing.JLabel sizeLabel; 863 private javax.swing.JCheckBox strikethroughCheckbox; 864 private javax.swing.JLabel styleLabel; 865 private javax.swing.JPanel styleMainPanel; 866 private javax.swing.JPanel stylePanel; 867 private javax.swing.JCheckBox underlineCheckbox; 868 private javax.swing.JLabel variantLabel; 869 private javax.swing.JLabel weightLabel; 870 } 872 | Popular Tags |