com.scudata.ide.spl.chart.DialogPlotEdit Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of esproc Show documentation
Show all versions of esproc Show documentation
SPL(Structured Process Language) A programming language specially for structured data computing.
package com.scudata.ide.spl.chart;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.scudata.chart.edit.*;
import com.scudata.common.MessageManager;
import com.scudata.common.StringUtils;
import com.scudata.ide.common.*;
import com.scudata.ide.common.swing.*;
import com.scudata.ide.spl.resources.*;
import java.util.*;
/**
* ͼ?β????༭?Ի???
*
* @author Joancy
*
*/
public class DialogPlotEdit extends JDialog implements ActionListener {
private static final long serialVersionUID = 1L;
private int m_option = JOptionPane.CLOSED_OPTION;
JButton okbtn = new JButton();
JButton cancelbtn = new JButton();
JButton btExpandAll = new JButton();
JButton btCollapseAll = new JButton();
private JComboBoxEx elmList;
private JComboBoxEx glist;
private String plotFunc;
private ParamInputPanel propPanel;
private ElementInfo elmInfo;
private String graphicsName;
MessageManager mm = ChartMessage.get();
/**
* ????һ????ͼ?༭?Ի???
* @param owner ??????
* @param plotFunc plot??????
* @param graphics spl?ļ??ж???õ????л???????
*/
public DialogPlotEdit(Frame owner, String plotFunc, java.util.List graphics) {
super(owner);
this.plotFunc = plotFunc;
this.setTitle(mm.getMessage("title.plotedit"));
this.setModal(true);
this.setSize(800, 520);
this.setResizable(true);
btExpandAll.setText(mm.getMessage("button.expandAll"));
btExpandAll.setMargin(new Insets(2, 10, 2, 10));
btExpandAll.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
propPanel.expandAll();
}
});
btCollapseAll.setText(mm.getMessage("button.collapseAll"));
btCollapseAll.setMargin(new Insets(2, 10, 2, 10));
btCollapseAll.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
propPanel.collapseAll();
}
});
okbtn.setText(mm.getMessage("button.ok"));
okbtn.setPreferredSize(new Dimension(70, 25));
okbtn.setMargin(new Insets(2, 10, 2, 10));
okbtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
okbtn_actionPerformed(e);
}
});
cancelbtn.setText(mm.getMessage("button.cancel"));
cancelbtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
cancelbtn_actionPerformed(e);
}
});
cancelbtn.setPreferredSize(new Dimension(70, 25));
cancelbtn.setMargin(new Insets(2, 10, 2, 10));
okbtn.setMnemonic('O');
cancelbtn.setMnemonic('C');
JPanel panel = new JPanel(new GridBagLayout());
panel.add(btExpandAll,GM.getGBC(1, 1));
panel.add(btCollapseAll,GM.getGBC(1, 2));
panel.add(new JLabel(" "),GM.getGBC(1, 3,true));
panel.add(okbtn,GM.getGBC(1, 4));
panel.add(cancelbtn,GM.getGBC(1, 5));
Container pane = this.getContentPane();
pane.setLayout(new BorderLayout());
pane.add(panel, BorderLayout.SOUTH);
JPanel cmdPanel = new JPanel();
cmdPanel.setLayout(new GridBagLayout());
cmdPanel.add(new JLabel(mm.getMessage("label.selG")),
GM.getGBC(1, 1));
glist = new JComboBoxEx();
Vector gnames = new Vector();
Vector gtitles = new Vector();
for (int i = 0; i < graphics.size(); i++) {
gnames.add(graphics.get(i));
gtitles.add(graphics.get(i));
}
glist.x_setData(gnames, gtitles);
glist.setEditable(true);
cmdPanel.add(glist, GM.getGBC(1, 2, true));
cmdPanel.add(new JLabel(mm.getMessage("label.selTy")),
GM.getGBC(1, 3)); // "??ѡ??ͼԪ"
elmList = new JComboBoxEx();
Vector names = new Vector();
Vector titles = new Vector();
ArrayList flList = ElementLib.getElementTitleList();
ArrayList> list = ElementLib.getElementInfoList();
for (int k = 0; k < flList.size(); k++) {
titles.add(flList.get(k));
names.add("");
ArrayList list1 = (ArrayList) list.get(k);
for (int i = 0; i < list1.size(); i++) {
ElementInfo ei = (ElementInfo) list1.get(i);
// ????ӳ???ᣬ??????֧?ֱ༭
if(ei.getName().equals("MapAxis")) continue;
names.add(ei.getName());
titles.add(" " + ei.getTitle());
}
}
elmList.x_setData(names, titles);
GridBagConstraints gbc = GM.getGBC(1, 4, true);
cmdPanel.add(elmList, gbc);
pane.add(cmdPanel, BorderLayout.NORTH);
propPanel = new ParamInputPanel(this);
pane.add(propPanel);
if (plotFunc == null)
plotFunc = "";
else
plotFunc = plotFunc.trim();
if (plotFunc.startsWith("="))
plotFunc = plotFunc.substring(1);
int pos = plotFunc.indexOf(".");
if (pos > 0) {
graphicsName = plotFunc.substring(0, pos);
plotFunc = plotFunc.substring(pos + 1);
}
if (plotFunc.startsWith("plot(")) {
elmInfo = new ElementInfo();
elmInfo.setPlotString(plotFunc);
dispDetail();
glist.x_setSelectedCodeItem(graphicsName);
elmList.x_setSelectedCodeItem(elmInfo.getName());
glist.setEnabled(false);
elmList.setEnabled(false);
} else {
glist.addActionListener(this);
elmList.addActionListener(this);
elmList.setSelectedIndex(1);
graphicsName = (String) glist.x_getSelectedItem();
}
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
closeDialog();
}
});
GM.setDialogDefaultButton(this, okbtn, cancelbtn);
}
/**
* ??ȡ???ڷ??ص?ѡ??
* @return ѡ??
*/
public int getOption() {
return m_option;
}
/**
* ??ʾ??????ϸ??Ϣ
*/
public void dispDetail() {
propPanel.setElementInfo(elmInfo);
}
private void closeDialog(){
GM.setWindowDimension(this);
dispose();
}
void okbtn_actionPerformed(ActionEvent e) {
if( !StringUtils.isValidString( graphicsName ) ) {
String message = mm.getMessage("DialogPlotEdit.emptyCanvas");
JOptionPane.showMessageDialog(this, message);
return;
}
propPanel.getParamTable().acceptText();
plotFunc = elmInfo.toPlotString(propPanel.infoList);
m_option = JOptionPane.OK_OPTION;
closeDialog();
}
void cancelbtn_actionPerformed(ActionEvent e) {
m_option = JOptionPane.CANCEL_OPTION;
closeDialog();
}
public String getPlotFunction() {
return graphicsName + "." + plotFunc;
}
/**
* ???ڼ????¼?
*
* @param e ?¼?
*/
public void actionPerformed(ActionEvent e) {
Object o = e.getSource();
if (o.equals(glist)) {
graphicsName = (String) glist.x_getSelectedItem();
} else if (o.equals(elmList)) {
String elmName = (String) elmList.x_getSelectedItem();
if (elmName.length() == 0)
return;
elmInfo = ElementLib.getElementInfo(elmName);
dispDetail();
}
}
}