From 40120b1c808268f73d02bebeb7510aeda23c535a Mon Sep 17 00:00:00 2001 From: baltasarq Date: Sun, 14 Feb 2016 00:36:34 +0100 Subject: [PATCH] Single attribute is from root in assignments New icons. "os" object. DateTime objects. --- .idea/workspace.xml | 290 ++++++++++++------------------ src/core/AppInfo.java | 2 +- src/core/Interpreter.java | 1 - src/core/Parser.java | 17 +- src/core/Runtime.java | 14 ++ src/core/objs/ObjectDateTime.java | 13 -- src/res/new.png | Bin 0 -> 161 bytes src/res/reset.png | Bin 0 -> 573 bytes src/ui/Gui.java | 111 ++++++++---- 9 files changed, 216 insertions(+), 232 deletions(-) create mode 100644 src/res/new.png create mode 100644 src/res/reset.png diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 40517ea..ccecc97 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,14 +7,15 @@ - - - + + - - + + + - + + @@ -88,79 +89,11 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -198,17 +131,19 @@ @@ -251,6 +186,16 @@ + + + + + + + + @@ -269,6 +214,24 @@ + + + + + + + + + + - - - - - - - - @@ -462,17 +415,20 @@ - - - - - + + + + + + + + @@ -956,7 +912,11 @@ - + + + + + 1453802639057 @@ -968,7 +928,7 @@ - @@ -991,7 +951,7 @@ - + @@ -1004,9 +964,10 @@ - + - + + @@ -1023,7 +984,6 @@ - @@ -1046,6 +1006,7 @@ + @@ -1058,7 +1019,6 @@ - @@ -1080,7 +1040,6 @@ - @@ -1102,7 +1061,6 @@ - @@ -1124,7 +1082,6 @@ - @@ -1139,7 +1096,6 @@ - @@ -1154,7 +1110,6 @@ - @@ -1169,7 +1124,6 @@ - @@ -1289,16 +1243,6 @@ - - - - - - - - - - @@ -1314,16 +1258,6 @@ - - - - - - - - - - @@ -1348,14 +1282,6 @@ - - - - - - - - @@ -1375,14 +1301,6 @@ - - - - - - - - @@ -1391,75 +1309,97 @@ - + - - + + - + - + - + - - - + + + + + - + - - + + - + - - + + - + - + - - + + + + + + + + + + + + + + + + + + - - + + - - - + - + - - - - - + + + + + + + + + + + diff --git a/src/core/AppInfo.java b/src/core/AppInfo.java index 48c5321..1ebfd2d 100644 --- a/src/core/AppInfo.java +++ b/src/core/AppInfo.java @@ -13,7 +13,7 @@ public class AppInfo { public static final String Name = "Pooi"; public static final String Email = "jbgarcia@uvigo.es"; public static final String Author = "Baltasar GarcĂ­a Perez-Schofield"; - public static final String Version = "0.8.1 20140707"; + public static final String Version = "0.9 20160213"; public static String getMsgVersion() { diff --git a/src/core/Interpreter.java b/src/core/Interpreter.java index e9bf864..cdfd18f 100644 --- a/src/core/Interpreter.java +++ b/src/core/Interpreter.java @@ -111,7 +111,6 @@ protected ObjectBag execute(InterpretedMethod method, ObjectBag self, Evaluable[ ObjectBag toret = null; error = false; final Runtime rt = this.getRuntime(); - final ObjectRoot root = rt.getRoot(); ExecutionStack stack = new ExecutionStack(); try { diff --git a/src/core/Parser.java b/src/core/Parser.java index d252304..5e5e63a 100644 --- a/src/core/Parser.java +++ b/src/core/Parser.java @@ -171,7 +171,7 @@ private static String getMessageId(Lexer lex) /** * This method is needed in order to deal with the case in which - * you have x,a = y, meaning x set "a" y + * you have x.a = y, meaning x set "a" y * @param toret the resulting command, as a Command object. * @param lex the lexer being used to interpret the command, as a Lexer object. */ @@ -188,14 +188,15 @@ public static void extractMethod(Command toret, Lexer lex) throws InterpretError if ( evl instanceof Reference ) { final Reference ref = (Reference) evl; - if ( ref.getAttrs().length > 1 ) { - String atr = ref.top(); - - ref.pop(); - lex.insertAtCurrentPos( '"' + atr + '"' ); - } else { - throw new InterpretError( "missing attribute at the end of the reference, left of: " + Reserved.AssignmentOperator ); + // If no context provided, assume it is in root + if ( ref.getAttrs().length == 1 ) { + ref.setAttrs( new String[]{ "Root", ref.getAttrs()[ 0 ] } ); } + + String atr = ref.top(); + + ref.pop(); + lex.insertAtCurrentPos( '"' + atr + '"' ); } else { throw new InterpretError( "reference expected at left of: " + Reserved.AssignmentOperator ); } diff --git a/src/core/Runtime.java b/src/core/Runtime.java index 2ac596a..f012c9d 100644 --- a/src/core/Runtime.java +++ b/src/core/Runtime.java @@ -115,6 +115,20 @@ public void addMethodsToRuntimeObjects() throws InterpretError this.str.set( NativeMethodStrSub.EtqMthStrSub, new NativeMethodStrSub() ); this.str.set( NativeMethodStrLeft.EtqMthStrLeft, new NativeMethodStrLeft() ); this.str.set( NativeMethodStrRight.EtqMthStrRight, new NativeMethodStrRight() ); + + // DateTime + this.dateTime.set( ObjectDateTime.EtqDateAsStr, new InterpretedMethod( ObjectDateTime.EtqDateAsStr, + "( ( ( ( self." + ObjectDateTime.EtqDay + " str ) + \"-\" ) + ( self." + + ObjectDateTime.EtqMonth + " str ) ) + \"-\" ) + ( self." + + ObjectDateTime.EtqYear + " str )" ) ); + + this.dateTime.set( ObjectDateTime.EtqTimeAsStr, new InterpretedMethod( ObjectDateTime.EtqTimeAsStr, + "( ( ( ( self." + ObjectDateTime.EtqHour + " str ) + \":\" ) + ( self." + + ObjectDateTime.EtqMinute + " str ) ) + \":\" ) + ( self." + + ObjectDateTime.EtqSecond + " str )" ) ); + + this.dateTime.set( ObjectDateTime.EtqStr, new InterpretedMethod( ObjectDateTime.EtqStr, + "( ( self dateAsStr ) + \" \" ) + ( self timeAsStr )" ) ); } diff --git a/src/core/objs/ObjectDateTime.java b/src/core/objs/ObjectDateTime.java index e7a3a01..d0bef68 100644 --- a/src/core/objs/ObjectDateTime.java +++ b/src/core/objs/ObjectDateTime.java @@ -21,19 +21,6 @@ public class ObjectDateTime extends ValueObject { public ObjectDateTime(String n, ObjectBag parent, ObjectBag container) throws InterpretError { super( n, parent, container ); - - this.set( EtqDateAsStr, new InterpretedMethod( EtqDateAsStr, - "( ( ( ( self." + EtqDay + " str ) + \"-\" ) + ( self." - + EtqMonth + " str ) ) + \"-\" ) + ( self." - + EtqYear + " str )" ) ); - - this.set( EtqTimeAsStr, new InterpretedMethod( EtqTimeAsStr, - "( ( ( ( self." + EtqHour + " str ) + \":\" ) + ( self." - + EtqMinute + " str ) ) + \":\" ) + ( self." - + EtqSecond + " str )" ) ); - - this.set( EtqStr, new InterpretedMethod( EtqStr, - "( ( self dateAsStr ) + \" \" ) + ( self timeAsStr )" ) ); } @Override diff --git a/src/res/new.png b/src/res/new.png new file mode 100644 index 0000000000000000000000000000000000000000..a299de7b37956541fc20e60cb97f094634a7c909 GIT binary patch literal 161 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#VfnpR$Oq*FkFEfA^ZI+xAcA?Yb@?P)Nklr45QhIf7%~QgX)K{hxCkq98g)V!8fhrv2B+2o#4iyF z@mx+Jna0ET4G6Il+yqD$I|Vpw3W#Ga@#JsLnVo;X-Pv8>8NGU0=Ck)_{G4Y?$Htoo z06HH!5kau)cnkoJ<3@&IM4Nu`=i|DrpH64u(dcUz06@z)t=`+wEe3;6-IKQ`?0KHQ z1z_gnVg3;4y1uis`Fxff8wSqLKLS9q2Jl=jzUp7WYr2pMQm_j!{XV^r6**|w7W$Wc zxULri02-F%3rcZ%FU`8HKepECEN9@k-r5ii!|(}$Q(})T%kssy@i<^!K&xxXa5%i! z+5Zy_27?Rz^-;1|{K8~14TPp?0RY_J|4eoz?AqbokGli_G_4j0$8iFHP$`$!Oub$& zVK81~GFyOJtpE)Od?-f*VgM2Bh8+F1Y?0${~Qe3T65{)#psT21q1MefdK^WggPH2|P~R7WP0PA20?_vXvZ+Ohoxt1hFwRY`8Z00000 LNkvXXu0mjfmeBbk literal 0 HcmV?d00001 diff --git a/src/ui/Gui.java b/src/ui/Gui.java index 1bde467..79aa899 100644 --- a/src/ui/Gui.java +++ b/src/ui/Gui.java @@ -32,36 +32,15 @@ * @author baltasarq */ public class Gui extends JFrame { - public static final String EtqIconName = "res/pooiIcon.png"; + public static final String EtqIconApp = "res/pooiIcon.png"; + public static final String EtqIconReset = "res/reset.png"; + public static final String EtqIconNew = "res/new.png"; /** Creates new form Gui */ public Gui() { this.build(); - - // Prepare ui dimensions - Dimension scrDim = Toolkit.getDefaultToolkit().getScreenSize(); - this.setTitle( AppInfo.Name + " " + AppInfo.Version ); - this.setMinimumSize( new Dimension( 620, 460 ) ); - this.setPreferredSize( new Dimension( 790, 590 ) ); - - // Center in screen - this.setLocation( - ( scrDim.width - this.getWidth() ) / 2, - ( scrDim.height - this.getHeight() ) / 2 - ); - - try { - URL url = this.getClass().getClassLoader().getResource( EtqIconName ); - ImageIcon iconImg = new ImageIcon( url ); - - setIconImage( iconImg.getImage() ); - } catch(Exception exc) - { - output.append( "[failed to retrieve icon from jar]\n\n" ); - } - - input.requestFocusInWindow(); + this.input.requestFocusInWindow(); } private void buildFontDialog(int fontSize) @@ -363,8 +342,11 @@ private void buildCanvas() private void buildToolbar() { - JButton btReset = new JButton( "Reset" ); - JButton btNewObject = new JButton( "New object" ); + JButton btReset = new JButton( this.iconReset ); + JButton btNewObject = new JButton( this.iconNew); + + btReset.setToolTipText( "reset" ); + btNewObject.setToolTipText( "new object" ); this.tbIconBar = new JToolBar(); this.tbIconBar.setFloatable( false ); @@ -378,11 +360,30 @@ private void buildToolbar() // Events btReset.addActionListener( e -> Gui.this.onReset() ); - btNewObject.addActionListener( e -> { - Gui.this.simulate( "(anObject copy)" ); - }); + btNewObject.addActionListener( e -> Gui.this.onNewObject() ); } - + + /** Retries icons from jar for future use */ + private void buildIcons() + { + URL url; + + try { + url = this.getClass().getClassLoader().getResource(EtqIconApp); + this.iconApp = new ImageIcon( url ); + + url = this.getClass().getClassLoader().getResource( EtqIconReset ); + this.iconReset = new ImageIcon( url ); + + url = this.getClass().getClassLoader().getResource(EtqIconNew); + this.iconNew = new ImageIcon( url ); + + } catch(Exception exc) + { + output.append( "[failed to retrieve icons from jar]\n\n" ); + } + } + /** * This method is called from within the constructor to initialize the form. */ @@ -393,6 +394,7 @@ private void build() this.spPanel.setDividerLocation( 150 ); // Build components + this.buildIcons(); this.buildMenuBar(); this.buildToolbar(); this.buildInput(); @@ -406,14 +408,28 @@ private void build() this.getContentPane().add( this.tpMain, java.awt.BorderLayout.CENTER ); // Polish the window - this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - this.setMinimumSize(new java.awt.Dimension(500, 400)); - this.addWindowListener(new java.awt.event.WindowAdapter() { + this.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE ); + this.setMinimumSize( new java.awt.Dimension( 600, 400 ) ); + this.addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosed(java.awt.event.WindowEvent evt) { Gui.this.close(); } }); + this.pack(); + this.setIconImage( this.iconApp.getImage() ); + + // Prepare ui dimensions + Dimension scrDim = Toolkit.getDefaultToolkit().getScreenSize(); + this.setTitle( AppInfo.Name + " " + AppInfo.Version ); + this.setMinimumSize( new Dimension( 620, 460 ) ); + this.setPreferredSize( new Dimension( 790, 590 ) ); + + // Center in screen + this.setLocation( + ( scrDim.width - this.getWidth() ) / 2, + ( scrDim.height - this.getHeight() ) / 2 + ); } private void onLoadSession() @@ -580,6 +596,29 @@ private void onReset() this.reset(); } + private void onNewObject() { + String order = "(anObject copy) rename \""; + + String s = (String) JOptionPane.showInputDialog( + this, + "New object's name:", + AppInfo.Name, + JOptionPane.PLAIN_MESSAGE, + this.iconNew, + null, + "obj" ); + + if ( s != null ) { + s = s.trim(); + + if ( s.length() > 0 ) { + this.simulate( order + s + '"' ); + } + } + + return; + } + private void reset() { try { @@ -709,6 +748,10 @@ private void addNodes(DefaultMutableTreeNode node, ObjectBag obj, HashSet