forked from fanruan/design
kerry
3 years ago
43 changed files with 534 additions and 1206 deletions
@ -1,4 +1,4 @@
|
||||
package com.fr.design.fit; |
||||
package com.fr.design.mainframe; |
||||
|
||||
import com.fr.stable.Constants; |
||||
import com.fr.stable.unit.LEN_UNIT; |
@ -1,4 +1,4 @@
|
||||
package com.fr.design.fit; |
||||
package com.fr.design.mainframe; |
||||
|
||||
import com.fr.design.fun.impl.AbstractReportLengthUNITProvider; |
||||
import com.fr.stable.unit.UNIT; |
@ -1,115 +0,0 @@
|
||||
package com.fr.design.actions; |
||||
|
||||
|
||||
import com.fr.base.iofile.attr.MobileOnlyTemplateAttrMark; |
||||
import com.fr.design.designer.creator.XLayoutContainer; |
||||
import com.fr.design.designer.creator.XWAbsoluteBodyLayout; |
||||
import com.fr.design.designer.creator.XWFitLayout; |
||||
import com.fr.design.dialog.BasicDialog; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.fit.NewJForm; |
||||
import com.fr.design.fit.common.AdaptiveSwitchUtil; |
||||
import com.fr.design.fit.common.TemplateTool; |
||||
import com.fr.design.form.mobile.FormMobileAttrPane; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.FormArea; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
import com.fr.design.mainframe.JForm; |
||||
import com.fr.design.mainframe.WidgetPropertyPane; |
||||
import com.fr.file.FILE; |
||||
import com.fr.form.main.Form; |
||||
import com.fr.form.main.mobile.FormMobileAttr; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.awt.event.ActionEvent; |
||||
|
||||
/** |
||||
* Created by fanglei on 2016/11/14. |
||||
*/ |
||||
@EnableMetrics |
||||
public class NewFormMobileAttrAction extends FormMobileAttrAction { |
||||
|
||||
public NewFormMobileAttrAction(JForm jf) { |
||||
super(jf); |
||||
} |
||||
|
||||
/** |
||||
* 执行动作 |
||||
* |
||||
* @return 是否执行成功 |
||||
*/ |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
final JForm jf = getEditingComponent(); |
||||
if (jf == null) { |
||||
return; |
||||
} |
||||
final Form formTpl = jf.getTarget(); |
||||
FormMobileAttr mobileAttr = formTpl.getFormMobileAttr(); |
||||
|
||||
final FormMobileAttrPane mobileAttrPane = new FormMobileAttrPane(); |
||||
mobileAttrPane.populateBean(mobileAttr); |
||||
|
||||
final boolean oldMobileOnly = mobileAttr.isMobileOnly(); |
||||
final boolean oldAdaptive = mobileAttr.isAdaptivePropertyAutoMatch(); |
||||
BasicDialog dialog = mobileAttrPane.showWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { |
||||
@Override |
||||
public void doOk() { |
||||
FormMobileAttr formMobileAttr = mobileAttrPane.updateBean(); |
||||
if (formMobileAttr.isMobileOnly() && jf.getTarget().getAttrMark(MobileOnlyTemplateAttrMark.XML_TAG) == null) { |
||||
// 如果是老模板,选择手机专属之后需要另存为
|
||||
FILE editingFILE = jf.getEditingFILE(); |
||||
if (editingFILE != null && editingFILE.exists()) { |
||||
String fileName = editingFILE.getName().substring(0, editingFILE.getName().length() - jf.suffix().length()) + "_mobile"; |
||||
if (!jf.saveAsTemplate(true, fileName)) { |
||||
return; |
||||
} |
||||
} |
||||
// 放到后面。如果提前 return 了,则仍然处于未设置状态,不要添加
|
||||
jf.getTarget().addAttrMark(new MobileOnlyTemplateAttrMark()); |
||||
} |
||||
// 设置移动端属性并刷新界面
|
||||
formTpl.setFormMobileAttr(formMobileAttr); // 会调整 body 的自适应布局,放到最后
|
||||
boolean changeSize = (!oldMobileOnly && formMobileAttr.isMobileOnly()) || (oldMobileOnly && !formMobileAttr.isMobileOnly()); |
||||
if (changeSize) { |
||||
((FormArea)jf.getFormDesign().getParent()).onMobileAttrModified(); |
||||
} |
||||
//改变布局为自适应布局,只在移动端属性设置保存后改变一次
|
||||
boolean changeLayout = !oldAdaptive && formMobileAttr.isAdaptivePropertyAutoMatch(); |
||||
if (changeLayout) { |
||||
jf.getFormDesign().getSelectionModel().setSelectedCreator(jf.getFormDesign().getRootComponent()); |
||||
doChangeBodyLayout(); |
||||
WidgetPropertyPane.getInstance().refreshDockingView(); |
||||
} |
||||
jf.fireTargetModified(); |
||||
FILE editingFILE = jf.getEditingFILE(); |
||||
if(editingFILE != null && editingFILE.exists()){ |
||||
JForm jForm = getEditingComponent(); |
||||
TemplateTool.saveForm(jForm); |
||||
if (jForm instanceof NewJForm) { |
||||
AdaptiveSwitchUtil.switch2OldUI(); |
||||
} |
||||
}else { |
||||
AdaptiveSwitchUtil.switch2OldUIMode(); |
||||
NewJForm mobileJForm = new NewJForm(jf.getTarget(), jf.getEditingFILE()); |
||||
//设置临时的id,和新建的模板区分
|
||||
mobileJForm.getTarget().setTemplateID(StringUtils.EMPTY); |
||||
TemplateTool.resetTabPaneEditingTemplate(mobileJForm); |
||||
TemplateTool.activeAndResizeTemplate(mobileJForm); |
||||
} |
||||
} |
||||
}); |
||||
dialog.setVisible(true); |
||||
} |
||||
|
||||
private void doChangeBodyLayout(){ |
||||
FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); |
||||
XLayoutContainer rootLayout = formDesigner.getRootComponent(); |
||||
if (rootLayout.getComponentCount() == 1 && rootLayout.getXCreator(0).acceptType(XWAbsoluteBodyLayout.class)) { |
||||
rootLayout = (XWAbsoluteBodyLayout) rootLayout.getXCreator(0); |
||||
} |
||||
((XWFitLayout)formDesigner.getRootComponent()).switch2FitBodyLayout(rootLayout); |
||||
} |
||||
} |
||||
|
@ -1,70 +0,0 @@
|
||||
package com.fr.design.fit.grid; |
||||
|
||||
import com.fr.base.DynamicUnitList; |
||||
import com.fr.design.fit.DesignerUIModeConfig; |
||||
import com.fr.design.mainframe.ElementCasePane; |
||||
import com.fr.grid.GridHeader; |
||||
import com.fr.grid.AbstractGridHeaderMouseHandler; |
||||
import com.fr.report.elementcase.ElementCase; |
||||
import com.fr.report.elementcase.TemplateElementCase; |
||||
|
||||
import java.awt.event.MouseEvent; |
||||
|
||||
public abstract class GridHeaderWithBoundMouseHandler extends AbstractGridHeaderMouseHandler{ |
||||
protected static final int FUZZY_EDGE = 10; |
||||
private int limit; |
||||
|
||||
public GridHeaderWithBoundMouseHandler(GridHeader gHeader, int limit) { |
||||
super(gHeader); |
||||
this.limit = limit; |
||||
} |
||||
|
||||
public void setLimit(int limit) { |
||||
this.limit = limit; |
||||
} |
||||
|
||||
public int getLimit() { |
||||
return limit; |
||||
} |
||||
|
||||
public int getDragIndex(MouseEvent evt) { |
||||
ElementCase report = this.getEditingElementCase(); |
||||
DynamicUnitList sizeList = getSizeList(report); |
||||
|
||||
int scrollValue = getScrollValue(this.getElementCasePane()); |
||||
int scrollExtent = getScrollExtent(this.getElementCasePane()); |
||||
int endValue = scrollValue + scrollExtent + 1; |
||||
|
||||
int beginValue = getBeginValue(this.getElementCasePane()); |
||||
|
||||
double tmpSize1 = 0; |
||||
double tmpSize2; |
||||
double tmpIncreaseSize = 0; |
||||
|
||||
int resolution = DesignerUIModeConfig.getInstance().getScreenResolution(); |
||||
|
||||
for (int index = beginValue; index < endValue; index++) { |
||||
if (index == 0) { |
||||
index = scrollValue; |
||||
} |
||||
|
||||
tmpSize1 += tmpIncreaseSize; |
||||
tmpIncreaseSize = sizeList.get(index).toPixD(resolution); |
||||
tmpSize2 = tmpSize1 + Math.max(1, tmpIncreaseSize); |
||||
if (isOnSeparatorLineIncludeZero(evt, tmpSize2, tmpIncreaseSize) || isOnNormalSeparatorLine(evt, tmpSize2)) { |
||||
return index; |
||||
} |
||||
} |
||||
return -1; |
||||
} |
||||
|
||||
|
||||
public ElementCasePane getElementCasePane() { |
||||
return this.gHeader.getElementCasePane(); |
||||
} |
||||
|
||||
public TemplateElementCase getEditingElementCase() { |
||||
return this.getElementCasePane().getEditingElementCase(); |
||||
} |
||||
|
||||
} |
@ -1,194 +0,0 @@
|
||||
package com.fr.design.fit.grid; |
||||
|
||||
import com.fr.base.DynamicUnitList; |
||||
import com.fr.design.fit.DesignerUIModeConfig; |
||||
import com.fr.design.gui.imenu.UIPopupMenu; |
||||
import com.fr.design.mainframe.ElementCasePane; |
||||
import com.fr.grid.GridColumn; |
||||
import com.fr.grid.GridHeader; |
||||
import com.fr.grid.GridUtils; |
||||
import com.fr.grid.selection.CellSelection; |
||||
import com.fr.grid.selection.Selection; |
||||
import com.fr.report.ReportHelper; |
||||
import com.fr.report.elementcase.ElementCase; |
||||
import com.fr.stable.ColumnRow; |
||||
import com.fr.stable.unit.FU; |
||||
import com.fr.stable.unit.UNIT; |
||||
|
||||
import javax.swing.SwingUtilities; |
||||
import java.awt.Dimension; |
||||
import java.awt.Point; |
||||
import java.awt.Rectangle; |
||||
import java.awt.Toolkit; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
/** |
||||
* peter:处理对GridColumn的Mouse事件. |
||||
*/ |
||||
public class GridLimitColumnMouseHandler extends GridHeaderWithBoundMouseHandler { |
||||
|
||||
|
||||
public GridLimitColumnMouseHandler(GridColumn gridColumn, int limit) { |
||||
super(gridColumn, limit); |
||||
this.resolution = gridColumn.getResolution(); |
||||
} |
||||
|
||||
@Override |
||||
protected void resetSelectionByRightButton(ColumnRow selectedCellPoint, Selection cs, ElementCasePane ePane) { |
||||
int[] selectedColumns = cs.getSelectedColumns(); |
||||
if (selectedColumns.length == 0 |
||||
|| selectedCellPoint.getColumn() < selectedColumns[0] |
||||
|| selectedCellPoint.getColumn() > selectedColumns[selectedColumns.length - 1]) { |
||||
resetGridSelectionBySelect(selectedCellPoint.getColumn(), ePane); |
||||
} |
||||
} |
||||
|
||||
|
||||
protected int doChooseFrom() { |
||||
return CellSelection.CHOOSE_COLUMN; |
||||
} |
||||
|
||||
@Override |
||||
protected Rectangle resetSelectedBoundsByShift(Rectangle editRectangle, ColumnRow selectedCellPoint, ElementCasePane reportPane) { |
||||
int tempOldSelectedCellX = editRectangle.x;// editRectangle.x;
|
||||
|
||||
// adjust them to got the correct selected bounds.
|
||||
if (selectedCellPoint.getColumn() >= editRectangle.x) { |
||||
selectedCellPoint = ColumnRow.valueOf(selectedCellPoint.getColumn() + 1, selectedCellPoint.getRow()); |
||||
} else { |
||||
tempOldSelectedCellX++; |
||||
} |
||||
|
||||
int lastRow = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane).getRow(); |
||||
return new Rectangle(Math.min(tempOldSelectedCellX, selectedCellPoint.getColumn()), 0, Math.max(editRectangle.width, Math.abs(tempOldSelectedCellX |
||||
- selectedCellPoint.getColumn())), lastRow); |
||||
} |
||||
|
||||
@Override |
||||
protected int[] getGridSelectionIndices(CellSelection cs) { |
||||
return cs.getSelectedColumns(); |
||||
} |
||||
|
||||
@Override |
||||
protected int getScrollValue(ElementCasePane casePane) { |
||||
return casePane.getGrid().getHorizontalValue(); |
||||
} |
||||
|
||||
@Override |
||||
protected int getScrollExtent(ElementCasePane casePane) { |
||||
return casePane.getGrid().getHorizontalExtent(); |
||||
} |
||||
|
||||
@Override |
||||
protected int getBeginValue(ElementCasePane casePane) { |
||||
return casePane.getGrid().getHorizontalBeginValue(); |
||||
} |
||||
|
||||
@Override |
||||
protected int getColumnOrRowByGridHeader(ColumnRow selectedCellPoint) { |
||||
return selectedCellPoint.getColumn(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Checks whether is on zero separator line. |
||||
*/ |
||||
@Override |
||||
protected boolean isOnSeparatorLineIncludeZero(MouseEvent evt, double tmpWidth2, double tmpIncreaseWidth) { |
||||
return tmpIncreaseWidth <= 1 && (evt.getX() >= tmpWidth2 + 2 && (evt.getX() <= tmpWidth2 + SEPARATOR_GAP)); |
||||
} |
||||
|
||||
@Override |
||||
protected boolean between(MouseEvent evt, double from, double to) { |
||||
return evt.getX() > from && evt.getX() <= to; |
||||
} |
||||
|
||||
/** |
||||
* Checks whether is on normal separator line. |
||||
*/ |
||||
@Override |
||||
protected boolean isOnNormalSeparatorLine(MouseEvent evt, double tmpWidth2) { |
||||
return (evt.getX() >= tmpWidth2 - 2) && (evt.getX() <= tmpWidth2 + 2); |
||||
} |
||||
|
||||
@Override |
||||
protected int evtOffset(MouseEvent evt, int offset) { |
||||
return evt.getX() - offset; |
||||
} |
||||
|
||||
@Override |
||||
protected DynamicUnitList getSizeList(ElementCase elementCase) { |
||||
return ReportHelper.getColumnWidthList(elementCase); |
||||
} |
||||
|
||||
@Override |
||||
protected String methodName() { |
||||
return "setColumnWidth"; |
||||
} |
||||
|
||||
@Override |
||||
protected String getSelectedHeaderTooltip(int selectedColumnCount) { |
||||
return selectedColumnCount + "C"; |
||||
} |
||||
|
||||
@Override |
||||
protected Point getTipLocationByMouseEvent(MouseEvent evt, GridHeader gHeader, Dimension tipPreferredSize) { |
||||
Point convertPoint = new Point(evt.getX(), 0); |
||||
SwingUtilities.convertPointToScreen(convertPoint, gHeader); |
||||
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
||||
convertPoint.x = Math.max(0, Math.min(convertPoint.x - tipPreferredSize.width / 2, screenSize.width - tipPreferredSize.width)); |
||||
convertPoint.y = convertPoint.y - tipPreferredSize.height - 2; |
||||
|
||||
return convertPoint; |
||||
} |
||||
|
||||
@Override |
||||
protected void resetGridSelectionBySelect(int column, ElementCasePane ePane) { |
||||
int lastRow = GridUtils.getAdjustLastColumnRowOfReportPane(ePane).getRow(); |
||||
CellSelection cellSelection = new CellSelection(column, 0, 1, lastRow); |
||||
cellSelection.setSelectedType(CellSelection.CHOOSE_COLUMN); |
||||
ePane.setSelection(cellSelection); |
||||
} |
||||
|
||||
@Override |
||||
protected String nameOfMoveCursorGIF() { |
||||
return "cursor_hmove"; |
||||
} |
||||
|
||||
@Override |
||||
protected String nameOfSelectCursorGIF() { |
||||
return "cursor_hselect"; |
||||
} |
||||
|
||||
@Override |
||||
protected String nameOfSplitCursorGIF() { |
||||
return "cursor_hsplit"; |
||||
} |
||||
|
||||
@Override |
||||
protected UIPopupMenu createPopupMenu(ElementCasePane reportPane, |
||||
MouseEvent evt, int columnIndex) { |
||||
return ElementCasePaneUtil.createColumnPopupMenu(reportPane, evt, columnIndex); |
||||
} |
||||
|
||||
@Override |
||||
protected void resetGridSelectionByDrag(CellSelection gridSelection, ElementCasePane reportPane, |
||||
int startMultiSelectIndex, int endMultiSelectIndex) { |
||||
int lastRow = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane).getRow(); |
||||
gridSelection.setLastRectangleBounds(Math.min(endMultiSelectIndex, startMultiSelectIndex), 0, Math.abs(startMultiSelectIndex - endMultiSelectIndex) + 1, lastRow); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseReleased(MouseEvent e) { |
||||
super.mouseReleased(e); |
||||
int resolution = DesignerUIModeConfig.getInstance().getScreenResolution(); |
||||
int dragIndex = getDragIndex(e); |
||||
if (Math.abs(e.getX() - getLimit()) < FUZZY_EDGE && dragIndex >= 0) { |
||||
UNIT oldValue = this.getEditingElementCase().getColumnWidth(dragIndex); |
||||
this.getEditingElementCase().setColumnWidth(dragIndex, FU.valueOfPix(oldValue.toPixI(resolution) + getLimit() - e.getX(), resolution)); |
||||
} |
||||
this.getElementCasePane().repaint(); |
||||
} |
||||
|
||||
} |
@ -1,190 +0,0 @@
|
||||
package com.fr.design.fit.grid; |
||||
|
||||
import com.fr.base.DynamicUnitList; |
||||
import com.fr.design.fit.DesignerUIModeConfig; |
||||
import com.fr.design.gui.imenu.UIPopupMenu; |
||||
import com.fr.design.mainframe.ElementCasePane; |
||||
import com.fr.grid.GridHeader; |
||||
import com.fr.grid.GridRow; |
||||
import com.fr.grid.GridUtils; |
||||
import com.fr.grid.selection.CellSelection; |
||||
import com.fr.grid.selection.Selection; |
||||
import com.fr.report.ReportHelper; |
||||
import com.fr.report.elementcase.ElementCase; |
||||
import com.fr.stable.ColumnRow; |
||||
import com.fr.stable.unit.FU; |
||||
import com.fr.stable.unit.UNIT; |
||||
|
||||
import javax.swing.SwingUtilities; |
||||
import java.awt.Dimension; |
||||
import java.awt.Point; |
||||
import java.awt.Rectangle; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
/** |
||||
* peter:处理对GridRow的Mouse事件. |
||||
*/ |
||||
public class GridLimitRowMouseHandler extends GridHeaderWithBoundMouseHandler { |
||||
|
||||
public GridLimitRowMouseHandler(GridRow gridRow, int limit) { |
||||
super(gridRow, limit); |
||||
} |
||||
|
||||
@Override |
||||
protected void resetSelectionByRightButton(ColumnRow selectedCellPoint, Selection cs, ElementCasePane ePane) { |
||||
int[] selectedRows = cs.getSelectedRows(); |
||||
if (selectedRows.length == 0 |
||||
|| selectedCellPoint.getRow() < selectedRows[0] |
||||
|| selectedCellPoint.getRow() > selectedRows[selectedRows.length - 1]) { |
||||
resetGridSelectionBySelect(selectedCellPoint.getRow(), ePane); |
||||
} |
||||
} |
||||
|
||||
|
||||
protected int doChooseFrom() { |
||||
return CellSelection.CHOOSE_ROW; |
||||
} |
||||
|
||||
@Override |
||||
protected int getScrollValue(ElementCasePane casePane) { |
||||
return casePane.getGrid().getVerticalValue(); |
||||
} |
||||
|
||||
@Override |
||||
protected int getScrollExtent(ElementCasePane casePane) { |
||||
return casePane.getGrid().getVerticalExtent(); |
||||
} |
||||
|
||||
@Override |
||||
protected int getBeginValue(ElementCasePane casePane) { |
||||
return casePane.getGrid().getVerticalBeginValue(); |
||||
} |
||||
|
||||
@Override |
||||
protected Rectangle resetSelectedBoundsByShift(Rectangle editRectangle, ColumnRow selectedCellPoint, ElementCasePane reportPane) { |
||||
int tempOldSelectedCellY = editRectangle.y;// editRectangle.x;
|
||||
|
||||
// ajust them to got the correct selected bounds.
|
||||
if (selectedCellPoint.getRow() >= editRectangle.y) { |
||||
selectedCellPoint = ColumnRow.valueOf(selectedCellPoint.getColumn(), selectedCellPoint.getRow() + 1); |
||||
} else { |
||||
tempOldSelectedCellY++; |
||||
} |
||||
|
||||
int lastColumn = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane).getColumn(); |
||||
return new Rectangle(0, Math.min(tempOldSelectedCellY, selectedCellPoint.getRow()), |
||||
lastColumn, Math.max(editRectangle.height, Math.abs(tempOldSelectedCellY - selectedCellPoint.getRow()))); |
||||
} |
||||
|
||||
@Override |
||||
protected int[] getGridSelectionIndices(CellSelection cs) { |
||||
return cs.getSelectedRows(); |
||||
} |
||||
|
||||
@Override |
||||
protected int getColumnOrRowByGridHeader(ColumnRow selectedCellPoint) { |
||||
return selectedCellPoint.getRow(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void resetGridSelectionBySelect(int row, ElementCasePane ePane) { |
||||
int lastColumn = GridUtils.getAdjustLastColumnRowOfReportPane(ePane).getColumn(); |
||||
CellSelection cellSelection = new CellSelection(0, row, lastColumn, 1); |
||||
cellSelection.setSelectedType(CellSelection.CHOOSE_ROW); |
||||
ePane.setSelection(cellSelection); |
||||
} |
||||
|
||||
/** |
||||
* Checks whether is on zero separator line. |
||||
*/ |
||||
@Override |
||||
protected boolean isOnSeparatorLineIncludeZero(MouseEvent evt, double tmpHeight2, double tmpIncreaseHeight) { |
||||
return tmpIncreaseHeight <= 1 && (evt.getY() >= tmpHeight2 + 2 && evt.getY() <= tmpHeight2 + SEPARATOR_GAP); |
||||
} |
||||
|
||||
@Override |
||||
protected boolean between(MouseEvent evt, double from, double to) { |
||||
return evt.getY() > from && evt.getY() <= to; |
||||
} |
||||
|
||||
@Override |
||||
protected DynamicUnitList getSizeList(ElementCase elementCase) { |
||||
return ReportHelper.getRowHeightList(elementCase); |
||||
} |
||||
|
||||
@Override |
||||
protected String methodName() { |
||||
return "setRowHeight"; |
||||
} |
||||
|
||||
/** |
||||
* Checks whether is on normal separator line. |
||||
*/ |
||||
@Override |
||||
protected boolean isOnNormalSeparatorLine(MouseEvent evt, double tmpHeight2) { |
||||
return (evt.getY() >= tmpHeight2 - 2) && (evt.getY() <= tmpHeight2 + 2); |
||||
} |
||||
|
||||
@Override |
||||
protected int evtOffset(MouseEvent evt, int offset) { |
||||
return evt.getY() - offset; |
||||
} |
||||
|
||||
@Override |
||||
protected String getSelectedHeaderTooltip(int rowSelectedCount) { |
||||
return rowSelectedCount + "R"; |
||||
} |
||||
|
||||
@Override |
||||
protected Point getTipLocationByMouseEvent(MouseEvent evt, GridHeader gHeader, Dimension tipPreferredSize) { |
||||
Point convertPoint = new Point(0, evt.getY()); |
||||
SwingUtilities.convertPointToScreen(convertPoint, gHeader); |
||||
|
||||
convertPoint.x = convertPoint.x + gHeader.getSize().width + 2; |
||||
convertPoint.y = convertPoint.y - tipPreferredSize.height / 2; |
||||
|
||||
return convertPoint; |
||||
} |
||||
|
||||
@Override |
||||
protected String nameOfMoveCursorGIF() { |
||||
return "cursor_vmove"; |
||||
} |
||||
|
||||
@Override |
||||
protected String nameOfSelectCursorGIF() { |
||||
return "cursor_vselect"; |
||||
} |
||||
|
||||
@Override |
||||
protected String nameOfSplitCursorGIF() { |
||||
return "cursor_vsplit"; |
||||
} |
||||
|
||||
@Override |
||||
protected UIPopupMenu createPopupMenu(ElementCasePane reportPane, |
||||
MouseEvent evt, int rowIndex) { |
||||
return ElementCasePaneUtil.createRowPopupMenu(reportPane, evt, rowIndex); |
||||
} |
||||
|
||||
@Override |
||||
protected void resetGridSelectionByDrag(CellSelection gridSelection, ElementCasePane reportPane, |
||||
int startMultiSelectIndex, int endMultiSelectIndex) { |
||||
int lastColumn = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane).getColumn(); |
||||
gridSelection.setLastRectangleBounds(0, Math.min(endMultiSelectIndex, startMultiSelectIndex), lastColumn, Math.abs(startMultiSelectIndex - endMultiSelectIndex) + 1); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void mouseReleased(MouseEvent e) { |
||||
super.mouseReleased(e); |
||||
int resolution = DesignerUIModeConfig.getInstance().getScreenResolution(); |
||||
int dragIndex = getDragIndex(e); |
||||
if (Math.abs(e.getY() - getLimit()) < FUZZY_EDGE && dragIndex >= 0) { |
||||
UNIT oldValue = this.getEditingElementCase().getRowHeight(dragIndex); |
||||
this.getEditingElementCase().setRowHeight(dragIndex, FU.valueOfPix(oldValue.toPixI(resolution) + getLimit() - e.getY(), resolution)); |
||||
} |
||||
this.getElementCasePane().repaint(); |
||||
} |
||||
} |
@ -1,201 +0,0 @@
|
||||
package com.fr.design.fit.grid; |
||||
|
||||
import com.fr.design.designer.creator.XElementCase; |
||||
import com.fr.design.fit.AdaptiveCellElementPainter; |
||||
import com.fr.design.fit.DesignerUIModeConfig; |
||||
import com.fr.design.fit.common.FormDesignerUtil; |
||||
import com.fr.design.mainframe.ElementCasePane; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
import com.fr.grid.CellElementPainter; |
||||
import com.fr.grid.Grid; |
||||
import com.fr.grid.GridColumn; |
||||
import com.fr.grid.GridRow; |
||||
import com.fr.grid.GridUI; |
||||
import com.fr.report.elementcase.TemplateElementCase; |
||||
import com.fr.report.worksheet.FormElementCase; |
||||
import com.fr.stable.Constants; |
||||
import com.fr.stable.GraphDrawHelper; |
||||
|
||||
import javax.swing.JComponent; |
||||
import java.awt.Color; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.Insets; |
||||
import java.awt.Rectangle; |
||||
import java.awt.event.MouseListener; |
||||
import java.awt.event.MouseMotionListener; |
||||
import java.awt.event.MouseWheelListener; |
||||
|
||||
|
||||
/** |
||||
* Created by kerry on 2020-04-14 |
||||
*/ |
||||
public class NewFormDesignerGridUI extends GridUI { |
||||
private GridLimitColumnMouseHandler gridColumnMouseHandler; |
||||
private GridLimitRowMouseHandler gridRowMouseHandler; |
||||
private AdaptiveGridListener adaptiveGridListener; |
||||
private FormDesigner designer; |
||||
|
||||
public NewFormDesignerGridUI(FormDesigner designer, int resolution) { |
||||
super(resolution); |
||||
this.designer = designer; |
||||
this.setCellElementPainter(new AdaptiveCellElementPainter()); |
||||
} |
||||
|
||||
public void setCellElementPainter(CellElementPainter elementPainter) { |
||||
this.painter = elementPainter; |
||||
} |
||||
|
||||
public void paint(Graphics g, JComponent c) { |
||||
Graphics2D g2d = (Graphics2D) g; |
||||
Grid grid = (Grid) c; |
||||
// 取得ElementCasePane.ElementCase
|
||||
ElementCasePane elementCasePane = grid.getElementCasePane(); |
||||
final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); |
||||
|
||||
super.paint(g, c); |
||||
|
||||
if (!(elementCase instanceof FormElementCase)) { |
||||
return; |
||||
} |
||||
final Rectangle rectangle = getBoundsLineRect(elementCase, grid); |
||||
int width = getScaleWidth(rectangle.width) - columnWidthList.getRangeValue(0, horizontalValue).toPixI(resolution); |
||||
int height = getScaleHeight(rectangle.height) - rowHeightList.getRangeValue(0, verticalValue).toPixI(resolution); |
||||
drawBoundsLine(g2d, width, height); |
||||
addListener(grid, elementCasePane, width, height, rectangle.width, rectangle.height); |
||||
} |
||||
|
||||
private int getScaleWidth(int width) { |
||||
return width * resolution / DesignerUIModeConfig.getInstance().getScreenResolution(); |
||||
|
||||
} |
||||
|
||||
private int getScaleHeight(int height) { |
||||
return height * resolution / DesignerUIModeConfig.getInstance().getScreenResolution(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取需要画线的矩形大小 |
||||
*/ |
||||
private Rectangle getBoundsLineRect(TemplateElementCase elementCase, Grid grid) { |
||||
final Rectangle rectangle = new Rectangle(); |
||||
XElementCase xElementCase = FormDesignerUtil.getXelementCase(designer.getRootComponent(), (FormElementCase) elementCase); |
||||
if (xElementCase != null) { |
||||
rectangle.setBounds(xElementCase.getBounds()); |
||||
|
||||
//减去内边距的宽和高
|
||||
Insets insets = xElementCase.getInsets(); |
||||
rectangle.width -= insets.left + insets.right; |
||||
rectangle.height -= insets.top + insets.bottom; |
||||
|
||||
} |
||||
return rectangle; |
||||
} |
||||
|
||||
|
||||
private void addListener(Grid grid, ElementCasePane elementCasePane, int width, int height, int actualWidth, int actualHeight) { |
||||
addGridColumnListener(elementCasePane.getGridColumn(), width); |
||||
addGridRowListener(elementCasePane.getGridRow(), height); |
||||
addMouseListener(grid, width, height, actualWidth, actualHeight); |
||||
} |
||||
|
||||
|
||||
private void drawBoundsLine(Graphics2D g2d, int width, int height) { |
||||
g2d.setPaint(Color.black); |
||||
g2d.setStroke(GraphDrawHelper.getStroke(Constants.LINE_DASH_DOT)); |
||||
g2d.drawLine(0, height, width, height); |
||||
g2d.drawLine(width, 0, width, height); |
||||
} |
||||
|
||||
private void removeGridColumnListener(GridColumn column) { |
||||
MouseMotionListener[] mouseMotionListeners = column.getMouseMotionListeners(); |
||||
for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { |
||||
if (mouseMotionListener instanceof com.fr.grid.GridColumnMouseHandler || mouseMotionListener instanceof GridLimitColumnMouseHandler) { |
||||
column.removeMouseMotionListener(mouseMotionListener); |
||||
} |
||||
} |
||||
MouseListener[] mouseListeners = column.getMouseListeners(); |
||||
for (MouseListener motionListener : mouseListeners) { |
||||
if (motionListener instanceof com.fr.grid.GridColumnMouseHandler || motionListener instanceof GridLimitColumnMouseHandler) { |
||||
column.removeMouseListener(motionListener); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void removeGridRowListener(GridRow row) { |
||||
MouseMotionListener[] mouseMotionListeners = row.getMouseMotionListeners(); |
||||
for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { |
||||
if (mouseMotionListener instanceof com.fr.grid.GridRowMouseHandler || mouseMotionListener instanceof GridLimitRowMouseHandler) { |
||||
row.removeMouseMotionListener(mouseMotionListener); |
||||
} |
||||
} |
||||
MouseListener[] mouseListeners = row.getMouseListeners(); |
||||
for (MouseListener motionListener : mouseListeners) { |
||||
if (motionListener instanceof com.fr.grid.GridRowMouseHandler || motionListener instanceof GridLimitRowMouseHandler) { |
||||
row.removeMouseListener(motionListener); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void removeGridListener(Grid grid) { |
||||
MouseMotionListener[] mouseMotionListeners = grid.getMouseMotionListeners(); |
||||
for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { |
||||
if (mouseMotionListener instanceof AdaptiveGridListener) { |
||||
grid.removeMouseMotionListener(mouseMotionListener); |
||||
break; |
||||
} |
||||
} |
||||
MouseListener[] mouseListeners = grid.getMouseListeners(); |
||||
for (MouseListener motionListener : mouseListeners) { |
||||
if (motionListener instanceof AdaptiveGridListener) { |
||||
grid.removeMouseListener(motionListener); |
||||
break; |
||||
} |
||||
} |
||||
MouseWheelListener[] mouseWheelListeners = grid.getMouseWheelListeners(); |
||||
for (MouseWheelListener mouseWheelListener : mouseWheelListeners) { |
||||
if (mouseWheelListener instanceof AdaptiveGridListener) { |
||||
grid.removeMouseWheelListener(mouseWheelListener); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void addGridColumnListener(GridColumn column, int width) { |
||||
if (gridColumnMouseHandler != null) { |
||||
gridColumnMouseHandler.setLimit(width); |
||||
return; |
||||
} |
||||
removeGridColumnListener(column); |
||||
gridColumnMouseHandler = new GridLimitColumnMouseHandler(column, width); |
||||
column.addMouseListener(gridColumnMouseHandler); |
||||
column.addMouseMotionListener(gridColumnMouseHandler); |
||||
} |
||||
|
||||
|
||||
private void addGridRowListener(GridRow row, int height) { |
||||
if (gridRowMouseHandler != null) { |
||||
gridRowMouseHandler.setLimit(height); |
||||
return; |
||||
} |
||||
removeGridRowListener(row); |
||||
gridRowMouseHandler = new GridLimitRowMouseHandler(row, height); |
||||
row.addMouseMotionListener(gridRowMouseHandler); |
||||
row.addMouseListener(gridRowMouseHandler); |
||||
} |
||||
|
||||
|
||||
private void addMouseListener(Grid grid, int width, int height, int actualWidth, int actualHeight) { |
||||
if (adaptiveGridListener != null) { |
||||
adaptiveGridListener.resetBoundInfo(width, height, actualWidth, actualHeight); |
||||
return; |
||||
} |
||||
removeGridListener(grid); |
||||
adaptiveGridListener = new AdaptiveGridListener(grid, width, height, actualWidth, actualHeight); |
||||
grid.addMouseMotionListener(adaptiveGridListener); |
||||
grid.addMouseListener(adaptiveGridListener); |
||||
grid.addMouseWheelListener(adaptiveGridListener); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue