/** Creates a new instance of MessageBox */ public MessageBox(XComponentContext _xContext, XMultiComponentFactory _xMCF){
m_xContext = _xContext;
m_xMCF = _xMCF;
}
MessageBox oMessageBox = new MessageBox(xContext, xMCF);
//load default text document to get an active frame
xComp = oMessageBox.createDefaultTextDocument();
XWindowPeer xWindowPeer = oMessageBox.getWindowPeerOfFrame(xComp); if (xWindowPeer != null) {
XVclWindowPeer xVclWindowPeer = UnoRuntime.queryInterface(XVclWindowPeer.class, xWindowPeer); boolean bisHighContrast = oMessageBox.isHighContrastModeActivated(xVclWindowPeer);
oMessageBox.showErrorMessageBox(xWindowPeer, "My Sampletitle", "HighContrastMode is enabled: " + bisHighContrast);
} else{
System.out.println("Could not retrieve current frame");
}
} catch( Exception e ) {
System.err.println( e + e.getMessage());
e.printStackTrace();
} finally { if (xComp != null) { try {
XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xComp); if (xClose != null) {
xClose.close(false);
} else {
xComp.dispose();
}
} catch (com.sun.star.util.CloseVetoException e) {
System.err.println( e + e.getMessage());
e.printStackTrace();
}
}
}
System.exit( 0 );
}
// helper method to get the window peer of a document or if no // document is specified it tries to get the active frame // which is potentially dangerous public XWindowPeer getWindowPeerOfFrame(XComponent xComp) { try {
XFrame xFrame = null;
} else { // Note: This method is potentially dangerous and should only be used for debugging // purposes as it relies on the platform dependent window handler...
Object oDesktop = m_xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_xContext);
XFramesSupplier xFramesSupplier = UnoRuntime.queryInterface(XFramesSupplier.class, oDesktop);
xFrame = xFramesSupplier.getActiveFrame();
}
// get the component loader from the desktop to create a new // text document
com.sun.star.frame.XComponentLoader xCLoader =UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class,oDesktop);
com.sun.star.beans.PropertyValue[] args = new com.sun.star.beans.PropertyValue [1];
args[0] = new com.sun.star.beans.PropertyValue();
args[0].Name = "Hidden";
args[0].Value = Boolean.TRUE;
String strDoc = "private:factory/swriter";
/** @param _xVclWindowPeer the windowpeer of a dialog control or the dialog itself *@returntrueifHighContrastModeisactivatedorfalseifHighContrastModeisdeactivated
*/ publicboolean isHighContrastModeActivated(XVclWindowPeer _xVclWindowPeer) { boolean bIsActivated = false;
try { if (_xVclWindowPeer != null){ int nUIColor = AnyConverter.toInt(_xVclWindowPeer.getProperty("DisplayBackgroundColor")); int nRed = getRedColorShare(nUIColor); int nGreen = getGreenColorShare(nUIColor); int nBlue = getBlueColorShare(nUIColor); int nLuminance = (( nBlue*28 + nGreen*151 + nRed*77 ) / 256 ); boolean bisactivated = (nLuminance <= 25); return bisactivated;
} else{ returnfalse;
}
} catch (IllegalArgumentException e) {
e.printStackTrace(System.err);
} return bIsActivated;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.