Example usage for org.apache.wicket.markup.html.image.resource BufferedDynamicImageResource BufferedDynamicImageResource

List of usage examples for org.apache.wicket.markup.html.image.resource BufferedDynamicImageResource BufferedDynamicImageResource

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.image.resource BufferedDynamicImageResource BufferedDynamicImageResource.

Prototype

public BufferedDynamicImageResource() 

Source Link

Document

Construct.

Usage

From source file:com.servoy.extensions.beans.dbtreeview.WicketTreeNodeStyleAdapter.java

License:Open Source License

/**
 * Creates the node image resource ref/*  w  w w .java 2 s.co m*/
 * 
 * @param treeNode
 * @return image resource ref
 */
public static ResourceReference imageResource(final Icon nodeIcon) {
    if (nodeIcon != null) {
        return new ResourceReference(nodeIcon.toString()) {
            private static final long serialVersionUID = 1L;

            @Override
            protected Resource newResource() {
                BufferedDynamicImageResource imgRes = new BufferedDynamicImageResource();

                imgRes.setImage(ImageLoader.imageToBufferedImage(((ImageIcon) nodeIcon).getImage()));

                return imgRes;
            }
        };
    }

    return null;
}

From source file:com.servoy.j2db.server.headlessclient.dataui.SortableCellViewHeader.java

License:Open Source License

/**
 * Construct.//from w w w .  j a va  2  s  .com
 * 
 * @param id The component's id
 * @param group The group of headers the new one will be added to
 * @param cellview
 */
public SortableCellViewHeader(Form form, final WebCellBasedView view, final String id,
        final SortableCellViewHeaderGroup group, AbstractBase cellview, boolean useAJAX,
        IApplication application) {
    super(id);
    this.id = id;
    this.cellview = cellview;
    this.view = view;
    this.application = application;
    this.form = form;

    headerColumnTable = new WebMarkupContainer("headerColumnTable"); //$NON-NLS-1$
    headerColumnTable.add(labelResolver = new LabelResolverLink("sortLink", useAJAX, group, id)); //$NON-NLS-1$
    labelResolver.add(new AttributeModifier("class", true, group)); //$NON-NLS-1$
    labelResolver
            .add(new StyleAppendingModifier(new Model<String>("white-space: nowrap;text-overflow: clip;")));
    boolean hasBgImage = false;
    // append background image in case of labelFor for the current label (goes through all labelFor components in the map to get the component by name )
    GraphicalComponent labelFor = getLabelComponent();
    if (labelFor != null) {
        Pair<IStyleSheet, IStyleRule> pair = ComponentFactory.getStyleForBasicComponent(application, labelFor,
                form);
        IStyleRule cssRule = pair == null || pair.getRight() == null ? null : pair.getRight();
        if (cssRule != null && cssRule.hasAttribute(CSS.Attribute.BACKGROUND_IMAGE.toString())) {
            TextualStyle headerStyle = new TextualStyle();
            headerStyle.setProperty(CSS.Attribute.BACKGROUND_IMAGE.toString(),
                    cssRule.getValues(CSS.Attribute.BACKGROUND_IMAGE.toString()), true);
            String text = headerStyle.getValuesAsString(null);
            WebClient webClient = ((WebClientSession) Session.get()).getWebClient();
            text = StripHTMLTagsConverter.convertMediaReferences(text, webClient.getSolutionName(),
                    new ResourceReference("media"), "", false).toString();
            add(new StyleAppendingModifier(new Model<String>(text)));
            hasBgImage = true;
        }
    }

    ChangesRecorder changesRecorder = new ChangesRecorder();
    changesRecorder.setBorder(view.getHeaderBorder());
    String inlineStyleStr = view.getHeaderBgColorStyle();

    if (view.getHeaderBorder() != null) {
        add(new StyleAppendingModifier(new Model<String>("border-right: none; padding: 0px;"))); //$NON-NLS-1$
    }

    final Properties changes = changesRecorder.getChanges();
    if (changes.size() > 0)
        applyStyleChanges(headerColumnTable, changes);
    if (inlineStyleStr != null)
        applyInlineStyleString(this, inlineStyleStr);

    inlineStyleStr = view.getHeaderBgImageStyle();
    if (inlineStyleStr != null)
        applyInlineStyleString(headerColumnTable, inlineStyleStr);

    //margin is applied to LabelResolverLink on the label (to mimic Label component margin behavior)

    ChangesRecorder textChangesRecorder = new ChangesRecorder();
    textChangesRecorder.setFont(view.getHeaderFont());
    inlineStyleStr = view.getHeaderFgColorStyle();

    final Properties textChanges = textChangesRecorder.getChanges();
    if (textChanges.size() > 0)
        applyStyleChanges(labelResolver, textChanges);
    if (inlineStyleStr != null)
        applyInlineStyleString(labelResolver, inlineStyleStr);

    boolean blockResize = false;

    Iterator<IPersist> iter = cellview.getAllObjects();
    while (iter.hasNext()) {
        IPersist element = iter.next();
        if (element instanceof ISupportAnchors) {
            if (id.equals(ComponentFactory.getWebID(form, element))) {
                int anchors = ((ISupportAnchors) element).getAnchors();
                if (((anchors & IAnchorConstants.EAST) == 0) || ((anchors & IAnchorConstants.WEST) == 0)) {
                    blockResize = true;
                }

                isUnmovable = ((anchors & IAnchorConstants.NORTH) == IAnchorConstants.NORTH)
                        && ((anchors & IAnchorConstants.SOUTH) == IAnchorConstants.SOUTH);
                break;
            }
        }
    }

    if (((!(cellview instanceof Portal) || ((Portal) cellview).getReorderable()) && useAJAX)
            && !isUnmovable()) {
        DraggableBehavior dragMoveBehavior = new DraggableBehavior() {
            private int startX;

            @Override
            protected void onDragEnd(String componentId, int x, int y, int m,
                    AjaxRequestTarget ajaxRequestTarget) {
                view.moveColumn(SortableCellViewHeader.this, x - startX, ajaxRequestTarget);
                labelResolver.setDropped(true);
            }

            @Override
            protected boolean onDragStart(String componentId, int x, int y, int m,
                    AjaxRequestTarget ajaxRequestTarget) {
                startX = x;
                return true;
            }

            @Override
            protected void onDrop(String componentId, String targetid, int x, int y, int m,
                    AjaxRequestTarget ajaxRequestTarget) {
                // TODO Auto-generated method stub

            }

            @Override
            protected void onDropHover(String componentId, String targeid, int m,
                    AjaxRequestTarget ajaxRequestTarget) {
                // TODO Auto-generated method stub

            }
        };
        dragMoveBehavior.setRenderOnHead(false);
        dragMoveBehavior.setYConstraint(true);
        dragMoveBehavior.setUseProxy(true);
        dragMoveBehavior.setResizeProxyFrame(true);
        headerColumnTable.add(dragMoveBehavior);
    } else if (isUnmovable()) {
        headerColumnTable.add(new SimpleAttributeModifier("ondragstart", "return false;"));
    }

    if (cellview instanceof Portal && !((Portal) cellview).getSortable()) {
        labelResolver.setSortable(false);
        resizeBar = new WebMarkupContainer("resizeBar"); //$NON-NLS-1$
    } else {
        resizeBar = new Image("resizeBar", view.R_ARROW_OFF); //$NON-NLS-1$
    }

    if (!blockResize && (!(cellview instanceof Portal) || ((Portal) cellview).getResizeble()) && useAJAX) {
        DraggableBehavior dragResizeBehavior = new DraggableBehavior() {
            private int startX;

            @Override
            protected void onDragEnd(String componentId, int x, int y, int m,
                    AjaxRequestTarget ajaxRequestTarget) {
                view.resizeColumn(SortableCellViewHeader.this, x - startX);
            }

            @Override
            protected boolean onDragStart(String componentId, int x, int y, int m,
                    AjaxRequestTarget ajaxRequestTarget) {
                startX = x;
                return true;
            }

            @Override
            protected void onDrop(String componentId, String targetid, int x, int y, int m,
                    AjaxRequestTarget ajaxRequestTarget) {
            }

            @Override
            protected void onDropHover(String componentId, String targeid, int m,
                    AjaxRequestTarget ajaxRequestTarget) {
            }
        };
        dragResizeBehavior.setRenderOnHead(false);
        dragResizeBehavior.setYConstraint(true);
        resizeBar.add(dragResizeBehavior);
        resizeBar.add(new AttributeModifier("style", true, new Model<String>("cursor: col-resize;"))); //$NON-NLS-1$ //$NON-NLS-2$
    } else {
        resizeBar.add(new AttributeModifier("style", true, new Model<String>("cursor: pointer;"))); //$NON-NLS-1$ //$NON-NLS-2$
    }

    headerColumnTable.add(resizeBar);
    add(headerColumnTable);

    try {
        Iterator<IPersist> it2 = cellview.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
        int height = -1;
        while (it2.hasNext()) {
            IPersist element = it2.next();
            if (id.equals(ComponentFactory.getWebID(form, element))) {
                final GraphicalComponent gc = (GraphicalComponent) view.labelsFor
                        .get(((ISupportName) element).getName());
                if (gc != null && height < 0) {
                    height = gc.getSize().height;
                }
                if (gc != null && gc.getImageMediaID() > 0) {
                    final int media_id = gc.getImageMediaID();
                    final Media media = application.getFlattenedSolution().getMedia(media_id);
                    if (media != null) {
                        hasBgImage = true;
                        final int headerHeight = height;
                        Pair<IStyleSheet, IStyleRule> pair = labelFor != null
                                ? ComponentFactory.getStyleForBasicComponent(application, labelFor, form)
                                : null;
                        final IStyleRule cssRule = pair == null || pair.getRight() == null ? null
                                : pair.getRight();
                        add(new StyleAppendingModifier(new Model<String>() {
                            @Override
                            public String getObject() {
                                ResourceReference iconReference = new ResourceReference(media.getName()) {
                                    private static final long serialVersionUID = 1L;

                                    @Override
                                    protected Resource newResource() {
                                        BufferedDynamicImageResource imgRes = new BufferedDynamicImageResource();
                                        MediaResource tempIcon = new MediaResource(media.getMediaData(),
                                                gc.getMediaOptions());
                                        (tempIcon).checkResize(new Dimension(width, headerHeight));
                                        ImageIcon icon = new ImageIcon(tempIcon.resized);
                                        imgRes.setImage(ImageLoader.imageToBufferedImage((icon).getImage()));

                                        return imgRes;
                                    }
                                };

                                TextualStyle style = new TextualStyle();
                                style.setProperty(CSS.Attribute.BACKGROUND_REPEAT.toString(), "no-repeat"); //$NON-NLS-1$
                                style.setProperty(CSS.Attribute.BACKGROUND_POSITION.toString(), "center right"); //$NON-NLS-1$
                                if (cssRule != null) {
                                    if (cssRule.hasAttribute(CSS.Attribute.BACKGROUND.toString()))
                                        style.setProperty(CSS.Attribute.BACKGROUND.toString(),
                                                cssRule.getValue(CSS.Attribute.BACKGROUND.toString()));
                                    if (cssRule.hasAttribute(CSS.Attribute.BACKGROUND_ATTACHMENT.toString()))
                                        style.setProperty(CSS.Attribute.BACKGROUND_ATTACHMENT.toString(),
                                                cssRule.getValue(
                                                        CSS.Attribute.BACKGROUND_ATTACHMENT.toString()));
                                    if (cssRule.hasAttribute(CSS.Attribute.BACKGROUND_COLOR.toString()))
                                        style.setProperty(CSS.Attribute.BACKGROUND_COLOR.toString(),
                                                cssRule.getValue(CSS.Attribute.BACKGROUND_COLOR.toString()));
                                    if (cssRule.hasAttribute(CSS.Attribute.BACKGROUND_POSITION.toString()))
                                        style.setProperty(CSS.Attribute.BACKGROUND_POSITION.toString(),
                                                cssRule.getValue(CSS.Attribute.BACKGROUND_POSITION.toString()),
                                                true);
                                    if (cssRule.hasAttribute(CSS.Attribute.BACKGROUND_REPEAT.toString()))
                                        style.setProperty(CSS.Attribute.BACKGROUND_REPEAT.toString(),
                                                cssRule.getValue(CSS.Attribute.BACKGROUND_REPEAT.toString()),
                                                true);
                                }
                                style.setProperty(CSS.Attribute.BACKGROUND_IMAGE.toString(),
                                        "url(" + urlFor(iconReference) + "?id=" + media_id + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                                return style.getValuesAsString(null);
                            }
                        }));
                    }

                } else if (gc != null && gc.getToolTipText() != null) {
                    tooltip = application.getI18NMessageIfPrefixed(gc.getToolTipText());
                    add(TooltipAttributeModifier.INSTANCE);
                }
                if (gc != null) {
                    int style_valign = -1;
                    Pair<IStyleSheet, IStyleRule> styleInfo = ComponentFactory
                            .getStyleForBasicComponent(application, gc, form);
                    if (styleInfo != null) {
                        IStyleSheet ss = styleInfo.getLeft();
                        IStyleRule s = styleInfo.getRight();
                        if (ss != null && s != null) {
                            style_valign = ss.getVAlign(s);
                        }
                    }
                    final int styleValign = style_valign;
                    add(new StyleAppendingModifier(new Model<String>() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public String getObject() {
                            int valign = ISupportTextSetup.CENTER;
                            if (gc.getVerticalAlignment() >= 0) {
                                valign = gc.getVerticalAlignment();
                            } else if (styleValign >= 0) {
                                valign = styleValign;
                            }
                            return "vertical-align:" + TemplateGenerator.getVerticalAlignValue(valign) + ";"; //$NON-NLS-1$//$NON-NLS-2$
                        }
                    }));
                }
                if (gc != null && gc.getOnRightClickMethodID() > 0) {
                    executor = new WebEventExecutor(this, useAJAX);
                    executor.setRightClickCmd(String.valueOf(gc.getOnRightClickMethodID()), null);
                    labelName = gc.getName();
                }
            }
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
    if (labelFor != null && hasBgImage && labelFor.getOnActionMethodID() > 0) {
        add(new AttributeModifier("onclick", true, new Model<String>(
                "var target = event.target || event.srcElement; var aEl = this.getElementsByTagName('a')[0]; if($(target).parents('#'+aEl.id).length == 0) { aEl.click(); }")));
    }
    Boolean dir = group.get(id);
    if (dir != null && form.getOnSortCmdMethodID() >= 0) {
        setResizeImage(dir ? view.R_ARROW_DOWN : view.R_ARROW_UP);
    }
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.history.HistoryPage.java

License:Apache License

private void getChartImage() {

    List<DownloadStatistic> topDownloadedFilesList = historyFacade.getTopDownloadHistory(choice, isGroupAdmin,
            groupId);//from w  ww. java 2 s.c  o  m
    long countOfFilesHistory = historyFacade.getCountOfFilesHistory(choice, isGroupAdmin, groupId);

    BufferedImage chart = ChartUtils.gererateChartForTopDownloadHistory(choice, groupId == -1 ? true : false,
            topDownloadedFilesList, countOfFilesHistory);

    BufferedDynamicImageResource res = new BufferedDynamicImageResource();
    res.setImage(chart);

    if (chartImage == null)
        chartImage = new NonCachingImage("chart", res);
    else
        chartImage.setImageResource(res);

    chartImage.setOutputMarkupId(true);
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.security.RegistrationForm.java

License:Apache License

private void generateCaptchaImageAndPrepareValidation() {

    // TODO create own captcha component with using this captcha service.
    String captcha = StringUtils.getCaptchaString();
    getModelObject().setCaptcha(captcha);

    BufferedImage image = captchaService.getImageChallengeForID(captcha, getLocale());
    BufferedDynamicImageResource res = new BufferedDynamicImageResource();
    res.setImage(image);/*from  w w  w  .  jav  a  2  s  .co  m*/

    if (captchaImage == null)
        captchaImage = new NonCachingImage("captchaImage", res);
    else
        captchaImage.setImageResource(res);

    captchaImage.setOutputMarkupId(true);

}

From source file:gr.abiss.calipso.wicket.AttachmentLinkPanel.java

License:Open Source License

public AttachmentLinkPanel(String id, final Attachment attachment, boolean addHeadScript) {
    super(id);// w  ww .j  av a2  s  .  c  o  m
    if (addHeadScript) {
        renderSighslideDirScript();
    }
    WebMarkupContainer attachmentContainer = new WebMarkupContainer("attachmentContainer");
    add(attachmentContainer);
    if (attachment == null) {
        attachmentContainer.setVisible(false);
        return;
    }
    final String fileName = getResponse().encodeURL(attachment.getFileName()).toString();
    String downloadLabel = null;
    WebMarkupContainer imageAttachmentContainer = new WebMarkupContainer("imageAttachment");
    attachmentContainer.add(imageAttachmentContainer);
    // if attachment is image, preview it
    if (fileName.endsWith(".png") || fileName.endsWith(".gif") || fileName.endsWith(".bmp")
            || fileName.endsWith(".jpeg") || fileName.endsWith(".jpg")) {
        BufferedImage icon = null;
        // read image
        try {
            File imageFileThumb = new File(getCalipso().getCalipsoHome() + File.separator
                    + attachment.getBasePath() + File.separator + "thumb_" + attachment.getFileName());
            if (imageFileThumb.exists()) {
                icon = ImageIO.read(imageFileThumb);
            }
        } catch (IOException e) {
            throw new RuntimeException("Unable to read thumb image", e);
        }
        // render html
        if (icon != null) {
            BufferedDynamicImageResource iconResource = new BufferedDynamicImageResource();
            iconResource.setImage(icon);
            Image image = new Image("imageThumb", iconResource);
            Link imageAttachmentLink = new Link("attachment") {
                // adapted from wicket.markup.html.link.DownloadLink
                // with the difference that the File is instantiated only
                // after onClick
                public void onClick() {
                    getRequestCycle().scheduleRequestHandlerAfterCurrent(new IRequestHandler() {

                        public void respond(IRequestCycle requestCycle) {
                            WebResponse r = (WebResponse) requestCycle.getResponse();
                            r.setAttachmentHeader(fileName);
                            try {
                                File previewfile = new File(getCalipso().getCalipsoHome() + File.separator
                                        + attachment.getBasePath() + File.separator + "small_"
                                        + attachment.getFileName());
                                logger.info("Looking for previewfile path: " + previewfile.getAbsolutePath());
                                InputStream is = new FileInputStream(previewfile);
                                try {
                                    Streams.copy(is, r.getOutputStream());
                                } catch (IOException e) {
                                    throw new RuntimeException(e);
                                } finally {
                                    try {
                                        is.close();
                                    } catch (IOException e) {
                                        throw new RuntimeException(e);
                                    }
                                }
                            } catch (FileNotFoundException e) {
                                throw new RuntimeException(e);
                            }
                        }

                        public void detach(IRequestCycle requestCycle) {
                            // TODO Auto-generated method stub

                        }
                    });
                }
            };
            imageAttachmentLink.add(image);
            imageAttachmentContainer.add(imageAttachmentLink);
            downloadLabel = attachment.isSimple() ? attachment.getOriginalFileName()
                    : localize("item_view_form.download");
        } else {
            imageAttachmentContainer.setVisible(false);
        }
    } else {
        imageAttachmentContainer.setVisible(false);
    }
    // attachment link
    Link link = new Link("attachment") {
        // adapted from wicket.markup.html.link.DownloadLink
        // with the difference that the File is instantiated only after
        // onClick
        public void onClick() {
            getRequestCycle().scheduleRequestHandlerAfterCurrent(new IRequestHandler() {

                public void respond(IRequestCycle requestCycle) {
                    WebResponse r = (WebResponse) requestCycle.getResponse();
                    try {
                        String ua = ((WebRequest) requestCycle.getRequest()).getHeader("User-Agent");
                        boolean isMSIE = (ua != null && ua.indexOf("MSIE") != -1);
                        logger.debug("Client browser is IE - " + isMSIE);
                        if (isMSIE) {
                            r.setAttachmentHeader(
                                    URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"));
                        } else {
                            // This works in FireFox - NEW W3C STANDART
                            // See
                            // http://greenbytes.de/tech/webdav/draft-reschke-rfc2231-in-http-latest.html#RFC2231
                            r.setHeader("Content-Disposition",
                                    "attachment; filename*=UTF-8''" + URLEncoder.encode(
                                            attachment.isSimple() ? attachment.getOriginalFileName() : fileName,
                                            "UTF-8").replaceAll("\\+", "%20"));
                        }
                        r.setContentType(MimeTable.getDefaultTable().getContentTypeFor(fileName));
                    } catch (UnsupportedEncodingException e1) {
                        logger.error("Error encoding", e1);
                        r.setAttachmentHeader(fileName);
                    }
                    try {
                        File file = AttachmentUtils.getSavedAttachmentFile(attachment,
                                getCalipso().getCalipsoHome());
                        InputStream is = new FileInputStream(file);
                        try {
                            Streams.copy(is, r.getOutputStream());
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        } finally {
                            try {
                                is.close();
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }
                        }
                    } catch (FileNotFoundException e) {
                        throw new RuntimeException(e);
                    }
                }

                public void detach(IRequestCycle requestCycle) {
                    // TODO Auto-generated method stub

                }
            });
        }
    };
    if (downloadLabel == null) {
        downloadLabel = fileName;
    }
    link.add(new Label("fileName", downloadLabel));
    attachmentContainer.add(link);
}

From source file:gr.abiss.calipso.wicket.IconPanel.java

License:Open Source License

public void addIcon(String id, IModel idModel, String iconsFolderName, boolean getSmall) {

    BufferedImage icon = null;//from  ww w. j a v a  2 s.  c om
    long iconId = (Long) idModel.getObject();

    if (iconId != 0) {
        //get image folder path
        String iconFolderPath = CalipsoPropertiesEditor.getHomeFolder(new StringBuffer(iconsFolderName)
                .append(File.separator).append("id").append(iconId).toString());
        File iconFile;
        if (getSmall) {
            iconFile = new File(new StringBuffer(iconFolderPath).append(File.separator).append("icon_small.png")
                    .toString());
        } else {
            iconFile = new File(
                    new StringBuffer(iconFolderPath).append(File.separator).append("icon.png").toString());
        }

        //read image           
        try {
            icon = ImageIO.read(iconFile);
        } catch (IOException e) {
        }
    }

    //modify css classes for the span tag
    SimpleAttributeModifier sam;
    if (getSmall) {
        sam = new SimpleAttributeModifier("class", "iconSmall");
    } else {
        sam = new SimpleAttributeModifier("class", "icon");
    }

    //render html
    if (icon != null) {
        BufferedDynamicImageResource iconResource = new BufferedDynamicImageResource();
        iconResource.setImage(icon);
        Image image = new Image("icon", iconResource);
        image.add(sam);

        add(image);
    } else {
        WebMarkupContainer defaultImage = new WebMarkupContainer("icon");
        if (getSmall) {// if small render the small icon
            defaultImage.add(new SimpleAttributeModifier("src",
                    "../resources/default-" + iconsFolderName + "-icon-small.png"));
        } else {
            defaultImage.add(new SimpleAttributeModifier("src",
                    "../resources/default-" + iconsFolderName + "-icon.png"));
        }
        defaultImage.add(sam);
        add(defaultImage);
    }

}

From source file:name.martingeisse.webide.features.verilog.wave.WaveEditorPanel.java

License:Open Source License

/**
 * Constructor./*from w w  w  . ja  v a 2  s. c  o m*/
 * @param id the wicket id
 * @param model the document model
 */
public WaveEditorPanel(final String id, final IModel<ValueChangeDump> model) {
    super(id, model);

    long length = 0;
    for (ValueChangeDump.Variable variable : model.getObject().getVariables()) {
        long variableLength = variable.getLastChangeTime();
        if (variableLength > length) {
            length = variableLength;
        }
        System.out.println("*** " + variable.getOriginalIdentifier());
    }
    this.totalLength = (int) length;

    add(new ListView<ValueChangeDump.Variable>("variables", model.getObject().getVariables()) {
        @Override
        protected void populateItem(final ListItem<ValueChangeDump.Variable> item) {
            ValueChangeDump.Variable variable = item.getModelObject();
            WaveRenderer renderer = new WaveRenderer(totalLength + 100, 16, variable.getValueChanges());
            BufferedDynamicImageResource resource = new BufferedDynamicImageResource();
            BufferedImageBackend imageBackend = (BufferedImageBackend) renderer
                    .render(BufferedImageBackendType.instance);
            resource.setImage(imageBackend.getBufferedImage());
            item.add(new Label("name", variable.getOriginalIdentifier()));
            item.add(new Image("wave", resource));
        }
    });
}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.isisapplib.IsisBlobOrClobPanelAbstract.java

License:Apache License

private Image asWicketImage(String id) {

    final ObjectAdapter adapter = getModel().getObject();
    if (adapter == null) {
        return null;
    }/*w w  w  .j  ava  2 s  .  c  o  m*/

    final Object object = adapter.getObject();
    if (!(object instanceof Blob)) {
        return null;
    }

    final Blob blob = (Blob) object;
    final MimeType mimeType = blob.getMimeType();
    if (mimeType == null || !mimeType.getPrimaryType().equals("image")) {
        return null;
    }

    final BufferedImage image = asBufferedImage(blob);
    if (image == null) {
        return null;
    }

    final BufferedDynamicImageResource imageResource = new BufferedDynamicImageResource();
    imageResource.setImage(image);
    final ThumbnailImageResource thumbnailImageResource = new ThumbnailImageResource(imageResource, 300);

    final NonCachingImage wicketImage = new NonCachingImage(id, thumbnailImageResource);
    return wicketImage;
}

From source file:org.geoserver.monitor.web.ActivityChartBasePanel.java

License:Open Source License

BufferedDynamicImageResource queryAndRenderChart(Monitor monitor, Date[] range) {
    Query q = new Query();
    q.properties("startTime").between(range[0], range[1]);

    DataGatherer gatherer = new DataGatherer();
    monitor.query(q, gatherer);//  w ww. ja  va2s  .c  o m

    HashMap<RegularTimePeriod, Integer> data = gatherer.getData();

    Class timeUnitClass = getTimePeriod(range[0]).getClass();
    TimeSeries series = new TimeSeries("foo", timeUnitClass);
    for (Map.Entry<RegularTimePeriod, Integer> d : data.entrySet()) {
        series.add(new TimeSeriesDataItem(d.getKey(), d.getValue()));
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection(series);

    final JFreeChart chart = createTimeSeriesChart(getChartTitle(range),
            "Time (" + timeUnitClass.getSimpleName() + ")", "Requests", dataset);

    BufferedDynamicImageResource resource = new BufferedDynamicImageResource();
    resource.setImage(chart.createBufferedImage(700, 500));
    return resource;
}

From source file:org.geoserver.monitor.web.OWSSummaryChartBasePanel.java

License:Open Source License

public OWSSummaryChartBasePanel(String id, Monitor monitor, String owsService) {
    super(id);//ww  w.j a  va 2 s. c o  m

    this.owsService = owsService;

    Map<String, Integer> data = gatherData(monitor);

    DefaultPieDataset dataset = new DefaultPieDataset();
    for (Map.Entry<String, Integer> e : data.entrySet()) {
        dataset.setValue(e.getKey(), e.getValue());
    }

    JFreeChart chart = ChartFactory.createPieChart(getChartTitle(), dataset, true, true, false);
    chart.setBackgroundPaint(Color.WHITE);

    BufferedDynamicImageResource resource = new BufferedDynamicImageResource();
    resource.setImage(chart.createBufferedImage(650, 500));

    add(new NonCachingImage("chart", resource));

}