-
Notifications
You must be signed in to change notification settings - Fork 4
Gui graphics kumar awijeet #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1a5dab1
4a2f14d
8968089
ce6a800
96e3769
62f860a
2958c5d
dfcdfcf
fdf8e75
85dfbca
e1ec5f2
cb706a2
e6b276c
c48f7b9
07aa8fc
0e173f6
b00e90f
770cb76
06a7ad3
6b09ddc
ae0f24c
dc510e2
26775ec
13ef310
34ce0d8
57100e9
105b0c9
4fe82d6
28ca852
3de9724
2891e94
feabfdb
6e248ac
23c3d11
ea44ac5
11e323f
d61c658
0651852
552f738
7aae3c0
5d6ef57
42b8d58
938a882
5215075
a416480
1ae338c
ec08426
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package kcl.teamIndexZero.traffic.gui; | ||
|
|
||
| import kcl.teamIndexZero.traffic.log.Logger_Interface; | ||
|
|
||
| import javax.imageio.ImageIO; | ||
| import java.awt.*; | ||
| import java.awt.geom.AffineTransform; | ||
| import java.io.BufferedInputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
|
|
||
| /** | ||
| * Created by kumar awijeet on 2/24/2016. thanks for Working!! | ||
| */ | ||
| public class GUI_Primitives { | ||
| protected static Logger_Interface log; | ||
| InputStream imageStream; | ||
| int j = 0, k = 0; | ||
| Image image, image1; | ||
|
|
||
| public void drawSmallCar(int x3, int y3, double angleToXAxis, Graphics2D g) throws IOException { | ||
| drawCar(x3, y3, angleToXAxis, "gui/src/main/resources/sprites/bmw_z_top_view_clip_art_18132.jpg", g); | ||
| } | ||
|
|
||
| public void drawTruck(int x3, int y3, double angleToXAxis, Graphics2D g) throws IOException { | ||
| drawCar(x3, y3, angleToXAxis, "gui/src/main/resources/sprites/8460_st0640_117.jpg", g); | ||
| } | ||
|
|
||
| private void drawCar(int x3, int y3, double angleToXAxis, String filename, Graphics2D g) throws IOException { | ||
| /* | ||
| Files taken from | ||
| http://all-free-download.com/free-vector/car-vector-top-view-download.html | ||
| http://hdimagelib.com/trailer+truck+top+view | ||
| */ | ||
| Graphics2D graphics = g; | ||
| AffineTransform originalTransform = graphics.getTransform(); | ||
| try { | ||
| AffineTransform newTransformation = new AffineTransform(); | ||
| newTransformation.rotate(angleToXAxis, x3, y3); | ||
| graphics.setTransform(newTransformation); | ||
| //InputStream imageStream; | ||
| if ((filename == "gui/src/main/resources/sprites/bmw_z_top_view_clip_art_18132.jpg") && (k == 0)) { | ||
| imageStream = new BufferedInputStream(getClass().getResourceAsStream(filename)); | ||
| image = ImageIO.read(imageStream); | ||
| graphics.drawImage(image, x3 - 18, y3 - 18, 40, 40, null); | ||
| k++; | ||
| } else if ((filename == "gui/src/main/resources/sprites/8460_st0640_117.jpg") && (j == 0)) { | ||
| imageStream = new BufferedInputStream(getClass().getResourceAsStream(filename)); | ||
| image1 = ImageIO.read(imageStream); | ||
| graphics.drawImage(image1, x3 - 18, y3 - 18, 40, 40, null); | ||
| j++; | ||
| } else { | ||
| if (filename == "gui/src/main/resources/sprites/8460_st0640_117.jpg") { | ||
| graphics.drawImage(image1, x3 - 18, y3 - 18, 40, 40, null); | ||
| } else if (filename == "gui/src/main/resources/sprites/bmw_z_top_view_clip_art_18132.jpg") { | ||
| graphics.drawImage(image, x3 - 18, y3 - 18, 40, 40, null); | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| if (e instanceof IOException) { | ||
| log.log_Fatal(e.getMessage(), "GUI_Primnitives"); | ||
| } | ||
| if (e instanceof IllegalArgumentException) { | ||
| log.log_Error("Check function, parameter passing error", "GUI_Primitives"); | ||
| } else { | ||
| log.log_Exception(e); | ||
| } | ||
| } finally { | ||
| graphics.setTransform(originalTransform); | ||
| if (imageStream != null) { | ||
| imageStream.close(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,5 +76,4 @@ private void startSimulatorWindow(OsmParseResult result) { | |
| LOG.log_Exception(e); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package kcl.teamIndexZero.traffic.gui; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import java.awt.*; | ||
| import java.awt.image.BufferedImage; | ||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Created by lexaux on 21/03/2016. | ||
| */ | ||
| public class GuiPrimitivesTest { | ||
|
|
||
| @Test | ||
| public void testDrawingPerformance() throws IOException { | ||
| // record time | ||
| GUI_Primitives primitives = new GUI_Primitives(); | ||
|
|
||
| long timestamp = System.currentTimeMillis(); | ||
| BufferedImage image = new BufferedImage(1000, 1000, BufferedImage.TYPE_INT_RGB); | ||
| Graphics2D g = (Graphics2D) image.getGraphics(); | ||
| int count = 25 * 500; | ||
| while (count-- > 0) { | ||
| if (count % 2 == 1) { | ||
| primitives.drawSmallCar(count, count, Math.random(), g); | ||
| } else { | ||
| primitives.drawTruck(count, count, Math.random(), g); | ||
| } | ||
| } | ||
|
|
||
| long diff = System.currentTimeMillis() - timestamp; | ||
| System.out.println(diff); | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| package kcl.teamIndexZero.traffic.log; | ||
|
|
||
| import kcl.teamIndexZero.traffic.log.fileIO.FileInput; | ||
| import kcl.teamIndexZero.traffic.log.FileIO.FileInput; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's bad.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
that's bad. —You are receiving this because you authored the thread.Reply to this email directly or view it on GitHub
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are you referring to? The double import statements? What is more surprising is that I didn't even touch the log files so don't know how did that end up there.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lexaux When I pulled a fresh version of the project on Kumar's laptop some of the packages you manually renamed to lowercase registered as the old uppercase ones. Weird behaviour.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@lexaux When I pulled a fresh version of the project on Kumar's laptop some of the packages you manually renamed to lowercase registered as the old uppercase ones. Weird behaviour. —You are receiving this because you were mentioned.Reply to this email directly or view it on GitHub
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay okay wait a sec gentlemen - I remember that problem.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@lexaux When I pulled a fresh version of the project on Kumar's laptop some of the packages you manually renamed to lowercase registered as the old uppercase ones. Weird behaviour. —You are receiving this because you were mentioned.Reply to this email directly or view it on GitHub
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
okay okay wait a sec gentlemen - I remember that problem. —You are receiving this because you were mentioned.Reply to this email directly or view it on GitHub
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
okay okay wait a sec gentlemen - I remember that problem. —You are receiving this because you were mentioned.Reply to this email directly or view it on GitHub |
||
| import kcl.teamIndexZero.traffic.log.fileIO.FileOutput; | ||
| import kcl.teamIndexZero.traffic.log.microLogger.MicroLogger; | ||
| import kcl.teamIndexZero.traffic.log.outputs.Output; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package kcl.teamIndexZero.traffic.log.fileIO; | ||
|
|
||
| import kcl.teamIndexZero.traffic.log.FileIO.FileInput; | ||
| import org.junit.After; | ||
| import org.junit.Test; | ||
|
|
||
|
|
@@ -24,7 +25,7 @@ public void tearDown() throws Exception { | |
|
|
||
| @Test | ||
| public void testRead() throws Exception { | ||
| FileOutput out = new FileOutput("", "testRead.test"); | ||
| kcl.teamIndexZero.traffic.log.fileIO.FileOutput out = new kcl.teamIndexZero.traffic.log.fileIO.FileOutput("", "testRead.test"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and that's not needed too
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
and that's not needed too —You are receiving this because you authored the thread.Reply to this email directly or view it on GitHub
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After having a look too I am unable to draw the cause of these, as I never edited the Log and other files. Let me know what can be done to make sure it is changes, won't touch it myself as of now because I might end up making it worse, so just tell me what to do in this, I will delete that specific line only. |
||
| out.appendString("String 1" + System.lineSeparator()); | ||
| out.appendString("String 2" + System.lineSeparator()); | ||
| out.appendString("String 3"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You got the point!
It should be faster now.
Instead of using extra variable for the flag, you could do much easier thing: check if the image itself is null or not. I.e.:
However, you will need to maintain separate variable for each of the image, and check if filename == one or another. What you could do instead, is use
Map<String, Image>, such as HashMap, to use store corresponding pairs of Path --> Image object, and the code would be like:Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You got the point!
It should be faster now.
Instead of using extra variable for the flag, you could do much easier thing: check if the image itself is null or not. I.e.:
public class Primitives {
...
private Image image1 = null;
...
public drawCar(..., filename ) {
if(image1 == null && filename = "/...car.png" ) {
... load image and file
image1 = ImageIO.read(...)
}
graphics.draw(... image);
}
However, you will need to maintain separate variable for each of the image, and check if filename == one or another. What you could do instead, is use Map<String, Image>, such as HashMap, to use store corresponding pairs of Path --> Image object, and the code would be like:
public class Primitives {
private Map<String, BufferedImage> imageCache = new HashMap<>();
...
public void drawCar(..., filename) {
if(!imageCache.containsKey(filename)) {
// load image,
BufferedImage im = ImageIO.read(...)
imageCache.put(filename, im);
}
im = imageCache.get(filename) // we are sure now that it exists, as if it would have not, we would have already loaded it
graphics.drawImage(im);
}
Does that make sense?
—You are receiving this because you were mentioned.Reply to this email directly or view it on GitHub
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You got the point!
It should be faster now.
Instead of using extra variable for the flag, you could do much easier thing: check if the image itself is null or not. I.e.:
public class Primitives {
...
private Image image1 = null;
...
public drawCar(..., filename ) {
if(image1 == null && filename = "/...car.png" ) {
... load image and file
image1 = ImageIO.read(...)
}
graphics.draw(... image);
}
However, you will need to maintain separate variable for each of the image, and check if filename == one or another. What you could do instead, is use Map<String, Image>, such as HashMap, to use store corresponding pairs of Path --> Image object, and the code would be like:
public class Primitives {
private Map<String, BufferedImage> imageCache = new HashMap<>();
...
public void drawCar(..., filename) {
if(!imageCache.containsKey(filename)) {
// load image,
BufferedImage im = ImageIO.read(...)
imageCache.put(filename, im);
}
im = imageCache.get(filename) // we are sure now that it exists, as if it would have not, we would have already loaded it
graphics.drawImage(im);
}
Does that make sense?
—You are receiving this because you were mentioned.Reply to this email directly or view it on GitHub