
com.xiongyingqi.captcha.service.AbstractCaptchaService Maven / Gradle / Ivy
/*
* Copyright (c) 2009 Piotr Piastucki
*
* This file is part of Patchca CAPTCHA library.
*
* Patchca 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 3 of the License, or
* (at your option) any later version.
*
* Patchca 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Patchca. If not, see .
*/
package com.xiongyingqi.captcha.service;
import com.xiongyingqi.captcha.background.BackgroundFactory;
import com.xiongyingqi.captcha.color.ColorFactory;
import com.xiongyingqi.captcha.filter.FilterFactory;
import com.xiongyingqi.captcha.font.FontFactory;
import com.xiongyingqi.captcha.text.renderer.TextRenderer;
import com.xiongyingqi.captcha.word.WordFactory;
import java.awt.image.BufferedImage;
public abstract class AbstractCaptchaService implements CaptchaService {
protected FontFactory fontFactory;
protected WordFactory wordFactory;
protected ColorFactory colorFactory;
protected BackgroundFactory backgroundFactory;
protected TextRenderer textRenderer;
protected FilterFactory filterFactory;
protected int width;
protected int height;
public void setFontFactory(FontFactory fontFactory) {
this.fontFactory = fontFactory;
}
public void setWordFactory(WordFactory wordFactory) {
this.wordFactory = wordFactory;
}
public void setColorFactory(ColorFactory colorFactory) {
this.colorFactory = colorFactory;
}
public void setBackgroundFactory(BackgroundFactory backgroundFactory) {
this.backgroundFactory = backgroundFactory;
}
public void setTextRenderer(TextRenderer textRenderer) {
this.textRenderer = textRenderer;
}
public void setFilterFactory(FilterFactory filterFactory) {
this.filterFactory = filterFactory;
}
public FontFactory getFontFactory() {
return fontFactory;
}
public WordFactory getWordFactory() {
return wordFactory;
}
public ColorFactory getColorFactory() {
return colorFactory;
}
public BackgroundFactory getBackgroundFactory() {
return backgroundFactory;
}
public TextRenderer getTextRenderer() {
return textRenderer;
}
public FilterFactory getFilterFactory() {
return filterFactory;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
@Override
public Captcha getCaptcha() {
BufferedImage bufImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
backgroundFactory.fillBackground(bufImage);
String word = wordFactory.getNextWord();
textRenderer.draw(word, bufImage, fontFactory, colorFactory);
bufImage = filterFactory.applyFilters(bufImage);
return new Captcha(word, bufImage);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy