Skip to content

Commit

Permalink
Single attribute is from root in assignments
Browse files Browse the repository at this point in the history
New icons.
"os" object.
DateTime objects.
  • Loading branch information
Baltasarq committed Feb 13, 2016
1 parent c8ddaeb commit 40120b1
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 232 deletions.
290 changes: 115 additions & 175 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/core/AppInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
1 change: 0 additions & 1 deletion src/core/Interpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 9 additions & 8 deletions src/core/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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 );
}
Expand Down
14 changes: 14 additions & 0 deletions src/core/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 )" ) );
}


Expand Down
13 changes: 0 additions & 13 deletions src/core/objs/ObjectDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added src/res/new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/res/reset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 77 additions & 34 deletions src/ui/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 );
Expand All @@ -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.
*/
Expand All @@ -393,6 +394,7 @@ private void build()
this.spPanel.setDividerLocation( 150 );

// Build components
this.buildIcons();
this.buildMenuBar();
this.buildToolbar();
this.buildInput();
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -709,6 +748,10 @@ private void addNodes(DefaultMutableTreeNode node, ObjectBag obj, HashSet<Object
private JLabel lblCanvasFrame;
private JToolBar tbIconBar;

private ImageIcon iconReset;
private ImageIcon iconNew;
private ImageIcon iconApp;

private Interpreter interpreter = null;

private static boolean rebuildingTree = false;
Expand Down

0 comments on commit 40120b1

Please sign in to comment.