iqq.app.core.service.impl.ResourceServiceImpl.java Source code

Java tutorial

Introduction

Here is the source code for iqq.app.core.service.impl.ResourceServiceImpl.java

Source

package iqq.app.core.service.impl;

import iqq.app.core.service.ResourceService;
import org.springframework.stereotype.Service;

import javax.swing.*;
import java.io.File;

/**
 * ???
 *
 * #
 *
 * Project  : iqq
 * Author   :  < 6208317@qq.com >
 * Created  : 14-4-17
 * License  : Apache License 2.0
 */
@Service
public class ResourceServiceImpl implements ResourceService {
    /**
     * ?
     */
    public static final String RESOURCES_DIR = System.getProperty("app.dir", System.getProperty("user.dir"))
            + File.separator + "resources" + File.separator;

    public static final String USER_DIR = "user" + File.separator;

    /**
     * ???
     *
     * @return
     */
    @Override
    public String getResourcePath() {
        return RESOURCES_DIR;
    }

    /**
     * ??
     *
     * @param filename
     * @return
     */
    @Override
    public File getFile(String filename) {
        return new File(RESOURCES_DIR + filename);
    }

    /**
     * ??
     *
     * @param filename
     * @return
     */
    @Override
    public ImageIcon getIcon(String filename) {
        return new ImageIcon(getFile(filename).getAbsolutePath());
    }

    /**
     * ???
     *
     * @param filename
     * @param width
     * @param height
     * @return
     */
    @Override
    public ImageIcon getIcon(String filename, int width, int height) {
        return new ImageIcon(getIcon(filename).getImage().getScaledInstance(width, height, 100));
    }

    /**
     * ?
     *
     * @return
     */
    @Override
    public String getUserPath() {
        return getResourcePath() + USER_DIR;
    }

    /**
     * ??
     *
     * @param filename
     * @return
     */
    @Override
    public File getUserFile(String filename) {
        return new File(RESOURCES_DIR + filename);
    }

    /**
     * ??
     *
     * @param filename
     * @return
     */
    @Override
    public ImageIcon getUserIcon(String filename) {
        return new ImageIcon(getUserFile(filename).getAbsolutePath());
    }

    /**
     * ???
     *
     * @param filename
     * @param width
     * @param height
     * @return
     */
    @Override
    public ImageIcon getUserIcon(String filename, int width, int height) {
        return new ImageIcon(getUserIcon(filename).getImage().getScaledInstance(width, height, 100));
    }
}