Browse Source

Merge pull request #632 in DESIGN/design from ~MATA.LI/design:feature/10.0 to feature/10.0

* commit '3d61cbadb7224789d40c02769af12490c8aa6e22':
  REPORT-12635
  REPORT-12635
  REPORT-12635
  REPORT-12635
  REPORT-12635
  REPORT-12635
  REPORT-12635
  REPORT-10536
research/10.0
Mata.Li 6 years ago
parent
commit
fb6ccfe0a5
  1. 43
      designer-base/src/main/java/com/fr/design/web/CustomIconPane.java

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

@ -24,6 +24,8 @@ import com.fr.stable.Constants;
import com.fr.stable.CoreGraphHelper;
import com.fr.stable.ListMap;
import com.fr.stable.StringUtils;
import com.fr.transaction.Configurations;
import com.fr.transaction.WorkerFacade;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
@ -39,9 +41,7 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
/**
*
* carl自定义Icon编辑
*
*/
public class CustomIconPane extends BasicPane {
private String selectedIconName = null;
@ -55,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;
@ -81,7 +80,7 @@ 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);
@ -116,9 +115,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);
@ -141,7 +140,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);
}
@ -162,11 +161,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();
@ -192,7 +191,7 @@ public class CustomIconPane extends BasicPane {
}
Icon oldIcon = null;
try {
oldIcon= iconManager.getIcon(selectedIconName);
oldIcon = iconManager.getIcon(selectedIconName);
} catch (CloneNotSupportedException e1) {
// do nothing
}
@ -211,7 +210,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);
@ -231,7 +230,7 @@ public class CustomIconPane extends BasicPane {
}
private void updateButtonPane() {
if (editButton == null || removeButton == null){
if (editButton == null || removeButton == null) {
return;
}
if (iconManager.isSystemIcon(selectedIconName)) {
@ -254,7 +253,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);
@ -283,6 +282,14 @@ public class CustomIconPane extends BasicPane {
}
public String update() {
//把图标信息入库
Configurations.update(new WorkerFacade(WidgetInfoConfig.class) {
@Override
public void run() {
WidgetInfoConfig.getInstance().setIconManager(IconManager.getIconManager());
}
});
return selectedIconName;
}
@ -303,12 +310,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);
@ -320,7 +328,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);
}
@ -403,6 +411,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;
@ -419,7 +428,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}};
@ -439,7 +448,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