finereport
7 years ago
63 changed files with 2812 additions and 2639 deletions
@ -1,71 +1,71 @@
|
||||
package com.fr.design.report; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.data.VerifyItem; |
||||
import com.fr.design.gui.itableeditorpane.ActionStyle; |
||||
import com.fr.design.gui.itableeditorpane.UIArrayFormulaTableModel; |
||||
import com.fr.design.gui.itableeditorpane.UITableEditorPane; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.general.GeneralUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.report.write.ValueVerifier; |
||||
import com.fr.stable.FormulaProvider; |
||||
import com.fr.stable.StableUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
public class ValueVerifierEditPane extends JPanel { |
||||
private UITableEditorPane<Object[]> tableEditorPane; |
||||
private final String[] columnNames = new String[] { |
||||
Inter.getLocText(new String[] {"Verify-Verify_Formula", "Verify-ToolTips"}, new String[] {"(", ")"}), |
||||
Inter.getLocText("Verify-Error_Information") }; |
||||
|
||||
public ValueVerifierEditPane() { |
||||
// ben:UITableEditorPane;
|
||||
this.setLayout(FRGUIPaneFactory.createM_BorderLayout()); |
||||
tableEditorPane = new UITableEditorPane(new UIArrayFormulaTableModel(columnNames, new int[] { |
||||
ActionStyle.ADDSTYLE, ActionStyle.DELETESTYLE, |
||||
ActionStyle.MOVEUPSTYLE, ActionStyle.MOVEDOWNSTYLE})); |
||||
this.add(tableEditorPane, BorderLayout.CENTER); |
||||
} |
||||
|
||||
/** |
||||
* populate |
||||
*/ |
||||
public void populate(ValueVerifier valueVerifier) { |
||||
if (valueVerifier == null) { |
||||
return; |
||||
} |
||||
int rowCount = valueVerifier.getVerifyItemsCount(); |
||||
Object[][] os = new Object[rowCount][]; |
||||
int tableDataCount = 0; |
||||
for (int i = 0; i < rowCount; i ++) { |
||||
VerifyItem item = valueVerifier.getVerifyItem(i); |
||||
FormulaProvider formula = item.getFormula(); |
||||
if (formula == null) { |
||||
continue; |
||||
} |
||||
String msg = item.getMessage(); |
||||
if (!StableUtils.canBeFormula(msg)) { |
||||
msg = "\"" + msg + "\"";//如果报错信息是以前的写法(字符串)就拼上""
|
||||
} |
||||
os[tableDataCount++] = new Object[]{formula, new Formula(msg)}; |
||||
} |
||||
this.tableEditorPane.populate(os); |
||||
} |
||||
|
||||
public ValueVerifier update() { |
||||
ValueVerifier valueVerifier = new ValueVerifier(); |
||||
java.util.List<Object[]> list = tableEditorPane.update(); |
||||
for (int i = 0; i < list.size(); i++) { |
||||
Object[] o = list.get(i); |
||||
if (o == null || o[0] == null) { |
||||
continue; |
||||
} |
||||
VerifyItem item = new VerifyItem(new Formula(GeneralUtils.objectToString(o[0])), GeneralUtils.objectToString(o[1])); |
||||
valueVerifier.addVerifyItem(item); |
||||
} |
||||
return valueVerifier; |
||||
} |
||||
} |
||||
package com.fr.design.report; |
||||
|
||||
import com.fr.base.BaseFormula; |
||||
import com.fr.data.VerifyItem; |
||||
import com.fr.design.gui.itableeditorpane.ActionStyle; |
||||
import com.fr.design.gui.itableeditorpane.UIArrayFormulaTableModel; |
||||
import com.fr.design.gui.itableeditorpane.UITableEditorPane; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.general.GeneralUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.report.write.ValueVerifier; |
||||
import com.fr.stable.FormulaProvider; |
||||
import com.fr.stable.StableUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
public class ValueVerifierEditPane extends JPanel { |
||||
private UITableEditorPane<Object[]> tableEditorPane; |
||||
private final String[] columnNames = new String[] { |
||||
Inter.getLocText(new String[] {"Verify-Verify_Formula", "Verify-ToolTips"}, new String[] {"(", ")"}), |
||||
Inter.getLocText("Verify-Error_Information") }; |
||||
|
||||
public ValueVerifierEditPane() { |
||||
// ben:UITableEditorPane;
|
||||
this.setLayout(FRGUIPaneFactory.createM_BorderLayout()); |
||||
tableEditorPane = new UITableEditorPane(new UIArrayFormulaTableModel(columnNames, new int[] { |
||||
ActionStyle.ADDSTYLE, ActionStyle.DELETESTYLE, |
||||
ActionStyle.MOVEUPSTYLE, ActionStyle.MOVEDOWNSTYLE})); |
||||
this.add(tableEditorPane, BorderLayout.CENTER); |
||||
} |
||||
|
||||
/** |
||||
* populate |
||||
*/ |
||||
public void populate(ValueVerifier valueVerifier) { |
||||
if (valueVerifier == null) { |
||||
return; |
||||
} |
||||
int rowCount = valueVerifier.getVerifyItemsCount(); |
||||
Object[][] os = new Object[rowCount][]; |
||||
int tableDataCount = 0; |
||||
for (int i = 0; i < rowCount; i ++) { |
||||
VerifyItem item = valueVerifier.getVerifyItem(i); |
||||
FormulaProvider formula = item.getFormula(); |
||||
if (formula == null) { |
||||
continue; |
||||
} |
||||
String msg = item.getMessage(); |
||||
if (!StableUtils.canBeFormula(msg)) { |
||||
msg = "\"" + msg + "\"";//如果报错信息是以前的写法(字符串)就拼上""
|
||||
} |
||||
os[tableDataCount++] = new Object[]{formula, BaseFormula.createFormulaBuilder().build(msg)}; |
||||
} |
||||
this.tableEditorPane.populate(os); |
||||
} |
||||
|
||||
public ValueVerifier update() { |
||||
ValueVerifier valueVerifier = new ValueVerifier(); |
||||
java.util.List<Object[]> list = tableEditorPane.update(); |
||||
for (int i = 0; i < list.size(); i++) { |
||||
Object[] o = list.get(i); |
||||
if (o == null || o[0] == null) { |
||||
continue; |
||||
} |
||||
VerifyItem item = new VerifyItem(BaseFormula.createFormulaBuilder().build(o[0]), GeneralUtils.objectToString(o[1])); |
||||
valueVerifier.addVerifyItem(item); |
||||
} |
||||
return valueVerifier; |
||||
} |
||||
} |
||||
|
File diff suppressed because one or more lines are too long
@ -1,405 +1,408 @@
|
||||
package com.fr.design.editor; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.editor.editor.*; |
||||
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.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.imenu.UIMenuEastAttrItem; |
||||
import com.fr.design.gui.imenu.UIPopupEastAttrMenu; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
public class ValueEditorPane extends BasicPane implements UIObserver, GlobalNameObserver { |
||||
|
||||
private Editor[] cards; |
||||
|
||||
private Editor currentEditor; |
||||
|
||||
private UIButton arrowButton; |
||||
private JPopupMenu menu; |
||||
private JPanel centerPane; |
||||
|
||||
private Object value; |
||||
|
||||
private GlobalNameListener globalNameListener = null; |
||||
private UIObserverListener uiObserverListener = null; |
||||
|
||||
public ValueEditorPane(Editor[] cards) { |
||||
this(cards, null, null); |
||||
} |
||||
|
||||
public ValueEditorPane(Editor[] cards, String popupName, String textEditorValue) { |
||||
initComponents(cards, popupName, textEditorValue, 200); |
||||
} |
||||
|
||||
public ValueEditorPane(Editor[] cards, String popupName, String textEditorValue, int centerPaneWidth) { |
||||
initComponents(cards, popupName, textEditorValue, centerPaneWidth); |
||||
} |
||||
|
||||
private void initComponents(final Editor[] cards, String popupName, String textEditorValue, int centerPaneWidth) { |
||||
|
||||
this.cards = cards; |
||||
|
||||
// Frank:布局
|
||||
this.setLayout(new BorderLayout(2, 0)); |
||||
centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
arrowButton = new UIButton(); |
||||
arrowButton.set4ToolbarButton(); |
||||
setCurrentEditor(0); |
||||
centerPane.setPreferredSize(new Dimension(centerPaneWidth, centerPane.getPreferredSize().height)); |
||||
arrowButton.setPreferredSize(new Dimension(20, centerPane.getPreferredSize().height)); |
||||
final Color beforeColor = arrowButton.getBackground(); |
||||
menu = createPopMenu(); |
||||
|
||||
arrowButton.addMouseListener(new MouseAdapter() { |
||||
public void mouseEntered(MouseEvent a) { |
||||
if (cards != null && cards.length > 1) { |
||||
arrowButton.setBackground(new Color(228, 246, 255)); |
||||
arrowButton.repaint(); |
||||
} |
||||
} |
||||
|
||||
public void mouseExited(MouseEvent a) { |
||||
arrowButton.setBackground(beforeColor); |
||||
arrowButton.setBorder(null); |
||||
} |
||||
}); |
||||
arrowButton.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
if (cards != null && cards.length > 1) { // 如果只有“列”的话,就不需要弹出菜单了
|
||||
Rectangle re = centerPane.getBounds(); |
||||
menu.setPopupSize(re.width + arrowButton.getWidth(), menu.getPreferredSize().height); |
||||
menu.show(centerPane, -arrowButton.getWidth(), re.height); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
this.add(centerPane, BorderLayout.CENTER); |
||||
if (cards.length > 1) { |
||||
this.add(arrowButton, BorderLayout.WEST); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("FR-Designer_Values-Editor"); |
||||
} |
||||
|
||||
public Editor getCurrentEditor() { |
||||
return currentEditor; |
||||
} |
||||
|
||||
public int getCurrentEditorIndex() { |
||||
for (int i = 0;i < cards.length; i++){ |
||||
if (cards[i].getClass() == currentEditor.getClass()){ |
||||
return i; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
public void setCurrentEditor(int i) { |
||||
this.add(arrowButton, BorderLayout.WEST); |
||||
currentEditor = this.cards[i]; |
||||
centerPane.removeAll(); |
||||
centerPane.add(currentEditor); |
||||
centerPane.validate(); |
||||
centerPane.repaint(); |
||||
arrowButton.setIcon(cards[i].getIcon()); |
||||
if (this.cards.length == 1) { |
||||
this.remove(arrowButton); |
||||
} |
||||
} |
||||
|
||||
public void setCurrentEditor(Class editorClass) { |
||||
for (int i = 0; i < cards.length; i++) { |
||||
if (cards[i].getClass() == editorClass) { |
||||
setCurrentEditor(i); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
private JPopupMenu createPopMenu() { |
||||
JPopupMenu scate = new UIPopupEastAttrMenu(); |
||||
|
||||
if (this.cards == null) { |
||||
return scate; |
||||
} |
||||
|
||||
for (int i = 0; i < this.cards.length; i++) { |
||||
JMenuItem item = new UIMenuEastAttrItem(cards[i].getName()); |
||||
final int j = i; |
||||
item.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
if (globalNameListener != null) { |
||||
globalNameListener.setGlobalName(Inter.getLocText("CellWrite-InsertRow_Policy")); |
||||
} |
||||
Object oldValue = currentEditor.getValue(); |
||||
setCurrentEditor(j); |
||||
currentEditor.selected(); |
||||
value = currentEditor.getValue(); |
||||
if (uiObserverListener != null) { |
||||
uiObserverListener.doChange(); |
||||
} |
||||
|
||||
ValueEditorPane.this.firePropertyChange("value", oldValue, value); |
||||
} |
||||
}); |
||||
scate.add(item); |
||||
} |
||||
return scate; |
||||
} |
||||
|
||||
public void populate(Object object) { |
||||
for (int i = 0; i < cards.length; i++) { |
||||
if (cards[i].accept(object)) { |
||||
setCardValue(i,object); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void populate(Object object,String name) { |
||||
for (int i = 0; i < cards.length; i++) { |
||||
if (cards[i].accept(object) && ComparatorUtils.equals(cards[i].getName(),name)) { |
||||
setCardValue(i,object); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void setCardValue(int i,Object object){ |
||||
setCurrentEditor(i); |
||||
cards[i].setValue(object); |
||||
// kunsnat: bug7861 所有的Editor值都要跟随改变, 因为populate的editor 从""
|
||||
// 一定是最后的Editor哦.
|
||||
for (int j = 0; j < cards.length; j++) { |
||||
if (i == j) { |
||||
continue; |
||||
} |
||||
this.cards[j].setValue(null); |
||||
} |
||||
} |
||||
|
||||
public Object update() { |
||||
String name = currentEditor.getName(); |
||||
Object columnIndex = currentEditor.getValue(); |
||||
//bug86542,这边为啥要new一个公式出来,只保留content,其他属性全不要了?
|
||||
//MoMeak:我也想注释了,但是有bug啊。。。
|
||||
if (columnIndex == null && ComparatorUtils.equals(name, Inter.getLocText("Formula"))) { |
||||
columnIndex = ((FormulaEditor) currentEditor).getFormula(); |
||||
} |
||||
|
||||
return columnIndex; |
||||
} |
||||
|
||||
public Object update(String makeAdiff) { |
||||
String name = currentEditor.getName(); |
||||
Object columnIndex = currentEditor.getValue(); |
||||
Object columnName = StringUtils.EMPTY; |
||||
|
||||
if (ComparatorUtils.equals(name, Inter.getLocText("FR-Designer_Formula"))) { |
||||
columnIndex = new Formula(columnIndex == null ? "" : columnIndex.toString()); |
||||
} |
||||
|
||||
if (currentEditor instanceof ColumnNameEditor) { |
||||
columnName = ((ColumnNameEditor) currentEditor).getColumnName(); |
||||
} |
||||
|
||||
return new Object[]{columnIndex, columnName}; |
||||
} |
||||
|
||||
public Object update(boolean isXMLA) { |
||||
String name = currentEditor.getName(); |
||||
Object columnIndex = currentEditor.getValue(); |
||||
Object columnName = StringUtils.EMPTY; |
||||
|
||||
if (ComparatorUtils.equals(name, Inter.getLocText("FR-Designer_Formula"))) { |
||||
columnIndex = new Formula(columnIndex == null ? "" : columnIndex.toString()); |
||||
} |
||||
|
||||
if (isXMLA) { |
||||
columnName = ((XMLANameEditor) currentEditor).getColumnName(); |
||||
} |
||||
|
||||
return new Object[]{columnIndex, columnName}; |
||||
} |
||||
|
||||
public void setEditors(Editor[] editors, Object obj) { |
||||
this.cards = editors; |
||||
this.populate(obj); |
||||
} |
||||
|
||||
/** |
||||
* 检查是否有效 |
||||
* |
||||
* @throws Exception 异常 |
||||
*/ |
||||
public void checkValid() throws Exception { |
||||
if (!(currentEditor instanceof TextEditor)) { |
||||
return; |
||||
} |
||||
|
||||
int i; |
||||
boolean containFormulaType = false; |
||||
for (i = 0; i < cards.length; i++) { |
||||
if (ComparatorUtils.equals(cards[i].getName(), Inter.getLocText("FR-Engine_Parameter-Formula"))) { |
||||
containFormulaType = true; |
||||
break; |
||||
} |
||||
} |
||||
if (!containFormulaType) { |
||||
return; |
||||
} |
||||
|
||||
final int j = i; |
||||
|
||||
if (!(currentEditor instanceof TextEditor)) { |
||||
return; |
||||
} |
||||
String string = (String) currentEditor.getValue(); |
||||
if (isFormula(string)) { |
||||
DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager(); |
||||
if (designerEnvManager.isSupportStringToFormula()) { |
||||
if (!designerEnvManager.isDefaultStringToFormula()) { |
||||
int returnValue = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_Edit_String_To_Formula") |
||||
+ "?", Inter.getLocText("FR-Designer_Tooltips"), JOptionPane.YES_NO_OPTION); |
||||
if (returnValue == JOptionPane.OK_OPTION) { |
||||
|
||||
setCurrentEditor(j); |
||||
Formula formula = new Formula(string); |
||||
currentEditor.setValue(formula); |
||||
} |
||||
} else { |
||||
setCurrentEditor(j); |
||||
Formula formula = new Formula(string); |
||||
currentEditor.setValue(formula); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
private boolean isFormula(String string) { |
||||
return StringUtils.isNotBlank(string) && (string.length() > 0 && string.charAt(0) == '='); |
||||
} |
||||
|
||||
@Override |
||||
public void setEnabled(boolean enabled) { |
||||
arrowButton.setEnabled(enabled); |
||||
for (Editor card : cards) { |
||||
card.setEnabled(enabled); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 重置组件 |
||||
*/ |
||||
public void resetComponets() { |
||||
for (Editor card : cards) { |
||||
card.reset(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 清除组件数据 |
||||
*/ |
||||
public void clearComponentsData() { |
||||
for (Editor card : cards) { |
||||
card.clearData(); |
||||
} |
||||
} |
||||
|
||||
public Editor[] getCards() { |
||||
return this.cards; |
||||
} |
||||
|
||||
public JPopupMenu getMenu() { |
||||
return this.menu; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 注册全局名字监听事件 |
||||
* |
||||
* @param listener 观察者监听事件 |
||||
*/ |
||||
public void registerNameListener(GlobalNameListener listener) { |
||||
globalNameListener = listener; |
||||
} |
||||
|
||||
/** |
||||
* 是否对名字listener监听器做出响应 |
||||
* |
||||
* @return 如果要做出响应,则返回true |
||||
*/ |
||||
public boolean shouldResponseNameListener() { |
||||
return false; |
||||
} |
||||
|
||||
public void setGlobalName(String name) { |
||||
for (Editor card : cards) { |
||||
setComponentGlobalName(card, name); |
||||
} |
||||
} |
||||
|
||||
private void setComponentGlobalName(Container card, String name) { |
||||
for (int i = 0, len = card.getComponentCount(); i < len; i++) { |
||||
Component component = card.getComponent(i); |
||||
if (component instanceof GlobalNameObserver) { |
||||
((GlobalNameObserver) component).setGlobalName(name); |
||||
} else { |
||||
setComponentGlobalName((Container) component, name); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 给组件登记一个观察者监听事件 |
||||
* |
||||
* @param listener 观察者监听事件 |
||||
*/ |
||||
public void registerChangeListener(UIObserverListener listener) { |
||||
uiObserverListener = listener; |
||||
for (Editor card : cards) { |
||||
doLoop(card, listener); |
||||
} |
||||
} |
||||
|
||||
private void doLoop(Container card, UIObserverListener listener) { |
||||
for (int i = 0, len = card.getComponentCount(); i < len; i++) { |
||||
Component component = card.getComponent(i); |
||||
if (component instanceof UIObserver) { |
||||
((UIObserver) component).registerChangeListener(listener); |
||||
} else { |
||||
doLoop((Container) component, listener); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 组件是否需要响应添加的观察者事件 |
||||
* |
||||
* @return 如果需要响应观察者事件则返回true,否则返回false |
||||
*/ |
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
package com.fr.design.editor; |
||||
|
||||
import com.fr.base.BaseFormula; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.editor.editor.ColumnNameEditor; |
||||
import com.fr.design.editor.editor.Editor; |
||||
import com.fr.design.editor.editor.FormulaEditor; |
||||
import com.fr.design.editor.editor.TextEditor; |
||||
import com.fr.design.editor.editor.XMLANameEditor; |
||||
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.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.imenu.UIMenuEastAttrItem; |
||||
import com.fr.design.gui.imenu.UIPopupEastAttrMenu; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
public class ValueEditorPane extends BasicPane implements UIObserver, GlobalNameObserver { |
||||
|
||||
private Editor[] cards; |
||||
|
||||
private Editor currentEditor; |
||||
|
||||
private UIButton arrowButton; |
||||
private JPopupMenu menu; |
||||
private JPanel centerPane; |
||||
|
||||
private Object value; |
||||
|
||||
private GlobalNameListener globalNameListener = null; |
||||
private UIObserverListener uiObserverListener = null; |
||||
|
||||
public ValueEditorPane(Editor[] cards) { |
||||
this(cards, null, null); |
||||
} |
||||
|
||||
public ValueEditorPane(Editor[] cards, String popupName, String textEditorValue) { |
||||
initComponents(cards, popupName, textEditorValue, 200); |
||||
} |
||||
|
||||
public ValueEditorPane(Editor[] cards, String popupName, String textEditorValue, int centerPaneWidth) { |
||||
initComponents(cards, popupName, textEditorValue, centerPaneWidth); |
||||
} |
||||
|
||||
private void initComponents(final Editor[] cards, String popupName, String textEditorValue, int centerPaneWidth) { |
||||
|
||||
this.cards = cards; |
||||
|
||||
// Frank:布局
|
||||
this.setLayout(new BorderLayout(2, 0)); |
||||
centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
arrowButton = new UIButton(); |
||||
arrowButton.set4ToolbarButton(); |
||||
setCurrentEditor(0); |
||||
centerPane.setPreferredSize(new Dimension(centerPaneWidth, centerPane.getPreferredSize().height)); |
||||
arrowButton.setPreferredSize(new Dimension(20, centerPane.getPreferredSize().height)); |
||||
final Color beforeColor = arrowButton.getBackground(); |
||||
menu = createPopMenu(); |
||||
|
||||
arrowButton.addMouseListener(new MouseAdapter() { |
||||
public void mouseEntered(MouseEvent a) { |
||||
if (cards != null && cards.length > 1) { |
||||
arrowButton.setBackground(new Color(228, 246, 255)); |
||||
arrowButton.repaint(); |
||||
} |
||||
} |
||||
|
||||
public void mouseExited(MouseEvent a) { |
||||
arrowButton.setBackground(beforeColor); |
||||
arrowButton.setBorder(null); |
||||
} |
||||
}); |
||||
arrowButton.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
if (cards != null && cards.length > 1) { // 如果只有“列”的话,就不需要弹出菜单了
|
||||
Rectangle re = centerPane.getBounds(); |
||||
menu.setPopupSize(re.width + arrowButton.getWidth(), menu.getPreferredSize().height); |
||||
menu.show(centerPane, -arrowButton.getWidth(), re.height); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
this.add(centerPane, BorderLayout.CENTER); |
||||
if (cards.length > 1) { |
||||
this.add(arrowButton, BorderLayout.WEST); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("FR-Designer_Values-Editor"); |
||||
} |
||||
|
||||
public Editor getCurrentEditor() { |
||||
return currentEditor; |
||||
} |
||||
|
||||
public int getCurrentEditorIndex() { |
||||
for (int i = 0;i < cards.length; i++){ |
||||
if (cards[i].getClass() == currentEditor.getClass()){ |
||||
return i; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
public void setCurrentEditor(int i) { |
||||
this.add(arrowButton, BorderLayout.WEST); |
||||
currentEditor = this.cards[i]; |
||||
centerPane.removeAll(); |
||||
centerPane.add(currentEditor); |
||||
centerPane.validate(); |
||||
centerPane.repaint(); |
||||
arrowButton.setIcon(cards[i].getIcon()); |
||||
if (this.cards.length == 1) { |
||||
this.remove(arrowButton); |
||||
} |
||||
} |
||||
|
||||
public void setCurrentEditor(Class editorClass) { |
||||
for (int i = 0; i < cards.length; i++) { |
||||
if (cards[i].getClass() == editorClass) { |
||||
setCurrentEditor(i); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
private JPopupMenu createPopMenu() { |
||||
JPopupMenu scate = new UIPopupEastAttrMenu(); |
||||
|
||||
if (this.cards == null) { |
||||
return scate; |
||||
} |
||||
|
||||
for (int i = 0; i < this.cards.length; i++) { |
||||
JMenuItem item = new UIMenuEastAttrItem(cards[i].getName()); |
||||
final int j = i; |
||||
item.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
if (globalNameListener != null) { |
||||
globalNameListener.setGlobalName(Inter.getLocText("CellWrite-InsertRow_Policy")); |
||||
} |
||||
Object oldValue = currentEditor.getValue(); |
||||
setCurrentEditor(j); |
||||
currentEditor.selected(); |
||||
value = currentEditor.getValue(); |
||||
if (uiObserverListener != null) { |
||||
uiObserverListener.doChange(); |
||||
} |
||||
|
||||
ValueEditorPane.this.firePropertyChange("value", oldValue, value); |
||||
} |
||||
}); |
||||
scate.add(item); |
||||
} |
||||
return scate; |
||||
} |
||||
|
||||
public void populate(Object object) { |
||||
for (int i = 0; i < cards.length; i++) { |
||||
if (cards[i].accept(object)) { |
||||
setCardValue(i,object); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void populate(Object object,String name) { |
||||
for (int i = 0; i < cards.length; i++) { |
||||
if (cards[i].accept(object) && ComparatorUtils.equals(cards[i].getName(),name)) { |
||||
setCardValue(i,object); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void setCardValue(int i,Object object){ |
||||
setCurrentEditor(i); |
||||
cards[i].setValue(object); |
||||
// kunsnat: bug7861 所有的Editor值都要跟随改变, 因为populate的editor 从""
|
||||
// 一定是最后的Editor哦.
|
||||
for (int j = 0; j < cards.length; j++) { |
||||
if (i == j) { |
||||
continue; |
||||
} |
||||
this.cards[j].setValue(null); |
||||
} |
||||
} |
||||
|
||||
public Object update() { |
||||
String name = currentEditor.getName(); |
||||
Object columnIndex = currentEditor.getValue(); |
||||
//bug86542,这边为啥要new一个公式出来,只保留content,其他属性全不要了?
|
||||
//MoMeak:我也想注释了,但是有bug啊。。。
|
||||
if (columnIndex == null && ComparatorUtils.equals(name, Inter.getLocText("Formula"))) { |
||||
columnIndex = ((FormulaEditor) currentEditor).getFormula(); |
||||
} |
||||
|
||||
return columnIndex; |
||||
} |
||||
|
||||
public Object update(String makeAdiff) { |
||||
String name = currentEditor.getName(); |
||||
Object columnIndex = currentEditor.getValue(); |
||||
Object columnName = StringUtils.EMPTY; |
||||
|
||||
if (ComparatorUtils.equals(name, Inter.getLocText("FR-Designer_Formula"))) { |
||||
columnIndex = BaseFormula.createFormulaBuilder().build(columnIndex == null ? "" : columnIndex.toString()); |
||||
} |
||||
|
||||
if (currentEditor instanceof ColumnNameEditor) { |
||||
columnName = ((ColumnNameEditor) currentEditor).getColumnName(); |
||||
} |
||||
|
||||
return new Object[]{columnIndex, columnName}; |
||||
} |
||||
|
||||
public Object update(boolean isXMLA) { |
||||
String name = currentEditor.getName(); |
||||
Object columnIndex = currentEditor.getValue(); |
||||
Object columnName = StringUtils.EMPTY; |
||||
|
||||
if (ComparatorUtils.equals(name, Inter.getLocText("FR-Designer_Formula"))) { |
||||
columnIndex = BaseFormula.createFormulaBuilder().build(columnIndex == null ? "" : columnIndex.toString()); |
||||
} |
||||
|
||||
if (isXMLA) { |
||||
columnName = ((XMLANameEditor) currentEditor).getColumnName(); |
||||
} |
||||
|
||||
return new Object[]{columnIndex, columnName}; |
||||
} |
||||
|
||||
public void setEditors(Editor[] editors, Object obj) { |
||||
this.cards = editors; |
||||
this.populate(obj); |
||||
} |
||||
|
||||
/** |
||||
* 检查是否有效 |
||||
* |
||||
* @throws Exception 异常 |
||||
*/ |
||||
public void checkValid() throws Exception { |
||||
if (!(currentEditor instanceof TextEditor)) { |
||||
return; |
||||
} |
||||
|
||||
int i; |
||||
boolean containFormulaType = false; |
||||
for (i = 0; i < cards.length; i++) { |
||||
if (ComparatorUtils.equals(cards[i].getName(), Inter.getLocText("FR-Engine_Parameter-Formula"))) { |
||||
containFormulaType = true; |
||||
break; |
||||
} |
||||
} |
||||
if (!containFormulaType) { |
||||
return; |
||||
} |
||||
|
||||
final int j = i; |
||||
|
||||
if (!(currentEditor instanceof TextEditor)) { |
||||
return; |
||||
} |
||||
String string = (String) currentEditor.getValue(); |
||||
if (isFormula(string)) { |
||||
DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager(); |
||||
if (designerEnvManager.isSupportStringToFormula()) { |
||||
if (!designerEnvManager.isDefaultStringToFormula()) { |
||||
int returnValue = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_Edit_String_To_Formula") |
||||
+ "?", Inter.getLocText("FR-Designer_Tooltips"), JOptionPane.YES_NO_OPTION); |
||||
if (returnValue == JOptionPane.OK_OPTION) { |
||||
|
||||
setCurrentEditor(j); |
||||
BaseFormula formula = BaseFormula.createFormulaBuilder().build(string); |
||||
currentEditor.setValue(formula); |
||||
} |
||||
} else { |
||||
setCurrentEditor(j); |
||||
BaseFormula formula = BaseFormula.createFormulaBuilder().build(string); |
||||
currentEditor.setValue(formula); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private boolean isFormula(String string) { |
||||
return StringUtils.isNotBlank(string) && (string.length() > 0 && string.charAt(0) == '='); |
||||
} |
||||
|
||||
@Override |
||||
public void setEnabled(boolean enabled) { |
||||
arrowButton.setEnabled(enabled); |
||||
for (Editor card : cards) { |
||||
card.setEnabled(enabled); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 重置组件 |
||||
*/ |
||||
public void resetComponets() { |
||||
for (Editor card : cards) { |
||||
card.reset(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 清除组件数据 |
||||
*/ |
||||
public void clearComponentsData() { |
||||
for (Editor card : cards) { |
||||
card.clearData(); |
||||
} |
||||
} |
||||
|
||||
public Editor[] getCards() { |
||||
return this.cards; |
||||
} |
||||
|
||||
public JPopupMenu getMenu() { |
||||
return this.menu; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 注册全局名字监听事件 |
||||
* |
||||
* @param listener 观察者监听事件 |
||||
*/ |
||||
public void registerNameListener(GlobalNameListener listener) { |
||||
globalNameListener = listener; |
||||
} |
||||
|
||||
/** |
||||
* 是否对名字listener监听器做出响应 |
||||
* |
||||
* @return 如果要做出响应,则返回true |
||||
*/ |
||||
public boolean shouldResponseNameListener() { |
||||
return false; |
||||
} |
||||
|
||||
public void setGlobalName(String name) { |
||||
for (Editor card : cards) { |
||||
setComponentGlobalName(card, name); |
||||
} |
||||
} |
||||
|
||||
private void setComponentGlobalName(Container card, String name) { |
||||
for (int i = 0, len = card.getComponentCount(); i < len; i++) { |
||||
Component component = card.getComponent(i); |
||||
if (component instanceof GlobalNameObserver) { |
||||
((GlobalNameObserver) component).setGlobalName(name); |
||||
} else { |
||||
setComponentGlobalName((Container) component, name); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 给组件登记一个观察者监听事件 |
||||
* |
||||
* @param listener 观察者监听事件 |
||||
*/ |
||||
public void registerChangeListener(UIObserverListener listener) { |
||||
uiObserverListener = listener; |
||||
for (Editor card : cards) { |
||||
doLoop(card, listener); |
||||
} |
||||
} |
||||
|
||||
private void doLoop(Container card, UIObserverListener listener) { |
||||
for (int i = 0, len = card.getComponentCount(); i < len; i++) { |
||||
Component component = card.getComponent(i); |
||||
if (component instanceof UIObserver) { |
||||
((UIObserver) component).registerChangeListener(listener); |
||||
} else { |
||||
doLoop((Container) component, listener); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 组件是否需要响应添加的观察者事件 |
||||
* |
||||
* @return 如果需要响应观察者事件则返回true,否则返回false |
||||
*/ |
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
} |
@ -1,118 +1,116 @@
|
||||
package com.fr.design.present.dict; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.Formula; |
||||
import com.fr.data.impl.FormulaDictionary; |
||||
import com.fr.design.beans.FurtherBasicBeanPane; |
||||
import com.fr.design.constants.LayoutConstants; |
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.editor.editor.FormulaEditor; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.event.DocumentListener; |
||||
import java.awt.*; |
||||
|
||||
public class FormulaDictPane extends FurtherBasicBeanPane<FormulaDictionary> { |
||||
|
||||
private static final int EDITOR_COLUMN = 15; |
||||
private static final int LEFT_BORDER = 5; |
||||
private FormulaEditor keyFormulaEditor; |
||||
private FormulaEditor valueFormulaEditor; |
||||
|
||||
public FormulaDictPane() { |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
keyFormulaEditor = new FormulaEditor(); |
||||
keyFormulaEditor.setColumns(EDITOR_COLUMN); |
||||
JPanel keyFormulaContainer = new JPanel(new FlowLayout(FlowLayout.RIGHT, LEFT_BORDER, 0)); |
||||
keyFormulaContainer.setBorder(BorderFactory.createEmptyBorder(0, -LEFT_BORDER, 0, -LEFT_BORDER)); |
||||
keyFormulaEditor.setPreferredSize(new Dimension(144, 20)); |
||||
Icon icon = BaseUtils.readIcon("/com/fr/design/images/m_insert/formula.png"); |
||||
keyFormulaContainer.add(new JLabel(icon)); |
||||
keyFormulaContainer.add(keyFormulaEditor); |
||||
|
||||
valueFormulaEditor = new FormulaEditor(); |
||||
valueFormulaEditor.setColumns(EDITOR_COLUMN); |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {p, f}; |
||||
double[] rowSize = {p, p, p}; |
||||
int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}}; |
||||
|
||||
UILabel tag = new UILabel(Inter.getLocText("FR-Designer-Formula_Dictionary_Display_Examples_Html")); |
||||
tag.setForeground(new Color(143, 143, 146)); |
||||
tag.setPreferredSize(new Dimension(225, 80)); |
||||
JPanel t = new JPanel(new BorderLayout()); |
||||
t.add(tag, BorderLayout.CENTER); |
||||
|
||||
Formula vf = new Formula("$$$"); |
||||
valueFormulaEditor = new FormulaEditor(StringUtils.EMPTY, vf); |
||||
|
||||
JPanel valueFormulaContainer = new JPanel(new FlowLayout(FlowLayout.RIGHT, LEFT_BORDER, 0)); |
||||
valueFormulaContainer.setBorder(BorderFactory.createEmptyBorder(0, -LEFT_BORDER, 0, -LEFT_BORDER)); |
||||
valueFormulaEditor.setPreferredSize(new Dimension(144, 20)); |
||||
valueFormulaContainer.add(new JLabel(icon)); |
||||
valueFormulaContainer.add(valueFormulaEditor); |
||||
|
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{new UILabel(Inter.getLocText("FR-Designer_Actual_Value"), UILabel.LEFT), keyFormulaContainer}, |
||||
new Component[]{new UILabel(Inter.getLocText("FR-Designer_Display_Value"), UILabel.LEFT), valueFormulaContainer}, |
||||
new Component[]{tag, null} |
||||
}; |
||||
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_LARGE); |
||||
|
||||
this.setLayout(new BorderLayout()); |
||||
this.add(panel, BorderLayout.CENTER); |
||||
|
||||
} |
||||
|
||||
public void addChangeListener(DocumentListener l) { |
||||
keyFormulaEditor.addDocumentListener(l); |
||||
valueFormulaEditor.addDocumentListener(l); |
||||
} |
||||
|
||||
@Override |
||||
public String title4PopupWindow() { |
||||
return Inter.getLocText("FR-Designer_Formula"); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(FormulaDictionary dict) { |
||||
keyFormulaEditor.setValue(new Formula(dict.getProduceFormula() == null ? StringUtils.EMPTY : dict.getProduceFormula())); |
||||
valueFormulaEditor.setValue(new Formula(dict.getExcuteFormula() == null ? StringUtils.EMPTY : dict.getExcuteFormula())); |
||||
} |
||||
|
||||
@Override |
||||
public FormulaDictionary updateBean() { |
||||
FormulaDictionary dict = new FormulaDictionary(); |
||||
if (keyFormulaEditor.getValue() != null) { |
||||
dict.setProduceFormula(keyFormulaEditor.getValue().getContent()); |
||||
} |
||||
if (valueFormulaEditor.getValue() != null) { |
||||
dict.setExcuteFormula(valueFormulaEditor.getValue().getContent()); |
||||
} |
||||
|
||||
return dict; |
||||
} |
||||
|
||||
@Override |
||||
public boolean accept(Object ob) { |
||||
return ob instanceof FormulaDictionary; |
||||
} |
||||
|
||||
@Override |
||||
public void reset() { |
||||
keyFormulaEditor.reset(); |
||||
valueFormulaEditor.reset(); |
||||
} |
||||
package com.fr.design.present.dict; |
||||
|
||||
import com.fr.base.BaseFormula; |
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.data.impl.FormulaDictionary; |
||||
import com.fr.design.beans.FurtherBasicBeanPane; |
||||
import com.fr.design.constants.LayoutConstants; |
||||
import com.fr.design.editor.editor.FormulaEditor; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.event.DocumentListener; |
||||
import java.awt.*; |
||||
|
||||
public class FormulaDictPane extends FurtherBasicBeanPane<FormulaDictionary> { |
||||
|
||||
private static final int EDITOR_COLUMN = 15; |
||||
private static final int LEFT_BORDER = 5; |
||||
private FormulaEditor keyFormulaEditor; |
||||
private FormulaEditor valueFormulaEditor; |
||||
|
||||
public FormulaDictPane() { |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
keyFormulaEditor = new FormulaEditor(); |
||||
keyFormulaEditor.setColumns(EDITOR_COLUMN); |
||||
JPanel keyFormulaContainer = new JPanel(new FlowLayout(FlowLayout.RIGHT, LEFT_BORDER, 0)); |
||||
keyFormulaContainer.setBorder(BorderFactory.createEmptyBorder(0, -LEFT_BORDER, 0, -LEFT_BORDER)); |
||||
keyFormulaEditor.setPreferredSize(new Dimension(144, 20)); |
||||
Icon icon = BaseUtils.readIcon("/com/fr/design/images/m_insert/formula.png"); |
||||
keyFormulaContainer.add(new JLabel(icon)); |
||||
keyFormulaContainer.add(keyFormulaEditor); |
||||
|
||||
valueFormulaEditor = new FormulaEditor(); |
||||
valueFormulaEditor.setColumns(EDITOR_COLUMN); |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {p, f}; |
||||
double[] rowSize = {p, p, p}; |
||||
int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}}; |
||||
|
||||
UILabel tag = new UILabel(Inter.getLocText("FR-Designer-Formula_Dictionary_Display_Examples_Html")); |
||||
tag.setForeground(new Color(143, 143, 146)); |
||||
tag.setPreferredSize(new Dimension(225, 80)); |
||||
JPanel t = new JPanel(new BorderLayout()); |
||||
t.add(tag, BorderLayout.CENTER); |
||||
|
||||
BaseFormula vf = BaseFormula.createFormulaBuilder().build("$$$"); |
||||
valueFormulaEditor = new FormulaEditor(StringUtils.EMPTY, vf); |
||||
|
||||
JPanel valueFormulaContainer = new JPanel(new FlowLayout(FlowLayout.RIGHT, LEFT_BORDER, 0)); |
||||
valueFormulaContainer.setBorder(BorderFactory.createEmptyBorder(0, -LEFT_BORDER, 0, -LEFT_BORDER)); |
||||
valueFormulaEditor.setPreferredSize(new Dimension(144, 20)); |
||||
valueFormulaContainer.add(new JLabel(icon)); |
||||
valueFormulaContainer.add(valueFormulaEditor); |
||||
|
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{new UILabel(Inter.getLocText("FR-Designer_Actual_Value"), UILabel.LEFT), keyFormulaContainer}, |
||||
new Component[]{new UILabel(Inter.getLocText("FR-Designer_Display_Value"), UILabel.LEFT), valueFormulaContainer}, |
||||
new Component[]{tag, null} |
||||
}; |
||||
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_LARGE); |
||||
|
||||
this.setLayout(new BorderLayout()); |
||||
this.add(panel, BorderLayout.CENTER); |
||||
|
||||
} |
||||
|
||||
public void addChangeListener(DocumentListener l) { |
||||
keyFormulaEditor.addDocumentListener(l); |
||||
valueFormulaEditor.addDocumentListener(l); |
||||
} |
||||
|
||||
@Override |
||||
public String title4PopupWindow() { |
||||
return Inter.getLocText("FR-Designer_Formula"); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(FormulaDictionary dict) { |
||||
keyFormulaEditor.setValue(BaseFormula.createFormulaBuilder().build(dict.getProduceFormula() == null ? StringUtils.EMPTY : dict.getProduceFormula())); |
||||
valueFormulaEditor.setValue(BaseFormula.createFormulaBuilder().build(dict.getExcuteFormula() == null ? StringUtils.EMPTY : dict.getExcuteFormula())); |
||||
} |
||||
|
||||
@Override |
||||
public FormulaDictionary updateBean() { |
||||
FormulaDictionary dict = new FormulaDictionary(); |
||||
if (keyFormulaEditor.getValue() != null) { |
||||
dict.setProduceFormula(keyFormulaEditor.getValue().getContent()); |
||||
} |
||||
if (valueFormulaEditor.getValue() != null) { |
||||
dict.setExcuteFormula(valueFormulaEditor.getValue().getContent()); |
||||
} |
||||
|
||||
return dict; |
||||
} |
||||
|
||||
@Override |
||||
public boolean accept(Object ob) { |
||||
return ob instanceof FormulaDictionary; |
||||
} |
||||
|
||||
@Override |
||||
public void reset() { |
||||
keyFormulaEditor.reset(); |
||||
valueFormulaEditor.reset(); |
||||
} |
||||
} |
@ -1,301 +1,297 @@
|
||||
package com.fr.design.chart.report; |
||||
|
||||
import java.awt.*; |
||||
import java.awt.event.FocusAdapter; |
||||
import java.awt.event.FocusEvent; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JTable; |
||||
import javax.swing.SwingConstants; |
||||
import javax.swing.event.ChangeEvent; |
||||
import javax.swing.event.ChangeListener; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.base.Utils; |
||||
import com.fr.chart.chartdata.BaseSeriesDefinition; |
||||
import com.fr.chart.chartdata.GisMapReportDefinition; |
||||
import com.fr.chart.chartdata.SeriesDefinition; |
||||
import com.fr.design.constants.LayoutConstants; |
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.beans.FurtherBasicBeanPane; |
||||
import com.fr.design.event.UIObserver; |
||||
import com.fr.design.event.UIObserverListener; |
||||
import com.fr.design.formula.TinyFormulaPane; |
||||
import com.fr.design.gui.frpane.UICorrelationPane; |
||||
import com.fr.design.gui.ibutton.UIButtonGroup; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itable.UITableEditor; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* 属性表gis地图单元格数据源设置界面 |
||||
* |
||||
* @author eason |
||||
*/ |
||||
public class GisMapReportDataContentPane extends FurtherBasicBeanPane<GisMapReportDefinition> implements UIObserver { |
||||
private UIButtonGroup<String> addressType; |
||||
private UIButtonGroup<String> lnglatOrder; |
||||
private TinyFormulaPane addressPane; |
||||
private TinyFormulaPane addressNamePane; |
||||
private UICorrelationPane seriesPane; |
||||
private JPanel orderPane; |
||||
private ArrayList<ChangeListener> changeListeners = new ArrayList<ChangeListener>(); |
||||
|
||||
public GisMapReportDataContentPane() { |
||||
initCom(); |
||||
} |
||||
|
||||
private void initCom() { |
||||
this.setLayout(new BorderLayout(0, 0)); |
||||
addressType = new UIButtonGroup<String>(new String[]{Inter.getLocText("Chart-Address"), Inter.getLocText("Chart-LngLat")}); |
||||
lnglatOrder = new UIButtonGroup<String>(new String[]{Inter.getLocText("Chart-LngFirst"), Inter.getLocText("Chart-LatFirst")}); |
||||
addressPane = new TinyFormulaPane(); |
||||
addressNamePane = new TinyFormulaPane(); |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = new double[]{p, f}; |
||||
double[] rowSize = new double[]{p, p, p}; |
||||
|
||||
orderPane = new JPanel(new BorderLayout(LayoutConstants.VGAP_MEDIUM, 0)) { |
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
if (this.isVisible()) { |
||||
return super.getPreferredSize(); |
||||
} else { |
||||
return new Dimension(0, 0); |
||||
} |
||||
} |
||||
}; |
||||
orderPane.add(new UILabel(Inter.getLocText("Chart-LatLngOrder")), BorderLayout.WEST); |
||||
orderPane.add(lnglatOrder, BorderLayout.CENTER); |
||||
orderPane.setVisible(false); |
||||
lnglatOrder.setSelectedIndex(0); |
||||
addressType.setSelectedIndex(0); |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{addressType, addressPane}, |
||||
new Component[]{orderPane, null}, |
||||
new Component[]{new UILabel(" " +Inter.getLocText("Chart-Address-Name")+":", SwingConstants.RIGHT), addressNamePane}, |
||||
}; |
||||
JPanel northPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
|
||||
this.add(northPane, BorderLayout.NORTH); |
||||
|
||||
String[] columnNames = new String[]{Inter.getLocText(new String[]{"Filed", "Title"}), Inter.getLocText("Area_Value")}; |
||||
seriesPane = new UICorrelationPane(columnNames) { |
||||
public UITableEditor createUITableEditor() { |
||||
return new InnerTableEditor(); |
||||
} |
||||
}; |
||||
|
||||
this.add(seriesPane, BorderLayout.CENTER); |
||||
} |
||||
|
||||
/** |
||||
* 界面接入. |
||||
* @param ob 对象 |
||||
* @return true表示接受 |
||||
*/ |
||||
public boolean accept(Object ob) { |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 重置 |
||||
*/ |
||||
public void reset() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 界面弹出标题. |
||||
* @return 标题 |
||||
*/ |
||||
public String title4PopupWindow() { |
||||
return Inter.getLocText("Cell"); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(GisMapReportDefinition ob) { |
||||
if (ob.getCategoryName() != null) { |
||||
if (ob.isAddress()) { |
||||
addressType.setSelectedIndex(0); |
||||
orderPane.setVisible(false); |
||||
} else { |
||||
addressType.setSelectedIndex(1); |
||||
orderPane.setVisible(true); |
||||
} |
||||
|
||||
if (ob.isLngFirst()) { |
||||
lnglatOrder.setSelectedIndex(0); |
||||
} else { |
||||
lnglatOrder.setSelectedIndex(1); |
||||
} |
||||
|
||||
addressPane.populateBean(Utils.objectToString(ob.getCategoryName())); |
||||
if (ob.getAddressName() != null) { |
||||
addressNamePane.populateBean(Utils.objectToString(ob.getAddressName())); |
||||
} |
||||
int size = ob.getTitleValueSize(); |
||||
List paneList = new ArrayList(); |
||||
for (int i = 0; i < size; i++) { |
||||
BaseSeriesDefinition first = ob.getTitleValueWithIndex(i); |
||||
if (first != null && first.getSeriesName() != null && first.getValue() != null) { |
||||
paneList.add(new Object[]{first.getSeriesName(), first.getValue()}); |
||||
} |
||||
} |
||||
if (!paneList.isEmpty()) { |
||||
seriesPane.populateBean(paneList); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public GisMapReportDefinition updateBean() { |
||||
GisMapReportDefinition reportDefinition = new GisMapReportDefinition(); |
||||
if (this.addressType.getSelectedIndex() == 0) { |
||||
reportDefinition.setAddressType(true); |
||||
orderPane.setVisible(false); |
||||
} else { |
||||
reportDefinition.setAddressType(false); |
||||
orderPane.setVisible(true); |
||||
} |
||||
|
||||
if (this.lnglatOrder.getSelectedIndex() == 0) { |
||||
reportDefinition.setLnglatOrder(true); |
||||
} else { |
||||
reportDefinition.setLnglatOrder(false); |
||||
} |
||||
|
||||
String address = addressPane.updateBean(); |
||||
if (StringUtils.isBlank(address)) { |
||||
return null; |
||||
} |
||||
if (StableUtils.canBeFormula(address)) { |
||||
reportDefinition.setCategoryName(new Formula(address)); |
||||
} else { |
||||
reportDefinition.setCategoryName(address); |
||||
} |
||||
|
||||
String addressName = addressNamePane.updateBean(); |
||||
if (addressName != null && !StringUtils.isBlank(addressName)) { |
||||
if (StableUtils.canBeFormula(addressName)) { |
||||
reportDefinition.setAddressName(addressName); |
||||
} else { |
||||
reportDefinition.setAddressName(addressName); |
||||
} |
||||
} |
||||
List values = seriesPane.updateBean(); |
||||
if (values != null && !values.isEmpty()) { |
||||
for (int i = 0, size = values.size(); i < size; i++) { |
||||
Object[] objects = (Object[]) values.get(i); |
||||
Object name = objects[0]; |
||||
Object value = objects[1]; |
||||
|
||||
if (StableUtils.canBeFormula(value)) { |
||||
value = new Formula(Utils.objectToString(value)); |
||||
} |
||||
SeriesDefinition definition = new SeriesDefinition(name, value); |
||||
reportDefinition.addTitleValue(definition); |
||||
} |
||||
} |
||||
return reportDefinition; |
||||
} |
||||
|
||||
/** |
||||
* 给组件登记一个观察者监听事件 |
||||
* |
||||
* @param listener 观察者监听事件 |
||||
*/ |
||||
public void registerChangeListener(final UIObserverListener listener) { |
||||
changeListeners.add(new ChangeListener() { |
||||
public void stateChanged(ChangeEvent e) { |
||||
listener.doChange(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 组件是否需要响应添加的观察者事件 |
||||
* |
||||
* @return 如果需要响应观察者事件则返回true,否则返回false |
||||
*/ |
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
|
||||
private class InnerTableEditor extends UITableEditor { |
||||
private JComponent editorComponent; |
||||
|
||||
/** |
||||
* 返回当前编辑器的值 |
||||
*/ |
||||
public Object getCellEditorValue() { |
||||
if (editorComponent instanceof TinyFormulaPane) { |
||||
return ((TinyFormulaPane) editorComponent).getUITextField().getText(); |
||||
} else if (editorComponent instanceof UITextField) { |
||||
return ((UITextField) editorComponent).getText(); |
||||
} |
||||
|
||||
return super.getCellEditorValue(); |
||||
} |
||||
|
||||
/** |
||||
* 返回当前编辑器.. |
||||
*/ |
||||
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
||||
if (column == table.getModel().getColumnCount()) { |
||||
return null; |
||||
} |
||||
return getEditorComponent(column, value); |
||||
} |
||||
|
||||
private JComponent getEditorComponent(int column, Object value) { |
||||
if (column == 0) { |
||||
UITextField field = new UITextField(); |
||||
addListener4UITextFiled(field); |
||||
|
||||
if (value != null) { |
||||
field.setText(Utils.objectToString(value)); |
||||
} |
||||
editorComponent = field; |
||||
} else { |
||||
TinyFormulaPane tinyPane = new TinyFormulaPane() { |
||||
@Override |
||||
public void okEvent() { |
||||
seriesPane.stopCellEditing(); |
||||
seriesPane.fireTargetChanged(); |
||||
} |
||||
}; |
||||
tinyPane.setBackground(UIConstants.FLESH_BLUE); |
||||
|
||||
addListener4UITextFiled(tinyPane.getUITextField()); |
||||
|
||||
if (value != null) { |
||||
tinyPane.getUITextField().setText(Utils.objectToString(value)); |
||||
} |
||||
|
||||
editorComponent = tinyPane; |
||||
} |
||||
return editorComponent; |
||||
} |
||||
|
||||
private void addListener4UITextFiled(UITextField textField) { |
||||
|
||||
textField.addFocusListener(new FocusAdapter() { |
||||
@Override |
||||
public void focusLost(FocusEvent e) { |
||||
// seriesPane.stopCellEditing(); //kunsnat: 不stop是因为可能直接点击公式编辑按钮, 否则需要点击两次才能弹出.
|
||||
seriesPane.fireTargetChanged(); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
package com.fr.design.chart.report; |
||||
|
||||
import com.fr.base.BaseFormula; |
||||
import com.fr.base.Utils; |
||||
import com.fr.chart.chartdata.BaseSeriesDefinition; |
||||
import com.fr.chart.chartdata.GisMapReportDefinition; |
||||
import com.fr.chart.chartdata.SeriesDefinition; |
||||
import com.fr.design.beans.FurtherBasicBeanPane; |
||||
import com.fr.design.constants.LayoutConstants; |
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.event.UIObserver; |
||||
import com.fr.design.event.UIObserverListener; |
||||
import com.fr.design.formula.TinyFormulaPane; |
||||
import com.fr.design.gui.frpane.UICorrelationPane; |
||||
import com.fr.design.gui.ibutton.UIButtonGroup; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itable.UITableEditor; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.event.ChangeEvent; |
||||
import javax.swing.event.ChangeListener; |
||||
import java.awt.*; |
||||
import java.awt.event.FocusAdapter; |
||||
import java.awt.event.FocusEvent; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 属性表gis地图单元格数据源设置界面 |
||||
* |
||||
* @author eason |
||||
*/ |
||||
public class GisMapReportDataContentPane extends FurtherBasicBeanPane<GisMapReportDefinition> implements UIObserver { |
||||
private UIButtonGroup<String> addressType; |
||||
private UIButtonGroup<String> lnglatOrder; |
||||
private TinyFormulaPane addressPane; |
||||
private TinyFormulaPane addressNamePane; |
||||
private UICorrelationPane seriesPane; |
||||
private JPanel orderPane; |
||||
private ArrayList<ChangeListener> changeListeners = new ArrayList<ChangeListener>(); |
||||
|
||||
public GisMapReportDataContentPane() { |
||||
initCom(); |
||||
} |
||||
|
||||
private void initCom() { |
||||
this.setLayout(new BorderLayout(0, 0)); |
||||
addressType = new UIButtonGroup<String>(new String[]{Inter.getLocText("Chart-Address"), Inter.getLocText("Chart-LngLat")}); |
||||
lnglatOrder = new UIButtonGroup<String>(new String[]{Inter.getLocText("Chart-LngFirst"), Inter.getLocText("Chart-LatFirst")}); |
||||
addressPane = new TinyFormulaPane(); |
||||
addressNamePane = new TinyFormulaPane(); |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = new double[]{p, f}; |
||||
double[] rowSize = new double[]{p, p, p}; |
||||
|
||||
orderPane = new JPanel(new BorderLayout(LayoutConstants.VGAP_MEDIUM, 0)) { |
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
if (this.isVisible()) { |
||||
return super.getPreferredSize(); |
||||
} else { |
||||
return new Dimension(0, 0); |
||||
} |
||||
} |
||||
}; |
||||
orderPane.add(new UILabel(Inter.getLocText("Chart-LatLngOrder")), BorderLayout.WEST); |
||||
orderPane.add(lnglatOrder, BorderLayout.CENTER); |
||||
orderPane.setVisible(false); |
||||
lnglatOrder.setSelectedIndex(0); |
||||
addressType.setSelectedIndex(0); |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{addressType, addressPane}, |
||||
new Component[]{orderPane, null}, |
||||
new Component[]{new UILabel(" " +Inter.getLocText("Chart-Address-Name")+":", SwingConstants.RIGHT), addressNamePane}, |
||||
}; |
||||
JPanel northPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
|
||||
this.add(northPane, BorderLayout.NORTH); |
||||
|
||||
String[] columnNames = new String[]{Inter.getLocText(new String[]{"Filed", "Title"}), Inter.getLocText("Area_Value")}; |
||||
seriesPane = new UICorrelationPane(columnNames) { |
||||
public UITableEditor createUITableEditor() { |
||||
return new InnerTableEditor(); |
||||
} |
||||
}; |
||||
|
||||
this.add(seriesPane, BorderLayout.CENTER); |
||||
} |
||||
|
||||
/** |
||||
* 界面接入. |
||||
* @param ob 对象 |
||||
* @return true表示接受 |
||||
*/ |
||||
public boolean accept(Object ob) { |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 重置 |
||||
*/ |
||||
public void reset() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 界面弹出标题. |
||||
* @return 标题 |
||||
*/ |
||||
public String title4PopupWindow() { |
||||
return Inter.getLocText("Cell"); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(GisMapReportDefinition ob) { |
||||
if (ob.getCategoryName() != null) { |
||||
if (ob.isAddress()) { |
||||
addressType.setSelectedIndex(0); |
||||
orderPane.setVisible(false); |
||||
} else { |
||||
addressType.setSelectedIndex(1); |
||||
orderPane.setVisible(true); |
||||
} |
||||
|
||||
if (ob.isLngFirst()) { |
||||
lnglatOrder.setSelectedIndex(0); |
||||
} else { |
||||
lnglatOrder.setSelectedIndex(1); |
||||
} |
||||
|
||||
addressPane.populateBean(Utils.objectToString(ob.getCategoryName())); |
||||
if (ob.getAddressName() != null) { |
||||
addressNamePane.populateBean(Utils.objectToString(ob.getAddressName())); |
||||
} |
||||
int size = ob.getTitleValueSize(); |
||||
List paneList = new ArrayList(); |
||||
for (int i = 0; i < size; i++) { |
||||
BaseSeriesDefinition first = ob.getTitleValueWithIndex(i); |
||||
if (first != null && first.getSeriesName() != null && first.getValue() != null) { |
||||
paneList.add(new Object[]{first.getSeriesName(), first.getValue()}); |
||||
} |
||||
} |
||||
if (!paneList.isEmpty()) { |
||||
seriesPane.populateBean(paneList); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public GisMapReportDefinition updateBean() { |
||||
GisMapReportDefinition reportDefinition = new GisMapReportDefinition(); |
||||
if (this.addressType.getSelectedIndex() == 0) { |
||||
reportDefinition.setAddressType(true); |
||||
orderPane.setVisible(false); |
||||
} else { |
||||
reportDefinition.setAddressType(false); |
||||
orderPane.setVisible(true); |
||||
} |
||||
|
||||
if (this.lnglatOrder.getSelectedIndex() == 0) { |
||||
reportDefinition.setLnglatOrder(true); |
||||
} else { |
||||
reportDefinition.setLnglatOrder(false); |
||||
} |
||||
|
||||
String address = addressPane.updateBean(); |
||||
if (StringUtils.isBlank(address)) { |
||||
return null; |
||||
} |
||||
if (StableUtils.canBeFormula(address)) { |
||||
reportDefinition.setCategoryName(BaseFormula.createFormulaBuilder().build(address)); |
||||
} else { |
||||
reportDefinition.setCategoryName(address); |
||||
} |
||||
|
||||
String addressName = addressNamePane.updateBean(); |
||||
if (addressName != null && !StringUtils.isBlank(addressName)) { |
||||
if (StableUtils.canBeFormula(addressName)) { |
||||
reportDefinition.setAddressName(addressName); |
||||
} else { |
||||
reportDefinition.setAddressName(addressName); |
||||
} |
||||
} |
||||
List values = seriesPane.updateBean(); |
||||
if (values != null && !values.isEmpty()) { |
||||
for (int i = 0, size = values.size(); i < size; i++) { |
||||
Object[] objects = (Object[]) values.get(i); |
||||
Object name = objects[0]; |
||||
Object value = objects[1]; |
||||
|
||||
if (StableUtils.canBeFormula(value)) { |
||||
value = BaseFormula.createFormulaBuilder().build(value); |
||||
} |
||||
SeriesDefinition definition = new SeriesDefinition(name, value); |
||||
reportDefinition.addTitleValue(definition); |
||||
} |
||||
} |
||||
return reportDefinition; |
||||
} |
||||
|
||||
/** |
||||
* 给组件登记一个观察者监听事件 |
||||
* |
||||
* @param listener 观察者监听事件 |
||||
*/ |
||||
public void registerChangeListener(final UIObserverListener listener) { |
||||
changeListeners.add(new ChangeListener() { |
||||
public void stateChanged(ChangeEvent e) { |
||||
listener.doChange(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 组件是否需要响应添加的观察者事件 |
||||
* |
||||
* @return 如果需要响应观察者事件则返回true,否则返回false |
||||
*/ |
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
|
||||
private class InnerTableEditor extends UITableEditor { |
||||
private JComponent editorComponent; |
||||
|
||||
/** |
||||
* 返回当前编辑器的值 |
||||
*/ |
||||
public Object getCellEditorValue() { |
||||
if (editorComponent instanceof TinyFormulaPane) { |
||||
return ((TinyFormulaPane) editorComponent).getUITextField().getText(); |
||||
} else if (editorComponent instanceof UITextField) { |
||||
return ((UITextField) editorComponent).getText(); |
||||
} |
||||
|
||||
return super.getCellEditorValue(); |
||||
} |
||||
|
||||
/** |
||||
* 返回当前编辑器.. |
||||
*/ |
||||
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
||||
if (column == table.getModel().getColumnCount()) { |
||||
return null; |
||||
} |
||||
return getEditorComponent(column, value); |
||||
} |
||||
|
||||
private JComponent getEditorComponent(int column, Object value) { |
||||
if (column == 0) { |
||||
UITextField field = new UITextField(); |
||||
addListener4UITextFiled(field); |
||||
|
||||
if (value != null) { |
||||
field.setText(Utils.objectToString(value)); |
||||
} |
||||
editorComponent = field; |
||||
} else { |
||||
TinyFormulaPane tinyPane = new TinyFormulaPane() { |
||||
@Override |
||||
public void okEvent() { |
||||
seriesPane.stopCellEditing(); |
||||
seriesPane.fireTargetChanged(); |
||||
} |
||||
}; |
||||
tinyPane.setBackground(UIConstants.FLESH_BLUE); |
||||
|
||||
addListener4UITextFiled(tinyPane.getUITextField()); |
||||
|
||||
if (value != null) { |
||||
tinyPane.getUITextField().setText(Utils.objectToString(value)); |
||||
} |
||||
|
||||
editorComponent = tinyPane; |
||||
} |
||||
return editorComponent; |
||||
} |
||||
|
||||
private void addListener4UITextFiled(UITextField textField) { |
||||
|
||||
textField.addFocusListener(new FocusAdapter() { |
||||
@Override |
||||
public void focusLost(FocusEvent e) { |
||||
// seriesPane.stopCellEditing(); //kunsnat: 不stop是因为可能直接点击公式编辑按钮, 否则需要点击两次才能弹出.
|
||||
seriesPane.fireTargetChanged(); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
} |
@ -1,202 +1,196 @@
|
||||
package com.fr.design.chart.report; |
||||
|
||||
import java.awt.BorderLayout; |
||||
import java.awt.Component; |
||||
import java.awt.Dimension; |
||||
import java.awt.FlowLayout; |
||||
import java.awt.event.FocusAdapter; |
||||
import java.awt.event.FocusEvent; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JTable; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.base.Utils; |
||||
import com.fr.chart.chartdata.BaseSeriesDefinition; |
||||
import com.fr.chart.chartdata.MapSingleLayerReportDefinition; |
||||
import com.fr.chart.chartdata.SeriesDefinition; |
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.event.UIObserver; |
||||
import com.fr.design.event.UIObserverListener; |
||||
import com.fr.design.formula.TinyFormulaPane; |
||||
import com.fr.design.gui.frpane.UICorrelationPane; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itable.UITableEditor; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* 多层地图, 单元格, 多层切换 单界面. |
||||
* @author kunsnat E-mail:kunsnat@gmail.com |
||||
* @version 创建时间:2013-4-22 下午04:26:10 |
||||
*/ |
||||
public class MapMoreReportIndexPane extends BasicBeanPane<MapSingleLayerReportDefinition> implements UIObserver{ |
||||
private String title = StringUtils.EMPTY; |
||||
|
||||
private TinyFormulaPane areaNamePane; |
||||
private UICorrelationPane tabPane; |
||||
|
||||
public MapMoreReportIndexPane() { |
||||
initPane(); |
||||
} |
||||
|
||||
public MapMoreReportIndexPane(String titleName) { |
||||
title = titleName; |
||||
initPane(); |
||||
} |
||||
|
||||
private void initPane() { |
||||
this.setLayout(new BorderLayout(0, 0)); |
||||
|
||||
JPanel northPane = new JPanel(); |
||||
this.add(northPane, BorderLayout.NORTH); |
||||
northPane.setLayout(new FlowLayout(FlowLayout.LEFT)); |
||||
|
||||
northPane.add(new UILabel(Inter.getLocText("Area_Name") + ":")); |
||||
|
||||
areaNamePane = new TinyFormulaPane(); |
||||
areaNamePane.setPreferredSize(new Dimension(120, 20)); |
||||
northPane.add(areaNamePane); |
||||
|
||||
tabPane = new UICorrelationPane(new String[]{Inter.getLocText(new String[]{"Filed", "Title"}), Inter.getLocText("Area_Value")}){ |
||||
public UITableEditor createUITableEditor() { |
||||
return new InnerTableEditor(); |
||||
} |
||||
}; |
||||
|
||||
this.add(tabPane, BorderLayout.CENTER); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(MapSingleLayerReportDefinition definition) { |
||||
if(definition != null && definition.getCategoryName() != null) { |
||||
areaNamePane.populateBean(Utils.objectToString(definition.getCategoryName())); |
||||
|
||||
List paneList = new ArrayList(); |
||||
int titleValueSize = definition.getTitleValueSize(); |
||||
for(int i = 0; i < titleValueSize; i++) { |
||||
BaseSeriesDefinition sd = definition.getTitleValueWithIndex(i); |
||||
if(sd != null && sd.getSeriesName() != null && sd.getValue() != null) { |
||||
paneList.add(new Object[]{sd.getSeriesName(), sd.getValue()}); |
||||
} |
||||
} |
||||
|
||||
if(!paneList.isEmpty()) { |
||||
tabPane.populateBean(paneList); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public MapSingleLayerReportDefinition updateBean() { |
||||
MapSingleLayerReportDefinition definition = new MapSingleLayerReportDefinition(); |
||||
|
||||
String areaName = areaNamePane.updateBean(); |
||||
if(StableUtils.canBeFormula(areaName)) { |
||||
definition.setCategoryName(new Formula(areaName)); |
||||
} else { |
||||
definition.setCategoryName(areaName); |
||||
} |
||||
|
||||
List paneList = tabPane.updateBean(); |
||||
for(int i = 0, size = paneList.size(); i < size; i++) { |
||||
Object[] values = (Object[])paneList.get(i); |
||||
if(values.length == 2) { |
||||
SeriesDefinition seriesDefinition = new SeriesDefinition(); |
||||
seriesDefinition.setSeriesName(values[0]); |
||||
seriesDefinition.setValue(values[1]); |
||||
definition.addTitleValue(seriesDefinition); |
||||
} |
||||
} |
||||
|
||||
return definition; |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return title; |
||||
} |
||||
|
||||
private class InnerTableEditor extends UITableEditor { |
||||
private JComponent editorComponent; |
||||
|
||||
/** |
||||
* 返回当前编辑器的值 |
||||
*/ |
||||
public Object getCellEditorValue() { |
||||
if(editorComponent instanceof TinyFormulaPane) { |
||||
return ((TinyFormulaPane)editorComponent).getUITextField().getText(); |
||||
} else if(editorComponent instanceof UITextField) { |
||||
return ((UITextField)editorComponent).getText(); |
||||
} |
||||
|
||||
return super.getCellEditorValue(); |
||||
} |
||||
|
||||
/** |
||||
* 返回当前编辑器.. |
||||
*/ |
||||
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
||||
if (column == table.getModel().getColumnCount()) { |
||||
return null; |
||||
} |
||||
return getEditorComponent(column, value); |
||||
} |
||||
|
||||
private JComponent getEditorComponent(int column, Object value) { |
||||
if(column == 0) { |
||||
UITextField field = new UITextField(); |
||||
editorComponent = field; |
||||
|
||||
if(value != null) { |
||||
field.setText(Utils.objectToString(value)); |
||||
} |
||||
} else { |
||||
TinyFormulaPane tinyPane = new TinyFormulaPane() { |
||||
@Override |
||||
public void okEvent() { |
||||
tabPane.stopCellEditing(); |
||||
tabPane.fireTargetChanged(); |
||||
} |
||||
}; |
||||
tinyPane.setBackground(UIConstants.FLESH_BLUE); |
||||
|
||||
tinyPane.getUITextField().addFocusListener(new FocusAdapter() { |
||||
@Override |
||||
public void focusLost(FocusEvent e) { |
||||
// tabPane.stopCellEditing();//kunsnat: 不stop是因为可能直接点击公式编辑按钮, 否则需要点击两次才能弹出.
|
||||
tabPane.fireTargetChanged(); |
||||
} |
||||
}); |
||||
|
||||
if(value != null) { |
||||
tinyPane.getUITextField().setText(Utils.objectToString(value)); |
||||
} |
||||
|
||||
editorComponent = tinyPane; |
||||
} |
||||
return editorComponent; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void registerChangeListener(UIObserverListener listener) { |
||||
if(tabPane != null) { |
||||
tabPane.registerChangeListener(listener); |
||||
} |
||||
if(areaNamePane != null) { |
||||
areaNamePane.registerChangeListener(listener); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
|
||||
package com.fr.design.chart.report; |
||||
|
||||
import com.fr.base.BaseFormula; |
||||
import com.fr.base.Utils; |
||||
import com.fr.chart.chartdata.BaseSeriesDefinition; |
||||
import com.fr.chart.chartdata.MapSingleLayerReportDefinition; |
||||
import com.fr.chart.chartdata.SeriesDefinition; |
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.event.UIObserver; |
||||
import com.fr.design.event.UIObserverListener; |
||||
import com.fr.design.formula.TinyFormulaPane; |
||||
import com.fr.design.gui.frpane.UICorrelationPane; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itable.UITableEditor; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.FocusAdapter; |
||||
import java.awt.event.FocusEvent; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 多层地图, 单元格, 多层切换 单界面. |
||||
* @author kunsnat E-mail:kunsnat@gmail.com |
||||
* @version 创建时间:2013-4-22 下午04:26:10 |
||||
*/ |
||||
public class MapMoreReportIndexPane extends BasicBeanPane<MapSingleLayerReportDefinition> implements UIObserver{ |
||||
private String title = StringUtils.EMPTY; |
||||
|
||||
private TinyFormulaPane areaNamePane; |
||||
private UICorrelationPane tabPane; |
||||
|
||||
public MapMoreReportIndexPane() { |
||||
initPane(); |
||||
} |
||||
|
||||
public MapMoreReportIndexPane(String titleName) { |
||||
title = titleName; |
||||
initPane(); |
||||
} |
||||
|
||||
private void initPane() { |
||||
this.setLayout(new BorderLayout(0, 0)); |
||||
|
||||
JPanel northPane = new JPanel(); |
||||
this.add(northPane, BorderLayout.NORTH); |
||||
northPane.setLayout(new FlowLayout(FlowLayout.LEFT)); |
||||
|
||||
northPane.add(new UILabel(Inter.getLocText("Area_Name") + ":")); |
||||
|
||||
areaNamePane = new TinyFormulaPane(); |
||||
areaNamePane.setPreferredSize(new Dimension(120, 20)); |
||||
northPane.add(areaNamePane); |
||||
|
||||
tabPane = new UICorrelationPane(new String[]{Inter.getLocText(new String[]{"Filed", "Title"}), Inter.getLocText("Area_Value")}){ |
||||
public UITableEditor createUITableEditor() { |
||||
return new InnerTableEditor(); |
||||
} |
||||
}; |
||||
|
||||
this.add(tabPane, BorderLayout.CENTER); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(MapSingleLayerReportDefinition definition) { |
||||
if(definition != null && definition.getCategoryName() != null) { |
||||
areaNamePane.populateBean(Utils.objectToString(definition.getCategoryName())); |
||||
|
||||
List paneList = new ArrayList(); |
||||
int titleValueSize = definition.getTitleValueSize(); |
||||
for(int i = 0; i < titleValueSize; i++) { |
||||
BaseSeriesDefinition sd = definition.getTitleValueWithIndex(i); |
||||
if(sd != null && sd.getSeriesName() != null && sd.getValue() != null) { |
||||
paneList.add(new Object[]{sd.getSeriesName(), sd.getValue()}); |
||||
} |
||||
} |
||||
|
||||
if(!paneList.isEmpty()) { |
||||
tabPane.populateBean(paneList); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public MapSingleLayerReportDefinition updateBean() { |
||||
MapSingleLayerReportDefinition definition = new MapSingleLayerReportDefinition(); |
||||
|
||||
String areaName = areaNamePane.updateBean(); |
||||
if(StableUtils.canBeFormula(areaName)) { |
||||
definition.setCategoryName(BaseFormula.createFormulaBuilder().build(areaName)); |
||||
} else { |
||||
definition.setCategoryName(areaName); |
||||
} |
||||
|
||||
List paneList = tabPane.updateBean(); |
||||
for(int i = 0, size = paneList.size(); i < size; i++) { |
||||
Object[] values = (Object[])paneList.get(i); |
||||
if(values.length == 2) { |
||||
SeriesDefinition seriesDefinition = new SeriesDefinition(); |
||||
seriesDefinition.setSeriesName(values[0]); |
||||
seriesDefinition.setValue(values[1]); |
||||
definition.addTitleValue(seriesDefinition); |
||||
} |
||||
} |
||||
|
||||
return definition; |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return title; |
||||
} |
||||
|
||||
private class InnerTableEditor extends UITableEditor { |
||||
private JComponent editorComponent; |
||||
|
||||
/** |
||||
* 返回当前编辑器的值 |
||||
*/ |
||||
public Object getCellEditorValue() { |
||||
if(editorComponent instanceof TinyFormulaPane) { |
||||
return ((TinyFormulaPane)editorComponent).getUITextField().getText(); |
||||
} else if(editorComponent instanceof UITextField) { |
||||
return ((UITextField)editorComponent).getText(); |
||||
} |
||||
|
||||
return super.getCellEditorValue(); |
||||
} |
||||
|
||||
/** |
||||
* 返回当前编辑器.. |
||||
*/ |
||||
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
||||
if (column == table.getModel().getColumnCount()) { |
||||
return null; |
||||
} |
||||
return getEditorComponent(column, value); |
||||
} |
||||
|
||||
private JComponent getEditorComponent(int column, Object value) { |
||||
if(column == 0) { |
||||
UITextField field = new UITextField(); |
||||
editorComponent = field; |
||||
|
||||
if(value != null) { |
||||
field.setText(Utils.objectToString(value)); |
||||
} |
||||
} else { |
||||
TinyFormulaPane tinyPane = new TinyFormulaPane() { |
||||
@Override |
||||
public void okEvent() { |
||||
tabPane.stopCellEditing(); |
||||
tabPane.fireTargetChanged(); |
||||
} |
||||
}; |
||||
tinyPane.setBackground(UIConstants.FLESH_BLUE); |
||||
|
||||
tinyPane.getUITextField().addFocusListener(new FocusAdapter() { |
||||
@Override |
||||
public void focusLost(FocusEvent e) { |
||||
// tabPane.stopCellEditing();//kunsnat: 不stop是因为可能直接点击公式编辑按钮, 否则需要点击两次才能弹出.
|
||||
tabPane.fireTargetChanged(); |
||||
} |
||||
}); |
||||
|
||||
if(value != null) { |
||||
tinyPane.getUITextField().setText(Utils.objectToString(value)); |
||||
} |
||||
|
||||
editorComponent = tinyPane; |
||||
} |
||||
return editorComponent; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void registerChangeListener(UIObserverListener listener) { |
||||
if(tabPane != null) { |
||||
tabPane.registerChangeListener(listener); |
||||
} |
||||
if(areaNamePane != null) { |
||||
areaNamePane.registerChangeListener(listener); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
|
||||
} |
@ -1,471 +1,469 @@
|
||||
package com.fr.design.mainframe.chart.gui.style; |
||||
|
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
|
||||
import javax.swing.JPanel; |
||||
import javax.swing.SpinnerNumberModel; |
||||
import javax.swing.event.ChangeEvent; |
||||
import javax.swing.event.ChangeListener; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.base.Style; |
||||
import com.fr.base.Utils; |
||||
import com.fr.chart.base.ChartBaseUtils; |
||||
import com.fr.chart.base.TextAttr; |
||||
import com.fr.chart.chartattr.Axis; |
||||
import com.fr.design.constants.LayoutConstants; |
||||
import com.fr.design.event.UIObserver; |
||||
import com.fr.design.event.UIObserverListener; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.ispinner.UIBasicSpinner; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.gui.style.NumberDragBar; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.general.Inter; |
||||
|
||||
public class ChartAxisLabelPane extends BasicPane implements UIObserver{ |
||||
private static final int LABEL_INTERVAL = 0; |
||||
private static final int LABEL_WRAP =1; |
||||
|
||||
private static final long serialVersionUID = 6601571951210596823L; |
||||
private static final int NUM90 = 90; |
||||
private UICheckBox isLabelShow; |
||||
private UIComboBox showWay;//显示方式
|
||||
private UITextField customLabelSamleTime; |
||||
private UIComboBox labelOrientationChoose; |
||||
private NumberDragBar orientationBar; |
||||
private UIBasicSpinner orientationSpinner; |
||||
private ChartTextAttrPane textAttrPane; |
||||
private UICheckBox auto; |
||||
private UICheckBox custom; |
||||
private UIComboBox labelSampleChoose; |
||||
|
||||
private JPanel labelPane; |
||||
private JPanel showWayPane; |
||||
private UIObserverListener observerListener; |
||||
private ActionListener autoActionListener = new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
auto.removeActionListener(autoActionListener); |
||||
custom.removeActionListener(customActionListener); |
||||
auto.setSelected(true); |
||||
custom.setSelected(false); |
||||
customLabelSamleTime.setEnabled(false); |
||||
auto.addActionListener(autoActionListener); |
||||
custom.addActionListener(customActionListener); |
||||
} |
||||
}; |
||||
|
||||
private ActionListener customActionListener = new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
auto.removeActionListener(autoActionListener); |
||||
custom.removeActionListener(customActionListener); |
||||
auto.setSelected(false); |
||||
custom.setSelected(true); |
||||
customLabelSamleTime.setEnabled(true); |
||||
customLabelSamleTime.setText("1"); |
||||
auto.addActionListener(autoActionListener); |
||||
custom.addActionListener(customActionListener); |
||||
} |
||||
}; |
||||
|
||||
public ChartAxisLabelPane() { |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
isLabelShow = new UICheckBox(Inter.getLocText("FR-Utils_Label")); |
||||
auto = new UICheckBox(Inter.getLocText(new String[]{"FR-App-All_Auto", "FR-Chart-Axis_labelInterval"})); |
||||
custom = new UICheckBox(Inter.getLocText(new String[]{"FR-App-All_Custom", "FR-Chart-Axis_labelInterval"})); |
||||
showWay = new UIComboBox(new String[]{Inter.getLocText("FR-Chart-Axis_labelInterval"),Inter.getLocText("FR-Chart-Axis_labelWrap")}); |
||||
customLabelSamleTime = new UITextField(); |
||||
|
||||
String[] nameObjects = {Inter.getLocText("FR-Chart_All_Normal"), Inter.getLocText("FR-Chart-Text_Vertical"), Inter.getLocText("FR-Chart-Text_Rotation")}; |
||||
labelOrientationChoose = new UIComboBox(nameObjects); |
||||
orientationBar = new NumberDragBar(-NUM90, NUM90); |
||||
orientationSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, -NUM90, NUM90, 1)); |
||||
|
||||
String[] sampleType = {Inter.getLocText("FR-App-All_Auto"), Inter.getLocText("FR-App-All_Custom")}; |
||||
labelSampleChoose = new UIComboBox(sampleType); |
||||
customLabelSamleTime = new UITextField(); |
||||
checkCustomSampleField(); |
||||
|
||||
checkOrientationField(); |
||||
|
||||
textAttrPane = new ChartTextAttrPane(); |
||||
this.setLayout(new BorderLayout()); |
||||
|
||||
initListener(); |
||||
} |
||||
|
||||
private void initListener(){ |
||||
|
||||
showWay.addItemListener(new ItemListener() { |
||||
@Override |
||||
public void itemStateChanged(ItemEvent e) { |
||||
checkShowWay(); |
||||
} |
||||
}); |
||||
|
||||
orientationSpinner.addChangeListener(new ChangeListener() { |
||||
@Override |
||||
public void stateChanged(ChangeEvent e) { |
||||
orientationBar.setValue((Integer) orientationSpinner.getValue()); |
||||
|
||||
} |
||||
}); |
||||
orientationBar.addChangeListener(new ChangeListener() { |
||||
@Override |
||||
public void stateChanged(ChangeEvent e) { |
||||
orientationSpinner.setValue((Integer) orientationBar.getValue()); |
||||
|
||||
} |
||||
}); |
||||
|
||||
|
||||
labelSampleChoose.addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkCustomSampleField(); |
||||
} |
||||
}); |
||||
|
||||
auto.addActionListener(autoActionListener); |
||||
|
||||
custom.addActionListener(customActionListener); |
||||
labelOrientationChoose.addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkOrientationField(); |
||||
} |
||||
}); |
||||
isLabelShow.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkLabelUse(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private JPanel getWrapShowWayPane() { |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; |
||||
double[] rowSize = {p, p, p, p}; |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{null, new UILabel(Inter.getLocText("FR-Chart-Axis_labelShowway")), showWay, null}, |
||||
new Component[]{null, new UILabel(Inter.getLocText("StyleAlignment-Text_Rotation")), labelOrientationChoose, null}, |
||||
new Component[]{null, orientationSpinner, orientationBar, null}, |
||||
new Component[]{null, textAttrPane, null, null}, |
||||
}; |
||||
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
} |
||||
|
||||
private JPanel getIntervalShowWayPane() { |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {f}; |
||||
double[] rowSize = {p, p, p}; |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{getCombox()}, |
||||
new Component[]{getTowChoose()}, |
||||
new Component[]{getOther()} |
||||
}; |
||||
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
} |
||||
|
||||
private JPanel getTowChoose() { |
||||
auto.registerChangeListener(this.observerListener); |
||||
custom.registerChangeListener(this.observerListener); |
||||
customLabelSamleTime.registerChangeListener(this.observerListener); |
||||
auto.setSelected(true); |
||||
custom.setSelected(false); |
||||
customLabelSamleTime.setVisible(true); |
||||
customLabelSamleTime.setEnabled(false); |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, f}; |
||||
double[] rowSize = {p, p}; |
||||
|
||||
JPanel customPane = TableLayoutHelper.createTableLayoutPane(new Component[][]{ |
||||
new Component[]{custom, customLabelSamleTime, null}, |
||||
}, new double[]{p}, new double[]{p, p, f}); |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{null, auto,}, |
||||
new Component[]{null, customPane} |
||||
}; |
||||
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
} |
||||
|
||||
private JPanel getCombox() { |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; |
||||
double[] rowSize = {p}; |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{null, new UILabel(Inter.getLocText("FR-Chart-Axis_labelShowway")), showWay, null} |
||||
}; |
||||
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
} |
||||
|
||||
private JPanel getOther() { |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; |
||||
double[] rowSize = {p, p, p}; |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{null, new UILabel(Inter.getLocText("StyleAlignment-Text_Rotation")), labelOrientationChoose, null}, |
||||
new Component[]{null, orientationSpinner, orientationBar, null}, |
||||
new Component[]{null, textAttrPane, null, null}, |
||||
}; |
||||
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
} |
||||
|
||||
private void checkShowWay() { |
||||
if (showWayPane != null) { |
||||
this.remove(showWayPane); |
||||
} |
||||
showWay.registerChangeListener(this.observerListener); |
||||
orientationSpinner.registerChangeListener(this.observerListener); |
||||
labelOrientationChoose.registerChangeListener(this.observerListener); |
||||
if (showWay.getSelectedIndex() == LABEL_INTERVAL) { |
||||
labelPane = getIntervalShowWayPane(); |
||||
} else { |
||||
labelPane = getWrapShowWayPane(); |
||||
} |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] row = {p, p}; |
||||
double[] col = {f}; |
||||
showWayPane = TableLayoutHelper.createTableLayoutPane(new Component[][]{ |
||||
new Component[]{isLabelShow}, new Component[]{labelPane}}, row, col); |
||||
this.add(showWayPane, BorderLayout.CENTER); |
||||
this.validate(); |
||||
} |
||||
|
||||
|
||||
|
||||
private void checkOrientationField() { |
||||
if (labelOrientationChoose.getSelectedIndex() != 2) { |
||||
orientationBar.setVisible(false); |
||||
orientationSpinner.setVisible(false); |
||||
} else { |
||||
orientationBar.setVisible(true); |
||||
orientationSpinner.setVisible(true); |
||||
} |
||||
} |
||||
|
||||
private void checkPaneOnlyInterval(){ |
||||
if (showWayPane != null) { |
||||
this.remove(showWayPane); |
||||
} |
||||
showWayPane = getPanel(); |
||||
this.add(showWayPane, BorderLayout.CENTER); |
||||
this.validate(); |
||||
} |
||||
|
||||
|
||||
private JPanel getPanel() { |
||||
labelSampleChoose.registerChangeListener(this.observerListener); |
||||
customLabelSamleTime.registerChangeListener(this.observerListener); |
||||
orientationSpinner.registerChangeListener(this.observerListener); |
||||
labelOrientationChoose.registerChangeListener(this.observerListener); |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; |
||||
double[] rowSize = {p, p, p, p}; |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{null,new UILabel(Inter.getLocText("ChartF-Label_Interval")), labelSampleChoose, customLabelSamleTime}, |
||||
new Component[]{null,new UILabel(Inter.getLocText("StyleAlignment-Text_Rotation")), labelOrientationChoose, null}, |
||||
new Component[]{null,orientationSpinner, orientationBar, null}, |
||||
new Component[]{null,textAttrPane, null, null}, |
||||
}; |
||||
labelPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
|
||||
double[] row = {p,p}; |
||||
double[] col = {f}; |
||||
return TableLayoutHelper.createTableLayoutPane(new Component[][]{ |
||||
new Component[]{isLabelShow}, new Component[]{labelPane}}, row, col); |
||||
} |
||||
|
||||
private void checkCustomSampleField() { |
||||
if (labelSampleChoose.getSelectedIndex() == 0) { |
||||
customLabelSamleTime.setVisible(false); |
||||
} else { |
||||
customLabelSamleTime.setVisible(true); |
||||
customLabelSamleTime.setText("1"); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 界面标签 |
||||
*/ |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("ChartF-Tick_Label"); |
||||
} |
||||
|
||||
private int getLabelTextOrientationIndex(TextAttr textAttr) { |
||||
if (textAttr.getAlignText() == Style.VERTICALTEXT) { |
||||
return 1; |
||||
} else if (textAttr.getRotation() != 0) { |
||||
return 2; |
||||
} else { |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
private int getLabelSampleNumber(Formula formula) { |
||||
Number number = ChartBaseUtils.formula2Number(formula); |
||||
if (number != null) { |
||||
int num = number.intValue(); |
||||
return num < 1 ? 0 : 1; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
private boolean isWrapShow(Formula formula){ |
||||
Number number = ChartBaseUtils.formula2Number(formula); |
||||
return number == null; |
||||
} |
||||
|
||||
/** |
||||
* 检查 标签界面是否可用. |
||||
*/ |
||||
private void checkLabelUse() { |
||||
isLabelShow.setEnabled(true); |
||||
labelPane.setVisible(isLabelShow.isSelected()); |
||||
} |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
if (isLabelShow.isSelected()) { |
||||
return super.getPreferredSize(); |
||||
} else { |
||||
return this.isLabelShow.getPreferredSize(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 更新界面内容. |
||||
*/ |
||||
public void populate(Axis axis) { |
||||
if(axis.isSupportAxisLabelWrap()){ |
||||
checkShowWay(); |
||||
if (isWrapShow(axis.getLabelNumber())) { |
||||
showWay.setSelectedIndex(LABEL_WRAP); |
||||
} else { |
||||
showWay.setSelectedIndex(LABEL_INTERVAL); |
||||
boolean isAuto = getLabelSampleNumber(axis.getLabelNumber()) == 0; |
||||
auto.setSelected(isAuto); |
||||
custom.setSelected(!isAuto); |
||||
customLabelSamleTime.setText(isAuto ? "" : String.valueOf(ChartBaseUtils.formula2Number(axis.getLabelNumber()))); |
||||
customLabelSamleTime.setEnabled(!isAuto); |
||||
} |
||||
}else{ |
||||
checkPaneOnlyInterval(); |
||||
labelSampleChoose.setSelectedIndex(getLabelSampleNumber(axis.getLabelNumber())); |
||||
if (labelSampleChoose.getSelectedIndex() == 1) { |
||||
customLabelSamleTime.setText(String.valueOf(ChartBaseUtils.formula2Number(axis.getLabelNumber()))); |
||||
} |
||||
} |
||||
isLabelShow.setSelected(axis.isShowAxisLabel()); |
||||
textAttrPane.populate(axis.getTextAttr()); |
||||
labelOrientationChoose.setSelectedIndex(getLabelTextOrientationIndex(axis.getTextAttr())); |
||||
orientationBar.setValue(axis.getTextAttr().getRotation()); |
||||
orientationSpinner.setValue(axis.getTextAttr().getRotation()); |
||||
checkLabelUse(); |
||||
this.initSelfListener(this); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 保存界面属性. |
||||
*/ |
||||
public void update(Axis axis) { |
||||
axis.setShowAxisLabel(isLabelShow.isSelected()); |
||||
if (isLabelShow.isSelected()) { |
||||
if(axis.isSupportAxisLabelWrap()){ |
||||
this.update4Wrap(axis); |
||||
}else{ |
||||
update4Normal(axis); |
||||
} |
||||
|
||||
TextAttr textAttr = axis.getTextAttr(); |
||||
textAttrPane.update(textAttr); |
||||
if (labelOrientationChoose.getSelectedIndex() == 0) { |
||||
textAttr.setRotation(0); |
||||
textAttr.setAlignText(Style.HORIZONTALTEXT); |
||||
} else if (labelOrientationChoose.getSelectedIndex() == 1) { |
||||
textAttr.setRotation(0); |
||||
textAttr.setAlignText(Style.VERTICALTEXT); |
||||
} else { |
||||
textAttr.setAlignText(Style.HORIZONTALTEXT); |
||||
textAttr.setRotation(Utils.objectToNumber(orientationSpinner.getValue(), false).intValue()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void update4Normal(Axis axis){ |
||||
if (labelSampleChoose.getSelectedIndex() == 0) { |
||||
axis.setLabelIntervalNumber(new Formula("0")); |
||||
} else { |
||||
axis.setLabelIntervalNumber(new Formula(customLabelSamleTime.getText())); |
||||
} |
||||
} |
||||
|
||||
private void update4Wrap(Axis axis){ |
||||
if (showWay.getSelectedIndex() == LABEL_WRAP) { |
||||
axis.setLabelIntervalNumber(new Formula()); |
||||
} else if (showWay.getSelectedIndex() == LABEL_INTERVAL) { |
||||
if (auto.isSelected()) { |
||||
axis.setLabelIntervalNumber(new Formula("0")); |
||||
} else if (custom.isSelected()) { |
||||
axis.setLabelIntervalNumber(new Formula(customLabelSamleTime.getText())); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 注册时间监听器 |
||||
* @param listener 观察者监听事件 |
||||
*/ |
||||
public void registerChangeListener(UIObserverListener listener) { |
||||
this.observerListener = listener; |
||||
} |
||||
|
||||
private void initSelfListener(Container parentComponent) { |
||||
for (int i = 0; i < parentComponent.getComponentCount(); i++) { |
||||
Component tmpComp = parentComponent.getComponent(i); |
||||
if (tmpComp instanceof Container) { |
||||
initSelfListener((Container) tmpComp); |
||||
} |
||||
if (tmpComp instanceof UIObserver) { |
||||
((UIObserver) tmpComp).registerChangeListener(observerListener); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 是否响应事件监听 |
||||
* @return 是则返回true |
||||
*/ |
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
package com.fr.design.mainframe.chart.gui.style; |
||||
|
||||
import com.fr.base.BaseFormula; |
||||
import com.fr.base.Style; |
||||
import com.fr.base.Utils; |
||||
import com.fr.chart.base.ChartBaseUtils; |
||||
import com.fr.chart.base.TextAttr; |
||||
import com.fr.chart.chartattr.Axis; |
||||
import com.fr.design.constants.LayoutConstants; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.event.UIObserver; |
||||
import com.fr.design.event.UIObserverListener; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.ispinner.UIBasicSpinner; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.gui.style.NumberDragBar; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.general.Inter; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.event.ChangeEvent; |
||||
import javax.swing.event.ChangeListener; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
|
||||
public class ChartAxisLabelPane extends BasicPane implements UIObserver{ |
||||
private static final int LABEL_INTERVAL = 0; |
||||
private static final int LABEL_WRAP =1; |
||||
|
||||
private static final long serialVersionUID = 6601571951210596823L; |
||||
private static final int NUM90 = 90; |
||||
private UICheckBox isLabelShow; |
||||
private UIComboBox showWay;//显示方式
|
||||
private UITextField customLabelSamleTime; |
||||
private UIComboBox labelOrientationChoose; |
||||
private NumberDragBar orientationBar; |
||||
private UIBasicSpinner orientationSpinner; |
||||
private ChartTextAttrPane textAttrPane; |
||||
private UICheckBox auto; |
||||
private UICheckBox custom; |
||||
private UIComboBox labelSampleChoose; |
||||
|
||||
private JPanel labelPane; |
||||
private JPanel showWayPane; |
||||
private UIObserverListener observerListener; |
||||
private ActionListener autoActionListener = new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
auto.removeActionListener(autoActionListener); |
||||
custom.removeActionListener(customActionListener); |
||||
auto.setSelected(true); |
||||
custom.setSelected(false); |
||||
customLabelSamleTime.setEnabled(false); |
||||
auto.addActionListener(autoActionListener); |
||||
custom.addActionListener(customActionListener); |
||||
} |
||||
}; |
||||
|
||||
private ActionListener customActionListener = new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
auto.removeActionListener(autoActionListener); |
||||
custom.removeActionListener(customActionListener); |
||||
auto.setSelected(false); |
||||
custom.setSelected(true); |
||||
customLabelSamleTime.setEnabled(true); |
||||
customLabelSamleTime.setText("1"); |
||||
auto.addActionListener(autoActionListener); |
||||
custom.addActionListener(customActionListener); |
||||
} |
||||
}; |
||||
|
||||
public ChartAxisLabelPane() { |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
isLabelShow = new UICheckBox(Inter.getLocText("FR-Utils_Label")); |
||||
auto = new UICheckBox(Inter.getLocText(new String[]{"FR-App-All_Auto", "FR-Chart-Axis_labelInterval"})); |
||||
custom = new UICheckBox(Inter.getLocText(new String[]{"FR-App-All_Custom", "FR-Chart-Axis_labelInterval"})); |
||||
showWay = new UIComboBox(new String[]{Inter.getLocText("FR-Chart-Axis_labelInterval"),Inter.getLocText("FR-Chart-Axis_labelWrap")}); |
||||
customLabelSamleTime = new UITextField(); |
||||
|
||||
String[] nameObjects = {Inter.getLocText("FR-Chart_All_Normal"), Inter.getLocText("FR-Chart-Text_Vertical"), Inter.getLocText("FR-Chart-Text_Rotation")}; |
||||
labelOrientationChoose = new UIComboBox(nameObjects); |
||||
orientationBar = new NumberDragBar(-NUM90, NUM90); |
||||
orientationSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, -NUM90, NUM90, 1)); |
||||
|
||||
String[] sampleType = {Inter.getLocText("FR-App-All_Auto"), Inter.getLocText("FR-App-All_Custom")}; |
||||
labelSampleChoose = new UIComboBox(sampleType); |
||||
customLabelSamleTime = new UITextField(); |
||||
checkCustomSampleField(); |
||||
|
||||
checkOrientationField(); |
||||
|
||||
textAttrPane = new ChartTextAttrPane(); |
||||
this.setLayout(new BorderLayout()); |
||||
|
||||
initListener(); |
||||
} |
||||
|
||||
private void initListener(){ |
||||
|
||||
showWay.addItemListener(new ItemListener() { |
||||
@Override |
||||
public void itemStateChanged(ItemEvent e) { |
||||
checkShowWay(); |
||||
} |
||||
}); |
||||
|
||||
orientationSpinner.addChangeListener(new ChangeListener() { |
||||
@Override |
||||
public void stateChanged(ChangeEvent e) { |
||||
orientationBar.setValue((Integer) orientationSpinner.getValue()); |
||||
|
||||
} |
||||
}); |
||||
orientationBar.addChangeListener(new ChangeListener() { |
||||
@Override |
||||
public void stateChanged(ChangeEvent e) { |
||||
orientationSpinner.setValue((Integer) orientationBar.getValue()); |
||||
|
||||
} |
||||
}); |
||||
|
||||
|
||||
labelSampleChoose.addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkCustomSampleField(); |
||||
} |
||||
}); |
||||
|
||||
auto.addActionListener(autoActionListener); |
||||
|
||||
custom.addActionListener(customActionListener); |
||||
labelOrientationChoose.addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkOrientationField(); |
||||
} |
||||
}); |
||||
isLabelShow.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkLabelUse(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private JPanel getWrapShowWayPane() { |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; |
||||
double[] rowSize = {p, p, p, p}; |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{null, new UILabel(Inter.getLocText("FR-Chart-Axis_labelShowway")), showWay, null}, |
||||
new Component[]{null, new UILabel(Inter.getLocText("StyleAlignment-Text_Rotation")), labelOrientationChoose, null}, |
||||
new Component[]{null, orientationSpinner, orientationBar, null}, |
||||
new Component[]{null, textAttrPane, null, null}, |
||||
}; |
||||
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
} |
||||
|
||||
private JPanel getIntervalShowWayPane() { |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {f}; |
||||
double[] rowSize = {p, p, p}; |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{getCombox()}, |
||||
new Component[]{getTowChoose()}, |
||||
new Component[]{getOther()} |
||||
}; |
||||
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
} |
||||
|
||||
private JPanel getTowChoose() { |
||||
auto.registerChangeListener(this.observerListener); |
||||
custom.registerChangeListener(this.observerListener); |
||||
customLabelSamleTime.registerChangeListener(this.observerListener); |
||||
auto.setSelected(true); |
||||
custom.setSelected(false); |
||||
customLabelSamleTime.setVisible(true); |
||||
customLabelSamleTime.setEnabled(false); |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, f}; |
||||
double[] rowSize = {p, p}; |
||||
|
||||
JPanel customPane = TableLayoutHelper.createTableLayoutPane(new Component[][]{ |
||||
new Component[]{custom, customLabelSamleTime, null}, |
||||
}, new double[]{p}, new double[]{p, p, f}); |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{null, auto,}, |
||||
new Component[]{null, customPane} |
||||
}; |
||||
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
} |
||||
|
||||
private JPanel getCombox() { |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; |
||||
double[] rowSize = {p}; |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{null, new UILabel(Inter.getLocText("FR-Chart-Axis_labelShowway")), showWay, null} |
||||
}; |
||||
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
} |
||||
|
||||
private JPanel getOther() { |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; |
||||
double[] rowSize = {p, p, p}; |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{null, new UILabel(Inter.getLocText("StyleAlignment-Text_Rotation")), labelOrientationChoose, null}, |
||||
new Component[]{null, orientationSpinner, orientationBar, null}, |
||||
new Component[]{null, textAttrPane, null, null}, |
||||
}; |
||||
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
} |
||||
|
||||
private void checkShowWay() { |
||||
if (showWayPane != null) { |
||||
this.remove(showWayPane); |
||||
} |
||||
showWay.registerChangeListener(this.observerListener); |
||||
orientationSpinner.registerChangeListener(this.observerListener); |
||||
labelOrientationChoose.registerChangeListener(this.observerListener); |
||||
if (showWay.getSelectedIndex() == LABEL_INTERVAL) { |
||||
labelPane = getIntervalShowWayPane(); |
||||
} else { |
||||
labelPane = getWrapShowWayPane(); |
||||
} |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] row = {p, p}; |
||||
double[] col = {f}; |
||||
showWayPane = TableLayoutHelper.createTableLayoutPane(new Component[][]{ |
||||
new Component[]{isLabelShow}, new Component[]{labelPane}}, row, col); |
||||
this.add(showWayPane, BorderLayout.CENTER); |
||||
this.validate(); |
||||
} |
||||
|
||||
|
||||
|
||||
private void checkOrientationField() { |
||||
if (labelOrientationChoose.getSelectedIndex() != 2) { |
||||
orientationBar.setVisible(false); |
||||
orientationSpinner.setVisible(false); |
||||
} else { |
||||
orientationBar.setVisible(true); |
||||
orientationSpinner.setVisible(true); |
||||
} |
||||
} |
||||
|
||||
private void checkPaneOnlyInterval(){ |
||||
if (showWayPane != null) { |
||||
this.remove(showWayPane); |
||||
} |
||||
showWayPane = getPanel(); |
||||
this.add(showWayPane, BorderLayout.CENTER); |
||||
this.validate(); |
||||
} |
||||
|
||||
|
||||
private JPanel getPanel() { |
||||
labelSampleChoose.registerChangeListener(this.observerListener); |
||||
customLabelSamleTime.registerChangeListener(this.observerListener); |
||||
orientationSpinner.registerChangeListener(this.observerListener); |
||||
labelOrientationChoose.registerChangeListener(this.observerListener); |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; |
||||
double[] rowSize = {p, p, p, p}; |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{null,new UILabel(Inter.getLocText("ChartF-Label_Interval")), labelSampleChoose, customLabelSamleTime}, |
||||
new Component[]{null,new UILabel(Inter.getLocText("StyleAlignment-Text_Rotation")), labelOrientationChoose, null}, |
||||
new Component[]{null,orientationSpinner, orientationBar, null}, |
||||
new Component[]{null,textAttrPane, null, null}, |
||||
}; |
||||
labelPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
|
||||
double[] row = {p,p}; |
||||
double[] col = {f}; |
||||
return TableLayoutHelper.createTableLayoutPane(new Component[][]{ |
||||
new Component[]{isLabelShow}, new Component[]{labelPane}}, row, col); |
||||
} |
||||
|
||||
private void checkCustomSampleField() { |
||||
if (labelSampleChoose.getSelectedIndex() == 0) { |
||||
customLabelSamleTime.setVisible(false); |
||||
} else { |
||||
customLabelSamleTime.setVisible(true); |
||||
customLabelSamleTime.setText("1"); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 界面标签 |
||||
*/ |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("ChartF-Tick_Label"); |
||||
} |
||||
|
||||
private int getLabelTextOrientationIndex(TextAttr textAttr) { |
||||
if (textAttr.getAlignText() == Style.VERTICALTEXT) { |
||||
return 1; |
||||
} else if (textAttr.getRotation() != 0) { |
||||
return 2; |
||||
} else { |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
private int getLabelSampleNumber(BaseFormula formula) { |
||||
Number number = ChartBaseUtils.formula2Number(formula); |
||||
if (number != null) { |
||||
int num = number.intValue(); |
||||
return num < 1 ? 0 : 1; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
private boolean isWrapShow(BaseFormula formula){ |
||||
Number number = ChartBaseUtils.formula2Number(formula); |
||||
return number == null; |
||||
} |
||||
|
||||
/** |
||||
* 检查 标签界面是否可用. |
||||
*/ |
||||
private void checkLabelUse() { |
||||
isLabelShow.setEnabled(true); |
||||
labelPane.setVisible(isLabelShow.isSelected()); |
||||
} |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
if (isLabelShow.isSelected()) { |
||||
return super.getPreferredSize(); |
||||
} else { |
||||
return this.isLabelShow.getPreferredSize(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 更新界面内容. |
||||
*/ |
||||
public void populate(Axis axis) { |
||||
if(axis.isSupportAxisLabelWrap()){ |
||||
checkShowWay(); |
||||
if (isWrapShow(axis.getLabelNumber())) { |
||||
showWay.setSelectedIndex(LABEL_WRAP); |
||||
} else { |
||||
showWay.setSelectedIndex(LABEL_INTERVAL); |
||||
boolean isAuto = getLabelSampleNumber(axis.getLabelNumber()) == 0; |
||||
auto.setSelected(isAuto); |
||||
custom.setSelected(!isAuto); |
||||
customLabelSamleTime.setText(isAuto ? "" : String.valueOf(ChartBaseUtils.formula2Number(axis.getLabelNumber()))); |
||||
customLabelSamleTime.setEnabled(!isAuto); |
||||
} |
||||
}else{ |
||||
checkPaneOnlyInterval(); |
||||
labelSampleChoose.setSelectedIndex(getLabelSampleNumber(axis.getLabelNumber())); |
||||
if (labelSampleChoose.getSelectedIndex() == 1) { |
||||
customLabelSamleTime.setText(String.valueOf(ChartBaseUtils.formula2Number(axis.getLabelNumber()))); |
||||
} |
||||
} |
||||
isLabelShow.setSelected(axis.isShowAxisLabel()); |
||||
textAttrPane.populate(axis.getTextAttr()); |
||||
labelOrientationChoose.setSelectedIndex(getLabelTextOrientationIndex(axis.getTextAttr())); |
||||
orientationBar.setValue(axis.getTextAttr().getRotation()); |
||||
orientationSpinner.setValue(axis.getTextAttr().getRotation()); |
||||
checkLabelUse(); |
||||
this.initSelfListener(this); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 保存界面属性. |
||||
*/ |
||||
public void update(Axis axis) { |
||||
axis.setShowAxisLabel(isLabelShow.isSelected()); |
||||
if (isLabelShow.isSelected()) { |
||||
if(axis.isSupportAxisLabelWrap()){ |
||||
this.update4Wrap(axis); |
||||
}else{ |
||||
update4Normal(axis); |
||||
} |
||||
|
||||
TextAttr textAttr = axis.getTextAttr(); |
||||
textAttrPane.update(textAttr); |
||||
if (labelOrientationChoose.getSelectedIndex() == 0) { |
||||
textAttr.setRotation(0); |
||||
textAttr.setAlignText(Style.HORIZONTALTEXT); |
||||
} else if (labelOrientationChoose.getSelectedIndex() == 1) { |
||||
textAttr.setRotation(0); |
||||
textAttr.setAlignText(Style.VERTICALTEXT); |
||||
} else { |
||||
textAttr.setAlignText(Style.HORIZONTALTEXT); |
||||
textAttr.setRotation(Utils.objectToNumber(orientationSpinner.getValue(), false).intValue()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void update4Normal(Axis axis){ |
||||
if (labelSampleChoose.getSelectedIndex() == 0) { |
||||
axis.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build("0")); |
||||
} else { |
||||
axis.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build(customLabelSamleTime.getText())); |
||||
} |
||||
} |
||||
|
||||
private void update4Wrap(Axis axis){ |
||||
if (showWay.getSelectedIndex() == LABEL_WRAP) { |
||||
axis.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build()); |
||||
} else if (showWay.getSelectedIndex() == LABEL_INTERVAL) { |
||||
if (auto.isSelected()) { |
||||
axis.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build("0")); |
||||
} else if (custom.isSelected()) { |
||||
axis.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build(customLabelSamleTime.getText())); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 注册时间监听器 |
||||
* @param listener 观察者监听事件 |
||||
*/ |
||||
public void registerChangeListener(UIObserverListener listener) { |
||||
this.observerListener = listener; |
||||
} |
||||
|
||||
private void initSelfListener(Container parentComponent) { |
||||
for (int i = 0; i < parentComponent.getComponentCount(); i++) { |
||||
Component tmpComp = parentComponent.getComponent(i); |
||||
if (tmpComp instanceof Container) { |
||||
initSelfListener((Container) tmpComp); |
||||
} |
||||
if (tmpComp instanceof UIObserver) { |
||||
((UIObserver) tmpComp).registerChangeListener(observerListener); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 是否响应事件监听 |
||||
* @return 是则返回true |
||||
*/ |
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
} |
@ -1,360 +1,365 @@
|
||||
package com.fr.design.mainframe.chart.gui.style; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.base.Utils; |
||||
import com.fr.chart.base.ChartConstants; |
||||
import com.fr.chart.chartattr.CategoryAxis; |
||||
import com.fr.design.beans.FurtherBasicBeanPane; |
||||
import com.fr.design.dialog.BasicDialog; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.editor.ValueEditorPane; |
||||
import com.fr.design.editor.editor.DateEditor; |
||||
import com.fr.design.editor.editor.Editor; |
||||
import com.fr.design.editor.editor.FormulaEditor; |
||||
import com.fr.design.formula.FormulaFactory; |
||||
import com.fr.design.formula.UIFormula; |
||||
import com.fr.design.gui.date.UIDatePicker; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.style.FormatBox; |
||||
import com.fr.general.DateUtils; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.*; |
||||
import java.text.ParseException; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* 属性表, 坐标轴, 日期范围定义界面 |
||||
* @author kunsnat E-mail:kunsnat@gmail.com |
||||
* @version 创建时间:2013-1-4 上午10:25:15 |
||||
*/ |
||||
public class DateAxisValuePane extends FurtherBasicBeanPane<CategoryAxis>{ |
||||
|
||||
private static String[] TYPES = new String[]{ |
||||
Inter.getLocText("Year"), Inter.getLocText("Month"), Inter.getLocText("Sun"), |
||||
Inter.getLocText("Sche-Hour"), Inter.getLocText("Sche-Minute"), |
||||
Inter.getLocText("Sche-Second") |
||||
}; |
||||
|
||||
private static Map<String, Integer> VALUES = new HashMap<String, Integer>(); |
||||
static { |
||||
VALUES.put(Inter.getLocText("Year"), ChartConstants.YEAR_TYPE); |
||||
VALUES.put(Inter.getLocText("Month"), ChartConstants.MONTH_TYPE); |
||||
VALUES.put(Inter.getLocText("Sun"), ChartConstants.DAY_TYPE); |
||||
VALUES.put(Inter.getLocText("Sche-Hour"), ChartConstants.HOUR_TYPE); |
||||
VALUES.put(Inter.getLocText("Sche-Minute"), ChartConstants.MINUTE_TYPE); |
||||
VALUES.put(Inter.getLocText("Sche-Second"), ChartConstants.SECOND_TYPE); |
||||
} |
||||
|
||||
private static Map<Integer, String> INTS = new HashMap<Integer, String>(); |
||||
static { |
||||
INTS.put(ChartConstants.YEAR_TYPE, Inter.getLocText("Year")); |
||||
INTS.put(ChartConstants.MONTH_TYPE, Inter.getLocText("Month")); |
||||
INTS.put(ChartConstants.DAY_TYPE, Inter.getLocText("Sun")); |
||||
INTS.put(ChartConstants.HOUR_TYPE, Inter.getLocText("Sche-Hour")); |
||||
INTS.put(ChartConstants.MINUTE_TYPE, Inter.getLocText("Sche-Minute")); |
||||
INTS.put(ChartConstants.SECOND_TYPE, Inter.getLocText("Sche-Second")); |
||||
} |
||||
|
||||
// 最大最小值
|
||||
private UICheckBox maxCheckBox; |
||||
private ValueEditorPane maxValueField; |
||||
private UICheckBox minCheckBox; |
||||
private ValueEditorPane minValueField; |
||||
|
||||
private UICheckBox mainTickBox; |
||||
private UITextField mainUnitField; |
||||
private UIComboBox mainType; |
||||
|
||||
private FormatBox formatBox; |
||||
public FormatBox getFormatBox() { |
||||
return this.formatBox; |
||||
} |
||||
|
||||
public DateAxisValuePane() { |
||||
this.initComponents(); |
||||
} |
||||
|
||||
private void initMin() { |
||||
// 最小值.
|
||||
minCheckBox = new UICheckBox(Inter.getLocText("Min_Value")); |
||||
Date tmp = null; |
||||
DateEditor dateEditor = new DateEditor(tmp, true, Inter.getLocText("Date"), UIDatePicker.STYLE_CN_DATETIME1); |
||||
Editor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); |
||||
Editor[] editor = new Editor[]{dateEditor, formulaEditor}; |
||||
minValueField = new ValueEditorPane(editor); |
||||
minValueField.setEnabled(false); |
||||
minCheckBox.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkBoxUse(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void initMax() { |
||||
// 最大值
|
||||
maxCheckBox = new UICheckBox(Inter.getLocText("Max_Value")); |
||||
Date tmp = null; |
||||
DateEditor dateEditor = new DateEditor(tmp, true, Inter.getLocText("Date"), UIDatePicker.STYLE_CN_DATETIME1); |
||||
Editor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); |
||||
Editor[] editor = new Editor[]{dateEditor, formulaEditor}; |
||||
maxValueField = new ValueEditorPane(editor); |
||||
maxValueField.setEnabled(false); |
||||
maxCheckBox.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkBoxUse(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void initMain() { |
||||
// 主要刻度单位
|
||||
mainTickBox = new UICheckBox(Inter.getLocText("MainGraduationUnit")); |
||||
mainUnitField = new UITextField(); |
||||
mainUnitField.setPreferredSize(new Dimension(30, 20)); |
||||
mainUnitField.setEditable(false); |
||||
mainType = new UIComboBox(TYPES); |
||||
mainType.setEnabled(false); |
||||
|
||||
mainTickBox.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkBoxUse(); |
||||
} |
||||
}); |
||||
|
||||
addListener(mainTickBox, mainUnitField); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
formatBox = new FormatBox(); |
||||
JPanel pane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); |
||||
add(pane, BorderLayout.NORTH); |
||||
|
||||
initMin(); |
||||
initMax(); |
||||
initMain(); |
||||
|
||||
JPanel mainTickPane = new JPanel(); |
||||
mainTickPane.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0)); |
||||
|
||||
mainTickPane.add(mainUnitField); |
||||
mainTickPane.add(mainType); |
||||
|
||||
JPanel secTickPane = new JPanel(); |
||||
secTickPane.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0)); |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] rowSize = {p, p, p}; |
||||
double[] columnSize = {p, f}; |
||||
Component[][] maxMin = { |
||||
{minCheckBox, minValueField}, |
||||
{maxCheckBox, maxValueField}, |
||||
|
||||
}; |
||||
JPanel maxMinPane = TableLayoutHelper.createTableLayoutPane(maxMin, rowSize, columnSize); |
||||
Component[][] components = { |
||||
{maxMinPane, null}, |
||||
{mainTickBox, mainTickPane} |
||||
|
||||
}; |
||||
pane.add(TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize)); |
||||
} |
||||
|
||||
private void addListener(final UICheckBox box, final UITextField textField) { |
||||
textField.addMouseListener(new MouseAdapter() { |
||||
public void mousePressed(MouseEvent e) { |
||||
if (box.isSelected()) { |
||||
showFormulaPane(textField); |
||||
} |
||||
} |
||||
}); |
||||
textField.addKeyListener(new KeyAdapter() { |
||||
public void keyTyped(KeyEvent e) { |
||||
if (box.isSelected()) { |
||||
e.consume(); |
||||
showFormulaPane(textField); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void showFormulaPane(final UITextField jTextField) { |
||||
final UIFormula formulaPane = FormulaFactory.createFormulaPane(); |
||||
formulaPane.populate(new Formula(jTextField.getText())); |
||||
BasicDialog dlg = formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(DateAxisValuePane.this), new DialogActionAdapter() { |
||||
public void doOk() { |
||||
jTextField.setText(Utils.objectToString(formulaPane.update())); |
||||
} |
||||
}); |
||||
dlg.setVisible(true); |
||||
} |
||||
|
||||
private void populateMain(CategoryAxis axis) { |
||||
if (axis.isCustomMainUnit() && axis.getMainUnit() != null) { |
||||
mainTickBox.setSelected(true); |
||||
mainUnitField.setText(Utils.objectToString(axis.getMainUnit())); |
||||
mainType.setSelectedItem(INTS.get(axis.getMainType())); |
||||
} |
||||
} |
||||
|
||||
private void updateMain(CategoryAxis axis) { |
||||
if (mainTickBox.isSelected() && StringUtils.isNotEmpty(mainUnitField.getText())) { |
||||
axis.setCustomMainUnit(true); |
||||
axis.setMainUnit(new Formula(mainUnitField.getText())); |
||||
axis.setMainType(VALUES.get(mainType.getSelectedItem())); |
||||
} else { |
||||
axis.setCustomMainUnit(false); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public boolean accept(Object ob) { |
||||
return ob instanceof CategoryAxis; |
||||
} |
||||
|
||||
@Override |
||||
public void reset() { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public String title4PopupWindow() { |
||||
return Inter.getLocText("Chart_Date_Axis"); |
||||
} |
||||
|
||||
private void checkBoxUse() { |
||||
minValueField.setEnabled(minCheckBox.isSelected()); |
||||
maxValueField.setEnabled(maxCheckBox.isSelected()); |
||||
if(minValueField.getCurrentEditor() instanceof FormulaEditor){ |
||||
FormulaEditor tmpEditor = (FormulaEditor)minValueField.getCurrentEditor(); |
||||
tmpEditor.enableEditor(minCheckBox.isSelected()); |
||||
} |
||||
|
||||
if(maxValueField.getCurrentEditor() instanceof FormulaEditor){ |
||||
FormulaEditor tmpEditor = (FormulaEditor)maxValueField.getCurrentEditor(); |
||||
tmpEditor.enableEditor(maxCheckBox.isSelected()); |
||||
} |
||||
|
||||
mainType.setEnabled(mainTickBox.isSelected()); |
||||
mainUnitField.setEnabled(mainTickBox.isSelected()); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(CategoryAxis axis) { |
||||
if (axis == null) { |
||||
return; |
||||
} |
||||
if (!axis.isDate()) { |
||||
return; |
||||
} |
||||
// 最小值
|
||||
if (axis.isCustomMinValue() && axis.getMinValue() != null) { |
||||
minCheckBox.setSelected(true); |
||||
String dateStr = axis.getMinValue().getPureContent(); |
||||
if(!isDateForm(dateStr)){ |
||||
minValueField.populate(axis.getMinValue()); |
||||
}else{ |
||||
Date tmpDate = getDateFromFormula(axis.getMinValue()); |
||||
minValueField.populate(tmpDate); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
// 最大值
|
||||
if (axis.isCustomMaxValue() && axis.getMaxValue() != null) { |
||||
maxCheckBox.setSelected(true); |
||||
String dateStr = axis.getMaxValue().getPureContent(); |
||||
if(!isDateForm(dateStr)){ |
||||
maxValueField.populate(axis.getMaxValue()); |
||||
}else{ |
||||
Date tmpDate = getDateFromFormula(axis.getMaxValue()); |
||||
maxValueField.populate(tmpDate); |
||||
} |
||||
} |
||||
populateMain(axis); |
||||
|
||||
checkBoxUse(); |
||||
} |
||||
|
||||
private boolean isDateForm(String form){ |
||||
form = Pattern.compile("\"").matcher(form).replaceAll(StringUtils.EMPTY); |
||||
//全部是数字的话直接返回,string2Date会把全部是数字也会转化成日期
|
||||
if(form.matches("^[+-]?[0-9]*[0-9]$")){ |
||||
return false; |
||||
} |
||||
return (DateUtils.string2Date(form, true) != null); |
||||
} |
||||
|
||||
public void updateBean(CategoryAxis axis) { |
||||
updateMain(axis); |
||||
//最小值
|
||||
if (minCheckBox.isSelected()) { |
||||
if(minValueField.getCurrentEditor() instanceof FormulaEditor){ |
||||
Formula min = (Formula)minValueField.update(); |
||||
axis.setMinValue(min); |
||||
axis.setCustomMinValue(!StringUtils.isEmpty(min.getPureContent())); |
||||
}else{ |
||||
Date datetmp = (Date)minValueField.update(); |
||||
DateEditor dateEditor = (DateEditor)minValueField.getCurrentEditor(); |
||||
String dateString = dateEditor.getUIDatePickerFormat().format(datetmp); |
||||
axis.setCustomMinValue(!StringUtils.isEmpty(dateString)); |
||||
axis.setMinValue(new Formula(dateString)); |
||||
} |
||||
} else { |
||||
axis.setCustomMinValue(false); |
||||
} |
||||
|
||||
//最大值
|
||||
if (maxCheckBox.isSelected()) { |
||||
if(maxValueField.getCurrentEditor() instanceof FormulaEditor){ |
||||
Formula max = (Formula)maxValueField.update(); |
||||
axis.setMaxValue(max); |
||||
axis.setCustomMaxValue(!StringUtils.isEmpty(max.getPureContent())); |
||||
}else{ |
||||
Date datetmp = (Date)maxValueField.update(); |
||||
DateEditor dateEditor = (DateEditor)maxValueField.getCurrentEditor(); |
||||
String dateString = dateEditor.getUIDatePickerFormat().format(datetmp); |
||||
axis.setCustomMaxValue(!StringUtils.isEmpty(dateString)); |
||||
axis.setMaxValue(new Formula(dateString)); |
||||
} |
||||
} else { |
||||
axis.setCustomMaxValue(false); |
||||
} |
||||
|
||||
this.checkBoxUse(); |
||||
} |
||||
|
||||
@Override |
||||
public CategoryAxis updateBean() { |
||||
return null; |
||||
} |
||||
|
||||
//将从formula读出来的内容转化为指定格式的日期
|
||||
private static final Date getDateFromFormula(Formula dateFormula){ |
||||
String dateStr = dateFormula.getPureContent(); |
||||
dateStr = Pattern.compile("\"").matcher(dateStr).replaceAll(StringUtils.EMPTY); |
||||
Date toDate = DateUtils.string2Date(dateStr, true); |
||||
try { |
||||
String tmp = DateUtils.getDate2LStr(toDate); |
||||
toDate = DateUtils.DATETIMEFORMAT2.parse(tmp); |
||||
} catch (ParseException e) { |
||||
FRLogger.getLogger().error(Inter.getLocText("Cannot_Get_Date")); |
||||
} |
||||
return toDate; |
||||
} |
||||
package com.fr.design.mainframe.chart.gui.style; |
||||
|
||||
import com.fr.base.BaseFormula; |
||||
import com.fr.base.Utils; |
||||
import com.fr.chart.base.ChartConstants; |
||||
import com.fr.chart.chartattr.CategoryAxis; |
||||
import com.fr.design.beans.FurtherBasicBeanPane; |
||||
import com.fr.design.dialog.BasicDialog; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.editor.ValueEditorPane; |
||||
import com.fr.design.editor.editor.DateEditor; |
||||
import com.fr.design.editor.editor.Editor; |
||||
import com.fr.design.editor.editor.FormulaEditor; |
||||
import com.fr.design.formula.FormulaFactory; |
||||
import com.fr.design.formula.UIFormula; |
||||
import com.fr.design.gui.date.UIDatePicker; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.style.FormatBox; |
||||
import com.fr.general.DateUtils; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.KeyAdapter; |
||||
import java.awt.event.KeyEvent; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.text.ParseException; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* 属性表, 坐标轴, 日期范围定义界面 |
||||
* @author kunsnat E-mail:kunsnat@gmail.com |
||||
* @version 创建时间:2013-1-4 上午10:25:15 |
||||
*/ |
||||
public class DateAxisValuePane extends FurtherBasicBeanPane<CategoryAxis>{ |
||||
|
||||
private static String[] TYPES = new String[]{ |
||||
Inter.getLocText("Year"), Inter.getLocText("Month"), Inter.getLocText("Sun"), |
||||
Inter.getLocText("Sche-Hour"), Inter.getLocText("Sche-Minute"), |
||||
Inter.getLocText("Sche-Second") |
||||
}; |
||||
|
||||
private static Map<String, Integer> VALUES = new HashMap<String, Integer>(); |
||||
static { |
||||
VALUES.put(Inter.getLocText("Year"), ChartConstants.YEAR_TYPE); |
||||
VALUES.put(Inter.getLocText("Month"), ChartConstants.MONTH_TYPE); |
||||
VALUES.put(Inter.getLocText("Sun"), ChartConstants.DAY_TYPE); |
||||
VALUES.put(Inter.getLocText("Sche-Hour"), ChartConstants.HOUR_TYPE); |
||||
VALUES.put(Inter.getLocText("Sche-Minute"), ChartConstants.MINUTE_TYPE); |
||||
VALUES.put(Inter.getLocText("Sche-Second"), ChartConstants.SECOND_TYPE); |
||||
} |
||||
|
||||
private static Map<Integer, String> INTS = new HashMap<Integer, String>(); |
||||
static { |
||||
INTS.put(ChartConstants.YEAR_TYPE, Inter.getLocText("Year")); |
||||
INTS.put(ChartConstants.MONTH_TYPE, Inter.getLocText("Month")); |
||||
INTS.put(ChartConstants.DAY_TYPE, Inter.getLocText("Sun")); |
||||
INTS.put(ChartConstants.HOUR_TYPE, Inter.getLocText("Sche-Hour")); |
||||
INTS.put(ChartConstants.MINUTE_TYPE, Inter.getLocText("Sche-Minute")); |
||||
INTS.put(ChartConstants.SECOND_TYPE, Inter.getLocText("Sche-Second")); |
||||
} |
||||
|
||||
// 最大最小值
|
||||
private UICheckBox maxCheckBox; |
||||
private ValueEditorPane maxValueField; |
||||
private UICheckBox minCheckBox; |
||||
private ValueEditorPane minValueField; |
||||
|
||||
private UICheckBox mainTickBox; |
||||
private UITextField mainUnitField; |
||||
private UIComboBox mainType; |
||||
|
||||
private FormatBox formatBox; |
||||
public FormatBox getFormatBox() { |
||||
return this.formatBox; |
||||
} |
||||
|
||||
public DateAxisValuePane() { |
||||
this.initComponents(); |
||||
} |
||||
|
||||
private void initMin() { |
||||
// 最小值.
|
||||
minCheckBox = new UICheckBox(Inter.getLocText("Min_Value")); |
||||
Date tmp = null; |
||||
DateEditor dateEditor = new DateEditor(tmp, true, Inter.getLocText("Date"), UIDatePicker.STYLE_CN_DATETIME1); |
||||
Editor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); |
||||
Editor[] editor = new Editor[]{dateEditor, formulaEditor}; |
||||
minValueField = new ValueEditorPane(editor); |
||||
minValueField.setEnabled(false); |
||||
minCheckBox.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkBoxUse(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void initMax() { |
||||
// 最大值
|
||||
maxCheckBox = new UICheckBox(Inter.getLocText("Max_Value")); |
||||
Date tmp = null; |
||||
DateEditor dateEditor = new DateEditor(tmp, true, Inter.getLocText("Date"), UIDatePicker.STYLE_CN_DATETIME1); |
||||
Editor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); |
||||
Editor[] editor = new Editor[]{dateEditor, formulaEditor}; |
||||
maxValueField = new ValueEditorPane(editor); |
||||
maxValueField.setEnabled(false); |
||||
maxCheckBox.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkBoxUse(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void initMain() { |
||||
// 主要刻度单位
|
||||
mainTickBox = new UICheckBox(Inter.getLocText("MainGraduationUnit")); |
||||
mainUnitField = new UITextField(); |
||||
mainUnitField.setPreferredSize(new Dimension(30, 20)); |
||||
mainUnitField.setEditable(false); |
||||
mainType = new UIComboBox(TYPES); |
||||
mainType.setEnabled(false); |
||||
|
||||
mainTickBox.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkBoxUse(); |
||||
} |
||||
}); |
||||
|
||||
addListener(mainTickBox, mainUnitField); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
formatBox = new FormatBox(); |
||||
JPanel pane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); |
||||
add(pane, BorderLayout.NORTH); |
||||
|
||||
initMin(); |
||||
initMax(); |
||||
initMain(); |
||||
|
||||
JPanel mainTickPane = new JPanel(); |
||||
mainTickPane.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0)); |
||||
|
||||
mainTickPane.add(mainUnitField); |
||||
mainTickPane.add(mainType); |
||||
|
||||
JPanel secTickPane = new JPanel(); |
||||
secTickPane.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0)); |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] rowSize = {p, p, p}; |
||||
double[] columnSize = {p, f}; |
||||
Component[][] maxMin = { |
||||
{minCheckBox, minValueField}, |
||||
{maxCheckBox, maxValueField}, |
||||
|
||||
}; |
||||
JPanel maxMinPane = TableLayoutHelper.createTableLayoutPane(maxMin, rowSize, columnSize); |
||||
Component[][] components = { |
||||
{maxMinPane, null}, |
||||
{mainTickBox, mainTickPane} |
||||
|
||||
}; |
||||
pane.add(TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize)); |
||||
} |
||||
|
||||
private void addListener(final UICheckBox box, final UITextField textField) { |
||||
textField.addMouseListener(new MouseAdapter() { |
||||
public void mousePressed(MouseEvent e) { |
||||
if (box.isSelected()) { |
||||
showFormulaPane(textField); |
||||
} |
||||
} |
||||
}); |
||||
textField.addKeyListener(new KeyAdapter() { |
||||
public void keyTyped(KeyEvent e) { |
||||
if (box.isSelected()) { |
||||
e.consume(); |
||||
showFormulaPane(textField); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void showFormulaPane(final UITextField jTextField) { |
||||
final UIFormula formulaPane = FormulaFactory.createFormulaPane(); |
||||
formulaPane.populate(BaseFormula.createFormulaBuilder().build(jTextField.getText())); |
||||
BasicDialog dlg = formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(DateAxisValuePane.this), new DialogActionAdapter() { |
||||
public void doOk() { |
||||
jTextField.setText(Utils.objectToString(formulaPane.update())); |
||||
} |
||||
}); |
||||
dlg.setVisible(true); |
||||
} |
||||
|
||||
private void populateMain(CategoryAxis axis) { |
||||
if (axis.isCustomMainUnit() && axis.getMainUnit() != null) { |
||||
mainTickBox.setSelected(true); |
||||
mainUnitField.setText(Utils.objectToString(axis.getMainUnit())); |
||||
mainType.setSelectedItem(INTS.get(axis.getMainType())); |
||||
} |
||||
} |
||||
|
||||
private void updateMain(CategoryAxis axis) { |
||||
if (mainTickBox.isSelected() && StringUtils.isNotEmpty(mainUnitField.getText())) { |
||||
axis.setCustomMainUnit(true); |
||||
axis.setMainUnit(BaseFormula.createFormulaBuilder().build(mainUnitField.getText())); |
||||
axis.setMainType(VALUES.get(mainType.getSelectedItem())); |
||||
} else { |
||||
axis.setCustomMainUnit(false); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public boolean accept(Object ob) { |
||||
return ob instanceof CategoryAxis; |
||||
} |
||||
|
||||
@Override |
||||
public void reset() { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public String title4PopupWindow() { |
||||
return Inter.getLocText("Chart_Date_Axis"); |
||||
} |
||||
|
||||
private void checkBoxUse() { |
||||
minValueField.setEnabled(minCheckBox.isSelected()); |
||||
maxValueField.setEnabled(maxCheckBox.isSelected()); |
||||
if(minValueField.getCurrentEditor() instanceof FormulaEditor){ |
||||
FormulaEditor tmpEditor = (FormulaEditor)minValueField.getCurrentEditor(); |
||||
tmpEditor.enableEditor(minCheckBox.isSelected()); |
||||
} |
||||
|
||||
if(maxValueField.getCurrentEditor() instanceof FormulaEditor){ |
||||
FormulaEditor tmpEditor = (FormulaEditor)maxValueField.getCurrentEditor(); |
||||
tmpEditor.enableEditor(maxCheckBox.isSelected()); |
||||
} |
||||
|
||||
mainType.setEnabled(mainTickBox.isSelected()); |
||||
mainUnitField.setEnabled(mainTickBox.isSelected()); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(CategoryAxis axis) { |
||||
if (axis == null) { |
||||
return; |
||||
} |
||||
if (!axis.isDate()) { |
||||
return; |
||||
} |
||||
// 最小值
|
||||
if (axis.isCustomMinValue() && axis.getMinValue() != null) { |
||||
minCheckBox.setSelected(true); |
||||
String dateStr = axis.getMinValue().getPureContent(); |
||||
if(!isDateForm(dateStr)){ |
||||
minValueField.populate(axis.getMinValue()); |
||||
}else{ |
||||
Date tmpDate = getDateFromFormula(axis.getMinValue()); |
||||
minValueField.populate(tmpDate); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
// 最大值
|
||||
if (axis.isCustomMaxValue() && axis.getMaxValue() != null) { |
||||
maxCheckBox.setSelected(true); |
||||
String dateStr = axis.getMaxValue().getPureContent(); |
||||
if(!isDateForm(dateStr)){ |
||||
maxValueField.populate(axis.getMaxValue()); |
||||
}else{ |
||||
Date tmpDate = getDateFromFormula(axis.getMaxValue()); |
||||
maxValueField.populate(tmpDate); |
||||
} |
||||
} |
||||
populateMain(axis); |
||||
|
||||
checkBoxUse(); |
||||
} |
||||
|
||||
private boolean isDateForm(String form){ |
||||
form = Pattern.compile("\"").matcher(form).replaceAll(StringUtils.EMPTY); |
||||
//全部是数字的话直接返回,string2Date会把全部是数字也会转化成日期
|
||||
if(form.matches("^[+-]?[0-9]*[0-9]$")){ |
||||
return false; |
||||
} |
||||
return (DateUtils.string2Date(form, true) != null); |
||||
} |
||||
|
||||
public void updateBean(CategoryAxis axis) { |
||||
updateMain(axis); |
||||
//最小值
|
||||
if (minCheckBox.isSelected()) { |
||||
if(minValueField.getCurrentEditor() instanceof FormulaEditor){ |
||||
BaseFormula min = (BaseFormula) minValueField.update(); |
||||
axis.setMinValue(min); |
||||
axis.setCustomMinValue(!StringUtils.isEmpty(min.getPureContent())); |
||||
}else{ |
||||
Date datetmp = (Date)minValueField.update(); |
||||
DateEditor dateEditor = (DateEditor)minValueField.getCurrentEditor(); |
||||
String dateString = dateEditor.getUIDatePickerFormat().format(datetmp); |
||||
axis.setCustomMinValue(!StringUtils.isEmpty(dateString)); |
||||
axis.setMinValue(BaseFormula.createFormulaBuilder().build(dateString)); |
||||
} |
||||
} else { |
||||
axis.setCustomMinValue(false); |
||||
} |
||||
|
||||
//最大值
|
||||
if (maxCheckBox.isSelected()) { |
||||
if(maxValueField.getCurrentEditor() instanceof FormulaEditor){ |
||||
BaseFormula max = (BaseFormula) maxValueField.update(); |
||||
axis.setMaxValue(max); |
||||
axis.setCustomMaxValue(!StringUtils.isEmpty(max.getPureContent())); |
||||
}else{ |
||||
Date datetmp = (Date)maxValueField.update(); |
||||
DateEditor dateEditor = (DateEditor)maxValueField.getCurrentEditor(); |
||||
String dateString = dateEditor.getUIDatePickerFormat().format(datetmp); |
||||
axis.setCustomMaxValue(!StringUtils.isEmpty(dateString)); |
||||
axis.setMaxValue(BaseFormula.createFormulaBuilder().build(dateString)); |
||||
} |
||||
} else { |
||||
axis.setCustomMaxValue(false); |
||||
} |
||||
|
||||
this.checkBoxUse(); |
||||
} |
||||
|
||||
@Override |
||||
public CategoryAxis updateBean() { |
||||
return null; |
||||
} |
||||
|
||||
//将从formula读出来的内容转化为指定格式的日期
|
||||
private static final Date getDateFromFormula(BaseFormula dateFormula){ |
||||
String dateStr = dateFormula.getPureContent(); |
||||
dateStr = Pattern.compile("\"").matcher(dateStr).replaceAll(StringUtils.EMPTY); |
||||
Date toDate = DateUtils.string2Date(dateStr, true); |
||||
try { |
||||
String tmp = DateUtils.getDate2LStr(toDate); |
||||
toDate = DateUtils.DATETIMEFORMAT2.parse(tmp); |
||||
} catch (ParseException e) { |
||||
FRLogger.getLogger().error(Inter.getLocText("Cannot_Get_Date")); |
||||
} |
||||
return toDate; |
||||
} |
||||
} |
@ -1,195 +1,191 @@
|
||||
package com.fr.design.mainframe.chart.gui.style.title; |
||||
|
||||
|
||||
import java.awt.BorderLayout; |
||||
import java.awt.Component; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
|
||||
import javax.swing.Icon; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JSeparator; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.Formula; |
||||
import com.fr.base.Utils; |
||||
import com.fr.chart.base.TextAttr; |
||||
import com.fr.chart.chartattr.Chart; |
||||
import com.fr.chart.chartattr.Title; |
||||
import com.fr.design.constants.LayoutConstants; |
||||
import com.fr.design.formula.TinyFormulaPane; |
||||
import com.fr.design.gui.ibutton.UIButtonGroup; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.ilable.BoldFontTextLabel; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.mainframe.chart.PaneTitleConstants; |
||||
import com.fr.design.mainframe.chart.gui.style.ChartBackgroundNoImagePane; |
||||
import com.fr.design.mainframe.chart.gui.style.ChartBorderPane; |
||||
import com.fr.design.mainframe.chart.gui.style.ChartTextAttrPane; |
||||
import com.fr.design.dialog.BasicScrollPane; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.Constants; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
public class ChartTitlePane extends BasicScrollPane<Chart> { |
||||
private static final long serialVersionUID = 5748881235830708722L; |
||||
private UICheckBox isTitleVisable; |
||||
|
||||
private TinyFormulaPane titleContent; |
||||
private ChartTextAttrPane textAttrPane; |
||||
private UIButtonGroup<Integer> alignmentPane; |
||||
|
||||
private JPanel chartDefaultAttrPane; |
||||
private ChartBorderPane borderPane; |
||||
private ChartBackgroundNoImagePane backgroundPane; |
||||
|
||||
private JPanel titlePane; |
||||
|
||||
private class ContentPane extends JPanel { |
||||
private static final long serialVersionUID = -6455600016731592455L; |
||||
|
||||
public ContentPane() { |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
isTitleVisable = new UICheckBox(Inter.getLocText("Chart_Title_Is_Visible")); |
||||
titlePane = createTitlePane(); |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {f}; |
||||
double[] rowSize = {p, p}; |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{isTitleVisable}, |
||||
new Component[]{titlePane} |
||||
} ; |
||||
|
||||
JPanel panel = TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); |
||||
this.setLayout(new BorderLayout()); |
||||
this.add(panel,BorderLayout.CENTER); |
||||
|
||||
isTitleVisable.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkTitlePaneUse(); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
|
||||
private JPanel createTitlePane(){ |
||||
borderPane = new ChartBorderPane(); |
||||
backgroundPane = new ChartBackgroundNoImagePane(); |
||||
chartDefaultAttrPane = createDefaultAttrPane(); |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {p, f}; |
||||
double[] rowSize = {p,p,p,p,p}; |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{chartDefaultAttrPane,null}, |
||||
new Component[]{new JSeparator(),null}, |
||||
new Component[]{borderPane,null}, |
||||
new Component[]{backgroundPane,null} |
||||
} ; |
||||
|
||||
return TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); |
||||
} |
||||
|
||||
private JPanel createDefaultAttrPane(){ |
||||
titleContent = new TinyFormulaPane(); |
||||
textAttrPane = new ChartTextAttrPane(); |
||||
Icon[] alignmentIconArray = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), |
||||
BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), |
||||
BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png")}; |
||||
Integer[] alignment = new Integer[]{Constants.LEFT, Constants.CENTER, Constants.RIGHT}; |
||||
alignmentPane = new UIButtonGroup<Integer>(alignmentIconArray, alignment); |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, f}; |
||||
double[] rowSize = {p, p,p}; |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{null,titleContent,null}, |
||||
new Component[]{null,textAttrPane,null}, |
||||
new Component[]{null,new BoldFontTextLabel(Inter.getLocText("Alignment-Style") + ":"),alignmentPane} , |
||||
} ; |
||||
|
||||
return TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); |
||||
} |
||||
|
||||
// 检查标题界面是否可用.
|
||||
private void checkTitlePaneUse() { |
||||
isTitleVisable.setVisible(true); |
||||
isTitleVisable.setEnabled(true); |
||||
titlePane.setVisible(isTitleVisable.isSelected()); |
||||
this.repaint(); |
||||
} |
||||
|
||||
/** |
||||
* 弹出框的界面标题 |
||||
* @return 界面标题 |
||||
*/ |
||||
public String title4PopupWindow() { |
||||
return PaneTitleConstants.CHART_STYLE_TITLE_TITLE; |
||||
} |
||||
|
||||
@Override |
||||
protected JPanel createContentPane() { |
||||
return new ContentPane(); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(Chart chart) { |
||||
Title title = chart.getTitle(); |
||||
if (title == null) { |
||||
return; |
||||
} |
||||
isTitleVisable.setSelected(title.isTitleVisible()); |
||||
if (title.getTextObject() instanceof Formula) { |
||||
titleContent.populateBean(((Formula) title.getTextObject()).getContent()); |
||||
} else { |
||||
titleContent.populateBean(Utils.objectToString(title.getTextObject())); |
||||
} |
||||
alignmentPane.setSelectedItem(title.getPosition()); |
||||
TextAttr textAttr = title.getTextAttr(); |
||||
if (textAttr == null) { |
||||
textAttr = new TextAttr(); |
||||
} |
||||
textAttrPane.populate(textAttr); |
||||
borderPane.populate(title); |
||||
backgroundPane.populate(title); |
||||
|
||||
checkTitlePaneUse(); |
||||
} |
||||
|
||||
@Override |
||||
public void updateBean(Chart chart) { |
||||
if (chart == null) { |
||||
chart = new Chart(); |
||||
} |
||||
Title title = chart.getTitle(); |
||||
if (title == null) { |
||||
title = new Title(StringUtils.EMPTY); |
||||
} |
||||
title.setTitleVisible(isTitleVisable.isSelected()); |
||||
String titleString = titleContent.updateBean(); |
||||
Object titleObj; |
||||
if (StableUtils.maybeFormula(titleString)) { |
||||
titleObj = new Formula(titleString); |
||||
} else { |
||||
titleObj = titleString; |
||||
} |
||||
title.setTextObject(titleObj); |
||||
TextAttr textAttr = title.getTextAttr(); |
||||
if (textAttr == null) { |
||||
textAttr = new TextAttr(); |
||||
} |
||||
title.setPosition(alignmentPane.getSelectedItem()); |
||||
textAttrPane.update(textAttr); |
||||
borderPane.update(title); |
||||
backgroundPane.update(title); |
||||
} |
||||
package com.fr.design.mainframe.chart.gui.style.title; |
||||
|
||||
|
||||
import com.fr.base.BaseFormula; |
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.Utils; |
||||
import com.fr.chart.base.TextAttr; |
||||
import com.fr.chart.chartattr.Chart; |
||||
import com.fr.chart.chartattr.Title; |
||||
import com.fr.design.constants.LayoutConstants; |
||||
import com.fr.design.dialog.BasicScrollPane; |
||||
import com.fr.design.formula.TinyFormulaPane; |
||||
import com.fr.design.gui.ibutton.UIButtonGroup; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.ilable.BoldFontTextLabel; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.mainframe.chart.PaneTitleConstants; |
||||
import com.fr.design.mainframe.chart.gui.style.ChartBackgroundNoImagePane; |
||||
import com.fr.design.mainframe.chart.gui.style.ChartBorderPane; |
||||
import com.fr.design.mainframe.chart.gui.style.ChartTextAttrPane; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.Constants; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
|
||||
public class ChartTitlePane extends BasicScrollPane<Chart> { |
||||
private static final long serialVersionUID = 5748881235830708722L; |
||||
private UICheckBox isTitleVisable; |
||||
|
||||
private TinyFormulaPane titleContent; |
||||
private ChartTextAttrPane textAttrPane; |
||||
private UIButtonGroup<Integer> alignmentPane; |
||||
|
||||
private JPanel chartDefaultAttrPane; |
||||
private ChartBorderPane borderPane; |
||||
private ChartBackgroundNoImagePane backgroundPane; |
||||
|
||||
private JPanel titlePane; |
||||
|
||||
private class ContentPane extends JPanel { |
||||
private static final long serialVersionUID = -6455600016731592455L; |
||||
|
||||
public ContentPane() { |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
isTitleVisable = new UICheckBox(Inter.getLocText("Chart_Title_Is_Visible")); |
||||
titlePane = createTitlePane(); |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {f}; |
||||
double[] rowSize = {p, p}; |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{isTitleVisable}, |
||||
new Component[]{titlePane} |
||||
} ; |
||||
|
||||
JPanel panel = TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); |
||||
this.setLayout(new BorderLayout()); |
||||
this.add(panel,BorderLayout.CENTER); |
||||
|
||||
isTitleVisable.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
checkTitlePaneUse(); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
|
||||
private JPanel createTitlePane(){ |
||||
borderPane = new ChartBorderPane(); |
||||
backgroundPane = new ChartBackgroundNoImagePane(); |
||||
chartDefaultAttrPane = createDefaultAttrPane(); |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {p, f}; |
||||
double[] rowSize = {p,p,p,p,p}; |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{chartDefaultAttrPane,null}, |
||||
new Component[]{new JSeparator(),null}, |
||||
new Component[]{borderPane,null}, |
||||
new Component[]{backgroundPane,null} |
||||
} ; |
||||
|
||||
return TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); |
||||
} |
||||
|
||||
private JPanel createDefaultAttrPane(){ |
||||
titleContent = new TinyFormulaPane(); |
||||
textAttrPane = new ChartTextAttrPane(); |
||||
Icon[] alignmentIconArray = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), |
||||
BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), |
||||
BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png")}; |
||||
Integer[] alignment = new Integer[]{Constants.LEFT, Constants.CENTER, Constants.RIGHT}; |
||||
alignmentPane = new UIButtonGroup<Integer>(alignmentIconArray, alignment); |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, f}; |
||||
double[] rowSize = {p, p,p}; |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{null,titleContent,null}, |
||||
new Component[]{null,textAttrPane,null}, |
||||
new Component[]{null,new BoldFontTextLabel(Inter.getLocText("Alignment-Style") + ":"),alignmentPane} , |
||||
} ; |
||||
|
||||
return TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); |
||||
} |
||||
|
||||
// 检查标题界面是否可用.
|
||||
private void checkTitlePaneUse() { |
||||
isTitleVisable.setVisible(true); |
||||
isTitleVisable.setEnabled(true); |
||||
titlePane.setVisible(isTitleVisable.isSelected()); |
||||
this.repaint(); |
||||
} |
||||
|
||||
/** |
||||
* 弹出框的界面标题 |
||||
* @return 界面标题 |
||||
*/ |
||||
public String title4PopupWindow() { |
||||
return PaneTitleConstants.CHART_STYLE_TITLE_TITLE; |
||||
} |
||||
|
||||
@Override |
||||
protected JPanel createContentPane() { |
||||
return new ContentPane(); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(Chart chart) { |
||||
Title title = chart.getTitle(); |
||||
if (title == null) { |
||||
return; |
||||
} |
||||
isTitleVisable.setSelected(title.isTitleVisible()); |
||||
if (title.getTextObject() instanceof BaseFormula) { |
||||
titleContent.populateBean(((BaseFormula) title.getTextObject()).getContent()); |
||||
} else { |
||||
titleContent.populateBean(Utils.objectToString(title.getTextObject())); |
||||
} |
||||
alignmentPane.setSelectedItem(title.getPosition()); |
||||
TextAttr textAttr = title.getTextAttr(); |
||||
if (textAttr == null) { |
||||
textAttr = new TextAttr(); |
||||
} |
||||
textAttrPane.populate(textAttr); |
||||
borderPane.populate(title); |
||||
backgroundPane.populate(title); |
||||
|
||||
checkTitlePaneUse(); |
||||
} |
||||
|
||||
@Override |
||||
public void updateBean(Chart chart) { |
||||
if (chart == null) { |
||||
chart = new Chart(); |
||||
} |
||||
Title title = chart.getTitle(); |
||||
if (title == null) { |
||||
title = new Title(StringUtils.EMPTY); |
||||
} |
||||
title.setTitleVisible(isTitleVisable.isSelected()); |
||||
String titleString = titleContent.updateBean(); |
||||
Object titleObj; |
||||
if (StableUtils.maybeFormula(titleString)) { |
||||
titleObj = BaseFormula.createFormulaBuilder().build(titleString); |
||||
} else { |
||||
titleObj = titleString; |
||||
} |
||||
title.setTextObject(titleObj); |
||||
TextAttr textAttr = title.getTextAttr(); |
||||
if (textAttr == null) { |
||||
textAttr = new TextAttr(); |
||||
} |
||||
title.setPosition(alignmentPane.getSelectedItem()); |
||||
textAttrPane.update(textAttr); |
||||
borderPane.update(title); |
||||
backgroundPane.update(title); |
||||
} |
||||
} |
@ -1,156 +1,154 @@
|
||||
package com.fr.design.designer.creator; |
||||
|
||||
import java.awt.Dimension; |
||||
import java.awt.Insets; |
||||
|
||||
import javax.swing.JComponent; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.design.border.UIRoundedBorder; |
||||
import com.fr.form.ui.AbstractBorderStyleWidget; |
||||
import com.fr.form.ui.Label; |
||||
import com.fr.form.ui.LayoutBorderStyle; |
||||
import com.fr.form.ui.PaddingMargin; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.form.ui.WidgetTitle; |
||||
import com.fr.form.ui.WidgetValue; |
||||
import com.fr.form.ui.container.WTitleLayout; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.stable.Constants; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* Created with IntelliJ IDEA. |
||||
* User: zx |
||||
* Date: 14-9-22 |
||||
* Time: 上午10:40 |
||||
*/ |
||||
|
||||
public class XBorderStyleWidgetCreator extends XWidgetCreator{ |
||||
protected static final Dimension BORDER_PREFERRED_SIZE = new Dimension(250, 150); |
||||
|
||||
public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) { |
||||
super(widget, initSize); |
||||
} |
||||
|
||||
/** |
||||
* 返回容器对应的widget |
||||
* @return 同上 |
||||
*/ |
||||
@Override |
||||
public AbstractBorderStyleWidget toData() { |
||||
return (AbstractBorderStyleWidget) data; |
||||
} |
||||
|
||||
protected void initStyle() { |
||||
LayoutBorderStyle style = toData().getBorderStyle(); |
||||
initBorderStyle(); |
||||
if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) { |
||||
initTitleStyle(style); |
||||
} else { |
||||
clearTitleWidget(); |
||||
} |
||||
} |
||||
|
||||
// 边框默认值设为NONE,不然像scalelayout这种只用默认边框的会不显示边框
|
||||
protected void initBorderStyle() { |
||||
LayoutBorderStyle style = toData().getBorderStyle(); |
||||
if (style != null && style.getBorder() != Constants.LINE_NONE) { |
||||
this.setBorder(new UIRoundedBorder(style.getBorder(), style.getColor(), style.getBorderRadius())); |
||||
} else { |
||||
this.setBorder(DEFALUTBORDER); |
||||
} |
||||
} |
||||
|
||||
private void clearTitleWidget() { |
||||
if (acceptType(XWFitLayout.class)) { |
||||
return; |
||||
} |
||||
XWTitleLayout parent = (XWTitleLayout) this.getParent(); |
||||
if (parent.getComponentCount() > 1) { |
||||
parent.remove(parent.getTitleCreator()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 设置样式为标题样式时,对应组件加上标题 |
||||
* @param style 样式 |
||||
*/ |
||||
protected void initTitleStyle(LayoutBorderStyle style){ |
||||
if (style.getTitle() == null) { |
||||
return; |
||||
} |
||||
XWTitleLayout parent = (XWTitleLayout) this.getParent(); |
||||
if (parent.getComponentCount() > 1) { |
||||
XLabel title = (XLabel) parent.getTitleCreator(); |
||||
Label widget = title.toData(); |
||||
updateTitleWidgetStyle(widget, style); |
||||
title.initXCreatorProperties(); |
||||
return; |
||||
} |
||||
// 初始化标题控件
|
||||
XLabel title = new XLabel(new Label(), new Dimension()); |
||||
Label label = title.toData(); |
||||
updateTitleWidgetStyle(label, style); |
||||
parent.add(title, WTitleLayout.TITLE); |
||||
// 初始化标题边框
|
||||
title.initXCreatorProperties(); |
||||
WTitleLayout layout = parent.toData(); |
||||
layout.updateChildBounds(layout.getBodyBoundsWidget().getBounds()); |
||||
} |
||||
|
||||
/** |
||||
* 更新标题控件所有的样式 |
||||
*/ |
||||
private void updateTitleWidgetStyle(Label title, LayoutBorderStyle style) { |
||||
//标题的边框样式目前是取对应的控件的边框样式
|
||||
title.setBorder(style.getBorder()); |
||||
title.setColor(style.getColor()); |
||||
// title.setCorner(style.isCorner());
|
||||
|
||||
WidgetTitle wTitle = style.getTitle(); |
||||
//设置成随机不重复的, 不然都用一个名字的话, 联动只能联动一个
|
||||
title.setWidgetName(wTitle.TITLE_NAME_INDEX + this.toData().getWidgetName()); |
||||
title.setWidgetValue(getTitleValue(wTitle)); |
||||
title.setFont(wTitle.getFrFont()); |
||||
title.setTextalign(wTitle.getPosition()); |
||||
title.setBackground(wTitle.getBackground()); |
||||
} |
||||
|
||||
private WidgetValue getTitleValue(WidgetTitle wTitle){ |
||||
String content = String.valueOf(wTitle.getTextObject()); |
||||
Object vlaue = content.startsWith("=") ? new Formula(content) : content; |
||||
return new WidgetValue(vlaue); |
||||
} |
||||
|
||||
@Override |
||||
protected String getIconName() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
@Override |
||||
protected JComponent initEditor() { |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 内边距 |
||||
* @return 同上 |
||||
*/ |
||||
@Override |
||||
public Insets getInsets() { |
||||
PaddingMargin padding = toData().getMargin(); |
||||
if (padding == null) { |
||||
return new Insets(0, 0, 0, 0); |
||||
} |
||||
return new Insets(padding.getTop(), padding.getLeft(), padding.getBottom(), padding.getRight()); |
||||
} |
||||
|
||||
/** |
||||
* data属性改变触发其他操作 |
||||
* |
||||
*/ |
||||
public void firePropertyChange(){ |
||||
|
||||
} |
||||
|
||||
package com.fr.design.designer.creator; |
||||
|
||||
import com.fr.base.BaseFormula; |
||||
import com.fr.design.border.UIRoundedBorder; |
||||
import com.fr.form.ui.AbstractBorderStyleWidget; |
||||
import com.fr.form.ui.Label; |
||||
import com.fr.form.ui.LayoutBorderStyle; |
||||
import com.fr.form.ui.PaddingMargin; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.form.ui.WidgetTitle; |
||||
import com.fr.form.ui.WidgetValue; |
||||
import com.fr.form.ui.container.WTitleLayout; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.stable.Constants; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
/** |
||||
* Created with IntelliJ IDEA. |
||||
* User: zx |
||||
* Date: 14-9-22 |
||||
* Time: 上午10:40 |
||||
*/ |
||||
|
||||
public class XBorderStyleWidgetCreator extends XWidgetCreator{ |
||||
protected static final Dimension BORDER_PREFERRED_SIZE = new Dimension(250, 150); |
||||
|
||||
public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) { |
||||
super(widget, initSize); |
||||
} |
||||
|
||||
/** |
||||
* 返回容器对应的widget |
||||
* @return 同上 |
||||
*/ |
||||
@Override |
||||
public AbstractBorderStyleWidget toData() { |
||||
return (AbstractBorderStyleWidget) data; |
||||
} |
||||
|
||||
protected void initStyle() { |
||||
LayoutBorderStyle style = toData().getBorderStyle(); |
||||
initBorderStyle(); |
||||
if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) { |
||||
initTitleStyle(style); |
||||
} else { |
||||
clearTitleWidget(); |
||||
} |
||||
} |
||||
|
||||
// 边框默认值设为NONE,不然像scalelayout这种只用默认边框的会不显示边框
|
||||
protected void initBorderStyle() { |
||||
LayoutBorderStyle style = toData().getBorderStyle(); |
||||
if (style != null && style.getBorder() != Constants.LINE_NONE) { |
||||
this.setBorder(new UIRoundedBorder(style.getBorder(), style.getColor(), style.getBorderRadius())); |
||||
} else { |
||||
this.setBorder(DEFALUTBORDER); |
||||
} |
||||
} |
||||
|
||||
private void clearTitleWidget() { |
||||
if (acceptType(XWFitLayout.class)) { |
||||
return; |
||||
} |
||||
XWTitleLayout parent = (XWTitleLayout) this.getParent(); |
||||
if (parent.getComponentCount() > 1) { |
||||
parent.remove(parent.getTitleCreator()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 设置样式为标题样式时,对应组件加上标题 |
||||
* @param style 样式 |
||||
*/ |
||||
protected void initTitleStyle(LayoutBorderStyle style){ |
||||
if (style.getTitle() == null) { |
||||
return; |
||||
} |
||||
XWTitleLayout parent = (XWTitleLayout) this.getParent(); |
||||
if (parent.getComponentCount() > 1) { |
||||
XLabel title = (XLabel) parent.getTitleCreator(); |
||||
Label widget = title.toData(); |
||||
updateTitleWidgetStyle(widget, style); |
||||
title.initXCreatorProperties(); |
||||
return; |
||||
} |
||||
// 初始化标题控件
|
||||
XLabel title = new XLabel(new Label(), new Dimension()); |
||||
Label label = title.toData(); |
||||
updateTitleWidgetStyle(label, style); |
||||
parent.add(title, WTitleLayout.TITLE); |
||||
// 初始化标题边框
|
||||
title.initXCreatorProperties(); |
||||
WTitleLayout layout = parent.toData(); |
||||
layout.updateChildBounds(layout.getBodyBoundsWidget().getBounds()); |
||||
} |
||||
|
||||
/** |
||||
* 更新标题控件所有的样式 |
||||
*/ |
||||
private void updateTitleWidgetStyle(Label title, LayoutBorderStyle style) { |
||||
//标题的边框样式目前是取对应的控件的边框样式
|
||||
title.setBorder(style.getBorder()); |
||||
title.setColor(style.getColor()); |
||||
// title.setCorner(style.isCorner());
|
||||
|
||||
WidgetTitle wTitle = style.getTitle(); |
||||
//设置成随机不重复的, 不然都用一个名字的话, 联动只能联动一个
|
||||
title.setWidgetName(wTitle.TITLE_NAME_INDEX + this.toData().getWidgetName()); |
||||
title.setWidgetValue(getTitleValue(wTitle)); |
||||
title.setFont(wTitle.getFrFont()); |
||||
title.setTextalign(wTitle.getPosition()); |
||||
title.setBackground(wTitle.getBackground()); |
||||
} |
||||
|
||||
private WidgetValue getTitleValue(WidgetTitle wTitle){ |
||||
String content = String.valueOf(wTitle.getTextObject()); |
||||
Object vlaue = content.startsWith("=") ? BaseFormula.createFormulaBuilder().build(content) : content; |
||||
return new WidgetValue(vlaue); |
||||
} |
||||
|
||||
@Override |
||||
protected String getIconName() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
@Override |
||||
protected JComponent initEditor() { |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 内边距 |
||||
* @return 同上 |
||||
*/ |
||||
@Override |
||||
public Insets getInsets() { |
||||
PaddingMargin padding = toData().getMargin(); |
||||
if (padding == null) { |
||||
return new Insets(0, 0, 0, 0); |
||||
} |
||||
return new Insets(padding.getTop(), padding.getLeft(), padding.getBottom(), padding.getRight()); |
||||
} |
||||
|
||||
/** |
||||
* data属性改变触发其他操作 |
||||
* |
||||
*/ |
||||
public void firePropertyChange(){ |
||||
|
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue