コード例 #1
0
ファイル: JDownloader.java プロジェクト: jforge/jain-I18n
 /** Download actual file */
 public void download() {
   StreamResource resource = new StreamResource(source, fileName);
   resource
       .getStream()
       .setParameter("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
   resource.setMIMEType("application/octet-stream");
   resource.setCacheTime(0);
   FileDownloader downloader = new FileDownloader(resource);
   downloader.extend(ui);
 }
コード例 #2
0
ファイル: ParkingUI.java プロジェクト: AwAkEd/parking-demo
  private void showNonMobileNotification() {
    try {
      URL appUrl = Page.getCurrent().getLocation().toURL();
      String myIp = Inet4Address.getLocalHost().getHostAddress();
      final String qrCodeUrl = appUrl.toString().replaceAll("localhost", myIp);

      Label info =
          new Label(
              "You appear to be running this demo on a non-portable device. "
                  + "Parking is intended for touch devices primarily. "
                  + "Please read the QR code on your touch device to access the demo.");
      info.setWidth("310px");

      Image qrCode = new Image();
      qrCode.addStyleName("qrcode-image");
      StreamResource resource =
          new StreamResource(
              new StreamSource() {
                @Override
                public InputStream getStream() {
                  InputStream result = null;
                  try {
                    final Map<EncodeHintType, ErrorCorrectionLevel> hintMap = Maps.newHashMap();
                    hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
                    final QRCodeWriter qrCodeWriter = new QRCodeWriter();
                    final BitMatrix byteMatrix =
                        qrCodeWriter.encode(qrCodeUrl, BarcodeFormat.QR_CODE, 150, 150, hintMap);
                    final int width = byteMatrix.getWidth();
                    final BufferedImage image =
                        new BufferedImage(width, width, BufferedImage.TYPE_INT_RGB);
                    image.createGraphics();

                    final Graphics2D graphics = (Graphics2D) image.getGraphics();
                    graphics.setColor(Color.WHITE);
                    graphics.fillRect(0, 0, width, width);
                    graphics.setColor(Color.BLACK);

                    for (int i = 0; i < width; i++) {
                      for (int j = 0; j < width; j++) {
                        if (byteMatrix.get(i, j)) {
                          graphics.fillRect(i, j, 1, 1);
                        }
                      }
                    }
                    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    try {
                      ImageIO.write(image, "png", baos);
                    } catch (final IOException e) {
                      e.printStackTrace();
                    }
                    result = new ByteArrayInputStream(baos.toByteArray());

                  } catch (WriterException e) {
                    e.printStackTrace();
                  }
                  return result;
                }
              },
              "qrcode-" + new Date().getTime() + ".png");
      resource.setCacheTime(0);
      qrCode.setSource(resource);

      CssLayout qrCodeLayout = new CssLayout(qrCode, info);
      qrCodeLayout.setSizeFull();

      Window window = new Window(null, qrCodeLayout);
      window.setWidth(500.0f, Unit.PIXELS);
      window.setHeight(200.0f, Unit.PIXELS);
      window.addStyleName("qr-code");
      window.setModal(true);
      window.setResizable(false);
      window.setDraggable(false);
      addWindow(window);
      window.center();
    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (UnknownHostException e) {
      e.printStackTrace();
    }
  }
コード例 #3
0
ファイル: MyVaadinUI.java プロジェクト: koa/Marathontabelle
  @Override
  protected void init(final VaadinRequest request) {
    final TabSheet tabLayout = new TabSheet();
    final VerticalLayout layout = new VerticalLayout();
    layout.addComponent(tabLayout);
    setContent(layout);

    final BinderCollection<MarathonData> binders = new BinderCollection<MarathonData>();

    binders.commitHandler();

    final FormLayout competitionParameters = new FormLayout();
    binders.appendBinder(showOverviewData(competitionParameters));
    tabLayout.addTab(competitionParameters, "Übersicht");

    final FormLayout phaseATabContent = new FormLayout();
    binders.appendBinder(showPhaseData(phaseATabContent, Phase.A));
    tabLayout.addTab(phaseATabContent, "Phase A");

    final FormLayout phaseDTabContent = new FormLayout();
    binders.appendBinder(showPhaseData(phaseDTabContent, Phase.D));
    tabLayout.addTab(phaseDTabContent, "Phase D");

    final FormLayout phaseETabContent = new FormLayout();
    binders.appendBinder(showPhaseData(phaseETabContent, Phase.E));
    tabLayout.addTab(phaseETabContent, "Phase E");

    final VerticalLayout outputLayout = new VerticalLayout();
    final FormLayout outputParameters = new FormLayout();

    final BeanItemContainer<String> driverDataSource = new BeanItemContainer<String>(String.class);
    final ComboBox selectDriverCombo = new ComboBox("Fahrer", driverDataSource);
    selectDriverCombo.setNewItemsAllowed(false);
    selectDriverCombo.setImmediate(true);
    outputLayout.addComponent(selectDriverCombo);
    binders.appendBinder(
        new DataBinder<MarathonData>() {

          private MarathonData data;

          @Override
          public void bindData(final MarathonData data) {
            this.data = data;
            driverDataSource.removeAllItems();
            driverDataSource.addAll(data.getDrivers().keySet());
          }

          @Override
          public void commitHandler() {}

          @Override
          public MarathonData getCurrentData() {
            return data;
          }
        });

    // new Button("Erstelle PDF");

    outputLayout.setSizeFull();
    outputLayout.addComponent(outputParameters);
    outputLayout.setExpandRatio(outputParameters, 0);

    final MarathonData marathonData = loadMarathonData("default");
    binders.bindData(marathonData);

    final StreamResource source =
        new StreamResource(
            new StreamSource() {

              @Override
              public InputStream getStream() {
                final ByteArrayOutputStream os = new ByteArrayOutputStream();
                new GeneratePdf()
                    .makePdf(os, binders.getCurrentData(), (String) selectDriverCombo.getValue());
                return new ByteArrayInputStream(os.toByteArray());
              }
            },
            makeOutputFilename());
    source.setMIMEType("application/pdf");
    final BrowserFrame pdf = new BrowserFrame("Output", source);
    pdf.setSizeFull();
    outputLayout.addComponent(pdf);
    outputLayout.setExpandRatio(pdf, 1);
    tabLayout.addTab(outputLayout, "Resultat");
    tabLayout.setSizeFull();
    layout.setExpandRatio(tabLayout, 1);

    layout.setSizeFull();

    selectDriverCombo.addValueChangeListener(
        new ValueChangeListener() {

          @Override
          public void valueChange(final ValueChangeEvent event) {
            binders.commitHandler();
            saveMarathonData(binders.getCurrentData());
            source.setFilename(makeOutputFilename());
            pdf.markAsDirty();
          }
        });

    final Button saveButton =
        new Button(
            "Übernehmen",
            new ClickListener() {
              @Override
              public void buttonClick(final ClickEvent event) {
                binders.commitHandler();
                saveMarathonData(binders.getCurrentData());
                source.setFilename(makeOutputFilename());
                pdf.markAsDirty();
              }
            });
    layout.addComponent(saveButton);
  }
コード例 #4
0
  @Override
  public void execute() {
    List<ChangeRecord> historyList = view.getUi().getStockService().findChanges(good);
    Window subWindow = new Window();
    subWindow.setModal(true);
    subWindow.setHeight("650px");
    subWindow.setWidth("700px");
    subWindow.setClosable(true);
    view.getUi().addWindow(subWindow);

    final Button pdfButton = new Button(bundle.getString("pdf.export"));
    pdfButton.setIcon(new ThemeResource("img/pdf.png"));
    pdfButton.setWidth("150");
    StreamResource pdfStream = getPDFStream(view.getUi().getStockService().findChanges(good));
    pdfStream.setMIMEType("application/pdf");
    FileDownloader pdfDownloader = new FileDownloader(pdfStream);
    pdfDownloader.extend(pdfButton);

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.addComponent(pdfButton);

    for (ChangeRecord record : historyList) {
      for (ChangeRecord.PropertyChange p : record.getChangeList()) {
        p.setName(bundle.getString(p.getName()));
      }
      Panel panel = new Panel();
      BeanItemContainer<ChangeRecord.PropertyChange> container =
          new BeanItemContainer<>(ChangeRecord.PropertyChange.class, record.getChangeList());
      Table table = new Table();
      table.setContainerDataSource(container);
      table.setVisibleColumns("name", "oldValue", "newValue");
      table.setColumnHeaders(
          bundle.getString("history.property"),
          bundle.getString("history.old"),
          bundle.getString("history.new"));
      table.setColumnExpandRatio("name", 0.33f);
      table.setColumnExpandRatio("oldValue", 0.33f);
      table.setColumnExpandRatio("newValue", 0.33f);
      table.setPageLength(0);
      table.setWidth("100%");

      VerticalLayout panelLayout = new VerticalLayout();
      panelLayout.addComponent(
          new Label(
              "<b>"
                  + new SimpleDateFormat("dd-MM-YYYY HH:mm").format(record.getDate())
                  + ": "
                  + record.getUser().getName()
                  + " "
                  + record.getUser().getSurname()
                  + "</b><br/>",
              ContentMode.HTML));
      panelLayout.addComponent(table);
      panel.setContent(panelLayout);
      layout.addComponent(panel);
    }

    subWindow.setContent(layout);
  }