-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add target display, patch by Pauline Thiele
git-svn-id: https://josm.openstreetmap.de/osmsvn/applications/editors/josm/plugins@36330 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
- Loading branch information
Showing
7 changed files
with
327 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// License: Public Domain. For details, see LICENSE file. | ||
package livegps; | ||
|
||
import javax.swing.JPanel; | ||
import javax.swing.JLabel; | ||
|
||
import java.awt.Graphics; | ||
import java.awt.Graphics2D; | ||
import java.awt.Shape; | ||
import java.awt.BasicStroke; | ||
import java.awt.Color; | ||
|
||
import java.awt.geom.Rectangle2D; | ||
import java.awt.geom.Ellipse2D; | ||
import java.awt.geom.Area; | ||
|
||
import org.openstreetmap.josm.spi.preferences.Config; | ||
|
||
/** | ||
* Draw a target visualization | ||
*/ | ||
public class CirclePanel extends JPanel { | ||
|
||
JLabel label = new JLabel(); | ||
double x = 0; | ||
|
||
public CirclePanel(double x) { | ||
add(label); | ||
this.x = x; | ||
} | ||
|
||
public void setOffset(double offs) { | ||
this.x = offs; | ||
} | ||
|
||
@Override | ||
protected void paintComponent(Graphics g) { | ||
boolean isVisible = Config.getPref().getBoolean(LiveGPSPreferences.C_DISTANCE_VISUALISATION, false); | ||
|
||
super.paintComponent(g); | ||
if (isVisible == true) { | ||
Graphics2D g2 = (Graphics2D) g; | ||
|
||
int w = getWidth(); | ||
int h = getHeight(); | ||
|
||
double width = 0; | ||
if (w > h) { | ||
width = h*0.9; | ||
} else { | ||
width = w*0.9; | ||
} | ||
|
||
double y_start = (h/2.0) - (width/2); // center circle vertical | ||
double x_start = (w - width) / 2; // center circle horizontal | ||
|
||
// 3 rectangles | ||
Shape rect1 = new Rectangle2D.Double(x_start, y_start, width*0.4, width); | ||
Shape rect2 = new Rectangle2D.Double(x_start+width*0.4, y_start, width*0.2, width); | ||
Shape rect3 = new Rectangle2D.Double(x_start+width*0.6, y_start, width*0.4, width); | ||
|
||
// 1 circle | ||
Shape circle = new Ellipse2D.Double(x_start, y_start, width, width); | ||
|
||
// intersection | ||
Area rect1Area = new Area(rect1); | ||
Area rect2Area = new Area(rect2); | ||
Area rect3Area = new Area(rect3); | ||
|
||
Area circleArea1 = new Area(circle); | ||
Area circleArea2 = new Area(circle); | ||
Area circleArea3 = new Area(circle); | ||
|
||
circleArea1.intersect(rect1Area); | ||
circleArea2.intersect(rect2Area); | ||
circleArea3.intersect(rect3Area); | ||
|
||
g2.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); | ||
|
||
DrawPoint drawpoint = new DrawPoint(); | ||
drawpoint.draw_point(x, g2, circleArea1, circleArea2, circleArea3, label, x_start, y_start, width); | ||
|
||
g2.draw(circleArea1); | ||
g2.draw(circleArea2); | ||
g2.draw(circleArea3); | ||
|
||
// red center line | ||
g2.setColor(Color.red); | ||
g2.drawLine((int) (x_start+(width/2)), (int) y_start, (int) (x_start+(width/2)), (int) (y_start+width)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// License: Public Domain. For details, see LICENSE file. | ||
package livegps; | ||
|
||
import javax.swing.JPanel; | ||
import javax.swing.JLabel; | ||
|
||
import java.awt.Graphics2D; | ||
import java.awt.Color; | ||
import java.awt.geom.Area; | ||
|
||
import org.openstreetmap.josm.spi.preferences.Config; | ||
|
||
class DrawPoint extends JPanel { | ||
public double threshold = Config.getPref().getDouble(LiveGPSPreferences.C_OFFSET_THRESHOLD, LiveGPSPreferences.DEFAULT_THRESHOLD); | ||
int x_p = 0; | ||
int w = getWidth(); | ||
int h = getHeight(); | ||
|
||
public void draw_point(double x, Graphics2D g2, Area circleArea1, Area circleArea2, | ||
Area circleArea3, JLabel label, double x_start, double y_start, double width) { | ||
|
||
// x-value of black point | ||
if (x < -threshold) { | ||
x_p = (int) (x_start + (width*0.4) + (x*(width/100)) - ((width*0.15)/2)); | ||
if (x_p < x_start) { | ||
x_p = (int) x_start; | ||
} | ||
} else if (x > threshold) { | ||
x_p = (int) (x_start + (x*(width/100)) + (width*0.6) - ((width*0.15)/2)); | ||
if (x_p > x_start + width) { | ||
x_p = (int) (x_start + width); | ||
} | ||
} else if (x >= -threshold && x <= threshold) { | ||
x_p = (int) (x_start + (width/2) - ((width*0.15)/2)); | ||
} | ||
|
||
// fill area | ||
fill(x, x_p, g2, circleArea1, circleArea2, circleArea3, label, x_start, y_start, width); | ||
|
||
// black position point | ||
g2.setColor(Color.black); | ||
g2.fillOval(x_p, (int) (y_start+(width/2)-((width*0.15)/2)), (int) (width*0.15), (int) (width*0.15)); | ||
} | ||
|
||
public void fill(double x, int x_p, Graphics2D g2, Area circleArea1, Area circleArea2, Area circleArea3, | ||
JLabel label, double x_start, double y_start, double width) { | ||
|
||
Color yellow; | ||
Color green; | ||
yellow = new Color(255, 210, 50, 255); | ||
green = new Color(30, 200, 50, 255); | ||
|
||
// Distance from point to center line, rounded to 2 decimals | ||
double y = Math.round(x * 100.0) / 100.0; | ||
|
||
if (x < 0 && -x > threshold) { | ||
// left yellow + text | ||
g2.setColor(yellow); | ||
g2.fill(circleArea1); | ||
|
||
if (width/3 < 60) { // if label larger than half circle, place label outside the circle | ||
label.setBounds((int) (x_start - 60), (int) (y_start + width*0.3), 60, 10); | ||
} else { | ||
label.setBounds((int) (x_start + width*0.1), (int) (y_start + width*0.3), (int) (width/3), (int) (width/15)); | ||
} | ||
label.setText(y+" m"); | ||
|
||
} else if ((-x <= threshold && x <= 0) || (x <= threshold && x >= 0)) { | ||
// center green | ||
g2.setColor(green); | ||
g2.fill(circleArea2); | ||
label.setText(""); | ||
} else if (x > 0 && x > threshold) { | ||
// right yellow + text | ||
g2.setColor(yellow); | ||
g2.fill(circleArea3); | ||
|
||
if (width/3 < 60) { | ||
label.setBounds((int) (x_start + width*1.1), (int) (y_start + width*0.3), 60, 10); | ||
} else { | ||
label.setBounds((int) (x_start + width*0.7), (int) (y_start + width*0.3), (int) (width/3), (int) (width/15)); | ||
} | ||
label.setText("+"+y+" m"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.