mirror of
https://github.com/13hannes11/archive.git
synced 2024-09-03 21:50:58 +02:00
added all past projects
This commit is contained in:
50
Java/Wettewerb_Foto/src/wettewerb_foto/Camera.java
Normal file
50
Java/Wettewerb_Foto/src/wettewerb_foto/Camera.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package wettewerb_foto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Camera {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private ArrayList<Image> images = new ArrayList();
|
||||
public Camera(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int countImages() {
|
||||
return getImages().size();
|
||||
}
|
||||
|
||||
public String writeLine() {
|
||||
String s = "";
|
||||
short i = 0;
|
||||
for (Image image : images) {
|
||||
s = s + this.name + " " + this.id + i + ";";
|
||||
s = s + image.getAbstand() + ";";
|
||||
s = s + image.getStreuung() + ";";
|
||||
s = s + System.getProperty("line.separator");
|
||||
i++;
|
||||
}
|
||||
s = s.replace(".", ",");
|
||||
return s;
|
||||
}
|
||||
|
||||
public void AddImage(String path) {
|
||||
Image tmp = new Image();
|
||||
|
||||
|
||||
tmp.Load(path);
|
||||
System.out.println(this.name + this.id + " loaded a new Image");
|
||||
getImages().add(tmp);
|
||||
|
||||
}
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return name + " " + id;
|
||||
}
|
||||
public ArrayList<Image> getImages() {
|
||||
return images;
|
||||
}
|
||||
}
|
||||
130
Java/Wettewerb_Foto/src/wettewerb_foto/Image.java
Normal file
130
Java/Wettewerb_Foto/src/wettewerb_foto/Image.java
Normal file
@@ -0,0 +1,130 @@
|
||||
package wettewerb_foto;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Image {
|
||||
|
||||
private int width = 0, height = 0;
|
||||
private double abstand, streuung;
|
||||
|
||||
//Streuung
|
||||
private void sigmaDist(double durchschnitt, ArrayList<Pixel> pMap) {
|
||||
double s = 0;
|
||||
for (int i = 0; i < pMap.size() - width; i++) {
|
||||
Pixel p = pMap.get(i);
|
||||
Pixel q = pMap.get(i + width);
|
||||
s = s + ((pixelDist(p, q) - durchschnitt) *
|
||||
(pixelDist(p, q) - durchschnitt));
|
||||
}
|
||||
streuung = Math.sqrt(s / (pMap.size() - width));
|
||||
}
|
||||
|
||||
private double pixelDist(Pixel p, Pixel q) {
|
||||
double d = Math.sqrt((p.r - q.r) * (p.r - q.r)
|
||||
+ (p.g - q.g) * (p.g - q.g)
|
||||
+ (p.b - q.b) * (p.b - q.b));
|
||||
return d;
|
||||
}
|
||||
|
||||
private void avgDist(ArrayList<Pixel> pMap) {
|
||||
double d = 0;
|
||||
for (int i = 0; i < pMap.size() - width; i++) {
|
||||
d = d + pixelDist(pMap.get(i), pMap.get(i + width));
|
||||
}
|
||||
abstand = d / (pMap.size() - width);
|
||||
}
|
||||
|
||||
private void compute(ArrayList<Pixel> pMap) {
|
||||
int size = pMap.size();
|
||||
avgDist(pMap);
|
||||
sigmaDist(abstand, pMap);
|
||||
//System.out.println(getAbstand());
|
||||
}
|
||||
//Lädt Image und gibt Farbspektrum zurück (um speicherplatz zu sparen)
|
||||
|
||||
public void Load(String path) {
|
||||
ArrayList<Pixel> pixelMap = new ArrayList();
|
||||
int i = 0;
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
br = new BufferedReader(new FileReader(path));
|
||||
|
||||
if (readHeader(br)) {
|
||||
while (br.ready()) {
|
||||
short r = (short) readInt(br);
|
||||
short g = (short) readInt(br);
|
||||
short b = (short) readInt(br);
|
||||
if (r >= 0 && g >= 0 && b >= 0) {
|
||||
pixelMap.add(new Pixel(i, r, g, b));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
compute(pixelMap);
|
||||
//return pixelMap;
|
||||
}
|
||||
|
||||
private boolean readHeader(BufferedReader br) {
|
||||
try {
|
||||
char c1 = (char) br.read();
|
||||
char c2 = (char) br.read();
|
||||
if (c1 == 'P' && c2 == '3') {
|
||||
width = readInt(br);
|
||||
height = readInt(br);
|
||||
int maxVal = readInt(br);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static char readNonwhiteChar(BufferedReader bf) throws IOException {
|
||||
char c;
|
||||
|
||||
do {
|
||||
c = (char) bf.read();
|
||||
} while (c == ' ' || c == '\t' || c == '\n' || c == '\r');
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
private int readInt(BufferedReader br) throws IOException {
|
||||
char c;
|
||||
int i;
|
||||
|
||||
c = readNonwhiteChar(br);
|
||||
i = 0;
|
||||
do {
|
||||
i = i * 10 + c - '0';
|
||||
c = (char) br.read();
|
||||
} while (c >= '0' && c <= '9');
|
||||
return i;
|
||||
}
|
||||
/**
|
||||
* @return the abstand
|
||||
*/
|
||||
public double getAbstand() {
|
||||
return abstand;
|
||||
}
|
||||
/**
|
||||
* @return the streuung
|
||||
*/
|
||||
public double getStreuung() {
|
||||
return streuung;
|
||||
}
|
||||
}
|
||||
125
Java/Wettewerb_Foto/src/wettewerb_foto/MainWindow.form
Normal file
125
Java/Wettewerb_Foto/src/wettewerb_foto/MainWindow.form
Normal file
@@ -0,0 +1,125 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" alignment="0" groupAlignment="1" max="-2" attributes="0">
|
||||
<Component id="export" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="unknownImage" alignment="0" pref="194" max="32767" attributes="0"/>
|
||||
<Component id="jScrollPane1" alignment="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="JaktuellLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="addImageButton" pref="194" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace min="0" pref="11" max="32767" attributes="0"/>
|
||||
<Component id="JaktuellLabel" min="-2" pref="9" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="addImageButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" min="-2" pref="118" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" min="-2" pref="9" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="unknownImage" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="export" min="-2" pref="23" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
|
||||
<AuxValues>
|
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JList" name="jList1">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
|
||||
<StringArray count="0"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="valueChanged" listener="javax.swing.event.ListSelectionListener" parameters="javax.swing.event.ListSelectionEvent" handler="jList1ValueChanged"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JButton" name="addImageButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Lade Bilder für Camera 1"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addImageButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabel1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Unbekanntes Bild: "/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="unknownImage">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Lade unbekanntes Bild"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="unknownImageActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="export">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Ergebnis exportieren"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="exportActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="JaktuellLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Anzahl der Bilder:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
287
Java/Wettewerb_Foto/src/wettewerb_foto/MainWindow.java
Normal file
287
Java/Wettewerb_Foto/src/wettewerb_foto/MainWindow.java
Normal file
@@ -0,0 +1,287 @@
|
||||
package wettewerb_foto;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.AbstractListModel;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.ListModel;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Hannes
|
||||
*/
|
||||
public class MainWindow extends javax.swing.JFrame {
|
||||
|
||||
static ArrayList<Camera> cam = new ArrayList();
|
||||
Camera uCam;
|
||||
|
||||
/**
|
||||
* Creates new form MainWindow
|
||||
*/
|
||||
public MainWindow() {
|
||||
initComponents();
|
||||
|
||||
|
||||
uCam = new Camera(0, "Unbekannt");
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
cam.add(new Camera(i, "Kamera"));
|
||||
}
|
||||
ListModel lm = new AbstractListModel() {
|
||||
@Override
|
||||
public int getSize() {
|
||||
return cam.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getElementAt(int i) {
|
||||
return cam.get(i);
|
||||
}
|
||||
};
|
||||
jList1.setModel(lm);
|
||||
jList1.setSelectedIndex(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
jList1 = new javax.swing.JList();
|
||||
addImageButton = new javax.swing.JButton();
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
unknownImage = new javax.swing.JButton();
|
||||
export = new javax.swing.JButton();
|
||||
JaktuellLabel = new javax.swing.JLabel();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
||||
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
|
||||
jList1ValueChanged(evt);
|
||||
}
|
||||
});
|
||||
jScrollPane1.setViewportView(jList1);
|
||||
|
||||
addImageButton.setText("Lade Bilder für Camera 1");
|
||||
addImageButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
addImageButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jLabel1.setText("Unbekanntes Bild: ");
|
||||
|
||||
unknownImage.setText("Lade unbekanntes Bild");
|
||||
unknownImage.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
unknownImageActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
export.setText("Ergebnis exportieren");
|
||||
export.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
exportActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
JaktuellLabel.setText("Anzahl der Bilder:");
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jLabel1)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
|
||||
.addComponent(export, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(unknownImage, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(JaktuellLabel)
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
.addComponent(addImageButton, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGap(0, 11, Short.MAX_VALUE)
|
||||
.addComponent(JaktuellLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(addImageButton)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(unknownImage)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(export, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void addImageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addImageButtonActionPerformed
|
||||
final JFileChooser fc = new JFileChooser();
|
||||
|
||||
FileNameExtensionFilter ppmFileFilter = new FileNameExtensionFilter("multiple selection recommended (*.ppm)", "ppm");
|
||||
fc.setFileFilter(ppmFileFilter);
|
||||
|
||||
//Allow Multiplefiles
|
||||
fc.setMultiSelectionEnabled(true);
|
||||
|
||||
int returnVal = fc.showOpenDialog(this);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File[] tmpFiles = fc.getSelectedFiles();
|
||||
for (int i = 0; i < tmpFiles.length; i++) {
|
||||
cam.get(jList1.getSelectedIndex()).AddImage(tmpFiles[i].getAbsolutePath());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
changeInfo();
|
||||
}//GEN-LAST:event_addImageButtonActionPerformed
|
||||
|
||||
private void unknownImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unknownImageActionPerformed
|
||||
uCam = new Camera(0, "Unbekannt");
|
||||
final JFileChooser fc = new JFileChooser();
|
||||
FileNameExtensionFilter ppmFileFilter = new FileNameExtensionFilter("PPM Images (*.ppm)", "ppm");
|
||||
fc.setFileFilter(ppmFileFilter);
|
||||
|
||||
|
||||
int returnVal = fc.showOpenDialog(this);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File tmpFile = fc.getSelectedFile();
|
||||
uCam.AddImage(tmpFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
jLabel1.setText("Unbekanntes Bild: " + uCam.countImages());
|
||||
}//GEN-LAST:event_unknownImageActionPerformed
|
||||
|
||||
private void exportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportActionPerformed
|
||||
//Open FileSaveDialo
|
||||
final JFileChooser fc = new JFileChooser();
|
||||
FileNameExtensionFilter ppmFileFilter = new FileNameExtensionFilter("Save as csv (*.csv)", "csv");
|
||||
fc.setFileFilter(ppmFileFilter);
|
||||
int returnVal = fc.showSaveDialog(this);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
try {
|
||||
//File Saving
|
||||
File tmpFile = fc.getSelectedFile();
|
||||
createCSV(tmpFile.getParent(), tmpFile.getName() + ".csv");
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
}//GEN-LAST:event_exportActionPerformed
|
||||
|
||||
private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
|
||||
changeInfo();
|
||||
}//GEN-LAST:event_jList1ValueChanged
|
||||
public void createCSV(String path, String filename) throws IOException {
|
||||
File file = new File(path, filename);
|
||||
if (!file.isFile() && !file.createNewFile()) {
|
||||
throw new IOException("Error creating new file: " + file.getAbsolutePath());
|
||||
}
|
||||
try {
|
||||
FileWriter writer = new FileWriter(path + "\\" + filename);
|
||||
|
||||
writer.append("Foto;Durchschnittlicher Abstand; Streuung" + System.getProperty("line.separator"));
|
||||
|
||||
for (int i = 0; i < cam.size(); i++) {
|
||||
writeLine(writer, cam.get(i));
|
||||
}
|
||||
|
||||
writeLine(writer, uCam);
|
||||
|
||||
|
||||
System.out.println("Written Data to File");
|
||||
|
||||
//generate whatever data you want
|
||||
|
||||
writer.flush();
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static FileWriter writeLine(FileWriter writer, Camera camera) throws IOException {
|
||||
writer.append(camera.writeLine());
|
||||
return writer;
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
*/
|
||||
try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new MainWindow().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JLabel JaktuellLabel;
|
||||
private javax.swing.JButton addImageButton;
|
||||
private javax.swing.JButton export;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JList jList1;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JButton unknownImage;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
private void changeInfo() {
|
||||
Camera c = cam.get(jList1.getSelectedIndex());
|
||||
JaktuellLabel.setText("Anzahl der Bilder: " + c.countImages());
|
||||
addImageButton.setText("Lade Bilder für " + c);
|
||||
}
|
||||
}
|
||||
11
Java/Wettewerb_Foto/src/wettewerb_foto/Pixel.java
Normal file
11
Java/Wettewerb_Foto/src/wettewerb_foto/Pixel.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package wettewerb_foto;
|
||||
|
||||
public class Pixel {
|
||||
short r,g,b;
|
||||
public Pixel(int id,short R, short G, short B)
|
||||
{
|
||||
r = R;
|
||||
g = G;
|
||||
b = B;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user