1 /* 2 * Copyright (C) 2015 Jack Jiang(cngeeker.com) The BeautyEye Project. 3 * All rights reserved. 4 * Project URL:https://github.com/JackJiang2011/beautyeye 5 * Version 3.6 6 * 7 * Jack Jiang PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 8 * 9 * NinePatchBorder.java at 2015-2-1 20:25:36, original version by Jack Jiang. 10 * You can contact author with jb2011@163.com. 11 */ 12 package org.jb2011.lnf.beautyeye.widget.border; 13 14 import java.awt.Component; 15 import java.awt.Graphics; 16 import java.awt.Graphics2D; 17 import java.awt.Insets; 18 19 import javax.swing.border.AbstractBorder; 20 21 import org.jb2011.ninepatch4j.NinePatch; 22 23 /** 24 * 一个利用NinePatch图实现边框的border实现类. 25 * <p> 26 * 本类可以很好地被重用于NinePatch图作为border实现的场景哦. 27 * 28 * @author Jack Jiang(jb2011@163.com), 2012-09-04 29 * @version 1.0 30 */ 31 public class NinePatchBorder extends AbstractBorder 32 { 33 34 /** The insets. */ 35 private Insets insets = null; 36 37 /** The np. */ 38 private NinePatch np = null; 39 40 /** 41 * Instantiates a new nine patch border. 42 * 43 * @param insets the insets 44 * @param np the np 45 */ 46 public NinePatchBorder(Insets insets, NinePatch np) 47 { 48 this.insets = insets; 49 this.np = np; 50 } 51 52 /* (non-Javadoc) 53 * @see javax.swing.border.AbstractBorder#getBorderInsets(java.awt.Component) 54 */ 55 public Insets getBorderInsets(Component c) 56 { 57 return insets; 58 } 59 60 /* (non-Javadoc) 61 * @see javax.swing.border.AbstractBorder#getBorderInsets(java.awt.Component, java.awt.Insets) 62 */ 63 public Insets getBorderInsets(Component c, Insets insets) 64 { 65 return insets; 66 } 67 68 /* (non-Javadoc) 69 * @see javax.swing.border.AbstractBorder#paintBorder(java.awt.Component, java.awt.Graphics, int, int, int, int) 70 */ 71 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) 72 { 73 this.np.draw((Graphics2D)g, x, y, width, height); 74 } 75 }