Good afternoon, habrazhitel!
I'm sure with the nine-patch format everyone has long been familiar with, probably even used it more than once in their Android projects (and maybe even somewhere else). Also about it a little less than a year ago,
skkap wrote a short
article about what kind of format it is and “what it is eaten with.” He also described the tool offered for quick editing of these very files.
Actually, almost a year has passed since that moment, and I stumbled upon that article again and, recalling complaints from my friends about the inconvenience of this very “tool,” decided to see if there were any other options and, to my great surprise, I did not find any. Probably because the format doesn’t represent anything complex and specific (if desired, nine-patch files can be edited in almost any graphical editor that supports png) and, all the more, there is already a ready-made tool (albeit not the most convenient).
')
Then I decided to personally get down to business ...
First sketches
So, in a few days on the basis of my own developed
library I managed to achieve quite good, I think, results - I would like to share them with you. Let all angles have not been smoothed out, there are some flaws and, possibly, bugs (well, where there are none), but still ...
Actually, the very small editor application looks like this:

Several advantages compared to the previously mentioned "ancient" tulza:
- The ability to quickly change nine-patch data by simply moving / changing guides and areas
- Display pixel strip and the distance between the individual guides on the area
- Customizable preview of the final file dynamically updated when editing
- Recognition of nine-patch data on images that do not have a ".9" in the name, as well as the ability to download simple images for quick conversion to nine-patch format
- The ability to download any image formats supported in J2SE, in addition to png
These are advantages related solely to editing nine-patch files in a ready-made visual editor. The jar file of the application itself can be used as a plug-in library for parsing nine-patch images, embedding the editor in your own Java applications, styling components and much more, but I will not spray it - I’ll talk about this in a separate an article in the java blog for anyone interested.
A little description ...
Actually, when working with this editor you will have to deal with several parts of it ...
Main toolbar
Opening an image (you can also simply drag and drop any file directly to the editor)
Quick save of previously opened image
Saving nine-patch images to a new location.
Dialog of preview of the image (about it further)
Whether to display distance between guides
Whether to show the ruler on the editing area
Show content area
Whether to show stretchable areas
Editor
- For zoom'a area, you can use the combination of Ctrl (or Alt) + Mouse wheel
- By moving the guides, you can quickly edit areas (within acceptable limits)
- You can drag areas beyond the black lines along the edges, or outside the area inside the image.
- You can add new stretchable areas by pinching the left mouse button on the left or on the top of the image.
- Erase stretchable areas can be clamped with the right mouse button to the left or top of the image
- You can move the area (if a scroll appears) by clamping the middle mouse button (wheel)
Image preview
- You can resize it around the image
- On the upper toolbar, you can customize the text and icon displayed in the image.
- On the bottom toolbar, you can customize the background under the image
Compresses the image to the minimum size based on the content
In general, that's all. You can see and feel the rest by launching the application on your own.
By the way, by default, this image opens for editing:
Actually, the application:Running jar



Naturally, you will need
jre installed on your OS to run.
The application should work on any OS where JDK 1.6.20+ (or OpenJDK) is available.
In custody
I hope those who often work with nine-patch files this editor will help make life easier :)
Naturally, the editor will continue to develop little by little with the library if there are good suggestions for improving it.
Speaking of birds, the
Web Look and Feel library itself, as well as this editor, written on its basis, are distributed under the
GPLv3 license and have completely open source code.
Since the newer version of the library on which this editor is based has not yet been released - you can download the
source directly from here:
http://weblookandfeel.com/downloads/ninepatch-sources.zipA library
distribution without source from here:
http://weblookandfeel.com/downloads/ninepatch.jarI will also be happy to hear any comments and suggestions and ...
Thank you for your attention!
# Update
After a few comments, as well as finding a couple of bugs, I made small changes to the library and editor, which was actually changed:
- Combined with the editor preview of the final 9-patch image
- Ability to select the text color in the preview
- Ability to copy 9-patch data from one editor to another
- Saving all editor settings when closing
- Possibility of multiline text in the preview ("\ n" or ";" separate lines)
- Binding the movement of the dialog previews to the editor's dialogue
- Added slider and buttons for zoom'a area on the lower toolbar
- The file name is automatically added to the mark ".9" when saving, if there is none
I am also aware of the last remaining problem - incorrect work of the file selector. This problem will be fixed a little later, along with the release of the next version of the Web Look and Feel library.
You can download binaries and sources from the old links - they have already been updated:
Running jar | Source code | Net library