forked from fanruan/design
superman
7 years ago
18 changed files with 653 additions and 395 deletions
@ -0,0 +1,99 @@ |
|||||||
|
package com.fr.design.mainframe; |
||||||
|
|
||||||
|
import com.fr.design.actions.UpdateAction; |
||||||
|
import com.fr.design.actions.core.ActionFactory; |
||||||
|
import com.fr.design.file.HistoryTemplateListPane; |
||||||
|
import com.fr.design.gui.ibutton.UIButton; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.gui.itoolbar.UIToolbar; |
||||||
|
import com.fr.design.layout.TableLayout; |
||||||
|
import com.fr.design.layout.TableLayoutHelper; |
||||||
|
import com.fr.design.menu.KeySetUtils; |
||||||
|
import com.fr.design.menu.MenuDef; |
||||||
|
import com.fr.general.Inter; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* 悬浮元素 |
||||||
|
* Created by MoMeak on 2017/7/27. |
||||||
|
*/ |
||||||
|
public class ReportFloatPane extends JPanel { |
||||||
|
|
||||||
|
private static ReportFloatPane THIS; |
||||||
|
private ElementCasePaneDelegate elementCasePaneDelegate; |
||||||
|
private MenuDef insertFloatMenu; |
||||||
|
|
||||||
|
private ReportFloatPane() { |
||||||
|
initComponent(); |
||||||
|
} |
||||||
|
|
||||||
|
public synchronized static final ReportFloatPane getInstance() { |
||||||
|
if (THIS == null) { |
||||||
|
THIS = new ReportFloatPane(); |
||||||
|
} |
||||||
|
return THIS; |
||||||
|
} |
||||||
|
|
||||||
|
private void initComponent() { |
||||||
|
this.setLayout(new BorderLayout()); |
||||||
|
|
||||||
|
UIToolbar topToolBar = new UIToolbar(); |
||||||
|
topToolBar.setLayout(new BorderLayout()); |
||||||
|
insertFloatMenu = createInsertToolBar(); |
||||||
|
topToolBar.add(createButtonUI()); |
||||||
|
topToolBar.setBorder(BorderFactory.createEmptyBorder(2, 10, 2, 0)); |
||||||
|
|
||||||
|
double p = TableLayout.PREFERRED; |
||||||
|
double f = TableLayout.FILL; |
||||||
|
double[] columnSize = {p, f}; |
||||||
|
double[] rowSize = {p}; |
||||||
|
Component[][] components = new Component[][]{ |
||||||
|
new Component[]{new UILabel(" " + Inter.getLocText("FR-Designer_Add_FloatElement")), topToolBar}, |
||||||
|
}; |
||||||
|
JPanel leftTopPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||||
|
leftTopPane.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 10)); |
||||||
|
this.add(leftTopPane, BorderLayout.NORTH); |
||||||
|
} |
||||||
|
|
||||||
|
private MenuDef createInsertToolBar() { |
||||||
|
MenuDef insertFloatMenu = new MenuDef(); |
||||||
|
insertFloatMenu.setName(KeySetUtils.INSERT_FLOAT.getMenuKeySetName()); |
||||||
|
insertFloatMenu.setTooltip(Inter.getLocText("FR-Designer_T_Insert_Float")); |
||||||
|
insertFloatMenu.setIconPath("com/fr/design/images/control/addPopup.png"); |
||||||
|
JTemplate editingTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); |
||||||
|
elementCasePaneDelegate = (ElementCasePaneDelegate) editingTemplate.getCurrentElementCasePane(); |
||||||
|
UpdateAction[] actions = ActionFactory.createFloatInsertAction(ElementCasePane.class, elementCasePaneDelegate); |
||||||
|
for (int i = 0; i < actions.length; i++) { |
||||||
|
insertFloatMenu.addShortCut(actions[i]); |
||||||
|
} |
||||||
|
return insertFloatMenu; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private UIButton createButtonUI() { |
||||||
|
UIButton createdButton = insertFloatMenu.createUIButton(); |
||||||
|
// 此按钮单独抽出,不应使用工具栏外观
|
||||||
|
if (!createdButton.isOpaque()) { |
||||||
|
createdButton.setOpaque(true); |
||||||
|
createdButton.setNormalPainted(true); |
||||||
|
createdButton.setBorderPaintedOnlyWhenPressed(false); |
||||||
|
} |
||||||
|
return createdButton; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
// JFrame jf = new JFrame("test");
|
||||||
|
// jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
// JPanel content = (JPanel) jf.getContentPane();
|
||||||
|
// content.setLayout(new BorderLayout());
|
||||||
|
// content.add(ReportFloatPane.getInstance(), BorderLayout.CENTER);
|
||||||
|
// GUICoreUtils.centerWindow(jf);
|
||||||
|
// jf.setSize(250, 400);
|
||||||
|
// jf.setVisible(true);
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -1,102 +1,127 @@ |
|||||||
package com.fr.quickeditor.floatquick; |
package com.fr.quickeditor.floatquick; |
||||||
|
|
||||||
import java.awt.*; |
import com.fr.base.BaseUtils; |
||||||
|
|
||||||
import javax.swing.*; |
|
||||||
import javax.swing.event.DocumentEvent; |
|
||||||
import javax.swing.event.DocumentListener; |
|
||||||
|
|
||||||
import com.fr.base.Formula; |
import com.fr.base.Formula; |
||||||
import com.fr.base.Style; |
import com.fr.base.Style; |
||||||
import com.fr.base.TextFormat; |
import com.fr.base.TextFormat; |
||||||
import com.fr.design.gui.itextfield.UITextField; |
import com.fr.design.file.HistoryTemplateListPane; |
||||||
import com.fr.design.layout.TableLayout; |
import com.fr.design.gui.ibutton.UIButton; |
||||||
import com.fr.design.layout.TableLayoutHelper; |
import com.fr.design.mainframe.ElementCasePane; |
||||||
import com.fr.quickeditor.FloatQuickEditor; |
import com.fr.quickeditor.FloatQuickEditor; |
||||||
import com.fr.report.ReportHelper; |
import com.fr.report.ReportHelper; |
||||||
import com.fr.stable.StringUtils; |
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import javax.swing.event.DocumentEvent; |
||||||
|
import javax.swing.event.DocumentListener; |
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.ActionListener; |
||||||
|
|
||||||
public class FloatStringQuickEditor extends FloatQuickEditor { |
public class FloatStringQuickEditor extends FloatQuickEditor { |
||||||
private UITextField stringTextField; |
private JTextArea stringTextField; |
||||||
|
private UIButton formulaButton; |
||||||
// august:如果是原来编辑的是公式,要保留公式里的这些属性,不然在公式和字符串转化时,就会丢失这些属性设置
|
|
||||||
private boolean reserveInResult = false; |
// august:如果是原来编辑的是公式,要保留公式里的这些属性,不然在公式和字符串转化时,就会丢失这些属性设置
|
||||||
private boolean reserveOnWriteOrAnaly = true; |
private boolean reserveInResult = false; |
||||||
|
private boolean reserveOnWriteOrAnaly = true; |
||||||
public FloatStringQuickEditor() { |
|
||||||
super(); |
public FloatStringQuickEditor() { |
||||||
double p = TableLayout.PREFERRED; |
super(); |
||||||
double f = TableLayout.FILL; |
stringTextField = new JTextArea(); |
||||||
double[] cloumnSize = {f}; |
initTextField(); |
||||||
double[] rowSize = {p}; |
formulaButton = new UIButton(); |
||||||
stringTextField = new UITextField(); |
formulaButton.setPreferredSize(new Dimension(25, 23)); |
||||||
Component[][] components = new Component[][]{ |
formulaButton.setIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/formula.png")); |
||||||
new Component[]{stringTextField} |
formulaButton.addActionListener(getFormulaActionListener); |
||||||
}; |
JPanel pane = new JPanel(new BorderLayout(5, 0)); |
||||||
JPanel pane = TableLayoutHelper.createTableLayoutPane(components,rowSize,cloumnSize) ; |
pane.add(stringTextField, BorderLayout.CENTER); |
||||||
|
pane.add(formulaButton, BorderLayout.EAST); |
||||||
|
formulaButton.setVisible(false); |
||||||
this.setLayout(new BorderLayout()); |
this.setLayout(new BorderLayout()); |
||||||
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
||||||
this.add(pane,BorderLayout.CENTER); |
this.add(pane, BorderLayout.NORTH); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
private void initTextField() { |
||||||
protected void refreshDetails() { |
stringTextField.setFont(new Font("Dialog", Font.PLAIN, 12)); |
||||||
String str = null; |
stringTextField.setOpaque(true); |
||||||
Object value = floatElement.getValue(); |
stringTextField.setLineWrap(true); |
||||||
if (value == null) { |
stringTextField.setWrapStyleWord(true); |
||||||
str = StringUtils.EMPTY; |
stringTextField.setMargin(new Insets(5, 5, 5, 5)); |
||||||
} else if (value instanceof Formula) { |
stringTextField.setBorder(BorderFactory.createLineBorder(Color.gray)); |
||||||
Formula formula = (Formula)value; |
stringTextField.setBackground(Color.white); |
||||||
str = formula.getContent(); |
} |
||||||
reserveInResult = formula.isReserveInResult(); |
|
||||||
reserveOnWriteOrAnaly = formula.isReserveOnWriteOrAnaly(); |
ActionListener getFormulaActionListener = new ActionListener() { |
||||||
} else { |
@Override |
||||||
str = value.toString(); |
public void actionPerformed(ActionEvent e) { |
||||||
} |
((ElementCasePane) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().getCurrentElementCasePane()).getGrid().startEditing(); |
||||||
showText(str); |
} |
||||||
} |
}; |
||||||
|
|
||||||
public void showText(String str) { |
@Override |
||||||
stringTextField.getDocument().removeDocumentListener(documentListener); |
protected void refreshDetails() { |
||||||
stringTextField.setText(str); |
String str = null; |
||||||
stringTextField.getDocument().addDocumentListener(documentListener); |
Object value = floatElement.getValue(); |
||||||
} |
if (value == null) { |
||||||
|
str = StringUtils.EMPTY; |
||||||
DocumentListener documentListener = new DocumentListener() { |
} else if (value instanceof Formula) { |
||||||
|
//MoMeak: 没拆文本框和公式所以需要这么个玩意
|
||||||
@Override |
formulaButton.setVisible(true); |
||||||
public void insertUpdate(DocumentEvent e) { |
Formula formula = (Formula) value; |
||||||
changeReportPaneCell(stringTextField.getText().trim()); |
str = formula.getContent(); |
||||||
} |
stringTextField.setLineWrap(false); |
||||||
|
this.setBorder(BorderFactory.createEmptyBorder(10, 74, 10, 10)); |
||||||
@Override |
reserveInResult = formula.isReserveInResult(); |
||||||
public void removeUpdate(DocumentEvent e) { |
reserveOnWriteOrAnaly = formula.isReserveOnWriteOrAnaly(); |
||||||
changeReportPaneCell(stringTextField.getText().trim()); |
} else { |
||||||
} |
str = value.toString(); |
||||||
|
} |
||||||
@Override |
showText(str); |
||||||
public void changedUpdate(DocumentEvent e) { |
} |
||||||
changeReportPaneCell(stringTextField.getText().trim()); |
|
||||||
} |
public void showText(String str) { |
||||||
|
stringTextField.getDocument().removeDocumentListener(documentListener); |
||||||
}; |
stringTextField.setText(str); |
||||||
|
stringTextField.getDocument().addDocumentListener(documentListener); |
||||||
protected void changeReportPaneCell(String tmpText) { |
} |
||||||
if (tmpText != null && (tmpText.length() > 0 && tmpText.charAt(0) == '=')) { |
|
||||||
Formula textFormula = new Formula(tmpText); |
DocumentListener documentListener = new DocumentListener() { |
||||||
textFormula.setReserveInResult(reserveInResult); |
|
||||||
textFormula.setReserveOnWriteOrAnaly(reserveOnWriteOrAnaly); |
@Override |
||||||
floatElement.setValue(textFormula); |
public void insertUpdate(DocumentEvent e) { |
||||||
} else { |
changeReportPaneCell(stringTextField.getText().trim()); |
||||||
Style style = floatElement.getStyle(); |
} |
||||||
if (floatElement != null && style != null && style.getFormat() != null && style.getFormat() == TextFormat.getInstance()) { |
|
||||||
floatElement.setValue(tmpText); |
@Override |
||||||
} else { |
public void removeUpdate(DocumentEvent e) { |
||||||
floatElement.setValue(ReportHelper.convertGeneralStringAccordingToExcel(tmpText)); |
changeReportPaneCell(stringTextField.getText().trim()); |
||||||
} |
} |
||||||
} |
|
||||||
fireTargetModified(); |
@Override |
||||||
stringTextField.requestFocus(); |
public void changedUpdate(DocumentEvent e) { |
||||||
} |
changeReportPaneCell(stringTextField.getText().trim()); |
||||||
|
} |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
protected void changeReportPaneCell(String tmpText) { |
||||||
|
if (tmpText != null && (tmpText.length() > 0 && tmpText.charAt(0) == '=')) { |
||||||
|
Formula textFormula = new Formula(tmpText); |
||||||
|
textFormula.setReserveInResult(reserveInResult); |
||||||
|
textFormula.setReserveOnWriteOrAnaly(reserveOnWriteOrAnaly); |
||||||
|
floatElement.setValue(textFormula); |
||||||
|
} else { |
||||||
|
Style style = floatElement.getStyle(); |
||||||
|
if (floatElement != null && style != null && style.getFormat() != null && style.getFormat() == TextFormat.getInstance()) { |
||||||
|
floatElement.setValue(tmpText); |
||||||
|
} else { |
||||||
|
floatElement.setValue(ReportHelper.convertGeneralStringAccordingToExcel(tmpText)); |
||||||
|
} |
||||||
|
} |
||||||
|
fireTargetModified(); |
||||||
|
stringTextField.requestFocus(); |
||||||
|
} |
||||||
|
|
||||||
} |
} |
Loading…
Reference in new issue