diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/IChartRendererService.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/IChartRendererService.java index 6c99cfff71..05363e6c12 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/IChartRendererService.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/IChartRendererService.java @@ -31,8 +31,9 @@ public interface IChartRendererService { * @param chartWidth * @param chartHeight * @param model + * @return true if render successfully */ - public void renderPerformanceIndicator(Component parent, int chartWidth, int chartHeight, IndicatorModel model); + public boolean renderPerformanceIndicator(Component parent, int chartWidth, int chartHeight, IndicatorModel model); /** * render chart for PA_Goal @@ -40,8 +41,9 @@ public interface IChartRendererService { * @param chartWidth * @param chartHeight * @param goalModel + * @return true if render successfully */ - public void renderPerformanceGraph(Component parent, int chartWidth, int chartHeight, GoalModel goalModel); + public boolean renderPerformanceGraph(Component parent, int chartWidth, int chartHeight, GoalModel goalModel); /** * render chart for AD_Chart @@ -49,6 +51,7 @@ public interface IChartRendererService { * @param width * @param height * @param chartModel + * @return true if render successfully */ - public void renderChart(Component parent, int width, int height, ChartModel chartModel); + public boolean renderChart(Component parent, int width, int height, ChartModel chartModel); } \ No newline at end of file diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WGraph.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WGraph.java index c378265045..2938b784ea 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WGraph.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WGraph.java @@ -17,6 +17,7 @@ import java.awt.Point; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collections; +import java.util.List; import org.adempiere.apps.graph.GraphColumn; import org.adempiere.base.Service; @@ -250,7 +251,6 @@ public class WGraph extends Div implements IdSpace { Panelchildren pc = new Panelchildren(); panel.appendChild(pc); } - IChartRendererService renderer = Service.locator().locate(IChartRendererService.class).getService(); GoalModel goalModel = new GoalModel(); goalModel.goal = m_goal; goalModel.chartType = type != null ? type : m_goal.getChartType(); @@ -259,7 +259,11 @@ public class WGraph extends Div implements IdSpace { goalModel.xAxisLabel = m_xAxisLabel; goalModel.yAxisLabel = m_yAxisLabel; goalModel.zoomFactor = zoomFactor; - renderer.renderPerformanceGraph(panel.getPanelchildren(), width, height, goalModel); + List list = Service.locator().list(IChartRendererService.class).getServices(); + for (IChartRendererService renderer : list) { + if (renderer.renderPerformanceGraph(panel.getPanelchildren(), width, height, goalModel)) + break; + } } /** diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WPerformanceIndicator.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WPerformanceIndicator.java index 876e65e46d..db620f176b 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WPerformanceIndicator.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WPerformanceIndicator.java @@ -15,6 +15,7 @@ package org.adempiere.webui.apps.graph; import java.awt.Color; import java.text.DecimalFormat; +import java.util.List; import java.util.Map; import org.adempiere.base.Service; @@ -26,6 +27,7 @@ import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Msg; import org.jfree.chart.ChartPanel; +import org.zkoss.zk.ui.event.AfterSizeEvent; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; @@ -60,10 +62,6 @@ public class WPerformanceIndicator extends Panel implements EventListener public WPerformanceIndicator(MGoal goal, Options options) { if (options != null) { - if (options.chartHeight > 0) - chartHeight = options.chartHeight; - if (options.chartWidth > 0) - chartWidth = options.chartWidth; if (options.colorMap != null) { Color color = options.colorMap.get(CHART_BACKGROUND); if (color != null) @@ -104,8 +102,6 @@ public class WPerformanceIndicator extends Panel implements EventListener private Menuitem mRefresh = new Menuitem(Msg.getMsg(Env.getCtx(), "Refresh"), ThemeManager.getThemeResource("images/Refresh16.png")); private Color chartBackground = new Color(0.0f, 0.0f, 0.0f, 0.0f); - private int chartWidth = 120; - private int chartHeight = 120; private Color dialBackground = Color.white; private Color needleColor = Color.darkGray; private Color tickColor = Color.darkGray; @@ -126,18 +122,7 @@ public class WPerformanceIndicator extends Panel implements EventListener * Kinamo (pelgrim) */ private void init() - { - IChartRendererService renderer = Service.locator().locate(IChartRendererService.class).getService(); - IndicatorModel model = new IndicatorModel(); - model.goalModel = m_goal; - model.chartBackground = chartBackground; - model.dialBackground = dialBackground; - model.needleColor = needleColor; - model.tickColor = tickColor; - renderer.renderPerformanceIndicator(this, chartWidth, chartHeight, model); - - this.getFirstChild().addEventListener(Events.ON_CLICK, this); - + { // Set Text StringBuilder text = new StringBuilder(m_goal.getName()); if (m_goal.isTarget()) @@ -157,26 +142,62 @@ public class WPerformanceIndicator extends Panel implements EventListener .append(s_format.format(m_goal.getMeasureTarget())); setTooltiptext(text.toString()); - invalidate(); + addEventListener(Events.ON_AFTER_SIZE, this); } public void onEvent(Event event) throws Exception { - if (event.getTarget() == this.getFirstChild()) + if (Events.ON_AFTER_SIZE.equals(event.getName())) + { + onAfterSize((AfterSizeEvent) event); + } + else if (event.getTarget() == this.getFirstChild()) { event.stopPropagation(); Events.sendEvent(Events.ON_CLICK, this, event.getData()); } } + private void onAfterSize(AfterSizeEvent event) { + int width = event.getWidth(); + int height = event.getHeight(); + //set normal height + if (height == 0) { + height = width > 300 ? width * 40 / 100 : width * 85 / 100; + this.setHeight(height+"px"); + } else { + int ratio = (height * 100) / width; + if (ratio > 85 || ratio < 50) { + height = width > 300 ? width * 40 / 100 : width * 85 / 100; + this.setHeight(height+"px"); + } + } + this.getChildren().clear(); + renderChart(width, height); + } + public String getTitle() { return m_text; } + private void renderChart(int chartWidth, int chartHeight) + { + IndicatorModel model = new IndicatorModel(); + model.goalModel = m_goal; + model.chartBackground = chartBackground; + model.dialBackground = dialBackground; + model.needleColor = needleColor; + model.tickColor = tickColor; + List list = Service.locator().list(IChartRendererService.class).getServices(); + for (IChartRendererService renderer : list) { + if (renderer.renderPerformanceIndicator(this, chartWidth, chartHeight, model)) + break; + } + this.getFirstChild().addEventListener(Events.ON_CLICK, this); + } + public static class Options { public Map colorMap; - public int chartWidth; - public int chartHeight; - } + } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WViewPI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WViewPI.java index b3a2d2eadd..7f2e5afaa9 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WViewPI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WViewPI.java @@ -13,10 +13,7 @@ public class WViewPI extends ADForm { protected void initForm() { this.setSclass("window-view-pi"); WPerformanceIndicator.Options options = new WPerformanceIndicator.Options(); - options.chartHeight = 180; - options.chartWidth = 180; WPAPanel paPanel = WPAPanel.get(options); appendChild(paPanel); } - } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/jfreegraph/ChartRendererServiceImpl.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/jfreegraph/ChartRendererServiceImpl.java index 5f9c819524..c28c46fe71 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/jfreegraph/ChartRendererServiceImpl.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/jfreegraph/ChartRendererServiceImpl.java @@ -53,7 +53,7 @@ public class ChartRendererServiceImpl implements IChartRendererService { private final static CLogger log = CLogger.getCLogger(ChartRendererServiceImpl.class); @Override - public void renderPerformanceIndicator(Component parent, int chartWidth, int chartHeight, IndicatorModel model) { + public boolean renderPerformanceIndicator(Component parent, int chartWidth, int chartHeight, IndicatorModel model) { PerformanceGraphBuilder builder = new PerformanceGraphBuilder(); JFreeChart chart = builder.createIndicatorChart(model); chart.setBackgroundPaint(model.chartBackground); @@ -70,11 +70,13 @@ public class ChartRendererServiceImpl implements IChartRendererService { catch (Exception e) { e.printStackTrace(); + return false; } + return true; } @Override - public void renderPerformanceGraph(Component parent, int chartWidth, int chartHeight, final GoalModel goalModel) { + public boolean renderPerformanceGraph(Component parent, int chartWidth, int chartHeight, final GoalModel goalModel) { GraphBuilder builder = new GraphBuilder(); builder.setMGoal(goalModel.goal); builder.setXAxisLabel(goalModel.xAxisLabel); @@ -151,7 +153,9 @@ public class ChartRendererServiceImpl implements IChartRendererService { }); } catch (Exception e) { log.log(Level.SEVERE, "", e); + return false; } + return true; } private void chartMouseClicked(MGoal goal, GraphColumn bgc) { @@ -165,9 +169,10 @@ public class ChartRendererServiceImpl implements IChartRendererService { } @Override - public void renderChart(Component parent, int width, int height, + public boolean renderChart(Component parent, int width, int height, ChartModel chartModel) { ChartRenderer renderer = new ChartRenderer(chartModel.chart); renderer.render(parent, width, height); + return true; } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java index 16c6d31803..25b1025223 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java @@ -393,8 +393,11 @@ public class DashboardController implements EventListener { chartPanel.getChildren().clear(); ChartModel model = new ChartModel(); model.chart = chartModel; - IChartRendererService renderer = Service.locator().locate(IChartRendererService.class).getService(); - renderer.renderChart(chartPanel, width, height, model); + List list = Service.locator().list(IChartRendererService.class).getServices(); + for (IChartRendererService renderer : list) { + if (renderer.renderChart(chartPanel, width, height, model)) + break; + } } }); } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WChartEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WChartEditor.java index b9c0e51afd..4e83013462 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WChartEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WChartEditor.java @@ -14,6 +14,8 @@ package org.adempiere.webui.editor; +import java.util.List; + import org.adempiere.base.Service; import org.adempiere.webui.apps.graph.IChartRendererService; import org.adempiere.webui.apps.graph.model.ChartModel; @@ -62,8 +64,11 @@ public class WChartEditor extends WEditor } ChartModel model = new ChartModel(); model.chart = chartModel; - IChartRendererService renderer = Service.locator().locate(IChartRendererService.class).getService(); - renderer.renderChart(panel.getPanelchildren(), 400, chartModel.getWinHeight(), model); + List list = Service.locator().list(IChartRendererService.class).getServices(); + for (IChartRendererService renderer : list) { + if (renderer.renderChart(panel.getPanelchildren(), 400, chartModel.getWinHeight(), model)) + break; + } } @Override diff --git a/org.adempiere.ui.zk/theme/default/css/theme.css.dsp b/org.adempiere.ui.zk/theme/default/css/theme.css.dsp index 02e7d86b2c..2f57ac8e94 100644 --- a/org.adempiere.ui.zk/theme/default/css/theme.css.dsp +++ b/org.adempiere.ui.zk/theme/default/css/theme.css.dsp @@ -1663,14 +1663,11 @@ table.z-vbox > tbody > tr > td > table { } .performance-indicator img { - height: 120px; - width: 120px; display: block; margin: auto; } .window-view-pi .performance-indicator img { - width: 180px !important; } .performance-indicator-box {