From 04b89bdbf22698a602d4cf44433ff0d9155b38c1 Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 14 Dec 2011 06:37:07 +0000 Subject: [PATCH] Time property for pie and bar charts git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23538 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../META-INF/MANIFEST.MF | 5 +- org.simantics.jfreechart.ontology/graph.tg | Bin 6294 -> 6733 bytes .../graph/JFreeChart.pgraph | 12 +++ .../simantics/sysdyn/JFreeChartResource.java | 12 +++ org.simantics.sysdyn.ui/META-INF/MANIFEST.MF | 3 +- .../icons/chart_bar_light.png | Bin 0 -> 562 bytes .../icons/chart_line_light.png | Bin 0 -> 599 bytes .../icons/chart_pie_light.png | Bin 0 -> 933 bytes .../sysdyn/ui/trend/chart/AbstractPlot.java | 23 ++++ .../ui/trend/chart/CategoryDataset.java | 27 ++++- .../sysdyn/ui/trend/chart/CategoryPlot.java | 37 ++++--- .../sysdyn/ui/trend/chart/ChartComposite.java | 13 +-- .../sysdyn/ui/trend/chart/JFreeChart.java | 49 +++++---- .../sysdyn/ui/trend/chart/PieDataset.java | 26 ++++- .../sysdyn/ui/trend/chart/PiePlot.java | 101 ++++++++++-------- .../sysdyn/ui/trend/chart/XYPlot.java | 40 +++---- .../chart/properties/DoubleValidator.java | 54 ++++++++++ .../chart/properties/bar/BarAxisTab.java | 26 +---- .../bar/BarGeneralPropertiesTab.java | 64 ++++++++--- .../bar/BarSeriesPropertyComposite.java | 22 +++- .../pie/PieGeneralPropertiesTab.java | 61 +++++++++-- .../pie/PieSeriesPropertyComposite.java | 21 +++- .../xyline/AxisPropertyComposite.java | 26 +---- .../xyline/XYLineGeneralPropertiesTab.java | 29 +---- .../SysdynDatasetSelectionListener.java | 17 ++- 25 files changed, 444 insertions(+), 224 deletions(-) create mode 100644 org.simantics.sysdyn.ui/icons/chart_bar_light.png create mode 100644 org.simantics.sysdyn.ui/icons/chart_line_light.png create mode 100644 org.simantics.sysdyn.ui/icons/chart_pie_light.png create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java diff --git a/org.simantics.jfreechart.ontology/META-INF/MANIFEST.MF b/org.simantics.jfreechart.ontology/META-INF/MANIFEST.MF index 6ab2f810..c792a6a0 100644 --- a/org.simantics.jfreechart.ontology/META-INF/MANIFEST.MF +++ b/org.simantics.jfreechart.ontology/META-INF/MANIFEST.MF @@ -5,6 +5,9 @@ Bundle-SymbolicName: org.simantics.jfreechart.ontology Bundle-Version: 0.1.0.qualifier Require-Bundle: org.simantics.layer0, org.simantics.layer0x.ontology;bundle-version="1.0.0", - org.simantics.g2d.ontology;bundle-version="1.0.0" + org.simantics.g2d.ontology;bundle-version="1.0.0", + org.simantics.diagram.ontology;bundle-version="2.1.0", + org.simantics.structural.ontology;bundle-version="1.1.0", + org.simantics.modeling.ontology;bundle-version="1.1.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: org.simantics.sysdyn diff --git a/org.simantics.jfreechart.ontology/graph.tg b/org.simantics.jfreechart.ontology/graph.tg index d250dc962037c81ecad6348996061b139869e416..32d291bd66ab100b8531c63ed4ed5c748555e2ba 100644 GIT binary patch literal 6733 zcmb7}iB}ZY62_ynEt-&cK0%04+cC!AAqe^vF}wfc4+?0GN$*-}m1ic5m!mMgCWt<=F?-j=vD?j&_L z5qF|&D>G|h!$nz`g)Xg-d-xB2{!YKOqWWCga4TU1X&m+DBKfyenvdh`ANwgqLECjR zyOeFL<*mxpi_9fa(E3MZ_gau(zB2x1FO}If&LY>AE7Q?tPvu&g1(|C@lrK=E-RnWC z^Y2$&7MbkR7S6urFy|=6&}o${OX_0_KmUQfk(T_kMHEBNpFbZi(nPSE zp)GxP;)ZL5QFHY4*l9R=#M{4+C7pWKNrD#qr{Lcz{@P5i;gVC{_d9)C2NpVOE=gP~ z;BL&Wz&9v??kOJe26%tYlW_-y0Ui*>jy-Wnn5FQ1FP`djwC0gg|;npmfu;+ zA#o2)rw?4P+S-`sI$dKihGM6LdNI6q3ujfFwdn{I5Y_Xg{Fx`pMzQo{^xNX>#!h4R zA?y|IirjO+kU(WJZU8l$8pOA zbky=bXQM1`#Z8{eYw=XsrwjzwT&`j~s zB}u>$%5-k&oeYC!60}FpNR53%XSrvpB@YPNU3pesTuZ*XDqWQJ-@2YSH}ND$GVk9( zf2F(_W>QNZ6L(bB;#BSgz;#KeE)-z zV*OxJj9mlmY20KSkf!1_P5O^B^6Sp7k&d^T+TB9S2Ru z3CSq=4la{U^!famVA-|c=+JxFh%QOmfKQ`#CX85|83UJ0=0(XI^qGrcef3U|ta9Ng zBNt8T1xXz;sWLuu6NWCB+;fuK)ec$YYlL$qdfrEa7YIBfoHx-c5*!z1=&OHBURD`?Sd$ zmAvZPsUiH7u2GXSLr0~5JxD@+^IQ*G_y&OMXZmMM;({dhjt7Y;jQis39*?suZbR@$ zxK9pw^K$%--bd9sOCrJt1?Zt9mgmFf6XIdP-We$at(Z^5SzW}(g1U}~Yj6&)lx(3M zv|O%055swfnZHv5;;@ZtqGsKPrFc{zBJXlXFjUD(=Nv3tv1e zpO^I9GbyuqH~1QITI9ddHEVLt&{2820>AcK;_cNsn7==bte@z-Wwd7{t6cXln3#Ch z#1|z#ypZ8t^Zj6%&zxnx-Yl;c z_-TQ|0`pe1dVbYe=BKe`-pQ6(l$PrSUM_G@;O`6{LYurD_6MvV_ARXXKm6eLZP+8& z0PIiLH=ZBk_g^sPGCl-*4P##qVVeIn+Dip~P~iIorbhLHXfGO`KzpIU^Wg8jy~1y@ z&i@0?x?ejz>w5Qt@4;06(zDewZuMl(J)bqQ)swBB ztoq$(&lKWhjoOVyLbC}l8F|C&N9!!GSAjB zYlUp*d(`j_w2u_{aDhK9@FxZS7_93%gf>~%$ND%3)BWMMAldE@S@k=8-0Ba&r+R)n zlC7R>^<>rWM|%XOdVXt?t)6W4WYu&2`(Ubfo~@p7t0$|TN)-% znCk1Et)6kKC##;%*DjdqmpxlO<5o{rJ?{tBh}I|1$}-QIZ0lVF?OjQ>F} z|DTXYVeZ1XR*`qy~me+xTy)c-YOWF<~U8ezKD3O4XZ?~ywHtecL65uEY|;uP8M F{U4Nd?E(M* literal 6294 zcmb7|iE|Uj62@b!TfPY*c2~wucz^qQ{q@e^ zkEv9uo~p*4Uw3~!SMRJ!<5d!h^&Q8 z6J=o*nzRBgV@ilFWCz{6SDD+- zOcDj{e^r*cK_c_j@ei|9mb;imt}Rv;qr*(aTABr!>4+#_ph`=7LA&?=uehi(-KRdx zzGh_3Q7S{HRj@8;06qEqN7@JN>7PDTjJ|*Wej*J!f$VuBorsf`IFG>9S6d1WOmgM& z)rl*D`>-7uUh8#Dl9+aY^(}9UZBQMhIUL%7@K-s{#yvS|;Q?jYgB_EESt^#NYN;+p zdnQSZCK<_t9t7!X5VasXfMuj?gQQ>8kP(EqqG<;y@_m4(N}DOGTH1vM;KRI zVJS>Ai5^oLTWV6#CMtV?jzN51s;@j9$88h9P|kBMM_JsCTR4}$)KW!G9Y{<|xeDdkGKm-#)lko;Ih7;< zgasJ;$_taTwiLdAp-`NW%nl8tMey^;oNQYCl97c442QzwUXYg$rp7^n^3Z3?~uL$NFcu+olE zJHM)-_N3R@GKt-_-_%xFJv_1*wG7Y52(36dIINXl)KPtki`%MyRMXH*+|hzIuFC6b zFY0q31D^uc2i?)gvllhR@(SitG~?qMSKo>gsUKI^&tW`HQ71mhHm$)D@&e`)6nB!d zJqw%Jjs(1f@gzl^fuUHiTXYF@W-!5>oY#ilo(-5Uk?Nwx)$NKFk`U|Jg7G3noz7o>+6$5p-#g~Rw!DYM zl)(Og0+%(gJ{=@<@~dhrO~+XlcSP`qa&a|m?VxC(P_!xB(odS$(Je+F~bYeJrJ))K=Qqv?p{-xtjL2G!3?D6Q*O7 z=Vy%>a3ySa{&%%jRt~S;IklA5^!Ae+Pr!49EbQPy*aJPGv=7ytpMbq9QfY50=Li@+eQ!mTSjVWd_qDikX0+_;Cex?el7_yW?Gbx+qb9!Z=Ubs~S~o z*teAdUM2sE`p4EXd54(hCneC2M`Tahm^9o#&!qJ{MlG-(N5G7NWB$`)ywuo_FB{Cb z7nxCt%(&K>cRhaRap*DD$a;J|Va9hnX4C>R4wbp#@s`Jd$8SA;8%=(AIPCqVvu+!sN0J9#< z`Ue!BNFVI`U4A^^^AwL~3C!_e7r!9=IcY=E{*rdpW5lu_V>4r}%vd`!_L3QA1?Kag zCB7s58IPwuo)UKRKPP>#+t03L-cR^>{r81g4|aOoEnwDzS&tg!`QH~TXFc}JogaM67>oJ7$JiVAc|E@pV}F0~_-BuA3%mJ$C4I1) zf7>$8AAX+yEn%m}^9gqPUCXS8pY=C|Sr2ylchU#59?be1!mI~7J>CUi)`MApU6}P? zr{9r2nDt=RUlVqE>>t?a@vZ^09?belVb+74ep~ur)`Q2S?Mpi<4bQyOe_`3_jb+v& zp7mFRUHzPq{!boHczjvdjfe9FyYcX@1oL=c9`BN{(~nCZ?DTlIf>{q{{Y7D?$M|5U z$GaHJdNAuR2s=IY3+(iPW!A&b`tub3R{CJy@ABjMLvznJ_MUmtW7G!wQESYoUFMq} zlOGG`#NzrJa?=^8>r}zp;K^Km5Et)QDRTe9YJjX6zj^&Vm_d%Zyq9^L&3K z9+mzN9)IugcOHN1@z=s`J>N(l?Dhlobow9I?ayoL=lwyv%ZKOjl&1$f{VVHdJ^ZXc zNqXETV5fg+nf36q{)8~E2ki7Oqz`62nDxhnogU8z*y*2JWIKGxm-dXTglK1@nAs w!frkb(l1J@O8X!UKCttbrQc`m=g!KH*Ys0%dXP2`qKU&_Al=W#693u%05%ec-~a#s diff --git a/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph b/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph index 2526730c..5aa93b6b 100644 --- a/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph +++ b/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph @@ -1,6 +1,9 @@ L0 = L0X = G2D = +DIA = +MOD = +STR = //##################################################################### // Ontology for defining JFreeChart charts @@ -20,6 +23,7 @@ JFREE.Chart -- JFREE.Chart.visibleBorder --> L0.Boolean -- JFREE.Chart.borderWidth --> L0.Double -- JFREE.Chart.visibleLegend --> L0.Boolean -- JFREE.Chart.time --> L0.Double -- JFREE.ChartElement.component --> JFREE.Chart Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ipt` z3px}CE%6Wl00FW|L_t(I%cYYmZ%{!HM$ZkmB?W3I!Ino-FofVxI1~zl&ux67@=IqIQGgDRZKW9GaasTa?iW1=<2@By$ zo;|)XoeE$s?p)s{t5B_w_XpojZ!kP@6-UQTq`0s(voxI^u=Kzq8JT1hp2gDRWWe$M zi?xdqMIjH`&O^+Exd<0$=ZT*l|2EjXdlw`qQIY&QNIZ+y6BUdoj@p@%0aXPV_@_fi zW8S+-vq2BhLrCJRO|(9p43HTW3EnA7@Zd);BE%R;s@U2PzDzuQ_oU2%jG&J}S7%nY zRec%jZO-@Q41I`hB1)X|nfL|wb{~+LNW#;2^YPVcfCpqy?vO!i6OmezP%%8ImP7=H zUq9n+T)DJMZ;e^Ypv+P0kO5kChbPMrfiMZ#`s?t{aKpmrZ7{3Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ipt` z3pqD|XVako00GxYL_t(I%cWCaNRx3Cz27%mXyU{Aqgb&bvV2(uSufGh2O}8PC1Pcka9k@@I zbKu-_uBEC_4k}6^eLvwiis&d}+%82x3x(dA)@H8|^;pGP_!jDRD|1E>Jwg;I+JX>8 z6>(gV8oY@i{;xo2@RcJXJxV-yHM}GK5f3QR7H?vR0RXIg^lVaz1B#ql8i@qw z3mlKV_`2J-WaX!P4ssu6-*k=LZG2qWIBERWLztT@74M?8kJLfw^n)Cuw%{i_a~J(pokeEtybpgr|#7s zA9yzVN#)4((=AV?+7De(l)5#yZtej9*wveM#FCR@=+a*)bPSBRo3iiIzMqrZSN+QV z24iLvsX-YE%2dBLnV9|ePWC*%b;30K(z8B$xxS?qjA>P*4a@eoxrA`>LSz5{D-;`X zSUJqdi&XghwKL5Z=av)u+LMYDQ0COS^zGn+Q60VTZ1P6>tsXx2=!dF8v15Z${NcO& l6tP50skK$^H`-7p{s1zbFmL2hvG@Q0002ovPDHLkV1mo*3dsNf literal 0 HcmV?d00001 diff --git a/org.simantics.sysdyn.ui/icons/chart_pie_light.png b/org.simantics.sysdyn.ui/icons/chart_pie_light.png new file mode 100644 index 0000000000000000000000000000000000000000..fa553c297880bf9f4825bd3bfd6c0eb5b6221eb2 GIT binary patch literal 933 zcmV;W16urvP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ipt` z3pf}vt>3u-00SjSL_t(I%bnBDPuq1I$MF~Kx24c8E&Y^m zw}Zb`_XzlW_S|z)%FBJ$(_KCz2wmr*rNKgBZ3#DXlNUMz@68LL#oMSB zCjD|-DD_P&9LE+tz@5r6{GJa_MSJn}?A6^yad^lIK07_w6|t87c!>2a`<0L1KJ+aB z_%3GB7D>7iHvCF2Yd`EF*%D@Z)-Ja&DjT?i6wPRw`+taL+*`97HM+F_|OB{sM$E zVg%~3R4qa%LX+Rb6V2V2&Ch^2{In*2`pJ%{Uq~05_X(@p90@CoD)&YJz+jB}1QdJ# zdLun(Z)nBZY7v=@UoZ7HO(Z!N&$PxGF<-2LGlext}wJ`dpJ!j&$h@<2@b0l=sT`|f=1_Q9L^@5)3p zaeTY`%V8CJ!*xo(5Aed_U)qj>qz2~-2QFX%;@P|Gi)K9PXyIM9rN zaRTQGsYDq0!aA}GTTon#X0M$r1Axyud$#OWYNI;42vsPeJ|2f=42pAT#vz12)sdK* zUc`?-FWg-#Z@iejcJix#yigi_^Ldx^Prbc+y1ZBvYGw}ler53W$7p@00000NkvXX Hu0mjf9Kx}L literal 0 HcmV?d00001 diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractPlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractPlot.java index e38b641a..afd6e255 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractPlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractPlot.java @@ -14,7 +14,10 @@ package org.simantics.sysdyn.ui.trend.chart; import java.util.ArrayList; import java.util.HashMap; +import javax.swing.SwingUtilities; + import org.jfree.chart.axis.Axis; +import org.jfree.chart.plot.Plot; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ObjectsWithType; @@ -37,6 +40,7 @@ public abstract class AbstractPlot implements IPlot { protected ArrayList datasets; protected HashMap rangeMappings; protected HashMap domainMappings; + protected Plot plot; public AbstractPlot(ReadGraph graph, Resource resource) { this.resource = resource; @@ -116,4 +120,23 @@ public abstract class AbstractPlot implements IPlot { public Resource getResource() { return resource; } + + protected abstract Plot newPlot(); + protected abstract void setPlotProperties(); + + @Override + public Plot getPlot() { + if(plot == null) + plot = newPlot(); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + setPlotProperties(); + } + }); + + return plot; + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java index 75be9b98..1fa12dbd 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java @@ -145,6 +145,21 @@ public class CategoryDataset extends AbstractDataset { } } + // Find if a specific time is set for this chart + Double chartTime = null; + if(!datasets.isEmpty()) { + Layer0 l0 = Layer0.getInstance(graph); + Resource datasetResource = graph.getPossibleObject(r, l0.PartOf); + if(datasetResource != null) { + Resource plot = graph.getPossibleObject(datasetResource, l0.PartOf); + if(plot != null) { + Resource chart = graph.getPossibleObject(plot, l0.PartOf); + if(chart != null) + chartTime = graph.getPossibleRelatedValue(chart, jfree.Chart_time); + } + } + } + for(SysdynDataSet dataset : datasets) { double[] va = dataset.values; @@ -152,9 +167,16 @@ public class CategoryDataset extends AbstractDataset { if(va == null || va.length == 0) continue; - // Time + /* + * Time + * + * 1. find time for the individual series. + * 2. find time for the whole chart + * 3. find simulation time + */ Double time = graph.getPossibleRelatedValue(r, jfree.Series_time, Bindings.DOUBLE); - + if(time == null) + time = chartTime; if(time == null) time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME, Bindings.DOUBLE); @@ -211,7 +233,6 @@ public class CategoryDataset extends AbstractDataset { @Override public void run() { - // Remove all unused series dataset.clear(); BarRenderer renderer = ((BarRenderer)getRenderer()); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java index 297eb678..69d5d791 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java @@ -28,7 +28,6 @@ import org.simantics.sysdyn.JFreeChartResource; */ public class CategoryPlot extends AbstractPlot { - private org.jfree.chart.plot.CategoryPlot plot; private Boolean visibleGrid; @@ -47,46 +46,50 @@ public class CategoryPlot extends AbstractPlot { } @Override - public Plot getPlot() { - if(plot == null) { - plot = new org.jfree.chart.plot.CategoryPlot(null, null, null, null); - } + protected Plot newPlot() { + return new org.jfree.chart.plot.CategoryPlot(null, null, null, null); + } + + @Override + protected void setPlotProperties() { + if(!(plot instanceof org.jfree.chart.plot.CategoryPlot)) + return; + + org.jfree.chart.plot.CategoryPlot cplot = (org.jfree.chart.plot.CategoryPlot) plot; /* Support using multiple axis, but prefer using only one domain and * one range axis */ for(int i = 0; i < ranges.size(); i++) { - plot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis()); + cplot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis()); } for(int i = 0; i < domains.size(); i++) { - plot.setDomainAxis(i, (CategoryAxis)domains.get(i).getAxis()); + cplot.setDomainAxis(i, (CategoryAxis)domains.get(i).getAxis()); } IAxis axis; for(int i = 0; i < datasets.size(); i++) { IDataset dataset = datasets.get(i); org.jfree.data.category.CategoryDataset ds = (org.jfree.data.category.CategoryDataset)dataset.getDataset(); - plot.setDataset(i, ds); + cplot.setDataset(i, ds); // System.out.println("setting dataset " + i + ": " + ds); - plot.setRenderer(i, (CategoryItemRenderer)dataset.getRenderer()); + cplot.setRenderer(i, (CategoryItemRenderer)dataset.getRenderer()); axis = rangeMappings.get(dataset); if(axis != null && ranges.contains(axis)) - plot.mapDatasetToRangeAxis(i, ranges.indexOf(axis)); + cplot.mapDatasetToRangeAxis(i, ranges.indexOf(axis)); axis = domainMappings.get(dataset); if(axis != null && ranges.contains(axis)) - plot.mapDatasetToDomainAxis(i, domains.indexOf(axis)); + cplot.mapDatasetToDomainAxis(i, domains.indexOf(axis)); } if(visibleGrid != null) { - plot.setRangeGridlinesVisible(visibleGrid); - plot.setDomainGridlinesVisible(false); + cplot.setRangeGridlinesVisible(visibleGrid); + cplot.setDomainGridlinesVisible(false); } // Cleaner look: no outline borders - plot.setInsets(new RectangleInsets(2,2,2,2), false); - plot.setOutlineVisible(false); - - return plot; + cplot.setInsets(new RectangleInsets(2,2,2,2), false); + cplot.setOutlineVisible(false); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java index 200f0a21..5db0e809 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java @@ -17,8 +17,6 @@ import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.awt.SWT_AWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.widgets.Composite; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; @@ -88,16 +86,7 @@ public class ChartComposite extends Composite { */ private void CreateContent(final Resource chartResource) { composite = this; - - composite.addDisposeListener(new DisposeListener() { - - @Override - public void widgetDisposed(DisposeEvent e) { - if(chart != null) - chart.dispose(); - } - }); - + GridLayoutFactory.fillDefaults().applyTo(composite); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); frame = SWT_AWT.new_Frame(composite); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java index 826c0320..e9c36388 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java @@ -13,7 +13,6 @@ package org.simantics.sysdyn.ui.trend.chart; import java.awt.Color; import java.awt.Font; -import java.lang.reflect.InvocationTargetException; import java.util.Collection; import javax.swing.SwingUtilities; @@ -79,34 +78,34 @@ public class JFreeChart implements IJFreeChart { if(plot == null) return null; - try { - SwingUtilities.invokeAndWait(new RunnableWithObject(plot) { - @Override - public void run() { - jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot()); - - jfreechart.setBackgroundPaint(Color.WHITE); + jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot()); + + SwingUtilities.invokeLater(new RunnableWithObject(plot) { + @Override + public void run() { + if(jfreechart == null) + return; + + jfreechart.setBackgroundPaint(Color.WHITE); + if(jfreechart.getLegend() != null) { jfreechart.getLegend().setBorder(0, 0, 0, 0); int size = jfreechart.getLegend().getItemFont().getSize(); jfreechart.getLegend().setItemFont(new Font("helvetica", Font.PLAIN, size)); - - org.jfree.chart.title.TextTitle t = (org.jfree.chart.title.TextTitle)title.getTitle(); - if(t.isVisible()) { - t.setFont(new Font("georgia", Font.BOLD, 13)); - t.setPadding(new RectangleInsets(4, 0, 0, 0)); - jfreechart.setTitle(t); - } - - if(legendVisible != null && !legendVisible) { - jfreechart.removeLegend(); - } } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } + + org.jfree.chart.title.TextTitle t = (org.jfree.chart.title.TextTitle)title.getTitle(); + if(t.isVisible()) { + t.setFont(new Font("georgia", Font.BOLD, 13)); + t.setPadding(new RectangleInsets(4, 0, 0, 0)); + jfreechart.setTitle(t); + } + + if(legendVisible != null && !legendVisible) { + jfreechart.removeLegend(); + } + } + }); + return jfreechart; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java index da1b61a1..af50b718 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java @@ -170,15 +170,37 @@ public class PieDataset extends AbstractDataset { } } + // Find if a specific time is set for this chart + Double chartTime = null; + if(!datasets.isEmpty()) { + Layer0 l0 = Layer0.getInstance(graph); + Resource datasetResource = graph.getPossibleObject(r, l0.PartOf); + if(datasetResource != null) { + Resource plot = graph.getPossibleObject(datasetResource, l0.PartOf); + if(plot != null) { + Resource chart = graph.getPossibleObject(plot, l0.PartOf); + if(chart != null) + chartTime = graph.getPossibleRelatedValue(chart, jfree.Chart_time); + } + } + } + for(SysdynDataSet dataset : datasets) { double[] va = dataset.values; if(va == null || va.length == 0) continue; - // Time + /* + * Time + * + * 1. find time for the individual series. + * 2. find time for the whole chart + * 3. find simulation time + */ Double time = graph.getPossibleRelatedValue(r, jfree.Series_time, Bindings.DOUBLE); - + if(time == null) + time = chartTime; if(time == null) time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME, Bindings.DOUBLE); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java index 231b6446..556c8742 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java @@ -37,7 +37,6 @@ import org.simantics.sysdyn.JFreeChartResource; */ public class PiePlot extends AbstractPlot { - private org.jfree.chart.plot.PiePlot plot; private org.jfree.data.general.PieDataset pieDataset; private DatasetChangeListener listener; @@ -53,28 +52,62 @@ public class PiePlot extends AbstractPlot { } } - @Override - public Plot getPlot() { - if(plot == null) { - plot = new MyPiePlot(); - plot.setToolTipGenerator(new StandardPieToolTipGenerator()); + /** + * Pie plot class with a stricter equals condition + * @author Teemu Lempinen + * + */ + private class MyPiePlot extends org.jfree.chart.plot.PiePlot { + + private static final long serialVersionUID = -5917620061541212934L; + + @Override + public boolean equals(Object obj) { + boolean result = super.equals(obj); + if(result == true) { + org.jfree.chart.plot.PiePlot that = (org.jfree.chart.plot.PiePlot) obj; + if (this.getDataset() != that.getDataset()) { + return false; // Normally plot does not check this. We need this to properly update the charts + } + } + + return result; } + } + + @Override + protected Plot newPlot() { + MyPiePlot plot = new MyPiePlot(); + plot.setToolTipGenerator(new StandardPieToolTipGenerator()); + return plot; + } + + @Override + protected void setPlotProperties() { + if(!(plot instanceof MyPiePlot)) + return; + + final MyPiePlot piePlot = (MyPiePlot)plot; + if(!datasets.isEmpty()) { // We assume that a pie plot has only one dataset final IDataset ds = datasets.get(0); Dataset dataset = ((PieDataset)ds).getDataset(); + + if(dataset == null) + return; if(pieDataset != null && listener != null) { pieDataset.removeChangeListener(listener); } pieDataset = (org.jfree.data.general.PieDataset)dataset; - plot.setDataset(pieDataset); + piePlot.setDataset(pieDataset); if(Boolean.FALSE.equals(labelsVisible)) - plot.setLabelGenerator(null); - else if(plot.getLabelGenerator() == null) - plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); + piePlot.setLabelGenerator(null); + else if(piePlot.getLabelGenerator() == null) + piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator()); listener = new DatasetChangeListener() { @@ -83,14 +116,14 @@ public class PiePlot extends AbstractPlot { HashMap colorMap = ((PieDataset)ds).getColorMap(); HashMap explodedMap = ((PieDataset)ds).getExplodedMap(); - for(Object o : plot.getDataset().getKeys()) { + for(Object o : piePlot.getDataset().getKeys()) { if(o instanceof Comparable) { Comparable key = (Comparable)o; if(explodedMap.containsKey(key) && explodedMap.get(key)) { - plot.setExplodePercent(key, 0.3); + piePlot.setExplodePercent(key, 0.3); } else { - plot.setExplodePercent(key, 0); + piePlot.setExplodePercent(key, 0); } } } @@ -98,12 +131,12 @@ public class PiePlot extends AbstractPlot { for(String name : explodedMap.keySet()) { Boolean exploded = explodedMap.get(name); if(Boolean.TRUE.equals(exploded)) - plot.setExplodePercent(name, 0.3); + piePlot.setExplodePercent(name, 0.3); } - plot.clearSectionPaints(false); - plot.setDrawingSupplier(new DefaultDrawingSupplier()); + piePlot.clearSectionPaints(false); + piePlot.setDrawingSupplier(new DefaultDrawingSupplier()); for(String name : colorMap.keySet()) - plot.setSectionPaint(name, colorMap.get(name)); + piePlot.setSectionPaint(name, colorMap.get(name)); } }; @@ -111,36 +144,10 @@ public class PiePlot extends AbstractPlot { } // Cleaner look: no outline borders - plot.setInsets(new RectangleInsets(0,0,0,0), false); - plot.setOutlineVisible(false); - plot.setLabelBackgroundPaint(Color.WHITE); - plot.setLabelFont(new Font("helvetica", Font.PLAIN, 11)); - - return plot; - } - - /** - * Pie plot class with a stricter equals condition - * @author Teemu Lempinen - * - */ - private class MyPiePlot extends org.jfree.chart.plot.PiePlot { - - private static final long serialVersionUID = -5917620061541212934L; - - @Override - public boolean equals(Object obj) { - boolean result = super.equals(obj); - if(result == true) { - org.jfree.chart.plot.PiePlot that = (org.jfree.chart.plot.PiePlot) obj; - if (this.getDataset() != that.getDataset()) { - return false; // Normally plot does not check this. We need this to properly update the charts - } - } - - return result; - } - + piePlot.setInsets(new RectangleInsets(0,0,0,0), false); + piePlot.setOutlineVisible(false); + piePlot.setLabelBackgroundPaint(Color.WHITE); + piePlot.setLabelFont(new Font("helvetica", Font.PLAIN, 11)); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java index af0cc336..b30c323f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java @@ -29,10 +29,8 @@ import org.simantics.sysdyn.JFreeChartResource; */ public class XYPlot extends AbstractPlot { - private org.jfree.chart.plot.XYPlot plot; private Boolean visibleGrid; - public XYPlot(ReadGraph graph, Resource plotResource) { super(graph, plotResource); @@ -47,45 +45,49 @@ public class XYPlot extends AbstractPlot { } @Override - public Plot getPlot() { - if(plot == null) - plot = new org.jfree.chart.plot.XYPlot(null, null, null, null); + protected Plot newPlot() { + return new org.jfree.chart.plot.XYPlot(null, null, null, null); + } + + @Override + protected void setPlotProperties() { + if(!(plot instanceof org.jfree.chart.plot.XYPlot)) + return; - plot.clearDomainAxes(); - plot.clearRangeAxes(); + org.jfree.chart.plot.XYPlot xyplot = (org.jfree.chart.plot.XYPlot)plot; + xyplot.clearDomainAxes(); + xyplot.clearRangeAxes(); for(int i = 0; i < ranges.size(); i++) { - plot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis()); + xyplot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis()); } for(int i = 0; i < domains.size(); i++) { - plot.setDomainAxis(i, (ValueAxis)domains.get(i).getAxis()); + xyplot.setDomainAxis(i, (ValueAxis)domains.get(i).getAxis()); } IAxis axis; for(int i = 0; i < datasets.size(); i++) { IDataset dataset = datasets.get(i); - plot.setDataset(i, (XYDataset)dataset.getDataset()); - plot.setRenderer(i, (XYItemRenderer)dataset.getRenderer()); + xyplot.setDataset(i, (XYDataset)dataset.getDataset()); + xyplot.setRenderer(i, (XYItemRenderer)dataset.getRenderer()); axis = rangeMappings.get(dataset); if(axis != null && ranges.contains(axis)) - plot.mapDatasetToRangeAxis(i, ranges.indexOf(axis)); + xyplot.mapDatasetToRangeAxis(i, ranges.indexOf(axis)); axis = domainMappings.get(dataset); if(axis != null && ranges.contains(axis)) - plot.mapDatasetToDomainAxis(i, domains.indexOf(axis)); + xyplot.mapDatasetToDomainAxis(i, domains.indexOf(axis)); } if(visibleGrid == null) visibleGrid = true; - plot.setRangeGridlinesVisible(visibleGrid); - plot.setDomainGridlinesVisible(visibleGrid); + xyplot.setRangeGridlinesVisible(visibleGrid); + xyplot.setDomainGridlinesVisible(visibleGrid); // Cleaner look: no outline borders - plot.setInsets(new RectangleInsets(2,2,2,2), false); - plot.setOutlineVisible(false); - - return plot; + xyplot.setInsets(new RectangleInsets(2,2,2,2), false); + xyplot.setOutlineVisible(false); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java new file mode 100644 index 00000000..74b984bd --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.eclipse.jface.dialogs.IInputValidator; + +/** + * Validator for validating that an input is double. + * + * Can allow empty strings. + * + * @author Teemu Lempinen + * + */ +public class DoubleValidator implements IInputValidator { + + boolean allowEmpty; + + /** + * New double validator. Does not allow empty strings + */ + public DoubleValidator() { + this(false); + } + + /** + * New double validator. + * @param allowEmpty Are empty strings allowed + */ + public DoubleValidator(boolean allowEmpty) { + this.allowEmpty = allowEmpty; + } + + @Override + public String isValid(String newText) { + if (allowEmpty && newText.trim().isEmpty()) + return null; + try { + Double.parseDouble(newText); + return null; + } catch (NumberFormatException e) { + return e.getMessage(); + } + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java index c0e84e6f..c17e6939 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart.properties.bar; -import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.StructuredSelection; @@ -48,6 +47,7 @@ import org.simantics.sysdyn.JFreeChartResource; import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite; import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; import org.simantics.sysdyn.ui.trend.chart.properties.TrackedSpinner; import org.simantics.ui.utils.AdaptionUtils; @@ -160,7 +160,7 @@ public class BarAxisTab extends LabelPropertyTabContributor implements Widget { rangemin.setColorProvider(new JFreeChartPropertyColorProvider(rangemin.getResourceManager())); rangemin.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min)); rangemin.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min)); - rangemin.setInputValidator(new DoubleValidator()); + rangemin.setInputValidator(new DoubleValidator(true)); label = new Label(minmax, SWT.NONE); label.setText("Max:"); @@ -168,7 +168,7 @@ public class BarAxisTab extends LabelPropertyTabContributor implements Widget { rangemax.setColorProvider(new JFreeChartPropertyColorProvider(rangemax.getResourceManager())); rangemax.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max)); rangemax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); - rangemax.setInputValidator(new DoubleValidator()); + rangemax.setInputValidator(new DoubleValidator(true)); // Range Color label = new Label(rangeGroup, SWT.NONE); @@ -289,24 +289,4 @@ public class BarAxisTab extends LabelPropertyTabContributor implements Widget { } }); } - - - /** - * Validator for validating that an input is double - * @author Teemu Lempinen - * - */ - private class DoubleValidator implements IInputValidator { - @Override - public String isValid(String newText) { - if (newText.trim().isEmpty()) - return null; - try { - Double.parseDouble(newText); - return null; - } catch (NumberFormatException e) { - return e.getMessage(); - } - } - } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java index 387f34e6..5982d6dc 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java @@ -16,6 +16,7 @@ import java.util.Map; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.layout.LayoutConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.graphics.Point; @@ -41,8 +42,11 @@ import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.JFreeChartResource; import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory; import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier; @@ -58,7 +62,7 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor { private ScrolledComposite sc; private Composite composite; private Button hgrid, htitle, hlegend; - private TrackedText name, title; + private TrackedText name, title, time; private TrackedCombo type; @@ -77,46 +81,74 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor { // General properties Group general = new Group(composite, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(general); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(general); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general); general.setText("General"); + // first column: labels + Composite labelColumn1 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1); + GridLayoutFactory.fillDefaults().applyTo(labelColumn1); + + // first column: name and title + Composite propertyColumn1 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1); + GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1); + + // first column: labels + Composite labelColumn2 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2); + GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2); + + // first column: type and time + Composite propertyColumn2 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2); + GridLayoutFactory.fillDefaults().applyTo(propertyColumn2); + // Name - Label label = new Label(general, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + Label label = new Label(labelColumn1, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); label.setText("Name:"); - Composite c = new Composite(general, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(c); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(c); - - name = new org.simantics.browsing.ui.swt.widgets.TrackedText(c, support, SWT.BORDER); + name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget()); name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel)); name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); // Type - label = new Label(c, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + label = new Label(labelColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); label.setText("Type:"); - type = new TrackedCombo(c, support, SWT.BORDER | SWT.READ_ONLY); + type = new TrackedCombo(propertyColumn2, support, SWT.BORDER | SWT.READ_ONLY); type.addModifyListener(new TypeModifyListener()); type.setItemFactory(new TypeItemFactory()); type.setSelectionFactory(new TypeSelectionFactory()); GridDataFactory.fillDefaults().applyTo(type.getWidget()); // Title (Which is different than name) - label = new Label(general, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + label = new Label(labelColumn1, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); label.setText("Title:"); - title = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER); + title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget()); title.setTextFactory(new TitleFactory()); title.addModifyListener(new TitleModifier()); title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); + // Time + label = new Label(labelColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Time:"); + + time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget()); + time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time)); + time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time)); + time.setInputValidator(new DoubleValidator(true)); + time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); + // Group for hide options Group hideGroup = new Group(composite, SWT.NONE); GridDataFactory.fillDefaults().applyTo(hideGroup); @@ -136,6 +168,8 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor { hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true)); hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend)); + + // Resize scrolled composite sc.setContent(composite); Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java index 7ccbbc4a..c7597ac0 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java @@ -22,6 +22,10 @@ import org.simantics.browsing.ui.swt.widgets.TrackedText; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; @@ -34,7 +38,7 @@ import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite; */ public class BarSeriesPropertyComposite extends Composite { - private TrackedText variable, label; + private TrackedText variable, label, time; public BarSeriesPropertyComposite(Composite parent, final ISessionContext context, WidgetSupport support, int style) { super(parent, style); @@ -71,5 +75,21 @@ public class BarSeriesPropertyComposite extends Composite { this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager())); GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget()); + + // Time + label = new Label(this, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + label.setText("Time:"); + + Composite composite = new Composite(this, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(composite); + GridLayoutFactory.fillDefaults().applyTo(composite); + + time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER); + time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time)); + time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time)); + time.setInputValidator(new DoubleValidator(true)); + time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); + GridDataFactory.fillDefaults().applyTo(time.getWidget()); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java index bbaa7b4b..10b034aa 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java @@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.trend.chart.properties.pie; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.layout.LayoutConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.graphics.Point; @@ -29,8 +30,11 @@ import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.JFreeChartResource; import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory; import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier; @@ -45,7 +49,7 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor { private ScrolledComposite sc; private Composite composite; private Button htitle, hlegend, hlabels; - private TrackedText name, title; + private TrackedText name, title, time; @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { @@ -62,31 +66,72 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor { // General properties Group general = new Group(composite, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(general); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(general); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general); general.setText("General"); + // first column: labels + Composite labelColumn1 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1); + GridLayoutFactory.fillDefaults().applyTo(labelColumn1); + + // first column: name and title + Composite propertyColumn1 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1); + GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1); + + // first column: labels + Composite labelColumn2 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2); + GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2); + + // first column: type and time + Composite propertyColumn2 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2); + GridLayoutFactory.fillDefaults().applyTo(propertyColumn2); + // Name - Label label = new Label(general, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + Label label = new Label(labelColumn1, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); label.setText("Name:"); - name = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER); + name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget()); name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel)); name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); + // Dummy data for now. Waiting for different pie chart types + label = new Label(labelColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(label); + label.setText(""); + + label = new Label(propertyColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(label); + label.setText(""); + // Title (Which is different than name) - label = new Label(general, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + label = new Label(labelColumn1, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); label.setText("Title:"); - title = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER); + title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget()); title.setTextFactory(new TitleFactory()); title.addModifyListener(new TitleModifier()); title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); + // Time + label = new Label(labelColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Time:"); + + time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget()); + time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time)); + time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time)); + time.setInputValidator(new DoubleValidator(true)); + time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); + // Group for hide options Group hideGroup = new Group(composite, SWT.NONE); GridDataFactory.fillDefaults().applyTo(hideGroup); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java index 1e8786c4..dad20d4a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java @@ -24,9 +24,12 @@ import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; @@ -39,7 +42,7 @@ import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite; */ public class PieSeriesPropertyComposite extends Composite { - private TrackedText variable, label; + private TrackedText variable, label, time; public PieSeriesPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { super(parent, style); @@ -85,6 +88,22 @@ public class PieSeriesPropertyComposite extends Composite { Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker); + // Time + label = new Label(this, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + label.setText("Time:"); + + Composite composite = new Composite(this, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(composite); + GridLayoutFactory.fillDefaults().applyTo(composite); + + time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER); + time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time)); + time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time)); + time.setInputValidator(new DoubleValidator(true)); + time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); + GridDataFactory.fillDefaults().applyTo(time.getWidget()); + // Exploded label = new Label(this, SWT.NONE); label.setText(""); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java index d029ddf4..22228fde 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart.properties.xyline; -import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; @@ -29,6 +28,7 @@ import org.simantics.modeling.ui.chart.property.DoublePropertyModifier; import org.simantics.sysdyn.JFreeChartResource; import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite; import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; /** @@ -70,7 +70,7 @@ public class AxisPropertyComposite extends Composite { min.setColorProvider(new JFreeChartPropertyColorProvider(min.getResourceManager())); min.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min)); min.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min)); - min.setInputValidator(new DoubleValidator()); + min.setInputValidator(new DoubleValidator(true)); label = new Label(minmax, SWT.NONE); label.setText("Max:"); @@ -78,7 +78,7 @@ public class AxisPropertyComposite extends Composite { max.setColorProvider(new JFreeChartPropertyColorProvider(max.getResourceManager())); max.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max)); max.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); - max.setInputValidator(new DoubleValidator()); + max.setInputValidator(new DoubleValidator(true)); // Color @@ -97,24 +97,4 @@ public class AxisPropertyComposite extends Composite { GridDataFactory.fillDefaults().applyTo(axisHide); } - /** - * Validator for validating that an input is double - * @author Teemu Lempinen - * - */ - private class DoubleValidator implements IInputValidator { - @Override - public String isValid(String newText) { - if (newText.trim().isEmpty()) - return null; - try { - Double.parseDouble(newText); - return null; - } catch (NumberFormatException e) { - return e.getMessage(); - } - } - } - - } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java index 421c63c2..857a7caf 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart.properties.xyline; -import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.StructuredSelection; @@ -44,6 +43,7 @@ import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; @@ -185,7 +185,7 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl xmin.setColorProvider(new JFreeChartPropertyColorProvider(xmin.getResourceManager())); xmin.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min)); xmin.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min)); - xmin.setInputValidator(new DoubleValidator()); + xmin.setInputValidator(new DoubleValidator(true)); label = new Label(minmax, SWT.NONE); label.setText("Max:"); @@ -193,7 +193,7 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl xmax.setColorProvider(new JFreeChartPropertyColorProvider(xmax.getResourceManager())); xmax.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max)); xmax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); - xmax.setInputValidator(new DoubleValidator()); + xmax.setInputValidator(new DoubleValidator(true)); // Set the same width to both label rows composite.layout(); @@ -225,25 +225,4 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl }); } - - /** - * Validator for validating that an input is double - * @author Teemu Lempinen - * - */ - private class DoubleValidator implements IInputValidator { - @Override - public String isValid(String newText) { - if (newText.trim().isEmpty()) - return null; - try { - Double.parseDouble(newText); - return null; - } catch (NumberFormatException e) { - return e.getMessage(); - } - } - } - - -} +} \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java index 39f85dcb..26602293 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java @@ -112,11 +112,26 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen if(variable != null) vars.add(variable); } + + // If there is no vars and only one selection, it can be a chart + if(vars.isEmpty() && ress.size() == 1) { + Resource r = ress.iterator().next(); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + if(graph.isInstanceOf(r, jfree.ChartElement)) { + if(graph.hasStatement(r, jfree.ChartElement_component)) { + r = graph.getSingleObject(r, jfree.ChartElement_component); + selectionChanged(graph, r); + return; + } + } + } + } else { // Selection is a jfreechart if(ress.size() == 1) { Resource r = ress.iterator().next(); - if(graph.isInstanceOf(r, JFreeChartResource.getInstance(graph).Chart)) { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + if(graph.isInstanceOf(r, jfree.Chart)) { selectionChanged(graph, r); return; } -- 2.47.1