Exemplo n.º 1
0
 /** @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));
 }
Exemplo n.º 2
0
 /** @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;
     }
   }
 }
Exemplo n.º 3
0
 /**
  * @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;
 }
Exemplo n.º 4
0
 /** 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()));
 }
Exemplo n.º 5
0
 /** @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));
 }
Exemplo n.º 6
0
  /** @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());
          }
        });
  }
Exemplo n.º 7
0
 /** @return the extension of the default filter (just the text, not the ".") */
 public String getDefaultSuffix() {
   return defaultFilter.getSuffix();
 }