diff --git a/designer/src/com/fr/design/mainframe/FormatBrushAction.java b/designer/src/com/fr/design/mainframe/FormatBrushAction.java index a2daa7902..84bd160ab 100644 --- a/designer/src/com/fr/design/mainframe/FormatBrushAction.java +++ b/designer/src/com/fr/design/mainframe/FormatBrushAction.java @@ -1 +1,171 @@ -package com.fr.design.mainframe; import com.fr.base.BaseUtils; import com.fr.base.Style; import com.fr.design.actions.ElementCaseAction; import com.fr.general.Inter; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.Selection; import com.fr.report.cell.DefaultTemplateCellElement; import com.fr.report.cell.TemplateCellElement; import com.fr.report.elementcase.TemplateElementCase; import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; /** * Author : daisy * Date: 13-8-7 * Time: 上午11:05 */ public class FormatBrushAction extends ElementCaseAction { private ElementCasePane ePane; private CellSelection oldSelection; public FormatBrushAction(ElementCasePane t) { super(t); this.setName(Inter.getLocText("M_Edit-FormatBrush")); this.setMnemonic('B'); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/formatBrush.png")); this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, DEFAULT_MODIFIER)); } public boolean executeActionReturnUndoRecordNeeded() { ePane = (ElementCasePane) getEditingComponent(); if (ePane != null) { Selection selection = ePane.getSelection(); if (!(selection instanceof CellSelection)) { return false; } oldSelection = ((CellSelection) selection).clone(); ePane.setFormatReferencedCell(oldSelection); int cellRectangleCount = oldSelection.getCellRectangleCount(); if (cellRectangleCount > 1) { //格式刷只支持单次选择的区域,如果用ctrl复选选中了多片区域,点击格式刷按钮时弹出提示 //判断是不是连续区域 //荣国是连续区域,那么这些长方形的长加起来应该等于 if (!isContinueArea()) { JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Can_not_use_FormatBursh")); ePane.setFormatState(DesignerContext.FORMAT_STATE_NULL); ePane.getFormatBrush().setSelected(false); return false; } } //只对单个区域进行格式刷操作 ((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setNotShowingTableSelectPane(false); ePane.repaint(); return true; } return false; } /** * 判断是不是连续区域 * * @return */ private boolean isContinueArea() { int xStart = oldSelection.getCellRectangle(1).x; int xend = 0; int yStrat = oldSelection.getCellRectangle(1).y; int yend = 0; int totalNum = 0; for (int i = 0; i < oldSelection.getCellRectangleCount(); i++) { Rectangle temp = oldSelection.getCellRectangle(i); if (temp.getX() < xStart) { xStart = temp.x; } if (temp.getX() + temp.getWidth() > xend) { xend = (int) (temp.getX() + temp.getWidth()); } if (temp.getY() < yStrat) { yStrat = temp.y; } if (temp.getY() + temp.getHeight() > yend) { yend = (int) (temp.getY() + temp.getHeight()); } totalNum += (int) (temp.getWidth() * temp.getHeight()); } if ((xend - xStart) * (yend - yStrat) == totalNum) { oldSelection = new CellSelection(xStart, yStrat, (xend - xStart), (yend - yStrat)); ePane.setSelection(oldSelection); ePane.setFormatReferencedCell(oldSelection); return true; } return false; } public void updateFormatBrush(Style[][] referencedStyle, CellSelection cs, ElementCasePane reportPane) { //得到被参照的单元格的行列数 if (referencedStyle == null) { return; } int rowSpan = referencedStyle[0].length; int columnSpan = referencedStyle.length; //开始进行格式刷样式复制 TemplateElementCase elementCase = reportPane.getEditingElementCase(); int rowNum = cs.getRowSpan(); int columnNum = cs.getColumnSpan(); //如果只点选了一个,则自动补足 if (cs.getColumnSpan() * cs.getRowSpan() == 1) { rowNum = rowSpan; columnNum = columnSpan; } for (int j = 0; j < rowNum; j++) { for (int i = 0; i < columnNum; i++) { int column = i + cs.getColumn(); int row = j + cs.getRow(); TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(column, row); elementCase.addCellElement(cellElement); } cellElement.setStyle(referencedStyle[i % columnSpan][j % rowSpan]); } } } private Style[][] getOldStyles(CellSelection oldSelection) { Style[][] referencedStyle = new Style[oldSelection.getColumnSpan()][oldSelection.getRowSpan()]; int cellRectangleCount = oldSelection.getCellRectangleCount(); TemplateElementCase elementCase = ePane.getEditingElementCase(); for (int rect = 0; rect < cellRectangleCount; rect++) { Rectangle cellRectangle = oldSelection.getCellRectangle(rect); for (int j = 0; j < cellRectangle.height; j++) { for (int i = 0; i < cellRectangle.width; i++) { int column = i + cellRectangle.x; int row = j + cellRectangle.y; TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(column, row); elementCase.addCellElement(cellElement); } Style style = cellElement.getStyle(); if (style == null) { style = style.DEFAULT_STYLE; } referencedStyle[i][j] = style; } } } return referencedStyle; } } \ No newline at end of file +package com.fr.design.mainframe; + +import com.fr.base.BaseUtils; +import com.fr.base.Style; +import com.fr.design.actions.ElementCaseAction; +import com.fr.general.Inter; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyEvent; + +import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; + +/** + * Author : daisy + * Date: 13-8-7 + * Time: 上午11:05 + */ +public class FormatBrushAction extends ElementCaseAction { + + private ElementCasePane ePane; + private CellSelection oldSelection; + + + public FormatBrushAction(ElementCasePane t) { + super(t); + this.setName(Inter.getLocText("M_Edit-FormatBrush")); + this.setMnemonic('B'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/formatBrush.png")); + this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, DEFAULT_MODIFIER)); + } + + public boolean executeActionReturnUndoRecordNeeded() { + ePane = (ElementCasePane) getEditingComponent(); + if (ePane != null) { + Selection selection = ePane.getSelection(); + if (!(selection instanceof CellSelection)) { + return false; + } + oldSelection = ((CellSelection) selection).clone(); + ePane.setFormatReferencedCell(oldSelection); + int cellRectangleCount = oldSelection.getCellRectangleCount(); + if (cellRectangleCount > 1) { + //格式刷只支持单次选择的区域,如果用ctrl复选选中了多片区域,点击格式刷按钮时弹出提示 + //判断是不是连续区域 + //荣国是连续区域,那么这些长方形的长加起来应该等于 + if (!isContinueArea()) { + JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Can_not_use_FormatBursh")); + ePane.setFormatState(DesignerContext.FORMAT_STATE_NULL); + ePane.getFormatBrush().setSelected(false); + return false; + } + } + //只对单个区域进行格式刷操作 + ((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setNotShowingTableSelectPane(false); + ePane.repaint(); + return true; + } + return false; + } + + + /** + * 判断是不是连续区域 + * + * @return + */ + private boolean isContinueArea() { + int xStart = oldSelection.getCellRectangle(1).x; + int xend = 0; + int yStrat = oldSelection.getCellRectangle(1).y; + int yend = 0; + int totalNum = 0; + for (int i = 0; i < oldSelection.getCellRectangleCount(); i++) { + Rectangle temp = oldSelection.getCellRectangle(i); + if (temp.getX() < xStart) { + xStart = temp.x; + } + if (temp.getX() + temp.getWidth() > xend) { + xend = (int) (temp.getX() + temp.getWidth()); + } + if (temp.getY() < yStrat) { + yStrat = temp.y; + } + if (temp.getY() + temp.getHeight() > yend) { + yend = (int) (temp.getY() + temp.getHeight()); + } + totalNum += (int) (temp.getWidth() * temp.getHeight()); + } + + if ((xend - xStart) * (yend - yStrat) == totalNum) { + oldSelection = new CellSelection(xStart, yStrat, (xend - xStart), (yend - yStrat)); + ePane.setSelection(oldSelection); + ePane.setFormatReferencedCell(oldSelection); + return true; + } + return false; + } + + + public void updateFormatBrush(Style[][] referencedStyle, CellSelection cs, ElementCasePane reportPane) { + //得到被参照的单元格的行列数 + if (referencedStyle == null) { + return; + } + int rowSpan = referencedStyle[0].length; + int columnSpan = referencedStyle.length; + + //开始进行格式刷样式复制 + TemplateElementCase elementCase = reportPane.getEditingElementCase(); + int rowNum = cs.getRowSpan(); + int columnNum = cs.getColumnSpan(); + + + //如果只点选了一个,则自动补足 + if (cs.getColumnSpan() * cs.getRowSpan() == 1) { + rowNum = rowSpan; + columnNum = columnSpan; + } + + for (int j = 0; j < rowNum; j++) { + for (int i = 0; i < columnNum; i++) { + int column = i + cs.getColumn(); + int row = j + cs.getRow(); + TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(column, row); + elementCase.addCellElement(cellElement); + } + cellElement.setStyle(referencedStyle[i % columnSpan][j % rowSpan]); + } + } + + + } + + + private Style[][] getOldStyles(CellSelection oldSelection) { + Style[][] referencedStyle = new Style[oldSelection.getColumnSpan()][oldSelection.getRowSpan()]; + int cellRectangleCount = oldSelection.getCellRectangleCount(); + TemplateElementCase elementCase = ePane.getEditingElementCase(); + for (int rect = 0; rect < cellRectangleCount; rect++) { + Rectangle cellRectangle = oldSelection.getCellRectangle(rect); + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(column, row); + elementCase.addCellElement(cellElement); + } + Style style = cellElement.getStyle(); + if (style == null) { + style = style.DEFAULT_STYLE; + } + + referencedStyle[i][j] = style; + } + } + } + + return referencedStyle; + } + +} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/gui/itextarea/UITextArea.java b/designer_base/src/com/fr/design/gui/itextarea/UITextArea.java index 03a70a6ef..6e04eacb8 100644 --- a/designer_base/src/com/fr/design/gui/itextarea/UITextArea.java +++ b/designer_base/src/com/fr/design/gui/itextarea/UITextArea.java @@ -19,14 +19,21 @@ public class UITextArea extends JTextArea implements UIObserver { public UITextArea(int i, int j) { super(i, j); InputMap inputMap = this.getInputMap(); - inputMap.getParent().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER), - DefaultEditorKit.selectAllAction); - inputMap.getParent().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), - DefaultEditorKit.copyAction); - inputMap.getParent().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER), - DefaultEditorKit.pasteAction); - inputMap.getParent().put(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER), - DefaultEditorKit.cutAction); + while (inputMap.getParent() != null) { + inputMap = inputMap.getParent(); + } + if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER)) == null) { + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER), DefaultEditorKit.selectAllAction); + } + if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER)) == null) { + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), DefaultEditorKit.copyAction); + } + if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER)) == null) { + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER), DefaultEditorKit.pasteAction); + } + if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER)) == null) { + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER), DefaultEditorKit.cutAction); + } initComponents(); } diff --git a/designer_base/src/com/fr/design/gui/itextfield/UITextField.java b/designer_base/src/com/fr/design/gui/itextfield/UITextField.java index 0af105058..4f15b1f81 100644 --- a/designer_base/src/com/fr/design/gui/itextfield/UITextField.java +++ b/designer_base/src/com/fr/design/gui/itextfield/UITextField.java @@ -1,20 +1,19 @@ package com.fr.design.gui.itextfield; -import java.awt.*; -import java.awt.event.KeyEvent; +import com.fr.design.event.GlobalNameListener; +import com.fr.design.event.GlobalNameObserver; +import com.fr.design.event.UIObserver; +import com.fr.design.event.UIObserverListener; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.stable.Constants; import javax.swing.*; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.DefaultEditorKit; import javax.swing.text.Document; - -import com.fr.design.event.GlobalNameListener; -import com.fr.design.event.GlobalNameObserver; -import com.fr.design.event.UIObserver; -import com.fr.design.event.UIObserverListener; -import com.fr.stable.Constants; -import com.fr.design.utils.gui.GUICoreUtils; +import java.awt.*; +import java.awt.event.KeyEvent; import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; @@ -33,14 +32,21 @@ public class UITextField extends JTextField implements UIObserver, GlobalNameObs public UITextField() { super(); InputMap inputMap = this.getInputMap(); - inputMap.getParent().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER), - DefaultEditorKit.selectAllAction); - inputMap.getParent().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), - DefaultEditorKit.copyAction); - inputMap.getParent().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER), - DefaultEditorKit.pasteAction); - inputMap.getParent().put(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER), - DefaultEditorKit.cutAction); + while (inputMap.getParent() != null) { + inputMap = inputMap.getParent(); + } + if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER)) == null) { + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER), DefaultEditorKit.selectAllAction); + } + if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER)) == null) { + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), DefaultEditorKit.copyAction); + } + if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER)) == null) { + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER), DefaultEditorKit.pasteAction); + } + if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER)) == null) { + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER), DefaultEditorKit.cutAction); + } initListener(); } @@ -197,6 +203,7 @@ public class UITextField extends JTextField implements UIObserver, GlobalNameObs /** * 主函数 + * * @param args 参数 */ public static void main(String... args) { diff --git a/designer_base/src/com/fr/design/gui/itree/checkboxtree/CheckBoxTree.java b/designer_base/src/com/fr/design/gui/itree/checkboxtree/CheckBoxTree.java index a22264477..941fd962a 100644 --- a/designer_base/src/com/fr/design/gui/itree/checkboxtree/CheckBoxTree.java +++ b/designer_base/src/com/fr/design/gui/itree/checkboxtree/CheckBoxTree.java @@ -22,8 +22,6 @@ import java.beans.PropertyChangeListener; import java.util.Hashtable; import java.util.Vector; -import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; - /** * CheckBoxTree is a special JTree which uses UICheckBox as the tree renderer. * In addition to regular JTree's features, it also allows you select any number @@ -82,8 +80,6 @@ public class CheckBoxTree extends JTree { public CheckBoxTree(TreeModel newModel) { super(newModel); - InputMap inputMap = this.getInputMap(); - inputMap.getParent().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER), "selectAll"); init(); }