Browse Source

代码修改

research/11.0
kerry 4 years ago
parent
commit
f59067714e
  1. 104
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/CellStyleSettingPane.java

104
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/CellStyleSettingPane.java

@ -6,19 +6,29 @@ import com.fr.config.StyleMap;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.dialog.AttrScrollPane;
import com.fr.design.dialog.BasicScrollPane;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.NameInspector;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilist.JNameEdList;
import com.fr.design.gui.ilist.ListModelElement;
import com.fr.design.gui.ilist.ModNameActionListener;
import com.fr.design.i18n.Toolkit;
import com.fr.design.icon.IconPathConstants;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.predefined.ui.PredefinedStyleEditPane;
import com.fr.design.mainframe.predefined.ui.detail.cell.CustomPredefinedStylePane;
import com.fr.general.ComparatorUtils;
import com.fr.general.NameObject;
import com.fr.report.cell.DefaultTemplateCellElement;
import com.fr.report.cell.TemplateCellElement;
import com.fr.report.core.PaintUtils;
import com.fr.stable.Constants;
import com.fr.stable.Nameable;
import com.fr.stable.StringUtils;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
@ -27,11 +37,13 @@ import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -137,11 +149,37 @@ public class CellStyleSettingPane extends BasicBeanPane<StyleMap> {
class StyleListPane extends JPanel {
private DefaultListModel defaultListModel;
private JList styleList;
private JNameEdList styleList;
public StyleListPane() {
defaultListModel = new DefaultListModel();
styleList = new JList(defaultListModel);
styleList = new JNameEdList(defaultListModel){
public Rectangle createRect(Rectangle rect, int iconWidth) {
return new Rectangle(rect.x , rect.y, rect.width, rect.height);
}
};
styleList.setEditable(true);
styleList.addModNameActionListener(new ModNameActionListener() {
public void nameModed(int index, String oldName, String newName) {
if (ComparatorUtils.equals(oldName, newName) || ComparatorUtils.equals(newName, NameInspector.ILLEGAL_NAME_HOLDER)) {
return;
}
String[] allNames = styleList.getAllNames();
allNames[index] = StringUtils.EMPTY;
if (StringUtils.isEmpty(newName)) {
showTipDialogAndReset(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Empty_Name"), index);
return;
}
if (isNameRepeated(new List[] {Arrays.asList(allNames)}, newName)) {
showTipDialogAndReset(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Duplicate_Name", newName), index);
styleList.setNameAt("请重新命名", index);
return;
}
styleList.repaint();
}
});
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.add(styleList, BorderLayout.CENTER);
@ -149,11 +187,36 @@ public class CellStyleSettingPane extends BasicBeanPane<StyleMap> {
@Override
public void mouseClicked(MouseEvent e) {
int selectIndex = styleList.getSelectedIndex();
cardLayout.show(centerPane, defaultListModel.get(selectIndex).toString());
cardLayout.show(centerPane,styleList.getNameAt(selectIndex));
styleList.stopEditing();
if (e.getClickCount() >= 2
&& SwingUtilities.isLeftMouseButton(e)) {
styleList.editItemAt(styleList.getSelectedIndex());
}
}
});
}
private void showTipDialogAndReset(String content, int index) {
styleList.stopEditing();
FineJOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(StyleListPane.this),
content,
Toolkit.i18nText("Fine-Design_Basic_Alert"),
JOptionPane.WARNING_MESSAGE);
}
protected boolean isNameRepeated(java.util.List[] list, String name) {
for (int i = 0; i < list.length; i++) {
if (list[i].contains(name)) {
return true;
}
}
return false;
}
public void populate(StyleMap ob) {
Iterator<Map.Entry<String, Style>> iterator = ob.getAllStyles().entrySet().iterator();
while (iterator.hasNext()) {
@ -167,7 +230,7 @@ public class CellStyleSettingPane extends BasicBeanPane<StyleMap> {
private void reset() {
if (defaultListModel.getSize() > 0) {
styleList.setSelectedIndex(0);
cardLayout.show(centerPane, defaultListModel.get(0).toString());
cardLayout.show(centerPane, styleList.getNameAt(0));
centerPane.validate();
}
@ -176,7 +239,7 @@ public class CellStyleSettingPane extends BasicBeanPane<StyleMap> {
public StyleMap update() {
StyleMap styleMap = new StyleMap();
for (int i = 0; i < defaultListModel.getSize(); i++) {
String name = defaultListModel.get(i).toString();
String name = styleList.getNameAt(i);
Style style = customStylePaneList.get(i).updateBean();
styleMap.put(name, style);
}
@ -184,11 +247,18 @@ public class CellStyleSettingPane extends BasicBeanPane<StyleMap> {
}
public void addNewStyle() {
String newStyleName = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Cell_New_Style");
if (isNameRepeated(new List[] {Arrays.asList(styleList.getAllNames())},
newStyleName)){
showTipDialogAndReset(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Duplicate_Name", newStyleName), 0);
return;
}
addStyle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Cell_New_Style"), Style.getInstance());
}
public void addStyle(String name, Style style) {
defaultListModel.addElement(name);
ListModelElement el = new ListCellStyleModelElement(new NameObject(name, style));
defaultListModel.addElement(el);
CustomPredefinedStylePane customPredefinedStylePane = new CustomPredefinedStylePane();
customPredefinedStylePane.populateBean(style);
customPredefinedStylePane.addChangeListener(new ChangeListener() {
@ -204,13 +274,27 @@ public class CellStyleSettingPane extends BasicBeanPane<StyleMap> {
public void removeStyle() {
int selectIndex = styleList.getSelectedIndex();
defaultListModel.remove(selectIndex);
styleList.remove(selectIndex);
centerPane.remove(customStylePaneList.get(selectIndex));
customStylePaneList.remove(selectIndex);
reset();
}
}
class ListCellStyleModelElement extends com.fr.design.gui.ilist.ListModelElement {
private Nameable nameable;
public ListCellStyleModelElement(Nameable nameable) {
super(nameable);
this.nameable = nameable;
}
@Override
public String toString() {
return this.nameable.getName();
}
}
class CellStylePreviewPane extends JPanel {
private TemplateCellElement ce;
@ -231,4 +315,6 @@ public class CellStyleSettingPane extends BasicBeanPane<StyleMap> {
PaintUtils.paintGridCellContent((Graphics2D) g, ce, this.getWidth(), this.getHeight(), Constants.FR_PAINT_RESOLUTION);
}
}
}

Loading…
Cancel
Save