From: permondes Date: Thu, 19 Dec 2019 16:03:43 +0000 (+0100) Subject: Initial release to git of this project from 2012/2013 X-Git-Url: https://permondes.de/gitweb/BorderLiner_Java.git/commitdiff_plain Initial release to git of this project from 2012/2013 --- 615be951ad3fcb405e3558823369ae1f145b9b65 diff --git a/BorderLiner 2p1p2.odt b/BorderLiner 2p1p2.odt new file mode 100755 index 0000000..6836806 Binary files /dev/null and b/BorderLiner 2p1p2.odt differ diff --git a/ColorChooser/ColorChooser.java b/ColorChooser/ColorChooser.java new file mode 100644 index 0000000..96950f1 --- /dev/null +++ b/ColorChooser/ColorChooser.java @@ -0,0 +1,239 @@ +/* ColorChooser.java - a Java class for a color choosing dialog for OpenOffice.org + * + * Copyright (C) 2008 Dietmar Hiller, dhiller + + This program is free software; you can redistribute it and/or modify it under the Terms of the GNU Lesser General Public License + as published by the Free Software Foundation; version 3 of the License. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with this program; if not, + see . + * + * Created on 5. Mai 2008, 21:34 + * + */ + +package name.dhiller.ooo.ColorChooser; + +import com.sun.star.awt.*; +import com.sun.star.beans.PropertyVetoException; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.beans.XPropertySet; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.lib.uno.helper.WeakBase; +import com.sun.star.lib.uno.helper.Factory; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.lang.XSingleComponentFactory; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.registry.XRegistryKey; +import com.sun.star.report.XImageControl; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.UnoRuntime; + +import java.awt.Color; + +/** Colordialog for OpenOffice.org + * @author dhiller + * @version 080507 + * @since OOo 2.0.4 (dialog handling, see http://api.openoffice.org/docs/DevelopersGuide/Components/Components.xhtml ch. 4.11) + */ +public final class ColorChooser extends WeakBase + implements XDialogEventHandler +{ + private final XComponentContext m_xContext; + private XDialog m_xDialog; + private XControlContainer m_xCC; + private XScrollBar m_xDlgHue; + private XNumericField m_xDlgSat; + private XNumericField m_xDlgVal; + private XPropertySet m_xrColorPS; + private Color m_initialColor; + private Color m_returnColor; + + /** Creates a new instance of ColorChooser */ + public ColorChooser(XComponentContext xContext) { + m_xContext = xContext; + } + + /** create ColorDialog and execute + * @param sDlgDir - URL of directory with dialog + * @param sDlgName - Name of dialog + * @param sDlgHue - URL to image of hue + * @param initialColor + * @since OpenOffice.org 2.0.4 + * @return Color final color + * @exception com.sun.star.lang.IllegalArgumentException + * @exception com.sun.star.uno.Exception + */ + // http://api.openoffice.org/docs/common/ref/com/sun/star/awt/XDialogProvider2.html + public Color executeDialog(String sDlgDir, String sDlgName, String sDlgHue, + Color initialColor) { + try { + final XMultiComponentFactory xFact = m_xContext.getServiceManager(); + final Object xObject = xFact.createInstanceWithContext( + "com.sun.star.awt.DialogProvider2", m_xContext); + final XDialogProvider2 aDialogProvider = (XDialogProvider2) + UnoRuntime.queryInterface(XDialogProvider2.class, xObject); + m_xDialog = aDialogProvider.createDialogWithHandler + (sDlgDir+"/"+sDlgName, this); + + Init(m_xDialog, sDlgDir+"/"+sDlgHue,initialColor); + + short nReturnValue = m_xDialog.execute(); + + if (nReturnValue == 1) { // okay + m_returnColor = getColor(); } + } catch (com.sun.star.lang.IllegalArgumentException ex) { + ex.printStackTrace(); + } catch (com.sun.star.uno.Exception ex) { + ex.printStackTrace(); + } + return m_returnColor; + } + + /** + * Initialize the Dialog (used internally only) + * @param theDialog + * @param sURLHue URL to hue file + * @param initialColor + */ + private void Init(XDialog theDialog, String sURLHue, Color initialColor) { + m_initialColor = initialColor; + m_xCC = (XControlContainer)UnoRuntime.queryInterface(XControlContainer.class, + theDialog); + // always useful controls etc + final XControl xDlgHueCtrl = m_xCC.getControl("dlgHue"); + m_xDlgHue = (XScrollBar) UnoRuntime.queryInterface(XScrollBar.class, xDlgHueCtrl); + + final XControl xDlgSatCtrl = m_xCC.getControl("dlgSat"); + m_xDlgSat = (XNumericField) UnoRuntime.queryInterface(XNumericField.class, xDlgSatCtrl); + + final XControl xDlgValCtrl = m_xCC.getControl("dlgVal"); + m_xDlgVal = (XNumericField) UnoRuntime.queryInterface(XNumericField.class, xDlgValCtrl); + + final XControl xrColor = m_xCC.getControl("rColor"); + final XControlModel xrColorModel = xrColor.getModel(); + m_xrColorPS = (XPropertySet)UnoRuntime.queryInterface + (XPropertySet.class, xrColorModel ); + // Colorbar + final XControl xImgHue = m_xCC.getControl("imgHue"); + final XControlModel xImgHueModel = xImgHue.getModel(); + final XPropertySet xPS = (XPropertySet)UnoRuntime.queryInterface + (XPropertySet.class, xImgHueModel ); + try { + xPS.setPropertyValue( "ImageURL", sURLHue); + } catch (UnknownPropertyException ex) { + ex.printStackTrace(); + } catch (PropertyVetoException ex) { + ex.printStackTrace(); + } catch (WrappedTargetException ex) { + ex.printStackTrace(); + } catch (com.sun.star.lang.IllegalArgumentException ex) { + ex.printStackTrace(); + } + setColor(initialColor); + } + + /** called from the dialog to handle events + * there is no need to call it directly + * @param xDialog the dialog instance that generated the event + * @param aEvent object derived from ::com::sun::star::lang::EventObject + * @param aEventString the name of the function which is to be called + * @return true if the event was handled, otherwise false. + * interface XDialogEventHandler + */ + public boolean callHandlerMethod(XDialog xDialog, Object aEvent, String aEventString ) { + boolean returnValue = false; + if (aEventString.equals("DlgColorHSV")) { // any color button + Color gotColor = getColor(); + setPreview(gotColor); + returnValue = true; + } + else if (aEventString.equals("DlgOkay")) { // BOK + m_returnColor = getColor(); + m_xDialog.endExecute(); + returnValue = true; + } + else if (aEventString.equals("DlgCancel")) { // BCancel + m_returnColor = m_initialColor; + m_xDialog.endExecute(); + returnValue = true; + } + else if (aEventString.equals("DlgReset")) { // BReset + setColor(m_initialColor); + returnValue = true; + } + return returnValue; + } + + /** getSupportedMethodNames + * there is no need to call it directly + * interface XDialogEventHandler + */ + public String[] getSupportedMethodNames() { + String[] retValue= new String[4]; + retValue[0]= "DlgOkay"; // BOK + retValue[1]= "DlgCancel"; // BCancel + retValue[2]= "DlgReset"; // BReset + retValue[3]= "DlgColorHSV"; // any color button + return retValue; + } + + /** gets the Color from the dialog + * @return Color + */ + private Color getColor() { + float hue = (float) m_xDlgHue.getValue() / 360.0f; + float sat = (float) m_xDlgSat.getValue() / 100.0f; + float val = (float) m_xDlgVal.getValue() / 100.0f; + Color workColor = new Color(0); + Color gotColor = Color.getHSBColor(hue, sat, val); + return gotColor; + } + + /** display color values + * Hue: 0..360, Saturation: 0..100, Value/Brightness: 0..100 + * @param initialColor + */ + private void setColor(Color initialColor) { + float[] colorHSB = initialColor.RGBtoHSB( initialColor.getRed(), + initialColor.getGreen(), initialColor.getBlue(), null); + m_xDlgHue.setValue(Math.round(colorHSB[0]*360)); + m_xDlgSat.setValue(Math.round(colorHSB[1]*100)); + m_xDlgVal.setValue(Math.round(colorHSB[2]*100)); + setPreview(initialColor); + } + + /** set color of preview bar + * @param color color to be set + * @exception UnknownPropertyException Property "BackgroundColor" not available + * @exception PropertyVetoException Property "BackgroundColor" not available + * @exception WrappedTargetException at setPropertyValue "BackgroundColor" + * @exception com.sun.star.lang.IllegalArgumentException at setPropertyValue "BackgroundColor" + */ + private void setPreview(Color color) { + try { + m_xrColorPS.setPropertyValue( "BackgroundColor", Math.round(color.getRed()*256*256 + +color.getGreen()*256 + color.getBlue())); + } catch (UnknownPropertyException ex) { + ex.printStackTrace(); + } catch (PropertyVetoException ex) { + ex.printStackTrace(); + } catch (WrappedTargetException ex) { + ex.printStackTrace(); + } catch (com.sun.star.lang.IllegalArgumentException ex) { + ex.printStackTrace(); + } + } + + /** returns the version of this class + * this function MUST be maintained for every modification + * @return Version in the format YYMMDD- + */ + public String getVersion() { + return ("080507-DHiller"); + } + +} diff --git a/Extension Knowhow.odt b/Extension Knowhow.odt new file mode 100755 index 0000000..718417a Binary files /dev/null and b/Extension Knowhow.odt differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ec2f1f4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +The contents of the Documentation are subject to the Public Documentation License, Version 1.0 (the "License"); you may only use this Documentation if you comply with the terms of this License. +A copy of the License is available at: +http://www.openoffice.org/licenses/PDL.rtf + +The Original Documentation is "BorderLiner". The Initial Writer(s) of the Original Documentation is Dietmar Hiller© 2006-2012. All Rights Reserved. (Initial Writer contact(s): provider: gmx in Germany (.de), user-ID: dhiller1) +Contributor(s): ______________________________________. +Portions created by ______ are Copyright (C)_________[insert year(s)]. All Rights Reserved. (Contributor contact(s):________________[insert hyperlink/alias]). +All trademarks within this guide belong to legitimate owners. +[Note: a copy of the PDL is included in this template and is also available at: http://www.openoffice.org/licenses/PDL.rtf.] + +The extension BorderLiner is released under GPL3. diff --git a/OOoRegistry/OOoRegistry.java b/OOoRegistry/OOoRegistry.java new file mode 100644 index 0000000..3420886 --- /dev/null +++ b/OOoRegistry/OOoRegistry.java @@ -0,0 +1,123 @@ +/** OOoRegistry.java - a Java class to handle OpenOffice.org's Registry + * + * Copyright (C) 2008 Dietmar Hiller, dhiller + + This program is free software; you can redistribute it and/or modify it under the Terms of the GNU Lesser General Public License + as published by the Free Software Foundation; version 3 of the License. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with this program; if not, + see . + * + * Created on 5. Mai 2008, 21:34 + * + */ + +package name.dhiller.ooo.OOoRegistry; + +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.container.XNameAccess; +import com.sun.star.util.XMacroExpander; +import com.sun.star.beans.PropertyValue; + +/** Handling of the Openoffice.org registry + * @author Dietmar Hiller (dhiller) + * @version 080508 + * @since OOo 2.0 + */ +public class OOoRegistry { + private final XComponentContext m_xContext; + + /** Creates a new instance of OOoRegistry + */ + public OOoRegistry(XComponentContext xContext) { + m_xContext = xContext; + } + + /** get String from registry + * @param sPackageName name of package (e.g. org.openoffice.my_extension_name) + * @param sPath the path a registryNode + * @param sRegKey the name of the registry key + * @return String + * @exception Exception returns empty string + */ + public String getString(String sPackageName, String sPath, String sRegKey) { + String sString = ""; + try { + // retrive the configuration node of the extension ##### + XNameAccess xNameAccess = getRegistryKeyContent(sPackageName+"."+sPath); + if (xNameAccess != null){ + if (xNameAccess.hasByName(sRegKey)){ + sString = (String) xNameAccess.getByName(sRegKey); + } + } + } catch (Exception ex) { + ex.printStackTrace(System.out); + } + return sString; + } + + /** get the value of a path, expand %origin% if available + * @param sPackageName name of package (e.g. org.openoffice.my_extension_name) + * @param sPath the path a registryNode + * @param sRegKey the name of the registry key + * @return local path to + * @exception Exception e.g. substring was not successfull, because string was not expanded; nevertheless, sUrl contains the correct data and can be returned + */ + public String getValue(String sPackageName, String sPath, String sRegKey){ + String sUrl = ""; + try { + // get the Url and process the Url by the macroexpander... + sUrl = getString(sPackageName, sPath, sRegKey); + Object oMacroExpander = + this.m_xContext.getValueByName("/singletons/com.sun.star.util.theMacroExpander"); + XMacroExpander xMacroExpander = (XMacroExpander) + UnoRuntime.queryInterface(XMacroExpander.class, oMacroExpander); + sUrl = xMacroExpander.expandMacros(sUrl); + sUrl = sUrl.substring(new String("vnd.sun.star.expand:").length(), sUrl.length()); + sUrl = sUrl.trim(); + } catch (Exception ex) { + return sUrl; + // e.g. substring was not successfull, because string was not expanded + // nevertheless, sUrl contains the correct data and can be returned + } + return sUrl; + } + +/* get access to the registry + * @author dhiller + * @version 071208 + * @param _sKeyName - key as in .xcu + * @return XNameAccess + * @exception Exception + */ +private XNameAccess getRegistryKeyContent(String _sKeyName){ +try { + Object oConfigProvider; + PropertyValue[] aNodePath = new PropertyValue[1]; + + XMultiComponentFactory m_xMCF = m_xContext.getServiceManager(); + + oConfigProvider = + m_xMCF.createInstanceWithContext("com.sun.star.configuration.ConfigurationProvider", this.m_xContext); + aNodePath[0] = new PropertyValue(); + aNodePath[0].Name = "nodepath"; + aNodePath[0].Value = _sKeyName; + XMultiServiceFactory xMSFConfig = (XMultiServiceFactory) + UnoRuntime.queryInterface(XMultiServiceFactory.class, oConfigProvider); + Object oNode = + xMSFConfig.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath); + XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, oNode); + return xNameAccess; +} +catch (Exception exception) { + exception.printStackTrace(System.out); + return null; +} +} +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..ec64d6d --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +## BorderLiner - an extension for LibreOffice + +This version of BorderLiner was written in 2012 in Java. +It was a follow up project of the version 1 in BASIC. + +The extension provided an easy way to copy and appy borders to cells in LibreOffice Calc. +It is probably not compatible to the current version of Calc. Calc contains a nice way to apply borders anyway. + +### Files +* borderliner.oxt - the extension package for the program. It is actually a zipped archive and thus the source code and all associated files can be found therein +* BorderLiner2p1p2.odt - documentation of the last version released +* Extension Knowhow.odt - some learnings about extension development those days +* ColorChooser/ColorChooser.java - a sub-program to choose colors; +* OOoRegistry/OOoRegistry.java - a sub-program to handle the LibreOffice registry +* LICENSE - License of documentation and software +* README.md - this file diff --git a/borderliner.oxt b/borderliner.oxt new file mode 100644 index 0000000..3f45fe9 Binary files /dev/null and b/borderliner.oxt differ