JSD-4334 GIS地图集成
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

143 lines
5.0 KiB

package com.fr.plugin.shdcmap.ui;
import com.bulenkov.iconloader.util.Base64Converter;
import com.fr.base.BaseUtils;
import com.fr.base.Style;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.style.background.image.ImageFileChooser;
import com.fr.design.style.background.image.ImagePreviewPane;
import com.fr.design.utils.ImageUtils;
import com.fr.general.ImageWithSuffix;
import com.fr.general.xml.GeneralXMLTools;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
public class ImageChooserPane extends BasicBeanPane<ImageEntity> {
private ImageFileChooser imageChooser;
private ImagePreviewPane imagePreview;
private UIButton imagebtn;
private ImageEntity imageEntity;
private CustomStylePane stylePane;
public ImageChooserPane(){
this.setLayout(new BorderLayout());
imagePreview = new ImagePreviewPane();
imageEntity = new ImageEntity();
imagebtn = new UIButton("选择图标");
UILabel imageLab = new UILabel("点图标");
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
double[] columnSize = {p, f};
double[] rowSize = {p, p, p};
Component[][] acomponents = new Component[][]{
new Component[]{imageLab, imagebtn},
new Component[]{null, imagePreview}
};
JPanel panel = TableLayoutHelper.createTableLayoutPane(acomponents,rowSize,columnSize);
this.add(panel, BorderLayout.CENTER);
this.setVisible(true);
imageChooser = new ImageFileChooser();
imageChooser.setMultiSelectionEnabled(false);
initLiseners();
}
private void initLiseners() {
this.imagebtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int returnVal = imageChooser.showOpenDialog(ImageChooserPane.this);
if (returnVal != JFileChooser.CANCEL_OPTION) {
dealWithImageFile();
if (null != ImageChooserPane.this.stylePane) {
ImageChooserPane.this.stylePane.attributeChanged();
}
}
}
});
}
private void dealWithImageFile() {
final File selectedFile = imageChooser.getSelectedFile();
if (selectedFile != null && selectedFile.isFile()) {
BufferedImage image = BaseUtils.readImage(selectedFile.getPath());
if (null == image) {
return;
}
if (image.getWidth() > 300 || image.getHeight() > 300) {
JOptionPane.showMessageDialog(null,
"图片太大,请重新选择!大小不超过300*300,当前尺寸:" + image.getWidth() + "*" + image.getHeight(),
"信息提示",
JOptionPane.ERROR_MESSAGE);
return;
}
String type = ImageUtils.getImageType(selectedFile);
String iconBase64 = Base64Converter.encode(GeneralXMLTools.imageEncode(image, type));
if (null == this.imageEntity) {
this.imageEntity = new ImageEntity();
}
this.imageEntity.setImagestr(iconBase64);
this.imageEntity.setImagetype(type);
this.imageEntity.setWidth(image.getWidth());
this.imageEntity.setHeight(image.getHeight());
if (imagePreview != null) {
ImageWithSuffix imageWithSuffix = new ImageWithSuffix(image, type);
imagePreview.setImageStyle(Style.getInstance());
imagePreview.setImageWithSuffix(imageWithSuffix);
imagePreview.repaint();
}
}
}
@Override
public void populateBean(ImageEntity ob) {
if (null == ob || null == ob.getImagestr() || "".equals(ob.getImagestr())) {
this.imageEntity = new ImageEntity();
this.imagePreview.setImage(null);
this.imagePreview.repaint();
new ImagePreviewPane();
return;
}
this.imageEntity = ob;
BufferedImage image = (BufferedImage)GeneralXMLTools.imageDecode(Base64Converter.decode(ob.getImagestr().getBytes()));
if (imagePreview != null && null != image) {
ImageWithSuffix imageWithSuffix = new ImageWithSuffix(image, ob.getImagetype());
imagePreview.setImageStyle(Style.getInstance());
imagePreview.setImageWithSuffix(imageWithSuffix);
imagePreview.repaint();
}
}
@Override
public ImageEntity updateBean() {
return this.imageEntity;
}
@Override
protected String title4PopupWindow() {
return "点图标设置";
}
public void setStylePane(CustomStylePane stylePane) {
this.stylePane = stylePane;
}
}