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

VAqua.src.org.violetlib.aqua.fc.FilenameDocument Maven / Gradle / Ivy

The newest version!
/*
 * @(#)FilenameDocument.java
 *
 * Copyright (c) 2010 Werner Randelshofer, 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 org.violetlib.aqua.fc;

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
import java.util.HashSet;

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

* On Mac OS X, only the colon character is forbidden: {@code : }. * * @author Werner Randelshofer * @version $Id$ */ public class FilenameDocument extends PlainDocument { private HashSet forbidden; public FilenameDocument() { forbidden = new HashSet(); 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 - 2025 Weber Informatics LLC | Privacy Policy