├── Citrus.jar ├── Citrus ├── images │ ├── Label.png │ ├── Tile.png │ ├── ellen.jpg │ ├── Button.png │ ├── Slider.png │ ├── Toggle.png │ ├── uparrow.png │ ├── Checkbox.png │ ├── FileIcon.png │ ├── TextField.png │ ├── downarrow.png │ ├── emptyImage.png │ ├── leftarrow.png │ ├── rightarrow.png │ ├── DropDownArrows.png │ ├── MarmaladeIcon.gif │ ├── comboBoxArrow.png │ ├── rotationFigure.png │ ├── ToolbarDownArrow.png │ └── ToolbarRightArrow.png └── languages │ ├── Collage │ ├── canvas.jpg │ └── images │ │ ├── 153_5334.jpg │ │ ├── IMG_0955.jpg │ │ ├── IMG_1058.jpg │ │ ├── IMG_4609.jpg │ │ ├── IMG_4711.jpg │ │ ├── IMG_5019.jpg │ │ ├── IMG_5146.jpg │ │ ├── IMG_5150.jpg │ │ └── IMG_6081.jpg │ ├── ToDoDemo │ ├── ToDo1.citrus │ ├── ToDo2.citrus │ ├── ToDo3.citrus │ ├── ToDo4.citrus │ ├── ToDo5.citrus │ ├── ToDoViews0.citrus │ ├── ToDoViews1.citrus │ ├── ToDoViews2.citrus │ ├── ToDoViews3.citrus │ └── ToDoViews4.citrus │ ├── RegressionTests │ └── RegressionTests.citrus │ ├── Widgets │ ├── LabeledView.citrus │ ├── Selector.citrus │ ├── Toggler.citrus │ ├── TreeView.citrus │ └── Palette.citrus │ ├── CaretDemo │ └── CaretDemo.citrus │ ├── ToDo │ ├── ToDo.citrus │ └── ToDo.tmproj │ ├── ViewConstraintDemo │ └── ViewConstraintDemo.citrus │ ├── ListenerTests │ └── ListenerTests.citrus │ ├── CollapsablePalette │ └── CollapsablePalette.citrus │ ├── RegularExpressionDemo │ └── RegularExpressionDemo.citrus │ ├── CitrusEditor │ └── CitrusEditor.tmproj │ └── HTML │ └── HTML.citrus ├── edu └── cmu │ └── hcii │ └── citrus │ ├── vieweditor │ ├── ShapeView.java │ ├── ColorReferenceView.java │ ├── ViewDecListView.java │ ├── BehaviorListView.java │ ├── PaintView.java │ ├── LayoutView.java │ ├── ViewSelection.java │ └── BehaviorView.java │ ├── Let.java │ ├── views │ ├── devices │ │ ├── KeyGroup.java │ │ ├── KeyboardKey.java │ │ └── MouseWheel.java │ ├── ReferenceView.java │ ├── ViewError.java │ ├── Action.java │ ├── Layout.java │ ├── layouts │ │ ├── NoLayout.java │ │ ├── CenteredLayout.java │ │ ├── TextFlowLayout.java │ │ ├── HorizontalLayout.java │ │ └── HorizontalTabbedLayout.java │ ├── transitions │ │ ├── Uniform.java │ │ └── FastToSlow.java │ ├── shapes │ │ ├── RectangleShape.java │ │ └── LineShape.java │ ├── Shape.java │ ├── Device.java │ ├── Image.java │ ├── AnimationStatement.java │ ├── SetView.java │ ├── Point.java │ ├── AnimateTogether.java │ ├── widgets │ │ ├── Picture.java │ │ └── MenuItem.java │ ├── Event.java │ ├── AnimateSetProperty.java │ ├── Transition.java │ ├── NoTranslatorView.java │ ├── paints │ │ ├── ImagePaint.java │ │ ├── PaintPaint.java │ │ ├── EllipsePaint.java │ │ └── GridPaint.java │ ├── behaviors │ │ └── Moveable.java │ ├── Rectangle.java │ ├── AnimateInOrder.java │ └── Transform.java │ ├── TypeExpression.java │ ├── TypeVariable.java │ ├── ElementChangeEvent.java │ ├── Parameter.java │ ├── Function.java │ ├── Context.java │ ├── PropertyRef.java │ ├── ViewState.java │ ├── Quote.java │ ├── Listener.java │ ├── ElementError.java │ ├── BoolLiteral.java │ ├── Expression.java │ ├── IntLiteral.java │ ├── RealLiteral.java │ ├── ListenerAdapter.java │ ├── Arg.java │ ├── Nothing.java │ ├── Int.java │ ├── Namespace.java │ ├── NewSet.java │ ├── DecInterface.java │ ├── ElementChangeAccumulator.java │ ├── Type.java │ ├── Bool.java │ ├── TextLiteral.java │ ├── Interpreter.java │ ├── ArgumentList.java │ ├── NewList.java │ ├── Char.java │ ├── CharLiteral.java │ ├── Possessive.java │ ├── BootTypeExpression.java │ ├── Real.java │ ├── When.java │ └── Closure.java ├── LICENSE └── CitrusJAR.jardesc /Citrus.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus.jar -------------------------------------------------------------------------------- /Citrus/images/Label.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/Label.png -------------------------------------------------------------------------------- /Citrus/images/Tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/Tile.png -------------------------------------------------------------------------------- /Citrus/images/ellen.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/ellen.jpg -------------------------------------------------------------------------------- /Citrus/images/Button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/Button.png -------------------------------------------------------------------------------- /Citrus/images/Slider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/Slider.png -------------------------------------------------------------------------------- /Citrus/images/Toggle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/Toggle.png -------------------------------------------------------------------------------- /Citrus/images/uparrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/uparrow.png -------------------------------------------------------------------------------- /Citrus/images/Checkbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/Checkbox.png -------------------------------------------------------------------------------- /Citrus/images/FileIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/FileIcon.png -------------------------------------------------------------------------------- /Citrus/images/TextField.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/TextField.png -------------------------------------------------------------------------------- /Citrus/images/downarrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/downarrow.png -------------------------------------------------------------------------------- /Citrus/images/emptyImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/emptyImage.png -------------------------------------------------------------------------------- /Citrus/images/leftarrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/leftarrow.png -------------------------------------------------------------------------------- /Citrus/images/rightarrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/rightarrow.png -------------------------------------------------------------------------------- /Citrus/images/DropDownArrows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/DropDownArrows.png -------------------------------------------------------------------------------- /Citrus/images/MarmaladeIcon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/MarmaladeIcon.gif -------------------------------------------------------------------------------- /Citrus/images/comboBoxArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/comboBoxArrow.png -------------------------------------------------------------------------------- /Citrus/images/rotationFigure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/rotationFigure.png -------------------------------------------------------------------------------- /Citrus/images/ToolbarDownArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/ToolbarDownArrow.png -------------------------------------------------------------------------------- /Citrus/images/ToolbarRightArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/images/ToolbarRightArrow.png -------------------------------------------------------------------------------- /Citrus/languages/Collage/canvas.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/languages/Collage/canvas.jpg -------------------------------------------------------------------------------- /Citrus/languages/ToDoDemo/ToDo1.citrus: -------------------------------------------------------------------------------- 1 | language ToDo uses "edu.cmu.hcii.citrus.restrictions" ####################### # Models # -------------------------------------------------------------------------------- /Citrus/languages/Collage/images/153_5334.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/languages/Collage/images/153_5334.jpg -------------------------------------------------------------------------------- /Citrus/languages/Collage/images/IMG_0955.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/languages/Collage/images/IMG_0955.jpg -------------------------------------------------------------------------------- /Citrus/languages/Collage/images/IMG_1058.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/languages/Collage/images/IMG_1058.jpg -------------------------------------------------------------------------------- /Citrus/languages/Collage/images/IMG_4609.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/languages/Collage/images/IMG_4609.jpg -------------------------------------------------------------------------------- /Citrus/languages/Collage/images/IMG_4711.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/languages/Collage/images/IMG_4711.jpg -------------------------------------------------------------------------------- /Citrus/languages/Collage/images/IMG_5019.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/languages/Collage/images/IMG_5019.jpg -------------------------------------------------------------------------------- /Citrus/languages/Collage/images/IMG_5146.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/languages/Collage/images/IMG_5146.jpg -------------------------------------------------------------------------------- /Citrus/languages/Collage/images/IMG_5150.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/languages/Collage/images/IMG_5150.jpg -------------------------------------------------------------------------------- /Citrus/languages/Collage/images/IMG_6081.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amyjko/citrus-barista/HEAD/Citrus/languages/Collage/images/IMG_6081.jpg -------------------------------------------------------------------------------- /Citrus/languages/ToDoDemo/ToDo2.citrus: -------------------------------------------------------------------------------- 1 | language ToDo uses "edu.cmu.hcii.citrus.restrictions" ####################### # Models # a ToDoItem is a Element that . a ToDoList is a Element that . a ToDoDoc is a Element that . -------------------------------------------------------------------------------- /Citrus/languages/ToDoDemo/ToDo3.citrus: -------------------------------------------------------------------------------- 1 | language ToDo uses "edu.cmu.hcii.citrus.restrictions" ####################### # Models # a ToDoItem is a Element that has Bool done = false has Text whatToDo = "" 2 | restricted to [ (a RegularExpression expr="[^\s]*") ] 3 | 4 | fun test [ has Real one has Real two ] 5 | (if done (one plus two) (one minus (this test2))) . a ToDoList is a Element that . a ToDoDoc is a Element that . -------------------------------------------------------------------------------- /Citrus/languages/ToDoDemo/ToDo4.citrus: -------------------------------------------------------------------------------- 1 | language ToDo uses "edu.cmu.hcii.citrus.restrictions" ####################### # Models # a ToDoItem is a Element that has Bool done = false has Text whatToDo = "" 2 | restricted to [ (a RegularExpression expr="[^\s]*") ] 3 | 4 | fun test [ has Real one has Real two ] 5 | (if done (one plus two) (one minus (this test2))) . a ToDoList is a ToDoItem that has List items = [(a ToDoItem)] . a ToDoDoc is a Element that . -------------------------------------------------------------------------------- /Citrus/languages/RegressionTests/RegressionTests.citrus: -------------------------------------------------------------------------------- 1 | language RegressionTests 2 | 3 | init 4 | (do 5 | refs Element test = (a ListTest) 6 | (test.list append "Blah item") 7 | (test.list append "Last") 8 | (test.list removeAll) 9 | ) 10 | 11 | a ListTest is an Element that 12 | 13 | has List list = [] 14 | 15 | when event (list ItemInserted) 16 | (debug event.item " inserted") 17 | 18 | when event (list ItemRemoved) 19 | (debug event.item " removed") 20 | 21 | . 22 | -------------------------------------------------------------------------------- /Citrus/languages/ToDoDemo/ToDo5.citrus: -------------------------------------------------------------------------------- 1 | language ToDo uses "edu.cmu.hcii.citrus.restrictions" ####################### # Models # a ToDoItem is a Element that has Bool done = false has Text whatToDo = "" 2 | restricted to [ (a RegularExpression expr="[^\s]*") ] 3 | 4 | fun test [ has Real one has Real two ] 5 | (if done (one plus two) (one minus (this test2))) . a ToDoList is a ToDoItem that has List items = [(a ToDoItem)] . a ToDoDoc is a Element that has ToDoList list = (a ToDoList) 6 | has Bool hide = false 7 | . -------------------------------------------------------------------------------- /Citrus/languages/ToDoDemo/ToDoViews0.citrus: -------------------------------------------------------------------------------- 1 | language ToDoViews 2 | 3 | uses "ToDo" 4 | uses "edu.cmu.hcii.citrus.views" 5 | uses "edu.cmu.hcii.citrus.views.widgets" 6 | uses "edu.cmu.hcii.citrus.views.layouts" 7 | 8 | ####################### 9 | # Views 10 | # 11 | 12 | a ToDoItemView is a ElementView that 13 | 14 | has ToDoItem model = ? 15 | 16 | has Layout layout = (a NoLayout) 17 | has Real width = 100.0 18 | has Real height = 100.0 19 | has Real scale = 1.0 20 | 21 | has List children = [ 22 | ] 23 | 24 | . -------------------------------------------------------------------------------- /Citrus/languages/Widgets/LabeledView.citrus: -------------------------------------------------------------------------------- 1 | language Widgets 2 | 3 | uses "edu.cmu.hcii.citrus.views" 4 | uses "edu.cmu.hcii.citrus.views.layouts" 5 | 6 | a LabeledView is an View that 7 | 8 | has Text label = ? 9 | refs View view = ? 10 | # has FontFace font = (a FontFace family="Arial" size=12.0) 11 | 12 | has Real hPad = 2.0 13 | has Real vPad = 2.0 14 | 15 | has Real width <- (this lastChildsRight) 16 | has Real height <- (this tallestChildsHeight) 17 | has Layout layout = (a HorizontalLayout spacing=2.0) 18 | 19 | has List children = [ (a Label text=label) view ] 20 | 21 | . 22 | -------------------------------------------------------------------------------- /Citrus/languages/ToDoDemo/ToDoViews1.citrus: -------------------------------------------------------------------------------- 1 | language ToDoViews 2 | 3 | uses "ToDo" 4 | uses "edu.cmu.hcii.citrus.views" 5 | uses "edu.cmu.hcii.citrus.views.widgets" 6 | uses "edu.cmu.hcii.citrus.views.layouts" 7 | 8 | ####################### 9 | # Views 10 | # 11 | 12 | a ToDoItemView is a ElementView that 13 | 14 | has ToDoItem model = ? 15 | 16 | has Layout layout = (a NoLayout) 17 | has Real width = 100.0 18 | has Real height = 100.0 19 | has Real scale = 1.0 20 | 21 | has List children = [ 22 | (a Checkbox0 property = model.@done) 23 | (a TextField1 property = model.@whatToDo) 24 | ] 25 | 26 | a Checkbox0 is a Checkbox that. 27 | a TextField1 is a TextField that. 28 | 29 | . -------------------------------------------------------------------------------- /Citrus/languages/ToDoDemo/ToDoViews2.citrus: -------------------------------------------------------------------------------- 1 | language ToDoViews 2 | 3 | uses "ToDo" 4 | uses "edu.cmu.hcii.citrus.views" 5 | uses "edu.cmu.hcii.citrus.views.widgets" 6 | uses "edu.cmu.hcii.citrus.views.layouts" 7 | 8 | ####################### 9 | # Views 10 | # 11 | 12 | a ToDoItemView is a ElementView that 13 | 14 | has ToDoItem model = ? 15 | 16 | has Layout layout = (a HorizontalLayout spacing=10.0) 17 | has Real width = 100.0 18 | has Real height = 100.0 19 | has Real scale = 1.0 20 | 21 | has List children = [ 22 | (a Checkbox0 property = model.@done) 23 | (a TextField1 property = model.@whatToDo) 24 | ] 25 | 26 | a Checkbox0 is a Checkbox that. 27 | a TextField1 is a TextField that. 28 | 29 | . -------------------------------------------------------------------------------- /Citrus/languages/ToDoDemo/ToDoViews3.citrus: -------------------------------------------------------------------------------- 1 | language ToDoViews 2 | 3 | uses "ToDo" 4 | uses "edu.cmu.hcii.citrus.views" 5 | uses "edu.cmu.hcii.citrus.views.widgets" 6 | uses "edu.cmu.hcii.citrus.views.layouts" 7 | 8 | ####################### 9 | # Views 10 | # 11 | 12 | a ToDoItemView is a ElementView that 13 | 14 | has ToDoItem model = ? 15 | 16 | has Layout layout = (a HorizontalLayout spacing=10.0) 17 | has Real width <= (this lastChildsRight) 18 | has Real height <= (this tallestChildsHeight) 19 | has Real scale = 1.0 20 | 21 | has List children = [ 22 | (a Checkbox0 property = model.@done) 23 | (a TextField1 property = model.@whatToDo) 24 | ] 25 | 26 | a Checkbox0 is a Checkbox that. 27 | a TextField1 is a TextField that. 28 | 29 | . -------------------------------------------------------------------------------- /Citrus/languages/ToDoDemo/ToDoViews4.citrus: -------------------------------------------------------------------------------- 1 | language ToDoViews 2 | 3 | uses "ToDo" 4 | uses "edu.cmu.hcii.citrus.views" 5 | uses "edu.cmu.hcii.citrus.views.widgets" 6 | uses "edu.cmu.hcii.citrus.views.layouts" 7 | 8 | ####################### 9 | # Views 10 | # 11 | 12 | a ToDoItemView is a ElementView that 13 | 14 | has ToDoItem model = ? 15 | 16 | has Layout layout = (a HorizontalLayout spacing=10.0) 17 | has Real width <= (this lastChildsRight) 18 | has Real height <= (this tallestChildsHeight) 19 | has Real scale <= (if (model.done and (model ownerOfType ToDoDoc).hide) 0.0 1.0) 20 | 21 | has List children = [ 22 | (a Checkbox0 property = model.@done) 23 | (a TextField1 property = model.@whatToDo) 24 | ] 25 | 26 | has List behaviors = [] 27 | 28 | a Checkbox0 is a Checkbox that. 29 | a TextField1 is a TextField that. 30 | 31 | . -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/vieweditor/ShapeView.java: -------------------------------------------------------------------------------- 1 | // Created on Feb 21, 2005 2 | 3 | package edu.cmu.hcii.citrus.vieweditor; 4 | 5 | import java.util.Hashtable; 6 | 7 | import edu.cmu.hcii.citrus.*; 8 | import edu.cmu.hcii.citrus.views.*; 9 | import edu.cmu.hcii.citrus.views.paints.*; 10 | 11 | // 12 | // @author Andrew J. Ko 13 | // 14 | public class ShapeView extends ElementView { 15 | 16 | public static final Dec model = new Dec(); 17 | 18 | public static final Dec width = new Dec(new Real(48)); 19 | public static final Dec height = new Dec(new Real(48)); 20 | 21 | public static final Dec> background = new Dec>(new NewList( 22 | new RectanglePaint(Color.black, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0, 0))); 23 | 24 | public ShapeView(ArgumentList arguments) { super(arguments); } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/vieweditor/ColorReferenceView.java: -------------------------------------------------------------------------------- 1 | // Created on Feb 25, 2005 2 | 3 | package edu.cmu.hcii.citrus.vieweditor; 4 | 5 | import java.util.Hashtable; 6 | 7 | import edu.cmu.hcii.citrus.*; 8 | import edu.cmu.hcii.citrus.views.*; 9 | 10 | // 11 | // @author Andrew J. Ko 12 | // 13 | public class ColorReferenceView extends ElementView { 14 | 15 | public static final Dec model = new Dec(); 16 | 17 | public static final Dec width = new Dec(new Real(40)); 18 | public static final Dec height = new Dec(new Real(20)); 19 | 20 | public static final Dec> background = new Dec>(View.>parseExpression( 21 | "[" + 22 | "(a FilledRectanglePaint primaryColor=model secondaryColor=model)" + 23 | "]" 24 | )); 25 | 26 | public ColorReferenceView(ArgumentList arguments) { super(arguments); } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Citrus/languages/CaretDemo/CaretDemo.citrus: -------------------------------------------------------------------------------- 1 | language RegExpDemo 2 | 3 | # We import citrus since we're making views 4 | uses "edu.cmu.hcii.citrus.views" 5 | uses "edu.cmu.hcii.citrus.views.widgets" 6 | uses "edu.cmu.hcii.citrus.views.paints" 7 | uses "edu.cmu.hcii.citrus.views.layouts" 8 | uses "edu.cmu.hcii.citrus.views.devices" 9 | uses "edu.cmu.hcii.citrus.views.transitions" 10 | uses "edu.cmu.hcii.citrus.views.behaviors" 11 | 12 | init 13 | (do 14 | ((a RegExpDemo) show) 15 | ) 16 | 17 | a RegExpDemo is an App that 18 | 19 | has Real width = 200.0 20 | has Real height = 200.0 21 | 22 | has Layout layout = (a VerticalLayout) 23 | has Text blah = "" 24 | has List children = [ 25 | (a TextField 26 | property=@blah 27 | left<-'(if (parent is nothing) 0.0 ((parent.width minus (this paddedWidth)) divide 2.0)) 28 | top<-'(if (parent is nothing) 0.0 ((parent.height minus (this paddedHeight)) divide 2.0)) 29 | ) 30 | ] 31 | 32 | . -------------------------------------------------------------------------------- /Citrus/languages/ToDo/ToDo.citrus: -------------------------------------------------------------------------------- 1 | language ToDo ####################### # Models # a ToDoItem is an Element that has Bool done = false has Text whatToDo = "" for which (whatToDo matches "[^\n\t]*") has List items = [] fun ToDoItem itemAfter [] (if (items isEmpty) (this itemAfterInList) (items first)) fun ToDoItem itemBefore [] (do refs ToDoItem itemBefore = (this itemBeforeInList) (if (itemBefore is nothing) nothing itemBefore) ) fun ToDoItem lastItem [] (if (items isEmpty) this ((items last) lastItem)) fun ToDoItem itemAfterInList [] (if ((owner itemAfter this) is nothing) (if (owner.owner isa ToDoItem) (owner.owner itemAfterInList) nothing) (owner itemAfter this)) fun ToDoItem itemBeforeInList [] (if ((owner itemBefore this) is nothing) (if (owner.owner isa ToDoItem) owner.owner nothing) ((owner itemBefore this) lastItem)) . a ToDoDoc is an Element that has List items = [(a ToDoItem)] has Bool hide = false . -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/vieweditor/ViewDecListView.java: -------------------------------------------------------------------------------- 1 | // Created on Feb 22, 2005 2 | 3 | package edu.cmu.hcii.citrus.vieweditor; 4 | 5 | import edu.cmu.hcii.citrus.*; 6 | import edu.cmu.hcii.citrus.views.*; 7 | import edu.cmu.hcii.citrus.views.layouts.*; 8 | 9 | // 10 | // @author Andrew J. Ko 11 | // 12 | public class ViewDecListView extends ListView { 13 | 14 | public static final Dec> model = new Dec>(); 15 | 16 | public static final Dec layout = new Dec(new VerticalLayout(-1, 0, 2)); 17 | 18 | public static final Dec hPad = new Dec(new Real(3)); 19 | public static final Dec vPad = new Dec(new Real(3)); 20 | 21 | public ViewDecListView(ArgumentList arguments) { super(arguments); 22 | 23 | // Hack to get property to update this view 24 | get(model).getPropertyOwner().addView(this); 25 | } 26 | 27 | public Bool include(Element item) { 28 | 29 | return item.get(Dec.typeExpression).getBaseType().isTypeOf(Boot.LIST).not(); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/vieweditor/BehaviorListView.java: -------------------------------------------------------------------------------- 1 | // Created on Feb 22, 2005 2 | 3 | package edu.cmu.hcii.citrus.vieweditor; 4 | 5 | import edu.cmu.hcii.citrus.*; 6 | import edu.cmu.hcii.citrus.views.*; 7 | import edu.cmu.hcii.citrus.views.layouts.*; 8 | 9 | // 10 | // @author Andrew J. Ko 11 | // 12 | public class BehaviorListView extends ListView { 13 | 14 | public static final Dec> model = new Dec>(); 15 | 16 | public static final Dec layout = new Dec(new VerticalLayout(-1, 0, 2)); 17 | 18 | public static final Dec width = new Dec(true, "(if (model isEmpty) 150.0 (this rightmostChildsRight))"); 19 | public static final Dec height = new Dec(true, "(if (model isEmpty) 150.0 (this lastChildsBottom))"); 20 | 21 | public static final Dec hPad = new Dec(new Real(3)); 22 | public static final Dec vPad = new Dec(new Real(3)); 23 | 24 | public BehaviorListView(ArgumentList arguments) { super(arguments); 25 | 26 | get(property).addView(this); 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Andrew J. Ko 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Citrus/languages/ViewConstraintDemo/ViewConstraintDemo.citrus: -------------------------------------------------------------------------------- 1 | language ViewConstraintDemo 2 | 3 | # We import citrus since we're making views 4 | uses "edu.cmu.hcii.citrus.views" 5 | uses "edu.cmu.hcii.citrus.views.widgets" 6 | uses "edu.cmu.hcii.citrus.views.paints" 7 | uses "edu.cmu.hcii.citrus.views.layouts" 8 | uses "edu.cmu.hcii.citrus.views.devices" 9 | uses "edu.cmu.hcii.citrus.views.transitions" 10 | uses "edu.cmu.hcii.citrus.views.behaviors" 11 | 12 | init 13 | (do 14 | ((a ViewConstraintDemo) show) 15 | ) 16 | 17 | a ViewConstraintDemo is an App that 18 | 19 | has Real width = 200.0 20 | has Real height = 200.0 21 | 22 | has Text blah = "" 23 | has Layout layout = (a VerticalLayout alignment="centered" spacing=5.0) 24 | has List children = [ 25 | (a Button 26 | top=5.0 27 | label=(a Label text="New") action=(fun [] (children appendOverTime (a GreenBox) (a Uniform duration=200.0)))) 28 | (a GreenBox) 29 | ] 30 | 31 | . 32 | 33 | a GreenBox is a View that 34 | 35 | has List background = [(a FilledRectanglePaint primaryColor=(a Color r=255.0 g=0.0 b=0.0) cornerWidth=5.0 cornerHeight=5.0)] 36 | has Real width = 15.0 37 | has Real height = 15.0 38 | 39 | . 40 | -------------------------------------------------------------------------------- /Citrus/languages/ListenerTests/ListenerTests.citrus: -------------------------------------------------------------------------------- 1 | language ListenerTests 2 | 3 | uses "edu.cmu.hcii.citrus.views" 4 | uses "edu.cmu.hcii.citrus.views.widgets" 5 | uses "edu.cmu.hcii.citrus.views.layouts" 6 | uses "edu.cmu.hcii.citrus.views.devices" 7 | uses "edu.cmu.hcii.citrus.views.paints" 8 | 9 | init 10 | (do 11 | ((a ListenerTestsApp) show) 12 | ) 13 | 14 | 15 | a ListenerTestsApp is an App that 16 | 17 | has Bool flag = false 18 | has List children = [ (a Checkbox property=@flag) (a TestView)] 19 | has Real width = 200.0 20 | has Real height = 200.0 21 | 22 | has Text text = "blah" for which (text matches "c[a-z]+") 23 | 24 | when event (@flag ValueChanged) 25 | (debug "Flag changed to " flag " and text is \"" text "\"") 26 | 27 | when event (@text ValidityChanged) 28 | (debug "Text was invalid; wasn't set") 29 | 30 | a TestView is a View that 31 | 32 | has Real hPad = 40.0 33 | has Real vPad = 40.0 34 | has Real width <- (this parentsWidth) 35 | for which (width lessThan 400.0) otherwise 400.0 36 | has Real height <- (this parentsHeight) 37 | for which (width lessThan 400.0) otherwise 400.0 38 | 39 | has List content = [ 40 | (a FilledRectanglePaint primaryColor=(a Color r=255.0 g=0.0 b=0.0)) 41 | ] 42 | 43 | . 44 | 45 | 46 | . 47 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Let.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | // A named namespace with a list of declarations and an expression that defines its evaluation. 27 | // Name, arguments and expression 28 | public class Let extends BaseFunction { 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/devices/KeyGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.devices; 25 | 26 | import edu.cmu.hcii.citrus.views.Device; 27 | 28 | public class KeyGroup extends Device { 29 | 30 | public KeyGroup(Device newOwner, String newName) { 31 | 32 | super(newName); 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Citrus/languages/CollapsablePalette/CollapsablePalette.citrus: -------------------------------------------------------------------------------- 1 | language Collaps 2 | 3 | uses "edu.cmu.hcii.citrus.views" 4 | uses "edu.cmu.hcii.citrus.views.widgets" 5 | uses "edu.cmu.hcii.citrus.views.layouts" 6 | uses "edu.cmu.hcii.citrus.views.devices" 7 | uses "edu.cmu.hcii.citrus.views.paints" 8 | uses "edu.cmu.hcii.citrus.views.transitions" 9 | uses "Widgets" 10 | 11 | init 12 | (do ((a PaletteTest) show)) 13 | 14 | a PaletteTest is an App that 15 | 16 | has Real width = 400.0 17 | has Real height = 400.0 18 | 19 | has List children = [ 20 | (a Palette 21 | name="Palette" 22 | contents=(a Options) 23 | left=100.0 24 | top=100.0 25 | width=100.0 26 | background=[ 27 | (a FilledRectanglePaint 28 | primaryColor=(a Color r=200.0 g=100.0 b=0.0) 29 | secondaryColor=(a Color r=200.0 g=200.0 b=50.0)) 30 | ] 31 | ) 32 | ] 33 | 34 | an Options is a View that 35 | 36 | has Real left = 10.0 37 | has Real width <- (this rightmostChildsRight) 38 | has Real height <- (this lastChildsBottom) 39 | has Layout layout = (a VerticalLayout alignment="left-aligned" spacing=5.0) 40 | 41 | has List children = [ 42 | (a Label text="Red") 43 | (a Label text="Green") 44 | (a Label text="Blue") 45 | (a Label text="Cyan") 46 | (a Label text="Magenta") 47 | (a Label text="Yellow") 48 | ] 49 | 50 | . 51 | 52 | . -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/TypeExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public interface TypeExpression extends Element { 27 | 28 | public Type getBaseType(); 29 | public List getTypeArguments(); 30 | public Text getBaseTypeName(); 31 | public Bool canBeAssignedA(Namespace t); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/TypeVariable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class TypeVariable extends BaseElement { 27 | 28 | public static final BootDec type = new BootDec(Boot.ELEMENT); 29 | public static final BootDec name = new BootDec(new Text("uninitialized type variable name")); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/ReferenceView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | // A subclass that exists solely to distinguish element views from reference views 29 | public class ReferenceView extends ElementView { 30 | 31 | public ReferenceView(Namespace type, ArgumentList args) { super(type, args); } 32 | 33 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/ViewError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | /** 27 | * @author ajko 28 | */ 29 | public class ViewError extends RuntimeException { 30 | 31 | public ViewError(String explanation) { 32 | 33 | super(explanation); 34 | 35 | // System.err.println(explanation); 36 | this.printStackTrace(); 37 | System.exit(0); 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/ElementChangeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public abstract class ElementChangeEvent { 27 | 28 | protected final Element elementChanged; 29 | 30 | public ElementChangeEvent(Element elementChanged) { 31 | 32 | this.elementChanged = elementChanged; 33 | 34 | } 35 | 36 | public Element getElementChanged() { return elementChanged; } 37 | 38 | public abstract void undo(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Parameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class Parameter extends BaseElement { 27 | 28 | public Parameter() { super(); } 29 | public Parameter(ArgumentList args) { super(args); } 30 | 31 | public ValueType evaluate(Element env) { throw new ElementError("Shouldn't be evaluating a parameter", this); } 32 | 33 | public Namespace getType() { return Boot.PARAMETER; } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public interface Function extends Namespace { 27 | 28 | // Return an iterator for all of the declarations that the Type declares 29 | // and inherits from its super types, in the order they should be instantiated. 30 | public Iterable getDeclarationsToInstantiate(); 31 | 32 | public String getName(); 33 | public Element getExpression(); 34 | 35 | public boolean isStatic(); 36 | 37 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/Action.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | // More convenient than typing "new Function..." everywhere, but definitely not necessary. 29 | // Definitely deprecated 30 | public abstract class Action extends Expression { 31 | 32 | public Action() {} 33 | 34 | public abstract boolean evaluate(View env); 35 | public final Bool evaluate(Element env) { return new Bool(evaluate((View)env)); } 36 | 37 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/Layout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | abstract public class Layout extends BaseElement { 29 | 30 | public Layout(ArgumentList args) { super(args); } 31 | public Layout(Namespace type, ArgumentList args) { super(type, args); } 32 | 33 | // Return the x and y coordinates for the given child, based on the layout's semantics. 34 | public abstract Real getLeft(View child); 35 | public abstract Real getTop(View child); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/layouts/NoLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.layouts; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.Layout; 28 | import edu.cmu.hcii.citrus.views.View; 29 | 30 | public class NoLayout extends Layout { 31 | 32 | public NoLayout(ArgumentList args) { super(args); } 33 | 34 | public Real getLeft(View child) { return child.peek(View.left); } 35 | public Real getTop(View child) { return child.peek(View.top); } 36 | 37 | public String toString() { return "No layout"; } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/transitions/Uniform.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.transitions; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.*; 28 | 29 | public final class Uniform extends Transition { 30 | 31 | public Uniform() { super(150); } 32 | public Uniform(Namespace type, ArgumentList args) { super(type, args); } 33 | public Uniform(long newDuration) { super(newDuration); } 34 | 35 | public double value(long t, double startValue, double endValue) { 36 | return startValue + percentElapsed(t) * (endValue - startValue); 37 | 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Context.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public interface Context extends Element { 27 | 28 | public Set getDeclarationsInContext(Set names); 29 | public Set getTypesInContext(Set names); 30 | public Set getFunctionsInContext(Set functions); 31 | 32 | // Searches the type and its prototypes for types, functions, etc. 33 | public DecInterface getDeclarationOf(Text name); 34 | public Type getTypeNamed(String name); 35 | public Function getFunctionNamed(Text name, Bool isStatic); 36 | 37 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/transitions/FastToSlow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.transitions; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.Transition; 28 | 29 | public final class FastToSlow extends Transition { 30 | 31 | public FastToSlow() { super(150); } 32 | public FastToSlow(Namespace type, ArgumentList args) { super(type, args); } 33 | public FastToSlow(long newDuration) { super(newDuration); } 34 | 35 | public double value(long t, double startValue, double endValue) { 36 | 37 | return startValue + Math.sqrt(Math.sqrt(percentElapsed(t))) * (endValue - startValue); 38 | 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/PropertyRef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class PropertyRef extends Expression> { 27 | 28 | public static final Dec name = new Dec(new Text("")); 29 | 30 | public PropertyRef() {} 31 | public PropertyRef(String newName) { 32 | 33 | set(name, new Text(newName)); 34 | 35 | } 36 | 37 | public Property evaluate(Element env) { 38 | 39 | return env.getProperty(peek(name)); 40 | 41 | } 42 | 43 | public Text toCitrus() { return new Text("" + CitrusParser.PROPERTY + peek(name)); } 44 | public String toString() { return toCitrus().value; } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/shapes/RectangleShape.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.shapes; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.*; 28 | 29 | public class RectangleShape extends Shape { 30 | 31 | public RectangleShape() { super(); } 32 | public RectangleShape(ArgumentList arguments) { super(arguments); } 33 | 34 | public boolean contains(double l, double t, double r, double b, double x, double y) { 35 | 36 | double minX, maxX, minY, maxY; 37 | if(l < r) { minX = l; maxX= r; } else { minX = r; maxX = l; } 38 | if(t < b) { minY = t; maxY= b; } else { minY = b; maxY = t; } 39 | 40 | return minX <= x && maxX >= x && minY <= y && maxY >= y; 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/ViewState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | import java.util.Hashtable; 27 | 28 | public class ViewState { 29 | 30 | private String viewTypeName; 31 | private Hashtable propertiesValues; 32 | 33 | public ViewState(String newViewTypeName) { 34 | 35 | this.viewTypeName = newViewTypeName; 36 | propertiesValues = new Hashtable(); 37 | 38 | } 39 | 40 | public void addPropertyValue(String propertyName, Object value) { 41 | 42 | propertiesValues.put(propertyName, value); 43 | 44 | } 45 | 46 | public String getViewTypeName() { return viewTypeName; } 47 | public Hashtable getPropertyValueTable() { return propertiesValues; } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/shapes/LineShape.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.shapes; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.Shape; 28 | 29 | public class LineShape extends Shape { 30 | 31 | public static final Dec strokeWidth = new Dec(new Real(5.0)); 32 | 33 | public LineShape() { super(); } 34 | public LineShape(ArgumentList arguments) { super(arguments); } 35 | 36 | public boolean contains(double l, double t, double r, double b, double x, double y) { 37 | 38 | double stroke = real(strokeWidth); 39 | java.awt.geom.Line2D line = new java.awt.geom.Line2D.Double(l, t, r, b); 40 | return line.intersects(x - stroke / 2, y - stroke / 2, stroke, stroke); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Quote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class Quote extends Expression { 27 | 28 | public static final Dec> value = new Dec>(); 29 | 30 | public Quote() { super(); } 31 | public Quote(ArgumentList arguments) { super(arguments); } 32 | public Quote(TypeContained newValue) { 33 | 34 | set(value, newValue); 35 | 36 | } 37 | 38 | public TypeContained evaluate(Element context) { 39 | 40 | return (TypeContained)peek(value); 41 | 42 | } 43 | 44 | public String toString() { return "" + CitrusParser.QUOTE + peek(value); } 45 | public Text toCitrus() { return new Text("" + CitrusParser.QUOTE + peek(value).toCitrus()); } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /CitrusJAR.jardesc: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /Citrus/languages/ToDo/ToDo.tmproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | currentDocument 6 | ToDo.citrus 7 | documents 8 | 9 | 10 | filename 11 | ToDoViews.citrus 12 | lastUsed 13 | 2005-10-23T22:29:57Z 14 | 15 | 16 | filename 17 | ToDo.citrus 18 | lastUsed 19 | 2005-10-23T22:29:57Z 20 | selected 21 | 22 | 23 | 24 | fileHierarchyDrawerWidth 25 | 200 26 | metaData 27 | 28 | ToDo.citrus 29 | 30 | caret 31 | 32 | column 33 | 0 34 | line 35 | 1 36 | 37 | firstVisibleColumn 38 | 0 39 | firstVisibleLine 40 | 0 41 | 42 | ToDoViews.citrus 43 | 44 | caret 45 | 46 | column 47 | 34 48 | line 49 | 5 50 | 51 | firstVisibleColumn 52 | 0 53 | firstVisibleLine 54 | 0 55 | 56 | 57 | openDocuments 58 | 59 | ToDo.citrus 60 | ToDoViews.citrus 61 | 62 | showFileHierarchyDrawer 63 | 64 | windowFrame 65 | {{365, 0}, {734, 878}} 66 | 67 | 68 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Listener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | import edu.cmu.hcii.citrus.views.Transition; 27 | 28 | // Handles changes to a property's value. 29 | // Both properties and elements maintain lists of listeners. 30 | // Properties notify when they change, and also notify their element 31 | // owner when they change. Elements that receive notifications from their properties 32 | // notify their listeners. 33 | public interface Listener { 34 | 35 | public void changed(Property p, Transition t, ValueType oldValue, ValueType newValue); 36 | public void outOfDate(Property p, Transition t, ValueType oldValue); 37 | public void validityChanged(Property p, Transition t, boolean isValid); 38 | public void cycle(Property p, List cycle); 39 | 40 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/Shape.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | // A Paint Element defines a single layer of paint for a Tile's Style. 29 | // Paint objects may be shared, since they are tile independent. 30 | public abstract class Shape extends BaseElement { 31 | 32 | public Shape() { super(); } 33 | public Shape(ArgumentList arguments) { super(arguments); } 34 | 35 | ///////////////////////////////////////////////////////////////////// 36 | // Should return true if the shape, as defined by the given rectangle, 37 | // contains the the given point. 38 | ///////////////////////////////////////////////////////////////////// 39 | 40 | abstract public boolean contains(double l, double t, double r, double b, double x, double y); 41 | 42 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/Device.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | // A device, which is capable of a set of discrete actions, and may 29 | // also have other devices. 30 | public class Device extends BaseElement { 31 | 32 | public static final Dec> devices = new Dec>(new NewList()); 33 | 34 | // The name of the device 35 | public static final Dec name = new Dec(new Text("unnamed device")); 36 | 37 | public Device() {} 38 | public Device(ArgumentList args) { super(args); } 39 | public Device(String newName) { 40 | 41 | set(name, new Text(newName)); 42 | 43 | } 44 | 45 | public void addDevice(Device d) { get(devices).append(d); } 46 | 47 | public String toString() { return text(name); } 48 | 49 | } -------------------------------------------------------------------------------- /Citrus/languages/Widgets/Selector.citrus: -------------------------------------------------------------------------------- 1 | language Widgets 2 | 3 | uses "edu.cmu.hcii.citrus.views" 4 | uses "edu.cmu.hcii.citrus.views.widgets" 5 | uses "edu.cmu.hcii.citrus.views.layouts" 6 | uses "edu.cmu.hcii.citrus.views.devices" 7 | uses "edu.cmu.hcii.citrus.views.paints" 8 | uses "edu.cmu.hcii.citrus.views.transitions" 9 | 10 | # Given an arbitrary set of views, maintains a selection among the views. 11 | a Selector is a View that 12 | 13 | has View selection = (children first) 14 | has Real hPad = 5.0 15 | has Real vPad = 5.0 16 | has Layout layout = (a HorizontalLayout spacing=5.0) 17 | has Real width <- (this lastChildsRight) 18 | has Real height <- (this tallestChildsHeight) 19 | has Bool clipsChildren = false 20 | 21 | has List background = [ 22 | (a FilledRectanglePaint 23 | primaryColor=(a Color r=0.0 g=0.0 b=0.0 alpha=64.0) 24 | cornerWidth=10.0 cornerHeight=10.0 25 | )] 26 | has List foreground = [(a SelectionBorder)] 27 | 28 | a SelectionBorder is a RectanglePaint that 29 | 30 | has Color primaryColor = (a Color r=100.0 g=100.0 b=255.0) 31 | has Real stroke = 3.0 32 | has Real cornerWidth = 10.0 33 | has Real cornerHeight = 10.0 34 | has Real alpha <- (if (selection is nothing) 0.0 1.0) 35 | has Real left <- (if (selection is nothing) 0.0 selection.left) 36 | has Real top <- (if (selection is nothing) 0.0 selection.top minus) 37 | has Real right <- (if (selection is nothing) 0.0 (enclosing.width minus selection.right)) 38 | has Real bottom <- (if (selection is nothing) 0.0 (enclosing.height minus selection.bottom)) 39 | 40 | . 41 | 42 | has List behaviors = [ 43 | (a Behavior event=(a MouseButton.Pressed) action= 44 | (fun [ refs View view refs Event event ] 45 | (do 46 | (@selection set (this getChildThatContains event.point)) 47 | true 48 | ))) 49 | ] 50 | 51 | . 52 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/ElementError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class ElementError extends RuntimeException { 27 | 28 | private Element element; 29 | private String message; 30 | 31 | public ElementError(String message, Element element) { 32 | 33 | super(message); 34 | this.message = message; 35 | this.element = element; 36 | 37 | } 38 | 39 | public String getMessage() { return toString(); } 40 | 41 | public String toString() { 42 | 43 | String stack = ""; 44 | System.err.println("" + message); 45 | for(Evaluate e : Evaluate.evalStack) { 46 | String eString = e.toString(); 47 | eString = eString.substring(0, Math.min(eString.length(), 80)); 48 | stack = "" + eString + "\n" + stack; 49 | } 50 | stack = element + ": " + message + "\n" + stack; 51 | 52 | return stack; 53 | 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/Image.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | public class Image extends BootElement { 29 | 30 | public final java.awt.Image value; 31 | 32 | public Image(java.awt.Image image) { 33 | 34 | value = image; 35 | 36 | } 37 | 38 | public Namespace getType() { return Reflection.getJavaType(Image.class); } 39 | 40 | public Real width() { return new Real(value.getWidth(null)); } 41 | public Real height() { return new Real(value.getHeight(null)); } 42 | 43 | public Image evaluate(Element env) { return this; } 44 | 45 | public Element duplicate() { return new Image(value); } 46 | public Text toCitrus() { return new Text(value.toString()); } 47 | public String toString() { return value.toString(); } 48 | 49 | public Bool isEquivalentTo(Element o) { return new Bool(this.equals(o)); } 50 | 51 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/AnimationStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | public abstract class AnimationStatement extends BaseElement { 29 | 30 | public AnimationStatement() {} 31 | public AnimationStatement(Namespace subType, ArgumentList args) { super(subType, args); } 32 | 33 | // Executing an animation statement enqueues it to be animated, and returns. 34 | public Nothing evaluate(Element context) { 35 | 36 | // When this is executed, it gets added to the App's animation list. 37 | startAnimating(context); 38 | App.enqueueAnimationStatement(this, context); 39 | return new Nothing(); 40 | 41 | } 42 | 43 | public abstract boolean startAnimating(Element context); 44 | 45 | // This is called by the app until it returns true, indicating that its done. 46 | public abstract boolean doneAnimating(Element context); 47 | 48 | } -------------------------------------------------------------------------------- /Citrus/languages/Widgets/Toggler.citrus: -------------------------------------------------------------------------------- 1 | language Widgets 2 | 3 | uses "edu.cmu.hcii.citrus.views" 4 | uses "edu.cmu.hcii.citrus.views.widgets" 5 | uses "edu.cmu.hcii.citrus.views.devices" 6 | uses "edu.cmu.hcii.citrus.views.transitions" 7 | 8 | a Toggler is an ElementView that 9 | 10 | refs Property property = ? 11 | 12 | refs View trueView = (a Label text="true") 13 | refs View falseView = (a Label text="false") 14 | 15 | has Real hPad = 3.0 16 | has Real vPad = 3.0 17 | 18 | has Real width <- (if (property get) ((children first) paddedWidth) ((children last) paddedWidth)) 19 | has Real height <- (if (property get) ((children first) paddedHeight) ((children last) paddedHeight)) 20 | 21 | has List behaviors = [ 22 | (a Behavior event=(a Keyboard.Typed character=` `) action= 23 | '(do (property set ((property get) not) (a Uniform duration=150.0)) true)) 24 | (a Behavior event=(a MouseButton.Pressed) action= 25 | '(do ((this mouse).cursor pick this) true)) 26 | (a Behavior event=(a MouseButton.Released) action= 27 | '(if ((this mouse).cursor.viewPicked is this) 28 | (do 29 | ((this mouse).cursor release) 30 | (property set ((property get) not) (a Uniform duration=150.0)) 31 | true 32 | ) 33 | false 34 | )) 35 | ] 36 | 37 | has List children = [ (a True) (a False) ] 38 | 39 | # fun updatedViewFor 40 | # public ElementView updatedViewFor(Property p, Element newValue, Transition t) { return this; } 41 | 42 | a False is a View that 43 | 44 | has Bool hidden <- (property get) 45 | has Real width <- (this widestChildsWidth) 46 | has Real height <- (this tallestChildsHeight) 47 | has List children = [ falseView ] 48 | 49 | . 50 | 51 | a True is a View that 52 | 53 | has Bool hidden <- ((property get) not) 54 | has Real width <- (this widestChildsWidth) 55 | has Real height <- (this tallestChildsHeight) 56 | has List children = [ trueView ] 57 | 58 | . 59 | 60 | . 61 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/devices/KeyboardKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.devices; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.*; 28 | 29 | public class KeyboardKey extends Device { 30 | 31 | // Legacy event instances used by widgets 32 | public final Event pressed; 33 | public final Event released; 34 | 35 | public final static Dec down = new Dec(new Bool(false)); 36 | 37 | private Keyboard keyboard; 38 | 39 | public KeyboardKey(Keyboard owner, String name) { 40 | 41 | super(name); 42 | 43 | keyboard = owner; 44 | pressed = new Keyboard.Pressed(null, 0, new Text(name), new Bool(false), new Bool(false), new Bool(false), new Bool(false)); 45 | released = new Keyboard.Released(null, 0, new Text(name), new Bool(false), new Bool(false), new Bool(false), new Bool(false)); 46 | 47 | } 48 | 49 | public boolean isDown() { return bool(down); } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/SetView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | // A view is a tile that's a view of some property. 29 | public class SetView extends GroupView { 30 | 31 | public static final Dec> model = new Dec>("(property get)", true); 32 | 33 | // An expression that takes two arguments and chooses one. 34 | public static final Dec> comparator = new Dec>(); 35 | // The order in which to place the set elements. 36 | public static final Dec direction = new Dec(new Bool(true)); 37 | 38 | public static final Dec referenceViewsOnly = new Dec(new Bool(false)); 39 | 40 | public SetView() { this(null, null); } 41 | public SetView(ArgumentList arguments) { this(null, arguments); } 42 | public SetView(Namespace subtype, ArgumentList arguments) { super(subtype, arguments); updatedViewFor(null, get(model), null); } 43 | 44 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/BoolLiteral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class BoolLiteral extends Expression { 27 | 28 | // Restricted in Boot.java 29 | public static final Dec token = new Dec(new Text("true")); 30 | 31 | public static final Dec value = new Dec(true, new BaseElement() { 32 | public Bool evaluate(Element env) { 33 | 34 | if(env.get(token).value.equals("true")) return new Bool(true); 35 | else return new Bool(false); 36 | 37 | } 38 | }); 39 | 40 | public BoolLiteral() {} 41 | public BoolLiteral(ArgumentList args) { super(args); } 42 | public BoolLiteral(String value) { set(token, new Text(value)); } 43 | 44 | public Bool evaluate(Element env) { return peek(value); } 45 | 46 | public Type resultingType() { return Boot.BOOL; } 47 | 48 | public Text toCitrus() { return get(value).toCitrus(); } 49 | public String toString() { return get(value).toString(); } 50 | 51 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Expression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public abstract class Expression extends BaseElement { 27 | 28 | // This is actually constrained to "((this getElementOwner) contextFor this)" in Boot 29 | public static final BootDec> context = new BootDec>(null, true); 30 | 31 | public Expression() { super(); } 32 | public Expression(Namespace type, ArgumentList arguments) { super(type, arguments); } 33 | public Expression(ArgumentList arguments) { super(arguments); } 34 | 35 | public abstract TypeEvaluatesTo evaluate(Element env); 36 | 37 | public String toString() { 38 | 39 | String str = "(" + getType().getName(); 40 | for(DecInterface pd : getType().getDeclarationsToInstantiate()) 41 | str = str + " " + pd.getName() + "=" + get(pd) + " "; 42 | 43 | str = str.substring(0, str.length() - 1); 44 | str = str + ")"; 45 | return str; 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/IntLiteral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class IntLiteral extends Expression { 27 | 28 | // Restricted in Boot.java 29 | public static final Dec token = new Dec(new Text("0")); 30 | 31 | public static final Dec value = new Dec(true, new BaseElement() { 32 | public Int evaluate(Element env) { 33 | 34 | int i = 0; 35 | try { 36 | i = Integer.parseInt(env.get(token).value); 37 | } 38 | catch(NumberFormatException e) {} 39 | return new Int(i); 40 | 41 | } 42 | }); 43 | 44 | public IntLiteral() {} 45 | public IntLiteral(ArgumentList args) { super(args); } 46 | public IntLiteral(String value) { set(token, new Text(value)); } 47 | 48 | public Int evaluate(Element env) { return peek(value); } 49 | 50 | public Type resultingType() { return Boot.INT; } 51 | 52 | public Text toCitrus() { return get(token); } 53 | public String toString() { return get(token).toString(); } 54 | 55 | } -------------------------------------------------------------------------------- /Citrus/languages/RegularExpressionDemo/RegularExpressionDemo.citrus: -------------------------------------------------------------------------------- 1 | language RegularExpressionDemo 2 | 3 | # We import citrus since we're making views 4 | uses "edu.cmu.hcii.citrus.views" 5 | uses "edu.cmu.hcii.citrus.views.widgets" 6 | uses "edu.cmu.hcii.citrus.views.paints" 7 | uses "edu.cmu.hcii.citrus.views.layouts" 8 | uses "edu.cmu.hcii.citrus.views.devices" 9 | uses "edu.cmu.hcii.citrus.views.transitions" 10 | uses "edu.cmu.hcii.citrus.views.behaviors" 11 | 12 | init 13 | (do 14 | ((a RegularExpressionDemo) show) 15 | ) 16 | 17 | a RegularExpressionDemo is an App that 18 | 19 | has Real width = 200.0 20 | has Real height = 200.0 21 | 22 | has Layout layout = (a VerticalLayout) 23 | has Text blah = "0" 24 | for which (blah matches "[0-9]+") 25 | has List children = [ (a DemoField property=@blah) ] 26 | 27 | . 28 | 29 | a DemoField is a TextField that 30 | 31 | has Real left <- (if (parent is nothing) 0.0 ((parent.width minus (this paddedWidth)) divide 2.0)) 32 | has Real top <- (if (parent is nothing) 0.0 ((parent.height minus (this paddedHeight)) divide 2.0)) 33 | 34 | refs Paint errorPaint = (an ErrorPaint) 35 | has List background = [ (a FilledRectanglePaint primaryColor=(a Color r=220.0 g=220.0 b=220.0) )errorPaint ] 36 | 37 | has List behaviors = ([ 38 | (a Behavior event=(a Keyboard.Typed) action= 39 | (fun [ refs View view refs Event event ] 40 | (do 41 | (if (event.character isEquivalentTo `\b`) 42 | (this backspace) 43 | (this insert event.character) 44 | ) 45 | true 46 | ) 47 | ) 48 | ) 49 | ] appendList super) 50 | 51 | when event (property ValidityChanged) 52 | (do 53 | (debug "validity changed to " (property isValid)) 54 | (if (property isValid) 55 | (errorPaint.@alpha set 0.0) 56 | (errorPaint.@alpha set 255.0) 57 | ) 58 | ) 59 | 60 | an ErrorPaint is a FilledRectanglePaint that 61 | 62 | has Color primaryColor = (a Color r=255.0 g=0.0 b=0.0 alpha=128.0) 63 | has Real alpha=0.0 64 | 65 | . 66 | 67 | . 68 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/Point.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | public class Point extends BaseElement { 29 | 30 | public static final Dec x = new Dec(new Real(0.0)); 31 | public static final Dec y = new Dec(new Real(0.0)); 32 | 33 | public Point(Namespace subtype, ArgumentList arguments) { super(subtype, arguments); } 34 | public Point(double newX, double newY) { super(null); set(x, new Real(newX)); set(y, new Real(newY)); } 35 | 36 | public double getX() { return real(x); } 37 | public double getY() { return real(y); } 38 | 39 | public String toString() { return "(" + getX() + ", " + getY() + ")"; } 40 | 41 | public int hashCode() { 42 | 43 | int code = 1; 44 | code = code * 31 + (new Double(getPropertyByDeclaration(x).getVisible().value)).hashCode(); 45 | code = code * 31 + (new Double(getPropertyByDeclaration(y).getVisible().value)).hashCode(); 46 | return code; 47 | 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/RealLiteral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class RealLiteral extends Expression { 27 | 28 | // Restricted in Boot.java 29 | public static final Dec token = new Dec(new Text("0.0")); 30 | 31 | public static final Dec value = new Dec(true, new BaseElement() { 32 | public Real evaluate(Element env) { 33 | 34 | double real = 0.0; 35 | try { 36 | real = Double.parseDouble(env.get(token).value); 37 | } 38 | catch(NumberFormatException e) {} 39 | return new Real(real); 40 | 41 | } 42 | }); 43 | 44 | public RealLiteral() {} 45 | public RealLiteral(ArgumentList args) { super(args); } 46 | public RealLiteral(String value) { set(token, new Text(value)); } 47 | 48 | public Real evaluate(Element env) { return peek(value); } 49 | 50 | public Type resultingType() { return Boot.REAL; } 51 | 52 | public Text toCitrus() { return get(token); } 53 | public String toString() { return get(token).toString(); } 54 | 55 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/ListenerAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | 27 | import edu.cmu.hcii.citrus.views.Transition; 28 | 29 | 30 | // Handles changes to a property's value. 31 | public class ListenerAdapter implements Listener { 32 | 33 | public void changed(Property p, Transition t, ValueType oldValue, ValueType newValue) {} 34 | public void outOfDate(Property p, Transition t, ValueType oldValue) {} 35 | public void validityChanged(Property p, Transition t, boolean isValid) {} 36 | public void cycle(Property p, List cycle) { 37 | 38 | System.err.println("*****CYCLE DETECTED******"); 39 | boolean first = true; 40 | for(Property prop : cycle) { 41 | System.err.print("" + prop.getElementOwner() + "'s " + prop.getName()); 42 | if(first) System.err.println(" depends on "); 43 | else System.err.println(", which depends on "); 44 | first = false; 45 | } 46 | System.err.println("" + p.getElementOwner() + "'s " + p.getName() + "."); 47 | 48 | 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/vieweditor/PaintView.java: -------------------------------------------------------------------------------- 1 | // Created on Feb 22, 2005 2 | 3 | package edu.cmu.hcii.citrus.vieweditor; 4 | 5 | import edu.cmu.hcii.citrus.*; 6 | import edu.cmu.hcii.citrus.views.*; 7 | import edu.cmu.hcii.citrus.views.layouts.*; 8 | import edu.cmu.hcii.citrus.views.paints.*; 9 | 10 | // 11 | // @author Andrew J. Ko 12 | // 13 | public class PaintView extends ElementView { 14 | 15 | public static final Dec model = new Dec(); 16 | 17 | public static final Dec layout = new Dec(new HorizontalLayout(0, App.getGlobalStyle().get(Style.horizontalSpacing).value)); 18 | 19 | public static final Dec width = new Dec(View.parseExpression("(this rightmostChildsRight)")); 20 | public static final Dec height = new Dec("(this tallestChildsHeight)"); 21 | 22 | public static final Dec scale = new Dec(new Real(0.75)); 23 | 24 | public static final Dec> background = new Dec>(new NewList( 25 | new FilledRectanglePaint(Color.lightGray, 0.5, 0.0, 0.0, 0.0, 0.0, 5, 5))); 26 | 27 | public static final Dec> children = new Dec>(View.>parseExpression( 28 | "[" + 29 | "(a Preview)" + 30 | "]" 31 | )); 32 | 33 | public static final Dec vPad = new Dec(new Real(5)); 34 | public static final Dec hPad = new Dec(new Real(5)); 35 | 36 | public static final Dec focusable = new Dec(new Bool(true)); 37 | 38 | public static final Dec> behaviors = new Dec>("[(a Draggable)]"); 39 | 40 | public PaintView(ArgumentList arguments) { super(arguments); } 41 | 42 | public static class Preview extends View { 43 | 44 | public static final Dec width = new Dec(new Real(48)); 45 | public static final Dec height = new Dec(new Real(48)); 46 | 47 | public static final Dec> background = new Dec>(View.>parseExpression("[model]")); 48 | 49 | public Preview(ArgumentList arguments) { super(arguments); } 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/AnimateTogether.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | public class AnimateTogether extends AnimationStatement { 29 | 30 | public static final Dec> statements = new Dec>(new NewList()); 31 | 32 | public AnimateTogether() { super(); } 33 | public AnimateTogether(Namespace subType, ArgumentList args) { super(subType, args); } 34 | 35 | public boolean startAnimating(Element context) { 36 | 37 | // Start all of the statements. 38 | for(AnimationStatement statement : get(statements)) 39 | statement.startAnimating(context); 40 | 41 | return false; 42 | 43 | } 44 | 45 | public boolean doneAnimating(Element context) { 46 | 47 | boolean allDone = true; 48 | for(AnimationStatement statement : get(statements)) { 49 | if(!statement.doneAnimating(context)) { 50 | allDone = false; 51 | break; 52 | } 53 | } 54 | 55 | // If we they're all done, we're done. 56 | return allDone; 57 | 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/widgets/Picture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.widgets; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.*; 28 | import edu.cmu.hcii.citrus.views.paints.ImagePaint; 29 | 30 | //////////////////////////////////// 31 | // 32 | // A Tile wrapped around its image paint. 33 | // 34 | //////////////////////////////////// 35 | public class Picture extends View { 36 | 37 | public static final Dec image = new Dec(Images.getImage("Slider.png")); 38 | 39 | public static final Dec width = new Dec(true, new Expression() { 40 | public Real evaluate(Element env) { 41 | return env.get(image).width(); }}); 42 | 43 | public static final Dec height = new Dec(true, new Expression() { 44 | public Real evaluate(Element env) { 45 | return env.get(image).height(); }}); 46 | 47 | public static final Dec> content = new Dec>("[(a ImagePaint image=image)]"); 48 | 49 | public Picture(ArgumentList arguments) { super(arguments); } 50 | 51 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Arg.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | 25 | package edu.cmu.hcii.citrus; 26 | 27 | public class Arg extends BaseElement { 28 | 29 | public static final BootDec param = new BootDec(new Text("")); 30 | public static final BootDec valueIsConstraint = new BootDec(new Bool(false)); 31 | public static final BootDec> value = new BootDec>(new Nothing()); 32 | 33 | public Arg() {} 34 | public Arg(ArgumentList args) { super(args); } 35 | public Arg(String newParam, boolean newValueIsConstraint, Element newValue) { 36 | 37 | set(param, new Text(newParam)); 38 | set(valueIsConstraint, new Bool(newValueIsConstraint)); 39 | set(value, newValue); 40 | 41 | } 42 | 43 | public Element value() { return peek(value); } 44 | 45 | public String toString() { 46 | 47 | String par = (get(Arg.param) == null || get(Arg.param).value.equals("")) ? "" : get(param).toString(); 48 | if(!par.equals("")) par = par + (bool(valueIsConstraint) ? CitrusParser.CONSTRAINT : "" + CitrusParser.DEFAULT); 49 | return "" + par + get(Arg.value); 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Nothing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | // Nothing is a JavaElement that doesn't track its users, since there's nothing it 27 | // would do with them anyway. 28 | public class Nothing extends BootElement { 29 | 30 | // TYPE 31 | public Namespace getType() { return Boot.NOTHING; } 32 | 33 | // EQUALITY 34 | public Bool isEquivalentTo(Element e) { return new Bool(e instanceof Nothing); } 35 | public Bool is(Element e) { return new Bool(e == null || e instanceof Nothing); } 36 | 37 | // DUPLICATION 38 | public Element duplicate() { return new Nothing(); } 39 | 40 | // TRANSLATION 41 | public Text toCitrus() { return new Text("nothing"); } 42 | public Text toCitrusReference() { return new Text("nothing"); } 43 | public String toString() { return "nothing"; } 44 | public Text toXML() { return toCitrus(); } 45 | 46 | // PREDICATES 47 | public Bool isNothing() { return Bool.TRUE; } 48 | public Bool isSomething() { return Bool.FALSE; } 49 | 50 | // Evaluate the element using the given environment. 51 | public Nothing evaluate(Element env) { return this; } 52 | 53 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/layouts/CenteredLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.layouts; 25 | 26 | 27 | import edu.cmu.hcii.citrus.*; 28 | import edu.cmu.hcii.citrus.views.Layout; 29 | import edu.cmu.hcii.citrus.views.View; 30 | 31 | public class CenteredLayout extends Layout { 32 | 33 | public static final Dec spacing = new Dec(new Real(0.0)); 34 | 35 | public CenteredLayout(ArgumentList args) { super(args); } 36 | 37 | public CenteredLayout(double newSpacing) { 38 | 39 | super(null); 40 | set(spacing, new Real(newSpacing)); 41 | 42 | } 43 | 44 | public Real getLeft(View child) { 45 | 46 | return child.getParent().get(View.width).minus(child.paddedWidth().divide(new Real(2))); 47 | 48 | } 49 | 50 | public Real getTop(View child) { 51 | 52 | return child.getPreviousSibling() == null ? 53 | child.getParent().get(View.height).minus(child.getParent().totalHeightOfChildren().divide(new Real(2))) : 54 | child.getPreviousSibling().get(View.bottom).plus(get(spacing)); 55 | 56 | } 57 | 58 | public String toString() { 59 | 60 | return "Centered Layout"; 61 | 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /Citrus/languages/Widgets/TreeView.citrus: -------------------------------------------------------------------------------- 1 | language Widgets 2 | 3 | uses "edu.cmu.hcii.citrus.views" 4 | uses "edu.cmu.hcii.citrus.views.widgets" 5 | uses "edu.cmu.hcii.citrus.views.layouts" 6 | uses "edu.cmu.hcii.citrus.views.devices" 7 | uses "edu.cmu.hcii.citrus.views.paints" 8 | 9 | a TreeView is an View that 10 | 11 | refs View label = ? 12 | refs View list = ? 13 | 14 | has View selection = nothing 15 | has Bool collapsed = false 16 | 17 | has Layout layout = (a VerticalLayout spacing=5.0) 18 | has Real width <- (if collapsed ((children first) lastChildsRight) (this rightmostChildsRight)) 19 | has Real height <- (if collapsed ((children first) tallestChildsHeight) (this lastChildsBottom)) 20 | has Bool clipsChildren = false 21 | has List children = [(a TreeHeader) list] 22 | 23 | a TreeHeader is a View that 24 | 25 | has Layout layout = (a HorizontalLayout spacing=5.0) 26 | has Real width <- (this lastChildsRight) 27 | has Real height <- (this tallestChildsHeight) 28 | has Bool clipsChildren = false 29 | has List children = [ 30 | (a Toggler 31 | property=@collapsed 32 | trueView=(a RightArrow) 33 | falseView=(a DownArrow)) 34 | label 35 | ] 36 | 37 | . 38 | 39 | a RightArrow is a View that 40 | 41 | has static List rightArrow = [ 42 | (a PolygonPaint 43 | primaryColor=(a Color r=0.0 g=0.0 b=0.0) 44 | points=[(a Point x=0.0 y=0.0) (a Point x=0.0 y=1.0) (a Point x=1.0 y=0.5)] 45 | ) 46 | ] 47 | 48 | has Real width = 10.0 49 | has Real height = 10.0 50 | has Real top <- (((this parentsHeight) minus height) divide 2.0) 51 | has List foreground = RightArrow.rightArrow 52 | has Bool hidden <- (collapsed not) 53 | 54 | . 55 | 56 | a DownArrow is a View that 57 | 58 | has static List downArrow = [ 59 | (a PolygonPaint 60 | primaryColor=(a Color r=0.0 g=0.0 b=0.0) 61 | points=[(a Point x=0.0 y=0.0) (a Point x=1.0 y=0.0) (a Point x=0.5 y=1.0)] 62 | ) 63 | ] 64 | 65 | has Real width = 10.0 66 | has Real height = 10.0 67 | has Real top <- (((this parentsHeight) minus height) divide 2.0) 68 | has List foreground = DownArrow.downArrow 69 | has Bool hidden <- collapsed 70 | 71 | . 72 | 73 | . 74 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Int.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class Int extends BootElement implements Comparable { 27 | 28 | public final int value; 29 | 30 | public Int(int newValue) { value = newValue; } 31 | 32 | public Int plus(Int operand) { return new Int(value + operand.value); } 33 | public Int minus(Int operand) { return new Int(value - operand.value); } 34 | public Bool equals(Int operand) { return new Bool(value == operand.value); } 35 | 36 | public Bool greaterThan(Int operand) { return new Bool(value > operand.value); } 37 | 38 | public String toString() { return "" + value; } 39 | 40 | public Bool isEquivalentTo(Element e) { return new Bool(e instanceof Int && ((Int)e).value == value); } 41 | public Element duplicate() { return new Int(value); } 42 | public Namespace getType() { return Boot.INT; } 43 | public Text toCitrus() { return new Text("" + value); } 44 | public Text toCitrusReference() { return toCitrus(); } 45 | public Text toXML() { return toCitrus(); } 46 | 47 | public Int evaluate(Element env) { return this; } 48 | 49 | public int compareTo(Int i) { return value < i.value ? -1 : value > i.value ? 1 : 0; } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Namespace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | // So that we can boostrap the Types in the Elements language without having to create actual types. 27 | public interface Namespace extends Context { 28 | 29 | // The name of this type of namespace 30 | public String getName(); 31 | 32 | // Returns true if the this type is a type of the given type. 33 | public Bool isTypeOf(Namespace t); 34 | 35 | // Return the language that this is part of. 36 | public Language getLanguage(); 37 | 38 | // Make an element by using the type's default values in the declarations and the arguments passed in. 39 | public Element instantiate(ArgumentList arguments); 40 | 41 | // Return an iterator for all of the declarations that the Type declares 42 | // and inherits from its super types, in the order they should be instantiated. 43 | public Iterable getDeclarationsToInstantiate(); 44 | 45 | // Return an iterator for all of the declarations that the Type declares. 46 | public Iterable getDeclarationsDeclared(); 47 | 48 | // Should return the number of property declarations. 49 | public int getNumberOfDeclarations(); 50 | 51 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | // Represents a generic input event, consisting of a time stamp, 29 | // the event that occured, and a record of the event's data. 30 | public class Event extends BaseElement { 31 | 32 | protected Window window; 33 | protected long timeStamp; 34 | 35 | public Event(Namespace type, ArgumentList args) { super(type, args); } 36 | public Event(ArgumentList args) { super(args); } 37 | public Event(Window newWindow, long newTimeStamp) { 38 | 39 | this.window = newWindow; 40 | this.timeStamp = newTimeStamp; 41 | 42 | } 43 | 44 | public Window getWindow() { return window; } 45 | public long getTimeStamp() { return timeStamp; } 46 | 47 | public boolean isNegligible() { return false; } 48 | 49 | // Equivalent if type equivalent 50 | public Bool isEquivalentTo(Element e) { return getType().is(e.getType()); } 51 | 52 | // Subclasses should handle the event instance appropriately. 53 | public void handle() {} 54 | 55 | public String toString() { return "" + getType() + " @ " + timeStamp; } 56 | public Text toText() { return new Text(toString()); } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/NewSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class NewSet extends Expression> { 27 | 28 | // The item expressions to be evaluated and inserted into a new list 29 | public static final BootDec>> items = new BootDec>>(new List()); 30 | 31 | public NewSet() { super(); } 32 | public NewSet(Namespace type, ArgumentList args) { super(type, args); } 33 | public NewSet(Element ... items) { 34 | 35 | super(); 36 | for(Element item : items) appendItem(item); 37 | 38 | } 39 | 40 | public void appendItem(Element item) { get(items).append(item); } 41 | 42 | public Set evaluate(Element env) { 43 | 44 | Set newList = new Set(); 45 | 46 | // Evaluate the arguments using the current environment, putting each in the function instance's local environment. 47 | for(Element item : peek(items)) 48 | newList.add(item.evaluate(env)); 49 | 50 | // Evaluate the function using the enclosing environment (which may be null) and return its value. 51 | return newList; 52 | 53 | } 54 | 55 | public Type resultingType() { return Boot.SET; } 56 | public Context contextFor(Element e) { return get(context); } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/DecInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public interface DecInterface extends Element { 27 | 28 | // NAME 29 | public Text getName(); 30 | 31 | // MODIFIERS 32 | public boolean isStatic(); 33 | public boolean isOverridable(); 34 | public boolean isReferenceOnly(); 35 | 36 | // TYPE 37 | public TypeExpression getTypeExpression(); 38 | 39 | // RESTRICTIONS 40 | public void is(PropertyRestriction newValueSet); 41 | public Element validate(Property property, ValueType value); 42 | public Set getValidValues(Property property, Set values); 43 | 44 | // DEFAULT 45 | public ValueType getDefaultValue(Element newElement); 46 | public boolean valueIsRecoverable(ValueType value); 47 | public boolean isParameterized(); 48 | public boolean isConstant(); 49 | public boolean isUndoable(); 50 | public boolean functionIsConstraint(); 51 | 52 | // CONSTRAINT 53 | public Element getValueFunction(); 54 | 55 | // OVERRIDING 56 | public void setDeclarationOverriden(DecInterface pd); 57 | public DecInterface getDeclarationOverridden(); 58 | 59 | // 60 | public Property make(Element owner); 61 | 62 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/ElementChangeAccumulator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | import java.util.LinkedList; 27 | 28 | public class ElementChangeAccumulator extends ElementChangeEvent { 29 | 30 | // Events are recorded reverse-chronologically. 31 | private final LinkedList events = new LinkedList(); 32 | 33 | public ElementChangeAccumulator(Element cause) { 34 | 35 | super(cause); 36 | 37 | } 38 | 39 | public void recordEvent(ElementChangeEvent event) { 40 | 41 | events.addFirst(event); 42 | 43 | } 44 | 45 | public boolean hasEvents() { return !events.isEmpty(); } 46 | 47 | static int blah = 0; 48 | public void undo() { 49 | 50 | //for(int i = 0; i < blah; i++) System.err.print("\t"); 51 | //System.err.println("Undoing " + elementChanged); 52 | //blah++; 53 | 54 | // Undo in reverse chronological order 55 | for(ElementChangeEvent event : events) { 56 | 57 | //for(int i = 0; i < blah; i++) System.err.print("\t"); 58 | //System.err.println("Undoing " + event); 59 | event.undo(); 60 | 61 | } 62 | 63 | //blah--; 64 | 65 | } 66 | 67 | public String toString() { 68 | 69 | String result = "" + elementChanged + " changed "; 70 | return result; 71 | 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Type.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public interface Type extends Namespace { 27 | 28 | // Returns true if the element can be created. 29 | public boolean isConcrete(); 30 | 31 | public Type getEnclosingType(); 32 | 33 | // Should return this type's prototype. 34 | public Type getPrototype(); 35 | 36 | // Adds this declaration to a type's list of instance or static declarations, depending on the declaration's static flag. 37 | // Throws an exception if a declaration with the give name already exists. 38 | public Nothing declareProperty(DecInterface newDeclaration); 39 | 40 | // Adds the given inner type to the type's list of type declarations. 41 | public Nothing declareType(Type newType); 42 | public Nothing declareFunction(Function newFunction); 43 | 44 | // Should return an iterator for all of the static declarations for this type. 45 | public Iterable> getStaticDeclarations(); 46 | 47 | // Constructs a canonical list of property declarations that should be used to instantiate 48 | // elements of this type, by searching through this type's prototypes and finding all of the 49 | // property declarations that need to be instantiated, and in what order. 50 | public void consolidate(); 51 | 52 | public boolean needsConsolidation(); 53 | 54 | public Type getInnerTypeNamed(String name); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/layouts/TextFlowLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.layouts; 25 | 26 | 27 | import edu.cmu.hcii.citrus.*; 28 | import edu.cmu.hcii.citrus.views.Layout; 29 | import edu.cmu.hcii.citrus.views.View; 30 | import edu.cmu.hcii.citrus.views.widgets.TextField; 31 | 32 | public class TextFlowLayout extends Layout { 33 | 34 | public static final Dec linespacing = new Dec(new Real(0.0)); 35 | 36 | public TextFlowLayout(Namespace type, ArgumentList args) { super(type, args); } 37 | 38 | // Return 0 if this is the first child, and the previous child's right + spacing for the rest. 39 | public Real getLeft(View child) { 40 | 41 | View sib = child.getPreviousSibling(); 42 | if(sib == null) return new Real(0.0); 43 | View second = sib.get(View.children).second(); 44 | if(!(second instanceof TextField)) return sib.get(View.right); 45 | return new Real(second.get(View.right).value + sib.get(View.left).value); 46 | 47 | } 48 | 49 | // Depends on the alignment. 50 | public Real getTop(View child) { 51 | 52 | View sib = child.getPreviousSibling(); 53 | if(sib == null) return new Real(0.0); 54 | View second = sib.get(View.children).second(); 55 | if(!(second instanceof TextField)) return sib.get(View.bottom).minus(child.paddedHeight()); 56 | return second.get(View.bottom).minus(child.paddedHeight()); 57 | 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/devices/MouseWheel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.devices; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.*; 28 | 29 | public class MouseWheel extends Device { 30 | 31 | public Event moved = new Moved(null, 0, this, null); 32 | 33 | public static class Moved extends Event { 34 | 35 | public static final Dec wheel = new Dec((Element)null, true); 36 | public static final Dec unitsMoved = new Dec(); 37 | 38 | public Moved(Window newWindow, long newTimeStamp, MouseWheel newWheel, Int newUnitsMoved) { 39 | super(newWindow, newTimeStamp); 40 | set(wheel, newWheel); 41 | set(unitsMoved, newUnitsMoved); 42 | } 43 | 44 | public void handle() { 45 | 46 | get(wheel).set(unitsMoved, get(unitsMoved)); 47 | Mouse mouse = get(wheel).getOwnerOfType(Mouse.class); 48 | if(mouse != null) mouse.handle(this); 49 | else System.err.println("Warning: " + wheel + " has no mouse owner"); 50 | 51 | } 52 | 53 | public boolean isNegligible() { return false; } 54 | 55 | }; 56 | 57 | public static final Dec unitsMoved = new Dec(new Int(0)); 58 | 59 | private Mouse mouse; 60 | 61 | public MouseWheel(Mouse newOwner, String name) { 62 | 63 | super(name); 64 | mouse = newOwner; 65 | 66 | } 67 | 68 | public int getUnitsMoved() { return integer(unitsMoved); } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Bool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class Bool extends BootElement { 27 | 28 | // Both set in Boot.java 29 | public static Bool TRUE, FALSE; 30 | 31 | public final boolean value; 32 | 33 | public Bool(boolean newValue) { value = newValue; } 34 | 35 | public Bool not() { return value ? FALSE : TRUE; } 36 | public Bool and(Bool operand) { return new Bool(value && operand.value); } 37 | public Bool or(Bool operand) { return new Bool(value || operand.value); } 38 | 39 | public Boolean valueFromString(String s) { 40 | 41 | if(s.equals("true")) return Boolean.TRUE; 42 | else if(s.equals("false")) return Boolean.FALSE; 43 | else throw new ElementError("A Boolean must be either \"true\" or \"false\"", this); 44 | 45 | } 46 | 47 | public Namespace getType() { return Boot.BOOL; } 48 | 49 | public Bool isEquivalentTo(Element e) { return new Bool(e instanceof Bool && ((Bool)e).value == value); } 50 | public Element duplicate() { return new Bool(value); } 51 | 52 | public Text toCitrus() { return new Text("" + value); } 53 | public Text toCitrusReference() { return new Text("" + value); } 54 | public String toString() { return "" + value; } 55 | public Text toXML() { return toCitrus(); } 56 | public static Bool valueOf(boolean bool) { return bool ? TRUE : FALSE; } 57 | 58 | public Bool evaluate(Element env) { return this; } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/AnimateSetProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | // 29 | // @author Andrew J. Ko 30 | // 31 | public class AnimateSetProperty extends AnimationStatement { 32 | 33 | public static final Dec property = new Dec(); 34 | public static final Dec value = new Dec(); 35 | public static final Dec transition = new Dec(); 36 | 37 | // Runtime state 38 | private Property propertyAnimating = null; 39 | 40 | public AnimateSetProperty() {} 41 | public AnimateSetProperty(Namespace subType, ArgumentList args) { super(subType, args); } 42 | 43 | public boolean startAnimating(Element context) { 44 | 45 | // Get the property, value, and transition 46 | Property p = get(property); 47 | Element v = get(value); 48 | Transition t = get(transition); 49 | if(t == null) t = App.getGlobalStyle().getQuickerTransition(); 50 | t.reset(); 51 | p.set(v, t); 52 | 53 | // If the property animating is visible, set it. 54 | propertyAnimating = p; 55 | 56 | return false; 57 | 58 | } 59 | 60 | public boolean doneAnimating(Element context) { 61 | 62 | // Is the property done transitioning? 63 | return propertyAnimating == null || propertyAnimating.isDoneTransitioning(); 64 | 65 | } 66 | 67 | public String toString() { 68 | 69 | return "set " + propertyAnimating.getName(); 70 | 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/TextLiteral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class TextLiteral extends Expression { 27 | 28 | private Text cache = null; 29 | public static final Dec token = new Dec(new Text("")); 30 | 31 | public static final Dec value = new Dec(true, new BaseElement() { 32 | public Text evaluate(Element env) { 33 | 34 | if(((TextLiteral)env).cache == null) { 35 | 36 | String tok = env.get(token).value; 37 | 38 | // if(tok.startsWith("\\u")) { 39 | // 40 | // 41 | // } 42 | // else { 43 | 44 | tok = tok.replace("\\\"", "\""); 45 | tok = tok.replace("\\\\", "\\"); 46 | tok = tok.replace("\\n", "\n"); 47 | tok = tok.replace("\\t", "\t"); 48 | tok = tok.replace("\\b", "\b"); 49 | 50 | // TODO: Still need to parse strings. 51 | 52 | ((TextLiteral)env).cache = new Text(tok); 53 | } 54 | return ((TextLiteral)env).cache; 55 | 56 | } 57 | }); 58 | 59 | public TextLiteral() {} 60 | public TextLiteral(ArgumentList args) { super(args); } 61 | public TextLiteral(String value) { set(token, new Text(value)); } 62 | 63 | public Text evaluate(Element env) { return peek(value); } 64 | 65 | public Type resultingType() { return Boot.TEXT; } 66 | 67 | public Text toCitrus() { return cache; }//get(token).toCitrus(); } 68 | public String toString() { return "\"" + cache + "\""; }//get(token).toString() + "\""; } 69 | 70 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/Transition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | /////////////////////////////////////////////////////////////// 29 | // 30 | // A data-agnostic animation class. Data comes in as objects, 31 | // and leaves as objects, and this class could care less about its type. 32 | // 33 | /////////////////////////////////////////////////////////////// 34 | public abstract class Transition extends BaseElement { 35 | 36 | // The time of the start of the transition 37 | protected long startTime; 38 | public static final Dec duration = new Dec(new Real(150.0)); 39 | 40 | // Created by passing a duration. Started by something else. 41 | public Transition(Namespace type, ArgumentList args) { super(type, args); } 42 | public Transition(double newDuration) { 43 | 44 | set(duration, new Real(newDuration)); 45 | reset(); 46 | 47 | } 48 | 49 | public void reset() { 50 | 51 | this.startTime = System.currentTimeMillis(); 52 | 53 | } 54 | 55 | // Returns true if the elapsed time is greater than the duration. 56 | public boolean isComplete(long t) { return (t - startTime) > real(duration); } 57 | protected double percentElapsed(long t) { return Math.min(1.0, (t - startTime) / real(duration)); } 58 | 59 | // The temporal function that determines the transition's behavior. 60 | public abstract double value(long t, double startValue, double endValue); 61 | 62 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Interpreter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class Interpreter extends Universe { 27 | 28 | public static final Dec showLexing = new Dec(new Bool(true)); 29 | public static final Dec env = new Dec((Element)null, true); 30 | public static final Dec temp = new Dec((Element)null, true); 31 | public static final Dec app = new Dec((Element)null, true); 32 | 33 | public Interpreter(Element newEnvironment) { 34 | 35 | set(env, this); 36 | set(app, newEnvironment); 37 | 38 | } 39 | 40 | public void readEvalPrint() { 41 | 42 | String input = ""; 43 | try { 44 | 45 | System.err.print("\n\n\n> "); 46 | 47 | char c = ' '; 48 | while(true) { 49 | c = (char)System.in.read(); 50 | if(c == '\n') { 51 | if(input.length() > 0) { 52 | try { 53 | if(bool(showLexing)) System.err.println(CitrusParser.tokenize(input)); 54 | Element code = CitrusParser.code(input); 55 | //System.err.println("Evaluating " + code); 56 | System.err.println("\n" + code.evaluate(get(env))); 57 | } catch(Exception e) { e.printStackTrace(); } 58 | System.err.println("\n"); 59 | } 60 | input = ""; 61 | System.err.print("" + get(env) + " > "); 62 | } 63 | else input = input + c; 64 | } 65 | 66 | } catch(java.io.IOException e) { System.err.println("Error reading input"); } 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/NoTranslatorView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.layouts.HorizontalLayout; 28 | import edu.cmu.hcii.citrus.views.paints.FilledRectanglePaint; 29 | import edu.cmu.hcii.citrus.views.widgets.Label; 30 | 31 | // 32 | // @author Andrew J. Ko 33 | // 34 | public class NoTranslatorView extends ElementView { 35 | 36 | public static final Dec property = new Dec(); 37 | 38 | public static final Dec layout = new Dec(new HorizontalLayout(0, 3)); 39 | 40 | public static final Dec width = new Dec("(this lastChildsRight)"); 41 | public static final Dec height = new Dec("(this tallestChildsHeight)"); 42 | 43 | public static final Dec hPad = new Dec(new Real(5)); 44 | public static final Dec vPad = new Dec(new Real(5)); 45 | 46 | public static final Dec> background = 47 | new Dec>( 48 | "[(a FilledRectanglePaint primaryColor=(a Color r=200.0 g=200.0 b=200.0) secondaryColor=(a Color r=220.0 g=220.0 b=220.0))]"); 49 | 50 | public static final Dec> children = new Dec>( 51 | "[" + 52 | "(a Label text=\"View of \")" + 53 | "(a Label text=(model getType).name font=(this getStyle).boldFont)" + 54 | "]" 55 | 56 | ); 57 | 58 | public NoTranslatorView(ArgumentList arguments) { super(arguments); } 59 | 60 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/ArgumentList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | import java.util.LinkedList; 27 | 28 | public class ArgumentList { 29 | 30 | public Element enclosingEnvironment = null; 31 | public LinkedList arguments = new LinkedList(); 32 | 33 | public ArgumentList(Argument ... args) { 34 | 35 | for(Argument arg : args) arguments.add(arg); 36 | 37 | } 38 | 39 | public void add(Text name, boolean isConstraint, Element value) { 40 | 41 | arguments.add(new Argument(name, isConstraint, value)); 42 | 43 | } 44 | public void add(String name, boolean isConstraint, Element value) { 45 | 46 | arguments.add(new Argument(new Text(name), isConstraint, value)); 47 | 48 | } 49 | public void add(String name, Element value) { 50 | 51 | arguments.add(new Argument(new Text(name), false, value)); 52 | 53 | } 54 | 55 | public boolean isEmpty() { return enclosingEnvironment == null && arguments.isEmpty(); } 56 | 57 | public String toString() { return arguments.toString(); } 58 | 59 | public class Argument { 60 | 61 | Text name; 62 | boolean isConstraint; 63 | Element value; 64 | 65 | public Argument(Text newName, boolean newIsConstraint, Element newValue) { 66 | 67 | name = newName; 68 | isConstraint = newIsConstraint; 69 | value = newValue; 70 | 71 | } 72 | 73 | public String toString() { return "" + name + (isConstraint ? " <- " : " = ") + value; } 74 | 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/NewList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class NewList extends Expression> { 27 | 28 | // The item expressions to be evaluated and inserted into a new list 29 | public static final BootDec>> items = new BootDec>>(new List()); 30 | 31 | public NewList() { super(); } 32 | public NewList(Namespace type, ArgumentList args) { super(type, args); } 33 | public NewList(Expression ... items) { 34 | 35 | super(); 36 | for(Expression item : items) appendItem(item); 37 | 38 | } 39 | 40 | public void appendItem(Expression item) { get(items).append(item); } 41 | 42 | public List evaluate(Element env) { 43 | 44 | List newList = new List(); 45 | 46 | // Evaluate the arguments using the current environment, putting each in the function instance's local environment. 47 | for(Element item : peek(items)) 48 | newList.append(item.evaluate(env)); 49 | 50 | // Evaluate the function using the enclosing environment (which may be null) and return its value. 51 | return newList; 52 | 53 | } 54 | 55 | public Type resultingType() { return Boot.LIST; } 56 | public Context contextFor(Element e) { return get(context); } 57 | 58 | public String toString() { 59 | 60 | String result = "[ "; 61 | for(Element e : get(items)) 62 | result = result + " " + e.toString(); 63 | result = result + " ]"; 64 | return result; 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/paints/ImagePaint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.paints; 25 | 26 | import java.awt.Graphics2D; 27 | import java.awt.Rectangle; 28 | 29 | import edu.cmu.hcii.citrus.*; 30 | import edu.cmu.hcii.citrus.views.*; 31 | 32 | public class ImagePaint extends Paint { 33 | 34 | public static final Dec image = new Dec(Images.getImage("ellen.jpg")); 35 | public static final Dec width = new Dec("(image width)"); 36 | 37 | public ImagePaint() { super(); } 38 | public ImagePaint(ArgumentList args) { super(args); } 39 | public ImagePaint(Image newImage) { super(); set(image, newImage); } 40 | 41 | public Rectangle getPaintBounds(double l, double t, double r, double b) { 42 | 43 | return new Rectangle((int)Math.floor(l) - 1, (int)Math.floor(t) - 1, (int)(r - l + 2), (int)(b - t + 2)); 44 | 45 | } 46 | 47 | public void paint(Graphics2D g, View v, double l, double t, double r, double b) { 48 | 49 | java.awt.Image img = get(image).value; 50 | double tileWidth = r - l; 51 | double tileHeight = b - t; 52 | double imageWidth = img.getWidth(null); 53 | double imageHeight = img.getHeight(null); 54 | 55 | double desiredWidth = real(width); 56 | double scaleFactor = desiredWidth / imageWidth; 57 | imageHeight *= scaleFactor; 58 | 59 | g.drawImage(img, 60 | (int)(l + (tileWidth - desiredWidth) / 2), 61 | (int)(t + (tileHeight - imageHeight) / 2), 62 | (int)desiredWidth, 63 | (int)imageHeight, 64 | null); 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Char.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class Char extends BootElement { 27 | 28 | public final char value; 29 | 30 | public Char(char newValue) { value = newValue; } 31 | 32 | public Boolean valueFromString(String s) { 33 | 34 | throw new ElementError("Not parsing chars yet.", this); 35 | 36 | } 37 | 38 | public Namespace getType() { return Boot.CHAR; } 39 | 40 | public Bool isEquivalentTo(Element e) { return new Bool(e.getType() == getType() && ((Char)e).value == value); } 41 | public Element duplicate() { return new Char(value); } 42 | 43 | public Text toCitrus() { return new Text("" + value); } 44 | public Text toCitrusReference() { return toCitrus(); } 45 | public String toString() { return "`" + value + "`"; } 46 | public Text toText() { return toCitrus(); } 47 | public Text toXML() { return toCitrus(); } 48 | public Bool isALetter() { return new Bool(Character.isLetter(value)); } 49 | 50 | 51 | public Bool isWhitespace() { return new Bool(Character.isWhitespace(value)); } 52 | public Bool isLetter() { return new Bool(Character.isLetter(value)); } 53 | public Bool isDigit() { return new Bool(Character.isDigit(value)); } 54 | public Bool isVowel() { 55 | return new Bool(value == 'a' || value == 'A' || 56 | value == 'e' || value == 'E' || 57 | value == 'i' || value == 'I' || 58 | value == 'o' || value == 'O' || 59 | value == 'u' || value == 'U'); 60 | } 61 | 62 | public Char evaluate(Element env) { return this; } 63 | 64 | } -------------------------------------------------------------------------------- /Citrus/languages/CitrusEditor/CitrusEditor.tmproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | currentDocument 6 | CitrusEditor.citrus 7 | documents 8 | 9 | 10 | filename 11 | CitrusEditor.citrus 12 | lastUsed 13 | 2005-10-23T19:20:10Z 14 | selected 15 | 16 | 17 | 18 | filename 19 | Citrus.citrus 20 | lastUsed 21 | 2005-10-23T18:35:26Z 22 | 23 | 24 | filename 25 | ToolkitViews.citrus 26 | lastUsed 27 | 2005-10-23T17:29:04Z 28 | 29 | 30 | filename 31 | LanguageViews.old 32 | lastUsed 33 | 2005-10-23T18:50:21Z 34 | 35 | 36 | fileHierarchyDrawerWidth 37 | 200 38 | metaData 39 | 40 | Citrus.citrus 41 | 42 | caret 43 | 44 | column 45 | 2 46 | line 47 | 41 48 | 49 | firstVisibleColumn 50 | 0 51 | firstVisibleLine 52 | 0 53 | 54 | CitrusEditor.citrus 55 | 56 | caret 57 | 58 | column 59 | 0 60 | line 61 | 16 62 | 63 | firstVisibleColumn 64 | 0 65 | firstVisibleLine 66 | 0 67 | 68 | LanguageViews.old 69 | 70 | caret 71 | 72 | column 73 | 0 74 | line 75 | 98 76 | 77 | firstVisibleColumn 78 | 0 79 | firstVisibleLine 80 | 59 81 | 82 | 83 | openDocuments 84 | 85 | Citrus.citrus 86 | CitrusEditor.citrus 87 | LanguageViews.old 88 | 89 | showFileHierarchyDrawer 90 | 91 | windowFrame 92 | {{505, 0}, {734, 878}} 93 | 94 | 95 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/vieweditor/LayoutView.java: -------------------------------------------------------------------------------- 1 | // Created on Feb 22, 2005 2 | 3 | package edu.cmu.hcii.citrus.vieweditor; 4 | 5 | import java.util.Hashtable; 6 | 7 | import edu.cmu.hcii.citrus.*; 8 | import edu.cmu.hcii.citrus.views.*; 9 | import edu.cmu.hcii.citrus.views.layouts.*; 10 | 11 | 12 | // 13 | // @author Andrew J. Ko 14 | // 15 | public class LayoutView extends ElementView { 16 | 17 | public static final Dec model = new Dec(); 18 | 19 | public static final Dec layout = new Dec(new HorizontalLayout(0, App.getGlobalStyle().get(Style.horizontalSpacing).value)); 20 | 21 | public static final Dec width = new Dec(View.parseExpression("(this rightmostChildsRight)")); 22 | public static final Dec height = new Dec(View.parseExpression("(this tallestChildsHeight)")); 23 | 24 | public static final Dec> background = new Dec>("[(this getStyle).lighterBackgroundPaint]"); 25 | 26 | public static final Dec vPad = new Dec(new Real(5)); 27 | public static final Dec hPad = new Dec(new Real(5)); 28 | 29 | // These were for Vertical Layout 30 | /* 31 | public static final Dec> children = new Dec>(View.children, 32 | make(Label.class, arg(Label.text, string("Vertical\nLayout")), arg(Label.font, getStyleProperty(Style.plainFont))), 33 | make(PropertyPopupMenu.class, arg(PropertyPopupMenu.property, dot(model, getProp(VerticalLayout.alignment)))), 34 | make(ParsedTextField.class, arg(ParsedTextField.model, dot(model, getProp(VerticalLayout.indentation)))), 35 | make(ParsedTextField.class, arg(ParsedTextField.model, dot(model, getProp(VerticalLayout.spacing))))); 36 | 37 | //Horizontal 38 | * 39 | public static final Dec> children = new Dec>(View.children, 40 | make(Label.class, arg(Label.text, string("Horizontal\nlayout")), arg(Label.font, getStyleProperty(Style.plainFont))), 41 | make(PropertyPopupMenu.class, arg(PropertyPopupMenu.property, dot(model, getProp(HorizontalLayout.alignment)))), 42 | make(ParsedTextField.class, arg(ParsedTextField.model, dot(model, getProp(HorizontalLayout.spacing))))); 43 | 44 | public static final Dec> children = new Dec>(View.children, 45 | make(Label.class, arg(Label.text, string("Horizontal\ntabbed layout")), arg(Label.font, getStyleProperty(Style.plainFont))), 46 | make(ParsedTextField.class, arg(ParsedTextField.model, dot(model, getProp(HorizontalTabbedLayout.spacing))))); 47 | 48 | */ 49 | 50 | public LayoutView(ArgumentList arguments) { super(arguments); } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Citrus/languages/HTML/HTML.citrus: -------------------------------------------------------------------------------- 1 | language HTML 2 | 3 | uses "edu.cmu.hcii.citrus.views" 4 | uses "edu.cmu.hcii.citrus.views.widgets" 5 | uses "edu.cmu.hcii.citrus.views.paints" 6 | uses "edu.cmu.hcii.citrus.views.layouts" 7 | uses "edu.cmu.hcii.citrus.views.devices" 8 | uses "edu.cmu.hcii.citrus.views.transitions" 9 | uses "edu.cmu.hcii.citrus.views.behaviors" 10 | 11 | an HTMLBody is a View that 12 | 13 | has List children = [] 14 | 15 | has Layout layout = (a VerticalLayout) 16 | has Real width <- 300.0 17 | has Real height <- ((this lastChildsBottom) max 20.0) 18 | has Bool clipsChildren = false 19 | . 20 | 21 | an HTMLElement is an abstract View that. 22 | 23 | a Paragraph is a HTMLElement that 24 | 25 | has Real width <- (this lastChildsRight) 26 | has Real height <- (this tallestChildsHeight) 27 | has Layout layout = (a HorizontalLayout) 28 | has Real hPad = 3.0 29 | has Real vPad = 5.0 30 | has Bool clipsChildren = false 31 | 32 | . 33 | 34 | a TextBlock is an HTMLElement that 35 | 36 | has Text text = ? 37 | has List children = [(a Label text=text)] 38 | 39 | has Real width <- (this widestChildsWidth) 40 | has Real height <- (this lastChildsBottom) 41 | has Bool clipsChildren = false 42 | 43 | . 44 | 45 | an ImageBlock is a HTMLElement that 46 | 47 | has Text imageName = ? 48 | has Image image = (this getImage imageName) 49 | has Real width <- (image width) 50 | has Real height <- ((width divide (image width)) times (image height)) 51 | 52 | has List content = [(an ImagePaint width=width image=image)] 53 | 54 | . 55 | 56 | a Center is a HTMLElement that 57 | 58 | has Layout layout = (a VerticalLayout alignment="centered") 59 | has Real width <- (this parentsWidth) 60 | has Real height <- (this lastChildsBottom) 61 | 62 | . 63 | 64 | an Anchor is an HTMLElement that 65 | 66 | has Text text = ? 67 | has Real width <- (this rightmostChildsRight) 68 | has Real height <- (this lastChildsBottom) 69 | has static Color linkColor = (a Color r=0.0 b=255.0 g=0.0) 70 | has List children = [(a Label color=Anchor.linkColor text=text)] 71 | has List foreground = [(a LinePaint x1=0.0 x2=1.0 y1=1.0 y2=1.0 primaryColor=Anchor.linkColor)] 72 | . 73 | 74 | a JavaBlock is an HTMLElement that 75 | 76 | has Element java = ? 77 | 78 | has Real width <- (this lastChildsRight) 79 | has Real height <- (this lastChildsBottom) 80 | has List children = [ (@java toView) ] 81 | has Real hPad = 2.0 82 | has Real vPad = 2.0 83 | 84 | has List background = [ 85 | (a FilledRectanglePaint primaryColor = (a Color r=220.0 g=220.0 b=220.0)) 86 | ] 87 | 88 | . 89 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/CharLiteral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class CharLiteral extends Expression { 27 | 28 | // Restricted in Boot.java 29 | public static final Dec token = new Dec(new Text(" ")); 30 | 31 | public static final Dec value = new Dec(true, new BaseElement() { 32 | public Char evaluate(Element env) { 33 | 34 | String tok = env.get(token).value; 35 | if(tok.equals("")) return new Char((char)0); 36 | else if(tok.startsWith("\\")) { 37 | char second = tok.charAt(1); 38 | if(second == 'b') return new Char('\b'); 39 | else if(second == 'n') return new Char('\n'); 40 | else if(second == 't') return new Char('\t'); 41 | else if(second == '`') return new Char('`'); 42 | else if(second == 'u') { 43 | 44 | tok = tok.substring(2); 45 | System.err.println("Not parsing hexidecimal " + tok + " to unicode!"); 46 | return new Char('\uFFFF'); 47 | 48 | } 49 | else throw new ElementError("Ellegal escape code for character " + tok, null); 50 | 51 | } 52 | else return new Char(tok.charAt(0)); 53 | 54 | } 55 | }); 56 | 57 | public CharLiteral() {} 58 | public CharLiteral(ArgumentList args) { super(args); } 59 | public CharLiteral(String value) { set(token, new Text(value)); } 60 | 61 | public Char evaluate(Element env) { return peek(value); } 62 | 63 | public Type resultingType() { return Boot.CHAR; } 64 | 65 | public Text toCitrus() { return get(value).toCitrus(); } 66 | public String toString() { return get(value).toString(); } 67 | 68 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/behaviors/Moveable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.behaviors; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.*; 28 | 29 | public class Moveable extends Behavior { 30 | 31 | public static final Dec> behaviors = new Dec>(new List( 32 | 33 | new Behavior(App.mouse.leftButton.pressed, new Action() { public boolean evaluate(View t) { 34 | App.mouse.pointer.pick.evaluate(t); 35 | return true; 36 | }}), 37 | 38 | new Behavior(App.mouse.pointer.dragged, new Action() { public boolean evaluate(View t) { 39 | if(App.mouse.pointer.isPicked(t)) { 40 | java.awt.geom.Point2D p = App.mouse.pointer.positionRelativeToPointPicked(); 41 | t.set(View.left, new Real(p.getX())); 42 | t.set(View.top, new Real(p.getY())); 43 | return true; 44 | } 45 | else return false; 46 | }}), 47 | 48 | new Behavior(App.mouse.leftButton.released, new Action() { public boolean evaluate(View t) { 49 | if(App.mouse.pointer.getViewPicked() == t) { 50 | App.mouse.pointer.release.evaluate(t); 51 | return true; 52 | } else return false; 53 | }}), 54 | 55 | new Behavior(App.mouse.pointer.picked, new Action() { public boolean evaluate(View t) { 56 | t.addBackgroundPaint(App.getGlobalStyle().getDragShadow()); 57 | return true; 58 | }}), 59 | 60 | new Behavior(App.mouse.pointer.released, new Action() { public boolean evaluate(View t) { 61 | t.set(View.hoisted, new Bool(false)); 62 | t.removeBackgroundPaint(App.getGlobalStyle().getDragShadow()); 63 | return true; 64 | }}) 65 | 66 | )); 67 | 68 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Possessive.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class Possessive extends Expression { 27 | 28 | public static final Dec> possessor = new Dec>(); 29 | public static final Dec peek = new Dec(); 30 | public static final Dec> possession = new Dec>(); 31 | 32 | public Possessive() {} 33 | public Possessive(ArgumentList args) { super(args); } 34 | public Possessive(Element or, Element ion, Bool newPeek) { 35 | 36 | set(possessor, or); 37 | set(possession, ion); 38 | set(peek, newPeek); 39 | 40 | } 41 | 42 | public TypeOfPossession evaluate(Element env) { 43 | 44 | Element or = peek(possessor).evaluate(env); 45 | if(or == null) { 46 | throw new NullPointerException("The possessor expression " + peek(possessor) + " evaluated to " + 47 | or + " in the context of " + env + " while executing " + this); 48 | } 49 | 50 | TypeOfPossession ion = (TypeOfPossession)peek(possession).evaluate(or); 51 | return ion; 52 | 53 | } 54 | 55 | public Context contextFor(Element e) { 56 | 57 | if(peek(possessor) == e) return get(context); 58 | else if(peek(possession) == e) return peek(possessor).resultingType(); 59 | else return null; 60 | 61 | } 62 | 63 | public Type resultingType() { return get(possession).resultingType(); } 64 | 65 | public String toString() { return "" + peek(possessor) + "." + peek(possession); } 66 | public Text toCitrus() { return new Text("" + peek(possessor).toCitrus() + "." + peek(possession).toCitrus()); } 67 | 68 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/vieweditor/ViewSelection.java: -------------------------------------------------------------------------------- 1 | // Created on Mar 7, 2005 2 | 3 | package edu.cmu.hcii.citrus.vieweditor; 4 | 5 | import java.util.Hashtable; 6 | 7 | import edu.cmu.hcii.citrus.*; 8 | import edu.cmu.hcii.citrus.views.*; 9 | import edu.cmu.hcii.citrus.views.paints.RectanglePaint; 10 | 11 | // 12 | // @author Andrew J. Ko 13 | // 14 | public class ViewSelection extends View { 15 | 16 | public static final Dec selection = new Dec((Element)null, true); 17 | 18 | public static final Dec left = 19 | new Dec(true, new BaseElement() { 20 | public Real evaluate(Element env) { 21 | View sel = env.get(selection); 22 | if(sel == null) return new Real(0.0); 23 | else { 24 | System.err.println("Selection's left is " + sel.get(left)); 25 | return sel.get(left); 26 | } 27 | } 28 | }); 29 | 30 | public static final Dec top = 31 | new Dec(true, new BaseElement() { 32 | public Real evaluate(Element env) { 33 | View sel = env.get(selection); 34 | if(sel == null) return new Real(0.0); 35 | else return sel.get(top); 36 | } 37 | }); 38 | 39 | public static final Dec width = 40 | new Dec(true, new BaseElement() { 41 | public Real evaluate(Element env) { 42 | View sel = env.get(selection); 43 | if(sel == null) return new Real(0.0); 44 | else { 45 | System.err.println("Selection's width is " + sel.get(width)); 46 | return sel.get(width); 47 | } 48 | } 49 | }); 50 | 51 | public static final Dec height = 52 | new Dec(true, new BaseElement() { 53 | public Real evaluate(Element env) { 54 | View sel = env.get(selection); 55 | if(sel == null) return new Real(0.0); 56 | else { 57 | System.err.println("Selection's height is " + sel.get(height)); 58 | return sel.get(height); 59 | } 60 | } 61 | }); 62 | 63 | public final Listener selectionListener = new ListenerAdapter() { 64 | public void changed(Property p, Transition t, Element oldValue, Element newValue) { 65 | System.err.println("New value is " + newValue); 66 | if(newValue instanceof Namespace) set(selection, (View)ViewSelection.this.getParent().getFirstChildOfType((Namespace)newValue)); 67 | else set(selection, null); 68 | System.err.println("Selection is " + get(selection)); 69 | } 70 | }; 71 | 72 | public static final Dec> background = new Dec>(new NewList( 73 | new RectanglePaint(Color.blue, 0.8, 2.0, 0, 0, 0, 0, 0, 0))); 74 | 75 | public static final Dec focusable = new Dec(new Bool(false)); 76 | 77 | public ViewSelection(ArgumentList arguments) { super(arguments); } 78 | 79 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/BootTypeExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class BootTypeExpression extends BootElement implements TypeExpression { 27 | 28 | public Type type = Boot.ELEMENT; 29 | public List arguments = new List(); 30 | 31 | public BootTypeExpression() {} 32 | public BootTypeExpression(Type newType, TypeExpression ... newTypeVariables) { 33 | 34 | type = newType; 35 | for(TypeExpression t : newTypeVariables) arguments.append(t); 36 | 37 | } 38 | 39 | // TYPE EXPRESSION INTERFACE 40 | public Type getBaseType() { return type; } 41 | public Text getBaseTypeName() { return new Text(type.getName()); } 42 | public List getTypeArguments() { return arguments; } 43 | public Bool canBeAssignedA(Namespace t) { return t.isTypeOf(type); } 44 | 45 | // TYPE 46 | public Namespace getType() { return Boot.TYPE_EXPRESSION; } 47 | 48 | // EQUIVALENCE 49 | public Bool isEquivalentTo(Element o) { 50 | 51 | if(!(o instanceof TypeExpression)) return new Bool(false); 52 | else return new Bool(false); 53 | 54 | } 55 | 56 | // DUPLICATION 57 | public Element duplicate() { return new BaseTypeExpression(type, arguments); } 58 | 59 | // TRANSLATION 60 | public Text toCitrus() { 61 | String str = "" + type; 62 | if(!arguments.isEmpty().value) str = str + "<"; 63 | for(TypeExpression t : arguments) str = str + t.toCitrus() + " "; 64 | if(!arguments.isEmpty().value) str = str.trim() + ">"; 65 | return new Text(str); 66 | } 67 | public Text toCitrusReference() { return toCitrus(); } 68 | public String toString() { return toCitrus().value; } 69 | 70 | // EVALUATION 71 | public TypeExpression evaluate(Element env) { return this; } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/paints/PaintPaint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.paints; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.*; 28 | 29 | import java.awt.Graphics2D; 30 | import java.awt.geom.Rectangle2D; 31 | 32 | // Paints a list of paints. 33 | public class PaintPaint extends Paint { 34 | 35 | public static final Dec> paint = new Dec>(new NewList()); 36 | 37 | public PaintPaint() {} 38 | public PaintPaint(Namespace type, ArgumentList args) { super(type, args); } 39 | public PaintPaint(Paint ... paints) { for(Paint p : paints) get(paint).append(p); } 40 | 41 | public PaintPaint addPaint(Paint p) { 42 | 43 | if(p == this) throw new ViewError("Can't add a PaintPaint to itself"); 44 | else if (p == null) throw new ViewError("Can't add null to a PaintPaint"); 45 | get(paint).append(p); 46 | return this; 47 | 48 | } 49 | 50 | // Add the paint of all of the paints. 51 | public Rectangle2D getPaintBounds(double l, double t, double r, double b) { 52 | 53 | Rectangle2D area = null; 54 | Rectangle2D temp = null; 55 | for(Paint p : get(paint)) { 56 | temp = p.getPaintBounds(l, t, r, b); 57 | if(area == null) area = temp; 58 | else area.add(temp); 59 | } 60 | if(area == null) return new Rectangle2D.Double(); 61 | else return area; 62 | 63 | } 64 | 65 | // Paint the paints in order 66 | public void paint(Graphics2D g, View v, double l, double t, double r, double b) { 67 | 68 | for(Paint p : get(paint)) 69 | p.paint(g, v, l, t, r, b); 70 | 71 | } 72 | 73 | public int hashCode(View v, double l, double t, double r, double b) { 74 | 75 | int code = super.hashCode(v, l, t, r, b); 76 | for(Paint p : get(paint)) code = code * 31 + p.hashCode(v, l, t, r, b); 77 | return code; 78 | 79 | } 80 | 81 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/Rectangle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import java.awt.geom.Rectangle2D; 27 | 28 | import edu.cmu.hcii.citrus.*; 29 | 30 | public class Rectangle extends BootElement { 31 | 32 | public final Rectangle2D value; 33 | 34 | public Rectangle(double x, double y, double w, double h) { value = new Rectangle2D.Double(x, y, w, h); } 35 | 36 | public Rectangle evaluate(Element env) { return this; } 37 | 38 | public Rectangle duplicate() { return new Rectangle(value.getX(), value.getY(), value.getWidth(), value.getHeight()); } 39 | 40 | public Text toCitrus() { return new Text(value.toString()); } 41 | public String toString() { return value.toString(); } 42 | 43 | // Returns a linear interpolation between the start and end transforms. 44 | public Rectangle getTransitionalValue(Transition t, Rectangle start, Rectangle end, long currentTime) { 45 | 46 | // Recover the attributes of the start transform. 47 | double startX = start.value.getX(); 48 | double startY = start.value.getY(); 49 | double startW = start.value.getWidth(); 50 | double startH = start.value.getHeight(); 51 | 52 | // Recover the attributes of the end transform. 53 | double endX = end.value.getX(); 54 | double endY = end.value.getY(); 55 | double endW = end.value.getWidth(); 56 | double endH = end.value.getHeight(); 57 | 58 | // Find the transitional values using the transition. 59 | double x = t.value(currentTime, startX, endX); 60 | double y = t.value(currentTime, startY, endY); 61 | double w = t.value(currentTime, startW, endW); 62 | double h = t.value(currentTime, startH, endH); 63 | 64 | return new Rectangle(x, y, w, h); 65 | 66 | } 67 | 68 | public Bool isEquivalentTo(Element o) { return new Bool(o instanceof Rectangle && ((Rectangle)o).value.equals(value)); } 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/AnimateInOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | 28 | public class AnimateInOrder extends AnimationStatement { 29 | 30 | public static final Dec> statements = new Dec>(new NewList()); 31 | 32 | // Runtime state 33 | private AnimationStatement statementAnimating = null; 34 | private int index = 1; 35 | 36 | public AnimateInOrder() {} 37 | public AnimateInOrder(Namespace subType, ArgumentList args) { super(subType, args); } 38 | 39 | public boolean startAnimating(Element context) { 40 | 41 | index = 1; 42 | return false; 43 | 44 | } 45 | 46 | public boolean doneAnimating(Element context) { 47 | 48 | // If we have no more statements, we're done. 49 | if(index > get(statements).length().value) return true; 50 | 51 | // If there's no statement animating, get one from the current index 52 | // and start it. 53 | if(statementAnimating == null) { 54 | statementAnimating = get(statements).nth(new Int(index)); 55 | statementAnimating.startAnimating(context); 56 | } 57 | // Otherwise, if the statement we're waiting on is done, proceed to the next. 58 | else if(statementAnimating.doneAnimating(context)) { 59 | 60 | // debug("Done animating " + statementAnimating); 61 | 62 | index++; 63 | 64 | // If that was the last statement, nullify the statement animating. 65 | if(index > get(statements).length().value) statementAnimating = null; 66 | // Otherwise, start the next one. 67 | else { 68 | 69 | statementAnimating = get(statements).nth(new Int(index)); 70 | statementAnimating.startAnimating(context); 71 | 72 | } 73 | 74 | } 75 | 76 | // Done animating if we're at the end of the list. 77 | return index > get(statements).length().value; 78 | 79 | } 80 | 81 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Real.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | import edu.cmu.hcii.citrus.views.Transition; 27 | 28 | public class Real extends BootElement implements Comparable { 29 | 30 | public final double value; 31 | 32 | public Real(double newValue) { value = newValue; } 33 | 34 | public Real evaluate(Element env) { return this; } 35 | public Namespace getType() { return Boot.REAL; } 36 | public Element duplicate() { return new Real(value); } 37 | public String toString() { return "" + value; } 38 | public Text toCitrus() { return new Text("" + value); } 39 | public Text toCitrusReference() { return toCitrus(); } 40 | 41 | public Real plus(Real operand) { return new Real(value + operand.value); } 42 | public Real minus(Real operand) { return new Real(value - operand.value); } 43 | public Real times(Real operand) { return new Real(value * operand.value); } 44 | public Real divide(Real operand) { return new Real(value / operand.value); } 45 | 46 | public Bool greaterThan(Real operand) { return new Bool(value > operand.value); } 47 | public Bool greaterThanOrEqualTo(Real operand) { return new Bool(value >= operand.value); } 48 | public Bool lessThan(Real operand) { return new Bool(value < operand.value); } 49 | 50 | public Real inc() { return new Real(value + 1.0); } 51 | public Real dec() { return new Real(value - 1.0); } 52 | 53 | public Real min(Real r) { return value < r.value ? this : r; } 54 | public Real max(Real r) { return value > r.value ? this : r; } 55 | public Real abs() { return value < 0 ? this : new Real(-value); } 56 | 57 | public Real getTransitionalValue(Transition t, Real start, Real end, long time) { 58 | 59 | return new Real(t.value(time, start.value, end.value)); 60 | 61 | } 62 | 63 | public int compareTo(Real i) { return value < i.value ? -1 : value > i.value ? 1 : 0; } 64 | 65 | public Bool isEquivalentTo(Element o) { return new Bool(o instanceof Real && ((Real)o).value == value); } 66 | 67 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/paints/EllipsePaint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.paints; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.*; 28 | 29 | import java.awt.AlphaComposite; 30 | import java.awt.Graphics2D; 31 | import java.awt.Rectangle; 32 | 33 | public class EllipsePaint extends Paint { 34 | 35 | public EllipsePaint(ArgumentList args) { super(args); } 36 | public EllipsePaint(Color newColor, 37 | double newAlpha, 38 | double l, double t, 39 | double r, double b) { 40 | 41 | super(newColor, newColor, newAlpha, l, t, r, b); 42 | 43 | } 44 | 45 | // Paints the tile's padded bounds 46 | public Rectangle getPaintBounds(double l, double t, double r, double b) { 47 | 48 | return new Rectangle(getLeft(l, r), getTop(t, b), getWidth(l, r) + 1, getHeight(t, b) + 1); 49 | 50 | } 51 | 52 | private int getLeft(double l, double r) { return (int)(l + getVisible(left) * (r - l)); } 53 | private int getTop(double t, double b) { return (int)(t + getVisible(top) * (b - t)); } 54 | private int getWidth(double l, double r) { return (int)(((r - l) - 1) * (1.0 - Math.abs(getVisible(right) + getVisible(left)))); } 55 | private int getHeight(double t, double b) { return (int)(((b - t) - 1) * (1.0 - Math.abs(getVisible(top) + getVisible(bottom)))); } 56 | 57 | public void paint(Graphics2D g, View v, double l, double t, double r, double b) { 58 | 59 | java.awt.Color oldColor = g.getColor(); 60 | AlphaComposite oldComposite = (AlphaComposite)g.getComposite(); 61 | 62 | int left, top, width, height; 63 | 64 | left = getLeft(l, r); 65 | top = getTop(t, b); 66 | width = getWidth(l, r); 67 | height = getHeight(t, b); 68 | 69 | g.setColor(get(primaryColor).getVisibleColor()); 70 | g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)getVisible(alpha) * oldComposite.getAlpha())); 71 | 72 | g.fillOval(left, top, width, height); 73 | 74 | g.setComposite(oldComposite); 75 | g.setColor(oldColor); 76 | 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/widgets/MenuItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.widgets; 25 | 26 | import edu.cmu.hcii.citrus.*; 27 | import edu.cmu.hcii.citrus.views.*; 28 | 29 | //////////////////////////////////////////// 30 | // 31 | // A widget with an arbitrary label and an 32 | // associated action. The label is the only child. 33 | // Performs an action when clicked. 34 | // 35 | //////////////////////////////////////////// 36 | public class MenuItem extends View { 37 | 38 | public static final Dec width = new Dec("(this parentsWidth)"); 39 | public static final Dec height = new Dec("(this tallestChildsHeight)"); 40 | public static final Dec vPad = new Dec("5.0"); 41 | public static final Dec hPad = new Dec("5.0"); 42 | public static final Dec> background = new Dec>("(this getStyle).menuItemPaint)"); 43 | public static final Dec action = new Dec(new Parameter()); 44 | 45 | public static final Dec> behaviors = new Dec>(new List( 46 | new Behavior(App.mouse.pointer.entered, new Action() { public boolean evaluate(View t) { 47 | t.removeBackgroundPaint(App.getGlobalStyle().getMenuItemPaint()); 48 | t.addBackgroundPaint(App.getGlobalStyle().getOverMenuItemPaint()); 49 | return true; 50 | }}), 51 | new Behavior(App.mouse.pointer.exited, new Action() { public boolean evaluate(View t) { 52 | t.removeBackgroundPaint(App.getGlobalStyle().getOverMenuItemPaint()); 53 | t.addBackgroundPaint(App.getGlobalStyle().getMenuItemPaint()); 54 | return true; 55 | }}), 56 | new Behavior(App.mouse.leftButton.released, new Action() { public boolean evaluate(View t) { 57 | if(t.get(action) != null) t.get(action).evaluate(t); 58 | return false; 59 | }}) 60 | )); 61 | 62 | private Object value; 63 | 64 | public MenuItem(View newLabel, Object value, Action newAction) { 65 | 66 | super(); 67 | 68 | this.value = value; 69 | 70 | addChild(newLabel); 71 | newLabel.moveTo(0, 0); 72 | 73 | } 74 | 75 | public Object getValue() { return value; } 76 | 77 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/When.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class When extends BaseElement implements Context { 27 | 28 | // The name of the event in the handler 29 | public static final BootDec name = new BootDec(new Text("")); 30 | 31 | // The subject expression, which evaluates to the element to listen to. 32 | public static final BootDec subjectExpression = new BootDec(null); 33 | 34 | // The event expression, which evaluates to the type of event to watch for. 35 | public static final BootDec eventExpression = new BootDec(null); 36 | 37 | // The code that should be executed when the event occurs. 38 | public static final BootDec response = new BootDec(null); 39 | 40 | // The arguments sent to the function 41 | public static final BootDec> arguments = new BootDec>(new List()); 42 | 43 | public final List declarations = new List(); 44 | 45 | public When(Text newName) { 46 | 47 | super(); 48 | 49 | Dec eventDeclaration = new Dec(false, new Nothing()); 50 | eventDeclaration.set(Dec.name, newName); 51 | set(name, newName); 52 | declarations.append(eventDeclaration); 53 | 54 | } 55 | 56 | public Text toCitrus() { return new Text("Haven't implemented When.toCitrus()"); } 57 | public String toString() { 58 | return "when " + 59 | peek(name) + 60 | " (" + 61 | peek(subjectExpression) + " " + 62 | peek(eventExpression) + " " + 63 | peek(arguments) + " " + 64 | peek(response); 65 | } 66 | 67 | public Set getDeclarationsInContext(Set names) { return names; } 68 | public Set getTypesInContext(Set names) { return names; } 69 | public Set getFunctionsInContext(Set functions) { return functions; } 70 | public DecInterface getDeclarationOf(Text name) { return null; } 71 | public Type getTypeNamed(String name) { return ((Type)ownerOfType(Boot.TYPE)).getTypeNamed(name); } 72 | public Function getFunctionNamed(Text name, Bool isStatic) { return ((Type)ownerOfType(Boot.TYPE)).getFunctionNamed(name, isStatic); } 73 | 74 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/paints/GridPaint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.paints; 25 | 26 | import java.awt.AlphaComposite; 27 | import java.awt.BasicStroke; 28 | import java.awt.Graphics2D; 29 | import java.awt.Rectangle; 30 | import java.awt.Stroke; 31 | 32 | import edu.cmu.hcii.citrus.*; 33 | import edu.cmu.hcii.citrus.views.*; 34 | 35 | 36 | public class GridPaint extends Paint { 37 | 38 | public static final Dec step = new Dec(new Real(5.0)); 39 | 40 | public GridPaint(ArgumentList arguments) { super(arguments); } 41 | public GridPaint(Color newColor, double newAlpha, double newStepSize) { 42 | 43 | super(newColor, newColor, newAlpha, 0, 0, 0, 0); 44 | set(step, new Real(newStepSize)); 45 | 46 | } 47 | 48 | // Paints the tile's padded bounds 49 | public Rectangle getPaintBounds(double l, double t, double r, double b) { return new Rectangle((int)l, (int)t, (int)(r - l), (int)(b - r)); } 50 | 51 | public void paint(Graphics2D g, View v, double l, double t, double r, double b) { 52 | 53 | java.awt.Color oldColor = g.getColor(); 54 | AlphaComposite oldComposite = (AlphaComposite)g.getComposite(); 55 | Stroke oldStroke = g.getStroke(); 56 | 57 | // Set the stroke 58 | g.setStroke(new BasicStroke(1.0f, java.awt.BasicStroke.CAP_BUTT, java.awt.BasicStroke.JOIN_MITER)); 59 | g.setColor(get(primaryColor).getVisibleColor()); 60 | g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)getVisible(alpha) * oldComposite.getAlpha())); 61 | 62 | int xOff = 0;//-(int)g.getTransform().getTranslateX(); 63 | int yOff = 0;//(int)g.getTransform().getTranslateY(); 64 | 65 | int top = (int)t + yOff; 66 | int bottom = (int)b + yOff; 67 | int left = (int)l + xOff; 68 | int right = (int)r + xOff; 69 | int stepInt = (int)getVisible(step); 70 | 71 | for(double x = left; x < right; x += stepInt) 72 | g.drawLine((int)x, top, (int)x, bottom); 73 | for(double y = top; y < bottom; y += stepInt) 74 | g.drawLine(left, (int)y, right, (int)y); 75 | 76 | g.setComposite(oldComposite); 77 | g.setColor(oldColor); 78 | g.setStroke(oldStroke); 79 | 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /Citrus/languages/Widgets/Palette.citrus: -------------------------------------------------------------------------------- 1 | language Widgets 2 | 3 | uses "edu.cmu.hcii.citrus.views" 4 | uses "edu.cmu.hcii.citrus.views.widgets" 5 | uses "edu.cmu.hcii.citrus.views.layouts" 6 | uses "edu.cmu.hcii.citrus.views.devices" 7 | uses "edu.cmu.hcii.citrus.views.paints" 8 | uses "edu.cmu.hcii.citrus.views.transitions" 9 | 10 | a Palette is a View that 11 | 12 | has Text name = ? 13 | 14 | has Real width <- (this parentsWidth) 15 | has Real height <- (if collapsed ((children first) paddedHeight) (this lastChildsBottom)) 16 | has Layout layout = (a VerticalLayout spacing=5.0) 17 | 18 | has Bool collapsed = false 19 | 20 | refs View contents = ? 21 | 22 | has List children = [ (a Header) contents ] 23 | has Real vPad = 5.0 24 | has Real hPad = 5.0 25 | 26 | a Header is a View that 27 | 28 | has Real width <- (this parentsWidth) 29 | has Real height <- ((children last) paddedHeight) 30 | 31 | has static FontFace headerFont = (a FontFace family="Arial" size=16.0) 32 | 33 | has List children = [ 34 | (a RightArrow) 35 | (a DownArrow) 36 | (a Label text=name font=Header.headerFont left=15.0) 37 | ] 38 | 39 | # has List background = [ 40 | # (a FilledRectanglePaint 41 | # primaryColor=(this getStyle).lightJavaColor 42 | # secondaryColor=(this getStyle).darkJavaColor 43 | # ) 44 | # ] 45 | 46 | has List behaviors = [ 47 | (a Behavior event=(a MouseButton.Clicked) action= 48 | '(@collapsed set (collapsed not) (a Uniform duration=200.0)) 49 | ) 50 | ] 51 | 52 | . 53 | 54 | a RightArrow is a View that 55 | 56 | has static List rightArrow = [ 57 | (a PolygonPaint 58 | primaryColor=(a Color r=0.0 g=0.0 b=0.0) 59 | points=[(a Point x=0.0 y=0.0) (a Point x=0.0 y=1.0) (a Point x=1.0 y=0.5)] 60 | ) 61 | ] 62 | 63 | has Real width = 10.0 64 | has Real height = 10.0 65 | has Real top <- (((this parentsHeight) minus height) divide 2.0) 66 | has List foreground = RightArrow.rightArrow 67 | has Bool hidden <- (collapsed not) 68 | 69 | . 70 | 71 | a DownArrow is a View that 72 | 73 | has static List downArrow = [ 74 | (a PolygonPaint 75 | primaryColor=(a Color r=0.0 g=0.0 b=0.0) 76 | points=[(a Point x=0.0 y=0.0) (a Point x=1.0 y=0.0) (a Point x=0.5 y=1.0)] 77 | ) 78 | ] 79 | 80 | has Real width = 10.0 81 | has Real height = 10.0 82 | has Real top <- (((this parentsHeight) minus height) divide 2.0) 83 | has List foreground = DownArrow.downArrow 84 | has Bool hidden <- collapsed 85 | 86 | . 87 | 88 | . 89 | 90 | a PaletteList is a View that 91 | 92 | has Real width <- 93 | (do 94 | refs Real widestContentWidth = 0.0 95 | (children foreach 96 | (fun [ refs Palette palette ] 97 | (@widestContentWidth set 98 | (widestContentWidth max 99 | (palette.contents paddedWidth) 100 | ((palette.children first) lastChildsRight))))) 101 | widestContentWidth 102 | ) 103 | 104 | has Real height <- (this parentsHeight) 105 | has Layout layout = (a VerticalLayout) 106 | has Bool clipsChildren = false 107 | 108 | . 109 | 110 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/Closure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus; 25 | 26 | public class Closure extends BaseElement implements Function { 27 | 28 | private final Function fun; 29 | private final Element env; 30 | 31 | public Closure(Function fun, Element environment) { 32 | 33 | this.fun = fun; 34 | this.env = environment; 35 | 36 | } 37 | 38 | public Element instantiate(ArgumentList args) { 39 | 40 | // Create an instance of this namespace using the given arguments, and 41 | // return the evaluation of this function's expression in this namespace. 42 | Element expr = fun.getExpression(); 43 | args.enclosingEnvironment = env; 44 | Element env = new BaseElement(fun, args); 45 | 46 | // We don't do lazy evaluation for functions. 47 | for(DecInterface dec : getDeclarationsToInstantiate()) 48 | env.get(dec); 49 | 50 | Element result = expr.evaluate(env); 51 | 52 | return result; 53 | 54 | } 55 | 56 | public Function getFunction() { return fun; } 57 | public Element getExpression() { return fun.getExpression(); } 58 | 59 | public Iterable getDeclarationsToInstantiate() { return fun.getDeclarationsToInstantiate(); } 60 | public Iterable getDeclarationsDeclared() { return fun.getDeclarationsDeclared(); } 61 | public String getName() { return fun.getName(); } 62 | public String toString() { return "fun " + getName(); } 63 | public Bool isTypeOf(Namespace t) { return new Bool(t == this); } 64 | public Language getLanguage() { return fun.getLanguage(); } 65 | public int getNumberOfDeclarations() { return fun.getNumberOfDeclarations(); } 66 | public DecInterface getDeclarationOf(Text name) { return fun.getDeclarationOf(name); } 67 | public Type getTypeNamed(String name) { return fun.getTypeNamed(name); } 68 | public Function getFunctionNamed(Text name, Bool isStatic) { return fun.getFunctionNamed(name, isStatic); } 69 | public Set getDeclarationsInContext(Set names) { return fun.getDeclarationsInContext(names); } 70 | public Set getTypesInContext(Set names) { return fun.getTypesInContext(names); } 71 | public Set getFunctionsInContext(Set functions) { return fun.getFunctionsInContext(functions); } 72 | public boolean isStatic() { return fun.isStatic(); } 73 | 74 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/layouts/HorizontalLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.layouts; 25 | 26 | 27 | import edu.cmu.hcii.citrus.*; 28 | import edu.cmu.hcii.citrus.views.Layout; 29 | import edu.cmu.hcii.citrus.views.View; 30 | 31 | public class HorizontalLayout extends Layout { 32 | 33 | public static final Text TOP = new Text("top-aligned"); 34 | public static final Text CENTERED = new Text("vertically-centered"); 35 | public static final Text BOTTOM = new Text("bottom-aligned"); 36 | 37 | public static final Dec alignment = new Dec(CENTERED); 38 | public static final Dec spacing = new Dec(new Real(0.0)); 39 | 40 | static { 41 | alignment.is(new PropertyRestriction("(alignment matches \"top-aligned|vertically-centered|bottom-aligned\")", null)); 42 | } 43 | 44 | public HorizontalLayout(Namespace type, ArgumentList args) { super(type, args); } 45 | public HorizontalLayout(int newAlignment, double newSpacing) { 46 | 47 | super(null); 48 | set(alignment, newAlignment == -1 ? TOP : newAlignment == 0 ? CENTERED : BOTTOM); 49 | set(spacing, new Real(newSpacing)); 50 | 51 | } 52 | 53 | // TODO: This should constrain the spacing, not set it. 54 | public HorizontalLayout(int newAlignment, Expression newSpacing) { 55 | 56 | super(null); 57 | set(alignment, newAlignment == -1 ? TOP : newAlignment == 0 ? CENTERED : BOTTOM); 58 | set(spacing, newSpacing.evaluate(null)); 59 | 60 | } 61 | 62 | // Return 0 if this is the first child, and the previous child's right + spacing for the rest. 63 | public Real getLeft(View child) { 64 | 65 | return child.getPreviousSibling() == null ? new Real(0.0) : 66 | child.getPreviousSibling().get(View.right).plus(peek(spacing)); 67 | 68 | } 69 | 70 | // Depends on the alignment. 71 | public Real getTop(View child) { 72 | 73 | Text align = peek(alignment); 74 | if(align.equals(TOP)) return new Real(0.0); 75 | else if(align.equals(BOTTOM)) return child.getParent().get(View.height).minus(child.paddedHeight()); 76 | else { 77 | View par = child.getParent(); 78 | if(par == null) return new Real(0.0); 79 | else return par.get(View.height).minus(child.paddedHeight()).divide(new Real(2.0)); 80 | } 81 | 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/Transform.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views; 25 | 26 | import java.awt.geom.AffineTransform; 27 | 28 | import edu.cmu.hcii.citrus.*; 29 | 30 | public class Transform extends BootElement { 31 | 32 | public final AffineTransform value; 33 | 34 | public Transform() { value = new AffineTransform(); } 35 | public Transform(AffineTransform at) { value = at; } 36 | 37 | public Transform evaluate(Element env) { return this; } 38 | 39 | public Transform duplicate() { return new Transform(value); } 40 | 41 | public Text toCitrus() { return new Text(value.toString()); } 42 | public String toString() { return value.toString(); } 43 | 44 | // Returns a linear interpolation between the start and end transforms. 45 | public Transform getTransitionalValue(Transition t, Transform start, Transform end, long currentTime) { 46 | 47 | if(start == null) { 48 | if(end == null) return null; 49 | else { 50 | System.err.println("Animating from nothing to " + end); 51 | return end; 52 | } 53 | 54 | } 55 | else if(end == null) { 56 | System.err.println("Animating from " + start + " to nothing"); 57 | return start; 58 | } 59 | 60 | // Recover the attributes of the start transform. 61 | double startScaleX = start.value.getScaleX(); 62 | double startScaleY = start.value.getScaleY(); 63 | double startTranslateX = start.value.getTranslateX(); 64 | double startTranslateY = start.value.getTranslateY(); 65 | 66 | // Recover the attributes of the end transform. 67 | double endScaleX = end.value.getScaleX(); 68 | double endScaleY = end.value.getScaleY(); 69 | double endTranslateX = end.value.getTranslateX(); 70 | double endTranslateY = end.value.getTranslateY(); 71 | 72 | // Find the transitional values using the transition. 73 | double scaleX = t.value(currentTime, startScaleX, endScaleX); 74 | double scaleY = t.value(currentTime, startScaleY, endScaleY); 75 | double translateX = t.value(currentTime, startTranslateX, endTranslateX); 76 | double translateY = t.value(currentTime, startTranslateY, endTranslateY); 77 | 78 | return new Transform(new AffineTransform(scaleX, 0, 0, scaleY, translateX, translateY)); 79 | 80 | } 81 | 82 | public Bool isEquivalentTo(Element o) { return new Bool(o instanceof Transform && ((Transform)o).value.equals(value)); } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/vieweditor/BehaviorView.java: -------------------------------------------------------------------------------- 1 | // Created on Feb 15, 2005 2 | 3 | package edu.cmu.hcii.citrus.vieweditor; 4 | 5 | import edu.cmu.hcii.citrus.*; 6 | import edu.cmu.hcii.citrus.views.*; 7 | import edu.cmu.hcii.citrus.views.behaviors.*; 8 | import edu.cmu.hcii.citrus.views.layouts.*; 9 | import edu.cmu.hcii.citrus.views.paints.*; 10 | 11 | // 12 | // @author Andrew J. Ko 13 | // 14 | public class BehaviorView extends ElementView { 15 | 16 | public static final Dec model = new Dec(); 17 | 18 | public static final Dec clipsChildren = new Dec(new Bool(false)); 19 | public static final Dec collapse = new Dec(new Bool(false)); 20 | 21 | public static final Dec hPad = new Dec(new Real(5)); 22 | public static final Dec vPad = new Dec(new Real(2)); 23 | 24 | public static final Dec layout = new Dec(new VerticalLayout(-1, 0, 0)); 25 | 26 | public static final Dec width = new Dec(true, new BaseElement() { public Real evaluate(Element env) { 27 | return env.get(collapse).value ? 28 | env.get(children).first().rightmostChildsRight() : 29 | ((View)env).rightmostChildsRight(); }}); 30 | 31 | public static final Dec height = new Dec(true, "(this lastChildsBottom)"); 32 | 33 | public static final Dec> background = new Dec>(new NewList( 34 | new RectanglePaint(Color.lightGrey, 0.3, 1.0, 0.0, 0.0, 0.0, 0.0, 5, 5))); 35 | 36 | public static final Dec> behaviors = new Dec>(new List( 37 | new Draggable(), 38 | new Behavior(App.keyboard.DOWN.pressed, App.keyboard.focusBelow), 39 | new Behavior(App.keyboard.UP.pressed, App.keyboard.focusAbove), 40 | new Navigable())); 41 | 42 | public static final Dec> children = new Dec>(View.>parseExpression( 43 | "[" + 44 | "(a Header)" + 45 | "(a Body)" + 46 | "]" 47 | )); 48 | 49 | public BehaviorView(ArgumentList arguments) { super(arguments); } 50 | 51 | public static class Header extends View { 52 | 53 | public static final Dec layout = new Dec(new HorizontalLayout(0, 5)); 54 | 55 | public static final Dec width = new Dec(true, "(this lastChildsRight)"); 56 | public static final Dec height = new Dec(true, "(this tallestChildsHeight)"); 57 | 58 | public static final Dec> children = new Dec>( 59 | "[" + 60 | "(a Label text=\"when\" font=(this getStyle).italicFont)" + 61 | "(model.@event toView)" + 62 | "]" 63 | ); 64 | 65 | public Header(ArgumentList arguments) { super(arguments); } 66 | 67 | } 68 | 69 | public static class Body extends View { 70 | 71 | public static final Dec hidden = new Dec("collapse"); 72 | 73 | public static final Dec layout = new Dec(new VerticalLayout(-1, 0, 5)); 74 | 75 | public static final Dec width = new Dec(true, "(this widestChildsWidth)"); 76 | public static final Dec height = new Dec(true, "(this lastChildsBottom)"); 77 | 78 | public static final Dec> children = new Dec>("[(model.@action toView)]"); 79 | 80 | public static final Dec hPad = new Dec(new Real(5)); 81 | public static final Dec vPad = new Dec(new Real(5)); 82 | 83 | public Body(ArgumentList arguments) { super(arguments); } 84 | 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /edu/cmu/hcii/citrus/views/layouts/HorizontalTabbedLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Citrus - A object-oriented, interpreted language that is designed to simplify 4 | * the creation of dynamic, immediate feedback graphical desktop applications. 5 | * 6 | * Copyright (c) 2005 Andrew Jensen Ko 7 | * All rights reserved. 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | * 23 | */ 24 | package edu.cmu.hcii.citrus.views.layouts; 25 | 26 | 27 | import edu.cmu.hcii.citrus.*; 28 | import edu.cmu.hcii.citrus.views.Layout; 29 | import edu.cmu.hcii.citrus.views.View; 30 | 31 | public class HorizontalTabbedLayout extends Layout { 32 | 33 | public static final Text TOP = new Text("top-aligned"); 34 | public static final Text CENTERED = new Text("vertically-centered"); 35 | public static final Text BOTTOM = new Text("bottom-aligned"); 36 | 37 | public static final Dec tabLength = new Dec(new Real(0.0)); 38 | public static final Dec spacing = new Dec(new Real(0.0)); 39 | public static final Dec alignment = new Dec(TOP); 40 | 41 | static { 42 | alignment.is(new PropertyRestriction("(alignment matches \"top-aligned|vertically-centered|bottom-aligned\")", null)); 43 | } 44 | 45 | public HorizontalTabbedLayout(ArgumentList args) { super(args); } 46 | public HorizontalTabbedLayout(int newAlignment, double newTabLength, double newSpacing) { 47 | 48 | super(null); 49 | set(alignment, newAlignment == -1 ? TOP : newAlignment == 0 ? CENTERED : BOTTOM); 50 | set(spacing, new Real(newSpacing)); 51 | set(tabLength, new Real(newTabLength)); 52 | 53 | } 54 | 55 | // Return 0 if this is the first child, and the previous child's right + spacing for the rest. 56 | public Real getLeft(View child) { 57 | 58 | double sp = peek(tabLength).value; 59 | 60 | // The first child is at 0. 61 | // Subsequent siblings are at the next closest interval defined by the spacing, right of the previous sibling. 62 | if(child.getPreviousSibling() == null) return new Real(0.0); 63 | else if(child.getPreviousSibling().getPreviousSibling() == null && 64 | child.getPreviousSibling().real(View.right) < sp) 65 | return new Real(sp); 66 | else return child.getPreviousSibling().get(View.right).plus(peek(spacing)); 67 | 68 | } 69 | 70 | // Depends on the alignment. 71 | public Real getTop(View child) { 72 | 73 | Text align = peek(alignment); 74 | if(align.equals(TOP)) return child.getPreviousSibling() == null ? new Real(0.0) : child.getPreviousSibling().get(View.top); 75 | else if(align.equals(BOTTOM)) return child.getParent().get(View.height).minus(child.paddedHeight()); 76 | else return child.getParent().get(View.height).minus(child.paddedHeight()).divide(new Real(2)); 77 | 78 | } 79 | 80 | public String toString() { return "Row layout"; } 81 | 82 | } --------------------------------------------------------------------------------