finished d-f
This commit is contained in:
parent
acc9602214
commit
84658670ad
@ -1,32 +1,16 @@
|
|||||||
public class Foto {
|
public class Foto extends Medien {
|
||||||
private String name;
|
|
||||||
private int ref1;
|
|
||||||
private int ref2;
|
|
||||||
private int height;
|
private int height;
|
||||||
private int width;
|
private int width;
|
||||||
private String fileformat;
|
private String fileformat;
|
||||||
|
|
||||||
public Foto(String name, int ref1, int ref2, int height, int width, String fileformat) {
|
public Foto(String name, int rating, int nrused, String fileformat, int height, int width) {
|
||||||
this.name = name;
|
super(name, rating, nrused);
|
||||||
this.ref1 = ref1;
|
|
||||||
this.ref2 = ref2;
|
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.fileformat = fileformat;
|
this.fileformat = fileformat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Foto() { }
|
public Foto() {
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRef1() {
|
|
||||||
return ref1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRef2() {
|
|
||||||
return ref2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
|
@ -2,16 +2,16 @@ import javax.swing.*;
|
|||||||
import javax.swing.event.ListSelectionEvent;
|
import javax.swing.event.ListSelectionEvent;
|
||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
public class MediaController implements ActionListener, ListSelectionListener {
|
public class MediaController implements ActionListener, ListSelectionListener {
|
||||||
MediaView mv = new MediaView(this, this);
|
MediaView mv = new MediaView(this, this);
|
||||||
//TODO: Collection für Fotos einfügen
|
//TODO: Collection für Fotos einfügen
|
||||||
Collection<Foto> fotocollection = new ArrayList<>();
|
ArrayList<Foto> fotocollection = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,10 +31,8 @@ public class MediaController implements ActionListener, ListSelectionListener {
|
|||||||
String[] getNamesPhoto() {
|
String[] getNamesPhoto() {
|
||||||
String[] strar = new String[fotocollection.size()];
|
String[] strar = new String[fotocollection.size()];
|
||||||
|
|
||||||
int i = 0;
|
for (int i = 0; i < fotocollection.size(); i++) {
|
||||||
for (Foto ft: fotocollection) {
|
strar[i] = fotocollection.get(i).getName();
|
||||||
strar[i] = ft.getName();
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return strar;
|
return strar;
|
||||||
@ -68,12 +66,15 @@ public class MediaController implements ActionListener, ListSelectionListener {
|
|||||||
Foto ft = new Foto(spl[0],
|
Foto ft = new Foto(spl[0],
|
||||||
Integer.parseInt(spl[1]),
|
Integer.parseInt(spl[1]),
|
||||||
Integer.parseInt(spl[2]),
|
Integer.parseInt(spl[2]),
|
||||||
|
spl[3],
|
||||||
Integer.parseInt(spl[4]),
|
Integer.parseInt(spl[4]),
|
||||||
Integer.parseInt(spl[5]),
|
Integer.parseInt(spl[5])
|
||||||
spl[3]);
|
);
|
||||||
|
|
||||||
fotocollection.add(ft);
|
fotocollection.add(ft);
|
||||||
|
mv.setPhotoList(getNamesPhoto());
|
||||||
} catch (NumberFormatException ee) {
|
} catch (NumberFormatException ee) {
|
||||||
|
showPopup(ee.getMessage());
|
||||||
throw new WrongFileFormatException("parse error- no integer in file column");
|
throw new WrongFileFormatException("parse error- no integer in file column");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,7 +84,8 @@ public class MediaController implements ActionListener, ListSelectionListener {
|
|||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
ioException.printStackTrace();
|
ioException.printStackTrace();
|
||||||
} catch (WrongFileFormatException en) {
|
} catch (WrongFileFormatException en) {
|
||||||
System.err.println("an File Format exception occured: "+en.getMessage());
|
System.err.println("an File Format exception occured: " + en.getMessage());
|
||||||
|
showPopup(en.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -91,8 +93,24 @@ public class MediaController implements ActionListener, ListSelectionListener {
|
|||||||
} else if (e.getActionCommand() == "Grafik") {
|
} else if (e.getActionCommand() == "Grafik") {
|
||||||
// TODO: die Häufigkeiten der Fotoformate muss berechnet werden
|
// TODO: die Häufigkeiten der Fotoformate muss berechnet werden
|
||||||
// und an die Methode displayGraph übergeben werden
|
// und an die Methode displayGraph übergeben werden
|
||||||
|
int raw = 0;
|
||||||
|
int jpeg = 0;
|
||||||
|
int gif = 0;
|
||||||
|
|
||||||
// mv.displayGraph(???);
|
for (Foto ft : fotocollection) {
|
||||||
|
switch (ft.getFileformat()) {
|
||||||
|
case "JPEG":
|
||||||
|
jpeg++;
|
||||||
|
break;
|
||||||
|
case "RAW":
|
||||||
|
raw++;
|
||||||
|
break;
|
||||||
|
case "GIF":
|
||||||
|
gif++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mv.displayGraph(raw, jpeg, gif);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -102,9 +120,23 @@ public class MediaController implements ActionListener, ListSelectionListener {
|
|||||||
* ListSelectionListener - wenn sich die
|
* ListSelectionListener - wenn sich die
|
||||||
*/
|
*/
|
||||||
public void valueChanged(ListSelectionEvent e) {
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
// TODO: die Daten zum ausgewähltem Foto müssen mit setData angezeigt werden
|
Foto ft = fotocollection.get(mv.photoList.getSelectedIndex());
|
||||||
|
|
||||||
// mv.setData(???);
|
mv.setData(ft.getFileformat(), ft.getWidth(), ft.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showPopup(String message) {
|
||||||
|
JDialog dialog = new JDialog(mv, "Title");
|
||||||
|
dialog.setSize(200, 200);
|
||||||
|
dialog.setLayout(new BorderLayout());
|
||||||
|
JButton btn = new JButton("ok");
|
||||||
|
btn.addActionListener(e1 -> {
|
||||||
|
dialog.setVisible(false);
|
||||||
|
dialog.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.add(btn, BorderLayout.SOUTH);
|
||||||
|
dialog.add(new JLabel(message), BorderLayout.CENTER);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,97 +1,128 @@
|
|||||||
import java.awt.BorderLayout;
|
import org.jfree.chart.ChartFactory;
|
||||||
import java.awt.GridLayout;
|
import org.jfree.chart.ChartPanel;
|
||||||
import java.awt.ScrollPane;
|
import org.jfree.chart.JFreeChart;
|
||||||
|
import org.jfree.chart.plot.PiePlot;
|
||||||
|
import org.jfree.data.general.DefaultPieDataset;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
import java.awt.*;
|
||||||
import java.awt.event.ActionListener;
|
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 {
|
public class MediaView extends JFrame {
|
||||||
JList<String> photoList = new JList<>();
|
JList<String> photoList = new JList<>();
|
||||||
JButton btnLoad = new JButton("Laden");
|
JButton btnLoad = new JButton("Laden");
|
||||||
JButton btnGraph = new JButton("Grafik");
|
JButton btnGraph = new JButton("Grafik");
|
||||||
|
|
||||||
JPanel ctrlPanel = new JPanel();
|
JPanel ctrlPanel = new JPanel();
|
||||||
JPanel photoPanel = new JPanel(new BorderLayout());
|
JPanel photoPanel = new JPanel(new BorderLayout());
|
||||||
JPanel graphPanel = new JPanel();
|
JPanel graphPanel = new JPanel();
|
||||||
|
|
||||||
JLabel lblStatus = new JLabel("Data: ");
|
JLabel lblStatus = new JLabel("Data: ");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Konstruktor
|
* Konstruktor
|
||||||
* @param al
|
*
|
||||||
* @param lsl
|
* @param al
|
||||||
*/
|
* @param lsl
|
||||||
public MediaView(ActionListener al, ListSelectionListener lsl) {
|
*/
|
||||||
this.setTitle("ihren Namen");
|
public MediaView(ActionListener al, ListSelectionListener lsl) {
|
||||||
|
this.setTitle("ihren Namen");
|
||||||
|
|
||||||
photoPanel.add(new JLabel("Fotos:"),BorderLayout.NORTH);
|
photoPanel.add(new JLabel("Fotos:"), BorderLayout.NORTH);
|
||||||
photoPanel.add(new ScrollPane().add(photoList));
|
photoPanel.add(new ScrollPane().add(photoList));
|
||||||
photoList.addListSelectionListener(lsl);
|
photoList.addListSelectionListener(lsl);
|
||||||
|
|
||||||
ctrlPanel.add(btnLoad);
|
ctrlPanel.add(btnLoad);
|
||||||
ctrlPanel.add(btnGraph);
|
ctrlPanel.add(btnGraph);
|
||||||
btnLoad.addActionListener(al);
|
btnLoad.addActionListener(al);
|
||||||
btnGraph.addActionListener(al);
|
btnGraph.addActionListener(al);
|
||||||
|
|
||||||
this.getContentPane().add(photoPanel, BorderLayout.WEST);
|
this.getContentPane().add(photoPanel, BorderLayout.WEST);
|
||||||
this.getContentPane().add(graphPanel);
|
this.getContentPane().add(graphPanel);
|
||||||
this.getContentPane().add(ctrlPanel, BorderLayout.NORTH);
|
this.getContentPane().add(ctrlPanel, BorderLayout.NORTH);
|
||||||
this.getContentPane().add(lblStatus, BorderLayout.SOUTH);
|
this.getContentPane().add(lblStatus, BorderLayout.SOUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Einf<EFBFBD>gen der <EFBFBD>bergebenen Namen in die JList
|
* Einf<EFBFBD>gen der <EFBFBD>bergebenen Namen in die JList
|
||||||
* @param namesPhoto
|
*
|
||||||
*/
|
* @param namesPhoto
|
||||||
public void setPhotoList(String[] namesPhoto) {
|
*/
|
||||||
// nichts ver<EFBFBD>ndern
|
public void setPhotoList(String[] namesPhoto) {
|
||||||
if (namesPhoto != null){
|
// nichts ver<EFBFBD>ndern
|
||||||
DefaultListModel listModel = (DefaultListModel) photoList.getModel();
|
if (namesPhoto != null) {
|
||||||
listModel.removeAllElements();
|
photoList.removeAll();
|
||||||
photoList.setListData(namesPhoto);
|
photoList.setListData(namesPhoto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frame anzeigen
|
* Frame anzeigen
|
||||||
*/
|
*/
|
||||||
public void display() {
|
public void display() {
|
||||||
// nichts ver<EFBFBD>ndern
|
// nichts ver<EFBFBD>ndern
|
||||||
this.setSize(600,530);
|
this.setSize(600, 530);
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Daten eines Fotos in der Statuszeile der View anzeigen
|
* Daten eines Fotos in der Statuszeile der View anzeigen
|
||||||
* @param photoType ... Datentyp (als String)
|
*
|
||||||
* @param width ... Breite des Bildes (int)
|
* @param photoType ... Datentyp (als String)
|
||||||
* @param height ... H<EFBFBD>he des Bildes (int)
|
* @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
|
public void setData(String photoType, int width, int height) {
|
||||||
lblStatus.setText( String.format("Typ: %s, Bildgr<67><72>e: (%d,%d)", photoType, width, 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
|
* Erstellen eines Kuchendiagrammes mit 3 Segmenten. Die 3 Parameter
|
||||||
* geben die H<EFBFBD>ufigkeiten der Bildtypen an
|
* geben die H<EFBFBD>ufigkeiten der Bildtypen an
|
||||||
* @param raw
|
*
|
||||||
* @param jpeg
|
* @param raw
|
||||||
* @param gif
|
* @param jpeg
|
||||||
*/
|
* @param gif
|
||||||
public void displayGraph(float raw, float jpeg, float gif) {
|
*/
|
||||||
// TODO: Kuchendiagramm erzeugen und in graphPanel einf<EFBFBD>gen
|
public void displayGraph(float raw, float jpeg, float gif) {
|
||||||
//this.graphPanel.add(???);
|
// create a dataset...
|
||||||
|
DefaultPieDataset dataset = new DefaultPieDataset();
|
||||||
|
dataset.setValue("raw", raw);
|
||||||
|
dataset.setValue("jpeg", jpeg);
|
||||||
|
dataset.setValue("gif", gif);
|
||||||
|
|
||||||
// zum Neuzeichnen der Anwendung nach dem Einf<EFBFBD>gen - nicht <EFBFBD>ndern!
|
|
||||||
this.getContentPane().validate();
|
// create a chart...
|
||||||
this.getContentPane().repaint();
|
JFreeChart chart = ChartFactory.createPieChart(
|
||||||
}
|
"Das supergeile pie chart",
|
||||||
|
dataset,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
PiePlot plot = (PiePlot) chart.getPlot();
|
||||||
|
if (raw >= jpeg && raw >= gif) {
|
||||||
|
plot.setExplodePercent("raw", 0.10);
|
||||||
|
}
|
||||||
|
if (jpeg >= raw && jpeg >= gif) {
|
||||||
|
plot.setExplodePercent("jpeg", 0.10);
|
||||||
|
}
|
||||||
|
if (gif >= raw && gif >= jpeg){
|
||||||
|
plot.setExplodePercent("gif", 0.10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// create and display a frame...
|
||||||
|
ChartPanel frame = new ChartPanel(chart);
|
||||||
|
this.graphPanel.add(frame);
|
||||||
|
|
||||||
|
|
||||||
|
// zum Neuzeichnen der Anwendung nach dem Einf<EFBFBD>gen - nicht <EFBFBD>ndern!
|
||||||
|
this.getContentPane().validate();
|
||||||
|
this.getContentPane().repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
26
src/Medien.java
Normal file
26
src/Medien.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
public class Medien {
|
||||||
|
private String name;
|
||||||
|
private int rating;
|
||||||
|
private int nrused;
|
||||||
|
|
||||||
|
public Medien(String name, int rating, int nrused) {
|
||||||
|
this.name = name;
|
||||||
|
this.rating = rating;
|
||||||
|
this.nrused = nrused;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Medien() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRating() {
|
||||||
|
return rating;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNrused() {
|
||||||
|
return nrused;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user