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;
/**
*
* carl自定义Icon编辑
*
*/
public class CustomIconPane extends BasicPane {
private String selectedIconName = null;
@ -57,7 +55,6 @@ public class CustomIconPane extends BasicPane {
private UIButton editButton;
private static final int THE_WIDTH = 180;
private static final int HORIZONTAL_COUNT = 6;
private static final int HEIGHT_PER = 29;
@ -83,11 +80,11 @@ public class CustomIconPane extends BasicPane {
refreshIconPane(false);
jsPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
jsPane.setPreferredSize(new Dimension(200,180));
jsPane.setPreferredSize(new Dimension(200, 180));
noNamePane.add(jsPane);
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);
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() {
iconButtonMap = new ListMap();
iconManager = WidgetInfoConfig.getInstance().getIconManager();
@ -118,9 +120,9 @@ public class CustomIconPane extends BasicPane {
}
// carl:默认选第一个
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);
iconPane.add(iconButton);
bg.add(iconButton);
@ -143,7 +145,7 @@ public class CustomIconPane extends BasicPane {
addIcon(icon, iconButton);
}else {
} 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);
}
@ -164,11 +166,11 @@ public class CustomIconPane extends BasicPane {
return;
}
if (iconManager.removeIcon(selectedIconName)) {
IconButton iconButton = (IconButton)iconButtonMap.get(selectedIconName);
IconButton iconButton = (IconButton) iconButtonMap.get(selectedIconName);
iconPane.remove(iconButton);
iconButtonMap.remove(selectedIconName);
bg.remove(iconButton);
selectedIconName = ((IconButton)iconButtonMap.getByIndex(0)).iconName;
selectedIconName = ((IconButton) iconButtonMap.getByIndex(0)).iconName;
refreshIconPane(false);
CustomIconPane.this.validate();
CustomIconPane.this.repaint();
@ -194,7 +196,7 @@ public class CustomIconPane extends BasicPane {
}
Icon oldIcon = null;
try {
oldIcon= iconManager.getIcon(selectedIconName);
oldIcon = iconManager.getIcon(selectedIconName);
} catch (CloneNotSupportedException e1) {
// do nothing
}
@ -213,7 +215,7 @@ public class CustomIconPane extends BasicPane {
iconManager.removeIcon(oldIcon.getName());
Icon icon = edit.update();
if (iconManager.addIcon(icon, false)) {
IconButton iconButton = (IconButton)iconButtonMap.get(oldIcon.getName());
IconButton iconButton = (IconButton) iconButtonMap.get(oldIcon.getName());
iconPane.remove(iconButton);
bg.remove(iconButton);
@ -233,7 +235,7 @@ public class CustomIconPane extends BasicPane {
}
private void updateButtonPane() {
if (editButton == null || removeButton == null){
if (editButton == null || removeButton == null) {
return;
}
if (iconManager.isSystemIcon(selectedIconName)) {
@ -256,7 +258,7 @@ public class CustomIconPane extends BasicPane {
* @param icon 图标
* @param iconButton 按钮
*/
public void addIcon(Icon icon,IconButton iconButton){
public void addIcon(Icon icon, IconButton iconButton) {
selectedIconName = icon.getName();
iconButton = new IconButton(icon.getName());
iconButtonMap.put(icon.getName(), iconButton);
@ -292,6 +294,7 @@ public class CustomIconPane extends BasicPane {
WidgetInfoConfig.getInstance().setIconManager(IconManager.getIconManager());
}
});
return selectedIconName;
}
@ -312,12 +315,13 @@ public class CustomIconPane extends BasicPane {
updateButtonPane();
}
private class IconButton extends JToggleButton implements ActionListener{
private class IconButton extends JToggleButton implements ActionListener {
private String iconName;
private Image iconImage = null;
private static final int ICON_BUTTON_SIZE = 24;
private static final int ICON_X = 4;
private static final int ICON_Y = 4;
public IconButton(String name) {
this.iconName = name;
this.addActionListener(this);
@ -329,7 +333,7 @@ public class CustomIconPane extends BasicPane {
@Override
public void updateUI() {
setUI(new BasicButtonUI(){
setUI(new BasicButtonUI() {
public void paint(Graphics g, JComponent c) {
super.paint(g, c);
}
@ -412,6 +416,7 @@ public class CustomIconPane extends BasicPane {
public void focusGained(FocusEvent e) {
// do nothing
}
public void focusLost(FocusEvent e) {
if (oldName != null && ComparatorUtils.equals(oldName, nameTextField.getText())) {
return;
@ -428,7 +433,7 @@ public class CustomIconPane extends BasicPane {
JPanel imagePane = new JPanel();
imagePane.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 0));
showImageLabel = new UILabel();
showImageLabel.setPreferredSize(new Dimension(20,20));
showImageLabel.setPreferredSize(new Dimension(20, 20));
imagePane.add(showImageLabel);
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}};
@ -448,7 +453,7 @@ public class CustomIconPane extends BasicPane {
// 将图片转化到16 × 16大小
Image image = BaseUtils.readImage(path);
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();
g2d.drawImage(image, 0, 0, IconManager.DEFAULT_ICONWIDTH, IconManager.DEFAULT_ICONHEIGHT, null);
bufferedImage.flush();

Loading…
Cancel
Save