import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Button; import java.io.IOException; import java.util.ArrayList; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Combo; public class MainWindowTest { protected Shell shell; /** * Launch the application. * @param args */ public static void main(String[] args) { try { MainWindowTest window = new MainWindowTest(); window.open(); } catch (Exception e) { e.printStackTrace(); } } /** * Open the window. * @throws Exception */ public void open() throws Exception { Display display = Display.getDefault(); createContents(); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } /** * Create contents of the window. * @throws IOException */ protected void createContents() throws IOException { shell = new Shell(); shell.setSize(450, 524); shell.setText("SWT Application"); shell.setLayout(null); ArrayList arrayList; ReadCategoriesSourceFile categoryFileReader = new ReadCategoriesSourceFile(); arrayList = categoryFileReader.getCategoriesResourceFileArray(); Combo comboCategories = new Combo(shell, SWT.NONE); for (String str : arrayList) { System.out.println(str); comboCategories.add(str); } //comboCategories.setItems(new String[] {"Bach", "Bartok", "Billingsly"}); comboCategories.setToolTipText("List of Composers"); comboCategories.setBounds(77, 75, 254, 23); comboCategories.setText("Composers List"); Button btnTestButton = new Button(shell, SWT.NONE); btnTestButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { System.out.println("The test phase is now over. Use JRE 22 and select the default JRE button (second button)"); if(comboCategories.getSelectionIndex() > -1) { System.out.println("You selected: " + comboCategories.getItem(comboCategories.getSelectionIndex()) ); } } }); btnTestButton.setBounds(316, 371, 75, 25); btnTestButton.setText("Test Click"); } } ====================================================================================== === Launche.java import java.awt.Desktop; import java.io.File; import java.io.IOException; public class Launcher { public void launchHTML() throws IOException { File file = new File("F:/SearchResultsFile/SearchResults.html"); Desktop.getDesktop().open(file); } } ======================================================================================= === SeaarchFrame.java import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JTextField; import java.awt.Font; import javax.swing.JButton; import java.awt.Color; import java.awt.event.ActionListener; import java.io.IOException; import java.io.File; import java.net.URISyntaxException; import java.net.URL; import java.awt.event.ActionEvent; public class SearchFrame extends JFrame { private JPanel contentPane; private JTextField txtTokens; private JTextField txtDefaultFilePath; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { SearchFrame frame = new SearchFrame(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public SearchFrame() { setTitle("Sheet Music File Search"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 936, 563); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel lblNewLabel = new JLabel("Enter Tokens (comma separated):"); lblNewLabel.setBounds(10, 11, 182, 24); contentPane.add(lblNewLabel); txtTokens = new JTextField(); txtTokens.setFont(new Font("Tahoma", Font.BOLD, 12)); txtTokens.setBounds(10, 31, 780, 30); contentPane.add(txtTokens); txtTokens.setColumns(10); JLabel lblNewLabel_1 = new JLabel("Default Search Path:"); lblNewLabel_1.setBounds(10, 72, 120, 24); contentPane.add(lblNewLabel_1); txtDefaultFilePath = new JTextField(); txtDefaultFilePath.setBounds(140, 74, 650, 22); contentPane.add(txtDefaultFilePath); txtDefaultFilePath.setColumns(10); // FilePathResource filePaths = new FilePathResource(); txtDefaultFilePath.setText(filePaths.getMusicScoresReadResource()); // JLabel lblStatus = new JLabel("Status: "); lblStatus.setBounds(0, 140, 498, 24); contentPane.add(lblStatus); JButton btnExecuteSearch = new JButton("Execute Search"); btnExecuteSearch.addActionListener(new ActionListener() { //btnExecuteSearch clicked - send all necessary data to the search // then obtain the results public void actionPerformed(ActionEvent e) { lblStatus.setText("Status: "); if(txtDefaultFilePath.getText().length() > 0 && txtTokens.getText().length() > 0) { lblStatus.setText("Status: Successful initiation"); SearchValues searchValues = new SearchValues(); searchValues.setSearchPath(txtDefaultFilePath.getText()); searchValues.setSearchTokens(txtTokens.getText()); searchValues.getTokenArray(); try { searchValues.launchFileSearch(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else { lblStatus.setText("Status: Path or Tokens are missing!"); } } }); btnExecuteSearch.setForeground(new Color(255, 0, 0)); btnExecuteSearch.setFont(new Font("Tahoma", Font.BOLD, 11)); btnExecuteSearch.setBackground(new Color(192, 192, 192)); btnExecuteSearch.setBounds(655, 128, 135, 23); contentPane.add(btnExecuteSearch); JButton btnLaunchHTMLFile = new JButton("Launch HTML File"); btnLaunchHTMLFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub Launcher launchHTML = new Launcher(); try { launchHTML.launchHTML(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); btnLaunchHTMLFile.setBounds(623, 181, 154, 23); contentPane.add(btnLaunchHTMLFile); } String getDriveLetter() { CurrentDriveLetter driveLetter = new CurrentDriveLetter(); return driveLetter.getPathRoot(); } } ========================================================================================== === SearchValues.java import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; public class SearchValues { private String searchPath; private String searchTokens; public void setSearchPath(String pSearchPath) { this.searchPath = pSearchPath; } public String getSearchPath() { return this.searchPath; } public void setSearchTokens(String pSearchTokens) { this.searchTokens = pSearchTokens; } public String getSearchTokens() { return this.searchTokens; } ArrayList getTokenArray() { ArrayList strList = new ArrayList(); System.out.println(this.searchTokens); String str = ""; str = this.getSearchTokens(); String[] strSplit = str.split(","); Arrays.asList(strSplit); System.out.println("Size: " + strSplit.length); // Now print the ArrayList for (String s : strSplit) { strList.add(s); System.out.println(s); } return strList; } public void launchFileSearch() throws IOException { ListDirectoryFiles listDirectoryFiles = new ListDirectoryFiles(); ArrayList returnedList = new ArrayList(); returnedList = listDirectoryFiles.getFilesMatchingTokens(this.getSearchTokens(), this.getSearchPath()); if(returnedList.size() > 0) { // MATCHES FOUND System.out.println("Array List size: " + returnedList.size()); HTMLFileWriter htmlFileWriter = new HTMLFileWriter(); htmlFileWriter.writeNewHTMLPreamble(); int ix = 0; for (String s : returnedList) { System.out.println("Matching " + this.getSearchTokens() + ": " + s); htmlFileWriter.writeHTMLTableRow("" + this.getSearchTokens() + "" + ++ix + "" + s + "\n\n"); } htmlFileWriter.writeHTMLClosing(); } else { // NO MATCHES FOUND System.out.println("No Matches Found!"); } } } ======================================================================================== === END