commit acc960221404245924102aeaa2730ffc05cd3445 Author: lukas Date: Sun May 17 11:04:10 2020 +0200 init diff --git a/data-WrongDataFormat.photo b/data-WrongDataFormat.photo new file mode 100644 index 0000000..2f39a16 --- /dev/null +++ b/data-WrongDataFormat.photo @@ -0,0 +1,5 @@ +mountains;0;0;JPEG;1024;768 +wrongFormatWidthMissing;0;0;JPEG; +church;0;0;RAW;800;600 +logo;0;0;GIF;300;300 +logo-large;0;0;GIF;1200;1200 diff --git a/data-WrongDataFormat2.photo b/data-WrongDataFormat2.photo new file mode 100644 index 0000000..2102e2b --- /dev/null +++ b/data-WrongDataFormat2.photo @@ -0,0 +1,2 @@ +mountains;0;0;JPEG;1024;768 +wrongFormatWidthNoInteger;0;0;JPEG;ABC;DEF diff --git a/data.photo b/data.photo new file mode 100644 index 0000000..c830d51 --- /dev/null +++ b/data.photo @@ -0,0 +1,5 @@ +mountains;0;0;JPEG;1024;768 +sunset01;0;0;JPEG;800;600 +church;0;0;RAW;800;600 +logo;0;0;GIF;300;300 +logo-large;0;0;GIF;1200;1200 diff --git a/src/Foto.java b/src/Foto.java new file mode 100644 index 0000000..3d4db03 --- /dev/null +++ b/src/Foto.java @@ -0,0 +1,43 @@ +public class Foto { + private String name; + private int ref1; + private int ref2; + private int height; + private int width; + private String fileformat; + + public Foto(String name, int ref1, int ref2, int height, int width, String fileformat) { + this.name = name; + this.ref1 = ref1; + this.ref2 = ref2; + this.height = height; + this.width = width; + this.fileformat = fileformat; + } + + public Foto() { } + + public String getName() { + return name; + } + + public int getRef1() { + return ref1; + } + + public int getRef2() { + return ref2; + } + + public int getHeight() { + return height; + } + + public int getWidth() { + return width; + } + + public String getFileformat() { + return fileformat; + } +} diff --git a/src/MediaController.java b/src/MediaController.java new file mode 100644 index 0000000..76bb540 --- /dev/null +++ b/src/MediaController.java @@ -0,0 +1,110 @@ +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.filechooser.FileNameExtensionFilter; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.*; +import java.util.ArrayList; +import java.util.Collection; + +public class MediaController implements ActionListener, ListSelectionListener { + MediaView mv = new MediaView(this, this); + //TODO: Collection für Fotos einfügen + Collection fotocollection = new ArrayList<>(); + + + /** + * Controller - nichts zu tun + */ + public MediaController() { + // nichts zu tun + mv.setPhotoList(getNamesPhoto()); + mv.display(); + } + + /** + * Aus der Collection müssen alle Namen in ein String[] kopiert werden + * + * @return String[] mit allen Namen + */ + String[] getNamesPhoto() { + String[] strar = new String[fotocollection.size()]; + + int i = 0; + for (Foto ft: fotocollection) { + strar[i] = ft.getName(); + i++; + } + + return strar; + } + + @Override + /** + * Actionlistener - muss ausprogrammiert werden + */ + public void actionPerformed(ActionEvent e) { + System.out.println(e.getActionCommand()); + if (e.getActionCommand() == "Laden") { + JFileChooser chooser = new JFileChooser(new File(".")); + FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "photo"); + chooser.setFileFilter(filter); + int returnVal = chooser.showOpenDialog(mv); + if (returnVal == JFileChooser.APPROVE_OPTION) { + System.out.println("You chose to open this file: " + chooser.getSelectedFile().getName()); + + File myfile = new File(chooser.getSelectedFile().getName()); + try { + BufferedReader reader = new BufferedReader(new FileReader(myfile)); + while (reader.ready()) { + String line = reader.readLine(); + String[] spl = line.split(";"); + + if (spl.length != 6) + throw new WrongFileFormatException("invaild number of columns"); + + try { + Foto ft = new Foto(spl[0], + Integer.parseInt(spl[1]), + Integer.parseInt(spl[2]), + Integer.parseInt(spl[4]), + Integer.parseInt(spl[5]), + spl[3]); + + fotocollection.add(ft); + } catch (NumberFormatException ee) { + throw new WrongFileFormatException("parse error- no integer in file column"); + } + } + + } catch (FileNotFoundException fileNotFoundException) { + fileNotFoundException.printStackTrace(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } catch (WrongFileFormatException en) { + System.err.println("an File Format exception occured: "+en.getMessage()); + } + + } + // TODO: Datei auswählen und die Daten in die Collection laden + } else if (e.getActionCommand() == "Grafik") { + // TODO: die Häufigkeiten der Fotoformate muss berechnet werden + // und an die Methode displayGraph übergeben werden + + // mv.displayGraph(???); + } + + } + + @Override + /** + * ListSelectionListener - wenn sich die + */ + public void valueChanged(ListSelectionEvent e) { + // TODO: die Daten zum ausgewähltem Foto müssen mit setData angezeigt werden + + // mv.setData(???); + } + +} diff --git a/src/MediaControllerMain.java b/src/MediaControllerMain.java new file mode 100644 index 0000000..5d068b6 --- /dev/null +++ b/src/MediaControllerMain.java @@ -0,0 +1,8 @@ + +public class MediaControllerMain { + public static void main(String[] args) { + MediaController mc = new MediaController(); + + } + +} diff --git a/src/MediaView.java b/src/MediaView.java new file mode 100644 index 0000000..11bc762 --- /dev/null +++ b/src/MediaView.java @@ -0,0 +1,97 @@ +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.ScrollPane; +import java.awt.event.ActionListener; + +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.event.ListSelectionListener; + +public class MediaView extends JFrame { + JList photoList = new JList<>(); + JButton btnLoad = new JButton("Laden"); + JButton btnGraph = new JButton("Grafik"); + + JPanel ctrlPanel = new JPanel(); + JPanel photoPanel = new JPanel(new BorderLayout()); + JPanel graphPanel = new JPanel(); + + JLabel lblStatus = new JLabel("Data: "); + + /** + * Konstruktor + * @param al + * @param lsl + */ + public MediaView(ActionListener al, ListSelectionListener lsl) { + this.setTitle("ihren Namen"); + + photoPanel.add(new JLabel("Fotos:"),BorderLayout.NORTH); + photoPanel.add(new ScrollPane().add(photoList)); + photoList.addListSelectionListener(lsl); + + ctrlPanel.add(btnLoad); + ctrlPanel.add(btnGraph); + btnLoad.addActionListener(al); + btnGraph.addActionListener(al); + + this.getContentPane().add(photoPanel, BorderLayout.WEST); + this.getContentPane().add(graphPanel); + this.getContentPane().add(ctrlPanel, BorderLayout.NORTH); + this.getContentPane().add(lblStatus, BorderLayout.SOUTH); + } + + /** + * Einf�gen der �bergebenen Namen in die JList + * @param namesPhoto + */ + public void setPhotoList(String[] namesPhoto) { + // nichts ver�ndern + if (namesPhoto != null){ + DefaultListModel listModel = (DefaultListModel) photoList.getModel(); + listModel.removeAllElements(); + photoList.setListData(namesPhoto); + } + } + + /** + * Frame anzeigen + */ + public void display() { + // nichts ver�ndern + this.setSize(600,530); + this.setVisible(true); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + + /** + * Daten eines Fotos in der Statuszeile der View anzeigen + * @param photoType ... Datentyp (als String) + * @param width ... Breite des Bildes (int) + * @param height ... H�he des Bildes (int) + */ + public void setData(String photoType, int width, int height) { + // nichts ver�ndern + lblStatus.setText( String.format("Typ: %s, Bildgr��e: (%d,%d)", photoType, width, height)); + } + + /** + * Erstellen eines Kuchendiagrammes mit 3 Segmenten. Die 3 Parameter + * geben die H�ufigkeiten der Bildtypen an + * @param raw + * @param jpeg + * @param gif + */ + public void displayGraph(float raw, float jpeg, float gif) { + // TODO: Kuchendiagramm erzeugen und in graphPanel einf�gen + //this.graphPanel.add(???); + + // zum Neuzeichnen der Anwendung nach dem Einf�gen - nicht �ndern! + this.getContentPane().validate(); + this.getContentPane().repaint(); + } +} diff --git a/src/WrongFileFormatException.java b/src/WrongFileFormatException.java new file mode 100644 index 0000000..ce4c8f5 --- /dev/null +++ b/src/WrongFileFormatException.java @@ -0,0 +1,5 @@ +public class WrongFileFormatException extends RuntimeException { + public WrongFileFormatException(String message) { + super(message); + } +}