ChartUtil.java (04813259) ChartUtil.java (70af8983)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 17 unchanged lines hidden (view full) ---

26import com.sun.star.drawing.XShape;
27import com.sun.star.lang.XMultiServiceFactory;
28import com.sun.star.uno.UnoRuntime;
29
30public class ChartUtil {
31
32 /**
33 * Retrieve Chart document as model of the OLE Shape(use to create chart)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 17 unchanged lines hidden (view full) ---

26import com.sun.star.drawing.XShape;
27import com.sun.star.lang.XMultiServiceFactory;
28import com.sun.star.uno.UnoRuntime;
29
30public class ChartUtil {
31
32 /**
33 * Retrieve Chart document as model of the OLE Shape(use to create chart)
34 *
34 * @param xShape
35 * @return
36 * @throws Exception
37 */
35 * @param xShape
36 * @return
37 * @throws Exception
38 */
38 public static XChartDocument retrieveChartDocument(XShape xShape)throws Exception{
39 public static XChartDocument retrieveChartDocument(XShape xShape)
40 throws Exception {
39 XChartDocument aChartDoc = null;
40 final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e";
41 // make the OLE shape a chart
42 XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
43 XPropertySet.class, xShape);
44 // set the class id for charts
45 aShapeProp.setPropertyValue("CLSID", msChartClassID);
46 // retrieve the chart document as model of the OLE shape
47 aChartDoc = (XChartDocument) UnoRuntime.queryInterface(
48 XChartDocument.class, aShapeProp.getPropertyValue("Model"));
49 return aChartDoc;
50 }
41 XChartDocument aChartDoc = null;
42 final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e";
43 // make the OLE shape a chart
44 XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
45 XPropertySet.class, xShape);
46 // set the class id for charts
47 aShapeProp.setPropertyValue("CLSID", msChartClassID);
48 // retrieve the chart document as model of the OLE shape
49 aChartDoc = (XChartDocument) UnoRuntime.queryInterface(
50 XChartDocument.class, aShapeProp.getPropertyValue("Model"));
51 return aChartDoc;
52 }
51
53
52 /**
54 /**
55 * retrieve chart2 document as model of the OLE shape
56 *
57 * @param xShape
58 * @return
59 * @throws Exception
60 */
61 public static com.sun.star.chart2.XChartDocument retrieveChart2Document(
62 XShape xShape) throws Exception {
63 com.sun.star.chart2.XChartDocument aChartDoc = null;
64 final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e";
65 // make the OLE shape a chart
66 XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
67 XPropertySet.class, xShape);
68 // set the class id for charts
69 aShapeProp.setPropertyValue("CLSID", msChartClassID);
70 // retrieve the chart document as model of the OLE shape
71 aChartDoc = (com.sun.star.chart2.XChartDocument) UnoRuntime
72 .queryInterface(com.sun.star.chart2.XChartDocument.class,
73 aShapeProp.getPropertyValue("Model"));
74 return aChartDoc;
75 }
76
77 /**
53 * Create Chart in ChartDocument.
78 * Create Chart in ChartDocument.
79 *
54 * @param aChartDoc
55 * @param ChartType
56 * @return
57 * @throws Exception
58 */
80 * @param aChartDoc
81 * @param ChartType
82 * @return
83 * @throws Exception
84 */
59 public static XDiagram createChart(XChartDocument aChartDoc, String ChartType)
60 throws Exception {
61
85 public static XDiagram createChart(XChartDocument aChartDoc,
86 String ChartType) throws Exception {
87
62 // let aChartDoc be a valid XChartDocument
63 // get the factory that can create diagrams
64 XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime
65 .queryInterface(XMultiServiceFactory.class, aChartDoc);
66 XDiagram aDiagram = (XDiagram) UnoRuntime.queryInterface(
67 XDiagram.class, aFact.createInstance(ChartType));
68 return aDiagram;
69 }
88 // let aChartDoc be a valid XChartDocument
89 // get the factory that can create diagrams
90 XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime
91 .queryInterface(XMultiServiceFactory.class, aChartDoc);
92 XDiagram aDiagram = (XDiagram) UnoRuntime.queryInterface(
93 XDiagram.class, aFact.createInstance(ChartType));
94 return aDiagram;
95 }
70
71
96
72 /**
97 /**
98 * Create Chart2 in ChartDocument.
99 *
100 * @param aChartDoc
101 * @param ChartType
102 * @return
103 * @throws Exception
104 */
105 public static com.sun.star.chart2.XDiagram createChart2(
106 com.sun.star.chart2.XChartDocument aChartDoc, String ChartType)
107 throws Exception {
108
109 // let aChartDoc be a valid XChartDocument
110 // get the factory that can create diagrams
111 XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime
112 .queryInterface(XMultiServiceFactory.class, aChartDoc);
113 com.sun.star.chart2.XDiagram aDiagram = (com.sun.star.chart2.XDiagram) UnoRuntime
114 .queryInterface(com.sun.star.chart2.XDiagram.class,
115 aFact.createInstance(ChartType));
116 return aDiagram;
117 }
118
119 /**
73 * Get Chart Doc from a Shape
120 * Get Chart Doc from a Shape
121 *
74 * @param xShape
75 * @return
76 * @throws Exception
77 */
122 * @param xShape
123 * @return
124 * @throws Exception
125 */
78 public static XChartDocument getChartDocument(XShape xShape)throws Exception{
126 public static XChartDocument getChartDocument(XShape xShape)
127 throws Exception {
79 XChartDocument aChartDoc = null;
80 XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
81 XPropertySet.class, xShape);
82 // retrieve the chart document as model of the OLE shape
83 aChartDoc = (XChartDocument) UnoRuntime.queryInterface(
84 XChartDocument.class, aShapeProp.getPropertyValue("Model"));
85 return aChartDoc;
128 XChartDocument aChartDoc = null;
129 XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
130 XPropertySet.class, xShape);
131 // retrieve the chart document as model of the OLE shape
132 aChartDoc = (XChartDocument) UnoRuntime.queryInterface(
133 XChartDocument.class, aShapeProp.getPropertyValue("Model"));
134 return aChartDoc;
86
135
87 }
136 }
137 /**
138 * Get Chart2 Doc from a Shape
139 *
140 * @param xShape
141 * @return
142 * @throws Exception
143 */
144 public static com.sun.star.chart2.XChartDocument getChart2Document(XShape xShape)
145 throws Exception {
146 com.sun.star.chart2.XChartDocument aChartDoc = null;
147 XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
148 XPropertySet.class, xShape);
149 // retrieve the chart document as model of the OLE shape
150 aChartDoc = (com.sun.star.chart2.XChartDocument) UnoRuntime.queryInterface(
151 com.sun.star.chart2.XChartDocument.class, aShapeProp.getPropertyValue("Model"));
152 return aChartDoc;
153
154 }
88}
155}