<commit_before>/*
 * File   : $Source: /alkacon/cvs/opencms/src-components/org/opencms/applet/upload/ImageFileView.java,v $
 * Date   : $Date: 2009/06/04 14:36:24 $
 * Version: $Revision: 1.14 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 2002 - 2009 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.applet.upload;

import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.StringTokenizer;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.filechooser.FileView;

/**
 * Image File View class, plugs image preview into the file selector box.<p>
 * 
 * Based on the Java 1.4 example.<p>
 * 
 * @author <NAME> 
 *
 * @version $Revision: 1.14 $ 
 * 
 * @since 6.0.0 
 */
public class ImageFileView extends FileView {

    /** Extension storage. */
    private HashMap m_extensions;

    /** The path to OpenCms, required to read the images. */
    private String m_opencms;

    /**
     * Creates a new ImageFile Vew object.<p>
     */
    public ImageFileView() {

        super();
    }

    /**
     * Creates a new ImageFile Vew object.<p>
     * 
     * @param opencms the complete path to opencms
     * @param fileExtensions list of file extensions to select the correct icons
     */
    public ImageFileView(String opencms, String fileExtensions) {

        super();

        m_opencms = opencms;
        m_extensions = extractExtensions(fileExtensions);

    }

    /**
     * @see javax.swing.filechooser.FileView#getDescription(java.io.File)
     */
    public String getDescription(File f) {

        return null;
    }

    /**
     * @see javax.swing.filechooser.FileView#getIcon(java.io.File)
     */
    public Icon getIcon(File f) {

        String extension = FileUploadUtils.getExtension(f);
        // set the default icon
        Icon icon = null;

        if (f.isDirectory()) {

            icon = (Icon)m_extensions.get("FOLDER");
        } else {

            icon = (Icon)m_extensions.get(extension);
        }
        // if no icon was found, set it to the default
        if (icon == null) {

            icon = (Icon)m_extensions.get("txt");
        }

        return icon;
    }

    /**
     * @see javax.swing.filechooser.FileView#getName(java.io.File)
     */
    public String getName(File f) {

        return null;
    }

    /**
     * @see javax.swing.filechooser.FileView#isTraversable(java.io.File)
     */
    public Boolean isTraversable(File f) {

        return null;
    }

    /**
     * Returns a resource image icon for a given path. <p>
     * 
     * The resource icon is chossen by the resource path, i.g. the resource type.
     * 
     * @param path the path of the resource
     * @return ImageIcon, or null if the path was invalid
     */
    private ImageIcon createImageIcon(String path) {

        try {
            URL imgURL = new URL(path);
            ImageIcon img = new ImageIcon(imgURL);
            return img;
        } catch (Exception e) {<commit_msg>- Typos by Mr. Emmerich... again.<commit_after>/*
 * File   : $Source: /alkacon/cvs/opencms/src-components/org/opencms/applet/upload/ImageFileView.java,v $
 * Date   : $Date: 2009/06/05 15:41:53 $
 * Version: $Revision: 1.15 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 2002 - 2009 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.applet.upload;

import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.StringTokenizer;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.filechooser.FileView;

/**
 * Image File View class, plugs image preview into the file selector box.<p>
 * 
 * Based on the Java 1.4 example.<p>
 * 
 * @author <NAME> 
 *
 * @version $Revision: 1.15 $ 
 * 
 * @since 6.0.0 
 */
public class ImageFileView extends FileView {

    /** Extension storage. */
    private HashMap m_extensions;

    /** The path to OpenCms, required to read the images. */
    private String m_opencms;

    /**
     * Creates a new ImageFile View object.<p>
     */
    public ImageFileView() {

        super();
    }

    /**
     * Creates a new ImageFile Vew object.<p>
     * 
     * @param opencms the complete path to opencms
     * @param fileExtensions list of file extensions to select the correct icons
     */
    public ImageFileView(String opencms, String fileExtensions) {

        super();

        m_opencms = opencms;
        m_extensions = extractExtensions(fileExtensions);

    }

    /**
     * @see javax.swing.filechooser.FileView#getDescription(java.io.File)
     */
    public String getDescription(File f) {

        return null;
    }

    /**
     * @see javax.swing.filechooser.FileView#getIcon(java.io.File)
     */
    public Icon getIcon(File f) {

        String extension = FileUploadUtils.getExtension(f);
        // set the default icon
        Icon icon = null;

        if (f.isDirectory()) {

            icon = (Icon)m_extensions.get("FOLDER");
        } else {

            icon = (Icon)m_extensions.get(extension);
        }
        // if no icon was found, set it to the default
        if (icon == null) {

            icon = (Icon)m_extensions.get("txt");
        }

        return icon;
    }

    /**
     * @see javax.swing.filechooser.FileView#getName(java.io.File)
     */
    public String getName(File f) {

        return null;
    }

    /**
     * @see javax.swing.filechooser.FileView#isTraversable(java.io.File)
     */
    public Boolean isTraversable(File f) {

        return null;
    }

    /**
     * Returns a resource image icon for a given path. <p>
     * 
     * The resource icon is chosen by the resource path, i.g. the resource type.
     * 
     * @param path the path of the resource
     * @return ImageIcon, or null if the path was invalid
     */
    private ImageIcon createImageIcon(String path) {

        try {
            URL imgURL = new URL(path);
            ImageIcon img = new ImageIcon(imgURL);
            return img;
        } catch (Exception e) {
{'fraction_non_alphanumeric': 0.09990059642147117, 'fraction_numerical': 0.012176938369781311, 'mean_word_length': 2.5026109660574414, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7485439', 'n_tokens_mistral': 2468, 'n_tokens_neox': 2308, 'n_words': 801}