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

org.nervousync.beans.image.MarkOptions Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
/*
 * Licensed to the Nervousync Studio (NSYC) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.nervousync.beans.image;

import java.awt.Color;
import java.awt.Image;

import javax.swing.ImageIcon;

import org.nervousync.commons.Globals;

/**
 * 

Mark options of image mark operate

*

用于图片水印操作的剪切选项

* * @author Steven Wee [email protected] * @version $Revision: 1.1.2 $ $Date: Dec 10, 2021 16:11:01 $ */ public final class MarkOptions { /** *

Mark type. Value of MarkOptions.MarkType enumeration

*

水印类型,MarkOptions.MarkType的枚举值

* @see MarkOptions.MarkType */ private final MarkType markType; /** *

Mark location. Instance of MarkOptions.MarkLocation

*

水印位置,MarkOptions.MarkLocation实例对象

* @see MarkOptions.MarkLocation */ private final MarkLocation markLocation; /** *

Mark image path. Only using when markType is MarkType.ICON

*

水印图片地址,仅当markType值为MarkType.ICON时有效

*/ private final String markPath; /** *

Transparent value of mark image. default is 1, valid value is between 0 and 1

*

水印图片的透明度,默认值为1,有效值在0到1之间

*/ private final float transparency; /** *

Mark text value. Only using when markType is MarkType.TEXT

*

水印文字,仅当markType值为MarkType.TEXT时有效

*/ private final String markText; /** *

Mark text color settings.

*

水印文字的颜色值

*/ private final Color color; /** *

Mark text font name settings.

*

水印文字的字体名

*/ private final String fontName; /** *

Mark text font size settings.

*

水印文字的字号

*/ private final int fontSize; /** *

Constructor for MarkOptions

*

CutOptions的构造方法

* * @param markType Mark type. Value of MarkOptions.MarkType enumeration * 水印类型,MarkOptions.MarkType的枚举值 * @param markLocation Mark location. Instance of MarkOptions.MarkLocation * * 水印位置,MarkOptions.MarkLocation实例对象 * @param markPath Mark image path. Only using when markType is MarkType.ICON * 水印图片地址,仅当markType值为MarkType.ICON时有效 * @param transparency Transparent value of mark image. default is 1, valid value is between 0 and 1 * 水印图片的透明度,默认值为1,有效值在0到1之间 * @param markText Mark text value. Only using when markType is MarkType.TEXT * 水印文字,仅当markType值为MarkType.TEXT时有效 * @param color Mark text color settings. * 水印文字的颜色值 * @param fontName Mark text font name settings. * 水印文字的字体名 * @param fontSize Mark text font size settings. * 水印文字的字号 */ private MarkOptions(final MarkType markType, final MarkLocation markLocation, final String markPath, final float transparency, final String markText, final Color color, final String fontName, final int fontSize) { this.markType = markType; this.markLocation = markLocation; this.markPath = markPath; this.transparency = transparency; this.markText = markText; this.color = color; this.fontName = fontName; this.fontSize = fontSize; } /** *

Static method for initialize Icon MarkOptions

*

用于初始化图片水印MarkOptions的静态方法

* * @param markLocation Mark location. Instance of MarkOptions.MarkLocation * * 水印位置,MarkOptions.MarkLocation实例对象 * @param markPath Mark image path. Only using when markType is MarkType.ICON * 水印图片地址,仅当markType值为MarkType.ICON时有效 * @param transparency Transparent value of mark image. default is 1, valid value is between 0 and 1 * 水印图片的透明度,默认值为1,有效值在0到1之间 * @return Initialized MarkOptions instance * 初始化的MarkOptions实例对象 */ public static MarkOptions markIcon(final MarkLocation markLocation, final String markPath, final float transparency) { return new MarkOptions(MarkType.ICON, markLocation, markPath, transparency, null, null, null, Globals.DEFAULT_VALUE_INT); } /** *

Static method for initialize Text MarkOptions

*

用于初始化文字水印MarkOptions的静态方法

* Initialize TEXT MarkOptions * * @param markLocation Mark location. Instance of MarkOptions.MarkLocation * * 水印位置,MarkOptions.MarkLocation实例对象 * @param markText Mark text value. Only using when markType is MarkType.TEXT * 水印文字,仅当markType值为MarkType.TEXT时有效 * @param color Mark text color settings. * 水印文字的颜色值 * @param fontName Mark text font name settings. * 水印文字的字体名 * @param fontSize Mark text font size settings. * 水印文字的字号 * @return Initialized MarkOptions instance * 初始化的MarkOptions实例对象 */ public static MarkOptions markText(final MarkLocation markLocation, final String markText, final Color color, final String fontName, final int fontSize) { return new MarkOptions(MarkType.TEXT, markLocation, null, Globals.DEFAULT_VALUE_FLOAT, markText, color, fontName, fontSize); } /** *

Getter method for mark type

*

水印类型的Getter方法

* * @return Value of mark type * 水印类型值 */ public MarkType getMarkType() { return markType; } /** *

Getter method for mark location

*

水印坐标的Getter方法

* * @return Value of mark location * 水印坐标实例对象 */ public MarkLocation getMarkLocation() { return markLocation; } /** *

Getter method for mark image path

*

水印图片地址的Getter方法

* * @return Value of mark image path * 水印图片地址 */ public String getMarkPath() { return markPath; } /** *

Getter method for mark image transparency value

*

水印透明度值的Getter方法

* * @return Value of mark image transparency value * 水印透明度值 */ public float getTransparency() { return transparency; } /** *

Getter method for mark text value

*

水印文字值的Getter方法

* * @return Value of mark text value * 水印文字值 */ public String getMarkText() { return markText; } /** *

Getter method for mark text color value

*

水印文字颜色值的Getter方法

* * @return Value of mark text color value * 水印文字颜色值 */ public Color getColor() { return color; } /** *

Getter method for mark text font name

*

水印文字字体名称的Getter方法

* * @return Value of mark text font name * 水印文字字体名称 */ public String getFontName() { return fontName; } /** *

Getter method for mark text font size

*

水印文字字号的Getter方法

* * @return Value of mark text font size * 水印文字字号 */ public int getFontSize() { return fontSize; } /** *

Calculate and generate MarkPosition by given image width and height

*

根据给定的图片尺寸,计算并生成水印位置的MarkPosition实例对象

* * @param width Image width value * 图片的宽度 * @param height Image height value * 图片的高度 * @return Initialized MarkPosition instance * 初始化的MarkPosition实例对象 */ public MarkPosition retrievePosition(int width, int height) { int positionX = Globals.DEFAULT_VALUE_INT; int positionY = Globals.DEFAULT_VALUE_INT; switch (this.markType) { case ICON: ImageIcon imageIcon = new ImageIcon(this.markPath); Image iconImg = imageIcon.getImage(); if (iconImg != null && this.transparency >= 0 && this.transparency <= 1) { switch (this.markLocation) { case LEFT_TOP: positionX = Globals.INITIALIZE_INT_VALUE; positionY = Globals.INITIALIZE_INT_VALUE; break; case TOP: positionX = (width - iconImg.getWidth(null)) / 2; positionY = Globals.INITIALIZE_INT_VALUE; break; case RIGHT_TOP: positionX = width - iconImg.getWidth(null); positionY = Globals.INITIALIZE_INT_VALUE; break; case LEFT: positionX = Globals.INITIALIZE_INT_VALUE; positionY = (height - iconImg.getHeight(null)) / 2; break; case CENTER: positionX = (width - iconImg.getWidth(null)) / 2; positionY = (height - iconImg.getHeight(null)) / 2; break; case RIGHT: positionX = width - iconImg.getWidth(null); positionY = (height - iconImg.getHeight(null)) / 2; break; case LEFT_BOTTOM: positionX = 0; positionY = height - iconImg.getHeight(null); break; case BOTTOM: positionX = (width - iconImg.getWidth(null)) / 2; positionY = height - iconImg.getHeight(null); break; case RIGHT_BOTTOM: positionX = width - iconImg.getWidth(null); positionY = height - iconImg.getHeight(null); break; } } break; case TEXT: if (this.markText != null && this.fontName != null && this.fontSize > 0) { int textWidth = this.markText.length() * this.fontSize; int textHeight = this.fontSize; switch (this.markLocation) { case LEFT_TOP: positionX = 0; positionY = textHeight; break; case TOP: positionX = (width - textWidth) / 2; positionY = textHeight; break; case RIGHT_TOP: positionX = width - textWidth; positionY = textHeight; break; case LEFT: positionX = 0; positionY = (height + textHeight) / 2; break; case CENTER: positionX = (width - textWidth) / 2; positionY = (height + textHeight) / 2; break; case RIGHT: positionX = width - textWidth; positionY = (height + textHeight) / 2; break; case LEFT_BOTTOM: positionX = 0; positionY = height; break; case BOTTOM: positionX = (width - textWidth) / 2; positionY = height; break; case RIGHT_BOTTOM: positionX = width - textWidth; positionY = height; break; } } break; } if (positionX != Globals.DEFAULT_VALUE_INT && positionY != Globals.DEFAULT_VALUE_INT) { return new MarkPosition(positionX, positionY); } return null; } /** *

MarkPosition define

*

MarkPosition定义

*/ public static final class MarkPosition { /** *

Mark position value X

*

水印起始X坐标

*/ private final int positionX; /** *

Mark position value Y

*

水印起始Y坐标

*/ private final int positionY; /** *

Constructor for MarkPosition

*

MarkPosition构造方法

* * @param positionX Mark position value X * 水印起始X坐标 * @param positionY Mark position value Y * 水印起始Y坐标 */ public MarkPosition(int positionX, int positionY) { this.positionX = positionX; this.positionY = positionY; } /** *

Getter method for position X

*

起始X坐标的Getter方法

* * @return Value of begin position X * 起始X坐标值 */ public int getPositionX() { return positionX; } /** *

Getter method for position Y

*

起始Y坐标的Getter方法

* * @return Value of begin position Y * 起始Y坐标值 */ public int getPositionY() { return positionY; } } /** *

Enumeration define for MarkType

*

MarkType枚举类定义

*/ public enum MarkType { /** *

Icon mark

*

图片水印

*/ ICON, /** *

Text mark

*

文字水印

*/ TEXT } /** *

Enumeration define for MarkLocation

*

MarkLocation枚举类定义

*/ public enum MarkLocation { /** * Location: Top and Left * 水印位置:左上方 */ LEFT_TOP, /** * Location: Top and middle * 水印位置:正上方 */ TOP, /** * Location: Top and Right * 水印位置:右上方 */ RIGHT_TOP, /** * Location: Middle and Left * 水印位置:左侧垂直居中 */ LEFT, /** * Location: Center * 水印位置:正中间 */ CENTER, /** * Location: Middle and Right * 水印位置:右侧垂直居中 */ RIGHT, /** * Location: Bottom and Left * 水印位置:左下方 */ LEFT_BOTTOM, /** * Location: Bottom and Middle * 水印位置:下方居中 */ BOTTOM, /** * Location: Bottom and Right * 水印位置:右下方 */ RIGHT_BOTTOM } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy