Clover coverage report -
Coverage timestamp: Sun Apr 18 2004 21:32:30 EDT
file stats: LOC: 583   Methods: 20
NCLOC: 312   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ParaStyleDialog.java 28.6% 57.3% 50% 50.6%
coverage coverage
 1   
 /*
 2   
  * SimplyHTML, a word processor based on Java, HTML and CSS
 3   
  * Copyright (C) 2002 Ulrich Hilger
 4   
  *
 5   
  * This program is free software; you can redistribute it and/or
 6   
  * modify it under the terms of the GNU General Public License
 7   
  * as published by the Free Software Foundation; either version 2
 8   
  * of the License, or (at your option) any later version.
 9   
  *
 10   
  * This program is distributed in the hope that it will be useful,
 11   
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12   
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13   
  * GNU General Public License for more details.
 14   
  *
 15   
  * You should have received a copy of the GNU General Public License
 16   
  * along with this program; if not, write to the Free Software
 17   
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 18   
  */
 19   
 
 20   
 import java.awt.*;
 21   
 import java.awt.event.*;
 22   
 import javax.swing.*;
 23   
 import javax.swing.border.*;
 24   
 import javax.swing.event.*;
 25   
 import javax.swing.text.*;
 26   
 import javax.swing.text.html.*;
 27   
 import java.util.*;
 28   
 import java.util.prefs.*;
 29   
 import java.io.*;
 30   
 
 31   
 /**
 32   
  * Dialog to set paragraph attributes and to manipulate styles in a
 33   
  * given style sheet.
 34   
  *
 35   
  * <p>In stage 9 this has an additional combo box to select different
 36   
  * element types in MODE_NAMED_STYLES.</p>
 37   
  *
 38   
  * @author Ulrich Hilger
 39   
  * @author Light Development
 40   
  * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
 41   
  * @author <a href="mailto:info@lightdev.com">info@lightdev.com</a>
 42   
  * @author published under the terms and conditions of the
 43   
  *      GNU General Public License,
 44   
  *      for details see file gpl.txt in the distribution
 45   
  *      package of this software
 46   
  *
 47   
  * @version stage 11, April 27, 2003
 48   
  */
 49   
 
 50   
 public class ParaStyleDialog extends DialogShell
 51   
     implements AttributeComponent, ActionListener, ListSelectionListener, ChangeListener
 52   
 {
 53   
 
 54   
   private String standardStyleName = FrmMain.dynRes.getResourceString(FrmMain.resources, "standardStyleName");
 55   
 
 56   
   /** mode to edit named styles with this dialog */
 57   
   private static int MODE_NAMED_STYLES = 1;
 58   
 
 59   
   /** mode to set a paragraph style with this dialog */
 60   
   private static int MODE_PARAGRAPH_STYLE = 2;
 61   
 
 62   
   /** button to save a named style */
 63   
   private JButton saveStyleBtn;
 64   
 
 65   
   /** button to save a named style under a different name */
 66   
   private JButton saveStyleAsBtn;
 67   
 
 68   
   /** button to delete a named style */
 69   
   private JButton deleteStyleBtn;
 70   
 
 71   
   /** the mode this dialog was created in */
 72   
   private int mode;
 73   
 
 74   
   /** the AttributeComponents in this dialog */
 75   
   private Vector components = new Vector();
 76   
 
 77   
   /** the FontPanel for the paragraph font settings */
 78   
   private FontPanel fp;
 79   
 
 80   
   /** list of styles available in style sheet */
 81   
   private JList styleList;
 82   
 
 83   
   /** style sheet to use in MODE_NAMED_STYLES */
 84   
   private StyleSheet styles;
 85   
 
 86   
   /** the document this dialog is operating on when in MODE_NAMED_STYLES */
 87   
   private Document doc;
 88   
 
 89   
   /** set of attributes for mapping discrepancies between HTML and Java */
 90   
   private AttributeSet mapSet;
 91   
 
 92   
   /**
 93   
    * panel for setting paragraph styles (needed in the change listener
 94   
    * of the list of named styles)
 95   
    */
 96   
   private StylePanel sp;
 97   
 
 98   
   /**
 99   
    * panel for setting margins (needed in the change listener
 100   
    * of the list of named styles)
 101   
    */
 102   
   private MarginPanel mp;
 103   
 
 104   
   /** table to map between HTML tags and 'content types' */
 105   
   private Hashtable cTypes;
 106   
 
 107   
   /** selector for content type */
 108   
   private JComboBox cType;
 109   
 
 110   
   /**
 111   
    * create a <code>ParaStyleDialog</code> to manipulate
 112   
    * the format of a paragraph
 113   
    *
 114   
    * @param parent  the parent frame of this dialog
 115   
    * @param title  the text to be shown as title for this dialog
 116   
    */
 117  1
   public ParaStyleDialog(Frame parent, String title) {
 118  1
     this(parent, title, null, MODE_PARAGRAPH_STYLE);
 119   
   }
 120   
 
 121   
   /**
 122   
    * create a <code>ParaStyleDialog</code> to edit named
 123   
    * styles of a given document
 124   
    *
 125   
    * @param parent  the parent frame of this dialog
 126   
    * @param title the text to be shown as title for this dialog
 127   
    * @param doc  the document having the style sheet to edit named styles from
 128   
    */
 129  1
   public ParaStyleDialog(Frame parent, String title, Document doc) {
 130  1
     this(parent, title, doc, MODE_NAMED_STYLES);
 131   
   }
 132   
 
 133   
   /**
 134   
    * construct a <code>ParaStyleDialog</code>
 135   
    *
 136   
    * @param parent  the parent frame for this dialog
 137   
    * @param title  the text to be shown as title for this dialog
 138   
    * @param mode  the mode this dialog is to be created, one of MODE_NAMED_STYLES or MODE_PARAGRAPH_STYLE
 139   
    */
 140  2
   private ParaStyleDialog(Frame parent, String title, Document doc, int mode)
 141   
   {
 142  2
     super(parent, title);
 143   
 
 144  2
     JPanel hPanel = null;
 145   
 
 146  2
     this.mode = mode;
 147  2
     this.doc = doc;
 148   
 
 149   
     // get content pane of DialogShell to add components to
 150  2
     Container contentPane = super.getContentPane();
 151   
 
 152   
     // construct tabbed pane for the various groups of settings
 153  2
     JTabbedPane tp = new JTabbedPane();
 154  2
     tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
 155   
 
 156   
     // create style panel
 157  2
     sp = new StylePanel(StylePanel.TYPE_PARAGRAPH);
 158  2
     sp.setBorder(new TitledBorder(new EtchedBorder(
 159   
                   EtchedBorder.LOWERED),
 160   
                   FrmMain.dynRes.getResourceString(
 161   
                   FrmMain.resources, "cellGenTabLabel")));
 162  2
     components.add(sp);
 163   
 
 164   
     // create margin panel
 165  2
     mp = new MarginPanel();
 166  2
     components.add(mp);
 167  2
     mp.setBorder(new TitledBorder(new EtchedBorder(
 168   
                   EtchedBorder.LOWERED),
 169   
                   FrmMain.dynRes.getResourceString(
 170   
                   FrmMain.resources, "cellMarginTabLabel")));
 171   
 
 172  2
     if(mode == MODE_NAMED_STYLES) {
 173  1
       styles = ((SHTMLDocument) doc).getStyleSheet();
 174   
 
 175   
       // create a combo box for content type
 176  1
       initContentTypes();
 177  1
       cType = new JComboBox(cTypes.keySet().toArray());
 178  1
       cType.addActionListener(this);
 179   
 
 180   
       // create a list of styles
 181   
       //Vector styleNames = Util.getStyleNamesForTag(styles, getContentType());
 182   
       //styleNames.insertElementAt(standardStyleName, 0);
 183  1
       styleList = new JList(/*new DefaultComboBoxModel(styleNames)*/);
 184  1
       updateStyleList();
 185  1
       styles.addChangeListener(this);
 186  1
       styleList.addListSelectionListener(this);
 187   
 
 188   
       // create a panel to control the styles
 189  1
       JPanel btnPanel = new JPanel(new GridLayout(3, 1, 5, 5));
 190  1
       saveStyleBtn = new JButton(FrmMain.dynRes.getResourceString(FrmMain.resources, "saveStyleButtonLabel"));
 191  1
       saveStyleBtn.addActionListener(this);
 192  1
       saveStyleBtn.setEnabled(false);
 193  1
       saveStyleAsBtn = new JButton(FrmMain.dynRes.getResourceString(FrmMain.resources, "saveStyleAsButtonLabel"));
 194  1
       saveStyleAsBtn.addActionListener(this);
 195  1
       deleteStyleBtn = new JButton(FrmMain.dynRes.getResourceString(FrmMain.resources, "deleteStyleButtonLabel"));
 196  1
       deleteStyleBtn.addActionListener(this);
 197  1
       deleteStyleBtn.setEnabled(false);
 198  1
       btnPanel.add(saveStyleBtn);
 199  1
       btnPanel.add(saveStyleAsBtn);
 200  1
       btnPanel.add(deleteStyleBtn);
 201   
 
 202   
       // use a helper panel for placement of buttons
 203  1
       hPanel = new JPanel(new BorderLayout());
 204  1
       hPanel.add(btnPanel, BorderLayout.NORTH);
 205   
 
 206   
       // create named styles panel
 207  1
       JPanel nsPanel = new JPanel(new BorderLayout(5, 5));
 208  1
       nsPanel.add(cType, BorderLayout.NORTH);
 209  1
       nsPanel.add(new JScrollPane(styleList), BorderLayout.CENTER);
 210  1
       nsPanel.add(hPanel, BorderLayout.EAST);
 211  1
       nsPanel.setBorder(new TitledBorder(new EtchedBorder(
 212   
           EtchedBorder.LOWERED),
 213   
           FrmMain.dynRes.getResourceString(
 214   
           FrmMain.resources, "stylePanelLabel")));
 215  1
       nsPanel.setVisible(mode == MODE_NAMED_STYLES);
 216   
 
 217   
       // use a helper panel for placement of style and named styles panels
 218  1
       hPanel = new JPanel(new BorderLayout());
 219  1
       hPanel.add(sp, BorderLayout.NORTH);
 220  1
       hPanel.add(nsPanel, BorderLayout.CENTER);
 221   
 
 222  1
       okButton.setText(FrmMain.dynRes.getResourceString(FrmMain.resources, "closeLabel"));
 223   
     }
 224   
     else {
 225  1
       hPanel = new JPanel(new BorderLayout());
 226  1
       hPanel.add(sp, BorderLayout.NORTH);
 227   
     }
 228   
 
 229   
 
 230   
     // create paragraph panel
 231  2
     JPanel paraPanel = new JPanel(new BorderLayout());
 232  2
     paraPanel.add(hPanel, BorderLayout.CENTER);
 233  2
     paraPanel.add(mp, BorderLayout.EAST);
 234   
 
 235   
     // add paragraph panel to tabbed pane
 236  2
     tp.add(FrmMain.dynRes.getResourceString(FrmMain.resources, "paraTabLabel"), paraPanel);
 237   
 
 238   
     // create font panel and add to tabbed pane
 239  2
     fp = new FontPanel();
 240   
 
 241   
     // add tabbed pane to content pane of dialog
 242  2
     contentPane.add(tp, BorderLayout.CENTER);
 243   
 
 244  2
     cancelButton.setVisible(mode != MODE_NAMED_STYLES);
 245  2
     try {
 246  2
       Preferences prefs = Preferences.userNodeForPackage(getClass().forName("PrefsDialog"));
 247  2
       String writeMode = prefs.get(PrefsDialog.PREFSID_WRITE_MODE, PrefsDialog.PREFS_WRITE_MODE_HTML32);
 248  2
       if(((mode == MODE_PARAGRAPH_STYLE) && (!writeMode.equalsIgnoreCase(PrefsDialog.PREFS_WRITE_MODE_HTML32))) ||
 249   
           (mode == MODE_NAMED_STYLES))
 250   
       {
 251  1
         tp.add(FrmMain.dynRes.getResourceString(FrmMain.resources, "fontTabLabel"), fp);
 252   
       }
 253   
     }
 254   
     catch(ClassNotFoundException e) {}
 255   
 
 256   
     // cause optimal placement of all elements
 257  2
     pack();
 258   
   }
 259   
 
 260   
   /**
 261   
    * update the list of available styles for the currently
 262   
    * selected tag
 263   
    */
 264  1
   private void updateStyleList() {
 265  1
     Vector styleNames = Util.getStyleNamesForTag(styles, getContentType());
 266  1
     styleNames.insertElementAt(standardStyleName, 0);
 267  1
     styleList.setModel(new DefaultComboBoxModel(styleNames));
 268   
   }
 269   
 
 270   
   /**
 271   
    * initialize content types hashtable
 272   
    */
 273  1
   private void initContentTypes() {
 274  1
     cTypes = new Hashtable();
 275  1
     cTypes.put(FrmMain.dynRes.getResourceString(FrmMain.resources, "cTagNamePara"), HTML.Tag.P.toString());
 276  1
     cTypes.put(FrmMain.dynRes.getResourceString(FrmMain.resources, "cTagNameHead1"), HTML.Tag.H1.toString());
 277  1
     cTypes.put(FrmMain.dynRes.getResourceString(FrmMain.resources, "cTagNameHead2"), HTML.Tag.H2.toString());
 278  1
     cTypes.put(FrmMain.dynRes.getResourceString(FrmMain.resources, "cTagNameHead3"), HTML.Tag.H3.toString());
 279  1
     cTypes.put(FrmMain.dynRes.getResourceString(FrmMain.resources, "cTagNameHead4"), HTML.Tag.H4.toString());
 280  1
     cTypes.put(FrmMain.dynRes.getResourceString(FrmMain.resources, "cTagNameHead5"), HTML.Tag.H5.toString());
 281  1
     cTypes.put(FrmMain.dynRes.getResourceString(FrmMain.resources, "cTagNameHead6"), HTML.Tag.H6.toString());
 282  1
     cTypes.put(FrmMain.dynRes.getResourceString(FrmMain.resources, "cTagNameLink"), HTML.Tag.A.toString());
 283  1
     cTypes.put(FrmMain.dynRes.getResourceString(FrmMain.resources, "cTagNameUL"), HTML.Tag.UL.toString());
 284  1
     cTypes.put(FrmMain.dynRes.getResourceString(FrmMain.resources, "cTagNameOL"), HTML.Tag.OL.toString());
 285   
   }
 286   
 
 287   
   /**
 288   
    * get the currently selected tag
 289   
    *
 290   
    * @return the tag name currently selected
 291   
    */
 292  1
   private String getContentType() {
 293  1
     Object key = cType.getSelectedItem();
 294  1
     return cTypes.get(key).toString();
 295   
   }
 296   
 
 297   
   /**
 298   
    * get the value of this <code>AttributeComponent</code>
 299   
    *
 300   
    * @return the value selected from this component
 301   
    */
 302  1
   public AttributeSet getValue() {
 303  1
     SimpleAttributeSet attributes = new SimpleAttributeSet();
 304  1
     Enumeration elements = components.elements();
 305  1
     AttributeComponent ac;
 306  1
     while(elements.hasMoreElements()) {
 307  2
       ac = (AttributeComponent) elements.nextElement();
 308  2
       attributes.addAttributes(ac.getValue());
 309   
     }
 310  1
     attributes.addAttributes(fp.getAttributes());
 311  1
     return attributes;
 312   
   }
 313   
 
 314  0
   public AttributeSet getValue(boolean includeUnchanged) {
 315  0
     if(includeUnchanged) {
 316  0
       SimpleAttributeSet attributes = new SimpleAttributeSet();
 317  0
       Enumeration elements = components.elements();
 318  0
       AttributeComponent ac;
 319  0
       while(elements.hasMoreElements()) {
 320  0
         ac = (AttributeComponent) elements.nextElement();
 321  0
         attributes.addAttributes(ac.getValue(includeUnchanged));
 322   
       }
 323  0
       attributes.addAttributes(fp.getAttributes(includeUnchanged));
 324  0
       return attributes;
 325   
     }
 326   
     else {
 327  0
       return getValue();
 328   
     }
 329   
   }
 330   
 
 331   
   /**
 332   
    * set the value of this <code>AttributeComponent</code>
 333   
    *
 334   
    * @param a  the set of attributes possibly having an
 335   
    *          attribute this component can display
 336   
    *
 337   
    * @return true, if the set of attributes had a matching attribute,
 338   
    *            false if not
 339   
    */
 340  2
   public boolean setValue(AttributeSet a) {
 341  2
     boolean result = true;
 342   
 
 343   
     /*
 344   
     System.out.println("\r\n");
 345   
     de.calcom.cclib.html.HTMLDiag hd = new de.calcom.cclib.html.HTMLDiag();
 346   
     hd.listAttributes(a, 4);
 347   
     */
 348   
 
 349  2
     AttributeSet set = Util.resolveAttributes(a);
 350  2
     Enumeration elements = components.elements();
 351  2
     AttributeComponent ac;
 352  2
     while(elements.hasMoreElements()) {
 353  4
       ac = (AttributeComponent) elements.nextElement();
 354  4
       if(!ac.setValue(set)) {
 355  2
         result = false;
 356   
       }
 357   
     }
 358  2
     fp.setAttributes(set);
 359  2
     return result;
 360   
   }
 361   
 
 362   
   /**
 363   
    * listen to changes of style list,
 364   
    * switch state of save and delete buttons accordingly and
 365   
    * set dialog to the selected style, if any
 366   
    */
 367  0
   public void valueChanged(ListSelectionEvent e) {
 368  0
     if(e.getSource().equals(styleList)) {
 369  0
       int selectedStyleNo = styleList.getSelectedIndex();
 370  0
       boolean styleSelected = selectedStyleNo > -1;
 371  0
       saveStyleBtn.setEnabled(styleSelected);
 372  0
       deleteStyleBtn.setEnabled(styleSelected);
 373  0
       if(styleSelected) {
 374   
         // set dialog contents to selected style
 375  0
         sp.reset();
 376  0
         fp.reset();
 377  0
         mp.reset();
 378  0
         String styleName;
 379  0
         String className = styleList.getSelectedValue().toString();
 380  0
         if(className.equalsIgnoreCase(standardStyleName)) {
 381  0
           styleName = getContentType();
 382   
         }
 383   
         else {
 384  0
           styleName = getContentType() + Util.CLASS_SEPARATOR + className;
 385   
         }
 386   
         //Style style = styles.getStyle(styleName);
 387  0
         AttributeSet style = (AttributeSet) styles.getStyle(styleName);
 388  0
         MutableAttributeSet allStyles = (MutableAttributeSet) FrmMain.getMaxAttributes(((SHTMLDocument) doc).getCharacterElement(doc.getEndPosition().getOffset()),
 389   
                                  ((SHTMLDocument) doc).getStyleSheet());
 390  0
         allStyles.addAttributes(style);
 391   
         //mapSet = new AttributeMapper(Util.resolveAttributes(style)).getMappedAttributes(AttributeMapper.toJava);
 392   
         //setValue(style);
 393  0
         setValue(allStyles);
 394   
       }
 395   
     }
 396   
   }
 397   
 
 398   
   /**
 399   
    * get the style name currently selected in the list of style names
 400   
    *
 401   
    * @return the name of the style currently selected in the
 402   
    * list of style names or null if none is currently selected
 403   
    */
 404  0
   private String getSelectedStyleName() {
 405  0
     String styleName = null;
 406  0
     if(styleList.getSelectedIndex() > -1) {
 407  0
       styleName = styleList.getSelectedValue().toString();
 408   
     }
 409  0
     return styleName;
 410   
   }
 411   
 
 412   
   /**
 413   
    * save the current settings on this <code>ParaStyleDialog</code>
 414   
    * to its associated style sheet under the name currently
 415   
    * selected in the list of named styles.
 416   
    *
 417   
    * <p>This will overwrite the existing style with the current
 418   
    * settings on this dialog.</p>
 419   
    */
 420  0
   private void doSaveStyle() {
 421  0
     String styleName = getSelectedStyleName();
 422  0
     if(styleName != null) {
 423  0
       saveStyleAs(styleName);
 424   
     }
 425   
   }
 426   
 
 427   
   /**
 428   
    * save the current settings on this <code>ParaStyleDialog</code>
 429   
    * to its associated style sheet under a name defined by the user.
 430   
    *
 431   
    * <p>This will ask for a name a style shall be saved under. If the name
 432   
    * exists, the user is prompted whether or not it shall be overwritten.
 433   
    * The sytle is saved according to the user's choices.</p>
 434   
    */
 435  0
   private void doSaveStyleAs() {
 436  0
     String initialName = getSelectedStyleName();
 437  0
     if(initialName == null) {
 438  0
       initialName = FrmMain.dynRes.getResourceString(
 439   
           FrmMain.resources, "newStyleDefaultName");
 440   
     }
 441  0
     String newStyleName = Util.nameInput(null, initialName, "styleNameInputTitle", "styleNameInputText");
 442  0
     if(newStyleName != null) {
 443  0
       if(styleNameExists(newStyleName) || newStyleName.equalsIgnoreCase(standardStyleName)) {
 444  0
         if(Util.msg(JOptionPane.YES_NO_OPTION, "confirmSaveAs", "fileExistsQuery", newStyleName, " ")) {
 445  0
           saveStyleAs(newStyleName);
 446   
         }
 447   
       }
 448   
       else {
 449  0
         saveStyleAs(newStyleName);
 450   
       }
 451   
     }
 452   
   }
 453   
 
 454   
   /**
 455   
    * delete the currently selected style name for the
 456   
    * currently selected tag
 457   
    */
 458  0
   private void doDeleteStyle() {
 459  0
     String styleName = getSelectedStyleName();
 460  0
     if(styleName != null) {
 461  0
       if(Util.msg(JOptionPane.YES_NO_OPTION, "confirmDelete", "deleteStyleQuery", styleName, "\r\n\r\n")) {
 462  0
         styles.removeStyle(getContentType() + Util.CLASS_SEPARATOR + styleName);
 463   
       }
 464   
     }
 465   
   }
 466   
 
 467   
   /**
 468   
    * save a style under a given name
 469   
    *
 470   
    * @param newStyleName  the name the style has to be saved under
 471   
    */
 472  0
   private void saveStyleAs(String newStyleName) {
 473  0
     try {
 474  0
       String className = getContentType();
 475  0
       if(!newStyleName.equalsIgnoreCase(standardStyleName)) {
 476  0
         className = className + Util.CLASS_SEPARATOR + newStyleName;
 477   
       }
 478  0
       StringWriter sw = new StringWriter();
 479  0
       CSSWriter cw = new CSSWriter(sw, null);
 480  0
       SimpleAttributeSet a = new SimpleAttributeSet();
 481  0
       if(mapSet != null) {
 482  0
         a.addAttributes(mapSet);
 483   
       }
 484   
 
 485   
       /*
 486   
       AttributeSet test = getValue(true);
 487   
       de.calcom.cclib.html.HTMLDiag hd = new de.calcom.cclib.html.HTMLDiag();
 488   
       hd.listAttributes(test, 4);
 489   
       System.out.println(" \r\n");
 490   
       */
 491   
 
 492  0
       a.addAttributes(new AttributeMapper(getValue(true)).getMappedAttributes(AttributeMapper.toHTML));
 493   
 
 494   
       // hd.listAttributes(a, 4);
 495   
 
 496  0
       cw.writeRule(className, a);
 497  0
       String ruleStr = sw.getBuffer().toString();
 498  0
       styles.removeStyle(className);
 499  0
       styles.addRule(ruleStr);
 500  0
       if(doc != null) {
 501  0
         SHTMLDocument sd = (SHTMLDocument) doc;
 502  0
         if(!sd.hasStyleRef()) {
 503  0
           sd.insertStyleRef();
 504   
         }
 505   
       }
 506   
     }
 507   
     catch(Exception ex) {
 508  0
       Util.errMsg(this, ex.getMessage(), ex);
 509   
     }
 510   
   }
 511   
 
 512   
   /**
 513   
    * get the style sheet this dialog uses
 514   
    *
 515   
    * @return the used style sheet
 516   
    */
 517  0
   public StyleSheet getStyleSheet() {
 518  0
     return styles;
 519   
   }
 520   
 
 521   
   /**
 522   
    * check whether or not a named style already exists in the style sheet
 523   
    * associated to this dialog
 524   
    *
 525   
    * @param styleName  the name of the style to be looked for
 526   
    *
 527   
    * @return true, if the given style name alread is used in the style sheet,
 528   
    *    false if not
 529   
    */
 530  0
   private boolean styleNameExists(String styleName) {
 531  0
     Vector styleNames = Util.getStyleNamesForTag(styles, getContentType() /*HTML.Tag.P.toString()*/);
 532  0
     return (styleNames.indexOf(styleName) > -1);
 533   
   }
 534   
 
 535   
   /**
 536   
    * overridden to addd some custom cleanup upon closing of dialog
 537   
    */
 538  2
   public void dispose() {
 539  2
     if(mode == MODE_NAMED_STYLES) {
 540  1
       styles.removeChangeListener(this);
 541   
     }
 542  2
     super.dispose();
 543   
   }
 544   
 
 545   
   /**
 546   
    * ChangeListener implementation to be used on a style sheet.
 547   
    *
 548   
    * <p>This is used to update the list of named styles whenever
 549   
    * a change was saved to the style sheet.</p>
 550   
    */
 551  0
   public void stateChanged(ChangeEvent e) {
 552  0
     Object src = e.getSource();
 553  0
     if(src instanceof StyleContext.NamedStyle) {
 554  0
       Vector styleNames = Util.getStyleNamesForTag((AttributeSet) src, getContentType() /*HTML.Tag.P.toString()*/);
 555  0
       styleNames.insertElementAt(standardStyleName, 0);
 556  0
       styleList.setModel(new DefaultComboBoxModel(styleNames));
 557   
     }
 558   
   }
 559   
 
 560   
   /**
 561   
    * listen to actions and route them accordingly, i.e. react to
 562   
    * buttons save, save as and delete style
 563   
    */
 564  2
   public void actionPerformed(ActionEvent e) {
 565  2
     Object src = e.getSource();
 566  2
     if(src.equals(saveStyleBtn)) {
 567  0
       doSaveStyle();
 568   
     }
 569  2
     else if(src.equals(saveStyleAsBtn)) {
 570  0
       doSaveStyleAs();
 571   
     }
 572  2
     else if(src.equals(deleteStyleBtn)) {
 573  0
       doDeleteStyle();
 574   
     }
 575  2
     else if(src.equals(cType)) {
 576   
       // update list of named styles
 577  0
       updateStyleList();
 578   
     }
 579   
     else {
 580  2
       super.actionPerformed(e);
 581   
     }
 582   
   }
 583   
 }