/** @see java.lang.Runnable#run() */
 public void run() {
   Designer dsgr = Designer.theDesigner();
   org.argouml.uml.cognitive.critics.Init.init();
   org.argouml.uml.cognitive.checklist.Init.init();
   Project p = ProjectManager.getManager().getCurrentProject();
   // set the icon for this poster
   dsgr.setClarifier(ResourceLoaderWrapper.lookupIconResource("PostItD0"));
   dsgr.setDesignerName(Configuration.getString(Argo.KEY_USER_FULLNAME));
   Configuration.addListener(Argo.KEY_USER_FULLNAME, dsgr); // MVW
   dsgr.spawnCritiquer(p);
   dsgr.setChildGenerator(new ChildGenUML());
   java.util.Enumeration models = (p.getUserDefinedModels()).elements();
   while (models.hasMoreElements()) {
     Object o = models.nextElement();
     Model.getPump().addModelEventListener(dsgr, o);
   }
   LOG.info("spawned critiquing thread");
   dsgr.getDecisionModel().startConsidering(UMLDecision.CLASS_SELECTION);
   dsgr.getDecisionModel().startConsidering(UMLDecision.BEHAVIOR);
   dsgr.getDecisionModel().startConsidering(UMLDecision.NAMING);
   dsgr.getDecisionModel().startConsidering(UMLDecision.STORAGE);
   dsgr.getDecisionModel().startConsidering(UMLDecision.INHERITANCE);
   dsgr.getDecisionModel().startConsidering(UMLDecision.CONTAINMENT);
   dsgr.getDecisionModel().startConsidering(UMLDecision.PLANNED_EXTENSIONS);
   dsgr.getDecisionModel().startConsidering(UMLDecision.STATE_MACHINES);
   dsgr.getDecisionModel().startConsidering(UMLDecision.PATTERNS);
   dsgr.getDecisionModel().startConsidering(UMLDecision.RELATIONSHIPS);
   dsgr.getDecisionModel().startConsidering(UMLDecision.INSTANCIATION);
   dsgr.getDecisionModel().startConsidering(UMLDecision.MODULARITY);
   dsgr.getDecisionModel().startConsidering(UMLDecision.EXPECTED_USAGE);
   dsgr.getDecisionModel().startConsidering(UMLDecision.METHODS);
   dsgr.getDecisionModel().startConsidering(UMLDecision.CODE_GEN);
   dsgr.getDecisionModel().startConsidering(UMLDecision.STEREOTYPES);
   Designer.setUserWorking(true);
 }
 /** The constructor. */
 private SaveGraphicsManager() {
   defaultFilter = FileFilters.PNG_FILTER;
   otherFilters.add(FileFilters.GIF_FILTER);
   otherFilters.add(FileFilters.SVG_FILTER);
   otherFilters.add(FileFilters.PS_FILTER);
   otherFilters.add(FileFilters.EPS_FILTER);
   setDefaultFilterBySuffix(
       Configuration.getString(KEY_DEFAULT_GRAPHICS_FILTER, defaultFilter.getSuffix()));
 }
  /** @param f the new default file-format */
  public void setDefaultFilter(SuffixFilter f) {
    otherFilters.remove(f);
    if (!otherFilters.contains(defaultFilter)) {
      otherFilters.add(defaultFilter);
    }
    defaultFilter = f;
    Configuration.setString(KEY_DEFAULT_GRAPHICS_FILTER, f.getSuffix());

    Collections.sort(
        otherFilters,
        new Comparator() {
          public int compare(Object arg0, Object arg1) {
            return ((SuffixFilter) arg0)
                .getSuffix()
                .compareToIgnoreCase(((SuffixFilter) arg1).getSuffix());
          }
        });
  }
/**
 * This class has some similar functions like PersistenceManager.
 *
 * <p>It centralizes all knowledge about the different graphical formats. This class is the only one
 * that is supposed to know the complete list of supported graphics formats.
 *
 * @author [email protected]
 */
public class SaveGraphicsManager {

  /** The configuration key for the preferred graphics format. */
  public static final ConfigurationKey KEY_DEFAULT_GRAPHICS_FILTER =
      Configuration.makeKey("graphics", "default", "filter");

  /** The configuration key for the "save graphics" file location. */
  public static final ConfigurationKey KEY_SAVE_GRAPHICS_PATH =
      Configuration.makeKey("graphics", "save", "path");

  /** The configuration key for the "save all graphics" file location. */
  public static final ConfigurationKey KEY_SAVEALL_GRAPHICS_PATH =
      Configuration.makeKey("graphics", "save-all", "path");

  /** The configuration key for the export graphics resolution. */
  public static final ConfigurationKey KEY_GRAPHICS_RESOLUTION =
      Configuration.makeKey("graphics", "export", "resolution");

  /** the default file format */
  private SuffixFilter defaultFilter;

  /** the list of other file formats */
  private List otherFilters = new ArrayList();

  /** The singleton instance. */
  private static SaveGraphicsManager INSTANCE;

  /** The constructor. */
  private SaveGraphicsManager() {
    defaultFilter = FileFilters.PNG_FILTER;
    otherFilters.add(FileFilters.GIF_FILTER);
    otherFilters.add(FileFilters.SVG_FILTER);
    otherFilters.add(FileFilters.PS_FILTER);
    otherFilters.add(FileFilters.EPS_FILTER);
    setDefaultFilterBySuffix(
        Configuration.getString(KEY_DEFAULT_GRAPHICS_FILTER, defaultFilter.getSuffix()));
  }

  /** @param suffix the extension of the new default file-format */
  public void setDefaultFilterBySuffix(String suffix) {
    Iterator i = otherFilters.iterator();
    while (i.hasNext()) {
      SuffixFilter sf = (SuffixFilter) i.next();
      if (sf.getSuffix().equalsIgnoreCase(suffix)) {
        setDefaultFilter(sf);
        break;
      }
    }
  }

  /** @param f the new default file-format */
  public void setDefaultFilter(SuffixFilter f) {
    otherFilters.remove(f);
    if (!otherFilters.contains(defaultFilter)) {
      otherFilters.add(defaultFilter);
    }
    defaultFilter = f;
    Configuration.setString(KEY_DEFAULT_GRAPHICS_FILTER, f.getSuffix());

    Collections.sort(
        otherFilters,
        new Comparator() {
          public int compare(Object arg0, Object arg1) {
            return ((SuffixFilter) arg0)
                .getSuffix()
                .compareToIgnoreCase(((SuffixFilter) arg1).getSuffix());
          }
        });
  }

  /** @return returns the singleton */
  public static SaveGraphicsManager getInstance() {
    if (INSTANCE == null) {
      INSTANCE = new SaveGraphicsManager();
    }
    return INSTANCE;
  }

  /**
   * This function allows to add new filters. This can be done e.g. by modules.
   *
   * <p>
   *
   * @param f the filter
   */
  public void register(SuffixFilter f) {
    otherFilters.add(f);
  }

  /** @param chooser the filechooser of which the filters will be set */
  public void setFileChooserFilters(JFileChooser chooser, String defaultName) {
    chooser.addChoosableFileFilter(defaultFilter);
    Iterator iter = otherFilters.iterator();
    while (iter.hasNext()) {
      chooser.addChoosableFileFilter((SuffixFilter) iter.next());
    }
    chooser.setFileFilter(defaultFilter);
    String fileName = defaultName + "." + defaultFilter.getSuffix();
    chooser.setSelectedFile(new File(fileName));
    chooser.addPropertyChangeListener(
        JFileChooser.FILE_FILTER_CHANGED_PROPERTY,
        new FileFilterChangedListener(chooser, defaultName));
  }

  /**
   * This class listens to changes in the selected filefilter. If the user changes the filefilter
   * (e.g. he changes from *.gif to *.png), then the filename field got emptied before I introduced
   * this class. Now, a new filename is made up, based on the diagram name + the new extension
   * (suffix).
   *
   * @author [email protected]
   */
  class FileFilterChangedListener implements PropertyChangeListener {
    JFileChooser chooser;
    String defaultName;

    public FileFilterChangedListener(JFileChooser c, String name) {
      chooser = c;
      defaultName = name;
    }

    /** @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */
    public void propertyChange(PropertyChangeEvent evt) {
      SuffixFilter filter = (SuffixFilter) evt.getNewValue();
      String fileName = defaultName + "." + filter.getSuffix();
      /* The next line does not work: */
      // chooser.setSelectedFile(new File(fileName));
      /* So, let's do it the hard way: */
      SwingUtilities.invokeLater(new Anonymous1(fileName));
    }

    class Anonymous1 implements Runnable {
      private String fileName;

      Anonymous1(String fn) {
        fileName = fn;
      }

      public void run() {
        chooser.setSelectedFile(new File(fileName));
      }
    }
  }

  /**
   * @param name the filename
   * @return the filter
   */
  public SuffixFilter getFilterFromFileName(String name) {
    if (name.toLowerCase().endsWith("." + defaultFilter.getSuffix())) {
      return defaultFilter;
    }
    Iterator iter = otherFilters.iterator();
    while (iter.hasNext()) {
      SuffixFilter filter = (SuffixFilter) iter.next();
      if (name.toLowerCase().endsWith("." + filter.getSuffix())) {
        return filter;
      }
    }
    return null;
  }

  /** @return the extension of the default filter (just the text, not the ".") */
  public String getDefaultSuffix() {
    return defaultFilter.getSuffix();
  }

  /**
   * @param in the input file or path name which may or may not have a recognised extension
   * @return the amended file or pathname, guaranteed to have a recognised extension
   */
  public String fixExtension(String in) {
    if (getFilterFromFileName(in) == null) {
      in += "." + getDefaultSuffix();
    }
    return in;
  }

  /**
   * @param suffix the suffix (extension) of the filename, which corresponds to the graphics format
   *     to be used
   * @return the command that will do the save
   */
  public CmdSaveGraphics getSaveCommandBySuffix(String suffix) {
    CmdSaveGraphics cmd = null;
    if (FileFilters.PS_FILTER.getSuffix().equals(suffix)) {
      cmd = new CmdSavePS();
    } else if (FileFilters.EPS_FILTER.getSuffix().equals(suffix)) {
      cmd = new ActionSaveGraphicsCmdSaveEPS();
    } else if (FileFilters.PNG_FILTER.getSuffix().equals(suffix)) {
      cmd = new CmdSavePNG();
    } else if (FileFilters.GIF_FILTER.getSuffix().equals(suffix)) {
      cmd = new CmdSaveGIF();
    } else if (FileFilters.SVG_FILTER.getSuffix().equals(suffix)) {
      cmd = new CmdSaveSVG();
    }
    return cmd;
  }

  /** @return the complete collection of SuffixFilters, the first one is the default one */
  public Collection getSettingsList() {
    Collection c = new ArrayList();
    c.add(defaultFilter);
    Iterator iter = otherFilters.iterator();
    while (iter.hasNext()) {
      c.add(((SuffixFilter) iter.next()));
    }
    return c;
  }
}
 public void actionPerformed(ActionEvent event) {
   ProjectBrowser.TheInstance.saveScreenConfiguration();
   if (!Configuration.save()) Configuration.save(true);
 }