**/\r
package org.tianocore.migration;\r
\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-import java.io.*;\r
-import java.util.*;\r
-import javax.swing.*;\r
-\r
-public final class FirstPanel extends JPanel implements ActionListener, ItemListener, UI {\r
- /**\r
- * Define class Serial Version UID\r
- */\r
- private static final long serialVersionUID = 207759413522910399L;\r
- \r
- private static final FirstPanel INSTANCE = FirstPanel.init();\r
- \r
- private String startpath = null;\r
- \r
- private JButton moduleButton, goButton, msaEditorButton, criticButton, specifyCommentButton;\r
- private JTextField moduletext;\r
- private JTextArea log;\r
- private JFileChooser fc = new JFileChooser();\r
- private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;\r
- \r
- private boolean tofile = true, toscreen = true;\r
- private PrintWriter logfile;\r
-\r
- FirstPanel() {\r
- GridBagLayout gridbag = new GridBagLayout();\r
- setLayout(gridbag);\r
- \r
- GridBagConstraints cst = new GridBagConstraints();\r
- \r
- goButton = new JButton("Go");\r
- goButton.addActionListener(this);\r
- goButton.setActionCommand("go");\r
- \r
- moduleButton = new JButton("Choose ModulePath");\r
- moduleButton.addActionListener(this);\r
-\r
- msaEditorButton = new JButton("MsaEditor");\r
- msaEditorButton.addActionListener(this);\r
- \r
- criticButton = new JButton("Critic");\r
- criticButton.addActionListener(this);\r
- \r
- specifyCommentButton = new JButton("Comment Style");\r
- specifyCommentButton.addActionListener(this);\r
- \r
- moduletext = new JTextField(30);\r
- \r
- filebox = new JCheckBox("Output to logfile", true);\r
- filebox.addItemListener(this);\r
- \r
- screenbox = new JCheckBox("Specify logfile", false);\r
- screenbox.addItemListener(this);\r
- \r
- mibox = new JCheckBox("Print ModuleInfo", false);\r
- mibox.addItemListener(this);\r
- MigrationTool.printModuleInfo = false;\r
- \r
- criticbox = new JCheckBox("Run Critic", true);\r
- criticbox.addItemListener(this);\r
- MigrationTool.doCritic = true;\r
- \r
- defaultpathbox = new JCheckBox("Use Default Output Path", true);\r
- defaultpathbox.addItemListener(this);\r
- MigrationTool.defaultoutput = true;\r
- \r
- JPanel modulePanel = new JPanel();\r
- modulePanel.add(moduleButton);\r
- modulePanel.add(moduletext);\r
- modulePanel.add(goButton);\r
- //modulePanel.add(msaEditorButton);\r
- cst.gridx = 0;\r
- cst.gridy = 0;\r
- //cst.gridwidth = GridBagConstraints.REMAINDER;\r
- gridbag.setConstraints(modulePanel, cst);\r
- add(modulePanel);\r
-\r
- cst.gridx = 1;\r
- cst.gridy = 0;\r
- gridbag.setConstraints(specifyCommentButton, cst);\r
- add(specifyCommentButton);\r
- //gridbag.setConstraints(criticButton, cst);\r
- //add(criticButton);\r
- \r
- JPanel checkboxPanel = new JPanel();\r
- checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));\r
- checkboxPanel.add(filebox);\r
- checkboxPanel.add(screenbox);\r
- checkboxPanel.add(mibox);\r
- checkboxPanel.add(criticbox);\r
- checkboxPanel.add(defaultpathbox);\r
- cst.gridx = 1;\r
- cst.gridy = 1;\r
- //cst.gridheight = 2;\r
- gridbag.setConstraints(checkboxPanel, cst);\r
- add(checkboxPanel);\r
- \r
- log = new JTextArea(10,20);\r
- log.setMargin(new Insets(5,5,5,5));\r
- log.setEditable(false);\r
- JScrollPane logScrollPane = new JScrollPane(log);\r
- cst.gridx = 0;\r
- cst.gridy = 1;\r
- cst.fill = GridBagConstraints.BOTH;\r
- gridbag.setConstraints(logScrollPane, cst);\r
- add(logScrollPane);\r
- }\r
- \r
- //---------------------------------------------------------------------------------------//\r
- \r
- public boolean yesOrNo(String question) {\r
- return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;\r
- }\r
- \r
- public void print(String message) {\r
- if (toscreen == true) {\r
- log.append(message);\r
- System.out.print(message);\r
- }\r
- if (tofile == true) {\r
- logfile.append(message);\r
- }\r
- }\r
- \r
- public void println(String message) {\r
- print(message + "\n");\r
- }\r
-\r
- public void println(Set<String> hash) {\r
- if (toscreen == true) {\r
- log.append(hash + "\n");\r
- System.out.println(hash);\r
- }\r
- if (tofile == true) {\r
- logfile.append(hash + "\n");\r
- }\r
- }\r
-\r
- public String choose(String message, Object[] choicelist) {\r
- return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);\r
- }\r
- \r
- public String getInput(String message) {\r
- return (String)JOptionPane.showInputDialog(message);\r
- }\r
-\r
- //---------------------------------------------------------------------------------------//\r
-\r
- public String getFilepath(String title, int mode) {\r
- fc.setDialogTitle(title);\r
- fc.setFileSelectionMode(mode);\r
- if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {\r
- log.append(fc.getSelectedFile().getAbsolutePath() + "\n");\r
- return fc.getSelectedFile().getAbsolutePath();\r
- }\r
- return null;\r
- }\r
-\r
- //---------------------------------------------------------------------------------------//\r
-\r
- public void actionPerformed(ActionEvent e) {\r
- if ( e.getSource() == moduleButton ) {\r
- startpath = getFilepath("Please choose a starting path", JFileChooser.DIRECTORIES_ONLY);\r
- moduletext.setText(startpath);\r
- }\r
- if ( e.getSource() == goButton ) {\r
- try {\r
- logfile = new PrintWriter(new BufferedWriter(new FileWriter(startpath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + "migration.log")));\r
- MigrationTool.startMigrateAll(startpath);\r
- logfile.flush();\r
- logfile.close();\r
- } catch (Exception en) {\r
- println(en.getMessage());\r
- }\r
- }\r
- if ( e.getSource() == msaEditorButton) {\r
- try {\r
- MsaTreeEditor.init();\r
- } catch (Exception en) {\r
- println(en.getMessage());\r
- }\r
- }\r
- if ( e.getSource() == criticButton) {\r
- try {\r
- Critic.fireAt(startpath);\r
- } catch (Exception en) {\r
- println(en.getMessage());\r
- }\r
- }\r
- if ( e.getSource() == specifyCommentButton) {\r
- try { // input examine is not imposed but should be added\r
- MigrationTool.MIGRATIONCOMMENT = getInput("Please type in wanted comment style used by the tool\nbe sure to start with '//', or you won't enjoy the result");\r
- //MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");\r
- } catch (Exception en) {\r
- println(en.getMessage());\r
- }\r
- }\r
- }\r
- \r
- public void itemStateChanged(ItemEvent e) {\r
- if (e.getSource() == filebox) {\r
- if (e.getStateChange() == ItemEvent.DESELECTED) {\r
- System.out.println("filebox DESELECTED");\r
- } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
- System.out.println("filebox SELECTED");\r
- }\r
- } else if (e.getSource() == screenbox) {\r
- if (e.getStateChange() == ItemEvent.DESELECTED) {\r
- System.out.println("screenbox DESELECTED");\r
- } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
- System.out.println("screenbox SELECTED");\r
- }\r
- } else if (e.getSource() == mibox) {\r
- if (e.getStateChange() == ItemEvent.DESELECTED) {\r
- MigrationTool.printModuleInfo = false;\r
- } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
- MigrationTool.printModuleInfo = true;\r
- }\r
- } else if (e.getSource() == criticbox) {\r
- if (e.getStateChange() == ItemEvent.DESELECTED) {\r
- MigrationTool.doCritic = false;\r
- } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
- MigrationTool.doCritic = true;\r
- }\r
- } else if (e.getSource() == defaultpathbox) {\r
- if (e.getStateChange() == ItemEvent.DESELECTED) {\r
- MigrationTool.defaultoutput = false;\r
- } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
- MigrationTool.defaultoutput = true;\r
- }\r
- }\r
- }\r
-\r
- //---------------------------------------------------------------------------------------//\r
- \r
- private static final FirstPanel init() {\r
- try {\r
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
- //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());\r
- //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");\r
- //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");\r
- //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");\r
- //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");\r
- } catch (Exception e) {\r
- System.out.println(e.getMessage());\r
- }\r
- \r
- JFrame frame = new JFrame("MigrationTools");\r
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
-\r
- FirstPanel fp = new FirstPanel();\r
- //fp.setLayout(new GridBagLayout());\r
- //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));\r
- fp.setOpaque(true);\r
- frame.setContentPane(fp);\r
-\r
- frame.pack();\r
- frame.setVisible(true);\r
- \r
- return fp;\r
- }\r
- \r
- public static final FirstPanel getInstance() {\r
- return INSTANCE;\r
- }\r
+import java.awt.GridBagConstraints;\r
+import java.awt.GridBagLayout;\r
+import java.awt.Insets;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.ItemEvent;\r
+import java.awt.event.ItemListener;\r
+import java.io.BufferedWriter;\r
+import java.io.File;\r
+import java.io.FileWriter;\r
+import java.io.PrintWriter;\r
+import java.util.Set;\r
+\r
+import javax.swing.BoxLayout;\r
+import javax.swing.JButton;\r
+import javax.swing.JCheckBox;\r
+import javax.swing.JFileChooser;\r
+import javax.swing.JFrame;\r
+import javax.swing.JOptionPane;\r
+import javax.swing.JPanel;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTextArea;\r
+import javax.swing.JTextField;\r
+import javax.swing.UIManager;\r
+\r
+public final class FirstPanel extends JPanel implements ActionListener,\r
+ ItemListener, UI {\r
+ /**\r
+ * Define class Serial Version UID\r
+ */\r
+ private static final long serialVersionUID = 207759413522910399L;\r
+\r
+ private static final FirstPanel INSTANCE = FirstPanel.init();\r
+\r
+ private String startpath = null;\r
+\r
+ private JButton moduleButton, goButton, msaEditorButton, criticButton,\r
+ specifyCommentButton;\r
+\r
+ private JTextField moduletext;\r
+\r
+ private JTextArea log;\r
+\r
+ private JFileChooser fc = new JFileChooser();\r
+\r
+ private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;\r
+\r
+ private boolean tofile = true, toscreen = true;\r
+\r
+ private PrintWriter logfile;\r
+\r
+ FirstPanel() {\r
+ GridBagLayout gridbag = new GridBagLayout();\r
+ setLayout(gridbag);\r
+\r
+ GridBagConstraints cst = new GridBagConstraints();\r
+\r
+ goButton = new JButton("Go");\r
+ goButton.addActionListener(this);\r
+ goButton.setActionCommand("go");\r
+\r
+ moduleButton = new JButton("Choose ModulePath");\r
+ moduleButton.addActionListener(this);\r
+\r
+ msaEditorButton = new JButton("MsaEditor");\r
+ msaEditorButton.addActionListener(this);\r
+\r
+ criticButton = new JButton("Critic");\r
+ criticButton.addActionListener(this);\r
+\r
+ specifyCommentButton = new JButton("Comment Style");\r
+ specifyCommentButton.addActionListener(this);\r
+\r
+ moduletext = new JTextField(30);\r
+\r
+ filebox = new JCheckBox("Output to logfile", true);\r
+ filebox.addItemListener(this);\r
+\r
+ screenbox = new JCheckBox("Specify logfile", false);\r
+ screenbox.addItemListener(this);\r
+\r
+ mibox = new JCheckBox("Print ModuleInfo", false);\r
+ mibox.addItemListener(this);\r
+ MigrationTool.printModuleInfo = false;\r
+\r
+ criticbox = new JCheckBox("Run Critic", true);\r
+ criticbox.addItemListener(this);\r
+ MigrationTool.doCritic = true;\r
+\r
+ defaultpathbox = new JCheckBox("Use Default Output Path", true);\r
+ defaultpathbox.addItemListener(this);\r
+ MigrationTool.defaultoutput = true;\r
+\r
+ JPanel modulePanel = new JPanel();\r
+ modulePanel.add(moduleButton);\r
+ modulePanel.add(moduletext);\r
+ modulePanel.add(goButton);\r
+ // modulePanel.add(msaEditorButton);\r
+ cst.gridx = 0;\r
+ cst.gridy = 0;\r
+ // cst.gridwidth = GridBagConstraints.REMAINDER;\r
+ gridbag.setConstraints(modulePanel, cst);\r
+ add(modulePanel);\r
+\r
+ cst.gridx = 1;\r
+ cst.gridy = 0;\r
+ gridbag.setConstraints(specifyCommentButton, cst);\r
+ add(specifyCommentButton);\r
+ // gridbag.setConstraints(criticButton, cst);\r
+ // add(criticButton);\r
+\r
+ JPanel checkboxPanel = new JPanel();\r
+ checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));\r
+ checkboxPanel.add(filebox);\r
+ checkboxPanel.add(screenbox);\r
+ checkboxPanel.add(mibox);\r
+ checkboxPanel.add(criticbox);\r
+ checkboxPanel.add(defaultpathbox);\r
+ cst.gridx = 1;\r
+ cst.gridy = 1;\r
+ // cst.gridheight = 2;\r
+ gridbag.setConstraints(checkboxPanel, cst);\r
+ add(checkboxPanel);\r
+\r
+ log = new JTextArea(10, 20);\r
+ log.setMargin(new Insets(5, 5, 5, 5));\r
+ log.setEditable(false);\r
+ JScrollPane logScrollPane = new JScrollPane(log);\r
+ cst.gridx = 0;\r
+ cst.gridy = 1;\r
+ cst.fill = GridBagConstraints.BOTH;\r
+ gridbag.setConstraints(logScrollPane, cst);\r
+ add(logScrollPane);\r
+ }\r
+\r
+ // ---------------------------------------------------------------------------------------//\r
+\r
+ public boolean yesOrNo(String question) {\r
+ return JOptionPane.showConfirmDialog(this, question, "Yes or No",\r
+ JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;\r
+ }\r
+\r
+ public void print(String message) {\r
+ if (toscreen == true) {\r
+ log.append(message);\r
+ System.out.print(message);\r
+ }\r
+ if (tofile == true) {\r
+ logfile.append(message);\r
+ }\r
+ }\r
+\r
+ public void println(String message) {\r
+ print(message + "\n");\r
+ }\r
+\r
+ public void println(Set<String> hash) {\r
+ if (toscreen == true) {\r
+ log.append(hash + "\n");\r
+ System.out.println(hash);\r
+ }\r
+ if (tofile == true) {\r
+ logfile.append(hash + "\n");\r
+ }\r
+ }\r
+\r
+ public String choose(String message, Object[] choicelist) {\r
+ return (String) JOptionPane.showInputDialog(this, message, "Choose",\r
+ JOptionPane.PLAIN_MESSAGE, null, choicelist, choicelist[0]);\r
+ }\r
+\r
+ public String getInput(String message) {\r
+ return (String) JOptionPane.showInputDialog(message);\r
+ }\r
+\r
+ // ---------------------------------------------------------------------------------------//\r
+\r
+ public String getFilepath(String title, int mode) {\r
+ fc.setDialogTitle(title);\r
+ fc.setFileSelectionMode(mode);\r
+ if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {\r
+ log.append(fc.getSelectedFile().getAbsolutePath() + "\n");\r
+ return fc.getSelectedFile().getAbsolutePath();\r
+ }\r
+ return null;\r
+ }\r
+\r
+ // ---------------------------------------------------------------------------------------//\r
+\r
+ public void actionPerformed(ActionEvent e) {\r
+ if (e.getSource() == moduleButton) {\r
+ startpath = getFilepath("Please choose a starting path",\r
+ JFileChooser.DIRECTORIES_ONLY);\r
+ moduletext.setText(startpath);\r
+ }\r
+ if (e.getSource() == goButton) {\r
+ try {\r
+ logfile = new PrintWriter(new BufferedWriter(new FileWriter(\r
+ startpath.replaceAll(Common.STRSEPARATER, "$1")\r
+ + File.separator + "migration.log")));\r
+ MigrationTool.startMigrateAll(startpath);\r
+ logfile.flush();\r
+ logfile.close();\r
+ } catch (Exception en) {\r
+ println(en.getMessage());\r
+ }\r
+ }\r
+ if (e.getSource() == msaEditorButton) {\r
+ try {\r
+ MsaTreeEditor.init();\r
+ } catch (Exception en) {\r
+ println(en.getMessage());\r
+ }\r
+ }\r
+ if (e.getSource() == criticButton) {\r
+ try {\r
+ Critic.fireAt(startpath);\r
+ } catch (Exception en) {\r
+ println(en.getMessage());\r
+ }\r
+ }\r
+ if (e.getSource() == specifyCommentButton) {\r
+ try { // input examine is not imposed but should be added\r
+ MigrationTool.MIGRATIONCOMMENT = getInput("Please type in wanted comment style used by the tool\nbe sure to start with '//', or you won't enjoy the result");\r
+ // MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");\r
+ } catch (Exception en) {\r
+ println(en.getMessage());\r
+ }\r
+ }\r
+ }\r
+\r
+ public void itemStateChanged(ItemEvent e) {\r
+ if (e.getSource() == filebox) {\r
+ if (e.getStateChange() == ItemEvent.DESELECTED) {\r
+ System.out.println("filebox DESELECTED");\r
+ } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
+ System.out.println("filebox SELECTED");\r
+ }\r
+ } else if (e.getSource() == screenbox) {\r
+ if (e.getStateChange() == ItemEvent.DESELECTED) {\r
+ System.out.println("screenbox DESELECTED");\r
+ } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
+ System.out.println("screenbox SELECTED");\r
+ }\r
+ } else if (e.getSource() == mibox) {\r
+ if (e.getStateChange() == ItemEvent.DESELECTED) {\r
+ MigrationTool.printModuleInfo = false;\r
+ } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
+ MigrationTool.printModuleInfo = true;\r
+ }\r
+ } else if (e.getSource() == criticbox) {\r
+ if (e.getStateChange() == ItemEvent.DESELECTED) {\r
+ MigrationTool.doCritic = false;\r
+ } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
+ MigrationTool.doCritic = true;\r
+ }\r
+ } else if (e.getSource() == defaultpathbox) {\r
+ if (e.getStateChange() == ItemEvent.DESELECTED) {\r
+ MigrationTool.defaultoutput = false;\r
+ } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
+ MigrationTool.defaultoutput = true;\r
+ }\r
+ }\r
+ }\r
+\r
+ // ---------------------------------------------------------------------------------------//\r
+\r
+ private static final FirstPanel init() {\r
+ try {\r
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
+ } catch (Exception e) {\r
+ System.out.println(e.getMessage());\r
+ }\r
+\r
+ JFrame frame = new JFrame("MigrationTools");\r
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
+\r
+ FirstPanel fp = new FirstPanel();\r
+ fp.setOpaque(true);\r
+ frame.setContentPane(fp);\r
+\r
+ frame.pack();\r
+ frame.setVisible(true);\r
+\r
+ return fp;\r
+ }\r
+\r
+ public static final FirstPanel getInstance() {\r
+ return INSTANCE;\r
+ }\r
}
\ No newline at end of file