finished d-f
This commit is contained in:
parent
acc9602214
commit
84658670ad
@ -1,32 +1,16 @@
|
||||
public class Foto {
|
||||
private String name;
|
||||
private int ref1;
|
||||
private int ref2;
|
||||
public class Foto extends Medien {
|
||||
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;
|
||||
public Foto(String name, int rating, int nrused, String fileformat, int height, int width) {
|
||||
super(name, rating, nrused);
|
||||
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 Foto() {
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
|
@ -2,16 +2,16 @@ import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
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<>();
|
||||
ArrayList<Foto> fotocollection = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
@ -31,10 +31,8 @@ public class MediaController implements ActionListener, ListSelectionListener {
|
||||
String[] getNamesPhoto() {
|
||||
String[] strar = new String[fotocollection.size()];
|
||||
|
||||
int i = 0;
|
||||
for (Foto ft: fotocollection) {
|
||||
strar[i] = ft.getName();
|
||||
i++;
|
||||
for (int i = 0; i < fotocollection.size(); i++) {
|
||||
strar[i] = fotocollection.get(i).getName();
|
||||
}
|
||||
|
||||
return strar;
|
||||
@ -68,12 +66,15 @@ public class MediaController implements ActionListener, ListSelectionListener {
|
||||
Foto ft = new Foto(spl[0],
|
||||
Integer.parseInt(spl[1]),
|
||||
Integer.parseInt(spl[2]),
|
||||
spl[3],
|
||||
Integer.parseInt(spl[4]),
|
||||
Integer.parseInt(spl[5]),
|
||||
spl[3]);
|
||||
Integer.parseInt(spl[5])
|
||||
);
|
||||
|
||||
fotocollection.add(ft);
|
||||
mv.setPhotoList(getNamesPhoto());
|
||||
} catch (NumberFormatException ee) {
|
||||
showPopup(ee.getMessage());
|
||||
throw new WrongFileFormatException("parse error- no integer in file column");
|
||||
}
|
||||
}
|
||||
@ -84,6 +85,7 @@ public class MediaController implements ActionListener, ListSelectionListener {
|
||||
ioException.printStackTrace();
|
||||
} catch (WrongFileFormatException en) {
|
||||
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") {
|
||||
// TODO: die Häufigkeiten der Fotoformate muss berechnet 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
|
||||
*/
|
||||
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,15 +1,13 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.ScrollPane;
|
||||
import java.awt.event.ActionListener;
|
||||
import org.jfree.chart.ChartFactory;
|
||||
import org.jfree.chart.ChartPanel;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.chart.plot.PiePlot;
|
||||
import org.jfree.data.general.DefaultPieDataset;
|
||||
|
||||
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.*;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class MediaView extends JFrame {
|
||||
JList<String> photoList = new JList<>();
|
||||
@ -24,6 +22,7 @@ public class MediaView extends JFrame {
|
||||
|
||||
/**
|
||||
* Konstruktor
|
||||
*
|
||||
* @param al
|
||||
* @param lsl
|
||||
*/
|
||||
@ -47,13 +46,13 @@ public class MediaView extends JFrame {
|
||||
|
||||
/**
|
||||
* 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.removeAll();
|
||||
photoList.setListData(namesPhoto);
|
||||
}
|
||||
}
|
||||
@ -70,6 +69,7 @@ public class MediaView extends JFrame {
|
||||
|
||||
/**
|
||||
* 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)
|
||||
@ -82,13 +82,44 @@ public class MediaView extends JFrame {
|
||||
/**
|
||||
* 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(???);
|
||||
// create a dataset...
|
||||
DefaultPieDataset dataset = new DefaultPieDataset();
|
||||
dataset.setValue("raw", raw);
|
||||
dataset.setValue("jpeg", jpeg);
|
||||
dataset.setValue("gif", gif);
|
||||
|
||||
|
||||
// create a chart...
|
||||
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();
|
||||
|
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