summaryrefslogtreecommitdiffstats
path: root/qtjava/designer/juic/java/put.xsl
blob: 7e2bd73a06cfd2eb7c46b730a9dd413a3a2dd0b2 (plain)
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<?xml version="1.0" encoding="iso-8859-1"?>
<!--
  ** Author: Marco Ladermann <marco.ladermann@gmx.de>
  ** Date:   Tue Jan 28 17:19:16 CET 2003 @721 /Internet Time/
  ** 
  ** This software is free software. It is released under the terms of the
  ** GNU Lesser General Public Licence (LGPL)
  ** see http://www.gnu.org/copyleft/lesser.html
  **
  ** These stylesheets are distributed in the hope that they will be useful,
  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  -->
<xsl:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:exsl="http://exslt.org/common"
    xmlns:date="http://exslt.org/dates-and-times"
    xmlns:redirect="http://xml.apache.org/xalan/redirect"
    xmlns:saxon="http://icl.com/saxon"
    xmlns:kde="http://kde.org/functions"
    xmlns:java="http://kde.org/java"
    extension-element-prefixes="exsl redirect saxon"
 >
    <!--
      ** This is the toplevel stylesheet of the language dependend parts
      -->

    <xsl:import href="definitions.xsl"/>
    <xsl:import href="properties.xsl"/>
    <xsl:import href="methods.xsl"/>
    <xsl:include href="../common/util.xsl"/>
    <xsl:include href="util.xsl"/>

    <xsl:variable name="mainClass" select="/UI/class"/>

    <!-- read XML file with Information about the Qt classes for Java -->
    <xsl:variable name="qtJavaClassesXml" select="'JavaClasses.xml'"/>
    <!--<xsl:variable name="qtJavaClasses" select="document($qtJavaClassesXml)"/> -->
    
    <xsl:variable name="nlIndent8" select="concat($newline, '        ')"/>

    <!-- 
      ** This template starts the whole process.
      ** 
      -->
    <xsl:template match="/">
        <xsl:variable name="file">
            <xsl:choose>
                <xsl:when test="$package = ''">
                    <xsl:value-of select="concat($outdir, '/', $mainClass, '.java')"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="concat($outdir, '/', translate($package, '.', '/'), '/', $mainClass, '.java')"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:choose>
            <xsl:when test="element-available('exsl:document')">
                <xsl:message>Using output file <xsl:value-of select="$file"/> with Exslt extension</xsl:message>
                <exsl:document href="{$file}" method="text">
                    <xsl:apply-templates mode="main" select="/"/>
                </exsl:document>
            </xsl:when>
            <xsl:when test="element-available('saxon:output')">
                <xsl:message>Using output file <xsl:value-of select="$file"/> with Saxon extension</xsl:message>
                <saxon:output href="{$file}" method="text">
                    <xsl:apply-templates mode="main" select="/"/>
                </saxon:output>
            </xsl:when>
            <xsl:when test="element-available('redirect:write')">
                <xsl:message>Using output file <xsl:value-of select="$file"/> with Xalan extension</xsl:message>
                <redirect:write file="$file" method="text">
                    <xsl:apply-templates mode="main" select="/"/>
                </redirect:write>
            </xsl:when>
            <xsl:otherwise>
                <xsl:message>Using stdout</xsl:message>
                <xsl:apply-templates mode="main" select="/"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
    <!-- 
      ** Put the file header
      ** @param comment from ui file
      ** @param author name of author from ui file
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putFileHeader">
        <xsl:param name="comment"/>
        <xsl:param name="author"/>
        <xsl:param name="data"/>
        <xsl:text>/*
 * </xsl:text><xsl:value-of select="$mainClass"/><xsl:text>.java
 *
 * This class is generated from a UI description generated by
 * the QtDesigner with XSLT.
 *
 * DO NOT EDIT! File will be overidden
 *
 * Author: </xsl:text>
        <xsl:value-of select="$author"/>
        <xsl:text>
 * Date:   </xsl:text><xsl:value-of select="date:date()"/>
        <xsl:text>
 * Comment: </xsl:text>
<xsl:value-of select="$comment"/>
        <xsl:text>
 */
</xsl:text>
    </xsl:template>

    <!--
      ** Put the class preamble. Use this to generate package information, imports etc.
      ** @param classes node-set with sorted list of all classes needed
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putClassPreamble">
        <xsl:param name="classes"/>
        <xsl:param name="data"/>
        <xsl:if test="not($package = '')">
            <xsl:value-of select="$newline"/>
            <xsl:text>package </xsl:text>
            <xsl:value-of select="$package"/>
            <xsl:text>;</xsl:text>
        </xsl:if>
        
        <!-- import Qt specific classes -->
        <xsl:value-of select="$newline"/>
        <xsl:for-each select="$classes/class">
            <xsl:variable name="name" select="."/>
            <xsl:variable name="classInfo" select="document($qtJavaClassesXml)/Qt/class[name = $name]"/>
            <xsl:if test="$classInfo">
                <xsl:value-of select="$newline"/>
                <xsl:value-of select="concat('import ', $classInfo/package, '.', $classInfo/name, ';')"/>
            </xsl:if>
        </xsl:for-each>
        
        <xsl:value-of select="$newline"/>
        
        <!-- import of java specific classes -->
        <xsl:if test="/UI/images">
            <xsl:message>Create imports to handle Images</xsl:message>
            <xsl:value-of select="'import java.util.zip.Inflater;'"/>
            <xsl:value-of select="$newline"/>
        </xsl:if>
    </xsl:template>
    
    <!--
      ** Put the class header.
      ** @param extends the class that is extended by this
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putClassHeader">
        <xsl:param name="extends"/>
        <xsl:param name="data"/>

        <xsl:text>
/**
 * </xsl:text><xsl:value-of select="$mainClass"/> a user interface class using Qt<xsl:text>
 */
        </xsl:text>
        <xsl:value-of select="$newline"/>
        <xsl:text>public </xsl:text>
        <xsl:if test="$abstract">
            <xsl:text>abstract </xsl:text>
        </xsl:if>
        <xsl:text>class </xsl:text>
        <xsl:value-of select="$mainClass"/>
        <xsl:if test="$extends"> 
            <xsl:text> extends </xsl:text>
            <xsl:value-of select="$extends"/>
        </xsl:if>
        <xsl:text> {</xsl:text>
        <xsl:value-of select="$newline"/>

    static {
        // initialize the toolkit
        org.kde.qt.qtjava.initialize();
        <xsl:if test="$kde">
        org.kde.koala.kdejava.initialize();
        </xsl:if>
    }
    </xsl:template>
    
    <!--
      ** Put the definition of user defined variables.
      ** Here we define some TQPixmap instances for embedded images
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putVariables">
        <xsl:param name="data"/>
        <xsl:for-each select="/UI/images/image">
            <xsl:message>Creating code for image <xsl:value-of select="@name"/></xsl:message>
            <!--
            <xsl:variable name="img" select="concat('_img', position())"/>
            <xsl:value-of select="$newline"/>
            <xsl:text>    protected static String </xsl:text>
            <xsl:value-of select="$img"/>
            <xsl:text> = "</xsl:text>
            <xsl:value-of select="data"/>            
            <xsl:text>";</xsl:text>
            -->
            <!--
            <xsl:call-template name="toBytes">
                <xsl:with-param name="hexstring" select="data"/>
            </xsl:call-template>
            <xsl:text> }; </xsl:text>
            -->
            <xsl:value-of select="$newline"/>
            <xsl:text>    protected TQPixmap </xsl:text>
            <xsl:value-of select="@name"/>
            <xsl:text> = decodePixmap( </xsl:text>
            <xsl:value-of select="data/@length"/>
            <xsl:text>, &quot;</xsl:text>
            <xsl:value-of select="data"/>
            <xsl:text>&quot;, </xsl:text>
            <xsl:choose>
                <xsl:when test="data/@format = 'XPM.GZ'">
                    <xsl:text> true</xsl:text>
                </xsl:when>
                <xsl:when test="data/@format = 'PNG'">
                    <xsl:text> false</xsl:text>
                </xsl:when>
            </xsl:choose>
            <xsl:text>);</xsl:text>
        </xsl:for-each>
    </xsl:template>

    <!-- helper template
    <xsl:template name="toBytes">
        <xsl:param name="hexstring" select="''"/>
        <xsl:param name="count" select="0"/>
        <xsl:variable name="len" select="string-length($hexstring)"/>
        <xsl:if test="$count = 0">
            <xsl:value-of select="$nlIndent8"/>
        </xsl:if>
        <xsl:variable name="cnt">
            <xsl:choose>
                <xsl:when test="$count = 6">0</xsl:when>
                <xsl:otherwise><xsl:value-of select="$count + 1"/></xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:choose>
            <xsl:when test="$len &gt; 2">
                <xsl:value-of select="concat('(byte)0x', substring($hexstring, 1, 2), ', ')"/>
                <xsl:call-template name="toBytes">
                    <xsl:with-param name="hexstring" select="substring($hexstring, 3)"/>
                    <xsl:with-param name="count" select="$cnt"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$len = 2">
                <xsl:value-of select="concat('(byte)0x', $hexstring)"/>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    -->
    
    <!--
      ** Put the definition of instance variables
      ** @context property
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putInstanceVariable">
        <xsl:param name="class"/>
        <xsl:param name="name"/>
        <xsl:param name="data"/>
        <xsl:variable name="varname">
            <xsl:choose>
                <xsl:when test="$name">
                    <xsl:value-of select="$name"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="java:getNodeName(..)"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:value-of select="$newline"/>
        <xsl:value-of select="concat('    protected ', $class, ' ', $varname, ' = null;')"/>
    </xsl:template>
    
    <!--
      ** Put the declaration of the constructors
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putConstructors">
        <xsl:param name="data"/>
        <xsl:variable name="kind" select="substring(/UI/widget/@class, 2)"/>
        <xsl:variable name="isModal" select="$kind = 'Wizard' or $kind = 'Dialog'"/>
        <xsl:variable name="modalParam" select="kde:if($isModal, ', false', '')"/>
        <xsl:variable name="modalArg" select="kde:if($isModal, ', boolean modal', '')"/>

    /**
     * Constructor for class <xsl:value-of select="$mainClass"/>
     */
    public <xsl:value-of select="$mainClass"/>() {
        this(null, "<xsl:value-of select="$mainClass"/>"<xsl:value-of select="$modalParam"/>, WType_TopLevel);
    }

    /**
     * Constructor for class <xsl:value-of select="$mainClass"/>
     * @param parent the parent widget of this class
     */
    public <xsl:value-of select="$mainClass"/>(TQWidget parent) {
        this(parent, "<xsl:value-of select="$mainClass"/>"<xsl:value-of select="$modalParam"/>, WType_TopLevel);
    }

    /**
     * Constructor for class <xsl:value-of select="$mainClass"/>
     * @param parent the patent widget of this class
     * @param name the name of the widget
     */
    public <xsl:value-of select="$mainClass"/>(TQWidget parent, String name) {
        this(parent, name<xsl:value-of select="$modalParam"/>, WType_TopLevel);
    }
<xsl:if test="$modalArg != ''">
    /**
     * Constructor for class <xsl:value-of select="$mainClass"/>
     * @param parent the patent widget of this class
     * @param name the name of the widget
     * @param modal modality of the widget
     */
    public <xsl:value-of select="$mainClass"/>(TQWidget parent, String name, boolean modal) {
        this(parent, name, modal, WType_TopLevel);
    }
</xsl:if>
    /**
     * Constructor for class <xsl:value-of select="$mainClass"/>
     * @param parent the patent widget of this class
     * @param name the name of the widget
     * @param flags some "or"ed properties
     */
    public <xsl:value-of select="$mainClass"/>(TQWidget parent, String name<xsl:value-of select="$modalArg"/>, int flags) {
        super(parent, name<xsl:value-of select="$modalParam"/>, flags);
<xsl:if test="/UI/widget/@class = 'TQMainWindow'"> 
        statusBar();
</xsl:if>
        if (name == null) setName("<xsl:value-of select="$mainClass"/>");

        // setup widgets 
        <xsl:call-template name="createInstanceDefinitions"/>

        // setup databases 
        <xsl:call-template name="createDatabaseDefinitions"/>

        // setup actions
        <xsl:call-template name="createActionDefinitions"/>

        // setup toolbar
        <xsl:call-template name="createToolbarDefinitions"/>

        // setup menubar
        <xsl:call-template name="createMenubarDefinitions"/>

        resize(size().expandedTo(minimumSizeHint()));

        // signals and slots connections
        <xsl:call-template name="createConnectionDefinitions"/>

        // tabstops 
        <xsl:call-template name="createTabstopsDefinitions"/>
    }
    </xsl:template>

    <!--
      ** Put the definition of a database
      ** @context widget[@class='TQDataTable' or @class='TQDataBrowser"]
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putDatabaseDefinition">
        <xsl:param name="data"/>
        <xsl:variable name="formName" select="concat(java:getNodeName(.), 'Form')"/>
        <xsl:variable name="conn" select="property[@name='database']/stringlist/string[1]"/>
        <xsl:variable name="table" select="property[@name='database']/stringlist/string[2]"/>
        <xsl:value-of select="$nlIndent8"/>
        <xsl:value-of select="concat('TQSqlForm ', $formName, ' = new TQSqlForm(this, &quot;', $formName, '&quot;);')"/>
        <xsl:for-each select=".//widget[@class != 'TQDataTable' and property[@name='database']]">
            <xsl:if test="property[@name='database']/stringlist/string[1]=$conn 
                      and property[@name='database']/stringlist/string[2]=$table">
                <xsl:value-of select="$nlIndent8"/>
                <xsl:value-of select="$formName"/>
                <xsl:text>.insert( </xsl:text>
                <xsl:value-of select="java:getNodeName()"/>
                <xsl:text>, "</xsl:text>
                <xsl:value-of select="property[@name='database']/stringlist/string[3]"/>
                <xsl:text>" );</xsl:text>
            </xsl:if>
        </xsl:for-each>
        <xsl:value-of select="$nlIndent8"/>
        <xsl:value-of select="concat(java:getNodeName(), '.setForm( ', $formName, ');')"/>
    </xsl:template>
        
        <!--
      ** Put the definition of a slot
      ** @context slot
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putSlot">
        <xsl:param name="data"/>
        <xsl:variable name="access" select="kde:if(@access, @access, 'public')"/>
        <xsl:variable name="return" select="kde:if(@returnType, @returnType, 'void')"/>
        <xsl:variable name="sig" select="java:cpp-to-java-signature(.)"/>
        <xsl:variable name="method" select="concat($access, ' ',
                                                   kde:if($abstract, 'abstract ', ''),
                                                   $return , ' ',
                                                   $sig)"/>
        <xsl:if test="$access = 'private'">
            <xsl:message>Error in slot: <xsl:value-of select="$method"/></xsl:message>
            <xsl:message>A private method can't be overriden.</xsl:message>
        </xsl:if>
        <xsl:message>Generating slot "<xsl:value-of select="$method"/></xsl:message>
    /**
     * SLOT <xsl:value-of select="$method"/>
     */
    <xsl:choose>
        <xsl:when test="$abstract">
    <xsl:value-of select="$method"/>;
        </xsl:when>
        <xsl:otherwise>
    <xsl:value-of select="$method"/> {
        tqWarning("Warning: SLOT \"<xsl:value-of select="$method"/>\" must be overridden");
        <xsl:if test="not($return = 'void')">
        <xsl:choose>
            <xsl:when test="$return = 'byte' or $return = 'short' or $return = 'int' or $return = 'long'">
                <xsl:text>return </xsl:text><xsl:value-of select="concat('(',$return,')')"/><xsl:text>0;</xsl:text>
            </xsl:when>
            <xsl:when test="$return = 'char'">
                <xsl:text>return '\0'</xsl:text>
            </xsl:when>
            <xsl:when test="$return = 'float' or $return = 'double'">
                <xsl:text>return 0.0;</xsl:text>
            </xsl:when>
            <xsl:otherwise>return null;</xsl:otherwise>
        </xsl:choose>
        </xsl:if>
    }
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <!--
      ** Put the definition of a signal
      ** @context slot
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putSignal">
        <xsl:param name="data"/>
        <xsl:variable name="sig" select="java:cpp-to-java-signature(.)"/>
    /** SIGNAL <xsl:value-of select="."/> */
    </xsl:template>
    
    <!--
      ** Put the definition of tabstops
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putTabstops">
        <xsl:param name="data"/>
        <xsl:variable name="widgets" select="count(/UI/tabstops/tabstop)"/>
        <xsl:for-each select="/UI/tabstops/tabstop">
            <xsl:variable name="pos" select="position()"/>
            <xsl:if test="$pos &lt; $widgets">
                <xsl:value-of select="$nlIndent8"/>
                <xsl:text>setTabOrder(</xsl:text>
                <xsl:value-of select="."/>
                <xsl:text>, </xsl:text>
                <xsl:value-of select="/UI/tabstops/tabstop[$pos + 1]"/>
                <xsl:text>);</xsl:text>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    
    <!--
      ** Put the class footer.
      ** Here it is nothing more, but a closing brace
      ** @param data opaque data for user purpose
      -->
    <xsl:template name="putClassFooter">
        <xsl:param name="data"/>
        <xsl:value-of select="$newline"/>
        <xsl:text>}</xsl:text>
        <xsl:value-of select="$newline"/>
    </xsl:template>

</xsl:stylesheet>