Skip to content
Snippets Groups Projects
Commit 4000779c authored by Goik Martin's avatar Goik Martin
Browse files

New JavaFX base address project

parent 12721375
No related branches found
No related tags found
No related merge requests found
Showing with 487 additions and 0 deletions
/target/
/.settings/
.classpath
.project
On Maven import you will see:
Access restriction: The type 'ObservableList<Address>' is not API (restriction on required library '/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar')
You may get rid of these messages by manually removing and adding
the standard Java library to your Java build path.
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.hdm-stuttgart.mi.sd1</groupId>
<artifactId>address</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>address</name>
<!--Fixme: Add a sensible project related domain here -->
<url>http://somedomain.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
<configuration/>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>de.hdm_stuttgart.mi.sd1.goikstart.App</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package de.hdm_stuttgart.mi.sd1.address;
import static de.hdm_stuttgart.mi.sd1.address.model.Address.Column.FIRST_NAME;
import static de.hdm_stuttgart.mi.sd1.address.model.Address.Column.LAST_NAME;
import static de.hdm_stuttgart.mi.sd1.address.model.Address.Column.STREET;
import static de.hdm_stuttgart.mi.sd1.address.model.Address.Column.TEL;
import static de.hdm_stuttgart.mi.sd1.address.model.Address.Column.TOWN;
import static de.hdm_stuttgart.mi.sd1.address.model.Address.Column.ZIP;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.StackPane;
import de.hdm_stuttgart.mi.sd1.address.model.Address;
public class AddressListScene extends Scene {
final TableView<Address> addressTable = new TableView<Address>();
final ObservableList<Address> personData = FXCollections
.observableArrayList(new Address("Martin","Goik", "Nobelstr. 10", 70579, "Stuttgart", "0711 8923 2188"),
new Address("Jens","Hahn", "Nobelstr. 10", 70579, "Stuttgart", "0711 8923 2157"));
final TableColumn<Address, String> firstNameCol = new TableColumn <Address, String>(FIRST_NAME.extern);
final TableColumn<Address, String> lastNameCol = new TableColumn <Address, String>(LAST_NAME.extern);
final TableColumn<Address, String> street = new TableColumn <Address, String>(STREET.extern);
final TableColumn<Address, Integer> zip = new TableColumn <Address, Integer>(ZIP.extern);
final TableColumn<Address, String> town = new TableColumn <Address, String>(TOWN.extern);
final TableColumn<Address, String> tel = new TableColumn <Address, String>(TEL.extern);
public AddressListScene(Main parent) {
super(parent.root);
firstNameCol.setCellValueFactory(new PropertyValueFactory<Address, String>(FIRST_NAME.intern));
lastNameCol.setCellValueFactory(new PropertyValueFactory<Address, String>(LAST_NAME.intern));
street.setCellValueFactory(new PropertyValueFactory<Address, String>(STREET.intern));
zip.setCellValueFactory(new PropertyValueFactory<Address, Integer>(ZIP.intern));
town.setCellValueFactory(new PropertyValueFactory<Address, String>(TOWN.intern));
tel.setCellValueFactory(new PropertyValueFactory<Address, String>(TEL.intern));
addressTable.setItems(personData);
addressTable.getColumns().add(firstNameCol);
addressTable.getColumns().add(lastNameCol);
addressTable.getColumns().add(street);
addressTable.getColumns().add(zip);
addressTable.getColumns().add(town);
addressTable.getColumns().add(tel);
Button addAddress = new Button("Add address");
addAddress.setOnAction(event -> {
parent.addAddress();
});
StackPane basePane = new StackPane();
basePane.getChildren().addAll(addressTable, addAddress);
setRoot(basePane);
}
public void addAddress(final Address address) {
personData.add(address);
}
}
package de.hdm_stuttgart.mi.sd1.address;
import de.hdm_stuttgart.mi.sd1.address.security.Authenticator;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.layout.GridPane;
public class LoginScene extends Scene {
final Main parent;
public LoginScene(final Main parent) {
super(parent.root);
this.parent = parent;
final GridPane loginPane = new GridPane();
loginPane.setAlignment(Pos.CENTER);
loginPane.setHgap(10);
loginPane.setVgap(10);
loginPane.setPadding(new Insets(25, 25, 25, 25));
final Label enterPwLabel = new Label("Bitte Passwort eingeben:");
final PasswordField masterPw = new PasswordField();
loginPane.add(enterPwLabel, 0, 0);
loginPane.add(masterPw, 0, 1);
final Button cancel = new Button ("cancel");
cancel.setOnAction(event -> System.exit(0));
loginPane.add(cancel, 0, 2);
final Button oK = new Button ("oK");
oK.setDefaultButton(true);
oK.setOnAction(event -> {
if (Authenticator.validate(masterPw.getText())) {
parent.showAddresses();
} else {
System.exit(0);
}
});
loginPane.add(oK, 1, 2);
setRoot(loginPane);
}
}
package de.hdm_stuttgart.mi.sd1.address;
import javafx.application.Application;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
final StackPane root;
final LoginScene loginScene;
public final AddressListScene browseAddresses;
public final NewAddressScene newAddress;
Stage primaryStage;
public Main() {
root = new StackPane();
loginScene = new LoginScene(this);
newAddress = new NewAddressScene(this);
browseAddresses = new AddressListScene(this);
browseAddresses.getStylesheets().add(getClass().getResource("styles.css").toExternalForm());
}
@Override
public void start(final Stage primaryStage) {
this.primaryStage = primaryStage;
primaryStage.setTitle("Adressverwaltung");
primaryStage.setScene(loginScene);
primaryStage.show();
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
public void showAddresses() {
primaryStage.setScene(browseAddresses);
primaryStage.sizeToScene();
primaryStage.show();
}
public void addAddress() {
primaryStage.setScene(newAddress);
primaryStage.sizeToScene();
primaryStage.show();
}
}
\ No newline at end of file
package de.hdm_stuttgart.mi.sd1.address;
import static de.hdm_stuttgart.mi.sd1.address.model.Address.Column.FIRST_NAME;
import static de.hdm_stuttgart.mi.sd1.address.model.Address.Column.LAST_NAME;
import static de.hdm_stuttgart.mi.sd1.address.model.Address.Column.STREET;
import static de.hdm_stuttgart.mi.sd1.address.model.Address.Column.TEL;
import static de.hdm_stuttgart.mi.sd1.address.model.Address.Column.TOWN;
import static de.hdm_stuttgart.mi.sd1.address.model.Address.Column.ZIP;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import de.hdm_stuttgart.mi.sd1.address.model.Address;
public class NewAddressScene extends Scene {
final Main parent;
final TextField firstName = new TextField()
,lastName = new TextField()
,street = new TextField()
,zip = new TextField()
,town = new TextField()
,tel = new TextField()
;
public NewAddressScene(final Main parent) {
super(parent.root);
this.parent = parent;
final GridPane addressPane = new GridPane();
addressPane.setAlignment(Pos.CENTER);
addressPane.setHgap(10);
addressPane.setVgap(10);
addressPane.setPadding(new Insets(25, 25, 25, 25));
int rowIndex = 0;
addressPane.add(new Label(FIRST_NAME.extern), 0, rowIndex);
addressPane.add(firstName, 1, rowIndex++);
addressPane.add(new Label(LAST_NAME.extern),0 , rowIndex);
addressPane.add(lastName, 1 , rowIndex++);
addressPane.add(new Label(STREET.extern),0 , rowIndex);
addressPane.add(street, 1 , rowIndex++);
addressPane.add(new Label(ZIP.extern),0 , rowIndex);
addressPane.add(zip, 1 , rowIndex++);
addressPane.add(new Label(TOWN.extern),0 , rowIndex);
addressPane.add(town, 1 , rowIndex++);
addressPane.add(new Label(TEL.extern),0 , rowIndex);
addressPane.add(tel, 1 , rowIndex++);
final Button cancel = new Button ("cancel");
cancel.setOnAction(event -> System.exit(0));
addressPane.add(cancel, 0, rowIndex);
final Button oK = new Button ("oK");
oK.setDefaultButton(true);
oK.setOnAction(event -> {
final Address nAdr = new Address(firstName.getText(), lastName.getText(), street.getText(),
Integer.parseInt(zip.getText()), town.getText(), tel.getText());
parent.browseAddresses.addAddress(nAdr);
parent.showAddresses();
});
addressPane.add(oK, 1, rowIndex++);
setRoot(addressPane);
}
}
package de.hdm_stuttgart.mi.sd1.address.model;
public class Address implements Comparable<Address> {
public enum Column {
FIRST_NAME("firstName", "First name")
,LAST_NAME("lastName", "Last name")
,STREET("street", "Street")
,ZIP("zip", "Zip code")
,TOWN("town", "Town")
,TEL("lastName", "Last name")
;
Column(final String intern, final String extern) {
this.intern = intern;
this.extern = extern;
}
public final String
intern,
extern; // May become subject to internationalization
}
private String firstName;
private String lastName;
private String street;
private int zip;
private String town;
private String tel;
public Address(
final String firstName,
final String lastName,
final String street,
final int zip,
final String town,
final String tel) {
setFirstName(firstName);
setLastName(lastName);
setStreet(street);
setZip(zip);
setTown(town);
setTel(tel);
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public int getZip() {
return zip;
}
public void setZip(int zip) {
this.zip = zip;
}
public String getTown() {
return town;
}
public void setTown(String town) {
this.town = town;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
@Override
public int compareTo(Address other) {
return lastName.compareTo(other.lastName);
}
}
package de.hdm_stuttgart.mi.sd1.address.security;
public class Authenticator {
static public boolean validate(final String password ) {
return password != null && password.equals("p");
}
}
/* Application wide styles */
.label {
-fx-font-size: 12px;
-fx-font-weight: bold;
-fx-text-fill: #333333;
-fx-effect: dropshadow( gaussian , rgba(255,255,255,0.5) , 0,0,0,1 );
}
.button {
-fx-text-fill: white;
-fx-font-family: "Arial Narrow";
-fx-font-weight: bold;
-fx-background-color: linear-gradient(#61a2b1, #2A5058);
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 );
}
.button:hover{
-fx-background-color: #395bae;
}
/* Component specific styles */
.main-panel {
-fx-background-image: url("../images/background.jpg");
}
.hello-message {
-fx-text-fill: #AA0000;
-fx-font-weight: bold;
-fx-effect: dropshadow( gaussian , rgba(255,255,255,0.5) , 0,0,0,1 );
}
/* Have empty table cells disappear */
/* http://fxexperience.com/2011/11/alternate-row-highlighting-in-empty-tableview-and-listview-rows */
.table-row-cell:empty {
-fx-background-color: white;
}
.table-row-cell:empty .table-cell {
-fx-border-width: 0px;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment