Commit ed4fd0ed by Tuukka Kivilahti

select place via coordinates.

1 parent 87b56a89
...@@ -30,7 +30,6 @@ public class PlaceMapBean implements PlaceMapBeanLocal { ...@@ -30,7 +30,6 @@ public class PlaceMapBean implements PlaceMapBeanLocal {
public PlaceMapBean() { public PlaceMapBean() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
@EJB @EJB
private PlaceFacade placeFacade; private PlaceFacade placeFacade;
@EJB @EJB
...@@ -52,7 +51,7 @@ public class PlaceMapBean implements PlaceMapBeanLocal { ...@@ -52,7 +51,7 @@ public class PlaceMapBean implements PlaceMapBeanLocal {
if (place != null) { if (place != null) {
map = place.getMap(); map = place.getMap();
} else { } else {
map = eventMapFacade.find(eventId,mapId); map = eventMapFacade.find(eventId, mapId);
} }
BufferedImage image = map.getMapWithPlaces(); BufferedImage image = map.getMapWithPlaces();
...@@ -62,11 +61,12 @@ public class PlaceMapBean implements PlaceMapBeanLocal { ...@@ -62,11 +61,12 @@ public class PlaceMapBean implements PlaceMapBeanLocal {
if (user != null) { if (user != null) {
for (PlaceGroup uplacegroup : user.getPlaceGroups()) { for (PlaceGroup uplacegroup : user.getPlaceGroups()) {
for (Place uplace : uplacegroup.getPlaces()) for (Place uplace : uplacegroup.getPlaces()) {
uplace.drawOwnedPlace(image); uplace.drawOwnedPlace(image);
} }
} }
} }
}
if (place != null) { if (place != null) {
place.drawSelectedPlace(image); place.drawSelectedPlace(image);
...@@ -75,4 +75,6 @@ public class PlaceMapBean implements PlaceMapBeanLocal { ...@@ -75,4 +75,6 @@ public class PlaceMapBean implements PlaceMapBeanLocal {
ImageIO.write(image, filetype, outputStream); ImageIO.write(image, filetype, outputStream);
} }
} }
package fi.insomnia.bortal.beans; package fi.insomnia.bortal.beans;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import javax.ejb.Local; import javax.ejb.Local;
import fi.insomnia.bortal.model.Event; import fi.insomnia.bortal.model.Event;
import fi.insomnia.bortal.model.Place;
@Local @Local
public interface PlaceMapBeanLocal { public interface PlaceMapBeanLocal {
void printPlaceMapToStream(OutputStream outputStream, String filetype, Event event, Integer mapId, Integer userId, Integer placeId) throws IOException; void printPlaceMapToStream(OutputStream outputStream, String filetype, Event event, Integer mapId, Integer userId, Integer placeId) throws IOException;
} }
...@@ -11,7 +11,6 @@ public interface TestDataBeanLocal { ...@@ -11,7 +11,6 @@ public interface TestDataBeanLocal {
Event generateMetaData(); Event generateMetaData();
void generateTestPlaces(EventMap map); void generateTestPlaces(EventMap map);
} }
...@@ -28,30 +28,24 @@ import javax.persistence.Version; ...@@ -28,30 +28,24 @@ import javax.persistence.Version;
*/ */
@Entity @Entity
@Table(name = "maps") @Table(name = "maps")
@NamedQueries( { @NamedQueries({
@NamedQuery(name = "EventMap.findAll", query = "SELECT e FROM EventMap e"), @NamedQuery(name = "EventMap.findAll", query = "SELECT e FROM EventMap e"),
@NamedQuery(name = "EventMap.findByName", query = "SELECT e FROM EventMap e WHERE e.name = :name")})
@NamedQuery(name = "EventMap.findByName", query = "SELECT e FROM EventMap e WHERE e.name = :name") })
public class EventMap implements EventChildInterface { public class EventMap implements EventChildInterface {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@EmbeddedId @EmbeddedId
private EventPk id; private EventPk id;
@Lob @Lob
@Column(name = "map_data") @Column(name = "map_data")
private byte[] mapData; private byte[] mapData;
@Column(name = "map_name") @Column(name = "map_name")
private String name; private String name;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "map") @OneToMany(cascade = CascadeType.ALL, mappedBy = "map")
private List<Place> places; private List<Place> places;
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "event_id", referencedColumnName = "event_id", insertable = false, updatable = false, nullable = false) @JoinColumn(name = "event_id", referencedColumnName = "event_id", insertable = false, updatable = false, nullable = false)
private Event event; private Event event;
@Version @Version
@Column(nullable = false) @Column(nullable = false)
private int jpaVersionField = 0; private int jpaVersionField = 0;
...@@ -180,4 +174,19 @@ public class EventMap implements EventChildInterface { ...@@ -180,4 +174,19 @@ public class EventMap implements EventChildInterface {
return event; return event;
} }
public Place findPlace(int x, int y) {
for (Place place : getPlaces()) {
if (place.getMapX() < x
&& (place.getMapX() + place.getWidth()) > x
&& place.getMapY() < y
&& (place.getMapY() + place.getHeight()) > y) {
return place;
}
}
return null;
}
} }
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:role="http://java.sun.com/jsf/composite/tools/role">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form>
<h:commandButton image="#{mapView.selectPlaceMapUrl}" actionListener="#{mapView.placeSelectActionListener}" />
</h:form>
</composite:implementation>
</html>
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
*/ */
package fi.insomnia.bortal.servlet; package fi.insomnia.bortal.servlet;
import fi.insomnia.bortal.model.Place;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
......
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.insomnia.bortal.view;
import fi.insomnia.bortal.model.EventMap;
import fi.insomnia.bortal.model.Place;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
/**
*
* @author tuukka
*/
@ManagedBean(name = "mapView")
@SessionScoped
public class MapView {
private EventMap activeMap;
/** Creates a new instance of MapView */
public MapView() {
}
public void placeSelectActionListener(ActionEvent e) {
FacesContext context = FacesContext.getCurrentInstance();
String clientId = e.getComponent().getClientId(context);
Map requestParams = context.getExternalContext().getRequestParameterMap();
int x = new Integer((String) requestParams.get(clientId + ".x")).intValue();
int y = new Integer((String) requestParams.get(clientId + ".y")).intValue();
Place place = getActiveMap().findPlace(x, y);
throw new UnsupportedOperationException("We got place, but are doing nothing with it");
}
public String getSelectPlaceMapUrl() {
throw new UnsupportedOperationException("Return map url");
}
/**
* @return the activeMap
*/
public EventMap getActiveMap() {
return activeMap;
}
/**
* @param activeMap the activeMap to set
*/
public void setActiveMap(EventMap activeMap) {
this.activeMap = activeMap;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!