Skip to content

Commit

Permalink
GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
aieozn committed Jan 16, 2019
1 parent f7dffe8 commit 9234901
Show file tree
Hide file tree
Showing 10 changed files with 509 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<name>net.sourceforge.metrics.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sourceforge.metrics.builder</name>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Każdą operacje dotyczącą jednego obiektu należy zakończyć **ID oczekiwane
Dostępne operacje:

* **building** - Wyświetla informacje o wszystkich elementach,
* **building/new/** - Dodaje nowy budynek zgodnie z danymi w formacie JSON
* **GUI/** - Otwiera GUI które pozwala na wprowadzanie nowych budynków do systemu
* **GUI/new/** - Dodaje nowy budynek zgodnie z danymi w formacie JSON
* **getRoomArea** - Wyświetla powierzchnię pokoju,
* **getLevelArea** - Wyświetla powierzchnię poziomu,
* **getBuildingArea** - Wyświetla powierzchnię budynku,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import pl.put.poznan.building_info.structures.Location;
import pl.put.poznan.building_info.structures.Room;
import pl.put.poznan.building_info.structures.Building;
import pl.put.poznan.building_info.structures.BuildingContent;
import pl.put.poznan.building_info.structures.Level;
import pl.put.poznan.building_info.structures.Collection;
import pl.put.poznan.building_info.structures.BuildingContent;
import pl.put.poznan.building_info.structures.LevelContent;
import pl.put.poznan.building_info.structures.Value;
import pl.put.poznan.building_info.structures.allLocations;
import pl.put.poznan.building_info.info.Result;
Expand Down Expand Up @@ -77,19 +80,24 @@ public ArrayList<Building> createSomeData(){

//Change new building elements ID's and add building to existing data structures

public Result addBuilding(Building newBuilding){
public Result addBuilding(BuildingContent newBuildingContent){
int baseID = currentID;

Building newBuilding = newBuildingContent.getBiuiding();
newBuilding.setID(currentID);
currentID ++;

for (Level level : newBuilding.getLevels()) {
for (LevelContent levelContent : newBuildingContent.getLevelContent()) {
Level level = levelContent.getLevel();
level.setID(currentID);
currentID ++;
newBuilding.addLevel(level);

for (Room room : level.getRooms()) {
for (Room room : levelContent.getRooms()) {
room.setID(currentID);
room.calcParamsAgain();
currentID ++;
level.addRoom(room);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@
import java.util.Arrays;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Type;

import pl.put.poznan.building_info.structures.Location;
import pl.put.poznan.building_info.structures.Room;
import pl.put.poznan.building_info.structures.Building;
import pl.put.poznan.building_info.structures.BuildingContent;
import pl.put.poznan.building_info.structures.Level;
import pl.put.poznan.building_info.structures.LevelContent;
import pl.put.poznan.building_info.info.Result;
import pl.put.poznan.building_info.structures.Collection;
import pl.put.poznan.building_info.structures.Value;
Expand All @@ -30,14 +39,42 @@ public class BuildingInfoController {
param newBuilding JSON format building object
@return JSON response
*/
@RequestMapping(value = "/building/new/", method = RequestMethod.POST, produces = "application/json")
@RequestMapping(value = "/GUI/new/", method = RequestMethod.POST, produces = "text/html")
public String createBuilding(@RequestBody String newBuilding) {

System.out.println(newBuilding);
Gson g = new Gson();
Building newBuildingObj = g.fromJson(newBuilding, Building.class);
Result result = transformer.addBuilding(newBuildingObj);
g = null;
return result.getAsJsonString();
BuildingContent newBuildingObj = g.fromJson(newBuilding, BuildingContent.class);

return transformer.addBuilding(newBuildingObj).getAsJsonString();
}

/**
* Open GUI for adding new buildings
* @param locationId
* @return
*/
@RequestMapping(value = "/GUI/", method = RequestMethod.GET, produces = "text/html")
public String GUI(@RequestParam(value = "id", required = false) String locationId) {

File file = new File("src/main/resources/newBuilding.html");
FileInputStream fis;
try {
fis = new FileInputStream(file);
byte[] data = new byte[(int) file.length()];
fis.read(data);
fis.close();
String str = new String(data, "UTF-8");
return str;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package pl.put.poznan.building_info.structures;
import java.util.ArrayList;
import java.util.List;

public class BuildingContent{

private Building building;
private ArrayList<LevelContent> levels = new ArrayList<LevelContent>();

public BuildingContent(Building b){
this.building = b;
}

public void addLevelContent(LevelContent l){
levels.add(l);
}

public Building getBiuiding(){
return building;
}

public ArrayList<LevelContent> getLevelContent(){
return levels;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package pl.put.poznan.building_info.structures;
import java.util.ArrayList;
import java.util.List;

public class LevelContent{
private Level level;
private ArrayList<Room> rooms = new ArrayList<Room>();

public LevelContent(Level l){
level = l;
}

public Level getLevel(){
return level;
}

public ArrayList<Room> getRooms(){
return rooms;
}

public void addRooms(ArrayList<Room> rooms){
this.rooms = rooms;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public boolean isRoom(){
return true;
}

public void calcParamsAgain(){
this.area = length * width;
this.cube = this.area * height;
}

/**
* <p>Zwraca zuzycie energii na ogrzewanie pokoju</p>
*/
Expand Down
Loading

0 comments on commit 9234901

Please sign in to comment.