Hi,

Il 26/10/2010 05:33, Pivithuru Wijegunawardana ha scritto:
Hi,

I am searching for a JPanel in java  like performing dialog control in
Openoffice to contain some other controls inside. And this control model
should be able to make visible and invisible such that the controls inside
it also does the same action. I looked into UnoControlGroupBoxModel, but it
seem to be only a visual component to group controls.
Is the above task possible in UNO awt? If it is possible what control I
should use for that?

The basic and most spread technique to control the visibility of groups of controls is by means of "dialog steps"

You may think to dialog steps just like to layers.
Each layer may contain controls.

Both dialog and control models offer a "Step" property that can be set to an integer value at design time or even at runtime.

If you set the Step property of the dialog to a given value, only controls with the same Step value are shown

The Step=0 have a special meaning:

If you set the *dialog* Step to 0 , all controls will be made visible, regardless their Step actual value.

If you set one control Step to 0 , that control wil be always visible, regardless the current Step value of the dialog.

A more versatile technique is by using the service: com.sun.star.awt.UnoControlContainer

Is not easy to use this control in dialogs, because it is not available in the toolbox of the dialog designer (you cannot use it at design time)

Another problem is that UnoControlContainer is not even registered at the XMultiServiceFactory of the UnoDialog model, so in theory you couldn't even use it at runtime.

In order to workaround the above mentioned limitations, I use a technique that makes use of normal FixedText controls as "placeholders" at design time. (Actually you can use any kind of control as placeholders but the fixedtext is the more suitable since it doesn't react to mouse/keyboard events and it doesn't eat much resources )

At runtime, placeholder controls are replaced (or better: overlayed) by a UnoControlContainer instanciated from the main MultiServiceFactory

Please, see the example below:
(before to run it you should prepare an Uno dialog named "Dialog1" with two labels (UnoFixedText controls) named "Label1" and "Label2"

More examples of that technique are in the source code of the BasicAddonBuilder extension:
http://www.paolo-mantovani.org/downloads/BasicAddonBuilder/


regards
Paolo Mantovani


------------------8<------------------


REM  *****  BASIC  *****

Sub Main
  oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1)

  xray oDlg
  oLbl1 = oDlg.getControl("Label1")
  oLbl2 = oDlg.getControl("Label2")

  'create a child window in the area of the oLbl1
  aPosSize = GetRect(0, 0, oLbl1.Size.Width, oLbl1.Size.Height)
  oViewFrame = CreateChildFrame(oLbl1.Peer, aPosSize)

  'create a control container service that will host the whole TranslateBox
  oCont1 = CreateUnoControl("Container")
  With oCont1.Model
    .Border = 1 ' 3D border
    '.BackgroundColor = //
  End With
oCont1.createPeer(oViewFrame.ContainerWindow.Toolkit, oViewFrame.ContainerWindow)
  oViewFrame.setComponent(oCont1, Null)

  'create a child window in the area of the oLbl1
  aPosSize = GetRect(0, 0, oLbl2.Size.Width, oLbl2.Size.Height)
  oViewFrame = CreateChildFrame(oLbl2.Peer, aPosSize)

  'create a control container service that will host the whole TranslateBox
  oCont2 = CreateUnoControl("Container")
  With oCont2.Model
    .Border = 1 ' 3D border
    '.BackgroundColor = //
  End With
oCont2.createPeer(oViewFrame.ContainerWindow.Toolkit, oViewFrame.ContainerWindow)
  oViewFrame.setComponent(oCont2, Null)

  oButton1 = InsertNewControl(oCont1, "Button", "Button1")
  oButton1.Label = "1"
  oButton2 = InsertNewControl(oCont2, "Button", "Button2")
  oButton2.Label = "2"

  oDlg.execute

End Sub


'______________________________________________________________________________
Function CreateChildFrame(oParentWin As Object, aPosSize As Object) As Object
Dim oChildWin As Object
Dim oToolkit As Object
Dim oChildFrame As Object

  oToolkit = oParentWin.getToolkit

  Dim aDescriptor as new com.sun.star.awt.WindowDescriptor
  With aDescriptor
    .Type = com.sun.star.awt.WindowClass.SIMPLE
    .WindowServiceName = ""
    '.ParentIndex = 0
    .Parent = oParentWin
    .Bounds = aPosSize
.WindowAttributes = com.sun.star.awt.WindowAttribute.SHOW '+ com.sun.star.awt.WindowAttribute.BORDER
  End With

  oChildWin = oToolkit.createWindow(aDescriptor)

  oChildFrame = createUnoService("com.sun.star.frame.Frame")
  oChildFrame.initialize(oChildWin)

  CreateChildFrame = oChildFrame

End Function


'______________________________________________________________________________
Function GetRect(nX, nY, nWidth, nHeight) As Object
Dim aRect as new com.sun.star.awt.Rectangle

  With aRect
    .X = nX
    .Y = nY
    .Width = nWidth
    .Height = nHeight
  End With

  GetRect = aRect
End Function

'______________________________________________________________________________
Function CreateUnoControl(sControlType As String) As Object
Dim oCtrl As Object
Dim oCModel As Object
  oCtrl = CreateUnoService("com.sun.star.awt.UnoControl" & sControlType)
oCModel = CreateUnoService("com.sun.star.awt.UnoControl" & sControlType & "Model")
  oCtrl.setModel(oCModel)
  CreateUnoControl = oCtrl

End Function


'______________________________________________________________________________
Function InsertNewControl(oContainer As Object, sControlType As String, sName As String) As Object
Dim oCtrl As Object

  oCtrl = CreateUnoControl(sControlType)
  oContainer.addControl(sName, oCtrl)

  InsertNewControl = oCtrl

End Function



'______________________________________________________________________________
Function CreateChildFrame(oParentWin As Object, aPosSize As Object) As Object
Dim oChildWin As Object
Dim oToolkit As Object
Dim oChildFrame As Object

        oToolkit = oParentWin.getToolkit
        
        Dim aDescriptor as new com.sun.star.awt.WindowDescriptor
        With aDescriptor
                .Type = com.sun.star.awt.WindowClass.SIMPLE
                .WindowServiceName = ""
                '.ParentIndex = 0
                .Parent = oParentWin
                .Bounds = aPosSize
.WindowAttributes = com.sun.star.awt.WindowAttribute.SHOW '+ com.sun.star.awt.WindowAttribute.BORDER
        End With
        
        oChildWin = oToolkit.createWindow(aDescriptor)
        
        oChildFrame = createUnoService("com.sun.star.frame.Frame")
        oChildFrame.initialize(oChildWin)
        
        CreateChildFrame = oChildFrame

End Function


'______________________________________________________________________________
Function GetRect(nX, nY, nWidth, nHeight) As Object
Dim aRect as new com.sun.star.awt.Rectangle
        
        With aRect
                .X = nX
                .Y = nY
                .Width = nWidth
                .Height = nHeight
        End With
        
        GetRect = aRect
End Function

'______________________________________________________________________________
Function CreateUnoControl(sControlType As String) As Object
Dim oCtrl As Object
Dim oCModel As Object
        oCtrl = CreateUnoService("com.sun.star.awt.UnoControl" & sControlType)
oCModel = CreateUnoService("com.sun.star.awt.UnoControl" & sControlType & "Model")
        oCtrl.setModel(oCModel)
        CreateUnoControl = oCtrl
        
End Function


'______________________________________________________________________________
Function InsertNewControl(oContainer As Object, sControlType As String, sName As String) As Object
Dim oCtrl As Object

        oCtrl = CreateUnoControl(sControlType)
        oContainer.addControl(sName, oCtrl)
        
        InsertNewControl = oCtrl
        
End Function

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org

Reply via email to