TS 68 JavaFX CodeFormating

(Difference between revisions)
({{testcase|Variable}})
 
(14 intermediate revisions not shown)
Line 1: Line 1:
-
=Code Formating=
 
'''Author:''' [mailto:sunflower@netbeans.org Alexandr Scherbatiy] <br>
'''Author:''' [mailto:sunflower@netbeans.org Alexandr Scherbatiy] <br>
'''Version:''' 1.1 <br>
'''Version:''' 1.1 <br>
Line 88: Line 87:
      
      
=== {{testcase|Variable}} ===
=== {{testcase|Variable}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
-
var a = 10;
+
var a =     10         ;
-
var b = 20.5;
+
    var         b = 20.5;
-
var c = a + b;
+
  var c = a +             b;
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
var a = 10;
var a = 10;
Line 101: Line 100:
var c = a + b;
var c = a + b;
</pre> </code>
</pre> </code>
 +
=== {{testcase|Data Types}} ===
=== {{testcase|Data Types}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
var i = 3;
var i = 3;
Line 130: Line 130:
var f = function(a:Number, b:String):Boolean { true };
var f = function(a:Number, b:String):Boolean { true };
-
var seqf = function(a:A[[ | ]], b:String[[ | ]]):Boolean[[ | ]] { [] };
+
var seqf = function(a:A[], b:String[]):Boolean[] { [] };
var seq = ["1","2","3" ];
var seq = ["1","2","3" ];
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
var i = 3;
var i = 3;
Line 164: Line 164:
var f = function(a:Number, b:String):Boolean { true };
var f = function(a:Number, b:String):Boolean { true };
-
var seqf = function(a:A[[ | ]], b:String[[ | ]]):Boolean[[ | ]] { [] };
+
var seqf = function(a:A[], b:String[]):Boolean[] { [] };
Line 170: Line 170:
</pre> </code>
</pre> </code>
=== {{testcase|Trigger}} ===
=== {{testcase|Trigger}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
var a = 3 on replace{
var a = 3 on replace{
Line 176: Line 176:
}
}
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
var a = 3 on replace{
var a = 3 on replace{
Line 184: Line 184:
</pre> </code>
</pre> </code>
=== {{testcase|Binding}} ===
=== {{testcase|Binding}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
var a  =  4;
var a  =  4;
var b  =  bind a with inverse;
var b  =  bind a with inverse;
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
var a  =  4;
var a  =  4;
Line 206: Line 206:
=== {{testcase|Simple Function Body}} ===
=== {{testcase|Simple Function Body}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
function    sqr(  x : Number) { x*  x }
function    sqr(  x : Number) { x*  x }
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code is formatted  }}  
+
** {{result|EXPECTED RESULT:  The code is formatted  }}  
<code> <pre>
<code> <pre>
function sqr(x:Number) { x * x }
function sqr(x:Number) { x * x }
Line 218: Line 218:
      
      
=== {{testcase|Function Body}} ===
=== {{testcase|Function Body}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
function sqr(x:Number) {    x  * x }
function sqr(x:Number) {    x  * x }
-
function f(name:String, seq:String[[ | ]]):String[]{
+
function f(name:String, seq:String[]):String[]{
-
                 return [Name,Seq ];
+
                 return [name,seq ];
}
}
Line 236: Line 236:
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code is formatted  }}  
+
** {{result|EXPECTED RESULT:  The code is formatted  }}  
<code> <pre>
<code> <pre>
function sqr(x:Number) { x * x }
function sqr(x:Number) { x * x }
-
function f(name:String, seq:String[[ | ]]):String[]{
+
function f(name:String, seq:String[]):String[]{
-
     return [Name,Seq ];
+
     return [name,seq ];
}
}
Line 267: Line 267:
      
      
=== {{testcase|Sequence}} ===
=== {{testcase|Sequence}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
-
var seq = [[1,2,3,[4,5,6 |  1, 2, 3, [ 4, 5, 6]], [7,8,9] ];
+
var seq = [[1,2,3], [4,5,6], [7,8,9] ];
var names = [ "Petr",
var names = [ "Petr",
Line 277: Line 277:
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
-
var seq = [[1,2,3,[4,5,6 |  1, 2, 3, [ 4, 5, 6]], [7,8,9] ];
+
var seq = [[1,2,3], [4,5,6], [7,8,9]];
var names = [
var names = [
Line 289: Line 289:
</pre> </code>
</pre> </code>
=== {{testcase|Sequence}} ===
=== {{testcase|Sequence}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
var seq = for(i in [1..3]){ i * i }
var seq = for(i in [1..3]){ i * i }
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
var seq = for(i in [1..3]){ i * i }
var seq = for(i in [1..3]){ i * i }
</pre> </code>
</pre> </code>
=== {{testcase|Slice}}  ===
=== {{testcase|Slice}}  ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
var seq = [1,3,6,8];
var seq = [1,3,6,8];
-
var slice = seq[N*N <10];
+
var slice = seq[n | n * n <10];
def selected = for (x in seq where (x*x) < 20) x;
def selected = for (x in seq where (x*x) < 20) x;
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
var seq = [1,3,6,8];
var seq = [1,3,6,8];
-
var slice = seq[N*N <10];
+
var slice = seq[n | n * n <10];
def selected = for (x in seq where (x*x) < 20) x;
def selected = for (x in seq where (x*x) < 20) x;
</pre> </code>
</pre> </code>
 +
 +
=== {{testcase|Native Array}}  ===
 +
*  Copy the code to the editor:
 +
<code> <pre>       
 +
var arr = ["1", "2"] as nativearray of String;
 +
var b = 3;
 +
 +
var str = "Simple string";
 +
var raw: nativearray of Byte = str.getBytes();
 +
 +
java.util.Arrays.sort(raw);
 +
var strRes: String = java.util.Arrays.toString(raw);
 +
println(strRes);
 +
</pre> </code> 
 +
*  Format the code (press &lt;Ctrl+F5&gt;).
 +
** {{result|EXPECTED RESULT:  The code should be formatted  }}
 +
<code> <pre>
 +
var arr = ["1", "2"] as nativearray of String;
 +
var b = 3;
 +
 +
var str = "Simple string";
 +
var raw: nativearray of Byte = str.getBytes();
 +
 +
java.util.Arrays.sort(raw);
 +
var strRes: String = java.util.Arrays.toString(raw);
 +
println(strRes);
 +
</pre> </code>
 +
=== {{testcase|Expressoins}}===
=== {{testcase|Expressoins}}===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
-
var names  =  [Evelyn,Will];
+
var names  =  ["Evelyn","Will"];
insert 'Marsha' into names;
insert 'Marsha' into names;
-
insert [[Ron,Melissa | 'Ron', 'Melissa']] before names[1];
+
insert ['Ron', 'Melissa' ] before names[1];
insert 'Daz' after names[3];
insert 'Daz' after names[3];
delete 'Ron' from names;
delete 'Ron' from names;
-
delete names[SizeofNames1];
+
delete names[sizeof names-1];
delete names[2..4];
delete names[2..4];
delete names;
delete names;
 +
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
-
var names  =  [Evelyn,Will];
+
var names  =  ["Evelyn","Will"];
insert 'Marsha' into names;
insert 'Marsha' into names;
-
insert [[Ron,Melissa | 'Ron', 'Melissa']] before names[1];
+
insert ['Ron', 'Melissa' ] before names[1];
insert 'Daz' after names[3];
insert 'Daz' after names[3];
delete 'Ron' from names;
delete 'Ron' from names;
-
delete names[SizeofNames1];
+
delete names[sizeof names-1];
delete names[2..4];
delete names[2..4];
delete names;
delete names;
 +
</pre> </code>
</pre> </code>
<br>
<br>
-
 
-
 
-
 
-
 
-
 
-
 
-
 
-
 
-
 
-
 
==Class==
==Class==
      
      
=== {{testcase|Attribute}} ===
=== {{testcase|Attribute}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
class A {
class A {
Line 366: Line 386:
}
}
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code is formatted  }}  
+
** {{result|EXPECTED RESULT:  The code is formatted  }}  
<code> <pre>
<code> <pre>
class A {
class A {
Line 374: Line 394:
</pre> </code>
</pre> </code>
=== {{testcase|Overridden Attribute}}  ===
=== {{testcase|Overridden Attribute}}  ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
class A{
class A{
Line 384: Line 404:
}
}
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code is formatted  }}  
+
** {{result|EXPECTED RESULT:  The code is formatted  }}  
<code> <pre>
<code> <pre>
class A{
class A{
Line 396: Line 416:
</pre> </code>
</pre> </code>
=== {{testcase|Trigger}} ===
=== {{testcase|Trigger}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
class Foo {
class Foo {
Line 402: Line 422:
     var y : Integer on replace { println("y: {y}"); };
     var y : Integer on replace { println("y: {y}"); };
     var z : String = "Ralph" on replace { println("z: {z}"); };
     var z : String = "Ralph" on replace { println("z: {z}"); };
-
     var seq: String[[ | ]] on replace oldSlice[A..b] = newSlice{ for(s in seq){ println(s)</tt>;
+
     var seq: String[] on replace oldSlice[a..b] = newSlice{ for(s in seq[a..b]){ println(s) } };
}
}
 +
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code is formatted  }}  
+
** {{result|EXPECTED RESULT:  The code is formatted  }}  
<code> <pre>
<code> <pre>
class Foo {
class Foo {
Line 412: Line 433:
     var y : Integer on replace { println("y: {y}"); };
     var y : Integer on replace { println("y: {y}"); };
     var z : String = "Ralph" on replace { println("z: {z}"); };
     var z : String = "Ralph" on replace { println("z: {z}"); };
-
     var seq: String[[ | ]] on replace oldSlice[A..b] = newSlice{ for(s in seq){ println(s)</tt>;
+
     var seq: String[] on replace oldSlice[a..b] = newSlice{ for(s in seq[a..b]){ println(s) } };
}
}
 +
</pre> </code>
</pre> </code>
 +
=== {{testcase|Function}} ===
=== {{testcase|Function}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
class A {
class A {
Line 429: Line 452:
}
}
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted }}  
<code> <pre>
<code> <pre>
class A {
class A {
Line 444: Line 467:
</pre> </code> ===
</pre> </code> ===
=== {{testcase|Function Return}}
=== {{testcase|Function Return}}
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
class B{
class B{
Line 452: Line 475:
}
}
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted }}  
<code> <pre>
<code> <pre>
class B{
class B{
Line 462: Line 485:
</pre> </code>
</pre> </code>
=== {{testcase|Init}} ===
=== {{testcase|Init}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
class A{
class A{
Line 476: Line 499:
}
}
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted }}  
<code> <pre>
<code> <pre>
class A{
class A{
Line 492: Line 515:
</pre> </code>
</pre> </code>
=== {{testcase|Inheritance}}  ===
=== {{testcase|Inheritance}}  ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
import javafx.scene.*;
import javafx.scene.*;
Line 500: Line 523:
}
}
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted }}  
<code> <pre>
<code> <pre>
import javafx.scene.*;
import javafx.scene.*;
Line 522: Line 545:
      
      
=== {{testcase|Stage}} ===
=== {{testcase|Stage}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
import javafx.stage.*;
import javafx.stage.*;
Line 565: Line 588:
}
}
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
=== {{testcase|Sequence}} ===
=== {{testcase|Sequence}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
import javafx.scene.shape.*;
import javafx.scene.shape.*;
Line 574: Line 597:
Circle {
Circle {
-
     transforms: [Rotate{Angle:90.0},Scale{X:0.3,Y:0.3} ]
+
     transforms: [ Rotate{ angle:90.0 }, Scale{ x:0.3, y:0.3 } ]
}
}
 +
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
import javafx.scene.shape.*;
import javafx.scene.shape.*;
Line 584: Line 608:
Circle {
Circle {
-
     transforms: [Rotate{Angle:90.0},Scale{X:0.3,Y:0.3} ]
+
     transforms: [ Rotate{ angle:90.0 }, Scale{ x:0.3, y:0.3 } ]
}
}
 +
</pre> </code>
</pre> </code>
 +
=== {{testcase|For Loop}} ===
=== {{testcase|For Loop}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
import javafx.scene.Group;
import javafx.scene.Group;
Line 596: Line 622:
Group {
Group {
-
     content: for( r in [1..10Step2]) Circle{ radius: r fill: Color.GREEN }
+
     content: for( r in [1..10 step 2]) Circle{ radius: r fill: Color.GREEN }
}
}
 +
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted }}  
<code> <pre>
<code> <pre>
import javafx.scene.Group;
import javafx.scene.Group;
Line 608: Line 635:
Group {
Group {
-
     content: for( r in [1..10Step2]) Circle{ radius: r fill: Color.GREEN }
+
     content: for( r in [1..10 step 2]) Circle{ radius: r fill: Color.GREEN }
}
}
 +
</pre> </code>
</pre> </code>
Line 616: Line 644:
 +
==Animation==
 +
   
 +
=== {{testcase|'at'}} ===
 +
*  Copy the code to the editor:
 +
<code> <pre>       
 +
import javafx.animation.*;
 +
var blur: Double = 80.0;
 +
Timeline {
 +
    repeatCount: Timeline.INDEFINITE
 +
    keyFrames: [
 +
        at (0s) {  blur        =>  80.0        }
 +
        at (3s) { blur =>          0.0 tween Interpolator.EASEBOTH}
 +
        at (5s) {    blur => 0.0 }
 +
    ]
 +
}
 +
</pre> </code> 
 +
*  Format the code (press &lt;Ctrl+F5&gt;).
 +
** {{result|EXPECTED RESULT:  The code should be formatted  }}
 +
==Text==
 +
   
 +
=== {{testcase|'Some lines'}} ===
 +
*  Copy the code to the editor:
 +
<code> <pre>       
 +
import javafx.scene.text.Text;
 +
 +
Text {
 +
    content: 'Sequence level1 = new Sequence();\n'
 +
'Text text0 = new Text();\n'
 +
              'text0.text = "Wird erreicht durch "\n'
 +
              'Sequence level2 = new Sequence();\n'
 +
                                'Text text1 = new Text();\n'
 +
              'text1.text="neue Constructor-Syntax \n'
 +
              'level2.add (text1);\n'
 +
              'Text text2 = new Text();\n'
 +
                    'text2.text="Sequenzen,";\n'
 +
              'level2.add (text2);\n'
 +
                          'Text text3 = new Text();\n'
 +
              'text3.text="und funktionale Sprachelemente.";\n'
 +
              'level2.add (text3);\n'
 +
              'text0.items = level1;\n'
 +
                        'Outline outline = new Outline();\n'
 +
              'outline.items = level1;\n'
 +
              'Html html = new Html();\n'
 +
              'Sequence childs = new Sequence();\n'
 +
                            'childs.add (html);\n'
 +
              'html.childs = childs\n';
 +
}
 +
 +
</pre> </code> 
 +
*  Format the code (press &lt;Ctrl+F5&gt;).
 +
** {{result|EXPECTED RESULT:  The code should be formatted  }}
==Operators==
==Operators==
      
      
=== {{testcase|Operator If}} ===
=== {{testcase|Operator If}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
-
ar a  =  10;
+
var a  =  10;
var f  =  false;
var f  =  false;
Line 641: Line 720:
var b = if( a +3 < 100  ) 10 else if( -100 < a - 3 ) -10 else 0;
var b = if( a +3 < 100  ) 10 else if( -100 < a - 3 ) -10 else 0;
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
-
ar a  =  10;
+
var a  =  10;
var f  =  false;
var f  =  false;
Line 660: Line 739:
var b = if( a +3 < 100  ) 10 else if( -100 < a - 3 ) -10 else 0;
var b = if( a +3 < 100  ) 10 else if( -100 < a - 3 ) -10 else 0;
</pre> </code>
</pre> </code>
 +
=== {{testcase|Operator For}} ===
=== {{testcase|Operator For}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
for(a in [1..100]){
for(a in [1..100]){
Line 669: Line 749:
var seq = for(b in [1,5,9]) b + b / 2;
var seq = for(b in [1,5,9]) b + b / 2;
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
for(a in [1..100]){
for(a in [1..100]){
Line 679: Line 759:
</pre> </code>
</pre> </code>
=== {{testcase|Operator While}} ===
=== {{testcase|Operator While}} ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
var a = 10;
var a = 10;
Line 689: Line 769:
}
}
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
var a = 10;
var a = 10;
Line 701: Line 781:
</pre> </code>
</pre> </code>
=== {{testcase|Operator Try-Ctach}}  ===
=== {{testcase|Operator Try-Ctach}}  ===
-
## Copy the code to the editor:
+
* Copy the code to the editor:
<code> <pre>         
<code> <pre>         
import java.io.FileReader;
import java.io.FileReader;
Line 726: Line 806:
}
}
</pre> </code>   
</pre> </code>   
-
## Format the code (press &lt;Ctrl+F5&gt;).  
+
* Format the code (press &lt;Ctrl+F5&gt;).  
-
#* {{result|EXPECTED RESULT:  The code should be formatted  }}  
+
** {{result|EXPECTED RESULT:  The code should be formatted  }}  
<code> <pre>
<code> <pre>
import java.io.FileReader;
import java.io.FileReader;

Current revision as of 10:35, 18 January 2010

Author: Alexandr Scherbatiy
Version: 1.1
Last update: 29 September 2009
Introduction:
Comments:


Contents



Code Formatting Umbrella issue: 173487

What Issues
Variable
declaration 173240
data types
trigger 173368
binding 173370
Function
body 173365, 173468
Sequence
declaration 173367,172466
select 173400
Class
attribute 172644
trigger
function
init
inheritance 173464
instantiation 173462
Scene Graph
Stage
sequence
Operators
if 173467
for
while
try-catch




Variable

Variable

  • Copy the code to the editor:
         
var a =     10          ;
    var         b = 20.5;
  var c = a +             b;
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
var a = 10;
var b = 20.5;
var c = a + b;

Data Types

  • Copy the code to the editor:
         
var i = 3;
var num = 3.0;

var b = true;

var c = "2".charAt(0);


var byte:Byte = 1;
var short:Short = 2;
var long:Long = 3;
var float:Float = 5.0;
var double:Double = 10.0;


var date = 3h;

var str = "Hello!";

class A{}

var a = A{};

var void = function():Void{};

var f = function(a:Number, b:String):Boolean { true };
var seqf = function(a:A[], b:String[]):Boolean[] { [] };


var seq = ["1","2","3" ];
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
var i = 3;
var num = 3.0;

var b = true;

var c = "2".charAt(0);


var byte:Byte = 1;
var short:Short = 2;
var long:Long = 3;
var float:Float = 5.0;
var double:Double = 10.0;


var date = 3h;

var str = "Hello!";

class A{}

var a = A{};

var void = function():Void{};

var f = function(a:Number, b:String):Boolean { true };
var seqf = function(a:A[], b:String[]):Boolean[] { [] };


var seq = ["1","2","3" ];

Trigger

  • Copy the code to the editor:
         
var a = 3 on replace{
    println(a);
}
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
var a = 3 on replace{
    println(a);
}

Binding

  • Copy the code to the editor:
         
var a  =  4;
var b  =  bind a with inverse;
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
var a  =  4;
var b  =  bind a with inverse;





Function

Simple Function Body

  • Copy the code to the editor:
         
function     sqr(  x : Number) { x*   x }
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code is formatted
function sqr(x:Number) { x * x }

Function Body

  • Copy the code to the editor:
         
function sqr(x:Number) {    x   * x }

function f(name:String, seq:String[]):String[]{
                return [name,seq ];
}

function show(a:Number, b:Number){
        var c = a + b;
    var d = a - b;

        println(c);
    println(d);

}

  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code is formatted
function sqr(x:Number) { x * x }

function f(name:String, seq:String[]):String[]{
    return [name,seq ];
}

function show(a:Number, b:Number){
    var c = a + b;
    var d = a - b;

    println(c);
    println(d);

}






Sequence

Sequence

  • Copy the code to the editor:
         
var seq = [[1,2,3], [4,5,6], [7,8,9] ];

var names = [ "Petr",
    "John",
    "Mary"
        ];

  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
var seq = [[1,2,3], [4,5,6], [7,8,9]];

var names = [
    "Petr",
    "John",
    "Mary"
];

Sequence

  • Copy the code to the editor:
         
var seq = for(i in [1..3]){ i * i }
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
var seq = for(i in [1..3]){ i * i }

Slice

  • Copy the code to the editor:
         
var seq = [1,3,6,8];
var slice = seq[n | n * n <10];
def selected = for (x in seq where (x*x) < 20) x;
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
var seq = [1,3,6,8];
var slice = seq[n | n * n <10];
def selected = for (x in seq where (x*x) < 20) x;

Native Array

  • Copy the code to the editor:
         
var arr = ["1", "2"] as nativearray of String;
var b = 3;

var str = "Simple string";
var raw: nativearray of Byte = str.getBytes();

java.util.Arrays.sort(raw);
var strRes: String = java.util.Arrays.toString(raw);
println(strRes);
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
var arr = ["1", "2"] as nativearray of String;
var b = 3;

var str = "Simple string";
var raw: nativearray of Byte = str.getBytes();

java.util.Arrays.sort(raw);
var strRes: String = java.util.Arrays.toString(raw);
println(strRes);

Expressoins

  • Copy the code to the editor:
         
var names  =  ["Evelyn","Will"];

insert 'Marsha' into names;
insert ['Ron', 'Melissa' ] before names[1];
insert 'Daz' after names[3];

delete 'Ron' from names;
delete names[sizeof names-1];
delete names[2..4];


delete names;

  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
var names  =  ["Evelyn","Will"];

insert 'Marsha' into names;
insert ['Ron', 'Melissa' ] before names[1];
insert 'Daz' after names[3];

delete 'Ron' from names;
delete names[sizeof names-1];
delete names[2..4];


delete names;


Class

Attribute

  • Copy the code to the editor:
         
class A {
    public var a : String;
}
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code is formatted
class A {
    public var a : String;
}

Overridden Attribute

  • Copy the code to the editor:
         
class A{
    public var a:Number;
}

class B extends A{
    override var a = 10;
}
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code is formatted
class A{
    public var a:Number;
}

class B extends A{
    override var a = 10;
}

Trigger

  • Copy the code to the editor:
         
class Foo {
    var x : Integer on replace = newV { println("x: =>{newV}={x}"); };
    var y : Integer on replace { println("y: {y}"); };
    var z : String = "Ralph" on replace { println("z: {z}"); };
    var seq: String[] on replace oldSlice[a..b] = newSlice{ for(s in seq[a..b]){ println(s) } };
}

  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code is formatted
class Foo {
    var x : Integer on replace = newV { println("x: =>{newV}={x}"); };
    var y : Integer on replace { println("y: {y}"); };
    var z : String = "Ralph" on replace { println("z: {z}"); };
    var seq: String[] on replace oldSlice[a..b] = newSlice{ for(s in seq[a..b]){ println(s) } };
}

Function

  • Copy the code to the editor:
         
class A {
        
    function f(name:String){
        println("class {this}");
        println("name: {name}");
    }

    override function toString():String{ "A" }

}
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
class A {
        
    function f(name:String){
        println("class {this}");
        println("name: {name}");
    }

    override function toString():String{ "A" }

}
===

=== Function Return

  • Copy the code to the editor:
         
class B{
    public function create ():B {
        return B{}
    }
}
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
class B{
    public function create ():B {
        return B{}
    }
}

Init

  • Copy the code to the editor:
         
class A{

    init{
        println("init");
    }

    postinit{
        println("post init");
    }

}
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
class A{

    init{
        println("init");
    }

    postinit{
        println("post init");
    }

}

Inheritance

  • Copy the code to the editor:
         
import javafx.scene.*;

class MyCustomNode extends CustomNode {
    override function create(){ Group{} }
}
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
import javafx.scene.*;

class MyCustomNode extends CustomNode {
    override function create(){ Group{} }
}






Scene Graph

Stage

  • Copy the code to the editor:
         
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.text.*;
import javafx.scene.input.*;
import javafx.scene.shape.*;
import javafx.scene.paint.*;
import javafx.scene.control.*;


Stage {
    title : "MyApp"
    scene: Scene {
    width: 200
    height: 200
        content: [
            Text {
                font: Font { size: 24 }
                x: 10, y: 30
                content: "Hello World!"
            }
            Button {
                    text: "Button"
                    action: function() {
                        println("2 + 3 = {2 + 3}");
                        println("Hello World!")
                    }
            }
            Circle {
                    centerX: 100, centerY: 100
                    radius: 40
                    fill: Color.GREEN
                    onMouseClicked: function( e: MouseEvent ):Void {
                        var x = e.x;
                        var y = e.y;
                        println("x: {x}, y: {y}");
                    }
            }
        ]
    }
}
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted

Sequence

  • Copy the code to the editor:
         
import javafx.scene.shape.*;
import javafx.scene.transform.*;

Circle {
    transforms: [ Rotate{ angle:90.0 }, Scale{ x:0.3, y:0.3 } ]
}

  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
import javafx.scene.shape.*;
import javafx.scene.transform.*;

Circle {
    transforms: [ Rotate{ angle:90.0 }, Scale{ x:0.3, y:0.3 } ]
}

For Loop

  • Copy the code to the editor:
         
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;


Group {
    content: for( r in [1..10 step 2]) Circle{ radius: r fill: Color.GREEN }
}

  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;


Group {
    content: for( r in [1..10 step 2]) Circle{ radius: r fill: Color.GREEN }
}




Animation

'at'

  • Copy the code to the editor:
         
import javafx.animation.*;

var blur: Double = 80.0;

Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames: [
        at (0s) {   blur         =>   80.0        }
        at (3s) { blur =>          0.0 tween Interpolator.EASEBOTH}
        at (5s) {     blur => 0.0 }
    ]
}
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted

Text

'Some lines'

  • Copy the code to the editor:
         
import javafx.scene.text.Text;

Text {
    content: 'Sequence level1 = new Sequence();\n'
'Text text0 = new Text();\n'
              'text0.text = "Wird erreicht durch "\n'
              'Sequence level2 = new Sequence();\n'
                                 'Text text1 = new Text();\n'
              'text1.text="neue Constructor-Syntax \n'
              'level2.add (text1);\n'
              'Text text2 = new Text();\n'
                     'text2.text="Sequenzen,";\n'
              'level2.add (text2);\n'
                           'Text text3 = new Text();\n'
              'text3.text="und funktionale Sprachelemente.";\n'
              'level2.add (text3);\n'
              'text0.items = level1;\n'
                        'Outline outline = new Outline();\n'
              'outline.items = level1;\n'
              'Html html = new Html();\n'
              'Sequence childs = new Sequence();\n'
                             'childs.add (html);\n'
              'html.childs = childs\n';
}

  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted

Operators

Operator If

  • Copy the code to the editor:
         
var a  =  10;
var f  =  false;

if(a < 100 and not f ){
    a++;
    f = not f;
}else if(a != 100 and f ) {
    a--;
    f = a!=2 ;
}else{
    a+=10;
    f = a < 100 ;
}

var b = if( a +3 < 100  ) 10 else if( -100 < a - 3 ) -10 else 0;
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
var a  =  10;
var f  =  false;

if(a < 100 and not f ){
    a++;
    f = not f;
}else if(a != 100 and f ) {
    a--;
    f = a!=2 ;
}else{
    a+=10;
    f = a < 100 ;
}

var b = if( a +3 < 100  ) 10 else if( -100 < a - 3 ) -10 else 0;

Operator For

  • Copy the code to the editor:
         
for(a in [1..100]){
    println(a+10);
}

var seq = for(b in [1,5,9]) b + b / 2;
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
for(a in [1..100]){
    println(a+10);
}

var seq = for(b in [1,5,9]) b + b / 2;

Operator While

  • Copy the code to the editor:
         
var a = 10;

while(a < 100){
    a++;
    a * 2;
    println(a);
}
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
var a = 10;

while(a < 100){
    a++;
    a * 2;
    println(a);
}

Operator Try-Ctach

  • Copy the code to the editor:
         
import java.io.FileReader;
import java.io.BufferedReader;

import java.io.IOException;
import java.lang.RuntimeException;

try {
    var reader = new BufferedReader(new FileReader("infilename"));
    var str = "";
    while (str != null) {
        println(str);
    }
    reader.close();
    throw new RuntimeException("");
    
} catch (e: IOException) {
    e.printStackTrace();
}catch(e: java.lang.Exception){
    println("Exception: {e.getMessage()}");
}finally{
    println("The end");
}
  • Format the code (press <Ctrl+F5>).
    • EXPECTED RESULT: The code should be formatted
import java.io.FileReader;
import java.io.BufferedReader;

import java.io.IOException;
import java.lang.RuntimeException;

try {
    var reader = new BufferedReader(new FileReader("infilename"));
    var str = "";
    while (str != null) {
        println(str);
    }
    reader.close();
    throw new RuntimeException("");
    
} catch (e: IOException) {
    e.printStackTrace();
}catch(e: java.lang.Exception){
    println("Exception: {e.getMessage()}");
}finally{
    println("The end");
}



Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo