001/* 002 * Copyright 2024-2025, Warm-Flow (290631660@qq.com). 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.dromara.warm.flow.core.chart; 017 018import org.dromara.warm.flow.core.utils.DrawUtils; 019import org.dromara.warm.flow.core.utils.ObjectUtil; 020import org.dromara.warm.flow.core.utils.StringUtils; 021 022import java.awt.*; 023 024/** 025 * 流程图开始或者结束节点 026 */ 027public class OvalChart implements FlowChart { 028 private int n; 029 030 private int xStartOval; 031 032 private int yStartOval; 033 034 private Color c; 035 036 private TextChart textChart; 037 038 public OvalChart() { 039 } 040 041 public OvalChart(int xStartOval, int yStartOval, Color c, TextChart textChart) { 042 this.xStartOval = xStartOval; 043 this.yStartOval = yStartOval; 044 this.c = c; 045 this.textChart = textChart; 046 } 047 048 public int getN() { 049 return n; 050 } 051 052 public OvalChart setN(int n) { 053 this.n = n; 054 return this; 055 } 056 057 public int getxStartOval() { 058 return xStartOval; 059 } 060 061 public OvalChart setxStartOval(int xStartOval) { 062 this.xStartOval = xStartOval; 063 return this; 064 } 065 066 public int getyStartOval() { 067 return yStartOval; 068 } 069 070 public OvalChart setyStartOval(int yStartOval) { 071 this.yStartOval = yStartOval; 072 return this; 073 } 074 075 public Color getC() { 076 return c; 077 } 078 079 public OvalChart setC(Color c) { 080 this.c = c; 081 return this; 082 } 083 084 public TextChart getTextChart() { 085 return textChart; 086 } 087 088 public OvalChart setTextChart(TextChart textChart) { 089 this.textChart = textChart; 090 return this; 091 } 092 093 @Override 094 public void draw(Graphics2D graphics) { 095 graphics.setColor(c); 096 graphics.drawOval((xStartOval - 20) * n, (yStartOval - 20) * n, 40 * n, 40 * n); 097 if (ObjectUtil.isNotNull(textChart) && StringUtils.isNotEmpty(textChart.getTitle())) { 098 textChart.setxText(textChart.getxText() - DrawUtils.stringWidth(graphics, textChart.getTitle()) / 2); 099 textChart.setyText(textChart.getyText() + 5); 100 // 填充文字说明 101 textChart.setN(n).draw(graphics); 102 } 103 } 104}