Commit 21b9b2fd authored by Claes Sjofors's avatar Claes Sjofors

Ge axis arc in java

parent 2f653994
/*
* Proview $Id$
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package jpwr.jop;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.font.*;
import javax.swing.*;
import java.awt.event.*;
import jpwr.rt.*;
public class JopAxisarc extends JComponent {
Dimension size;
public JopAxisarc()
{
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
size = new Dimension( 102, 36);
}
float angle1 = 0;
float angle2 = 360;
int fillColor = 9999;
int borderColor = 9999;
public int originalTextColor = 9999;
public int textColor = 9999;
int lineWidth = 1;
float lineLength;
int lines = 11;
int longQuotient = 1;
int valueQuotient = 1;
GeCFormat cFormat;
Font font;
public void setAngle1( float angle1) {
this.angle1 = angle1;
}
public void setAngle2( float angle2) {
this.angle2 = angle2;
}
public void setFillColor( int fillColor) {
this.fillColor = fillColor;
}
public int getFillColor() {
return fillColor;
}
public void setBorderColor( int borderColor) {
this.borderColor = borderColor;
}
public int getBorderColor() {
return borderColor;
}
public void setTextColor( int textColor) {
this.textColor = textColor;
this.originalTextColor = textColor;
}
public int getTextColor() {
return textColor;
}
public void setLineWidth( int lineWidth) {
this.lineWidth = lineWidth;
}
public int getLineWidth() {
return lineWidth;
}
public void setLineLength( float lineLength) {
this.lineLength = lineLength;
}
public float getLineLength() {
return lineLength;
}
public void setLines( int lines) {
this.lines = lines;
}
public int getLines() {
return lines;
}
public void setLongQuotient( int longQuotient) {
this.longQuotient = longQuotient;
}
public int getLongQuotient() {
return longQuotient;
}
public void setValueQuotient( int valueQuotient) {
this.valueQuotient = valueQuotient;
}
public int getValueQuotient() {
return valueQuotient;
}
public void setFormat( String format) {
this.cFormat = new GeCFormat(format);
}
public void setFont( Font font) {
this.font = font;
}
public Font getFont() {
return font;
}
public double rotate;
public void setRotate( double rotate) { this.rotate = rotate;}
public double getRotate() { return rotate;}
Shape[] shapes = null;
Line2D.Float[] hLines;
public void paint(Graphics g1) {
super.paint(g1);
Graphics2D g = (Graphics2D) g1;
Component c;
Point p;
paintComponent(g);
for ( int i = 0; i < getComponentCount(); i++) {
AffineTransform save = g.getTransform();
c = getComponent(i);
p = c.getLocation();
g.translate((int)p.getX(), (int)p.getY());
c.paint(g);
g.setTransform(save);
}
}
float hTextPosX[];
float hTextPosY[];
String hText[];
float oldWidth;
float widthOrig = 0;
public void paintComponent(Graphics g1) {
int i, j;
Graphics2D g = (Graphics2D) g1;
float width = getWidth();
float height = getHeight();
AffineTransform save = g.getTransform();
float delta;
float value;
boolean drawText = (minValue != maxValue);
System.out.println( "w: " + width + " h: " + height + " Lines " + lines + " Len " + lineLength);
if ( widthOrig == 0)
widthOrig = width;
//g.setFont( font);
g.setFont( font.deriveFont( width / widthOrig * font.getSize()));
if ( shapes == null || width != oldWidth) {
float lineLen = this.lineLength * width / widthOrig;
shapes = new Shape[1];
FontRenderContext frc = g.getFontRenderContext();
if ( lines > 0)
{
hLines = new Line2D.Float[lines];
if ( drawText) {
hText = new String[lines/valueQuotient + 1];
hTextPosY = new float[lines/valueQuotient + 1];
hTextPosX = new float[lines/valueQuotient + 1];
}
shapes[0] = new Arc2D.Float( 0F, 0F, width, height, angle1, angle2, Arc2D.PIE);
float line_angle = angle2 / (lines - 1);
for ( i = 0; i < lines; i++) {
float sin1 = (float) Math.sin( (angle1 + i * line_angle) / 180 * Math.PI);
float cos1 = (float) Math.cos( (angle1 + i * line_angle) / 180 * Math.PI);
float x1, y1, x2, y2, xt, yt;
xt = yt = 0;
y1 = height / 2 * ( -sin1 + 1);
x1 = width / 2 * ( cos1 + 1);
if ( i % longQuotient == 0) {
y2 = height / 2 * ( -sin1 * ( 1F - lineLen) + 1);
x2 = width / 2 * ( cos1 * ( 1F - lineLen) + 1);
}
else {
y2 = height / 2 * ( -sin1 * ( 1F - lineLen / 2) + 1);
x2 = width / 2 * ( cos1 * ( 1F - lineLen / 2) + 1);
}
hLines[i] = new Line2D.Float( x1, y1, x2, y2);
if ( drawText && i % valueQuotient == 0) {
if ( maxValue > minValue)
value = maxValue - (maxValue - minValue) / ( lines - 1) * i;
else
value = (minValue - maxValue) / ( lines - 1) * i;
hText[i/valueQuotient] =
cFormat.format( value, new StringBuffer()).toString();
Rectangle2D textBounds =
g.getFont().getStringBounds( hText[i/valueQuotient], frc);
float textHeight = (float) textBounds.getHeight();
float textWidth = (float) textBounds.getWidth();
yt = height / 2 * ( -sin1 * (1F - lineLen) + 1) + sin1 * textHeight;
xt = width / 2 * ( cos1 * (1F - lineLen) + 1) + cos1 * textWidth / 2;
float increment = (maxValue - minValue) / (lines - 1);
System.out.println( "Text w: " + textWidth + " h: " + textHeight);
if ( i % valueQuotient == 0 &&
!(angle2 == 360 &&
((increment > 0 && i == lines - 1) || (increment < 0 && i == 0)))) {
if ( i == lines - 1 && angle1 == 0 && angle2 == 180) {
xt = xt - textWidth/2;
}
else if ( i == 0 && angle1 == 0 && angle2 != 360) {
xt = xt - textWidth/2;
}
else {
yt = yt + textHeight/2;
xt = xt - textWidth/2;
}
hTextPosY[i/valueQuotient] = yt;
hTextPosX[i/valueQuotient] = xt;
}
}
System.out.println( "Line (" + x1 + "," + y1 + ") (" + x2 + "," + y2 + ") (" + xt + "," + yt + ")");
}
}
}
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g.setStroke( new BasicStroke((float)lineWidth));
g.setColor(GeColor.getColor(0, borderColor));
g.draw( shapes[0]);
for ( i = 0; i < lines; i++)
g.draw( hLines[i]);
if ( drawText) {
for ( i = 0; i < lines; i++) {
if ( i % valueQuotient == 0) {
g.drawString( hText[i/valueQuotient], hTextPosX[i/valueQuotient],
hTextPosY[i/valueQuotient]);
}
}
}
oldWidth = width;
}
public Dimension getPreferredSize() { return size;}
public Dimension getMinimumSize() { return size;}
float minValue = 0;
float maxValue = 100;
public void setMinValue( float minValue) {
this.minValue = minValue;
}
public void setMaxValue( float maxValue) {
this.maxValue = maxValue;
}
public float getMaxValue() {
return maxValue;
}
public float getMinValue() {
return minValue;
}
}
......@@ -33,6 +33,7 @@ local_java_sources := \
JopBar.java \
JopTrend.java \
JopAxis.java \
JopAxisarc.java \
GeTable.java \
GeDynElem.java \
GeDynDigLowColor.java \
......
......@@ -3679,6 +3679,120 @@ void GlowExportJBean::axis( double x1, double y1, double x2, double y2,
}
}
void GlowExportJBean::axisarc( double x1, double y1, double x2, double y2,
double angle1, double angle2,
glow_eDrawType border_drawtype,
glow_eDrawType text_drawtype,
double min_value,
double max_value,
int lines,
int longquotient,
int valuequotient,
double line_length,
int line_width,
double rotate,
int bold,
int text_idx,
char *format,
glow_eExportPass pass, int *shape_cnt, int node_cnt, ofstream& fp)
{
double dim_x0, dim_x1, dim_y0, dim_y1;
char var_name[40];
char class_name[] = "JopAxisarc";
strcpy( var_name, class_name);
var_name[0] = _tolower(var_name[0]);
sprintf( &var_name[strlen(var_name)], "%d", node_cnt);
switch ( pass)
{
case glow_eExportPass_Shape:
break;
case glow_eExportPass_Declare:
{
fp <<
" " << class_name << " " << var_name << ";" << endl;
break;
}
case glow_eExportPass_Attributes:
{
char bold_str[20];
int text_size;
((GrowCtx *)ctx)->measure_javabean( &dim_x1, &dim_x0, &dim_y1, &dim_y0);
switch ( text_idx)
{
case 0: text_size = 8; break;
case 1: text_size = 10; break;
case 2: text_size = 12; break;
case 3: text_size = 14; break;
case 4: text_size = 14; break;
case 5: text_size = 18; break;
case 6: text_size = 18; break;
case 7: text_size = 18; break;
default: text_size = 24;
}
if ( text_idx < 0)
text_size = 6;
if ( bold)
strcpy(bold_str, "BOLD");
else
strcpy(bold_str, "PLAIN");
fp <<
" " << var_name << " = new " << class_name << "();" << endl <<
" " << var_name << ".setBounds(new Rectangle(" <<
(int)(x1 - dim_x0 + glow_cJBean_Offset) << "," <<
(int)(y1 - dim_y0 + glow_cJBean_Offset) << "," <<
(int)(x2 - x1) << "," <<
(int)(y2 - y1) << "));" << endl;
if ( border_drawtype != glow_eDrawType_No)
fp <<
" " << var_name << ".setBorderColor(" << (int)border_drawtype << ");" << endl;
else
fp <<
" " << var_name << ".setBorderColor( 0);" << endl;
if ( text_drawtype != glow_eDrawType_No)
fp <<
" " << var_name << ".setTextColor(" << (int)text_drawtype << ");" << endl;
else
fp <<
" " << var_name << ".setTextColor( 0);" << endl;
fp <<
" " << var_name << ".setAngle1(" << angle1 << "F);" << endl <<
" " << var_name << ".setAngle2(" << angle2 << "F);" << endl <<
" " << var_name << ".setLineWidth(" << line_width << ");" << endl <<
" " << var_name << ".setMinValue(" << min_value << "F);" << endl <<
" " << var_name << ".setMaxValue(" << max_value << "F);" << endl <<
" " << var_name << ".setLines(" << lines << ");" << endl <<
" " << var_name << ".setLongQuotient(" << longquotient << ");" << endl <<
" " << var_name << ".setValueQuotient(" << valuequotient << ");" << endl <<
" " << var_name << ".setLineLength(" << line_length << "F);" << endl <<
" " << var_name << ".setLineWidth(" << line_width << ");" << endl <<
" " << var_name << ".setRotate(" << rotate << ");" << endl <<
" " << var_name << ".setFont(new Font(\"Helvetica\", Font." << bold_str
<< ", " << text_size << "));" << endl <<
" " << var_name << ".setFormat(\"" << format << "\");" << endl;
if ( is_nodeclass)
fp <<
" add(" << var_name << ");" << endl;
else
fp <<
" localPanel.add(" << var_name << ", new Proportion(" << var_name << ".getBounds(), dsize));" << endl;
break;
}
case glow_eExportPass_Draw:
break;
default:
;
}
}
void GlowExportJBean::window( double x1, double y1, double x2, double y2,
char *filename,
int vertical_scrollbar, int horizontal_scrollbar, char *owner,
......
......@@ -160,6 +160,22 @@ class GlowExportJBean {
int text_idx,
char *format,
glow_eExportPass pass, int *shape_cnt, int node_cnt, ofstream& fp);
void axisarc( double x1, double y1, double x2, double y2,
double angle1, double angle2,
glow_eDrawType border_drawtype,
glow_eDrawType text_drawtype,
double min_value,
double max_value,
int lines,
int longquotient,
int valuequotient,
double line_length,
int line_width,
double rotate,
int bold,
int text_idx,
char *format,
glow_eExportPass pass, int *shape_cnt, int node_cnt, ofstream& fp);
void window( double x1, double y1, double x2, double y2,
char *filename,
int vertical_scrollbar,
......
......@@ -715,6 +715,32 @@ void GrowArc::draw( GlowWind *w, GlowTransform *t, int highlight, int hot, void
rot = int( trf.rot( t));
}
if ( rot % 90 != 0 && fabs((ur.x - ll.x) - (ur.y - ll.y)) < FLT_EPSILON) {
double scale;
double x_c;
double y_c;
if ( !t) {
scale = trf.vertical_scale( &trf);
x_c = ((trf.x( ll.x, ll.y) * w->zoom_factor_x - w->offset_x) +
(trf.x( ur.x, ur.y) * w->zoom_factor_x - w->offset_x)) / 2;
y_c = ((trf.y( ll.x, ll.y) * w->zoom_factor_y - w->offset_y) +
(trf.y( ur.x, ur.y) * w->zoom_factor_y - w->offset_y)) / 2;
}
else {
GlowTransform tmp = *t * trf;
scale = trf.vertical_scale( &tmp);
x_c = ((trf.x( t, ll.x, ll.y) * w->zoom_factor_x - w->offset_x) +
(trf.x( t, ur.x, ur.y) * w->zoom_factor_x - w->offset_x)) / 2;
y_c = ((trf.y( t, ll.x, ll.y) * w->zoom_factor_y - w->offset_y) +
(trf.y( t, ur.x, ur.y) * w->zoom_factor_y - w->offset_y)) / 2;
}
x1 = int(-scale * (double(ur.x - ll.x)/2 * w->zoom_factor_x) + x_c + 0.5);
y1 = int(-scale * (double(ur.y - ll.y)/2 * w->zoom_factor_y) + y_c + 0.5);
x2 = int(scale * (double(ur.x - ll.x)/2 * w->zoom_factor_x) + x_c + 0.5);
y2 = int(scale * (double(ur.y - ll.y)/2 * w->zoom_factor_y) + y_c + 0.5);
}
ll_x = min( x1, x2);
ur_x = max( x1, x2);
ll_y = min( y1, y2);
......@@ -859,11 +885,38 @@ void GrowArc::erase( GlowWind *w, GlowTransform *t, int hot, void *node)
y2 = int( trf.y( t, ur.x, ur.y) * w->zoom_factor_y + 0.5) - w->offset_y;
rot = int( trf.rot( t));
}
if ( rot % 90 != 0 && fabs((ur.x - ll.x) - (ur.y - ll.y)) < FLT_EPSILON) {
double scale;
double x_c;
double y_c;
if ( !t) {
scale = trf.vertical_scale( &trf);
x_c = ((trf.x( ll.x, ll.y) * w->zoom_factor_x - w->offset_x) +
(trf.x( ur.x, ur.y) * w->zoom_factor_x - w->offset_x)) / 2;
y_c = ((trf.y( ll.x, ll.y) * w->zoom_factor_y - w->offset_y) +
(trf.y( ur.x, ur.y) * w->zoom_factor_y - w->offset_y)) / 2;
}
else {
GlowTransform tmp = *t * trf;
scale = trf.vertical_scale( &tmp);
x_c = ((trf.x( t, ll.x, ll.y) * w->zoom_factor_x - w->offset_x) +
(trf.x( t, ur.x, ur.y) * w->zoom_factor_x - w->offset_x)) / 2;
y_c = ((trf.y( t, ll.x, ll.y) * w->zoom_factor_y - w->offset_y) +
(trf.y( t, ur.x, ur.y) * w->zoom_factor_y - w->offset_y)) / 2;
}
x1 = int(-scale * (double(ur.x - ll.x)/2 * w->zoom_factor_x) + x_c + 0.5);
y1 = int(-scale * (double(ur.y - ll.y)/2 * w->zoom_factor_y) + y_c + 0.5);
x2 = int(scale * (double(ur.x - ll.x)/2 * w->zoom_factor_x) + x_c + 0.5);
y2 = int(scale * (double(ur.y - ll.y)/2 * w->zoom_factor_y) + y_c + 0.5);
}
ll_x = min( x1, x2);
ur_x = max( x1, x2);
ll_y = min( y1, y2);
ur_y = max( y1, y2);
w->set_draw_buffer_only();
if ( border || !fill)
ctx->gdraw->arc_erase( w, ll_x, ll_y, ur_x - ll_x, ur_y - ll_y,
......
......@@ -471,17 +471,10 @@ void GrowAxisArc::set_range( double min, double max)
void GrowAxisArc::export_javabean( GlowTransform *t, void *node,
glow_eExportPass pass, int *shape_cnt, int node_cnt, int in_nc, ofstream &fp)
{
int i;
int draw_text = (fabs(increment) > DBL_EPSILON);
double x1, y1, x2, y2, ll_x, ll_y, ur_x, ur_y;
double rotation;
int bold;
char text[20];
int line_length;
int z_height, z_width, z_descent;
int max_z_width = 0;
int idx = int( ctx->mw.zoom_factor_y / ctx->mw.base_zoom_factor * (text_size +4) - 4);
double tsize = ctx->mw.zoom_factor_y / ctx->mw.base_zoom_factor * (8+2*text_size);
idx = min( idx, DRAW_TYPE_SIZE-1);
bold = (text_drawtype == glow_eDrawType_TextHelveticaBold);
......@@ -511,74 +504,9 @@ void GrowAxisArc::export_javabean( GlowTransform *t, void *node,
else
rotation = (trf.rot() / 360 - floor( trf.rot() / 360)) * 360;
// Calculate max value line width
if ( 45 >= rotation || rotation > 315)
{
if ( draw_text) {
for ( i = 0; i < lines; i++) {
if ( i % valuequotient == 0) {
format_text( text, format, max_value - i * increment);
ctx->gdraw->get_text_extent( text, strlen(text), text_drawtype,
max( 0, idx), glow_eFont_Helvetica,
&z_width, &z_height, &z_descent, tsize);
if ( max_z_width < z_width)
max_z_width = z_width;
}
}
line_length = int(ur_x - ll_x) - max_z_width;
}
else
line_length = int(ur_x - ll_x);
}
else if ( 45 < rotation && rotation <= 135)
{
if ( draw_text) {
ctx->gdraw->get_text_extent( "0", 1, text_drawtype,
max( 0, idx), glow_eFont_Helvetica,
&z_width, &z_height, &z_descent, tsize);
line_length = int(ur_y - ll_y) - (z_height - z_descent);
}
else
line_length = int(ur_y - ll_y);
}
else if ( 135 < rotation && rotation <= 225)
{
if ( draw_text) {
for ( i = 0; i < lines; i++) {
if ( i % valuequotient == 0) {
format_text( text, format, max_value - i * increment);
ctx->gdraw->get_text_extent( text, strlen(text), text_drawtype,
max( 0, idx), glow_eFont_Helvetica,
&z_width, &z_height, &z_descent, tsize);
if ( max_z_width < z_width)
max_z_width = z_width;
}
}
line_length = int(ur_x - ll_x) - max_z_width;
}
else
line_length = int(ur_x - ll_x);
}
else // if ( 225 < rotation && rotation <= 315)
{
if ( draw_text) {
ctx->gdraw->get_text_extent( "0", 1, text_drawtype,
max( 0, idx), glow_eFont_Helvetica,
&z_width, &z_height, &z_descent, tsize);
line_length = int(ur_y - ll_y) - (z_height - z_descent);
}
else
line_length = int(ur_y - ll_y);
}
if ( line_length < 3)
line_length = 3;
((GrowCtx *)ctx)->export_jbean->axis( ll_x, ll_y, ur_x, ur_y,
((GrowCtx *)ctx)->export_jbean->axisarc( ll_x, ll_y, ur_x, ur_y, angle1, angle2,
draw_type, text_color_drawtype, min_value, max_value, lines, longquotient, valuequotient,
line_length, line_width, rotation, bold, idx, format,
linelength, line_width, rotation, bold, idx, format,
pass, shape_cnt, node_cnt, fp);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment