software engeneering übungen, lösungen etc

This commit is contained in:
Ulf Gebhardt 2013-12-19 18:14:34 +01:00
parent 4ed3749b75
commit b0d9662d87
248 changed files with 1872 additions and 0 deletions

View File

@ -0,0 +1,437 @@
/** License (BSD Style License):
* Copyright (c) 2010
* Software Engineering
* Department of Computer Science
* Technische Universität Darmstadt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the Software Engineering Group or Technische
* Universität Darmstadt nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.tud.cs.se.flashcards.ui;
import java.awt.BorderLayout;
import java.awt.FileDialog;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import de.tud.cs.se.flashcards.model.Flashcard;
import de.tud.cs.se.flashcards.model.FlashcardSeries;
import de.tud.cs.se.flashcards.persistence.Store;
/**
* A Frame is always associated with exactly one document and it is the parent
* of all related dialogs etc.
*
* @author Michael Eichberg
* @author Ralf Mitschke
*/
public class FlashcardsWindow {
// The UI components:
private final JFrame frame;
private final JMenuBar menuBar;
private final JMenu fileMenu;
private final JMenuItem newFileMenuItem;
private final JMenuItem openFileMenuItem;
private final JMenuItem saveFileMenuItem;
private final JMenuItem saveAsFileMenuItem;
private final JMenuItem closeFileMenuItem;
private final JToolBar toolbar;
private final JButton addButton;
private final JButton removeButton;
private final JButton editButton;
private final JButton playButton;
private final JScrollPane listScrollPane;
private final JList list;
private final FlashcardEditor flashcardEditor;
private final LearnDialog learnDialog;
private final FileDialog fileDialog;
// State of the editor:
private final FlashcardSeries series;
private File file;
protected FlashcardsWindow(File file) throws IOException {
this(Store.openSeries(file));
this.file = file;
Utilities.setFrameTitle(frame, file);
}
public static boolean createFlashcardsEditor(File file) {
try {
new FlashcardsWindow(file);
return true;
} catch (Exception e) {
JOptionPane.showMessageDialog(
null,
"The document \"" + file.getName()
+ "\" could not be read." + "\n"
+ e.getLocalizedMessage(), "",
JOptionPane.WARNING_MESSAGE);
return false;
}
}
public FlashcardsWindow(FlashcardSeries series) {
/*
* General Design Decision(s):
*
* ActionListener do not contain domain logic; they always delegate to
* corresponding methods.
*
* All errors are handled as early as possible.
*
* A Frame is associated with exactly one FlashcardSeries.
*/
this.series = series;
// setup of this frame; we need to do it here since the rootpane's
// client property has to set before the other components are created
frame = new JFrame();
frame.getRootPane().putClientProperty("apple.awt.brushMetalLook",
java.lang.Boolean.TRUE);
Utilities.setFrameTitle(frame, file);
// dialogs and other components that are related to this frame
flashcardEditor = new FlashcardEditor(this);
learnDialog = new LearnDialog(this);
fileDialog = new java.awt.FileDialog(frame);
fileDialog.setFilenameFilter(new FilenameFilter() {
public boolean accept(File directory, String name) {
return name.endsWith(Store.FILE_ENDING);
}
});
// setup the menu and its listeners
newFileMenuItem = new JMenuItem("New");
newFileMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
// TODO Implement the functionality to create an empty flashcard series in a new FlashcardsEditor Window
openFileMenuItem = new JMenuItem("Open File...");
openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
openFileMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
openFlashcardSeries();
}
});
saveFileMenuItem = new JMenuItem("Save");
saveFileMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
saveFileMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
saveFlashcardSeries();
}
});
saveAsFileMenuItem = new JMenuItem("Save As...");
saveAsFileMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
(java.awt.event.InputEvent.SHIFT_MASK | Toolkit
.getDefaultToolkit().getMenuShortcutKeyMask())));
saveAsFileMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
saveAsFlashcardSeries();
}
});
closeFileMenuItem = new JMenuItem("Close Window");
closeFileMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
closeFileMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
closeFlashcardEditor();
}
});
fileMenu = new JMenu("File");
fileMenu.add(newFileMenuItem);
fileMenu.addSeparator();
fileMenu.add(openFileMenuItem);
fileMenu.addSeparator();
fileMenu.add(saveFileMenuItem);
fileMenu.add(saveAsFileMenuItem);
fileMenu.addSeparator();
fileMenu.add(closeFileMenuItem);
menuBar = new JMenuBar();
menuBar.add(fileMenu);
addButton = Utilities.createToolBarButton(" Create ", "list-add.png",
"create new flashcard");
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
createFlashcard();
}
});
removeButton = Utilities.createToolBarButton(" Delete ",
"list-remove.png", "remove selected flashcards");
removeButton.setEnabled(false);
removeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
removeFlashcards();
}
});
editButton = Utilities.createToolBarButton(" Edit ",
"accessories-text-editor.png", "edit selected flashcard");
editButton.setEnabled(false);
editButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
editFlashcard();
}
});
list = new JList(series);
// TODO Add a cell renderer to render flashcards.
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent event) {
// Only GUI related functionality:
if (list.getSelectedIndex() != -1) {
removeButton.setEnabled(true);
editButton.setEnabled(true);
} else {
removeButton.setEnabled(false);
editButton.setEnabled(false);
}
}
});
listScrollPane = new JScrollPane(list);
listScrollPane.setBorder(BorderFactory.createEmptyBorder());
listScrollPane
.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
playButton = Utilities.createToolBarButton(" Learn ",
"media-playback-start.png", "learn flashcards");
playButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
learn();
}
});
// TODO Disable the playButton if the series contains no flashcards.
toolbar = new JToolBar();
toolbar.putClientProperty("JToolBar.isRollover", Boolean.FALSE);
toolbar.add(addButton);
toolbar.add(removeButton);
toolbar.addSeparator();
toolbar.add(editButton);
toolbar.add(Box.createHorizontalGlue());
toolbar.add(playButton);
toolbar.setFloatable(false);
frame.setJMenuBar(menuBar);
frame.getContentPane().add(listScrollPane);
frame.getContentPane().add(toolbar, BorderLayout.NORTH);
frame.setSize(640, 480);
frame.setLocationByPlatform(true);
frame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent event) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// we have to make sure that the JFrame object will be
// collected...
// (the VM terminates if all frames are disposed and
// finally collected)
System.gc();
}
});
}
});
// Everything is setup; show the window:
frame.setVisible(true);
}
// Implementation of the "logic":
public FlashcardSeries getSeries() {
return series;
}
public JFrame getFrame() {
return frame;
}
protected void openFlashcardSeries() {
fileDialog.setMode(FileDialog.LOAD);
fileDialog.setVisible(true);
String filename = fileDialog.getFile();
if (filename != null) {
if (!filename.endsWith(Store.FILE_ENDING))
filename += Store.FILE_ENDING;
File file = new File(fileDialog.getDirectory(), filename);
createFlashcardsEditor(file);
}
}
protected void saveFlashcardSeries() {
if (file == null)
saveAsFlashcardSeries();
else
doSave(file);
}
protected void saveAsFlashcardSeries() {
fileDialog.setMode(FileDialog.SAVE);
fileDialog.setVisible(true);
String filename = fileDialog.getFile();
if (filename != null) {
if (!filename.endsWith(Store.FILE_ENDING))
filename += Store.FILE_ENDING;
File newFile = new File(fileDialog.getDirectory(), filename);
if (newFile.exists()) {
if (JOptionPane
.showConfirmDialog(
frame,
"The file with the name:\n"
+ filename
+ "\nalready exists.\nDo you want to overwrite the file?",
"Warning", JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE) == JOptionPane.NO_OPTION)
return;
}
doSave(newFile);
}
}
protected void doSave(File file) {
try {
Store.saveSeries(series, file);
// Saving the file was successful:
this.file = file;
Utilities.setFrameTitle(frame, file);
} catch (IOException e) {
JOptionPane.showMessageDialog(frame, "Could not save flashcards",
"Saving the flashcards to :\n" + file.getName()
+ "\nfailed.", JOptionPane.ERROR_MESSAGE);
}
}
public void learn() {
learnDialog.show();
}
protected void closeFlashcardEditor() {
frame.setVisible(false);
frame.dispose(); // required to give up all resources
}
protected void createFlashcard() {
Flashcard card = new Flashcard();
if (flashcardEditor.edit(card))
series.addCard(card);
}
protected void removeFlashcards() {
FlashcardsWindow.this.series.removeCards(list.getSelectedIndices());
list.clearSelection();
}
protected void editFlashcard() {
int index = list.getSelectedIndex();
flashcardEditor.edit(series.getElementAt(index));
}
}

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 930 B

After

Width:  |  Height:  |  Size: 930 B

View File

Before

Width:  |  Height:  |  Size: 601 B

After

Width:  |  Height:  |  Size: 601 B

View File

Before

Width:  |  Height:  |  Size: 317 B

After

Width:  |  Height:  |  Size: 317 B

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>EiSE-Exercise08</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>EiSE-Exercise01</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

Binary file not shown.

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 150 KiB

After

Width:  |  Height:  |  Size: 150 KiB

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>EiSE-Exercise02</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

Binary file not shown.

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>EiSE-Exercise03</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 113 KiB

After

Width:  |  Height:  |  Size: 113 KiB

View File

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="lib/commons-io-1.4.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Some files were not shown because too many files have changed in this diff Show More