Browse Source

1

bugfix/10.0
neil 6 years ago
parent
commit
dff9c1758b
  1. 629
      designer-base/src/main/java/com/fr/design/web/CustomIconPane.java

629
designer-base/src/main/java/com/fr/design/web/CustomIconPane.java

@ -41,333 +41,337 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
/** /**
*
* carl自定义Icon编辑 * carl自定义Icon编辑
*
*/ */
public class CustomIconPane extends BasicPane { public class CustomIconPane extends BasicPane {
private String selectedIconName = null; private String selectedIconName = null;
private ListMap iconButtonMap = null; private ListMap iconButtonMap = null;
private JPanel iconPane = null; private JPanel iconPane = null;
private ButtonGroup bg; private ButtonGroup bg;
private UIScrollPane jsPane; private UIScrollPane jsPane;
// 老一次次去拿真麻烦 // 老一次次去拿真麻烦
private IconManager iconManager = null; private IconManager iconManager = null;
private UIButton removeButton; private UIButton removeButton;
private UIButton editButton; private UIButton editButton;
private static final int THE_WIDTH = 180;
private static final int THE_WIDTH = 180; private static final int HORIZONTAL_COUNT = 6;
private static final int HORIZONTAL_COUNT = 6; private static final int HEIGHT_PER = 29;
private static final int HEIGHT_PER = 29; private static final int GAP = 10;
private static final int GAP = 10;
public CustomIconPane() {
public CustomIconPane() { this.initComponents();
this.initComponents(); }
}
private void initComponents() {
private void initComponents() { this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setLayout(FRGUIPaneFactory.createBorderLayout()); JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); centerPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Icon")));
centerPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Icon"))); JPanel noNamePane = FRGUIPaneFactory.createCenterFlowInnerContainer_S_Pane();
JPanel noNamePane = FRGUIPaneFactory.createCenterFlowInnerContainer_S_Pane(); centerPane.add(noNamePane, BorderLayout.CENTER);
centerPane.add(noNamePane, BorderLayout.CENTER);
iconPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
iconPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
// 开始加图标选择按钮
// 开始加图标选择按钮 initIcons();
initIcons();
jsPane = new UIScrollPane(iconPane);
jsPane = new UIScrollPane(iconPane); refreshIconPane(false);
refreshIconPane(false); jsPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
jsPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
jsPane.setPreferredSize(new Dimension(200, 180));
jsPane.setPreferredSize(new Dimension(200,180)); noNamePane.add(jsPane);
noNamePane.add(jsPane);
DescriptionTextArea des = new DescriptionTextArea(2);
DescriptionTextArea des = new DescriptionTextArea(2); des.setText(createDescriptionText());
des.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_Message1")); centerPane.add(des, BorderLayout.SOUTH);
centerPane.add(des, BorderLayout.SOUTH);
this.add(centerPane, BorderLayout.CENTER);
this.add(centerPane, BorderLayout.CENTER);
JPanel eastPane = FRGUIPaneFactory.createCenterFlowInnerContainer_S_Pane();
JPanel eastPane = FRGUIPaneFactory.createCenterFlowInnerContainer_S_Pane(); JPanel buttonPane = FRGUIPaneFactory.createNColumnGridInnerContainer_S_Pane(1);
JPanel buttonPane = FRGUIPaneFactory.createNColumnGridInnerContainer_S_Pane(1);
// 增加、删除、编辑按钮
// 增加、删除、编辑按钮 initAddButton(buttonPane);
initAddButton(buttonPane); initRemoveButton(buttonPane);
initRemoveButton(buttonPane); initEditButton(buttonPane);
initEditButton(buttonPane);
eastPane.add(buttonPane);
eastPane.add(buttonPane); this.add(eastPane, BorderLayout.EAST);
this.add(eastPane, BorderLayout.EAST);
}
}
private void initIcons() { protected String createDescriptionText(){
iconButtonMap = new ListMap(); return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_Message1");
iconManager = WidgetInfoConfig.getInstance().getIconManager(); }
bg = new ButtonGroup();
Object[] names = iconManager.getIconNames(); private void initIcons() {
Object name = null; iconButtonMap = new ListMap();
for (int i = 0; i < names.length; i++) { iconManager = WidgetInfoConfig.getInstance().getIconManager();
name = names[i]; bg = new ButtonGroup();
if (name == null || !(name instanceof String)) { Object[] names = iconManager.getIconNames();
continue; Object name = null;
} for (int i = 0; i < names.length; i++) {
// carl:默认选第一个 name = names[i];
if (this.selectedIconName == null) { if (name == null || !(name instanceof String)) {
this.selectedIconName = (String)name; continue;
} }
IconButton iconButton = new IconButton((String)name); // carl:默认选第一个
iconButtonMap.put(name, iconButton); if (this.selectedIconName == null) {
iconPane.add(iconButton); this.selectedIconName = (String) name;
bg.add(iconButton); }
} IconButton iconButton = new IconButton((String) name);
} iconButtonMap.put(name, iconButton);
iconPane.add(iconButton);
private void initAddButton(JPanel buttonPane) { bg.add(iconButton);
UIButton addButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Add")); }
addButton.setPreferredSize(new Dimension(80, 25)); }
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { private void initAddButton(JPanel buttonPane) {
final EditIconDialog add = new EditIconDialog(); UIButton addButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Add"));
add.populate(null); addButton.setPreferredSize(new Dimension(80, 25));
add.showWindow(SwingUtilities.getWindowAncestor(CustomIconPane.this), new DialogActionAdapter() { addButton.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
public void doOk() { final EditIconDialog add = new EditIconDialog();
Icon icon = add.update(); add.populate(null);
if (iconManager.addIcon(icon, false)) { add.showWindow(SwingUtilities.getWindowAncestor(CustomIconPane.this), new DialogActionAdapter() {
IconButton iconButton = null;//初始化 @Override
public void doOk() {
addIcon(icon, iconButton); Icon icon = add.update();
if (iconManager.addIcon(icon, false)) {
}else { IconButton iconButton = null;//初始化
// add failed
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_Message2"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), JOptionPane.WARNING_MESSAGE); addIcon(icon, iconButton);
}
} } else {
// add failed
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_Message2"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), JOptionPane.WARNING_MESSAGE);
}
}
}).setVisible(true); }).setVisible(true);
} }
}); });
buttonPane.add(addButton); buttonPane.add(addButton);
} }
private void initRemoveButton(JPanel buttonPane) { private void initRemoveButton(JPanel buttonPane) {
removeButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Remove")); removeButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Remove"));
removeButton.setPreferredSize(new Dimension(80, 25)); removeButton.setPreferredSize(new Dimension(80, 25));
removeButton.addActionListener(new ActionListener() { removeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (iconManager.isSystemIcon(selectedIconName)) { if (iconManager.isSystemIcon(selectedIconName)) {
return; return;
} }
if (iconManager.removeIcon(selectedIconName)) { if (iconManager.removeIcon(selectedIconName)) {
IconButton iconButton = (IconButton)iconButtonMap.get(selectedIconName); IconButton iconButton = (IconButton) iconButtonMap.get(selectedIconName);
iconPane.remove(iconButton); iconPane.remove(iconButton);
iconButtonMap.remove(selectedIconName); iconButtonMap.remove(selectedIconName);
bg.remove(iconButton); bg.remove(iconButton);
selectedIconName = ((IconButton)iconButtonMap.getByIndex(0)).iconName; selectedIconName = ((IconButton) iconButtonMap.getByIndex(0)).iconName;
refreshIconPane(false); refreshIconPane(false);
CustomIconPane.this.validate(); CustomIconPane.this.validate();
CustomIconPane.this.repaint(); CustomIconPane.this.repaint();
} else { } else {
// remove failed // remove failed
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_Message2"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_Message2"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"),
JOptionPane.WARNING_MESSAGE); JOptionPane.WARNING_MESSAGE);
} }
} }
}); });
buttonPane.add(removeButton); buttonPane.add(removeButton);
} }
private void initEditButton(JPanel buttonPane) { private void initEditButton(JPanel buttonPane) {
editButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Edit")); editButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Edit"));
editButton.setPreferredSize(new Dimension(80, 25)); editButton.setPreferredSize(new Dimension(80, 25));
editButton.addActionListener(new ActionListener() { editButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (iconManager.isSystemIcon(selectedIconName)) { if (iconManager.isSystemIcon(selectedIconName)) {
return; return;
} }
Icon oldIcon = null; Icon oldIcon = null;
try { try {
oldIcon= iconManager.getIcon(selectedIconName); oldIcon = iconManager.getIcon(selectedIconName);
} catch (CloneNotSupportedException e1) { } catch (CloneNotSupportedException e1) {
// do nothing // do nothing
} }
if (oldIcon == null) { if (oldIcon == null) {
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
"Error", "Error",
"Error", "Error",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
} }
final EditIconDialog edit = new EditIconDialog(); final EditIconDialog edit = new EditIconDialog();
edit.populate(oldIcon); edit.populate(oldIcon);
edit.showWindow(DesignerContext.getDesignerFrame(), new IconDialogActionListener(oldIcon) { edit.showWindow(DesignerContext.getDesignerFrame(), new IconDialogActionListener(oldIcon) {
@Override @Override
public void doOk() { public void doOk() {
iconManager.removeIcon(oldIcon.getName()); iconManager.removeIcon(oldIcon.getName());
Icon icon = edit.update(); Icon icon = edit.update();
if (iconManager.addIcon(icon, false)) { if (iconManager.addIcon(icon, false)) {
IconButton iconButton = (IconButton)iconButtonMap.get(oldIcon.getName()); IconButton iconButton = (IconButton) iconButtonMap.get(oldIcon.getName());
iconPane.remove(iconButton); iconPane.remove(iconButton);
bg.remove(iconButton); bg.remove(iconButton);
addIcon(icon, iconButton); addIcon(icon, iconButton);
} else { } else {
// 失败了再弄回去 // 失败了再弄回去
iconManager.addIcon(oldIcon, true); iconManager.addIcon(oldIcon, true);
// edit failed // edit failed
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_Message2"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), JOptionPane.WARNING_MESSAGE); JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_Message2"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), JOptionPane.WARNING_MESSAGE);
} }
} }
}).setVisible(true); }).setVisible(true);
} }
}); });
buttonPane.add(editButton); buttonPane.add(editButton);
} }
private void updateButtonPane() { private void updateButtonPane() {
if (editButton == null || removeButton == null){ if (editButton == null || removeButton == null) {
return; return;
} }
if (iconManager.isSystemIcon(selectedIconName)) { if (iconManager.isSystemIcon(selectedIconName)) {
editButton.setEnabled(false); editButton.setEnabled(false);
removeButton.setEnabled(false); removeButton.setEnabled(false);
} else { } else {
editButton.setEnabled(true); editButton.setEnabled(true);
removeButton.setEnabled(true); removeButton.setEnabled(true);
} }
} }
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_SelectIcon"); return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_SelectIcon");
} }
/** /**
* 添加按钮 * 添加按钮
* *
* @param icon 图标 * @param icon 图标
* @param iconButton 按钮 * @param iconButton 按钮
*/ */
public void addIcon(Icon icon,IconButton iconButton){ public void addIcon(Icon icon, IconButton iconButton) {
selectedIconName = icon.getName(); selectedIconName = icon.getName();
iconButton = new IconButton(icon.getName()); iconButton = new IconButton(icon.getName());
iconButtonMap.put(icon.getName(), iconButton); iconButtonMap.put(icon.getName(), iconButton);
iconPane.add(iconButton); iconPane.add(iconButton);
bg.add(iconButton); bg.add(iconButton);
refreshIconPane(true); refreshIconPane(true);
CustomIconPane.this.validate(); CustomIconPane.this.validate();
CustomIconPane.this.repaint(); CustomIconPane.this.repaint();
} }
public static class IconDialogActionListener extends DialogActionAdapter { public static class IconDialogActionListener extends DialogActionAdapter {
protected Icon oldIcon; protected Icon oldIcon;
public IconDialogActionListener(Icon oldIcon) { public IconDialogActionListener(Icon oldIcon) {
this.oldIcon = oldIcon; this.oldIcon = oldIcon;
} }
} }
public void populate(String iconName) { public void populate(String iconName) {
if (iconName == null) { if (iconName == null) {
return; return;
} }
this.selectedIconName = iconName; this.selectedIconName = iconName;
updateButtonPane(); updateButtonPane();
this.repaint(); this.repaint();
} }
public String update() { public String update() {
//把图标信息入库 //把图标信息入库
Configurations.update(new WorkerFacade(WidgetInfoConfig.class) { Configurations.update(new WorkerFacade(WidgetInfoConfig.class) {
@Override @Override
public void run() { public void run() {
WidgetInfoConfig.getInstance().setIconManager(IconManager.getIconManager()); WidgetInfoConfig.getInstance().setIconManager(IconManager.getIconManager());
} }
}); });
return selectedIconName;
} return selectedIconName;
}
// 不知道怎么动态布局,就这么傻傻的调一下大小
private void refreshIconPane(boolean down) { // 不知道怎么动态布局,就这么傻傻的调一下大小
iconPane.setPreferredSize(new Dimension(THE_WIDTH, (iconButtonMap.size() / HORIZONTAL_COUNT + 1) * HEIGHT_PER + GAP)); private void refreshIconPane(boolean down) {
UIScrollBar jsBar = jsPane.createVerticalScrollBar(); iconPane.setPreferredSize(new Dimension(THE_WIDTH, (iconButtonMap.size() / HORIZONTAL_COUNT + 1) * HEIGHT_PER + GAP));
try { UIScrollBar jsBar = jsPane.createVerticalScrollBar();
if (down) { try {
// 将滚动条滚到最后 if (down) {
jsBar.setValue(jsBar.getMaximum() - jsBar.getVisibleAmount()); // 将滚动条滚到最后
} else { jsBar.setValue(jsBar.getMaximum() - jsBar.getVisibleAmount());
jsBar.setValue(0); } else {
} jsBar.setValue(0);
} catch (RuntimeException re) { }
} catch (RuntimeException re) {
return; return;
} }
updateButtonPane(); updateButtonPane();
} }
private class IconButton extends JToggleButton implements ActionListener{ private class IconButton extends JToggleButton implements ActionListener {
private String iconName; private String iconName;
private Image iconImage = null; private Image iconImage = null;
private static final int ICON_BUTTON_SIZE = 24; private static final int ICON_BUTTON_SIZE = 24;
private static final int ICON_X = 4; private static final int ICON_X = 4;
private static final int ICON_Y = 4; private static final int ICON_Y = 4;
public IconButton(String name) {
this.iconName = name; public IconButton(String name) {
this.addActionListener(this); this.iconName = name;
this.addActionListener(this);
this.setCursor(new Cursor(Cursor.HAND_CURSOR)); this.setCursor(new Cursor(Cursor.HAND_CURSOR));
this.setBorder(null); this.setBorder(null);
this.iconImage = WidgetInfoConfig.getInstance().getIconManager().getIconImage(name); this.iconImage = WidgetInfoConfig.getInstance().getIconManager().getIconImage(name);
this.setToolTipText(iconName); this.setToolTipText(iconName);
} }
@Override @Override
public void updateUI() { public void updateUI() {
setUI(new BasicButtonUI(){ setUI(new BasicButtonUI() {
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
super.paint(g, c); super.paint(g, c);
} }
}); });
} }
@Override @Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
// carl:这里缩放显示 16 × 16 // carl:这里缩放显示 16 × 16
if (iconImage != null) { if (iconImage != null) {
g2d.drawImage(iconImage, ICON_X, ICON_Y, IconManager.DEFAULT_ICONWIDTH, IconManager.DEFAULT_ICONHEIGHT, null); g2d.drawImage(iconImage, ICON_X, ICON_Y, IconManager.DEFAULT_ICONWIDTH, IconManager.DEFAULT_ICONHEIGHT, null);
} }
if (this.iconName != null && ComparatorUtils.equals(this.iconName, selectedIconName)) { if (this.iconName != null && ComparatorUtils.equals(this.iconName, selectedIconName)) {
g2d.setPaint(Color.RED); g2d.setPaint(Color.RED);
} else { } else {
g2d.setPaint(Color.LIGHT_GRAY); g2d.setPaint(Color.LIGHT_GRAY);
} }
GraphHelper.draw(g2d, new Rectangle2D.Double(0, 0, IconManager.DEFAULT_ICONWIDTH + 7, GraphHelper.draw(g2d, new Rectangle2D.Double(0, 0, IconManager.DEFAULT_ICONWIDTH + 7,
IconManager.DEFAULT_ICONHEIGHT + 7), Constants.LINE_THICK); IconManager.DEFAULT_ICONHEIGHT + 7), Constants.LINE_THICK);
} }
@Override @Override
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
return new Dimension(ICON_BUTTON_SIZE, ICON_BUTTON_SIZE); return new Dimension(ICON_BUTTON_SIZE, ICON_BUTTON_SIZE);
} }
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
CustomIconPane.this.selectedIconName = iconName; CustomIconPane.this.selectedIconName = iconName;
fireChagneListener(); fireChagneListener();
updateButtonPane(); updateButtonPane();
CustomIconPane.this.repaint();// repaint CustomIconPane.this.repaint();// repaint
} }
@Override @Override
public void addChangeListener(ChangeListener changeListener) { public void addChangeListener(ChangeListener changeListener) {
this.changeListener = changeListener; this.changeListener = changeListener;
} }
@ -377,18 +381,18 @@ public class CustomIconPane extends BasicPane {
this.changeListener.stateChanged(evt); this.changeListener.stateChanged(evt);
} }
} }
} }
private static class EditIconDialog extends BasicPane { private static class EditIconDialog extends BasicPane {
private UITextField nameTextField; private UITextField nameTextField;
private UILabel showImageLabel; private UILabel showImageLabel;
private Image iconImage = null; private Image iconImage = null;
private String oldName = null; private String oldName = null;
protected EditIconDialog() { protected EditIconDialog() {
init(); init();
} }
private void init() { private void init() {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
@ -402,16 +406,17 @@ public class CustomIconPane extends BasicPane {
nameTextField = new UITextField(20); nameTextField = new UITextField(20);
browseButton.addActionListener(new ActionListener() { browseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
onBrowseButtonClicked(); onBrowseButtonClicked();
} }
}); });
// 焦点丢失时看看名称是否已经存在 // 焦点丢失时看看名称是否已经存在
nameTextField.addFocusListener(new FocusListener() { nameTextField.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) { public void focusGained(FocusEvent e) {
// do nothing // do nothing
} }
public void focusLost(FocusEvent e) { public void focusLost(FocusEvent e) {
if (oldName != null && ComparatorUtils.equals(oldName, nameTextField.getText())) { if (oldName != null && ComparatorUtils.equals(oldName, nameTextField.getText())) {
return; return;
@ -428,7 +433,7 @@ public class CustomIconPane extends BasicPane {
JPanel imagePane = new JPanel(); JPanel imagePane = new JPanel();
imagePane.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 0)); imagePane.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 0));
showImageLabel = new UILabel(); showImageLabel = new UILabel();
showImageLabel.setPreferredSize(new Dimension(20,20)); showImageLabel.setPreferredSize(new Dimension(20, 20));
imagePane.add(showImageLabel); imagePane.add(showImageLabel);
imagePane.add(browseButton); imagePane.add(browseButton);
Component[][] components = {{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Name") + ":"), nameTextField}, {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Icon") + ":"), imagePane}}; Component[][] components = {{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Name") + ":"), nameTextField}, {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Icon") + ":"), imagePane}};
@ -448,7 +453,7 @@ public class CustomIconPane extends BasicPane {
// 将图片转化到16 × 16大小 // 将图片转化到16 × 16大小
Image image = BaseUtils.readImage(path); Image image = BaseUtils.readImage(path);
BufferedImage bufferedImage = CoreGraphHelper.createBufferedImage(IconManager.DEFAULT_ICONWIDTH, BufferedImage bufferedImage = CoreGraphHelper.createBufferedImage(IconManager.DEFAULT_ICONWIDTH,
IconManager.DEFAULT_ICONHEIGHT, BufferedImage.TYPE_INT_ARGB); IconManager.DEFAULT_ICONHEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bufferedImage.createGraphics(); Graphics2D g2d = bufferedImage.createGraphics();
g2d.drawImage(image, 0, 0, IconManager.DEFAULT_ICONWIDTH, IconManager.DEFAULT_ICONHEIGHT, null); g2d.drawImage(image, 0, 0, IconManager.DEFAULT_ICONWIDTH, IconManager.DEFAULT_ICONHEIGHT, null);
bufferedImage.flush(); bufferedImage.flush();
@ -461,29 +466,29 @@ IconManager.DEFAULT_ICONHEIGHT, BufferedImage.TYPE_INT_ARGB);
} }
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style_Add_Icon"); return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style_Add_Icon");
} }
// 用户自定义的只有name 和 imgae两属性, path不要去管 // 用户自定义的只有name 和 imgae两属性, path不要去管
public void populate(Icon icon) { public void populate(Icon icon) {
if (icon == null) { if (icon == null) {
return; return;
} }
oldName = icon.getName(); oldName = icon.getName();
nameTextField.setText(icon.getName()); nameTextField.setText(icon.getName());
if (icon.getImage() != null) { if (icon.getImage() != null) {
showImageLabel.setIcon(new ImageIcon(icon.getImage())); showImageLabel.setIcon(new ImageIcon(icon.getImage()));
} }
iconImage = icon.getImage(); iconImage = icon.getImage();
} }
public Icon update() { public Icon update() {
// 有一个是空,都返回null,反正不会添加的 // 有一个是空,都返回null,反正不会添加的
if (StringUtils.isBlank(nameTextField.getText()) || iconImage == null) { if (StringUtils.isBlank(nameTextField.getText()) || iconImage == null) {
return null; return null;
} }
return new Icon(nameTextField.getText(), iconImage); return new Icon(nameTextField.getText(), iconImage);
} }
} }
} }

Loading…
Cancel
Save