Browse Source

REPORT-3348 普通文本编辑器面板

master
yaoh.wu 7 years ago
parent
commit
ac8adaaca2
  1. 51
      designer/src/com/fr/quickeditor/cellquick/CellStringQuickEditor.java

51
designer/src/com/fr/quickeditor/cellquick/CellStringQuickEditor.java

@ -3,7 +3,8 @@ package com.fr.quickeditor.cellquick;
import com.fr.base.Formula;
import com.fr.base.Style;
import com.fr.base.TextFormat;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.gui.itextarea.UITextArea;
import com.fr.grid.GridKeyListener;
import com.fr.grid.selection.CellSelection;
import com.fr.quickeditor.CellQuickEditor;
import com.fr.report.ReportHelper;
@ -22,12 +23,8 @@ import java.awt.event.KeyEvent;
*
*/
public class CellStringQuickEditor extends CellQuickEditor {
//instance
private static CellStringQuickEditor THIS;
//文本域
//TODO 9.0 文本域要根据具体文本数量自适应大小,比较难搞,先跳过。
private UITextField stringTextField;
//文本域 直接可以自适应大小
private UITextArea stringTextArea;
//编辑状态
private boolean isEditing = false;
@ -39,17 +36,17 @@ public class CellStringQuickEditor extends CellQuickEditor {
private DocumentListener documentListener = new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
changeReportPaneCell(stringTextField.getText().trim());
changeReportPaneCell(stringTextArea.getText().trim());
}
@Override
public void removeUpdate(DocumentEvent e) {
changeReportPaneCell(stringTextField.getText().trim());
changeReportPaneCell(stringTextArea.getText().trim());
}
@Override
public void changedUpdate(DocumentEvent e) {
changeReportPaneCell(stringTextField.getText().trim());
changeReportPaneCell(stringTextArea.getText().trim());
}
};
@ -60,22 +57,38 @@ public class CellStringQuickEditor extends CellQuickEditor {
/**
* 详细信息面板
* todo 文本框可自适应大小公式编辑新写一个
*/
@Override
public JComponent createCenterBody() {
JPanel content = new JPanel(new BorderLayout());
content.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 15));
stringTextField = new UITextField();
stringTextField.addKeyListener(new KeyAdapter() {
stringTextArea = new UITextArea();
stringTextArea.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (tc == null) {
return;
}
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
//todo yaoh.wu虽然模仿选中单元格按enter可以做到,但是原理没有弄清楚。
GridKeyListener dispatchListener = new GridKeyListener(tc.getGrid());
dispatchListener.keyPressed(e);
dispatchListener.keyTyped(e);
}
}
@Override
public void keyReleased(KeyEvent e) {
if (tc != null) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
return;
}
tc.getGrid().dispatchEvent(e);
}
}
});
content.add(stringTextField, BorderLayout.CENTER);
content.add(stringTextArea, BorderLayout.CENTER);
return content;
}
@ -107,7 +120,7 @@ public class CellStringQuickEditor extends CellQuickEditor {
}
}
fireTargetModified();
stringTextField.requestFocus();
stringTextArea.requestFocus();
isEditing = false;
}
@ -133,7 +146,7 @@ public class CellStringQuickEditor extends CellQuickEditor {
}
}
showText(str);
stringTextField.setEditable(tc.isSelectedOneCell());
stringTextArea.setEditable(tc.isSelectedOneCell());
}
/**
@ -146,9 +159,9 @@ public class CellStringQuickEditor extends CellQuickEditor {
if (isEditing) {
return;
}
stringTextField.getDocument().removeDocumentListener(documentListener);
stringTextField.setText(str);
stringTextField.getDocument().addDocumentListener(documentListener);
stringTextArea.getDocument().removeDocumentListener(documentListener);
stringTextArea.setText(str);
stringTextArea.getDocument().addDocumentListener(documentListener);
}
@Override

Loading…
Cancel
Save