Search in sources :

Example 1 with MouseEvent

use of org.zkoss.zk.ui.event.MouseEvent in project adempiere by adempiere.

the class WChartEditor method render.

private void render(JFreeChart chart) {
    ChartRenderingInfo info = new ChartRenderingInfo();
    int width = 400;
    int height = chartModel.getWinHeight();
    BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info);
    try {
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);
        AImage image = new AImage("", bytes);
        Imagemap myImage = new Imagemap();
        Panel panel = getComponent();
        myImage.setContent(image);
        if (panel.getPanelchildren() != null) {
            panel.getPanelchildren().getChildren().clear();
            panel.getPanelchildren().appendChild(myImage);
        } else {
            Panelchildren pc = new Panelchildren();
            panel.appendChild(pc);
            pc.appendChild(myImage);
        }
        int count = 0;
        for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext(); ) {
            ChartEntity entity = (ChartEntity) it.next();
            String key = null;
            String seriesName = null;
            if (entity instanceof CategoryItemEntity) {
                CategoryItemEntity item = ((CategoryItemEntity) entity);
                Comparable<?> colKey = item.getColumnKey();
                Comparable<?> rowKey = item.getRowKey();
                if (colKey != null && rowKey != null) {
                    key = colKey.toString();
                    seriesName = rowKey.toString();
                }
            } else if (entity instanceof PieSectionEntity) {
                Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
                if (sectionKey != null) {
                    key = sectionKey.toString();
                }
            }
            if (entity instanceof XYItemEntity) {
                XYItemEntity item = ((XYItemEntity) entity);
                if (item.getDataset() instanceof TimeSeriesCollection) {
                    TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset();
                    TimeSeries series = data.getSeries(item.getSeriesIndex());
                    TimeSeriesDataItem dataitem = series.getDataItem(item.getItem());
                    seriesName = series.getKey().toString();
                    key = dataitem.getPeriod().toString();
                }
            }
            if (key == null)
                continue;
            Area area = new Area();
            myImage.appendChild(area);
            area.setCoords(entity.getShapeCoords());
            area.setShape(entity.getShapeType());
            area.setTooltiptext(entity.getToolTipText());
            area.setId(count + "_WG__" + seriesName + "__" + key);
            count++;
        }
        myImage.addEventListener(Events.ON_CLICK, new EventListener() {

            public void onEvent(Event event) throws Exception {
                MouseEvent me = (MouseEvent) event;
                String areaId = me.getArea();
                if (areaId != null) {
                    String[] strs = areaId.split("__");
                    if (strs.length == 3) {
                        chartMouseClicked(strs[2], strs[1]);
                    }
                }
            }
        });
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) MouseEvent(org.zkoss.zk.ui.event.MouseEvent) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) Panelchildren(org.zkoss.zul.Panelchildren) BufferedImage(java.awt.image.BufferedImage) XYItemEntity(org.jfree.chart.entity.XYItemEntity) Panel(org.zkoss.zul.Panel) Area(org.zkoss.zul.Area) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) AImage(org.zkoss.image.AImage) ValueChangeEvent(org.adempiere.exceptions.ValueChangeEvent) Event(org.zkoss.zk.ui.event.Event) MouseEvent(org.zkoss.zk.ui.event.MouseEvent) ChartEntity(org.jfree.chart.entity.ChartEntity) EventListener(org.zkoss.zk.ui.event.EventListener) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity) Imagemap(org.zkoss.zul.Imagemap)

Example 2 with MouseEvent

use of org.zkoss.zk.ui.event.MouseEvent in project adempiere by adempiere.

the class WGraph method render.

// loadData
private void render(JFreeChart chart) {
    ChartRenderingInfo info = new ChartRenderingInfo();
    int width = 560;
    int height = 400;
    if (zoomFactor > 0) {
        width = width * zoomFactor / 100;
        height = height * zoomFactor / 100;
    }
    if (m_hideTitle) {
        chart.setTitle("");
    }
    BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info);
    try {
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);
        AImage image = new AImage("", bytes);
        Imagemap myImage = new Imagemap();
        myImage.setContent(image);
        if (panel.getPanelchildren() != null) {
            panel.getPanelchildren().getChildren().clear();
            panel.getPanelchildren().appendChild(myImage);
        } else {
            Panelchildren pc = new Panelchildren();
            panel.appendChild(pc);
            pc.appendChild(myImage);
        }
        int count = 0;
        for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext(); ) {
            ChartEntity entity = (ChartEntity) it.next();
            String key = null;
            if (entity instanceof CategoryItemEntity) {
                Comparable<?> colKey = ((CategoryItemEntity) entity).getColumnKey();
                if (colKey != null) {
                    key = colKey.toString();
                }
            } else if (entity instanceof PieSectionEntity) {
                Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
                if (sectionKey != null) {
                    key = sectionKey.toString();
                }
            }
            if (key == null) {
                continue;
            }
            Area area = new Area();
            myImage.appendChild(area);
            area.setCoords(entity.getShapeCoords());
            area.setShape(entity.getShapeType());
            area.setTooltiptext(entity.getToolTipText());
            area.setId(count + "_WG_" + key);
            count++;
        }
        myImage.addEventListener(Events.ON_CLICK, new EventListener() {

            public void onEvent(Event event) throws Exception {
                MouseEvent me = (MouseEvent) event;
                String areaId = me.getArea();
                if (areaId != null) {
                    for (int i = 0; i < list.size(); i++) {
                        String s = "_WG_" + list.get(i).getLabel();
                        if (areaId.endsWith(s)) {
                            chartMouseClicked(i);
                            return;
                        }
                    }
                }
            }
        });
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
}
Also used : MouseEvent(org.zkoss.zk.ui.event.MouseEvent) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) Panelchildren(org.zkoss.zul.Panelchildren) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Area(org.zkoss.zul.Area) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) AImage(org.zkoss.image.AImage) ValueChangeEvent(org.adempiere.exceptions.ValueChangeEvent) Event(org.zkoss.zk.ui.event.Event) MouseEvent(org.zkoss.zk.ui.event.MouseEvent) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) ChartEntity(org.jfree.chart.entity.ChartEntity) EventListener(org.zkoss.zk.ui.event.EventListener) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity) Imagemap(org.zkoss.zul.Imagemap)

Example 3 with MouseEvent

use of org.zkoss.zk.ui.event.MouseEvent in project adempiere by adempiere.

the class WSchedule method onEvent.

public void onEvent(Event event) throws Exception {
    if (event instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) event;
        if (me.getX() > 0) {
            MResourceAssignment assignment = new MResourceAssignment(Env.getCtx(), me.getX(), null);
            WAssignmentDialog wad = new WAssignmentDialog(assignment, false, infoSchedule.isCreateNew());
            if (!wad.isCancelled()) {
                _assignmentDialogResult = wad.getMResourceAssignment();
                Events.echoEvent("onAssignmentCallback", this, null);
            }
        }
    } else if (event instanceof BandScrollEvent) {
        BandScrollEvent e = (BandScrollEvent) event;
        Date end = e.getMax();
        Date start = e.getMin();
        Date mid = e.getCenter();
        if (mid != null) {
            m_center = mid;
            infoSchedule.dateCallback(mid);
        }
    }
}
Also used : MResourceAssignment(org.compiere.model.MResourceAssignment) MouseEvent(org.zkoss.zk.ui.event.MouseEvent) WAssignmentDialog(org.adempiere.webui.window.WAssignmentDialog) BandScrollEvent(org.zkforge.timeline.event.BandScrollEvent) Date(java.util.Date)

Example 4 with MouseEvent

use of org.zkoss.zk.ui.event.MouseEvent in project adempiere by adempiere.

the class WFPanel method onEvent.

public void onEvent(Event event) throws Exception {
    if (Events.ON_CLICK.equals(event.getName()) && event instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) event;
        String areaId = me.getArea();
        if (areaId != null && areaId.startsWith("WFN_")) {
            int id = Integer.valueOf(areaId.substring(4));
            for (WFNode node : nodeContainer.getNodes()) {
                if (node.getAD_WF_Node_ID() == id) {
                    start(node);
                    break;
                }
            }
        }
    }
}
Also used : MouseEvent(org.zkoss.zk.ui.event.MouseEvent) MWFNode(org.compiere.wf.MWFNode)

Aggregations

MouseEvent (org.zkoss.zk.ui.event.MouseEvent)4 BufferedImage (java.awt.image.BufferedImage)2 ValueChangeEvent (org.adempiere.exceptions.ValueChangeEvent)2 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)2 CategoryItemEntity (org.jfree.chart.entity.CategoryItemEntity)2 ChartEntity (org.jfree.chart.entity.ChartEntity)2 PieSectionEntity (org.jfree.chart.entity.PieSectionEntity)2 AImage (org.zkoss.image.AImage)2 Event (org.zkoss.zk.ui.event.Event)2 EventListener (org.zkoss.zk.ui.event.EventListener)2 Area (org.zkoss.zul.Area)2 Imagemap (org.zkoss.zul.Imagemap)2 Panelchildren (org.zkoss.zul.Panelchildren)2 Point (java.awt.Point)1 Date (java.util.Date)1 WAssignmentDialog (org.adempiere.webui.window.WAssignmentDialog)1 MResourceAssignment (org.compiere.model.MResourceAssignment)1 MWFNode (org.compiere.wf.MWFNode)1 ChartMouseEvent (org.jfree.chart.ChartMouseEvent)1 XYItemEntity (org.jfree.chart.entity.XYItemEntity)1