I am trying to use JXMapViewer (from swingx-ws) with Open Street Maps. I was wondering if it would be possible to display the map tiles in the JXMapViewer based on heading up, rather than on North up. For example, the normal car GPS navigation systems let you do that.
I've looked through the documentation and there doesn't seem to be a straightforward way to do this. Is there something else that accomplish this, besides JXMapViewer?
Nevermind, I found a solution. Here is how I did it(if anybody is interested) :
I subclassed JXMapViewer, and overrode the paint method.
In the paint method contents of the JPanel are converted to a BufferedImage which is then rotated according to an angle and then painted on top of the panel.
so super.paint()-> BufferedImage-> apply an affineTransformation to it-> draw the new Image.
Of course, you would also need to override the convertGeoPositionToPoint and convertPointToGeoPosition methods taking into account the fact that the image is rotated.
Related
For reference the effect I'm going for is this:
I'm working in Processing 3, NOT p5.js.
I've looked around processing forums, but i can't find anything that works in the current version or doesn't use PGraphics and a mask which from what I've read can be expensive to use.
My current ideas and implementations have resulted to drawing shapes around the player and filling the gaps in with a circles with no fill that has a large stroke weight.
Does anyone know of any methods to easily and inexpensively draw a black background over everything except a small circular area?
If this is the wrong place to ask this question just send me on my way I guess, but please be nice. Thank you:)
You could create an image (or PGraphics) that consists of mostly black, with a transparent circle in it. This is called image masking or alpha compositing. Doing a Google image search for "alpha composite" returns a bunch of the images I'm talking about.
Anyway, after you have the image, it's just a matter of drawing it on top of your scene wherever the player is. You might also use the PImage#mask() function. More info can be found in the reference.
Been building up a little game in java, already asked a few questions about the usage of JPanel in it, and used them to paint the graphics and the main part of the screens.
Now i have a little doubt about other components. My intention is to add on the corner a pair of bars to show health and mana of an entity (like in a rpg game), and wondered which was the best approach for it.
Thought about making a new JPnale with a pair of JProgressBar to set the ammount of it, but then i wondered if it would be better to paint it completely and fill a pair of rectangles.
I mean, doing a pair of new JProgressBar() for it, or a pair of g.fillRect() and then paint the ammounts.
I guess that easiest is to set the JProgress, as i can set values and text if i want, maybe, but not sure about it and if it would run smoother without overwhelming it with JComponents.
Also, if want to add buttons would be better the JButton, or paint a rectangle and check for containment of the mouse pointer with an event (I have this approach at some points where there is not KeyBinding). Should i change that?
Thank you beforehand :)
I'm writing an answer because i haven't got enough reputation to comment :(
I think is better if you paint it in your graphics engine. Use Rectangles is of course a better idea than use a new JPanel with JProgressBar.
But i think that it's even better if you use Images to build your own Progress Bar.
You can create them or find them on internet.
For example you can take an Image for the Progress Bar Background, and another Image for the Foreground (the part that will fill the Bar). Then you can set their X and Y position and then just change the Foreground Width in relation with the entity health to fill or empty the Progress Bar.
I heard SO people like diagrams so I took the time to draw one :D
I need to design an activity that roughly looks like the following:
The map is just an image file of city, terrain etc. Users are able to enter values inside the x-coord and y-coord textbox and when both of them have been entered, a triangular icon (also an image file) will appear on top of the map with respect to the coordinates on the map. The min,max of coordinates are fixed as 0,0 to 10000,10000 for all maps. Users can click the triangular icon (button) and it just takes them to another activity.
What is a sensible approach of designing something as above?
As far as I'm concerned, there are several things I need to take into consideration:
1)Mapping the coordinates with respect to the screen size. An obvious workaround for this is to use absolutelayout and use pixels for positioning the triangular icon, but this solution is terrible for obvious reasons.
2)Laying a button on top of the map (image file). After playing around with bunch of layouts, I couldn't figure out how to do this via Java.
I'm just looking for a really simple guidance, just to get myself going in the right direction.
I would use a SurfaceView. You can draw anything in the onDraw method. Youll get a Canvas object to draw on so it shouldn't be difficult to transform your coordinates and do what you want.
take a look at this tutorial:
http://www.mindfiresolutions.com/Using-Surface-View-for-Android-1659.php
I'd like to create shadow effects around my JComponent and especially around my JTextField's (JXTextField's since i use SwingX api).
I already know about the DropShadowBorder class from SwingX but it's not exactly what i want to achieve. I decided to do it myself by using rounded rectangle and gradients.
My idea is to create a rounded rectangle, apply a gradient to it and then draw the component on top of this rectangle with a given offset to create the shadow effect.
The problem is that i'm only aware of the GradientPaint class that allow me to specify start and end point of my gradient. Unless i'm wrong, i think i can't achieve this effect which such a gradient, i think i would need a gradient that start at the center and then fade toward the edges. Is there a way to do such a gradient with the actual API or do i need to write it myself?
Thanks.
EDIT: The is to do a text field that looks like:
The shadow is more important on the bottom than on the right and left sides.
There is no easy way to achieve exactly what you want.
To create an exact effect of such shadow you will have to do several things:
Paint a black/gray (color of your shadow) rounded rectanle on a separate image sized to component plus some additional spacing at the sides
Blur that image to create a shadow from the flat rounded rectangle
Render that image under the field by either using your own UI or just replacing field's paintComponent method
Let me explain each step a bit more:
You need a separate image so that the background/component won't get blurred together with the shadow. Plus you cannot apply any filter directly to the Graphics - you need an Image.
You can read a good explanation of how-to-blur here: http://www.jhlabs.com/ip/blurring.html
You need to place (paint) the shadow image before the component itself and that is possible in two ways: paint it on the panel/container that contains the field or replace the field paintComponent method or UI itself.
If you need a radial gradient, there is one: RadialGradientPaint
http://docs.oracle.com/javase/6/docs/api/java/awt/RadialGradientPaint.html
(You specify a center point and a radius here)
BTW, what's wrong with DropShadowBorder? (it is very similar to what you want, and you could always take the source code and modify it)
I'm willing to make a isometric game but I'm having hard time with the mouseListener.
I'm using Swing and make losanges by using square images with transparent pixels (GIF format).
The problem is that making losanges touch each other edge means having the transparent pixels of one on the top of the others, which is a problem with the mouseListener.
I'm willing to know exactly which losange was clicked on, but as the transparent pixels of the nearby losange get on the top of the one that was clicked on, the wrong losange is selected as the KeyEvent source.
Is there a way to have mouseListener not considering transparent pixels as part of the shape ?
Thanks for reading.
It's not clear
1) why the tiles have to overlap, or
2) why you're using JLabels for the tiles
There's are many ways to solve the problem you're having, but I'd just make a single JComponent that renders the tiles as needed, and is the sole MouseListener.
As mentioned by Jonathan, I think you're using the wrong technology for the job. I've had great success using a 2D graphics framework for software such as this. In my case I'm a big fan of Piccolo. I know you don't want to hear this, but consider starting over with the appropriate toolset.