forked from fanruan/design
hzzz
8 years ago
1 changed files with 170 additions and 170 deletions
@ -1,171 +1,171 @@ |
|||||||
package com.fr.design.mainframe; |
package com.fr.design.mainframe; |
||||||
|
|
||||||
import com.fr.base.BaseUtils; |
import com.fr.base.BaseUtils; |
||||||
import com.fr.base.Style; |
import com.fr.base.Style; |
||||||
import com.fr.design.actions.ElementCaseAction; |
import com.fr.design.actions.ElementCaseAction; |
||||||
import com.fr.general.Inter; |
import com.fr.general.Inter; |
||||||
import com.fr.grid.selection.CellSelection; |
import com.fr.grid.selection.CellSelection; |
||||||
import com.fr.grid.selection.Selection; |
import com.fr.grid.selection.Selection; |
||||||
import com.fr.report.cell.DefaultTemplateCellElement; |
import com.fr.report.cell.DefaultTemplateCellElement; |
||||||
import com.fr.report.cell.TemplateCellElement; |
import com.fr.report.cell.TemplateCellElement; |
||||||
import com.fr.report.elementcase.TemplateElementCase; |
import com.fr.report.elementcase.TemplateElementCase; |
||||||
|
|
||||||
import javax.swing.*; |
import javax.swing.*; |
||||||
import java.awt.*; |
import java.awt.*; |
||||||
import java.awt.event.KeyEvent; |
import java.awt.event.KeyEvent; |
||||||
|
|
||||||
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; |
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; |
||||||
|
|
||||||
/** |
/** |
||||||
* Author : daisy |
* Author : daisy |
||||||
* Date: 13-8-7 |
* Date: 13-8-7 |
||||||
* Time: 上午11:05 |
* Time: 上午11:05 |
||||||
*/ |
*/ |
||||||
public class FormatBrushAction extends ElementCaseAction { |
public class FormatBrushAction extends ElementCaseAction { |
||||||
|
|
||||||
private ElementCasePane ePane; |
private ElementCasePane ePane; |
||||||
private CellSelection oldSelection; |
private CellSelection oldSelection; |
||||||
|
|
||||||
|
|
||||||
public FormatBrushAction(ElementCasePane t) { |
public FormatBrushAction(ElementCasePane t) { |
||||||
super(t); |
super(t); |
||||||
this.setName(Inter.getLocText("M_Edit-FormatBrush")); |
this.setName(Inter.getLocText("M_Edit-FormatBrush")); |
||||||
this.setMnemonic('B'); |
this.setMnemonic('B'); |
||||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/formatBrush.png")); |
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/formatBrush.png")); |
||||||
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, DEFAULT_MODIFIER)); |
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, DEFAULT_MODIFIER)); |
||||||
} |
} |
||||||
|
|
||||||
public boolean executeActionReturnUndoRecordNeeded() { |
public boolean executeActionReturnUndoRecordNeeded() { |
||||||
ePane = (ElementCasePane) getEditingComponent(); |
ePane = (ElementCasePane) getEditingComponent(); |
||||||
if (ePane != null) { |
if (ePane != null) { |
||||||
Selection selection = ePane.getSelection(); |
Selection selection = ePane.getSelection(); |
||||||
if (!(selection instanceof CellSelection)) { |
if (!(selection instanceof CellSelection)) { |
||||||
return false; |
return false; |
||||||
} |
} |
||||||
oldSelection = ((CellSelection) selection).clone(); |
oldSelection = ((CellSelection) selection).clone(); |
||||||
ePane.setFormatReferencedCell(oldSelection); |
ePane.setFormatReferencedCell(oldSelection); |
||||||
int cellRectangleCount = oldSelection.getCellRectangleCount(); |
int cellRectangleCount = oldSelection.getCellRectangleCount(); |
||||||
if (cellRectangleCount > 1) { |
if (cellRectangleCount > 1) { |
||||||
//格式刷只支持单次选择的区域,如果用ctrl复选选中了多片区域,点击格式刷按钮时弹出提示
|
//格式刷只支持单次选择的区域,如果用ctrl复选选中了多片区域,点击格式刷按钮时弹出提示
|
||||||
//判断是不是连续区域
|
//判断是不是连续区域
|
||||||
//荣国是连续区域,那么这些长方形的长加起来应该等于
|
//荣国是连续区域,那么这些长方形的长加起来应该等于
|
||||||
if (!isContinueArea()) { |
if (!isContinueArea()) { |
||||||
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Can_not_use_FormatBursh")); |
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Can_not_use_FormatBursh")); |
||||||
ePane.setFormatState(DesignerContext.FORMAT_STATE_NULL); |
ePane.setFormatState(DesignerContext.FORMAT_STATE_NULL); |
||||||
ePane.getFormatBrush().setSelected(false); |
ePane.getFormatBrush().setSelected(false); |
||||||
return false; |
return false; |
||||||
} |
} |
||||||
} |
} |
||||||
//只对单个区域进行格式刷操作
|
//只对单个区域进行格式刷操作
|
||||||
((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setNotShowingTableSelectPane(false); |
((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setNotShowingTableSelectPane(false); |
||||||
ePane.repaint(); |
ePane.repaint(); |
||||||
return true; |
return true; |
||||||
} |
} |
||||||
return false; |
return false; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* 判断是不是连续区域 |
* 判断是不是连续区域 |
||||||
* |
* |
||||||
* @return |
* @return |
||||||
*/ |
*/ |
||||||
private boolean isContinueArea() { |
private boolean isContinueArea() { |
||||||
int xStart = oldSelection.getCellRectangle(1).x; |
int xStart = oldSelection.getCellRectangle(1).x; |
||||||
int xend = 0; |
int xend = 0; |
||||||
int yStrat = oldSelection.getCellRectangle(1).y; |
int yStrat = oldSelection.getCellRectangle(1).y; |
||||||
int yend = 0; |
int yend = 0; |
||||||
int totalNum = 0; |
int totalNum = 0; |
||||||
for (int i = 0; i < oldSelection.getCellRectangleCount(); i++) { |
for (int i = 0; i < oldSelection.getCellRectangleCount(); i++) { |
||||||
Rectangle temp = oldSelection.getCellRectangle(i); |
Rectangle temp = oldSelection.getCellRectangle(i); |
||||||
if (temp.getX() < xStart) { |
if (temp.getX() < xStart) { |
||||||
xStart = temp.x; |
xStart = temp.x; |
||||||
} |
} |
||||||
if (temp.getX() + temp.getWidth() > xend) { |
if (temp.getX() + temp.getWidth() > xend) { |
||||||
xend = (int) (temp.getX() + temp.getWidth()); |
xend = (int) (temp.getX() + temp.getWidth()); |
||||||
} |
} |
||||||
if (temp.getY() < yStrat) { |
if (temp.getY() < yStrat) { |
||||||
yStrat = temp.y; |
yStrat = temp.y; |
||||||
} |
} |
||||||
if (temp.getY() + temp.getHeight() > yend) { |
if (temp.getY() + temp.getHeight() > yend) { |
||||||
yend = (int) (temp.getY() + temp.getHeight()); |
yend = (int) (temp.getY() + temp.getHeight()); |
||||||
} |
} |
||||||
totalNum += (int) (temp.getWidth() * temp.getHeight()); |
totalNum += (int) (temp.getWidth() * temp.getHeight()); |
||||||
} |
} |
||||||
|
|
||||||
if ((xend - xStart) * (yend - yStrat) == totalNum) { |
if ((xend - xStart) * (yend - yStrat) == totalNum) { |
||||||
oldSelection = new CellSelection(xStart, yStrat, (xend - xStart), (yend - yStrat)); |
oldSelection = new CellSelection(xStart, yStrat, (xend - xStart), (yend - yStrat)); |
||||||
ePane.setSelection(oldSelection); |
ePane.setSelection(oldSelection); |
||||||
ePane.setFormatReferencedCell(oldSelection); |
ePane.setFormatReferencedCell(oldSelection); |
||||||
return true; |
return true; |
||||||
} |
} |
||||||
return false; |
return false; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
public void updateFormatBrush(Style[][] referencedStyle, CellSelection cs, ElementCasePane reportPane) { |
public void updateFormatBrush(Style[][] referencedStyle, CellSelection cs, ElementCasePane reportPane) { |
||||||
//得到被参照的单元格的行列数
|
//得到被参照的单元格的行列数
|
||||||
if (referencedStyle == null) { |
if (referencedStyle == null) { |
||||||
return; |
return; |
||||||
} |
} |
||||||
int rowSpan = referencedStyle[0].length; |
int rowSpan = referencedStyle[0].length; |
||||||
int columnSpan = referencedStyle.length; |
int columnSpan = referencedStyle.length; |
||||||
|
|
||||||
//开始进行格式刷样式复制
|
//开始进行格式刷样式复制
|
||||||
TemplateElementCase elementCase = reportPane.getEditingElementCase(); |
TemplateElementCase elementCase = reportPane.getEditingElementCase(); |
||||||
int rowNum = cs.getRowSpan(); |
int rowNum = cs.getRowSpan(); |
||||||
int columnNum = cs.getColumnSpan(); |
int columnNum = cs.getColumnSpan(); |
||||||
|
|
||||||
|
|
||||||
//如果只点选了一个,则自动补足
|
//如果只点选了一个,则自动补足
|
||||||
if (cs.getColumnSpan() * cs.getRowSpan() == 1) { |
if (cs.getColumnSpan() * cs.getRowSpan() == 1) { |
||||||
rowNum = rowSpan; |
rowNum = rowSpan; |
||||||
columnNum = columnSpan; |
columnNum = columnSpan; |
||||||
} |
} |
||||||
|
|
||||||
for (int j = 0; j < rowNum; j++) { |
for (int j = 0; j < rowNum; j++) { |
||||||
for (int i = 0; i < columnNum; i++) { |
for (int i = 0; i < columnNum; i++) { |
||||||
int column = i + cs.getColumn(); |
int column = i + cs.getColumn(); |
||||||
int row = j + cs.getRow(); |
int row = j + cs.getRow(); |
||||||
TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); |
TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); |
||||||
if (cellElement == null) { |
if (cellElement == null) { |
||||||
cellElement = new DefaultTemplateCellElement(column, row); |
cellElement = new DefaultTemplateCellElement(column, row); |
||||||
elementCase.addCellElement(cellElement); |
elementCase.addCellElement(cellElement); |
||||||
} |
} |
||||||
cellElement.setStyle(referencedStyle[i % columnSpan][j % rowSpan]); |
cellElement.setStyle(referencedStyle[i % columnSpan][j % rowSpan]); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
private Style[][] getOldStyles(CellSelection oldSelection) { |
private Style[][] getOldStyles(CellSelection oldSelection) { |
||||||
Style[][] referencedStyle = new Style[oldSelection.getColumnSpan()][oldSelection.getRowSpan()]; |
Style[][] referencedStyle = new Style[oldSelection.getColumnSpan()][oldSelection.getRowSpan()]; |
||||||
int cellRectangleCount = oldSelection.getCellRectangleCount(); |
int cellRectangleCount = oldSelection.getCellRectangleCount(); |
||||||
TemplateElementCase elementCase = ePane.getEditingElementCase(); |
TemplateElementCase elementCase = ePane.getEditingElementCase(); |
||||||
for (int rect = 0; rect < cellRectangleCount; rect++) { |
for (int rect = 0; rect < cellRectangleCount; rect++) { |
||||||
Rectangle cellRectangle = oldSelection.getCellRectangle(rect); |
Rectangle cellRectangle = oldSelection.getCellRectangle(rect); |
||||||
for (int j = 0; j < cellRectangle.height; j++) { |
for (int j = 0; j < cellRectangle.height; j++) { |
||||||
for (int i = 0; i < cellRectangle.width; i++) { |
for (int i = 0; i < cellRectangle.width; i++) { |
||||||
int column = i + cellRectangle.x; |
int column = i + cellRectangle.x; |
||||||
int row = j + cellRectangle.y; |
int row = j + cellRectangle.y; |
||||||
TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); |
TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); |
||||||
if (cellElement == null) { |
if (cellElement == null) { |
||||||
cellElement = new DefaultTemplateCellElement(column, row); |
cellElement = new DefaultTemplateCellElement(column, row); |
||||||
elementCase.addCellElement(cellElement); |
elementCase.addCellElement(cellElement); |
||||||
} |
} |
||||||
Style style = cellElement.getStyle(); |
Style style = cellElement.getStyle(); |
||||||
if (style == null) { |
if (style == null) { |
||||||
style = style.DEFAULT_STYLE; |
style = style.DEFAULT_STYLE; |
||||||
} |
} |
||||||
|
|
||||||
referencedStyle[i][j] = style; |
referencedStyle[i][j] = style; |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
return referencedStyle; |
return referencedStyle; |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
Loading…
Reference in new issue