Browse Source

1

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

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

@ -41,9 +41,7 @@ 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;
@ -57,7 +55,6 @@ public class CustomIconPane extends BasicPane {
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;
@ -83,11 +80,11 @@ public class CustomIconPane extends BasicPane {
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(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_Message1")); des.setText(createDescriptionText());
centerPane.add(des, BorderLayout.SOUTH); centerPane.add(des, BorderLayout.SOUTH);
this.add(centerPane, BorderLayout.CENTER); this.add(centerPane, BorderLayout.CENTER);
@ -105,6 +102,11 @@ public class CustomIconPane extends BasicPane {
} }
protected String createDescriptionText(){
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_Message1");
}
private void initIcons() { private void initIcons() {
iconButtonMap = new ListMap(); iconButtonMap = new ListMap();
iconManager = WidgetInfoConfig.getInstance().getIconManager(); iconManager = WidgetInfoConfig.getInstance().getIconManager();
@ -118,9 +120,9 @@ public class CustomIconPane extends BasicPane {
} }
// carl:默认选第一个 // carl:默认选第一个
if (this.selectedIconName == null) { if (this.selectedIconName == null) {
this.selectedIconName = (String)name; this.selectedIconName = (String) name;
} }
IconButton iconButton = new IconButton((String)name); IconButton iconButton = new IconButton((String) name);
iconButtonMap.put(name, iconButton); iconButtonMap.put(name, iconButton);
iconPane.add(iconButton); iconPane.add(iconButton);
bg.add(iconButton); bg.add(iconButton);
@ -143,7 +145,7 @@ public class CustomIconPane extends BasicPane {
addIcon(icon, iconButton); addIcon(icon, iconButton);
}else { } else {
// add failed // 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); 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);
} }
@ -164,11 +166,11 @@ public class CustomIconPane extends BasicPane {
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();
@ -194,7 +196,7 @@ public class CustomIconPane extends BasicPane {
} }
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
} }
@ -213,7 +215,7 @@ public class CustomIconPane extends BasicPane {
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);
@ -233,7 +235,7 @@ public class CustomIconPane extends BasicPane {
} }
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)) {
@ -256,7 +258,7 @@ public class CustomIconPane extends BasicPane {
* @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);
@ -292,6 +294,7 @@ public class CustomIconPane extends BasicPane {
WidgetInfoConfig.getInstance().setIconManager(IconManager.getIconManager()); WidgetInfoConfig.getInstance().setIconManager(IconManager.getIconManager());
} }
}); });
return selectedIconName; return selectedIconName;
} }
@ -312,12 +315,13 @@ public class CustomIconPane extends BasicPane {
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) { public IconButton(String name) {
this.iconName = name; this.iconName = name;
this.addActionListener(this); this.addActionListener(this);
@ -329,7 +333,7 @@ public class CustomIconPane extends BasicPane {
@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);
} }
@ -412,6 +416,7 @@ public class CustomIconPane extends BasicPane {
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();

Loading…
Cancel
Save