📄 templateform.java
字号:
//falsdfdsaf/fadfd/dfadf.xml
String tempStr = "";
int posStart,posEnd;
String sep = "";
if(System.getProperty("os.name").startsWith("Window")){
sep = "\\";
}
else if(System.getProperty("os.name").startsWith("Linux")){
sep = "/";
}
if(sep.length() > 0){
posEnd = file.getAbsolutePath().lastIndexOf(sep);
if(posEnd >= 0){
String str = file.getAbsolutePath().substring(0, posEnd);
int tmp = str.lastIndexOf(sep);
if(tmp >= 0)
tempStr = str.substring(tmp+1);
}
}
//System.out.println("tempStr="+tempStr);
//int posEnd = file.getAbsolutePath().lastIndexOf("/")
if(tempStr.length() > 0){
int index = file.getName().lastIndexOf(".");
System.out.println("name="+tempStr+",model="+file.getName().substring(0, index));
((JGroupPanel)FlowManager.getInstance().getGroupPanel().getGroupPanel().getMember(1, 0)).removeMember(tempStr, file.getName().substring(0, index));
}
((JGroupPanel)FlowManager.getInstance().getGroupPanel().getGroupPanel().getMember(1, 0)).expandGroup(tempStr);
file.delete();
}
JFileTree fileTree1 = new JFileTree(new JFileTree.TemplateFilter(), System.getProperty("user.dir")+"/"+TemplateFactory.TEMPLATE_PATH);
treeBox.setTree(fileTree1);
}
}
});
exitButton = new JButton("关 闭");
exitButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
dialog.dispose();
//System.out.println(treeBox.getSelectedItem().toString());
}
});
final JButton testButton = new JButton("测试");
testButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//dialog.dispose();
//System.out.println(treeBox.getSelectedItem().toString());
//System.out.println(((JFileTree)treeBox.getTree()).getSelectSubFile());
//System.out.println(testButton.getActionCommand());
}
});
JPanel createPanel = new JPanel(new BorderLayout());
createPanel.setBorder(new TitledBorder("创建模板库"));
Box createBox = Box.createHorizontalBox();
createBox.add(new JLabel("模板库名称"));
createBox.add(Box.createHorizontalStrut(3));
createBox.add(templateName);
createBox.add(Box.createHorizontalStrut(20));
createBox.add(addTemplateButton);
createPanel.add(createBox, BorderLayout.CENTER);
JPanel savePanel = new JPanel(new BorderLayout());
savePanel.setBorder(new TitledBorder("保存模板"));
Box saveBox = Box.createHorizontalBox();
saveBox.add(new JLabel("选择模板库"));
saveBox.add(treeBox);
saveBox.add(Box.createHorizontalStrut(20));
saveBox.add(new JLabel("模板名称"));
saveBox.add(fileName);
Box saveLayoutBox = Box.createVerticalBox();
JPanel savePan = new JPanel(new FlowLayout());
//savePan.add(modifyTemplateButton);
savePan.add(deleteTemplateButton);
savePan.add(saveTemplateButton);
saveLayoutBox.add(saveBox);
saveLayoutBox.add(Box.createVerticalStrut(3));
saveLayoutBox.add(savePan);
savePanel.add(saveLayoutBox, BorderLayout.CENTER);
JPanel exitPanel = new JPanel(new FlowLayout());
exitPanel.add(exitButton);
//exitPanel.add(testButton);
Box layoutBox = Box.createVerticalBox();
layoutBox.add(createPanel);
layoutBox.add(Box.createVerticalStrut(3));
layoutBox.add(savePanel);
layoutBox.add(Box.createVerticalStrut(3));
layoutBox.add(exitPanel);
dialog = new JDialog(FlowManager.getInstance(), "模板库编辑窗口", true);
dialog.getContentPane().setLayout(new BorderLayout());
dialog.setSize(450, 220);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
dialog.setLocation((screenSize.width-450)/2, (screenSize.height-220)/2);
dialog.setResizable(false);
dialog.addWindowListener(new WindowListener(){
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
dialog.dispose();
}
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}});
dialog.addKeyListener(new KeyListener(){
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
dialog.dispose();
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}});
dialog.add(layoutBox, BorderLayout.CENTER);
dialog.show();
}
private JTree getTemplate(){
JTree tree = new JTree();
return tree;
}
public void writeGraphString(String name) throws FileNotFoundException{
Object[] cells = graph.getSelectionCells();
//System.out.println("cells.length="+cells.length);
cells = graph.getDescendants(cells);
//System.out.println("cells.length="+cells.length);
Object[] cellss = filterStoneCell(cells);
//System.out.println("cellss.length="+cellss.length);
Vector vec = new Vector();
for(int i=0;i<cellss.length;i++){
vec.add(cellss[i]);
}
//System.out.println(cells);
XMLEncoder enc = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(name)));
enc.writeObject(vec);
enc.close();
}
private Object[] filterStoneCell(Object[] cells){
Object[] cellss = new Object[cells.length];
int pos = 0;
//System.out.println("cell.length="+cells.length);
for(int i=0;i<cells.length;i++){
//System.out.println("delete"+i+":"+cells[i]);
if(cells[i] instanceof DefaultGraphCell){
DefaultGraphCell cell = (DefaultGraphCell)cells[i];
Object obj = FlowGraphConstants.getTemplateType(cell.getAttributes());
if(obj != null){
if(obj.toString().equals(TemplateConstants.START_TEMPLATE) || obj.toString().equals(TemplateConstants.STOP_TEMPLATE)){
//System.out.println("loop"+i+":"+cells[i]);
i += 1;
continue;
}
}
}
//System.out.println("i="+i+","+cells[i]);
cellss[pos] = cells[i];
pos++;
}
return cellss;
}
public Vector readGraphFile(String s){
try {
XMLDecoder dec = new XMLDecoder(new BufferedInputStream(new FileInputStream(s)));
Vector vec = (Vector)dec.readObject();
dec.close();
return vec;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public void deleteDir(File dir) {
if (dir == null || !dir.exists() || !dir.isDirectory())
return; // 检查参数
for (File file : dir.listFiles()) {
if (file.isFile())
file.delete(); // 删除所有文件
else if (file.isDirectory())
deleteDir(file); // 递规的方式删除文件夹
}
dir.delete();// 删除目录本身
}
public static void main(String[] args){
//AssignForm.configureUI();
//new TemplateForm(new JGraph());
System.out.println(System.getProperties());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -