File: p3.pl

package info (click to toggle)
libinline-java-perl 0.58~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 964 kB
  • ctags: 684
  • sloc: perl: 4,717; java: 2,844; makefile: 35
file content (164 lines) | stat: -rwxr-xr-x 4,205 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use blib ;
use vars qw($JARS);
BEGIN {
  $JARS = '/home/patrickl/perl/dev/Inline-Java/bug/piccolo-1.0/build' ;
}
use Inline Java => Config =>
  CLASSPATH => "$JARS/piccolo.jar:$JARS/piccolox.jar:$JARS/examples.jar";
use Inline::Java qw(study_classes) ;
study_classes(['java.awt.Color',
	       'edu.umd.cs.piccolo.nodes.PPath',
	       'edu.umd.cs.piccolo.nodes.PText',
	       'edu.umd.cs.piccolo.PCanvas',
	       'edu.umd.cs.piccolo.PLayer',
	       'java.awt.BasicStroke',
	      ]);
use Inline Java => 'DATA';

use Getopt::Long;
my %OPTIONS;
my $rc = GetOptions(\%OPTIONS,
		    'input=s',
		    'help',
		   );

my $USAGE = <<"EOU";
usage: $0 [required params] [options]
  require params:
    --input=file : gaps file to process

  options:
    --help        : this message
EOU

die "Bad option\n$USAGE" unless $rc;
die "$USAGE" if exists $OPTIONS{help};

die "Must specify --input\n$USAGE"
  unless exists $OPTIONS{input};

# create the Java connection
my $t = new Test();

# set up some useful constants
my $UNIT = 10;
my $STROKE = java::awt::BasicStroke->new($UNIT);

# read in the file data
open(IN,$OPTIONS{input})
  or die "Couldn't open $OPTIONS{input} for reading";
while (<IN>) {
  my ($ref_pos,$query_pos,$length) = m/^\s+(\d+)\s+(\d+)\s+(\d+)\s+/;
  push(@gaps,[$ref_pos,$query_pos,$length]);
}
my $max_ref = $gaps[-1]->[0] + $gaps[-1]->[2];
my $max_query = $gaps[-1]->[1] + $gaps[-1]->[2];

# get access to some picolo internal objects
my $c = $t->getCanvas();
my $layer = $c->getLayer();

# create rectangles for the landmarks
for (my $i=0;$i<$max_ref;$i+=10_000) {
  print "$i\n" ;
  my $r = edu::umd::cs::piccolo::nodes::PPath->createRectangle($i-$UNIT,
					$i-$UNIT,
					2*$UNIT,
					2*$UNIT);
  $r->setPaint($java::awt::Color::RED);
  $layer->addChild($r);

# FIXME - this line causes the following error:
# Method createPolyline for class edu.umd.cs.piccolo.nodes.PPath with signature ([F,[F) not found at (eval 10) line 1159
my $text = edu::umd::cs::piccolo::nodes::PText->new("$i");
$text->setOffset($i,$i);
$layer->addChild($text);

# FIXME - this line causes the following error:
# Method createPolyline for class edu.umd.cs.piccolo.nodes.PPath with signature ([F,[F) not found at (eval 10) line 1159
#
# unless you comment out the foreach loop for drawing lines
  my $text = $t->getText("$i");
  $text->setOffset($i,$i);
  $layer->addChild($text);
}

my $tag = 0;
my $i = 0 ;
foreach my $gap (@gaps) {
  print "$i\n" ; $i++ ;

  my $l = edu::umd::cs::piccolo::nodes::PPath->createPolyline([$gap->[0],$gap->[0]+$gap->[2]],
			     [$gap->[1],$gap->[1]+$gap->[2]],
			    );
  $l->setStroke($STROKE);
  if ($tag) {
    $l->setStrokePaint($java::awt::Color::BLUE);
    $tag = 0;
  } else {
    $l->setStrokePaint($java::awt::Color::GREEN);
    $tag = 1;
  }
# FIXME - this line causes the following error:
# Method createPolyline for class edu.umd.cs.piccolo.nodes.PPath with signature ([F,[F) not found at (eval 10) line 1159
 $layer->addChild($l);

# so instead I've created a bogus wrapper method to do the work
#  $t->addChild($l);

}

while (1) {
  sleep 5;
}
print "Finished\n";

__DATA__

__Java__

import java.awt.BasicStroke;
import java.awt.Paint;
// import java.awt.Color;
// import java.awt.Graphics2D;
// import edu.umd.cs.piccolo.activities.PActivity;
// import edu.umd.cs.piccolo.util.PPaintContext;
import edu.umd.cs.piccolo.PLayer;
import edu.umd.cs.piccolo.PCanvas;
import edu.umd.cs.piccolo.PNode;
import edu.umd.cs.piccolox.PFrame;
import edu.umd.cs.piccolo.nodes.PPath;
import edu.umd.cs.piccolo.nodes.PText;

class Test extends PFrame {

	public Test() {
		super();
	}
	public void addChild(PNode aNode) {
		PLayer layer = getCanvas().getLayer();
		layer.addChild(aNode);
        }
	public PText getText(String s) {
	        return new PText(s);
        }
	public void initialize() {
		long currentTime = System.currentTimeMillis();
	}
}
/*
public class SemanticPath extends PPath {
	public void paint(PPaintContext aPaintContext) {
		double s = aPaintContext.getScale();
		Graphics2D g2 = aPaintContext.getGraphics();
		
		if (s < 1) {
			g2.setPaint(Color.blue);
		} else {
			g2.setPaint(Color.orange);
		}
		
		g2.fill(getBoundsReference());
	}
}
*/