package org.liufei.gerber; import java.awt.BorderLayout; import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; import java.awt.HeadlessException; import java.awt.Image; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.InputEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; import java.util.Map; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JDesktopPane; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JRadioButton; import javax.swing.JSplitPane; import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import org.liufei.exception.GerberException; import org.liufei.gerber.iframe.GerberProjectManager; import org.liufei.gerber.iframe.GerberProjectPropsManager; import org.liufei.gerber.iframe.JdbcManager; import org.liufei.gerber.iframe.LocalGenerateWin; import org.liufei.gerber.iframe.RemoteGenerateWin; import org.liufei.gerber.iframe.SvnGerberManager; import org.liufei.gerber.iframe.SvnManager; import org.liufei.quota.Install; import org.liufei.quota.SoftwareInstall; import org.liufei.util.DesktopUtil; import org.liufei.util.Source; import org.pushingpixels.substance.api.SubstanceLookAndFeel; import org.pushingpixels.substance.api.skin.SkinInfo; /** * 生成Gerber文件窗口. * * @author 刘飞 * */ public class WinMainGenerate extends MyJFrame implements ActionListener, ItemListener { private static final long serialVersionUID = 1L; private static final JDesktopPane DESKTOP_PANE = new JDesktopPane(); private JMenuBar menuBar = new JMenuBar(); private JMenu menuOption = new JMenu("系统"); private JMenu menuHelpe = new JMenu("帮助"); private JMenu menuConfig = new JMenu("配置项"); private JMenu menuGenerate = new JMenu("生成"); private JMenu itemskin = new JMenu("皮肤设置"); private ButtonGroup plafButtonGroup = new ButtonGroup(); private JRadioButton[] plafJRadioButton; private JMenuItem itemExit = new JMenuItem("退出", new ImageIcon(this .getClass().getResource("/image/user_delete.gif"))); private JMenuItem itemChangeModes = new JMenuItem("设置系统分辨率", new ImageIcon(this .getClass().getResource("/image/refresh.gif"))); private JMenuItem gerberProject = new JMenuItem("Gerber工程配置", new ImageIcon( this.getClass().getResource("/image/books.gif"))); private JMenuItem gerberProjectProps = new JMenuItem("Gerber工程属性配置", new ImageIcon(this .getClass().getResource("/image/grid.png"))); private JMenuItem jdbc = new JMenuItem("远程jdbc配置", new ImageIcon(this .getClass().getResource("/image/prev_nav.gif"))); private JMenuItem svn = new JMenuItem("SVN配置", new ImageIcon(this.getClass().getResource("/image/plugin.gif"))) ; private JMenuItem svnGerberProps = new JMenuItem("Gerber的SVN属性配置", new ImageIcon(this.getClass().getResource("/image/xxsl.gif"))) ; private JMenuItem generateLocal = new JMenuItem("本地生成", new ImageIcon(this.getClass().getResource("/image/zip.gif"))) ; private JMenuItem generateRemote = new JMenuItem("远程SVN生成", new ImageIcon(this.getClass().getResource("/image/wtjsl.gif"))) ; private JMenuItem itemHelpe = new JMenuItem("帮助", new ImageIcon(this .getClass().getResource("/image/docs.gif"))); private JMenuItem itemAbout = new JMenuItem("关于", new ImageIcon(this .getClass().getResource("/image/comment.gif"))); private JMenu menuQuota = new JMenu("系统配额"); private JMenuItem qtpInstall = new JMenuItem("安装QTP", new ImageIcon(this .getClass().getResource("/image/qtp.jpg"))); private JMenuItem cam350Install = new JMenuItem("安装CAM350", new ImageIcon(this .getClass().getResource("/image/cam350.jpg"))); static { final JLabel label = new JLabel(); label.setBounds(0, 0, 0, 0); label.setIcon(null); // 窗体背景 DESKTOP_PANE.addComponentListener(new ComponentAdapter() { public void componentResized(final ComponentEvent e) { Dimension size = e.getComponent().getSize(); label.setSize(e.getComponent().getSize()); label.setText("<html><img width=" + size.width + " height=" + size.height + " src='" + this.getClass().getResource("/image/bg33.jpg") + "'></html>"); } }); DESKTOP_PANE.add(label, new Integer(Integer.MIN_VALUE)); DESKTOP_PANE.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); } public WinMainGenerate(String title) throws HeadlessException { super(title); Container container = getContentPane(); container.setLayout(new BorderLayout()); this.setResizable(true); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setCursor(new Cursor(0)); Toolkit tool = getToolkit(); Dimension dim = tool.getScreenSize(); this.setBounds(dim.width / 2 - 550, dim.height / 2 - 350, 1100, 700); Image image = tool.getImage(this.getClass().getResource( "/image/LOGO.png")); this.setIconImage(image); this.initMenuItem(); this.initCheckBox(); JSplitPane jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, LeftTreeMenu.getInstance(), DESKTOP_PANE); jSplitPane.setDividerSize(7); jSplitPane.setDividerLocation(0.5); container.add(MenuBar.getMenuBarHORIZONTAL(), BorderLayout.NORTH); container.add(jSplitPane, BorderLayout.CENTER); this.setContentPane(container); this.validate(); } private void initCheckBox() { Map<String, SkinInfo> allSkins = SubstanceLookAndFeel.getAllSkins() ; plafJRadioButton = new JRadioButton[allSkins.size()]; int i = 0; for (String skinInfo : allSkins.keySet()) { plafJRadioButton[i] = new JRadioButton(skinInfo); plafButtonGroup.add(plafJRadioButton[i]); plafJRadioButton[i].addItemListener(this); itemskin.add(plafJRadioButton[i]); itemskin.addSeparator(); i++; } // for(JRadioButton b : plafJRadioButton) { // if(b.getText().equals("Office Silver 2007")) { // b.setSelected(true); // } // } } public static void addAndShowIFrame(JInternalFrame iframe) { DESKTOP_PANE.add(iframe); DESKTOP_PANE.setSelectedFrame(iframe) ; DESKTOP_PANE.getDesktopManager().activateFrame(iframe) ; } public static JDesktopPane jDesktopPane() { return DESKTOP_PANE; } private void initMenuItem() { /** * 系统操作菜单 */ menuOption.add(itemskin); menuOption.setCursor(Cursor.getPredefinedCursor(12)); itemskin.setCursor(Cursor.getPredefinedCursor(12)); menuOption.addSeparator(); menuOption.add(itemChangeModes) ; itemChangeModes.setCursor(Cursor.getPredefinedCursor(12)); menuOption.addSeparator(); menuOption.add(itemExit); itemExit.setCursor(Cursor.getPredefinedCursor(12)); itemExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_MASK)); /** * 配置项菜单 */ menuConfig.setCursor(Cursor.getPredefinedCursor(12)); menuConfig.add(gerberProject); gerberProject.setCursor(Cursor.getPredefinedCursor(12)); gerberProject.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK)); menuConfig.addSeparator(); menuConfig.add(gerberProjectProps); gerberProjectProps.setCursor(Cursor.getPredefinedCursor(12)); gerberProjectProps.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK)); menuConfig.addSeparator(); menuConfig.add(jdbc); jdbc.setCursor(Cursor.getPredefinedCursor(12)); jdbc.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, InputEvent.CTRL_MASK)); menuConfig.addSeparator(); menuConfig.add(svn); svn.setCursor(Cursor.getPredefinedCursor(12)); svn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_MASK)); menuConfig.addSeparator(); menuConfig.add(svnGerberProps); svnGerberProps.setCursor(Cursor.getPredefinedCursor(12)); svnGerberProps.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_MASK)); /** * 生成菜单 */ menuGenerate.setCursor(Cursor.getPredefinedCursor(12)); menuGenerate.add(generateLocal); generateLocal.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK)); generateLocal.setCursor(Cursor.getPredefinedCursor(12)); menuGenerate.addSeparator(); menuGenerate.add(generateRemote); generateRemote.setCursor(Cursor.getPredefinedCursor(12)); generateRemote.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); /** * 帮助菜单 */ menuHelpe.add(itemHelpe); menuHelpe.setCursor(Cursor.getPredefinedCursor(12)); itemHelpe.setCursor(Cursor.getPredefinedCursor(12)); itemHelpe.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, InputEvent.CTRL_MASK)); menuHelpe.addSeparator(); menuHelpe.add(itemAbout); itemAbout.setCursor(Cursor.getPredefinedCursor(12)); itemAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK)); /** * 系统配额 */ menuQuota.add(qtpInstall) ; menuQuota.addSeparator(); menuQuota.setCursor(Cursor.getPredefinedCursor(12)); qtpInstall.setCursor(Cursor.getPredefinedCursor(12)); cam350Install.setCursor(Cursor.getPredefinedCursor(12)); menuQuota.add(cam350Install) ; menuBar.add(menuOption); menuBar.add(menuConfig); menuBar.add(menuGenerate); menuBar.add(menuQuota); menuBar.add(menuHelpe); menuBar.setBorderPainted(true); gerberProject.addActionListener(this); gerberProjectProps.addActionListener(this); itemExit.addActionListener(this); itemHelpe.addActionListener(this); itemAbout.addActionListener(this); jdbc.addActionListener(this); svn.addActionListener(this); svnGerberProps.addActionListener(this); generateLocal.addActionListener(this); generateRemote.addActionListener(this); qtpInstall.addActionListener(this); cam350Install.addActionListener(this); itemChangeModes.addActionListener(this) ; menuBar.setCursor(Cursor.getPredefinedCursor(12)); this.setJMenuBar(menuBar); } @Override public void actionPerformed(ActionEvent e) { Object actionObject = e.getSource(); if (actionObject == itemExit) { int n = JOptionPane.showConfirmDialog(this, "你确定要退出系统吗?", "系统提示", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, new ImageIcon(this .getClass().getResource("/image/help.gif"))); if (n == JOptionPane.YES_OPTION) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() {// 在退出JVM之前要处理的必要操作代码 // System.gc() ; } }); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() {// 在退出JVM之前要处理的必要操作代码 // System.gc() ; } }); System.exit(0); } else if (n == JOptionPane.NO_OPTION) { } else if (n == JOptionPane.CANCEL_OPTION) { } else if (n == JOptionPane.OK_OPTION) { } else if (n == JOptionPane.CLOSED_OPTION) { } } else if (actionObject == itemskin) { JOptionPane.showMessageDialog(this, "皮肤设置") ; } else if (actionObject == itemHelpe) { DesktopUtil.openAndWarn(new File("help/gerber文件生成系统.pdf"), this) ; } else if (actionObject == itemAbout) { // DesktopUtil.openAndWarn(new File("help/gerber文件生成系统.doc"), this) ; DesktopUtil.browseAndWarn("http://liufei-fir.iteye.com/", this) ; } else if (actionObject == gerberProject) { GerberProjectManager gerberProjectManager = new GerberProjectManager("Gerber工程配置管理", false, true, false, true) ; WinMainGenerate.addAndShowIFrame(gerberProjectManager) ; } else if (actionObject == gerberProjectProps) { GerberProjectPropsManager gerberProjectManager = new GerberProjectPropsManager("Gerber工程相应属性配置管理", false, true, false, true) ; WinMainGenerate.addAndShowIFrame(gerberProjectManager) ; } else if (actionObject == svn) { SvnManager svnManager = new SvnManager("SVN配置管理", false, true, false, true) ; WinMainGenerate.addAndShowIFrame(svnManager) ; } else if (actionObject == svnGerberProps) { SvnGerberManager svnGerberManager = new SvnGerberManager("Gerber工程SVN属性配置管理", false, true, false, true) ; WinMainGenerate.addAndShowIFrame(svnGerberManager) ; } else if (actionObject == jdbc) { JdbcManager jdbcManager = new JdbcManager("JDBC配置管理", false, true, false, true) ; WinMainGenerate.addAndShowIFrame(jdbcManager) ; } else if (actionObject == generateLocal) { LocalGenerateWin generateWin = new LocalGenerateWin("本地资源生成Gerber文件", false, true, false, true) ; WinMainGenerate.addAndShowIFrame(generateWin) ; } else if (actionObject == generateRemote) { RemoteGenerateWin generateWin = new RemoteGenerateWin("远程SVN资源Gerber文件生成", false, true, false, true) ; WinMainGenerate.addAndShowIFrame(generateWin) ; } else if (actionObject == qtpInstall) {//安装QTP String[] paths = new String[]{ Source.getAbsolutePath("Quota/QTP/qtp92"), Source.getAbsolutePath("Quota/QTP/qtp92/安装重要说明(获取免费).txt") } ; SoftwareInstall install = new Install(this, "QTP", paths) ; try { install.install(Source.getAbsolutePath("Quota/QTP/qtp92/QTP92/setup.exe")) ; } catch (GerberException e1) { JOptionPane.showInternalMessageDialog( this, "QTP安装时异常", "系统提示", JOptionPane.ERROR_MESSAGE ); } } else if (actionObject == cam350Install) {//安装CAM350 String[] paths = new String[]{ Source.getAbsolutePath("Quota/CAM350/camv8.6/CAM350V8_6新的解密文件"), Source.getAbsolutePath("Quota/CAM350/camv8.6/CAM350安装说明.txt") } ; SoftwareInstall install = new Install(this, "CAM350", paths) ; try { install.install(Source.getAbsolutePath("Quota/CAM350/camv8.6/CAM350v86.exe")) ; } catch (GerberException e1) { JOptionPane.showInternalMessageDialog( this, "CAM350安装时异常", "系统提示", JOptionPane.ERROR_MESSAGE ); } } else if(actionObject == itemChangeModes) { try { Process process = Runtime.getRuntime().exec(Source.getAbsolutePath(Source.CHANGE_MODES), null); process.waitFor() ; if(process.exitValue() == 0) { JOptionPane.showMessageDialog(this, "系统分辨率设置成功!", "系统提示", JOptionPane.INFORMATION_MESSAGE) ; } } catch (IOException e1) { JOptionPane.showMessageDialog(this, "系统分辨率设置异常!", "系统提示", JOptionPane.ERROR_MESSAGE) ; } catch (InterruptedException e2) { JOptionPane.showMessageDialog(this, "系统分辨率设置异常!", "系统提示", JOptionPane.ERROR_MESSAGE) ; } } } @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { for (final JRadioButton radio : plafJRadioButton) { if (e.getSource() == radio) { SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { SubstanceLookAndFeel.setSkin(SubstanceLookAndFeel.getAllSkins().get(radio.getText()).getClassName()); }}) ; } } } } }
package org.liufei; import java.awt.HeadlessException; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import org.liufei.db.SystemInitialize; import org.liufei.gerber.WinMainGenerate; import org.liufei.util.LoadingSource; import org.liufei.util.Source; import org.pushingpixels.substance.api.SubstanceLookAndFeel; /** * * @author 刘飞 * */ public class SystemRunner { /** * 系统注册表根 */ private static final String PREFERENCES_ROOT = "gerber" ; /** * 系统注册表键 */ private static final String[] PREFERENCES_KEYS = {"author", "version", "email"} ; /** * 系统注册表值 */ private static final String[] PREFERENCES_VALUES = {"liufei", "1.0 beta", "[email protected]"} ; /** * @param args * @throws IOException * @throws FileNotFoundException * @throws HeadlessException */ public static void main(String[] args){ init() ; JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { // SubstanceLookAndFeel.getAllSkins().get("Mist Silver").getClassName(); SubstanceLookAndFeel.setSkin("org.pushingpixels.substance.api.skin.MistSilverSkin"); WinMainGenerate generate = null ; try { generate = new WinMainGenerate(LoadingSource.reader( new File("config/system_init.properties")).getProperty( "system.main.title")); } catch (HeadlessException e) { JOptionPane.showMessageDialog(generate, "系统初始化失败!", "系统提示", JOptionPane.ERROR_MESSAGE) ; } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(generate, "系统启动找不到初始化文件!", "系统提示", JOptionPane.ERROR_MESSAGE) ; } catch (IOException e) { JOptionPane.showMessageDialog(generate, "系统启动加载初始化文件异常!", "系统提示", JOptionPane.ERROR_MESSAGE) ; } }}) ; } public static void init() { Source.deleteQTPReportFile() ; new SystemInitialize() ; Preferences preferences = Preferences.systemRoot().node(PREFERENCES_ROOT); try { if( !preferences.nodeExists(PREFERENCES_ROOT) ) { for (int i = 0 ; i < PREFERENCES_KEYS.length ; i++) { preferences.put(PREFERENCES_KEYS[i], PREFERENCES_VALUES[i]) ; } } } catch (BackingStoreException e) {} } }