📄 dialogtoexcel.java
字号:
package net.aetherial.gis.surface;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;
import java.util.Vector;
import java.io.*;
import net.aetherial.gis.excel.*;
public class DialogToExcel extends JDialog {
JPanel panel1 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JPanel jPanel1 = new JPanel();
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
Vector v = new Vector();
JButton jButton2 = new JButton();
public DialogToExcel(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
pack();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
public DialogToExcel() {
this(null, "", false);
this.addTracks();
this.setSize(500,500);
}
public void addTracks(){
final int height = 30;
JCheckBox jTracksCheckBox = null;
int[] pos = ItemValue.getPosition("track");
if(pos ==null){
this.jButton2.setEnabled(false);
}else{
if (pos.length > 0) {
for (int i = 0; i < pos.length; i++) {
jTracksCheckBox = new JCheckBox();
jTracksCheckBox.setText(ItemValue.getTracksName(i));
jPanel1.add(jTracksCheckBox,
new XYConstraints(30 + this.widthSet(i), (40 + heightSet(i,height)), -1, -1));
jTracksCheckBox.addItemListener(new
DialogToExcel_jCheckBox_itemAdapter(this));
jTracksCheckBox.setActionCommand(i + "");
jTracksCheckBox = null;
}
}
}
}
private int widthSet(int i){
return (i%3)*150;
}
private int heightSet(int i,int height){
return ((int)(i/3))*height;
}
private void jbInit() throws Exception {
Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(
(screenDim.width - 500) / 2,
(screenDim.height - 500) / 2
);
this.setTitle("选择需要生成Excel文件的航迹");
//this.addWindowFocusListener(new DialogToFront_this_windowFocusAdapter(this));
panel1.setLayout(borderLayout1);
jPanel1.setLayout(xYLayout1);
jPanel1.setOpaque(true);
jLabel1.setText("选择需要生成Excel文件的航迹:");
jButton2.setText("生成Excel文件");
jButton2.addActionListener(new DialogToExcel_jButton2_actionAdapter(this));
getContentPane().add(panel1);
panel1.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jPanel1, null);
jPanel1.add(jLabel1, new XYConstraints(11, 8, 202, 24));
jPanel1.add(jButton2, new XYConstraints(217, 11, 101, -1));
}
void jCheckBox1_itemStateChanged(ItemEvent e) {
//e.DESELECTED;
// System.out.println((JCheckBox)e.getSource()+""+((JCheckBox)e.getSource()).isSelected());
int pos = Integer.parseInt(((JCheckBox)e.getSource()).getActionCommand());
if(((JCheckBox)e.getSource()).isSelected()){
v.add(pos + "");
}else{
v.remove(pos + "");
}
}
void jButton2_actionPerformed(ActionEvent e) {
JFileChooser fileDialog = new JFileChooser();
ExcelFilter filter = new ExcelFilter();
fileDialog.setFileFilter(filter);
if(!(ItemValue.fileChoosePath.equals(""))){
fileDialog.setCurrentDirectory(new File(ItemValue.fileChoosePath));
}
int result = fileDialog.showSaveDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
File f = fileDialog.getSelectedFile();
new CreateExcelLast(f,this,v).start();
}
}
}
class DialogToExcel_jCheckBox_itemAdapter implements java.awt.event.ItemListener {
DialogToExcel adaptee;
DialogToExcel_jCheckBox_itemAdapter(DialogToExcel adaptee) {
this.adaptee = adaptee;
}
public void itemStateChanged(ItemEvent e) {
adaptee.jCheckBox1_itemStateChanged(e);
}
}
class DialogToExcel_jButton2_actionAdapter implements java.awt.event.ActionListener {
DialogToExcel adaptee;
DialogToExcel_jButton2_actionAdapter(DialogToExcel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -