⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svborder.java

📁 java 读写word excel ppt
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ====================================================================   Licensed to the Apache Software Foundation (ASF) 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.apache.poi.hssf.contrib.view;import java.awt.*;import javax.swing.border.AbstractBorder;import org.apache.poi.hssf.usermodel.HSSFCellStyle;/** * This is an attempt to implement Excel style borders for the SheetViewer. * Mostly just overrides stuff so the javadoc won't appear here but will  * appear in the generated stuff. *  * @author Andrew C. Oliver (acoliver at apache dot org) * @author Jason Height */public class SVBorder extends AbstractBorder {  private Color northColor = null;  private Color eastColor = null;  private Color southColor = null;  private Color westColor = null;  private int northBorderType = HSSFCellStyle.BORDER_NONE;  private int eastBorderType =HSSFCellStyle.BORDER_NONE;  private int southBorderType = HSSFCellStyle.BORDER_NONE;  private int westBorderType = HSSFCellStyle.BORDER_NONE;  private boolean northBorder=false;  private boolean eastBorder=false;  private boolean southBorder=false;  private boolean westBorder=false;  private boolean selected = false;   public void setBorder(Color northColor, Color eastColor,                         Color southColor, Color westColor,                         int northBorderType, int eastBorderType,                         int southBorderType, int westBorderType,                         boolean selected) {     this.eastColor = eastColor;     this.southColor = southColor;     this.westColor = westColor;     this.northBorderType = northBorderType;     this.eastBorderType = eastBorderType;     this.southBorderType = southBorderType;     this.westBorderType = westBorderType;     this.northBorder=northBorderType != HSSFCellStyle.BORDER_NONE;     this.eastBorder=eastBorderType != HSSFCellStyle.BORDER_NONE;     this.southBorder=southBorderType != HSSFCellStyle.BORDER_NONE;     this.westBorder=westBorderType != HSSFCellStyle.BORDER_NONE;     this.selected = selected;   }   public void paintBorder(Component c, Graphics g, int x, int y, int width,                           int height) {      Color oldColor = g.getColor();     paintSelectedBorder(g, x, y, width, height);     paintNormalBorders(g, x, y, width, height);     paintDottedBorders(g, x, y, width, height);     paintDashedBorders(g, x, y, width, height);     paintDoubleBorders(g, x, y, width, height);     paintDashDotDotBorders(g, x, y, width, height);     g.setColor(oldColor);   }   /**    * Called by paintBorder to paint the border of a selected cell.    * The paramaters are the Graphics object, location and dimensions of the     * cell.    */   private void paintSelectedBorder(Graphics g, int x, int y, int width,                                  int height) {     if (selected) {       //Need to setup thickness of 2       g.setColor(Color.black);       //paint the border       g.drawRect(x,y,width-1,height-1);       //paint the filled rectangle at the bottom left hand position       g.fillRect(x+width-5, y+height-5, 5, 5);     }   }   /**    * Called by paintBorder to paint the various versions of normal line    * borders for a cell.      */   private void paintNormalBorders(Graphics g, int x, int y, int width,                                  int height) {      if (northBorder &&             ((northBorderType == HSSFCellStyle.BORDER_THIN) ||              (northBorderType == HSSFCellStyle.BORDER_MEDIUM) ||              (northBorderType == HSSFCellStyle.BORDER_THICK)             )         ) {        int thickness = getThickness(northBorderType);      	g.setColor(northColor);        for (int k=0; k < thickness; k++) {           g.drawLine(x,y+k,width,y+k);        }      }      if (eastBorder &&             ((eastBorderType == HSSFCellStyle.BORDER_THIN) ||              (eastBorderType == HSSFCellStyle.BORDER_MEDIUM) ||              (eastBorderType == HSSFCellStyle.BORDER_THICK)             )         ) {        int thickness = getThickness(eastBorderType);      	g.setColor(eastColor);        for (int k=0; k < thickness; k++) {           g.drawLine(width-k,y,width-k,height);        }      }      if (southBorder &&              ((southBorderType == HSSFCellStyle.BORDER_THIN) ||               (southBorderType == HSSFCellStyle.BORDER_MEDIUM) ||               (southBorderType == HSSFCellStyle.BORDER_THICK)              )         ) {        int thickness = getThickness(southBorderType);      	g.setColor(southColor);        for (int k=0; k < thickness; k++) {           g.drawLine(x,height - k,width,height - k);        }      }      if (westBorder &&             ((westBorderType == HSSFCellStyle.BORDER_THIN) ||              (westBorderType == HSSFCellStyle.BORDER_MEDIUM) ||              (westBorderType == HSSFCellStyle.BORDER_THICK)             )         ) {        int thickness = getThickness(westBorderType);      	g.setColor(westColor);        for (int k=0; k < thickness; k++) {           g.drawLine(x+k,y,x+k,height);        }      }   }   /**    * Called by paintBorder to paint the dotted line    * borders for a cell.      */   private void paintDottedBorders(Graphics g, int x, int y, int width,                                  int height) {      if (northBorder &&             northBorderType == HSSFCellStyle.BORDER_DOTTED) {        int thickness = getThickness(northBorderType);      	g.setColor(northColor);        for (int k=0; k < thickness; k++) {           for (int xc = x; xc < width; xc=xc+2) {             g.drawLine(xc,y+k,xc,y+k);           }        }      }      if (eastBorder &&              eastBorderType == HSSFCellStyle.BORDER_DOTTED         ) {        int thickness = getThickness(eastBorderType);        thickness++; //need for dotted borders to show up east      	g.setColor(eastColor);        for (int k=0; k < thickness; k++) {           for (int yc=y;yc < height; yc=yc+2) {                g.drawLine(width-k,yc,width-k,yc);           }        }      }      if (southBorder &&              southBorderType == HSSFCellStyle.BORDER_DOTTED         ) {        int thickness = getThickness(southBorderType);        thickness++;      	g.setColor(southColor);        for (int k=0; k < thickness; k++) {           for (int xc = x; xc < width; xc=xc+2) {             g.drawLine(xc,height-k,xc,height-k);           }        }      }      if (westBorder &&            westBorderType == HSSFCellStyle.BORDER_DOTTED         ) {        int thickness = getThickness(westBorderType);//        thickness++;      	g.setColor(westColor);        for (int k=0; k < thickness; k++) {           for (int yc=y;yc < height; yc=yc+2) {                g.drawLine(x+k,yc,x+k,yc);           }        }      }   }   /**    * Called by paintBorder to paint the various versions of dotted line    * borders for a cell.      */   private void paintDashedBorders(Graphics g, int x, int y, int width,                                  int height) {      if (northBorder &&             ((northBorderType == HSSFCellStyle.BORDER_DASHED) ||              (northBorderType == HSSFCellStyle.BORDER_HAIR))         ) {        int thickness = getThickness(northBorderType);        int dashlength = 1;        if (northBorderType == HSSFCellStyle.BORDER_DASHED)           dashlength = 2;      	g.setColor(northColor);        for (int k=0; k < thickness; k++) {           for (int xc = x; xc < width; xc=xc+5) {             g.drawLine(xc,y+k,xc+dashlength,y+k);           }        }      }      if (eastBorder &&              ((eastBorderType == HSSFCellStyle.BORDER_DASHED) ||               (eastBorderType == HSSFCellStyle.BORDER_HAIR))         ) {        int thickness = getThickness(eastBorderType);        thickness++; //need for dotted borders to show up east        int dashlength = 1;        if (eastBorderType == HSSFCellStyle.BORDER_DASHED)           dashlength = 2;      	g.setColor(eastColor);        for (int k=0; k < thickness; k++) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -