Commit 62bc311b by Tuukka Kivilahti

paikkakooditulostus

1 parent b2593292
......@@ -82,14 +82,18 @@ public class BarcodeBean implements BarcodeBeanLocal {
sb.append(PLACE_PREFIX);
String idStr = place.getId().toString();
for (int i = 12 - idStr.length() - sb.length(); i > 0; --i) {
for (int i = 8 - idStr.length() - sb.length(); i > 0; --i) {
sb.append("0");
}
sb.append(idStr);
String barcode = sb.toString();
String hexcode = Integer.toHexString(Integer.parseInt(barcode));
String hexcode = Long.toHexString(Long.parseLong(barcode));
String checksum = Integer.toHexString(hexcode.hashCode());
checksum = checksum.substring(checksum.length() -3);
hexcode += checksum;
logger.debug("Geneating hexcode for place {} : {}", place.getId(), hexcode);
......
......@@ -537,12 +537,12 @@ public class PlaceBean implements PlaceBeanLocal {
font.setSize(font1);
TextLine textLine = new TextLine(font);
textLine.setText(place.getCode());
textLine.setPosition(3, 3);
textLine.setText(place.getName());
textLine.setPosition(5, 15);
textLine.setColor(new double[] { 0, 0, 0 });
textLine.drawOn(page);
double currentX = font1 * 4;
double currentX = 42;
// nick
if(place.getPlaceReserver() != null && place.getPlaceReserver().getUser() != null) {
......@@ -551,7 +551,7 @@ public class PlaceBean implements PlaceBeanLocal {
textLine = new TextLine(font);
textLine.setText(place.getPlaceReserver().getUser().getNick());
textLine.setPosition(currentX, 3);
textLine.setPosition(currentX, 15);
textLine.setColor(new double[] { 0, 0, 0 });
textLine.drawOn(page);
}
......@@ -562,7 +562,7 @@ public class PlaceBean implements PlaceBeanLocal {
textLine = new TextLine(font);
textLine.setText( barcodeBean.getPlaceHexcode(place));
textLine.setPosition(currentX, (height / 2));
textLine.setPosition(currentX, (pagey / 2)+font1);
textLine.setColor(new double[] { 0, 0, 0 });
textLine.drawOn(page);
......
package fi.codecrew.moya.beans;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.imageio.ImageIO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.pdfjet.CoreFont;
import com.pdfjet.Image;
import com.pdfjet.ImageType;
import com.pdfjet.PDF;
import com.pdfjet.Page;
import com.pdfjet.TextLine;
import fi.codecrew.moya.facade.EventMapFacade;
import fi.codecrew.moya.facade.PlaceFacade;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PlaceMapBeanLocal;
import fi.codecrew.moya.model.CardTemplate;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.util.MassPrintResult;
/**
* Session Bean implementation class PlaceMapBean
......@@ -63,4 +78,51 @@ public class PlaceMapBean implements PlaceMapBeanLocal {
}
return null;
}
/*
wanha, poistoon
public byte[] placeCodesPdf(List<Place> places) {
// double[] pageSize = new double[] { cardBackground.getWidth(),
// cardBackground.getHeight() };
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PDF pdf;
try {
pdf = new PDF(outputStream);
pdf.setTitle("placecodes");
double pagex = 155.9;
double pagey = 48;
Page page = new Page(pdf, new double[] { pagex, pagey });
// Render texts
// Big font for nick
com.pdfjet.Font font = new com.pdfjet.Font(pdf, CoreFont.HELVETICA);
font.setSize(8.0);
TextLine line = new TextLine(font);
line.setText("testi");
line.setPosition(1, 1);
line.setColor(new double[] { 1.0, 1.0, 1.0 });
line.drawOn(page);
pdf.flush();
outputStream.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return outputStream.toByteArray();
}
*/
}
package fi.codecrew.moya.beans;
import java.util.List;
import javax.ejb.Local;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.Place;
@Local
public interface PlaceMapBeanLocal {
......@@ -17,6 +20,9 @@ public interface PlaceMapBeanLocal {
public Long availablePlaceCount(EventMap activeMap);
public EventMap getActiveMap();
// wanha poistoon, see placebean
// public byte[] placeCodesPdf(List<Place> places);
// public List<Place> findSelectedPlaces(EventMap map);
......
......@@ -28,6 +28,12 @@
<p:fileUpload mode="simple" value="#{mapManageView.bgFile}" />
<h:commandButton action="#{mapManageView.submitBg}" value="#{i18n['map.submitMap']}" />
</h:form>
<h:form>
<p:commandButton id="downloadLink" value="koodipdf" ajax="false" >
<p:fileDownload value="#{mapManageView.streamedFile}" />
</p:commandButton>
</h:form>
</ui:define>
</ui:composition>
</h:body>
......
package fi.codecrew.moya.web.cdiview.map;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -10,6 +11,8 @@ import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Named;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.primefaces.model.UploadedFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -71,6 +74,8 @@ public class MapManageView extends GenericCDIView {
private String namebase;
private Integer mapId;
private List<Product> productlist;
private StreamedContent streamedFile;
private LanEvent copyEvent;
......@@ -86,7 +91,10 @@ public class MapManageView extends GenericCDIView {
map = eventmapBean.find(getMapId());
setProductlist(productbean.getProducts());
super.beginConversation();
streamedFile = new DefaultStreamedContent(new ByteArrayInputStream(placebean.generatePlacesPdf(54, 17, 18, 15)),"application/pdf", "paikkakoodit");
}
}
......@@ -340,4 +348,14 @@ public class MapManageView extends GenericCDIView {
public void setBgFile(UploadedFile bgFile) {
this.bgFile = bgFile;
}
//StreamedContent new DefaultStreamedContent(pdfstream)
public StreamedContent getStreamedFile() {
//DefaultStreamedContent(new ByteArrayInputStream(placebean.generatePlacesPdf(54, 17, 10, 6)));
return streamedFile;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!