init
This commit is contained in:
commit
acc9602214
5
data-WrongDataFormat.photo
Normal file
5
data-WrongDataFormat.photo
Normal file
@ -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
|
2
data-WrongDataFormat2.photo
Normal file
2
data-WrongDataFormat2.photo
Normal file
@ -0,0 +1,2 @@
|
||||
mountains;0;0;JPEG;1024;768
|
||||
wrongFormatWidthNoInteger;0;0;JPEG;ABC;DEF
|
5
data.photo
Normal file
5
data.photo
Normal file
@ -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
|
43
src/Foto.java
Normal file
43
src/Foto.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
110
src/MediaController.java
Normal file
110
src/MediaController.java
Normal file
@ -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<Foto> 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(???);
|
||||
}
|
||||
|
||||
}
|
8
src/MediaControllerMain.java
Normal file
8
src/MediaControllerMain.java
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
public class MediaControllerMain {
|
||||
public static void main(String[] args) {
|
||||
MediaController mc = new MediaController();
|
||||
|
||||
}
|
||||
|
||||
}
|
97
src/MediaView.java
Normal file
97
src/MediaView.java
Normal file
@ -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<String> 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<EFBFBD>gen der <EFBFBD>bergebenen Namen in die JList
|
||||
* @param namesPhoto
|
||||
*/
|
||||
public void setPhotoList(String[] namesPhoto) {
|
||||
// nichts ver<EFBFBD>ndern
|
||||
if (namesPhoto != null){
|
||||
DefaultListModel listModel = (DefaultListModel) photoList.getModel();
|
||||
listModel.removeAllElements();
|
||||
photoList.setListData(namesPhoto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frame anzeigen
|
||||
*/
|
||||
public void display() {
|
||||
// nichts ver<EFBFBD>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<EFBFBD>he des Bildes (int)
|
||||
*/
|
||||
public void setData(String photoType, int width, int height) {
|
||||
// nichts ver<EFBFBD>ndern
|
||||
lblStatus.setText( String.format("Typ: %s, Bildgr<67><72>e: (%d,%d)", photoType, width, height));
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellen eines Kuchendiagrammes mit 3 Segmenten. Die 3 Parameter
|
||||
* geben die H<EFBFBD>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<EFBFBD>gen
|
||||
//this.graphPanel.add(???);
|
||||
|
||||
// zum Neuzeichnen der Anwendung nach dem Einf<EFBFBD>gen - nicht <EFBFBD>ndern!
|
||||
this.getContentPane().validate();
|
||||
this.getContentPane().repaint();
|
||||
}
|
||||
}
|
5
src/WrongFileFormatException.java
Normal file
5
src/WrongFileFormatException.java
Normal file
@ -0,0 +1,5 @@
|
||||
public class WrongFileFormatException extends RuntimeException {
|
||||
public WrongFileFormatException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user