B
Bryan Castillo
use strict;
use warnings;
use Tk;
my $top = MainWindow->new();
my $t1 = $top->Scrolled(
'Text', -scrollbars=>'se',
-height=>5, -width=>40, -wrap=>'none'
)->grid(
-row=>0,-col=>0,-sticky=>'nsew'
);
my $t2 = $top->Scrolled(
'Text', -scrollbars=>'se',
-height=>5, -width=>40, -wrap=>'none'
)->grid(
-row=>1,-col=>0,-sticky=>'nsew'
);
my $btn = $top->Button(-text=>'Generate (Java Crap)',
-command=>[\&generate, $t1, $t2])
->grid(
-row=>2,-col=>0,-sticky=>'e'
);
$top->gridRowconfigure(0, -weight=>1);
$top->gridRowconfigure(1, -weight=>1);
$top->gridRowconfigure(2, -weight=>0);
$top->gridColumnconfigure(0, -weight=>1);
MainLoop;
# generate getters and setters for those !@*&*n beans!
sub generate {
my ($t1, $t2) = @_;
my $text = $t1->get("0.0", "end");
my @lines = split /[\r\n]+/, $text;
my $out = '';
foreach my $line (@lines) {
if ($line =~ /
(\w+)\s* # variable type
(\[[\d\s]*\])?\s* # array type?
(\w+)\s* # variable name
(\[[\d\s]*\])?\s* # array type?
[;=]/x)
{
my ($type, $var) = ($1,$3);
my $array = $2 || $4;
$type .= " []" if ($array)
my $var_uc = ucfirst($var);
$out .= sprintf
" public %s get%s {\n return this.%s;\n }\n",
$type, $var_uc, $var;
$out .= sprintf
" public void set%s(%s %s) {\n this.%s = %s;\n }\n\n",
$var_uc, $type, $var, $var, $var;
}
}
$t2->delete("0.0", "end");
$t2->insert('end', $out);
}
# thats all I really had to say
use warnings;
use Tk;
my $top = MainWindow->new();
my $t1 = $top->Scrolled(
'Text', -scrollbars=>'se',
-height=>5, -width=>40, -wrap=>'none'
)->grid(
-row=>0,-col=>0,-sticky=>'nsew'
);
my $t2 = $top->Scrolled(
'Text', -scrollbars=>'se',
-height=>5, -width=>40, -wrap=>'none'
)->grid(
-row=>1,-col=>0,-sticky=>'nsew'
);
my $btn = $top->Button(-text=>'Generate (Java Crap)',
-command=>[\&generate, $t1, $t2])
->grid(
-row=>2,-col=>0,-sticky=>'e'
);
$top->gridRowconfigure(0, -weight=>1);
$top->gridRowconfigure(1, -weight=>1);
$top->gridRowconfigure(2, -weight=>0);
$top->gridColumnconfigure(0, -weight=>1);
MainLoop;
# generate getters and setters for those !@*&*n beans!
sub generate {
my ($t1, $t2) = @_;
my $text = $t1->get("0.0", "end");
my @lines = split /[\r\n]+/, $text;
my $out = '';
foreach my $line (@lines) {
if ($line =~ /
(\w+)\s* # variable type
(\[[\d\s]*\])?\s* # array type?
(\w+)\s* # variable name
(\[[\d\s]*\])?\s* # array type?
[;=]/x)
{
my ($type, $var) = ($1,$3);
my $array = $2 || $4;
$type .= " []" if ($array)
my $var_uc = ucfirst($var);
$out .= sprintf
" public %s get%s {\n return this.%s;\n }\n",
$type, $var_uc, $var;
$out .= sprintf
" public void set%s(%s %s) {\n this.%s = %s;\n }\n\n",
$var_uc, $type, $var, $var, $var;
}
}
$t2->delete("0.0", "end");
$t2->insert('end', $out);
}
# thats all I really had to say