@Override
public void paint(Graphics vg) {
if (vg == null) {
return;
}
VectorGraphics g = VectorGraphics.create(vg);
super.paint(g);
// Pulizia piano lavoro
g.setColor(Color.WHITE);
g.fillRect(0, 0, 640, 670);
// Sfondo bianco del grafico
g.fillRect(UpperLeftGraph.x, UpperLeftGraph.y, WIDTH + 1, HEIGHT + 1);
// Sfondo grigio per label informativa
g.setColor(Color.LIGHT_GRAY);
g.fillRect(0, 0, UpperRightGraph.x + RIGHT_SPACE, UpperLeftGraph.y - 10);
g.setColor(Color.BLACK);
g.drawRect(0, 0, UpperRightGraph.x + RIGHT_SPACE, UpperLeftGraph.y - 10);
Font fn = new Font("Arial", Font.ITALIC, 16);
g.setFont(fn);
g.drawString("Single left click and drag to zoom, single right click to choose scatter options", 50, 20);
// Bordi neri del grafico
g.setColor(Color.BLACK);
g.drawLine(UpperLeftGraph.x - 1, UpperLeftGraph.y - 1, UpperRightGraph.x, UpperRightGraph.y - 1); //UP
g.drawLine(UpperLeftGraph.x - 1, UpperLeftGraph.y - 1, LowerLeftGraph.x - 1, LowerLeftGraph.y); //LEFT
g.drawLine(LowerLeftGraph.x, LowerLeftGraph.y, LowerRightGraph.x, LowerRightGraph.y); //BOTTOM
g.drawLine(LowerRightGraph.x, LowerRightGraph.y, UpperRightGraph.x, UpperRightGraph.y); //RIGHT
// Testo variabile in x
fn = new Font("Arial", Font.PLAIN, 15);
g.setFont(fn);
g.drawString(model.getMatrix().getVariables()[xVar].getName(), XText.x, XText.y);
// Elenco etichette valori in Y
fn = new Font("Arial", Font.PLAIN, 9);
g.setFont(fn);
for (int i = 0; i <= 9; i++) {
if (model.getMatrix().getVariables()[yVar].getType() == JWATConstants.DATE) {
SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
g.drawString(f.format(new Date((long) (yMax - (yMax - yMin) / 9 * i))), WIDTH_TEXT_Y, UpperLeftGraph.y + (i * (HEIGHT / 9)));
} else {
g.drawString(valueFormat.format(yMax - (yMax - yMin) / 9 * i), WIDTH_TEXT_Y, UpperLeftGraph.y + (i * (HEIGHT / 9)));
}
}
// Testo variabile in Y
fn = new Font("Arial", Font.PLAIN, 17);
fn = fn.deriveFont(AffineTransform.getRotateInstance(3.14 / 2 + 3.14));
g.setFont(fn);
g.drawString(model.getMatrix().getVariables()[yVar].getName(), YText.x, YText.y);
// Testo etichette valori in x
fn = new Font("Arial", Font.PLAIN, 9);
fn = fn.deriveFont(AffineTransform.getRotateInstance(3.14 / 2 + 3.14));
g.setFont(fn);
for (int i = 0; i <= 9; i++) {
if (model.getMatrix().getVariables()[xVar].getType() == JWATConstants.DATE) {
SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
g.drawString(f.format(new Date((long) (xMin + (xMax - xMin) / 9 * i))), LowerLeftGraph.x + (i * (WIDTH / 9)), LowerLeftGraph.y
+ HEIGHT_VALUES_X);
} else {
g.drawString(valueFormat.format(xMin + (xMax - xMin) / 9 * i), LowerLeftGraph.x + (i * (WIDTH / 9)), LowerLeftGraph.y
+ HEIGHT_VALUES_X);
}
}
// Disegno punti
if (first) {
first = false;
new TimeConsumingWorker(new ProgressMonitorShow(this, "Plotting observations ...", 100)) {
@Override
public Object construct() {
VectorGraphics g1 = VectorGraphics.create(graph.getGraphics());
g1.setColor(Color.BLACK);
g1.drawLine(0, 500, 500, 500);
g1.drawLine(500, 500, 500, 0);
g1.setColor(Color.WHITE);
g1.fillRect(0, 0, WIDTH, HEIGHT);
g1.setColor(Color.LIGHT_GRAY);
g1.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 1.5F }, 0));
for (int i = 1; i < 9; i++) {
g1.drawLine(1, 1 + (i * (HEIGHT / 9)), 499, 1 + (i * (HEIGHT / 9)));
g1.drawLine(1 + (i * (WIDTH / 9)), 1, 1 + (i * (WIDTH / 9)), 499);
}
g1.setColor(Color.RED);
VariableNumber x = model.getMatrix().getVariables()[xVar];
x.setRangeIntervallo(x.getIndexMin(xMin), x.getIndexMax(xMax), yMin, yMax, yVar);
/* 28 Settembre */
try {
initShow(x.Size());
} catch (InterruptedException e1) {
e1.printStackTrace();
} catch (InvocationTargetException e1) {
e1.printStackTrace();
}
int xPos = 0;
for (int i = 0; i < x.Size(); i++) {
try {
xPos = x.getNextInt();
if (i % getStep() == 0) {
updateInfos(i, "Plotting obs " + i, false);
}
g1.fillOval((int) ((x.getValue(xPos) - xMin) / (xMax - xMin) * (WIDTH - 2)), (HEIGHT - 2)
- (int) ((x.getValue(xPos, yVar) - yMin) / (yMax - yMin) * (HEIGHT - 1)), pointSize, pointSize);
} catch (Exception e) {
break;
}
}