Skip to content

Commit

Permalink
Better diagramming
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltasarq committed Apr 30, 2016
1 parent 7c11c25 commit 3847b07
Show file tree
Hide file tree
Showing 10 changed files with 833 additions and 304 deletions.
1 change: 0 additions & 1 deletion .idea/artifacts/Pooi_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions .idea/libraries/jgraphx.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

551 changes: 341 additions & 210 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Pooi.iml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="jgraphx" level="project" />
</component>
</module>
2 changes: 1 addition & 1 deletion src/com/devbaltasarq/pooi/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 = "1.0 20160426";
public static final String Version = "1.1 20160430";

public static String getMsgVersion()
{
Expand Down
10 changes: 10 additions & 0 deletions src/com/devbaltasarq/pooi/core/ObjectBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public Attribute[] getAttributes()
return this.attributes.values().toArray( new Attribute[ attributes.size() ] );
}

/**
* Returns the collection of methods, as a native vector
*
* @return The collection of methods, as a native vector
*/
public Method[] getLocalMethods()
{
return this.methods.values().toArray( new Method[ this.methods.size() ] );
}

/**
* Returns the name of the object
*
Expand Down
7 changes: 2 additions & 5 deletions src/com/devbaltasarq/pooi/ui/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ public static void main(String args[]) {
final Gui g = new Gui();

try {
// Prepare interpreter
g.reset();

// run
// Prepare interpreter & run
java.awt.EventQueue.invokeLater( new Runnable() {
@Override
public void run() {
g.setVisible( true );
g.setVisible( true ); g.reset();
}
} );
} catch(Exception e)
Expand Down
181 changes: 181 additions & 0 deletions src/com/devbaltasarq/pooi/ui/Canvas.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package com.devbaltasarq.pooi.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

/**
* Created by baltasarq on 27/04/16.
*/
public class Canvas extends JPanel {
/** Creates a new canvas with the specified dimensions
* @param width The width of the drawing area.
* @param height The height of the drawing area.
*/
public Canvas(int width, int height)
{
this.setMinimumSize( new Dimension( width, height ) );

canvas = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB);
JLabel canvasFrame = new JLabel( new ImageIcon( canvas ) );
canvasFrame.setPreferredSize( new Dimension( width, height ) );
canvasFrame.setMinimumSize( new Dimension( width, height ) );
this.add( canvasFrame );
this.setColor( Color.black );
this.setBackgroundColor( Color.white );
this.setFontSize( 10 );
}

/** Gets the foreground color
* @return The foreground color, as a Color object
*/
public Color getColor() {
return this.color;
}

/** Modifies the foreground color
* @param c The new foreground color, as a Color object.
*/
public void setColor(Color c) {
this.color = c;
}

/** Gets the background color.
* @return The background color, as a Color object.
*/
public Color getBackgroundColor() {
return this.backgroundColor;
}

/** Modifies the background color
* @param c The new background color, as a Color object.
*/

public void setBackgroundColor(Color c) {
this.backgroundColor = c;
this.cls();
}

/** Clears the drawing area */
public void cls() {
final Graphics grfs = this.canvas.getGraphics();

grfs.setColor( this.getBackgroundColor() );
grfs.fillRect( 0, 0, this.getWidth(), this.getHeight() );
}

/** Draws a new line
* @param x1 x coordinate first point
* @param y1 y coordinate first point
* @param x2 x coordinate second point
* @param y2 y coordinate second point
*/
public void drawLine(int x1, int y1, int x2, int y2)
{
final Graphics grfs = this.canvas.getGraphics();

grfs.setColor( this.getColor() );
grfs.drawLine( x1, y1, x2, y2 );
}

/**
* Draws a rectangle in the graphics window, given its
* starting and ending point.
* @param x1 the x coordinate of the starting point
* @param y1 the y coordinate of the starting point
* @param x2 the x coordinate of the ending point
* @param y2 the y coordinate of the ending point
* @param filled whether to fill the rectangle or not
*/
public void rectangle(int x1, int y1, int x2, int y2, boolean filled) {
final Graphics grfs = this.canvas.getGraphics();

if ( x1 > x2 ) {
int t = x1;
x1 = x2;
x2 = t;
}

if ( y1 > y2 ) {
int t = y1;
y1 = y2;
y2 = t;
}

final int rectWidth = Math.abs( x2 - x1 );
final int rectHeight = Math.abs( y2 - y1 );

grfs.setColor( this.getColor() );

if ( filled ) {
grfs.fillRect( x1, y1, rectWidth, rectHeight );
} else {
grfs.drawRect( x1, y1, rectWidth, rectHeight );
}
}

/**
* Draws a circle in the graphics window,
* given its starting and ending point.
* @param x the x coordinate of the starting point
* @param y the y coordinate of the starting point
* @param r the radius
* @param filled whether to fill the circle or not
*/
public void circle(int x, int y, int r, boolean filled)
{
Graphics grfs = this.canvas.getGraphics();

if ( filled ) {
grfs.drawOval( x, y, r, r );
} else {
grfs.fillOval( x, y, r, r );
}
}

/**
* Draws a string in the graphic window
* @param x the x coordinate of the starting point
* @param y the y coordinate of the starting point
* @param str the vector of chars containing the string.
*/
public void print(int x, int y, String str)
{
if ( str != null ) {
final Graphics grfs = canvas.getGraphics();

grfs.setColor( this.getColor() );
grfs.drawChars( str.toCharArray(), 0, str.length(), x, y );
}
}

/** Changes the font size
* @param newSize The font size, as an int
*/
public void setFontSize(int newSize)
{
final Graphics grfs = this.canvas.getGraphics();

grfs.setFont( new Font( "mono", Font.PLAIN, newSize ) );
this.fontSize = newSize;
}

public int getTextHeight() {
final Graphics grfs = this.canvas.getGraphics();
FontMetrics metrics = grfs.getFontMetrics( grfs.getFont() );

return metrics.getHeight();
}

public int getTextWidth(String text) {
final Graphics grfs = this.canvas.getGraphics();
FontMetrics metrics = grfs.getFontMetrics( grfs.getFont() );

return metrics.stringWidth( text );
}

private BufferedImage canvas;
private Color color;
private Color backgroundColor;
private int fontSize;
}
Loading

0 comments on commit 3847b07

Please sign in to comment.