1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
| package ooswtviewer;
import java.awt.Panel;
import com.sun.star.awt.XView;
import com.sun.star.beans.Property;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.comp.beans.Frame;
import com.sun.star.comp.beans.NoConnectionException;
import com.sun.star.comp.beans.OOoBean;
import com.sun.star.comp.beans.OfficeDocument;
import com.sun.star.drawing.XDrawView;
import com.sun.star.frame.XController;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XFrame;
import com.sun.star.frame.XFramesSupplier;
import com.sun.star.frame.XLayoutManager;
import com.sun.star.frame.XModel;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.ui.XUIElement;
import com.sun.star.uno.Any;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
import com.sun.star.view.XViewSettingsSupplier;
/**
* Code based on example from http://www.eclipsezone.com/eclipse/forums/t48966.html
*
* @author Aaron digulla
*/
public class OOoSwtViewer extends Panel
{
private static final String RESOURCE_TOOLBAR_TEXTOBJECTBAR ="private:resource/toolbar/textobjectbar";
private static final String RESOURCE_TOOLBAR_STANDARDBAR ="private:resource/toolbar/standardbar";
private static final String RESOURCE_MENUBAR ="private:resource/menubar/menubar";
private static final long serialVersionUID = -1408623115735065822L;
private OOoBean aBean;
public OOoSwtViewer()
{
super();
aBean = new OOoBean();
setLayout(new java.awt.BorderLayout());
add(aBean, java.awt.BorderLayout.CENTER);
aBean.setAllBarsVisible (false);
}
public XPropertySet getXPropertySet ()
{
return getXPropertySet (getFrame ());
}
public XPropertySet getXPropertySet (Object o)
{
return (XPropertySet)UnoRuntime.queryInterface (XPropertySet.class, o);
}
public Frame getFrame ()
{
try
{
return aBean.getFrame ();
}
catch (NoConnectionException e)
{
throw new OOException ("Error getting frame from bean", e);
}
}
public XLayoutManager getXLayoutManager ()
{
try
{
return (XLayoutManager)UnoRuntime.queryInterface (XLayoutManager.class, getXPropertySet ().getPropertyValue ("LayoutManager"));
}
catch (Exception e)
{
throw new OOException ("Error getting LayoutManager from bean's properties", e);
}
}
public void setMenuBarVisible (boolean visible)
{
if (visible)
getXLayoutManager ().showElement (RESOURCE_MENUBAR);
else
getXLayoutManager ().hideElement (RESOURCE_MENUBAR);
}
public void setStandardBarVisible (boolean visible)
{
if (visible)
getXLayoutManager ().showElement (RESOURCE_TOOLBAR_STANDARDBAR);
else
getXLayoutManager ().hideElement (RESOURCE_TOOLBAR_STANDARDBAR);
}
public void setTextObjectBarVisible (boolean visible)
{
if (visible)
getXLayoutManager ().showElement (RESOURCE_TOOLBAR_TEXTOBJECTBAR);
else
getXLayoutManager ().hideElement (RESOURCE_TOOLBAR_TEXTOBJECTBAR);
}
private Thread loadThread;
private Exception loadException;
public void setDocument(final String url)
{
loadThread = new Thread () {
public void run() {
try
{
aBean.loadFromURL(url, null);
aBean.aquireSystemWindow();
setTextObjectBarVisible (false);
// for (XUIElement e: getXLayoutManager ().getElements ())
// {
// XInterface i = (XInterface)e.getRealInterface ();
// System.out.println (e);
// System.out.println (i);
// printProperties (getXPropertySet (e));
// }
/*
System.out.println ("frame:");
printProperties (getXPropertySet ());
frame:
Title=test - OpenOffice.org Writer
IndicatorInterception=Any[Type[com.sun.star.task.XStatusIndicator], null]
LayoutManager=Any[Type[com.sun.star.frame.XLayoutManager], [Proxy:26506390,717ea70;msci[0];342169f1a1164ee688893a857f65b3e1,Type[com.sun.star.frame.XLayoutManager]]]
DispatchRecorderSupplier=Any[Type[com.sun.star.frame.XDispatchRecorderSupplier], null]
IsHidden=false
*/
XController controller = aBean.getDocument ().getCurrentController ();
/*
System.out.println ("controller:");
printProperties (getXPropertySet (controller));
controller:
IsConstantSpellcheck=true
IsHideSpellMarks=false
LineCount=1
PageCount=1
*/
/*
System.out.println ("layoutManager:");
printProperties (getXPropertySet (getXLayoutManager ()));
layoutManager:
AutomaticToolbars=true
HideCurrentUI=false
LockCount=0
MenuBarCloser=true
RefreshContextToolbarVisibility=false
*/
/*
System.out.println ("document:");
printProperties (getXPropertySet (aBean.getDocument ()));
OfficeDocument doc = aBean.getDocument ();
ApplyFormDesignMode=false
ApplyWorkaroundForB6375613=false
AutomaticControlFocus=false
BasicLibraries=Any[Type[com.sun.star.script.XLibraryContainer], [Proxy:14806696,73ca178;msci[0];342169f1a1164ee688893a857f65b3e1,Type[com.sun.star.script.XLibraryContainer]]]
BuildId=680$9310
CharFontCharSet=1
CharFontCharSetAsian=1
CharFontCharSetComplex=1
CharFontFamily=3
CharFontFamilyAsian=6
CharFontFamilyComplex=6
CharFontName=Times New Roman
CharFontNameAsian=Arial Unicode MS
CharFontNameComplex=Tahoma
CharFontPitch=2
CharFontPitchAsian=2
CharFontPitchComplex=2
CharFontStyleName=
CharFontStyleNameAsian=
CharFontStyleNameComplex=
CharLocale=com.sun.star.lang.Locale@fb6354
CharacterCount=20
DialogLibraries=Any[Type[com.sun.star.script.XLibraryContainer], [Proxy:3556929,73a39c0;msci[0];342169f1a1164ee688893a857f65b3e1,Type[com.sun.star.script.XLibraryContainer]]]
ForbiddenCharacters=Any[Type[com.sun.star.i18n.XForbiddenCharacters], [Proxy:11544872,7669148;msci[0];342169f1a1164ee688893a857f65b3e1,Type[com.sun.star.i18n.XForbiddenCharacters]]]
HasValidSignatures=false
HideFieldTips=false
IndexAutoMarkFileURL=
LockUpdates=false
ParagraphCount=1
RecordChanges=false
RedlineDisplayType=2
RedlineProtectionKey=[B@f593af
RuntimeUID=10
ShowChanges=true
TwoDigitYear=1930
WordCount=5
WordSeparator=()
*/
// System.out.println ("viewData:");
// printProperties (getXPropertySet (controller.getFrame ().getContainerWindow ()));
XViewSettingsSupplier settingsSupplier = (XViewSettingsSupplier)UnoRuntime.queryInterface (XViewSettingsSupplier.class, controller);
// System.out.println ("settingsSupplier:");
// printProperties (settingsSupplier.getViewSettings ());
settingsSupplier.getViewSettings ().setPropertyValue ("ShowVertRuler", Boolean.FALSE);
settingsSupplier.getViewSettings ().setPropertyValue ("ShowHoriRuler", Boolean.FALSE);
// Switch to Web Layout. This layout mode comes without gray border and the page borders automatically adujst to the frame
settingsSupplier.getViewSettings ().setPropertyValue ("ShowOnlineLayout", Boolean.TRUE);
// settingsSupplier.getViewSettings ().setPropertyValue ("ShowTextBoundaries", Boolean.TRUE);
// XView view = (XView)UnoRuntime.queryInterface (XView.class, getFrame ());
// System.out.println ("drawView="+view);
// printProperties (getXPropertySet (view));
/*
XModel model = (XModel)UnoRuntime.queryInterface (XModel.class, doc);
printProperties ("model", model);
Same as getDocument()
*/
/*
System.out.println ("Interfaces implemented by aBean.getDocument():");
for (Class c: OOoInspector.queryInterface (aBean.getDocument ()))
System.out.println (" "+c.getName ());
com.sun.star.datatransfer.XTransferable
com.sun.star.document.XDocumentInfoSupplier
com.sun.star.document.XDocumentLanguages
com.sun.star.document.XDocumentSubStorageSupplier
com.sun.star.document.XEmbeddedScripts
com.sun.star.document.XEventBroadcaster
com.sun.star.document.XEventsSupplier
com.sun.star.document.XLinkTargetSupplier
com.sun.star.document.XRedlinesSupplier
com.sun.star.document.XStorageBasedDocument
com.sun.star.document.XViewDataSupplier
com.sun.star.drawing.XDrawPageSupplier
com.sun.star.embed.XVisualObject
com.sun.star.frame.XLoadable
com.sun.star.frame.XModel
com.sun.star.frame.XModel2
com.sun.star.frame.XModule
com.sun.star.frame.XStorable
com.sun.star.frame.XStorable2
com.sun.star.script.provider.XScriptProviderSupplier
com.sun.star.style.XAutoStylesSupplier
com.sun.star.style.XStyleFamiliesSupplier
com.sun.star.text.XBookmarksSupplier
com.sun.star.text.XChapterNumberingSupplier
com.sun.star.text.XDocumentIndexesSupplier
com.sun.star.text.XEndnotesSupplier
com.sun.star.text.XFootnotesSupplier
com.sun.star.text.XLineNumberingProperties
com.sun.star.text.XNumberingRulesSupplier
com.sun.star.text.XPagePrintable
com.sun.star.text.XReferenceMarksSupplier
com.sun.star.text.XTextDocument
com.sun.star.text.XTextEmbeddedObjectsSupplier
com.sun.star.text.XTextFieldsSupplier
com.sun.star.text.XTextFramesSupplier
com.sun.star.text.XTextGraphicObjectsSupplier
com.sun.star.text.XTextSectionsSupplier
com.sun.star.text.XTextTablesSupplier
com.sun.star.ui.XUIConfigurationManagerSupplier
com.sun.star.util.XCloseable
com.sun.star.util.XCloseBroadcaster
com.sun.star.util.XLinkUpdate
com.sun.star.util.XModifiable
com.sun.star.util.XModifiable2
com.sun.star.util.XModifyBroadcaster
com.sun.star.util.XNumberFormatsSupplier
com.sun.star.util.XRefreshable
com.sun.star.util.XReplaceable
com.sun.star.util.XSearchable
com.sun.star.view.XPrintable
com.sun.star.view.XPrintJobBroadcaster
com.sun.star.view.XRenderable
com.sun.star.xforms.XFormsSupplier
*/
/*
System.out.println ("Interfaces implemented by controller:");
for (Class c: OOoInspector.queryInterface (controller))
System.out.println (" "+c.getName ());
com.sun.star.awt.XUserInputInterception
com.sun.star.datatransfer.XTransferableSupplier
com.sun.star.frame.XController
com.sun.star.frame.XControllerBorder
com.sun.star.frame.XDispatchInformationProvider
com.sun.star.frame.XDispatchProvider
com.sun.star.task.XStatusIndicatorSupplier
com.sun.star.text.XRubySelection
com.sun.star.text.XTextViewCursorSupplier
com.sun.star.ui.XContextMenuInterception
com.sun.star.view.XControlAccess
com.sun.star.view.XFormLayerAccess
com.sun.star.view.XSelectionSupplier
com.sun.star.view.XViewSettingsSupplier
*/
/*
System.out.println ("Interfaces implemented by frame:");
for (Class c: OOoInspector.queryInterface (getFrame ()))
System.out.println (" "+c.getName ());
com.sun.star.awt.XFocusListener
com.sun.star.awt.XTopWindowListener
com.sun.star.awt.XWindowListener
com.sun.star.document.XActionLockable
com.sun.star.frame.XComponentLoader
com.sun.star.frame.XDispatchInformationProvider
com.sun.star.frame.XDispatchProvider
com.sun.star.frame.XDispatchProviderInterception
com.sun.star.frame.XFrame
com.sun.star.frame.XFramesSupplier
com.sun.star.task.XStatusIndicatorFactory
com.sun.star.util.XCloseable
com.sun.star.util.XCloseBroadcaster
*/
/*
XFramesSupplier frames = OOoInspector.queryInterface (XFramesSupplier.class, getFrame ());
printProperties ("frames", frames);
for (int i=0; iframes.getFrames ().getCount (); i++)
{
XFrame frame = (XFrame)frames.getFrames ().getByIndex (i);
printProperties ("Frame"+i, frame);
}
frames=[Proxy:16382237,6ace84c;msci[0];342169f1a1164ee688893a857f65b3e1,Type[com.sun.star.frame.XFramesSupplier]]
Title=test - OpenOffice.org Writer
IndicatorInterception=Any[Type[com.sun.star.task.XStatusIndicator], null]
LayoutManager=Any[Type[com.sun.star.frame.XLayoutManager], [Proxy:22149392,76bd794;msci[0];342169f1a1164ee688893a857f65b3e1,Type[com.sun.star.frame.XLayoutManager]]]
DispatchRecorderSupplier=Any[Type[com.sun.star.frame.XDispatchRecorderSupplier], null]
IsHidden=false
*/
XPropertySet p = getXPropertySet (getFrame ());
Any any = (Any)p.getPropertyValue ("LayoutManager");
System.out.println (any);
System.out.println (any.getClass ().getName ());
XLayoutManager layoutManager = (XLayoutManager)any.getObject ();
printProperties ("layoutManager", layoutManager);
/*
printProperties ("containerWindow", getFrame ().getContainerWindow ());
containerWindow=[Proxy:11970262,6d33e60;msci[0];342169f1a1164ee688893a857f65b3e1,Type[com.sun.star.awt.XWindow]]
null
*/
/*
printProperties ("componentWindow", getFrame ().getComponentWindow ());
componentWindow=[Proxy:25380515,8657cc4;msci[0];342169f1a1164ee688893a857f65b3e1,Type[com.sun.star.awt.XWindow]]
null
*/
}
catch (Exception e)
{
e.printStackTrace ();
}
}
};
if (1 == 1)
loadThread.start ();
else
loadThread.run ();
}
/** closes the bean viewer and tries to terminate OOo.
*/
public void terminate() throws NoConnectionException {
setVisible(false);
XDesktop xDesktop = null;
xDesktop = aBean.getOOoDesktop();
aBean.stopOOoConnection();
if (xDesktop != null)
xDesktop.terminate();
}
/** closes the bean viewer, leaves OOo running.
*/
public void close() {
setVisible(false);
aBean.stopOOoConnection();
}
public void printProperties (String name, Object obj)
{
System.out.println (name+"="+obj);
if (obj != null)
printProperties (getXPropertySet (obj));
}
public void printProperties (XPropertySet set)
{
if (set == null)
{
System.out.println ("null");
return;
}
for (Property p: set.getPropertySetInfo ().getProperties ())
{
try
{
System.out.println (p.Name+"="+set.getPropertyValue (p.Name));
}
catch (Exception e)
{
throw new OOException ("Error getting value of property"+p.Name, e);
}
}
}
} |