Demo001



package com.huawei.crs.dataswitch.ui;


import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.Border;

public class DataSwitchUI
{
 
 public static List<String> getModulecodes(final String str)
 {
  List<String> codes = new ArrayList<String>();
  char[] charArray = str.toCharArray();
  
  StringBuffer code = new StringBuffer();
  boolean outCode = true;
  for(char ch : charArray)
  {
   if(outCode)
   {
    if((ch == 'M' || ch == 'U' || ch == 'R' || ch == 'm' || ch == 'u' || ch == 'r'))
    {
     outCode = false;
     code.append(ch);
    }
    else
    {
     
    }
    
   }else
   {
    if(ch == 'W' || ch == 'w' || ('0' <= ch && ch <= '9'))
    {
     code.append(ch);
    }else
    {
     outCode = true;
     codes.add(new String(code.toString()));
     code.delete(0, code.length());
     if((ch == 'M' || ch == 'U' || ch == 'R' || ch == 'm' || ch == 'u' || ch == 'r'))
     {
      outCode = false;
      code.append(ch);
     }
    }
   }
   
   
   
//      if(!inCode && (ch == 'M' || ch == 'U' || ch == 'R' || ch == 'm' || ch == 'u' || ch == 'r'))
//      {
//       inCode = true;
//       code.append(ch);
//      }
//      else if(inCode && (ch == 'W' || ch == 'w' || ('0' <= ch && ch <= '9')))
//      {
//       code.append(ch);
//      }
  }
  
  return codes;
 }
 
 public static void main(String[] args)
 {

     //获取屏幕尺寸
     Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
     
     try
  {
   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  } catch (ClassNotFoundException e1)
  {
   e1.printStackTrace();
  } catch (InstantiationException e1)
  {
   e1.printStackTrace();
  } catch (IllegalAccessException e1)
  {
   e1.printStackTrace();
  } catch (UnsupportedLookAndFeelException e1)
  {
   e1.printStackTrace();
  }
  
     final JFrame jFrame = new JFrame("数据切换SQL脚本生成工具");
  Image image = null;
  
  try
  {
   image = ImageIO.read(new FileInputStream("img/logo.jpg"));
  }
  catch (FileNotFoundException e)
  {
   JOptionPane.showMessageDialog(jFrame,"图片Logo没有找到 !","警告信息",JOptionPane.WARNING_MESSAGE);
   //System.exit(0);
  }
  catch (IOException e)
  {
   JOptionPane.showMessageDialog(jFrame,"读取文件异常 !","警告信息",JOptionPane.WARNING_MESSAGE);
   //System.exit(0);
  } 

        jFrame.setIconImage(image);
     Container container = jFrame.getContentPane();
     container.setLayout(null);

  final JScrollPane scrollPane = new JScrollPane();
  scrollPane.setBounds(10, 10, 770, 180);
  scrollPane.setWheelScrollingEnabled(true);
  scrollPane.setBorder(BorderFactory.createTitledBorder("信息栏"));
  container.add(scrollPane);
     
     
  final JTextArea resultTextArea = new JTextArea();
  
  Color color = new Color( 255, 255, 255);
  Color selectedColor = new Color( 0, 255, 0);
  
  Border border = BorderFactory.createLineBorder(Color.black);
  //border = BorderFactory.createLoweredBevelBorder();
  //border = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
  //border = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
  //border = BorderFactory.createRaisedBevelBorder();
  
  resultTextArea.setBorder(border);
  resultTextArea.setBackground(color);
  resultTextArea.setSelectedTextColor(selectedColor);
  resultTextArea.setText(
    "\n\t数据切换SQL脚本生成工具说明: " +
    "\n\t\t\t 待补充");
  
  resultTextArea.setEditable(false);
  scrollPane.setViewportView(resultTextArea);
  
  
  JPanel comparePane = new JPanel();
  comparePane.setLayout(null);
  comparePane.setBounds(10, 200, 770, 120);
  comparePane.setBorder(BorderFactory.createTitledBorder("生成SQL脚本文件"));
  container.add(comparePane);
  
  
  JLabel expectLabel = new JLabel("模  块:");
  expectLabel.setBounds(60, 40, 80, 26);
  comparePane.add(expectLabel);
  
  final JTextField expectTextField = new JTextField();
  expectTextField.setBounds(120, 40, 220, 26);
  comparePane.add(expectTextField);

  
  expectTextField.addKeyListener(new KeyAdapter(){

   @Override
   public void keyReleased(KeyEvent e) {
    StringBuffer sb = new StringBuffer("\t需要处理的模块:\n");
//    sb.append("");
    String content = expectTextField.getText();
    
    int len = 80;
    int i = 0;
    do
    {
     sb.append("\t");
     sb.append(content.substring(i * len, Math.min((i + 1) * len, content.length())));
     sb.append("\n");
     i ++;
    }while(len * i  <= content.length());
     
    resultTextArea.setText(sb.toString());
   }
  });
  
  
  JLabel actualLabel = new JLabel("文  件:");
  actualLabel.setBounds(390, 40, 80, 26);
  comparePane.add(actualLabel);
  
  final JTextField actualTextField = new JTextField();
  actualTextField.setBounds(450, 40, 200, 26);
  comparePane.add(actualTextField);
  
     
  JButton actualButton = new JButton("...");
  actualButton.setBounds(650, 40, 20, 26);
  comparePane.add(actualButton);
  actualButton.addActionListener(new ActionListener()
  {
   @Override
   public void actionPerformed(ActionEvent e)
   {
    JFileChooser jFileChooser = new JFileChooser();
     int returnVal = jFileChooser.showSaveDialog(jFrame);
              if (returnVal == JFileChooser.APPROVE_OPTION)
              {
                  File file = jFileChooser.getSelectedFile();              
                  actualTextField.setText(file.getAbsolutePath());
              }
   }
  });
  
  JButton compareButton = new JButton("生成脚本");
  compareButton.setBounds(590, 80, 80, 26);
  comparePane.add(compareButton);
  compareButton.addActionListener(new ActionListener()
  {
   @Override
   public void actionPerformed(ActionEvent e)
   {
    String expaceFile = expectTextField.getText();
    String actualFile = actualTextField.getText();
    if(null == expaceFile || "".equals(expaceFile))
    {
     JOptionPane.showMessageDialog(jFrame,"预期文件不能为空!","警告信息",JOptionPane.WARNING_MESSAGE);
    }
    else if(null == actualFile || "".equals(actualFile))
    {
     JOptionPane.showMessageDialog(jFrame,"实际文件不能为空!","警告信息",JOptionPane.WARNING_MESSAGE);
    }
    else
    {
     
    }
   }
  });
  
  
  JPanel sortPane = new JPanel();
  sortPane.setLayout(null);
  sortPane.setBounds(10, 330, 770, 120);
  sortPane.setBorder(BorderFactory.createTitledBorder("执行SQL脚本文件"));
  container.add(sortPane);
     
  JLabel inputLabel = new JLabel("文  件:");
  inputLabel.setBounds(60, 40, 80, 26);
  sortPane.add(inputLabel);
  
  final JTextField inputTextField = new JTextField();
  inputTextField.setBounds(120, 40, 200, 26);
  sortPane.add(inputTextField);
  
  JButton inputButton = new JButton("...");
  inputButton.setBounds(320, 40, 20, 26);
  sortPane.add(inputButton);
  inputButton.addActionListener(new ActionListener()
  {
   @Override
   public void actionPerformed(ActionEvent e)
   {
    JFileChooser jFileChooser = new JFileChooser();
     int returnVal = jFileChooser.showOpenDialog(jFrame);
              if (returnVal == JFileChooser.APPROVE_OPTION)
              {
                  File file = jFileChooser.getSelectedFile();              
                  inputTextField.setText(file.getAbsolutePath());
              }
   }
  });
     
  
  
  
  
  JButton sortButton = new JButton("执行脚本");
  sortButton.setBounds(388, 40, 80, 26);//590, 80, 80, 26
  sortPane.add(sortButton);
  sortButton.addActionListener(new ActionListener()
  {
   @Override
   public void actionPerformed(ActionEvent e)
   {
    String inputFile = inputTextField.getText();
    String outputFile = inputTextField.getText();
    String sequenceFlag = "";
    if(null == inputFile || "".equals(inputFile))
    {
     JOptionPane.showMessageDialog(jFrame,"输入文件不能为空!","警告信息",JOptionPane.WARNING_MESSAGE);
    }
    else if(null == outputFile || "".equals(outputFile))
    {
     JOptionPane.showMessageDialog(jFrame,"输出文件不能为空!","警告信息",JOptionPane.WARNING_MESSAGE);
    }
    else
    {
                  
    }
   }
  });
  
     int width = 800;
     int height = (int)(width * 0.618);
  jFrame.setSize(width,height);
  int x = (dimension.width - jFrame.getSize().width)/2;
  int y = (dimension.height - jFrame.getSize().height)/2;
  jFrame.setLocation(x, y);
  jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  jFrame.setResizable(false);
  jFrame.setVisible(true);
 }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值