Lab6 open


// File->Open MenuItem, O - Mnemonic
JMenuItem openMenuItem = new JMenuItem("Open", KeyEvent.VK_O);
fileMenu.add(openMenuItem);
openMenuItem.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent event) {
        System.out.println("OPEN");
        File[] selectedFiles = openFileDialog();
        if (selectedFiles == null) return;
        List photoList = new ArrayList(); // photoList
        for (int i = 0; i < selectedFiles.length; i++) {
            try {
                String fullPath = selectedFiles[i].getCanonicalPath(); //String fullPath = file.getCanonicalPath().replace('\\', '/');
                System.out.println("OPEN fullPath=" + fullPath);
                Photo photo = new Photo(fullPath);
                if (photo.getImg() != null) { // if image is loaded
                    photoList.add(photo);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }	
	photoArray = new Photo[photoList.size()]; // create photoArray with photoList.size()
	photoArray = photoList.toArray(photoArray); // photoList => photoArray
	for (Photo p : photoArray) p.print(); // debug to print photoArray
	
	displayPanel.loadPhotos(photoArray); // reload photoArray in displayPanel
	displayPanel.repaint(); // repaint
    }
});