All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.randelshofer.quaqua.filechooser.FilenameDocument Maven / Gradle / Ivy

Go to download

A Mavenisation of the Quaqua Mac OSX Swing Look and Feel (Java library) Quaqua Look and Feel (C) 2003-2010, Werner Randelshofer. Mavenisation by Matt Gumbley, DevZendo.org - for problems with Mavenisation, see Matt; for issues with Quaqua, see the Quaqua home page. For full license details, see http://randelshofer.ch/quaqua/license.html

The newest version!
/*
 * @(#)FilenameDocument.java  
 * 
 * Copyright (c) 2010 Werner Randelshofer, Immensee, Switzerland.
 * All rights reserved.
 * 
 * You may not use, copy or modify this file, except in compliance with the
 * license agreement you entered into with Werner Randelshofer.
 * For details see accompanying license terms.
 */
package ch.randelshofer.quaqua.filechooser;

import ch.randelshofer.quaqua.QuaquaManager;
import java.util.HashSet;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

/**
 * A document model which silently converts forbidden filename characters
 * into dashes.
 * 

* On Mac OS X, only the colon character is forbidden: {@code : }. *

* On Windows, the following characters are forbidden: {@code \ / : * ? " < > | } *

* On other operating systems, no characters are converted. * * @author Werner Randelshofer * @version $Id: FilenameDocument.java 363 2010-11-21 17:41:04Z wrandelshofer $ */ public class FilenameDocument extends PlainDocument { private HashSet forbidden; public FilenameDocument() { forbidden = new HashSet(); int os = QuaquaManager.getOS(); if (os >= QuaquaManager.CHEETAH) { forbidden.add(':'); } else if (os == QuaquaManager.WINDOWS) { forbidden.add('\\'); forbidden.add('/'); forbidden.add(':'); forbidden.add('*'); forbidden.add('?'); forbidden.add('"'); forbidden.add('<'); forbidden.add('>'); } } @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { char[] chars = str.toCharArray(); for (int i = 0; i < chars.length; i++) { if (forbidden.contains(chars[i])) { chars[i] = '-'; } } super.insertString(offs, new String(chars), a); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy