├── .hgignore ├── CHANGES ├── COPYING ├── INSTALL ├── MANIFEST.MF ├── README ├── SUGGESTIONS ├── TODO ├── build.xml ├── examples ├── desert.tmx ├── hexmap.tmx ├── iso-test.tmx ├── iso-test2.tmx ├── iso-test3.tmx ├── iso-test4.tmx ├── sewer_tileset.png ├── snowy_trees.tmx ├── tilebmp-test.tmx ├── tilespacing-test.tmx ├── tmw_desert_spacing.png └── water.tsx ├── nbproject ├── genfiles.properties ├── project.properties └── project.xml ├── plugins ├── build.xml ├── json │ ├── MANIFEST.MF │ ├── build.xml │ ├── nbproject │ │ ├── genfiles.properties │ │ ├── project.properties │ │ └── project.xml │ └── src │ │ ├── org │ │ └── json │ │ │ ├── CDL.java │ │ │ ├── Cookie.java │ │ │ ├── CookieList.java │ │ │ ├── HTTP.java │ │ │ ├── HTTPTokener.java │ │ │ ├── JSONArray.java │ │ │ ├── JSONObject.java │ │ │ ├── JSONTokener.java │ │ │ ├── Test.java │ │ │ ├── XML.java │ │ │ └── XMLTokener.java │ │ └── tiled │ │ └── plugins │ │ └── json │ │ ├── JSONMapWriter.java │ │ └── JSONUtils.java ├── lua │ ├── MANIFEST.MF │ ├── build.xml │ ├── nbproject │ │ ├── genfiles.properties │ │ ├── project.properties │ │ └── project.xml │ └── src │ │ └── tiled │ │ └── plugins │ │ └── lua │ │ └── LuaMapWriter.java ├── mappy │ ├── MANIFEST.MF │ ├── build.xml │ ├── nbproject │ │ ├── genfiles.properties │ │ ├── project.properties │ │ └── project.xml │ └── src │ │ └── tiled │ │ └── plugins │ │ └── mappy │ │ ├── Chunk.java │ │ ├── MappyMapReader.java │ │ ├── MappyMapWriter.java │ │ └── Util.java └── tmw │ ├── MANIFEST.MF │ ├── build.xml │ ├── nbproject │ ├── genfiles.properties │ ├── project.properties │ └── project.xml │ └── src │ └── tiled │ └── plugins │ └── tmw │ ├── TMWServerMapWriter.java │ └── WLKWriter.java ├── prototypes ├── PLUGIN.MF ├── TMX-format.txt ├── cave.tsx ├── garden.tsx ├── garden01.tmx └── garden_ext.tsx └── src └── tiled ├── Main.java ├── command ├── Command.java ├── CommandInterpreter.java ├── HelpCommand.java ├── OpenCommand.java └── SaveCommand.java ├── core ├── AnimatedTile.java ├── LayerLockedException.java ├── Map.java ├── MapChangeAdapter.java ├── MapChangeListener.java ├── MapChangedEvent.java ├── MapLayer.java ├── MapLayerChangeEvent.java ├── MapLayerChangeListener.java ├── MapObject.java ├── MapParallaxChangeEvent.java ├── MapParallaxChangeListener.java ├── MultilayerPlane.java ├── ObjectGroup.java ├── Sprite.java ├── Tile.java ├── TileLayer.java ├── TileSet.java ├── TilesetChangeListener.java └── TilesetChangedEvent.java ├── io ├── ImageHelper.java ├── MapHelper.java ├── MapReader.java ├── MapWriter.java ├── PluggableMapIO.java ├── PluginLogger.java └── xml │ ├── XMLMapTransformer.java │ ├── XMLMapWriter.java │ ├── XMLWriter.java │ └── XMLWriterException.java ├── mapeditor ├── MapEditor.java ├── Resources.java ├── actions │ ├── AbstractFileAction.java │ ├── AbstractLayerAction.java │ ├── AddLayerAction.java │ ├── AddObjectGroupAction.java │ ├── CloneLayerAction.java │ ├── CloseMapAction.java │ ├── DeleteLayerAction.java │ ├── ExitAction.java │ ├── MergeAllLayersAction.java │ ├── MergeLayerDownAction.java │ ├── MoveLayerDownAction.java │ ├── MoveLayerUpAction.java │ ├── NewMapAction.java │ ├── OpenMapAction.java │ ├── OpenRecentAction.java │ ├── SaveAction.java │ ├── SaveAsAction.java │ ├── SaveAsImageAction.java │ └── ShowLayerPropertiesAction.java ├── animation │ ├── AnimationDialog.java │ └── KeyDialog.java ├── brush │ ├── AbstractBrush.java │ ├── Brush.java │ ├── BrushException.java │ ├── CustomBrush.java │ ├── LayerInvisibleBrushException.java │ ├── LayerLockedBrushException.java │ ├── RandomBrush.java │ └── ShapeBrush.java ├── dialogs │ ├── AboutDialog.java │ ├── BrushDialog.java │ ├── ConfigurationDialog.java │ ├── ImageColorDialog.java │ ├── LayerPropertiesDialog.java │ ├── MapPropertiesDialog.java │ ├── NewMapDialog.java │ ├── NewTilesetDialog.java │ ├── ObjectDialog.java │ ├── PluginDialog.java │ ├── PluginLogDialog.java │ ├── PropertiesDialog.java │ ├── ResizeDialog.java │ ├── SearchDialog.java │ ├── TileDialog.java │ ├── TileImageDialog.java │ ├── TileInstancePropertiesDialog.java │ └── TilesetManager.java ├── dungeon │ ├── Builder.java │ └── CorridorBuilder.java ├── plugin │ ├── PluginClassLoader.java │ └── TiledPlugin.java ├── resources │ ├── back.png │ ├── cursor-pencil.png │ ├── document-save-as.png │ ├── document-save.png │ ├── empty.png │ ├── forward.png │ ├── gimp-duplicate-16.png │ ├── gimp-flip-horizontal-16.png │ ├── gimp-flip-vertical-16.png │ ├── gimp-rotate-180-16.png │ ├── gimp-rotate-270-16.png │ ├── gimp-rotate-90-16.png │ ├── gimp-tool-bucket-fill-22.png │ ├── gimp-tool-color-picker-22.png │ ├── gimp-tool-eraser-22.png │ ├── gimp-tool-move-22.png │ ├── gimp-tool-object-move-22.png │ ├── gimp-tool-pencil-22.png │ ├── gimp-tool-rect-select-22.png │ ├── gnome-delete.png │ ├── gnome-down.png │ ├── gnome-list-add-22.png │ ├── gnome-list-remove-22.png │ ├── gnome-new.png │ ├── gnome-up.png │ ├── gnome-zoom-in.png │ ├── gnome-zoom-out.png │ ├── gtk-edit.png │ ├── gui.properties │ ├── gui_de.properties │ ├── gui_es.properties │ ├── gui_fr.properties │ ├── gui_it.properties │ ├── gui_nl.properties │ ├── insert-object.png │ ├── lastframe.png │ ├── logo.png │ ├── map.dtd │ ├── map.xsd │ ├── play.png │ ├── propertyflag-12.png │ ├── source.png │ ├── startframe.png │ ├── stock_animation.png │ ├── stop.png │ └── visible.png ├── selection │ ├── ObjectSelection.java │ ├── ObjectSelectionToolSemantic.java │ ├── Selection.java │ ├── SelectionLayer.java │ ├── SelectionSet.java │ ├── SelectionSetListener.java │ └── ToolSemantic.java ├── undo │ ├── AddObjectEdit.java │ ├── ChangeObjectEdit.java │ ├── ChangePropertiesEdit.java │ ├── DeleteLayerEdit.java │ ├── LayerResizeEdit.java │ ├── MapLayerEdit.java │ ├── MapLayerStateEdit.java │ ├── MapLayerViewportSettingsEdit.java │ ├── MapViewportSettingsEdit.java │ ├── MoveLayerEdit.java │ ├── MoveObjectEdit.java │ ├── RemoveObjectEdit.java │ └── UndoHandler.java ├── util │ ├── ConfirmableFileFilter.java │ ├── ConfirmingFileChooser.java │ ├── ImageCellRenderer.java │ ├── LayerTableModel.java │ ├── MapEventAdapter.java │ ├── MultisetListRenderer.java │ ├── PropertiesTableModel.java │ ├── TileDialogListRenderer.java │ ├── TileRegionSelectionEvent.java │ ├── TileSelectionEvent.java │ ├── TileSelectionListener.java │ ├── TiledFileFilter.java │ ├── TilesetTableModel.java │ ├── TransparentImageFilter.java │ └── cutter │ │ ├── BasicTileCutter.java │ │ ├── BorderTileCutter.java │ │ └── TileCutter.java └── widget │ ├── BrushBrowser.java │ ├── BrushPreview.java │ ├── ColorButton.java │ ├── FloatDocument.java │ ├── FloatablePanel.java │ ├── ImageViewPanel.java │ ├── IntegerSpinner.java │ ├── LayerParallaxDistancePanel.form │ ├── LayerParallaxDistancePanel.java │ ├── MiniMapViewer.java │ ├── ParallaxEditorPanel.form │ ├── ParallaxEditorPanel.java │ ├── ResizePanel.java │ ├── SmartSplitPane.java │ ├── TButton.java │ ├── TMenuItem.java │ ├── TabbedTilesetsPane.java │ ├── TilePalettePanel.java │ ├── TimedStatusLabel.java │ └── VerticalStaticJPanel.java ├── util ├── Base64.java ├── MersenneTwister.java ├── NumberedSet.java ├── OverriddenPreferences.java ├── TileMergeHelper.java ├── TiledConfiguration.java ├── TiledProperty.java └── Util.java └── view ├── HexMapView.java ├── IsoMapView.java ├── MapView.java ├── OrthoMapView.java └── ShiftedMapView.java /.hgignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | *.class 3 | *.jar 4 | build/* 5 | docs/* 6 | intellij/* 7 | docs/api/* 8 | releases/*.zip 9 | \.orig\..*$ 10 | \.orig$ 11 | \.chg\..*$ 12 | \.rej$ 13 | \.conflict\~$ 14 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | ---------------- 2 | BUILDING TILED 3 | ---------------- 4 | 5 | NOTE: If you have downloaded the binary archive (bin), then you can skip this 6 | as you will already have the tiled.jar file. Continue to "Running Tiled" below. 7 | 8 | Take the following steps to build Tiled from source: 9 | 10 | - Install the JDK (http://java.sun.com/) 11 | - Install apache-ant (http://ant.apache.org/) 12 | - Run ant in the directory where you placed Tiled 13 | 14 | --------------- 15 | RUNNING TILED 16 | --------------- 17 | 18 | - Install the Java Runtime Environment (JRE) (http://java.sun.com/) 19 | 20 | - From the command line, you can run the following from the directory where you 21 | placed Tiled: 22 | 23 | cd dist (if you have compiled Tiled yourself) 24 | java -jar tiled.jar 25 | 26 | - You can also use the Java webstart link on the website, see "Start Now!" 27 | 28 | - Windows users that have the JRE installed should be able to double click the 29 | tiled.jar file to run it. 30 | -------------------------------------------------------------------------------- /MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Created-By: 1.4.1_05 (Sun Microsystems Inc.) 3 | Main-Class: tiled.Main 4 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | ------------------------ 2 | TILED MAP EDITOR 0.7.x 3 | ------------------------ 4 | 5 | This is Tiled, a general purpose tiled map editor. Although this release is 6 | pretty capable and flexible, we don't expect it to be able to do enough for 7 | most people at the moment. We need your feedback! 8 | 9 | 10 | Website: http://mapeditor.org/ 11 | Bugtracker: http://bugs.mapeditor.org/ 12 | Mercurial: http://hg.mapeditor.org/ 13 | 14 | ----------------- 15 | CURRENT FEATURES 16 | ----------------- 17 | 18 | - Multilayer, layers can be changed around dynamically 19 | - Multiple orientations (orthographic and isometric at the moment) 20 | - Objects can be placed anywhere on the map 21 | - Arbitrary custom properties can be set on the maps, layers, objects and tiles 22 | - Tiles can be taller than the default tile height 23 | - Easy to use drawing operations 24 | - Universal XML-based map and tileset file formats 25 | - Can embed tiles in the map or tileset file 26 | - Highly portable and free software 27 | - Maps may include tiles from multiple tilesets 28 | - Ability to write custom Map reader/writer plugins 29 | 30 | --------- 31 | AUTHORS 32 | --------- 33 | 34 | - Adam Turk 35 | - Bjorn Lindeijer 36 | 37 | ----------- 38 | TRANSLATORS 39 | ----------- 40 | 41 | - Nader Akhres (French) 42 | - Bjorn Lindeijer (Dutch) 43 | - ElvenProgrammer (Italian) 44 | - Matthias Hartmann (German) 45 | - Alexandra Puente (Spanish) 46 | 47 | ----------- 48 | THANKS TO 49 | ----------- 50 | 51 | (In no particular order) 52 | - Frode Lindeijer for the design of the logo 53 | - Eean Cook for various contributions 54 | - Andreas Mross for Hexagonal map implementation 55 | - Ahmed Mohombe for many good suggestions and notes on implementation 56 | - Rickard Isaksson for an improved image loader 57 | - Kevin Kelley for the base64 encoder/decoder we use 58 | - GNOME and GIMP for their magnificent icons 59 | - Nephilim for suggesting layer opacity 60 | - Rainer Deyke for useful suggestions and many code contributions 61 | - Jerome Blouin for some meticulous performance testing 62 | - Hendrik Brummermann for improving error reporting on map loading 63 | - Nader Akhres for the JSON map writer plugin 64 | - William C. Bubel for the Lua map writer plugin 65 | - Matthias Kievernagel for a nice HexMapView 66 | - Olivier Beaton for the DTD and Schema files describing the TMX format 67 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | ROADMAP TO FUTURE RELEASES 2 | 3 | 0.7.3 4 | * Check that tile palette panel doesn't keep listening after being replaced 5 | * Update translations for dialog.saveas.confirm.mismatch 6 | * Make continuous layout and tiles per row behaviour configurable 7 | * Fix default tabbed tilesets panel height 8 | * Fix redraw issue on empty area in tile palette panel 9 | * Do not reset brush when switching tools (but do show a small tile highlight 10 | while other tools than stamp brush are selected) 11 | + Add Shift-Ctrl-C deep copy (Copies all layers into a new one) 12 | * Add custom brush from selection (via Ctrl-B) 13 | 14 | 0.8.0 15 | * Add support for animated tiles 16 | * Set up a layer->map->mapview changes event trail to automatically handle 17 | repainting changes in all views on the map. 18 | * Add minimap above layer table 19 | * Pretty brush preview 20 | 21 | 0.9.0 22 | * Introduce concept of a project 23 | * Add concept of 'textures' and automatic texture transitions using smart brush 24 | * Store stamp brushes and texture transition definitions to project 25 | 26 | 1.0.0 27 | * Tool plugins 28 | * Fix all remaining issues. 29 | 30 | GENERAL TODO ITEMS 31 | 32 | * Add a brush preview widget 33 | * Add support for tile instance properties (by Christian Henz) (WIP) 34 | - Implement an effective way of displaying the presence of these properties 35 | * Fix memory problems when loading several maps with many tilesets in a row 36 | * Add ability to select multiple layers from layer table 37 | * Add preview of new tileset when creating a tileset 38 | * Add the Shifted view, which emulates several tiling configurations 39 | * Add additional "tile cutters" 40 | * Rewrite main mapeditor code 41 | * Move actions out of MapEditor, and created a package for them 42 | * Reintroduce usage counts in tileset manager without performance issues 43 | * Add convenient map resizing preview widget 44 | * Turning on/off layer visibility shouldn't select them 45 | * Allow mapviews to have parameters 46 | * Start open image in new tileset dialog at map location when possible. 47 | * Add offset settings to New Tileset dialog and tileset xml tag 48 | * Look into making selections more efficient by not using a tile layer 49 | * See about using real numbers for tile positioning with isometric 50 | * Look into color button on New Tileset dialog 51 | * Try to generalize color button for setting grid and background color 52 | settings. Change Grid to Display tab with Grid and Colors groups. 53 | -------------------------------------------------------------------------------- /examples/hexmap.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | iVBORw0KGgoAAAANSUhEUgAAADEAAAAsCAYAAADM1FBZAAADjUlEQVR42s1ZsYHbMAxk4SLFFyl+hB8gRYovU36RIk3KFCldagQPoBFSaAUP4AG8lPOECOgAgRJli5LdSBZECCQOwBEMYeHv5ePr7cfb4Xbowi3ex+uhTfencPv57fN6Cf3zJtw+h4gs3qOM9Jz7MSTr+meh9i9+PBpEhiVDyPBjkMnR/6Z/h54d07NkJI8TudFZfQJkzLk34vXXsOrxf/vne28UGIQyGmtkPFn2SNRZbQIMHVw9gsAprW4L0LkGDbl2WPmRLHkOPcSwrDEP+RB5oOuv9OwCRiYD4j0bl5PhgqDOGhMYgjVBgDH/7+/7AI02KMzL/cWX0TjQybKokzycdK42CVqlRjKHhhV4hFeTZTguJ2OP5HSuMoGosPl4E+XKG5gqkxGC7zSO34sygWRGJ3/P6nxoAvxRdi8r5rRJ16sOXsw4Ah8jkxhpgqoPkoqNzsdjwXyY06SaEKRehISqIxmZPDsN2QoXLRpy90Q4GFUAXgbIYIpUE2oBbjZwPZnRqQpmp9L38h/mbvsBSa3XAW74LlZzmWwD9KIZG2t1vv7+onQu9obAxeE5CAmBRjsUKW9cTubBDHViMV3sBQ/vludwrZCVP/pxwrIS7mRX3tNZPAGZiMNzaHUc7hTfi/yIV8/jTjmd6JESPlYU0LKC1zByM66eylRT/MjotDE2pdPaUhzQlucwseOgnONOmI4td+J71ulxJ86IGVtm4mCOAzncie95nPAehzvJu7kUnHTO2cLbgjGMCjnQFM+Z4kdr6xxBSwVYZ7JRhufYyosfYj04zpMhI7A6S23xNz4t7J0bvWFRldrhOZamINRQhrHABhEMHT42Z4vyhFJ61m7GnK92cxADvMW046TYTXCnHB8rsIUKc5jjQCqoM9zJ8hwvcOk/Br/RifuUpbb0nki5O/IVLijocqsYeQ4VKOA5HlRG3Y8ZPlZiCyYjRTOQA9kekcdzavWdltiiWjGCu6OPTSx2tftOhbbka4XlK1igtuo75XRaW1z6zcGHHAgL0dZ9pylbZukH4huhtGXfydOJUCraliJf2bPv5NlStJ+Y4Sub9p28ccV9V0x7e/ed2Ja7tqdq9XfsOxlblnc89u47cTq/q8n8bH0nxVgXw+pJ+k6PnQ49Qd9ptSOuPftO6x027tR3Wu/AEfj71n2naieoW/Sd6p5hV+47YVbc7ii4Qt+p7mH8Bn2ne+z6D4sUaiE8Ubh4AAAAAElFTkSuQmCC 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | H4sIAAAAAAAAAO3DAQkAAAwEofv+pddjKLhqqqqq6usHHB1pSAAQAAA= 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/iso-test2.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | iVBORw0KGgoAAAANSUhEUgAAAEAAAAAgCAYAAACinX6EAAAB3klEQVR42u2Z7StEQRjFT3a9RlgRkkTyBykRSYiiSHbb9Zo2Wfa/IUmSFCXJZyWJvP4Zzpn5ZPbDtu377jx12tvcmec5v9m9d+feAYoTNdQYEHyy0rFpq/gQ5AShn4G2R2A0aaVjtelcZU5EgJrixwsQeuAXfggcLf2X2nROfdTXjCn7CFIzZHkFOu6B8YNUcFfqo74ao7EmR9lFLTVPiDeg8w6Y3E8P7kpjNFY5lMvkLPmooxZp+h3ougWm45mDu1IO5VJO5TY1Si7qKZoNfADdN8DsXvbgrpRTuVVDtUzNokcDtUJTn0DPNTC3m3twV6qhWqqp2sZDwaORWqOJL6D3CljYyT+4K9VUbXmQF+Mp79FERVj0G+i75C9xq/DgruRBXuRJ3ozHnEcz1ycbtkj/BbC8WXxwV/Ikb/Ior/KcfbQw2TaT/gAD58BqrPTAXcmjvMqzvIsh82jlYN51A7/A4BmTRksfPGUiota7GMQipvTRzs5xO2joFAhHyg/clRjEYiYibhlTI8STCfuzGT7hvSRc/uCuxCQ2c2kkLLNdridt48gxEFuvPHBXYhSrmMXuJ6DqLwF/E/R/g34h5JfC/mHIPw77FyL+lZh/Kepfi/uNEb815jdHq257/A8rj91mixMZJgAAAABJRU5ErkJggg== 9 | 10 | 11 | 12 | 13 | 14 | 15 | iVBORw0KGgoAAAANSUhEUgAAAEAAAAAlCAYAAADyUO83AAAD9ElEQVR42t2aWU8TURTHDxZ9xWA0GnHXGD+CPqhPGlETlbKFHSMY4wNSlMV9gbaDIPAF9AlFvoEvIFiQAvrovsbER5cvgOd/79RlOjN3GEtnpic5mcn0nnP+v39vpwsQeRN5nGGi/BcycS6u5XwAsoyhXxKtfEZUosnEOa7hsdw0YhlnOUO+Yth5CR0/828KI+blGqwVNTkBXsFQr4kK53inx9LBjYk1WIsa1AbTCIiu1MFn+QmNqsGNiRrUCiMqg2IERFYRhd6w+KQavLdFptKIpOyJ3v40IsRZzYe3RKtmeOd2q8HjfUTasEycq4xAT/TGDMwSM30BXsOHdyzuKT9Bt9TgWr8O/sCQw/IxlRGYgVmYidneGIGhdXx4T7R6Wg2unbMBtzACNSojMBsaoCU7RuRzNvCsDzx8ip+Am87A4/cdgBtS1DgwAhqgBZqgTWhcEvBGHTxBVHtDsdVb+XjHHbiZEegletrMhCZoE0Y0ZsoINDnJTT8SrXnCBl/PHrhbI6ARWqEZ2t0ZsZzzFDf5RLR2kg295h24WyOgGdrBABbB5Ai8SQefcAauDWQH3PQeMeDQiAndiCYrI3CxWQd/zDvniuKTWoRz0Btw0x0xqGuy0QwmsAkjmv824jRf/Ey0bjxY4P9jBFjBDHYKjRKt+Eq05y5R9Kw1uDbkT3DTl8aQtRFgBCuYwS5jF98sYQS7svveHyO0tuCAWxkBhhQ42MAIVjCnx05+aYwQFXwhKn1E1DMSPHBjggEsYAIbGC2jv5CLDhC1XCU6xN/J93/ju+hMMI2AZmgHA1jABDYwmoLHDqa/Xlr5LaQ4KZvUc7PoQ/+DQ2O9Dg7trSZv5WD9bUSsgAsr7e+cEb5zFnPTfdy0IelPI6AJ2qARWiOKdzQwg13EQh5f2LEII76zyzysxwdGQAO0QJNTcLAumP346tSItstER6bl0LpZb4zATMyGBmiBJtfgZkZEt/PHzAr7pucvER2e0o2Yy44RAnxOzsRsaLD9uF4hWRbc/tyubeMsd2BEQoqqhRGjSwA+KnsL8IQaHJqhPWOBZr1l9kMvXOTtqBtRN58ZI9ADvcRWT8gZts94WYbBjRHdqjaivYvFTkrRNSy+24URqKlJgU/KnipwaMta9G5hoaUOjOCvont/ODciBY4a1KrAoQFaPIvoZrURHZ1ER8clVPVzcyNwDY9hDdaiRgWO2b6J25tYWNhedGcHw41JyCrdCGRVCnxMrrH9Sh6Ws3wbTozoateN+CkT57gWaHBjxDbyNi1RG6ECRw/0Cmz0bWCQE4v/4yhqUJszES/iu/VxNbhYU5TD/yRiZUTOg6f9BrGegY/JxLk38Quqva98Bot+bAAAAABJRU5ErkJggg== 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | H4sIAAAAAAAAAO3DwQkAAAwDoSP7D90x+lFw1VRVVVVVVVVVVVVVVVVVVdXXB2sNXEYAQAAA 24 | 25 | 26 | 27 | 28 | H4sIAAAAAAAAAO3WQQrAIBAEQWH//+ccIxIfELoKFs/jOuBawGxTc2au3cF8DB1zOSvk139e9f3X8ut/m/9v+/3X919X37f+AwAAAAAAAAAAAMA/PMMCaKAAQAAA 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /examples/iso-test4.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | H4sIAAAAAAAAAO3DQQ0AAAwDoat/05OxDySsmqqqqqqqqqqqqqqqqqqqqvr6AFA+aDAAQAAA 9 | 10 | 11 | 12 | 13 | H4sIAAAAAAAAAO3SMQqAMAxAUYeiZxC8/znVoeAiFhVKmvcgW4b+0GkCAAAAgPdK7wd0UG5mZHfNGW7Q2j7iHd60j3SDL/3Rb/C1XX9sT23zMVvDXlRPXcsxa8NeVH/8f/2xZe8/Ze+vMrdfZe+vsnYDAAAAAAAA9LAD/njXxQBAAAA= 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/sewer_tileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/examples/sewer_tileset.png -------------------------------------------------------------------------------- /examples/tilebmp-test.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | H4sIAAAAAAAAAO3POwoCMRiF0cHOJ/jAahpHLNT9788r5IfgCiSc4kBuIJBvnqZp7txiF/s4xNLturv/vBnJt/8Sq7i2/tp1N3r/Ojaxbf21y+j9xzjFufXXLiP3P+PVPLpz7/0H/wQAAAAAAAAAAAAAAAAAgBF9AJgOlPoAQAAA 22 | 23 | 24 | 25 | 26 | H4sIAAAAAAAAAO3PsQ0AMAgDQaZKE7H/WpmBKhK+k+go/FUzZ/i/jf5s+rPpz6Z/lzu8/jMTAAAAAAAAAAAAAAAAgDAPGg5TPgBAAAA= 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /examples/tilespacing-test.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | H4sIAAAAAAAAAO3TTQ+CMAwG4KIn8aSelIRE4IIf/P+fZ5dsoTQlqXPlYHp4krFA361sAwA8lJ6oLSzUnAzq5qrQTrA3ymvY8wHVgqNRfp+Zf0W3uP40pvi+SuffURe/T2OK19Xmn9BZcGHvjTDfiTTOuSvadXK0/5r5Nbl3mvZfM1/aWg79L1bZocfvmP+C5Zn/tv+/7F0681v0P2QMIJ/5Lfo/Gtd3zjnnnPtnH/8uAvwAEAAA 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/tmw_desert_spacing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/examples/tmw_desert_spacing.png -------------------------------------------------------------------------------- /nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | nbbuild.xml.data.CRC32=10b66c50 2 | nbbuild.xml.script.CRC32=4c82b3b6 3 | nbbuild.xml.stylesheet.CRC32=be360661 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=10b66c50 7 | nbproject/build-impl.xml.script.CRC32=1517c8fc 8 | nbproject/build-impl.xml.stylesheet.CRC32=487672f9 9 | -------------------------------------------------------------------------------- /nbproject/project.properties: -------------------------------------------------------------------------------- 1 | application.title=tiled 2 | application.vendor=upachler 3 | build.classes.dir=${build.dir}/classes 4 | build.classes.excludes=**/*.java,**/*.form 5 | # This directory is removed when the project is cleaned: 6 | build.dir=build 7 | build.generated.dir=${build.dir}/generated 8 | # Only compile against the classpath explicitly listed here: 9 | build.sysclasspath=ignore 10 | build.test.classes.dir=${build.dir}/test/classes 11 | build.test.results.dir=${build.dir}/test/results 12 | buildfile=nbbuild.xml 13 | debug.classpath=\ 14 | ${run.classpath} 15 | debug.test.classpath=\ 16 | ${run.test.classpath} 17 | # This directory is removed when the project is cleaned: 18 | dist.dir=dist 19 | dist.jar=${dist.dir}/tiled.jar 20 | dist.javadoc.dir=${dist.dir}/javadoc 21 | excludes= 22 | file.reference.tiled-src=src 23 | includes=** 24 | jar.compress=false 25 | javac.classpath= 26 | # Space-separated list of extra javac options 27 | javac.compilerargs= 28 | javac.deprecation=false 29 | javac.source=1.5 30 | javac.target=1.5 31 | javac.test.classpath=\ 32 | ${javac.classpath}:\ 33 | ${build.classes.dir}:\ 34 | ${libs.junit.classpath}:\ 35 | ${libs.junit_4.classpath} 36 | javadoc.additionalparam= 37 | javadoc.author=false 38 | javadoc.encoding=${source.encoding} 39 | javadoc.noindex=false 40 | javadoc.nonavbar=false 41 | javadoc.notree=false 42 | javadoc.private=false 43 | javadoc.splitindex=true 44 | javadoc.use=true 45 | javadoc.version=false 46 | javadoc.windowtitle= 47 | main.class=tiled.Main 48 | manifest.file=manifest.mf 49 | meta.inf.dir=${src.dir}/META-INF 50 | platform.active=default_platform 51 | run.classpath=\ 52 | ${javac.classpath}:\ 53 | ${build.classes.dir} 54 | # Space-separated list of JVM arguments used when running the project 55 | # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value 56 | # or test-sys-prop.name=value to set system properties for unit tests): 57 | run.jvmargs= 58 | run.test.classpath=\ 59 | ${javac.test.classpath}:\ 60 | ${build.test.classes.dir} 61 | source.encoding=UTF-8 62 | src.dir=${file.reference.tiled-src} 63 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | tiled 7 | 1.6.5 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /plugins/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Plugins for Tiled 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /plugins/json/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Created-By: 1.4.1_05 (Sun Microsystems Inc.) 3 | Writer-Class: tiled.plugins.json.JSONMapWriter 4 | -------------------------------------------------------------------------------- /plugins/json/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | A Java-based Tile Map Editor 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /plugins/json/nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | nbbuild.xml.data.CRC32=5b801dc8 2 | nbbuild.xml.script.CRC32=4b8f0111 3 | nbbuild.xml.stylesheet.CRC32=be360661 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=5b801dc8 7 | nbproject/build-impl.xml.script.CRC32=48543e5a 8 | nbproject/build-impl.xml.stylesheet.CRC32=487672f9 9 | -------------------------------------------------------------------------------- /plugins/json/nbproject/project.properties: -------------------------------------------------------------------------------- 1 | application.title=tiled-json-plugin 2 | application.vendor=upachler 3 | build.classes.dir=${build.dir}/classes 4 | build.classes.excludes=**/*.java,**/*.form 5 | # This directory is removed when the project is cleaned: 6 | build.dir=build 7 | build.generated.dir=${build.dir}/generated 8 | # Only compile against the classpath explicitly listed here: 9 | build.sysclasspath=ignore 10 | build.test.classes.dir=${build.dir}/test/classes 11 | build.test.results.dir=${build.dir}/test/results 12 | buildfile=nbbuild.xml 13 | debug.classpath=\ 14 | ${run.classpath} 15 | debug.test.classpath=\ 16 | ${run.test.classpath} 17 | # This directory is removed when the project is cleaned: 18 | dist.dir=dist 19 | dist.jar=${dist.dir}/tiled-json-plugin.jar 20 | dist.javadoc.dir=${dist.dir}/javadoc 21 | excludes= 22 | file.reference.json-src=src 23 | includes=** 24 | jar.compress=false 25 | javac.classpath=\ 26 | ${reference.tiled.jar} 27 | # Space-separated list of extra javac options 28 | javac.compilerargs= 29 | javac.deprecation=false 30 | javac.source=1.5 31 | javac.target=1.5 32 | javac.test.classpath=\ 33 | ${javac.classpath}:\ 34 | ${build.classes.dir}:\ 35 | ${libs.junit.classpath}:\ 36 | ${libs.junit_4.classpath} 37 | javadoc.additionalparam= 38 | javadoc.author=false 39 | javadoc.encoding=${source.encoding} 40 | javadoc.noindex=false 41 | javadoc.nonavbar=false 42 | javadoc.notree=false 43 | javadoc.private=false 44 | javadoc.splitindex=true 45 | javadoc.use=true 46 | javadoc.version=false 47 | javadoc.windowtitle= 48 | main.class= 49 | manifest.file=manifest.mf 50 | meta.inf.dir=${src.dir}/META-INF 51 | platform.active=default_platform 52 | project.tiled=../.. 53 | reference.tiled.jar=${project.tiled}/dist/tiled.jar 54 | run.classpath=\ 55 | ${javac.classpath}:\ 56 | ${build.classes.dir} 57 | # Space-separated list of JVM arguments used when running the project 58 | # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value 59 | # or test-sys-prop.name=value to set system properties for unit tests): 60 | run.jvmargs= 61 | run.test.classpath=\ 62 | ${javac.test.classpath}:\ 63 | ${build.test.classes.dir} 64 | source.encoding=UTF-8 65 | src.dir=${file.reference.json-src} 66 | -------------------------------------------------------------------------------- /plugins/json/nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | tiled-json-plugin 7 | 1.6.5 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | tiled 16 | jar 17 | 18 | jar 19 | clean 20 | jar 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /plugins/json/src/org/json/CookieList.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | import java.util.Iterator; 4 | import java.text.ParseException; 5 | 6 | /** 7 | * Convert a web browser cookie list string to a JSONObject and back. 8 | *

9 | * Public Domain 2002 JSON.org 10 | * @author JSON.org 11 | * @version 0.1 12 | */ 13 | public class CookieList { 14 | 15 | private CookieList() {} 16 | 17 | /** 18 | * Convert a cookie list into a JSONObject. A cookie list is a sequence 19 | * of name/value pairs. The names are separated from the values by '='. 20 | * The pairs are separated by ';'. The names and the values 21 | * will be unescaped, possibly converting '+' and '%' sequences. 22 | * 23 | * To add a cookie to a cooklist, 24 | * cookielistJSONObject.put(cookieJSONObject.getString("name"), 25 | * cookieJSONObject.getString("value")); 26 | * @param string A cookie list string 27 | * @return A JSONObject 28 | * @throws ParseException 29 | */ 30 | public static JSONObject toJSONObject(String string) 31 | throws ParseException { 32 | JSONObject o = new JSONObject(); 33 | JSONTokener x = new JSONTokener(string); 34 | while (x.more()) { 35 | String name = JSONTokener.unescape(x.nextTo('=')); 36 | x.next('='); 37 | o.put(name, JSONTokener.unescape(x.nextTo(';'))); 38 | x.next(); 39 | } 40 | return o; 41 | } 42 | 43 | 44 | /** 45 | * Convert a JSONObject into a cookie list. A cookie list is a sequence 46 | * of name/value pairs. The names are separated from the values by '='. 47 | * The pairs are separated by ';'. The characters '%', '+', '=', and ';' 48 | * in the names and values are replaced by "%hh". 49 | * @param o A JSONObject 50 | * @return A cookie list string 51 | */ 52 | public static String toString(JSONObject o) { 53 | boolean b = false; 54 | Iterator keys = o.keys(); 55 | String s; 56 | StringBuffer sb = new StringBuffer(); 57 | while (keys.hasNext()) { 58 | s = keys.next().toString(); 59 | if (!o.isNull(s)) { 60 | if (b) { 61 | sb.append(';'); 62 | } 63 | sb.append(Cookie.escape(s)); 64 | sb.append("="); 65 | sb.append(Cookie.escape(o.getString(s))); 66 | b = true; 67 | } 68 | } 69 | return sb.toString(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /plugins/json/src/org/json/HTTPTokener.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | import java.text.ParseException; 4 | 5 | /** 6 | * The HTTPTokener extends the JSONTokener to provide additional methods 7 | * for the parsing of HTTP headers. 8 | *

9 | * Public Domain 2002 JSON.org 10 | * @author JSON.org 11 | * @version 0.1 12 | */ 13 | public class HTTPTokener extends JSONTokener { 14 | 15 | /** 16 | * Construct an XMLTokener from a string. 17 | * @param s A source string. 18 | */ 19 | public HTTPTokener(String s) { 20 | super(s); 21 | } 22 | 23 | 24 | /** 25 | * Get the next token or string. This is used in parsing HTTP headers. 26 | * @throws ParseException 27 | * @return A String. 28 | */ 29 | public String nextToken() throws ParseException { 30 | char c; 31 | char q; 32 | StringBuffer sb = new StringBuffer(); 33 | do { 34 | c = next(); 35 | } while (Character.isWhitespace(c)); 36 | if (c == '"' || c == '\'') { 37 | q = c; 38 | while (true) { 39 | c = next(); 40 | if (c < ' ') { 41 | throw syntaxError("Unterminated string."); 42 | } 43 | if (c == q) { 44 | return sb.toString(); 45 | } 46 | sb.append(c); 47 | } 48 | } else { 49 | while (true) { 50 | if (c == 0 || Character.isWhitespace(c)) { 51 | return sb.toString(); 52 | } 53 | sb.append(c); 54 | c = next(); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /plugins/json/src/tiled/plugins/json/JSONUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * JSON map writer contributed by 10 | * Nader Akhres 11 | */ 12 | 13 | package tiled.plugins.json; 14 | 15 | import java.text.ParseException; 16 | 17 | import org.json.JSONArray; 18 | import org.json.JSONObject; 19 | 20 | /** 21 | * Contains utilities to extend JSON capabilities. 22 | */ 23 | public class JSONUtils 24 | { 25 | /** 26 | * Constructor. 27 | */ 28 | public JSONUtils() { 29 | //nothing 30 | } 31 | 32 | /** 33 | * This method takes an object that is JSONArray already or JSONObject and 34 | * convert it into JSONArray this is useful because JSON turn an xml entry 35 | * into array or object according to number of entries using this method 36 | * will avoid to treat as special cases whether you have one entrie or 37 | * several. 38 | * 39 | * @param obj 40 | * @return JSONArray 41 | * @throws ParseException 42 | */ 43 | public static JSONArray getAsJSONArray(Object obj) throws ParseException { 44 | // We always convert to a json array: json object become a json array 45 | // with one item 46 | JSONArray result = null; 47 | 48 | if (obj instanceof JSONArray) { 49 | result = (JSONArray) obj; 50 | } else if (obj instanceof JSONObject) { 51 | result = new JSONArray(); 52 | result.put(obj); 53 | } else { 54 | throw new ParseException("problem while interpreting "+obj,0); 55 | } 56 | 57 | return result; 58 | } 59 | 60 | /** 61 | * Unit test. 62 | * 63 | * @param args 64 | */ 65 | /* 66 | public static void main(String[] args) { 67 | //test 68 | } 69 | */ 70 | } 71 | -------------------------------------------------------------------------------- /plugins/lua/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Created-By: 1.4.1_05 (Sun Microsystems Inc.) 3 | Writer-Class: tiled.plugins.lua.LuaMapWriter 4 | -------------------------------------------------------------------------------- /plugins/lua/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Lua plugin for Tiled 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /plugins/lua/nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | nbbuild.xml.data.CRC32=2710f671 2 | nbbuild.xml.script.CRC32=a3921f61 3 | nbbuild.xml.stylesheet.CRC32=be360661 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=2710f671 7 | nbproject/build-impl.xml.script.CRC32=2be52943 8 | nbproject/build-impl.xml.stylesheet.CRC32=487672f9 9 | -------------------------------------------------------------------------------- /plugins/lua/nbproject/project.properties: -------------------------------------------------------------------------------- 1 | application.title=tiled-lua-plugin 2 | application.vendor=upachler 3 | build.classes.dir=${build.dir}/classes 4 | build.classes.excludes=**/*.java,**/*.form 5 | # This directory is removed when the project is cleaned: 6 | build.dir=build 7 | build.generated.dir=${build.dir}/generated 8 | # Only compile against the classpath explicitly listed here: 9 | build.sysclasspath=ignore 10 | build.test.classes.dir=${build.dir}/test/classes 11 | build.test.results.dir=${build.dir}/test/results 12 | buildfile=nbbuild.xml 13 | debug.classpath=\ 14 | ${run.classpath} 15 | debug.test.classpath=\ 16 | ${run.test.classpath} 17 | # This directory is removed when the project is cleaned: 18 | dist.dir=dist 19 | dist.jar=${dist.dir}/tiled-lua-plugin.jar 20 | dist.javadoc.dir=${dist.dir}/javadoc 21 | excludes= 22 | file.reference.lua-src=src 23 | includes=** 24 | jar.compress=false 25 | javac.classpath=\ 26 | ${reference.tiled.jar} 27 | # Space-separated list of extra javac options 28 | javac.compilerargs= 29 | javac.deprecation=false 30 | javac.source=1.5 31 | javac.target=1.5 32 | javac.test.classpath=\ 33 | ${javac.classpath}:\ 34 | ${build.classes.dir}:\ 35 | ${libs.junit.classpath}:\ 36 | ${libs.junit_4.classpath} 37 | javadoc.additionalparam= 38 | javadoc.author=false 39 | javadoc.encoding=${source.encoding} 40 | javadoc.noindex=false 41 | javadoc.nonavbar=false 42 | javadoc.notree=false 43 | javadoc.private=false 44 | javadoc.splitindex=true 45 | javadoc.use=true 46 | javadoc.version=false 47 | javadoc.windowtitle= 48 | main.class= 49 | manifest.file=manifest.mf 50 | meta.inf.dir=${src.dir}/META-INF 51 | platform.active=default_platform 52 | project.tiled=../.. 53 | reference.tiled.jar=${project.tiled}/dist/tiled.jar 54 | run.classpath=\ 55 | ${javac.classpath}:\ 56 | ${build.classes.dir} 57 | # Space-separated list of JVM arguments used when running the project 58 | # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value 59 | # or test-sys-prop.name=value to set system properties for unit tests): 60 | run.jvmargs= 61 | run.test.classpath=\ 62 | ${javac.test.classpath}:\ 63 | ${build.test.classes.dir} 64 | source.encoding=UTF-8 65 | src.dir=${file.reference.lua-src} 66 | -------------------------------------------------------------------------------- /plugins/lua/nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | tiled-lua-plugin 7 | 1.6.5 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | tiled 16 | jar 17 | 18 | jar 19 | clean 20 | jar 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /plugins/mappy/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Created-By: 1.4.1_05 (Sun Microsystems Inc.) 3 | Reader-Class: tiled.plugins.mappy.MappyMapReader 4 | Writer-Class: tiled.plugins.mappy.MappyMapWriter 5 | -------------------------------------------------------------------------------- /plugins/mappy/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Mappy plugin for Tiled 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /plugins/mappy/nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | nbbuild.xml.data.CRC32=6ed2f5dc 2 | nbbuild.xml.script.CRC32=8407903f 3 | nbbuild.xml.stylesheet.CRC32=be360661 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=6ed2f5dc 7 | nbproject/build-impl.xml.script.CRC32=9b97627b 8 | nbproject/build-impl.xml.stylesheet.CRC32=487672f9 9 | -------------------------------------------------------------------------------- /plugins/mappy/nbproject/project.properties: -------------------------------------------------------------------------------- 1 | application.title=tiled-mappy-plugin 2 | application.vendor=upachler 3 | build.classes.dir=${build.dir}/classes 4 | build.classes.excludes=**/*.java,**/*.form 5 | # This directory is removed when the project is cleaned: 6 | build.dir=build 7 | build.generated.dir=${build.dir}/generated 8 | # Only compile against the classpath explicitly listed here: 9 | build.sysclasspath=ignore 10 | build.test.classes.dir=${build.dir}/test/classes 11 | build.test.results.dir=${build.dir}/test/results 12 | buildfile=nbbuild.xml 13 | debug.classpath=\ 14 | ${run.classpath} 15 | debug.test.classpath=\ 16 | ${run.test.classpath} 17 | # This directory is removed when the project is cleaned: 18 | dist.dir=dist 19 | dist.jar=${dist.dir}/tiled-mappy-plugin.jar 20 | dist.javadoc.dir=${dist.dir}/javadoc 21 | excludes= 22 | file.reference.mappy-src=src 23 | includes=** 24 | jar.compress=false 25 | javac.classpath=\ 26 | ${reference.tiled.jar} 27 | # Space-separated list of extra javac options 28 | javac.compilerargs= 29 | javac.deprecation=false 30 | javac.source=1.5 31 | javac.target=1.5 32 | javac.test.classpath=\ 33 | ${javac.classpath}:\ 34 | ${build.classes.dir}:\ 35 | ${libs.junit.classpath}:\ 36 | ${libs.junit_4.classpath} 37 | javadoc.additionalparam= 38 | javadoc.author=false 39 | javadoc.encoding=${source.encoding} 40 | javadoc.noindex=false 41 | javadoc.nonavbar=false 42 | javadoc.notree=false 43 | javadoc.private=false 44 | javadoc.splitindex=true 45 | javadoc.use=true 46 | javadoc.version=false 47 | javadoc.windowtitle= 48 | main.class= 49 | manifest.file=manifest.mf 50 | meta.inf.dir=${src.dir}/META-INF 51 | platform.active=default_platform 52 | project.tiled=../.. 53 | reference.tiled.jar=${project.tiled}/dist/tiled.jar 54 | run.classpath=\ 55 | ${javac.classpath}:\ 56 | ${build.classes.dir} 57 | # Space-separated list of JVM arguments used when running the project 58 | # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value 59 | # or test-sys-prop.name=value to set system properties for unit tests): 60 | run.jvmargs= 61 | run.test.classpath=\ 62 | ${javac.test.classpath}:\ 63 | ${build.test.classes.dir} 64 | source.encoding=UTF-8 65 | src.dir=${file.reference.mappy-src} 66 | -------------------------------------------------------------------------------- /plugins/mappy/nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | tiled-mappy-plugin 7 | 1.6.5 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | tiled 16 | jar 17 | 18 | jar 19 | clean 20 | jar 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /plugins/mappy/src/tiled/plugins/mappy/Chunk.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Mappy Plugin for Tiled, (c) 2004 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.plugins.mappy; 14 | 15 | import java.io.*; 16 | 17 | public class Chunk 18 | { 19 | private String headerTag; 20 | private int chunkSize; 21 | private ByteArrayInputStream bais; 22 | private ByteArrayOutputStream out; 23 | 24 | public Chunk(InputStream in) throws IOException { 25 | byte[] header = new byte[4]; 26 | byte[] data; 27 | int readSize; 28 | 29 | in.read(header); 30 | headerTag = new String(header); 31 | chunkSize = (int)Util.readLongReverse(in); 32 | if (chunkSize > 0) { 33 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 34 | data = new byte[chunkSize]; 35 | readSize = in.read(data, 0, chunkSize); 36 | if(readSize!=chunkSize) 37 | throw new IOException("Incomplete read!"); 38 | baos.write(data); 39 | bais = new ByteArrayInputStream(baos.toByteArray()); 40 | } 41 | } 42 | 43 | public Chunk(String header) { 44 | headerTag = header; 45 | out = new ByteArrayOutputStream(); 46 | } 47 | 48 | public boolean isGood() { 49 | return chunkSize > 0; 50 | } 51 | 52 | public boolean equals(Object o) { 53 | if (o instanceof String) { 54 | return o.equals(headerTag); 55 | } else if (o instanceof Chunk) { 56 | return ((Chunk)o).headerTag.equals(headerTag); 57 | } 58 | return false; 59 | } 60 | 61 | public int size() { 62 | return headerTag.length()+out.size()+4; 63 | } 64 | 65 | public void write(OutputStream out) throws IOException { 66 | byte [] data = this.out.toByteArray(); 67 | out.write(headerTag.getBytes()); 68 | Util.writeLongReverse((long)(data.length-(headerTag.length()+4)), out); 69 | out.write(data); 70 | } 71 | 72 | public InputStream getInputStream() { 73 | return bais; 74 | } 75 | 76 | public OutputStream getOutputStream() { 77 | return out; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /plugins/mappy/src/tiled/plugins/mappy/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Mappy Plugin for Tiled, (c) 2004 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.plugins.mappy; 14 | 15 | import java.awt.*; 16 | import java.awt.image.DirectColorModel; 17 | import java.awt.image.MemoryImageSource; 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.io.OutputStream; 21 | 22 | /** 23 | * @version $Id$ 24 | */ 25 | public class Util 26 | { 27 | private static final int LAST_BYTE = 0x000000FF; 28 | 29 | public static long readLongReverse(InputStream in) throws IOException { 30 | int a = in.read(); 31 | int b = in.read(); 32 | int c = in.read(); 33 | int d = in.read(); 34 | 35 | return (long) (a << 24 | b << 16 | c << 8 | d); 36 | } 37 | 38 | public static void writeLongReverse(long val, OutputStream out) throws IOException { 39 | out.write((int) (val >> 24 & LAST_BYTE)); 40 | out.write((int) (val >> 16 & LAST_BYTE)); 41 | out.write((int) (val >> 8 & LAST_BYTE)); 42 | out.write((int) (val & LAST_BYTE)); 43 | } 44 | 45 | public static int readShortReverse(InputStream in) throws IOException { 46 | int a = in.read(); 47 | int b = in.read(); 48 | return a << 8 | b; 49 | } 50 | 51 | public static int readShort(InputStream in) throws IOException { 52 | int a = in.read(); 53 | int b = in.read(); 54 | return a | b << 8; 55 | } 56 | 57 | public static void writeShort(int val, OutputStream out) throws IOException { 58 | //TODO: this 59 | } 60 | 61 | public static Image readRawImage(InputStream in, int twidth, int theight) throws IOException { 62 | DirectColorModel cm = new DirectColorModel(16, 0xF800, 0x07E0, 0x001F); 63 | 64 | int [] pixels = new int[twidth * theight + 1]; 65 | int i, j; 66 | 67 | for (i = 0; i < theight; i++) 68 | for (j = 0; j < twidth; j++) { 69 | pixels[i * twidth + j] = readShortReverse(in); 70 | //System.out.println(pixels[i*width+j]); 71 | } 72 | 73 | MemoryImageSource s = new MemoryImageSource(twidth, theight, cm, pixels, 0, twidth); 74 | 75 | return Toolkit.getDefaultToolkit().createImage(s); 76 | //return(Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(orig.getSource(),new TransImageFilter(cm.getRGB(64305))))); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /plugins/tmw/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Created-By: 1.4.1_05 (Sun Microsystems Inc.) 3 | Writer-Class: tiled.plugins.tmw.TMWServerMapWriter 4 | -------------------------------------------------------------------------------- /plugins/tmw/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | A plugin to write TMW map files. 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /plugins/tmw/nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | nbbuild.xml.data.CRC32=8587b6a9 2 | nbbuild.xml.script.CRC32=69106b43 3 | nbbuild.xml.stylesheet.CRC32=be360661 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=8587b6a9 7 | nbproject/build-impl.xml.script.CRC32=59b0b772 8 | nbproject/build-impl.xml.stylesheet.CRC32=487672f9 9 | -------------------------------------------------------------------------------- /plugins/tmw/nbproject/project.properties: -------------------------------------------------------------------------------- 1 | application.title=tmw 2 | application.vendor=upachler 3 | build.classes.dir=${build.dir}/classes 4 | build.classes.excludes=**/*.java,**/*.form 5 | # This directory is removed when the project is cleaned: 6 | build.dir=build 7 | build.generated.dir=${build.dir}/generated 8 | # Only compile against the classpath explicitly listed here: 9 | build.sysclasspath=ignore 10 | build.test.classes.dir=${build.dir}/test/classes 11 | build.test.results.dir=${build.dir}/test/results 12 | buildfile=nbbuild.xml 13 | debug.classpath=\ 14 | ${run.classpath} 15 | debug.test.classpath=\ 16 | ${run.test.classpath} 17 | # This directory is removed when the project is cleaned: 18 | dist.dir=dist 19 | dist.jar=${dist.dir}/tiled-tmw-plugin.jar 20 | dist.javadoc.dir=${dist.dir}/javadoc 21 | excludes= 22 | file.reference.tmw-src=src 23 | includes=** 24 | jar.compress=false 25 | javac.classpath=\ 26 | ${reference.tiled.jar} 27 | # Space-separated list of extra javac options 28 | javac.compilerargs= 29 | javac.deprecation=false 30 | javac.source=1.5 31 | javac.target=1.5 32 | javac.test.classpath=\ 33 | ${javac.classpath}:\ 34 | ${build.classes.dir}:\ 35 | ${libs.junit.classpath}:\ 36 | ${libs.junit_4.classpath} 37 | javadoc.additionalparam= 38 | javadoc.author=false 39 | javadoc.encoding=${source.encoding} 40 | javadoc.noindex=false 41 | javadoc.nonavbar=false 42 | javadoc.notree=false 43 | javadoc.private=false 44 | javadoc.splitindex=true 45 | javadoc.use=true 46 | javadoc.version=false 47 | javadoc.windowtitle= 48 | main.class= 49 | manifest.file=manifest.mf 50 | meta.inf.dir=${src.dir}/META-INF 51 | platform.active=default_platform 52 | project.tiled=../.. 53 | reference.tiled.jar=${project.tiled}/dist/tiled.jar 54 | run.classpath=\ 55 | ${javac.classpath}:\ 56 | ${build.classes.dir} 57 | # Space-separated list of JVM arguments used when running the project 58 | # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value 59 | # or test-sys-prop.name=value to set system properties for unit tests): 60 | run.jvmargs= 61 | run.test.classpath=\ 62 | ${javac.test.classpath}:\ 63 | ${build.test.classes.dir} 64 | source.encoding=UTF-8 65 | src.dir=${file.reference.tmw-src} 66 | -------------------------------------------------------------------------------- /plugins/tmw/nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | tiled-tmw-plugin 7 | 1.6.5 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | tiled 16 | jar 17 | 18 | jar 19 | clean 20 | jar 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /plugins/tmw/src/tiled/plugins/tmw/WLKWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The Mana World Plugin for Tiled, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.plugins.tmw; 14 | 15 | import java.io.*; 16 | 17 | import tiled.core.*; 18 | 19 | /** 20 | * The WLK file writer. The format is very simple: 21 | * 22 | *

23 |  *  short (width)
24 |  *  short (height)
25 |  *  char[] (data)
26 |  * 
27 | * 28 | * @version $Id$ 29 | */ 30 | public class WLKWriter 31 | { 32 | private static final int FIRST_BYTE = 0x000000FF; 33 | 34 | public static void writeMap(Map map, OutputStream out) throws Exception { 35 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 36 | 37 | MapLayer layer = null; 38 | 39 | // Get the last "collision" layer 40 | for (MapLayer mapLayer : map) { 41 | if (mapLayer.getName().equalsIgnoreCase("collision")) { 42 | layer = mapLayer; 43 | } 44 | } 45 | 46 | if (layer != null && layer instanceof TileLayer) { 47 | int width = layer.getWidth(); 48 | int height = layer.getHeight(); 49 | 50 | // Write width and height 51 | out.write(width & FIRST_BYTE); 52 | out.write(width >> 8 & FIRST_BYTE); 53 | out.write(height & FIRST_BYTE); 54 | out.write(height >> 8 & FIRST_BYTE); 55 | 56 | for (int y = 0; y < height; y++) { 57 | for (int x= 0; x < width; x++) { 58 | Tile tile = ((TileLayer) layer).getTileAt(x, y); 59 | if (tile != null && tile.getId() > 0) { 60 | out.write(1); 61 | } else { 62 | out.write(0); 63 | } 64 | } 65 | } 66 | 67 | baos.writeTo(out); 68 | } else { 69 | throw new Exception("No collision layer found!"); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /prototypes/PLUGIN.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Created-By: 1.4.1_05 (Sun Microsystems Inc.) 3 | Reader-Class: name.of.your.reader 4 | Writer-Class: name.of.your.writer 5 | -------------------------------------------------------------------------------- /prototypes/TMX-format.txt: -------------------------------------------------------------------------------- 1 | 2 | --====The TMX Map Format Guide====-- 3 | 4 | 5 | Introduction 6 | 7 | Among the many things that we have had questions about, using an XML 8 | map format has come up the most. It isn't that using one is hard to 9 | do, simply that it is a bit of a departure from the standard 10 | binary-only formats most engines use. 11 | This document is an attempt to explain the motivations, goals, and 12 | methods of an XML map format. 13 | 14 | 15 | Section 1 - XML 16 | 17 | To understand TMX/TSX and related information, a simple 18 | understanding of XML is necessary. If you believe you already possess 19 | this knowledge, then you may safely skip to Chapter 2: TMX Structure. 20 | References for good sources of XML related material can be found in 21 | the appendix of this document. 22 | XML was meant to be an answer to the various markup languages that 23 | had already been standardized and in heavy use. The problem that arose 24 | for many of these languages is that as new functionality was required 25 | or proposed, new tags had to be added to the standard. Different 26 | vendors often added implementation-specific tags that fell outside of 27 | the specification, and eventually the language came to have a large 28 | and complex lexicon. 29 | As a result, the W3C designed XML to be free of predefined tags and 30 | structures. Like any markup language, XML has tags, but unlike others, 31 | no tags are predefined. Any tag that the implementor wishs to use to 32 | describe a data element could be defined in the Document Type 33 | Definition, or DTD of the implementation-specific XML document. This 34 | allowed that any previously standardized markup language could be 35 | recreated very easily in XML. More importantly, it opened the door for 36 | the free exchange of data between disparate, directly incompatible 37 | systems - provided they both understood the DTD for the XML document. 38 | At the endpoints of the data exchange, the data would usually be 39 | converted to a native format of some kind. Enter the Extensible 40 | Stylesheet Language, or XSL. XSL templates (XSLT) can be used to 41 | convert XML documents to a native format using the actions defined for 42 | XSL. 43 | 44 | 45 | Section 2 - TMX Structure 46 | 47 | Now that we have a basic knowledge of XML documents, let's take a 48 | look at the basic structure of an TMX file. 49 | TMX is used to define, as generically as possible, a map that 50 | holds enough information as to be useful to the vast majority of game 51 | engines. It accomplishes this by using a very small set of possible 52 | tags to encapsulate all relevant data, and keeps attributes to a 53 | minimum. More engine-specific data is usually defined as 54 | tags within a element. 55 | The root element of a TMX file is always . This map element 56 | contains the definitions for all data, including layers, tilesets, 57 | and objects. There can be only one tag per TMX file. 58 | Within the map element, the three distinct tags for map data are 59 | , , and . 60 | -------------------------------------------------------------------------------- /prototypes/cave.tsx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /prototypes/garden.tsx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /prototypes/garden01.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | Jds54a543k5j4k54lH5JKLDSAHUIHNJkhkdsajhdsauildsAjkljklfdJK534LH... 21 | 22 | 23 | 24 | 25 | 26 | 27 | ... 28 | 29 | 30 | ... 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /prototypes/garden_ext.tsx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | P1BORw0KGgoAAAANSUhEUgAAACMAAAA/CAYAAABwB2I/AAADP0lEQVR4Pz8/P24/UBQ/AwMNPyxhWWg/Pz81MD9lP0VVYFlVPz8/Iz8FPz8/Lz9cPxNdPz8XP0hHPz93PD8/Hj9eXARBEARBEARBPws/Pz8/Pz8/P38PP1k/Pz8/Pz8+HT9vXz8/P2k/Pz8/Pz8/Rj8/Lz8/Pz8/Pz8/RD8/Pzg/NgM/XT8/Pz8PTT97dD8/P2cNKkA/fSk/eS0/Pyg/Sj8/CT8/Pz8/fVk/Hj9NPz9AGTM/P1w1Pz8ZFHBCP2I/PwkFPxkRclI/Pz8/Pxo/Gz9DPz8/Pz8/PwIVTj8/P2w/P3Y/Pz8SXHs/fBxsID94Pz81Pz8bTj8SP3s/cH5QPz8/P1oBP2U/P1oiPzxOPy8iPz8/fkQDP1dLP1UvPz94XB4zZT8/GCBtZTc/P3AOElI/Pz8/PyoaZz9+Pz93Pz88PyE/Zz8/MRY/KT8RTT8/P3g/P0A/Pz8GPz9yMj8ZPz8/Pz9tPz8/UT8/Pyo/A1hEJHEZPz4/Pz8/QlJlPz8/QTxwP2UEPz85MT8kPyZlPz9MPz9uIDk1Pz89Pz99Pz8KPz8/Py8PHz9GN2lwPxE/Pz9lP0A/Eys/H0IaP1o/MVg/Pz8/aT9jPz9ZPyk/Pz8/Kz8xP3tgPz8yPz97RAZjYj8/Pz8PPzw/az8/P1UHKz8/P0RkWH1lOj80Lz8/Pz8/Pz8/Pz8/Akc/Pz8/Pz8/CxwqPz9XbURtD0xPUj95Pz92ExM/PT8/Pz8IPz9OPz8/Pz8/QT8/PzVOFD8/Pz8/P20/Pz89Pz8/Pwg/dXo/P1E/OmY/Cj8/P15jPxRDDT8/P1R/Pz8dP3c/Xj8IPzI/Pz8/YD8/KjI/Pz8/Wj81Lz8/Pz8/P3Y/Pww/IC0ZPys/Pz0/Rj8/Wix1XD82aT8/bWgGPz8fP3FcHmg/P20/Pz8bP2sVP0w/Pz90Qz9cDiYCPz8/Rj8/dT86P2s/P1Y/Pz8/VD9NYz8aPxAyPzU/UGU/Pz8wKSs8PyE/cEw/U00/VD9JZSI/Pz9FPwAJXz9lPz4/WTBdFT8/Yj8GOT9DPz9NPz8/Pz9yPz8GYRJ/Y2IJPz8/OW0/Pz8/FT8yCD8bEU98ORAXPyQ/cT8/KQU/Pz8MGUhrYlcJMig/eyh8PwlMPz8/Pz8jP2k/PD8XfR0/GlM/PD8/Pz8/Pz8/Pz9HPz8/Ij8/Pz9TP0o/Pz8oP0k/IhtXPxltPz9RPz9cPz8/Pz9OP1Y/bU5mKmM8P3c/P1k0P04FQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRA/GT8DPz8/Pz86PT8AAAAASUVORD9CYD8= 16 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/tiled/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled; 7 | 8 | import tiled.command.CommandInterpreter; 9 | import java.io.File; 10 | import java.io.IOException; 11 | import java.io.PrintStream; 12 | import tiled.mapeditor.MapEditor; 13 | import tiled.util.TiledConfiguration; 14 | 15 | /** 16 | * 17 | * @author upachler 18 | */ 19 | public class Main { 20 | /** 21 | * Starts Tiled. 22 | * 23 | * @param args the first argument may be a map file 24 | */ 25 | public static void main(String[] args) { 26 | 27 | 28 | if(args.length > 0){ 29 | if(args[0].equals("-commandmode")){ 30 | CommandInterpreter i = new CommandInterpreter(); 31 | int result = i.interpret(args, 1); 32 | System.exit(result); 33 | } else if(args[0].equals("-?") || args[0].equals("-help")){ 34 | printHelpMessage(); 35 | } else { 36 | File file = new File(args[0]); 37 | try { 38 | String path = file.getCanonicalPath(); 39 | MapEditor editor = new MapEditor(); 40 | editor.loadMap(path); 41 | } catch (IOException ex) { 42 | } 43 | } 44 | } 45 | else{ 46 | MapEditor editor = new MapEditor(); 47 | if (TiledConfiguration.node("io").getBoolean("autoOpenLast", false)) { 48 | // Load last map if it still exists 49 | java.util.List recent = TiledConfiguration.getRecentFiles(); 50 | if (!recent.isEmpty()) { 51 | String filename = recent.get(0); 52 | if (new File(filename).exists()) { 53 | editor.loadMap(filename); 54 | } 55 | } 56 | } 57 | } 58 | } 59 | 60 | private static void printHelpMessage() { 61 | PrintStream o = System.out; 62 | o.println(); 63 | o.println("Start tiled with no parameters to just start the editor.\n" + 64 | "When a parameter is given, it can either be a file name or an \n" + 65 | "option starting with '-'. These options are available:\n" + 66 | "\n" + 67 | "-?\n" + 68 | "-help\n" + 69 | "\tdisplays this help message\n" + 70 | "\n" + 71 | "-commandmode [parameter] { [parameter] }\n" + 72 | "\twill start tiled in command interpreter mode. All commands are\n" + 73 | "\tread from the command line after the -commandmode option.\n" + 74 | "\tFor a list of available commands, run tiled with\n" + 75 | "\t'-commandmode help' (which runs the help command)\n"); 76 | o.println(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/tiled/command/HelpCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.command; 7 | 8 | /** 9 | * 10 | * @author upachler 11 | */ 12 | class HelpCommand extends Command { 13 | 14 | HelpCommand(CommandInterpreter interp){ 15 | super("help", ArgumentRequirement.REQUIRES_NONE, interp); 16 | } 17 | 18 | @Override 19 | int execute() { 20 | // FIXME: this should be more detailed 21 | System.out.println("Supported commands are: "); 22 | for(Command c : interpreter.getCommandPrototypes()){ 23 | System.out.println("\t'"+c.getName()+'\''); 24 | } 25 | System.out.println(); 26 | return 0; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/tiled/command/OpenCommand.java: -------------------------------------------------------------------------------- 1 | package tiled.command; 2 | 3 | import tiled.io.xml.XMLMapTransformer; 4 | 5 | class OpenCommand extends Command { 6 | 7 | @Override 8 | int execute() { 9 | XMLMapTransformer t = new XMLMapTransformer(); 10 | String filename = getArguments()[0]; 11 | try { 12 | interpreter.setMap(t.readMap(filename), filename); 13 | } catch (Exception ex) { 14 | interpreter.raiseError("could not load file " + filename + ""); 15 | return 1; 16 | } 17 | return 0; 18 | } 19 | 20 | OpenCommand(CommandInterpreter outer) { 21 | super("open", ArgumentRequirement.REQUIRES_ONE, outer); 22 | this.interpreter = outer; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/tiled/command/SaveCommand.java: -------------------------------------------------------------------------------- 1 | package tiled.command; 2 | 3 | import tiled.io.xml.XMLMapWriter; 4 | import tiled.util.OverriddenPreferences; 5 | 6 | class SaveCommand extends Command { 7 | 8 | private XMLMapWriter mapWriter; 9 | private OverriddenPreferences oprefs; 10 | CommandInterpreter outer; 11 | 12 | SaveCommand(CommandInterpreter outer) { 13 | super("save", ArgumentRequirement.REQUIRES_ZERO_OR_ONE, outer); 14 | this.outer = outer; 15 | init(); 16 | } 17 | 18 | private void init() { 19 | mapWriter = new XMLMapWriter(); 20 | oprefs = new OverriddenPreferences(mapWriter.getPreferences()); 21 | mapWriter.setPreferences(oprefs); 22 | } 23 | 24 | @Override 25 | public Object clone() throws CloneNotSupportedException { 26 | SaveCommand c = (SaveCommand) super.clone(); 27 | c.init(); 28 | return c; 29 | } 30 | 31 | public void setEmbedImageDataEnabled(boolean enabled){ 32 | oprefs.putBoolean("embedImages", enabled); 33 | } 34 | 35 | @Override 36 | int execute() { 37 | String filename = outer.getMapFileName(); 38 | if (getArguments().length > 0) { 39 | filename = getArguments()[0]; 40 | } 41 | try { 42 | mapWriter.writeMap(outer.getMap(), filename); 43 | } catch (Exception ex) { 44 | outer.raiseError("could not write map to " + filename + " - " + ex.getMessage()); 45 | return 1; 46 | } 47 | return 0; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/tiled/core/AnimatedTile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2008 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.core; 14 | 15 | import java.awt.Graphics; 16 | import java.awt.Image; 17 | import java.util.Iterator; 18 | 19 | import tiled.core.Sprite.KeyFrame; 20 | import tiled.util.TiledConfiguration; 21 | 22 | /** 23 | * Animated tiles take advantage of the Sprite class internally to handle 24 | * animation using an array of tiles. 25 | * 26 | * @see tiled.core.Sprite 27 | */ 28 | public class AnimatedTile extends Tile { 29 | 30 | private Sprite sprite; 31 | 32 | public AnimatedTile() { 33 | } 34 | 35 | public AnimatedTile(TileSet set) { 36 | super(set); 37 | } 38 | 39 | public AnimatedTile(Tile[] frames) { 40 | this(); 41 | if (TiledConfiguration.node("animation").getBoolean("safe", false)) { 42 | //TODO:clone all the frames, just to be safe 43 | } else { 44 | sprite = new Sprite(frames); 45 | } 46 | } 47 | 48 | public AnimatedTile(Sprite s) { 49 | this(); 50 | setSprite(s); 51 | } 52 | 53 | public void setSprite(Sprite s) { 54 | sprite = s; 55 | } 56 | 57 | public int countAnimationFrames() { 58 | return sprite.getTotalFrames(); 59 | } 60 | 61 | public int countKeys() { 62 | return sprite.getTotalKeys(); 63 | } 64 | 65 | public Sprite getSprite() { 66 | return sprite; 67 | } 68 | 69 | /** 70 | * In an AnimatedTile we must take the extra step of zooming all frames of 71 | * the animation. This function can be somewhat slower than calling 72 | * getScaledImage() on a Tile, but it depends on several factors. 73 | * 74 | * @see tiled.core.Tile#getScaledImage(double) 75 | */ 76 | public Image getScaledImage(double zoom) { 77 | try { 78 | Iterator itr = sprite.getKeys(); 79 | 80 | while (itr.hasNext()) { 81 | KeyFrame key = itr.next(); 82 | for (int i = 0;i < key.getTotalFrames(); i++) { 83 | key.getFrame(i).getScaledImage(zoom); 84 | } 85 | } 86 | } catch (Exception e) {} 87 | return sprite.getCurrentFrame().getScaledImage(zoom); 88 | } 89 | 90 | /** 91 | * Handles drawing the correct frame, and iterating by the 92 | * frame rate 93 | * 94 | * @see tiled.core.Tile#draw(Graphics, int, int, double) 95 | */ 96 | public void draw(Graphics g, int x, int y, double zoom) { 97 | sprite.getCurrentFrame().draw(g, x, y, zoom); 98 | sprite.iterateFrame(); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/tiled/core/LayerLockedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.core; 14 | 15 | /** 16 | * This exception is thrown when an attempt is made to perform a modification 17 | * on a locked layer. 18 | * 19 | * @version $Id$ 20 | */ 21 | public class LayerLockedException extends Throwable { 22 | public LayerLockedException(String s) { 23 | super(s); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/tiled/core/MapChangeAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.core; 7 | 8 | /** 9 | * 10 | * @author upachler 11 | */ 12 | public class MapChangeAdapter implements MapChangeListener{ 13 | 14 | public void mapChanged(MapChangedEvent e) { 15 | } 16 | 17 | public void layerAdded(MapChangedEvent e) { 18 | } 19 | 20 | public void layerRemoved(MapChangedEvent e) { 21 | } 22 | 23 | public void layerMoved(MapChangedEvent e) { 24 | } 25 | 26 | public void tilesetAdded(MapChangedEvent e, TileSet tileset) { 27 | } 28 | 29 | public void tilesetRemoved(MapChangedEvent e, int index) { 30 | } 31 | 32 | public void tilesetsSwapped(MapChangedEvent e, int index0, int index1) { 33 | } 34 | 35 | public void layerChanged(MapChangedEvent e, MapLayerChangeEvent mlce) { 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/tiled/core/MapChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.core; 14 | 15 | import java.util.EventListener; 16 | 17 | /** 18 | * Gets notified about changes made to a map. This includes events relating to 19 | * changes in the list of layers or tilesets used by this map. 20 | * 21 | * @version $Id$ 22 | */ 23 | public interface MapChangeListener extends EventListener 24 | { 25 | public void mapChanged(MapChangedEvent e); 26 | 27 | /// called after a layer has been added. the getLayerIndex() method 28 | /// of the supplied MapChangedEvent will yield the index of the new layer 29 | /// (where it has been inserted) 30 | public void layerAdded(MapChangedEvent e); 31 | 32 | /// called after a layer has been removed. the getLayerIndex() method 33 | /// of the supplied MapChangedEvent will yield the index of the layer that 34 | /// was removed. 35 | public void layerRemoved(MapChangedEvent e); 36 | 37 | /// called after a layer has been moved around in the map's list of 38 | /// layers. This changes which layer is on top of which other layer. A move 39 | /// is basically the 40 | /// same as removing the layer on one position and inserting it at another. 41 | /// e.getLayerIndex() returns the layer's new index, e.getOldLayerIndex() 42 | /// returns the layer's old index. Note that the indices calculate the 43 | /// same way as for a an remove/add operation required to move the layer 44 | /// around: remove(N) will remove the layer from position N. removal will 45 | /// cause all subsequent layers to move one position down. After that, 46 | /// add(M) will add the layer at position M (counted from the state of the 47 | /// sequence after remove(N) 48 | public void layerMoved(MapChangedEvent e); 49 | 50 | /// This event is fired every time the name of a layer is changed. 51 | public void layerChanged(MapChangedEvent e, MapLayerChangeEvent layerChangeEvent); 52 | 53 | public void tilesetAdded(MapChangedEvent e, TileSet tileset); 54 | 55 | public void tilesetRemoved(MapChangedEvent e, int index); 56 | 57 | public void tilesetsSwapped(MapChangedEvent e, int index0, int index1); 58 | } 59 | -------------------------------------------------------------------------------- /src/tiled/core/MapChangedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.core; 14 | 15 | import java.util.EventObject; 16 | 17 | /** 18 | * @version $Id$ 19 | */ 20 | public class MapChangedEvent extends EventObject 21 | { 22 | private int layerIndex; 23 | private int oldLayerIndex = -1; 24 | 25 | public MapChangedEvent(Map map) { 26 | this(map, -1); 27 | layerIndex = -1; 28 | } 29 | 30 | public MapChangedEvent(Map map, int layerIndex){ 31 | this(map, layerIndex, -1); 32 | } 33 | 34 | public MapChangedEvent(Map map, int layerIndex, int oldLayerIndex){ 35 | super(map); 36 | this.layerIndex = layerIndex; 37 | this.oldLayerIndex = oldLayerIndex; 38 | } 39 | 40 | public int getLayerIndex(){ 41 | return layerIndex; 42 | } 43 | 44 | public int getOldLayerIndex(){ 45 | return oldLayerIndex; 46 | } 47 | 48 | public Map getMap() { 49 | return (Map) getSource(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/tiled/core/MapLayerChangeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.core; 7 | 8 | /** 9 | * A change event for a layer specifies what change happened to that layer. 10 | * To know the type of change, call getChangeType(). Depending on the value 11 | * it returns, certain member functions will yield valid values (look at 12 | * the documentation for the CHANGETYPE_* constants for details). 13 | * @author upachler 14 | */ 15 | public class MapLayerChangeEvent { 16 | 17 | /** 18 | * Indicates that the layer in question has been renamed. The 19 | * getOldName() and getNewName() member functions will yield the layer's 20 | * old and new name. 21 | */ 22 | public static final int CHANGETYPE_NAME = 1; 23 | 24 | private int changeType = -1; 25 | 26 | private String oldName; 27 | private String newName; 28 | 29 | private MapLayerChangeEvent(int changeType){ 30 | this.changeType = changeType; 31 | } 32 | 33 | 34 | static MapLayerChangeEvent createNameChangeEvent(String oldName, String newName){ 35 | MapLayerChangeEvent e = new MapLayerChangeEvent(CHANGETYPE_NAME); 36 | e.oldName = oldName; 37 | e.newName = newName; 38 | return e; 39 | } 40 | 41 | public int getChangeType() { 42 | return changeType; 43 | } 44 | 45 | public String getOldName() { 46 | return oldName; 47 | } 48 | 49 | public String getNewName() { 50 | return newName; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/tiled/core/MapLayerChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.core; 7 | 8 | /** 9 | * 10 | * @author upachler 11 | */ 12 | interface MapLayerChangeListener { 13 | 14 | public void layerChanged(MapLayer aThis, MapLayerChangeEvent e); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/tiled/core/MapParallaxChangeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.core; 7 | 8 | /** 9 | * 10 | * @author upachler 11 | */ 12 | public class MapParallaxChangeEvent { 13 | 14 | public ChangeType getChangeType() { 15 | return changeType; 16 | } 17 | 18 | public Map getMap() { 19 | return map; 20 | } 21 | 22 | public int getLayerIndex() { 23 | return layerIndex; 24 | } 25 | 26 | public enum ChangeType{ 27 | /// indicates that the map's eye/viewplane distance changed. 28 | EYE_VIEWPLANE_DISTANCE, 29 | /// indicates that a layer's viewplane distance changed. This 30 | /// may include that it has been set to infinity 31 | LAYER_VIEWPLANE_DISTANCE, 32 | } 33 | 34 | private ChangeType changeType; 35 | private Map map; 36 | private int layerIndex = -1; 37 | 38 | public MapParallaxChangeEvent(Map map, int layerIndex, ChangeType changeType){ 39 | this.map = map; 40 | this.changeType = changeType; 41 | if(changeType != ChangeType.EYE_VIEWPLANE_DISTANCE) 42 | this.layerIndex = layerIndex; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/tiled/core/MapParallaxChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.core; 7 | 8 | /** 9 | * 10 | * @author upachler 11 | */ 12 | public interface MapParallaxChangeListener { 13 | public void parallaxParameterChanged(MapParallaxChangeEvent e); 14 | } 15 | -------------------------------------------------------------------------------- /src/tiled/core/TilesetChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.core; 14 | 15 | import java.util.EventListener; 16 | 17 | /** 18 | * A tileset listener can get notified about changes to a tileset through 19 | * receiving {@link TilesetChangedEvent}s. 20 | * 21 | * @version $Id$ 22 | */ 23 | public interface TilesetChangeListener extends EventListener 24 | { 25 | void tilesetChanged(TilesetChangedEvent event); 26 | 27 | void nameChanged(TilesetChangedEvent event, String oldName, String newName); 28 | 29 | void sourceChanged(TilesetChangedEvent event, String oldSource, String newSource); 30 | } 31 | -------------------------------------------------------------------------------- /src/tiled/core/TilesetChangedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.core; 14 | 15 | import java.util.EventObject; 16 | 17 | /** 18 | * An event indicating that a certain tileset changed. 19 | * 20 | * @version $Id$ 21 | */ 22 | public class TilesetChangedEvent extends EventObject 23 | { 24 | public TilesetChangedEvent(TileSet set) { 25 | super(set); 26 | } 27 | 28 | public TileSet getTileset() { 29 | return (TileSet) getSource(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/tiled/io/MapReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.io; 14 | 15 | import java.io.FileFilter; 16 | import java.io.InputStream; 17 | 18 | import tiled.core.Map; 19 | import tiled.core.TileSet; 20 | 21 | 22 | /** 23 | * Used by Tiled to denote a plugin for reading maps. The map file 24 | * can have any format, as long as the MapReader implementor returns 25 | * instances of {@link Map} and {@link TileSet}. 26 | */ 27 | public interface MapReader extends PluggableMapIO, FileFilter 28 | { 29 | /** 30 | * Loads a map from a file. 31 | * 32 | * @param filename the filename of the map file 33 | * @return A {@link tiled.core.Map} instance with the relevant data 34 | * @throws Exception 35 | */ 36 | public Map readMap(String filename) throws Exception; 37 | 38 | /** 39 | * Loads a tileset from a file. 40 | * 41 | * @param filename the filename of the tileset file 42 | * @return A {@link tiled.core.TileSet} instance with the relevant data 43 | * @throws Exception 44 | */ 45 | public TileSet readTileset(String filename) throws Exception; 46 | 47 | /** 48 | * Overload this to load a map from an already opened stream. Useful 49 | * for maps which are part of a larger binary dataset 50 | * 51 | * @param in 52 | * @return A {@link tiled.core.Map} object with the relevant data 53 | * @throws Exception 54 | */ 55 | public Map readMap(InputStream in) throws Exception; 56 | 57 | /** 58 | * Overload this to load a tileset from an open stream. 59 | * 60 | * @param in 61 | * @return A (@link tiled.core.TileSet} instance 62 | * @throws Exception 63 | */ 64 | public TileSet readTileset(InputStream in) throws Exception; 65 | } 66 | -------------------------------------------------------------------------------- /src/tiled/io/MapWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.io; 14 | 15 | import java.io.FileFilter; 16 | import java.io.OutputStream; 17 | 18 | import tiled.core.Map; 19 | import tiled.core.TileSet; 20 | 21 | /** 22 | * Used by Tiled to denote a plugin for writing maps. The map file 23 | * can have any format, as long as the MapWriter implementor accepts 24 | * instances of {@link tiled.core.Map} and {@link TileSet}. 25 | * 26 | * $Id$ 27 | */ 28 | public interface MapWriter extends PluggableMapIO, FileFilter 29 | { 30 | /** 31 | * Saves a map to a file. 32 | * 33 | * @param map 34 | * @param filename the filename of the map file 35 | * @throws Exception 36 | */ 37 | public void writeMap(Map map, String filename) throws Exception; 38 | 39 | /** 40 | * Saves a tileset to a file. 41 | * 42 | * @param set 43 | * @param filename the filename of the tileset file 44 | * @throws Exception 45 | */ 46 | public void writeTileset(TileSet set, String filename) throws Exception; 47 | 48 | /** 49 | * Writes a map to an already opened stream. Useful 50 | * for maps which are part of a larger binary dataset 51 | * 52 | * @param map the Map to be written 53 | * @param out 54 | * @throws Exception 55 | */ 56 | public void writeMap(Map map, OutputStream out) throws Exception; 57 | 58 | /** 59 | * Overload this to write a tileset to an open stream. 60 | * 61 | * @param set 62 | * @param out 63 | * @throws Exception 64 | */ 65 | public void writeTileset(TileSet set, OutputStream out) throws Exception; 66 | } 67 | -------------------------------------------------------------------------------- /src/tiled/io/PluggableMapIO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.io; 14 | 15 | /** 16 | * This is the interface for all Tiled I/O plugins, whether they load, save, or 17 | * both. The PluginClassLoader also uses this to check the supported file 18 | * extensions. 19 | */ 20 | public interface PluggableMapIO 21 | { 22 | /** 23 | * Lists supported file extensions. This function is used by the editor to 24 | * find the plugin to use for a specific file extension. 25 | * 26 | * @return a comma delimited string of supported file extensions 27 | * @throws Exception 28 | */ 29 | public String getFilter() throws Exception; 30 | 31 | /** 32 | * Returns a short description of the plugin, or the plugin name. This 33 | * string is displayed in the list of loaded plugins under the Help menu in 34 | * Tiled. 35 | * 36 | * @return a short name or description 37 | */ 38 | public String getName(); 39 | 40 | /** 41 | * Returns a long description (no limit) that details the plugin's 42 | * capabilities, author, contact info, etc. 43 | * 44 | * @return a long description of the plugin 45 | */ 46 | public String getDescription(); 47 | 48 | /** 49 | * Returns the base Java package string for the plugin 50 | * 51 | * @return String the base package of the plugin 52 | */ 53 | public String getPluginPackage(); 54 | 55 | /** 56 | * The PluginLogger object passed by the editor when the plugin is called to load 57 | * or save a map can be used by the plugin to notify the user of any 58 | * problems or messages. 59 | * 60 | * @param logger 61 | */ 62 | public void setLogger(PluginLogger logger); 63 | } 64 | -------------------------------------------------------------------------------- /src/tiled/io/PluginLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.io; 14 | 15 | import java.util.LinkedList; 16 | 17 | /** 18 | * @version $Id$ 19 | */ 20 | public class PluginLogger 21 | { 22 | private final LinkedList messages = new LinkedList(); 23 | 24 | public void error(Object message) { 25 | } 26 | 27 | public void warn(Object message) { 28 | } 29 | 30 | public void info(Object message) { 31 | } 32 | 33 | public void debug(Object message) { 34 | } 35 | 36 | public boolean isEmpty() { 37 | return messages.isEmpty(); 38 | } 39 | 40 | public class PluginMessage 41 | { 42 | private int type; 43 | private Object message; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/tiled/io/xml/XMLWriterException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.io.xml; 14 | 15 | /** 16 | * @version $Id$ 17 | */ 18 | public class XMLWriterException extends RuntimeException 19 | { 20 | public XMLWriterException(String error) { 21 | super(error); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/Resources.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor; 14 | 15 | import java.util.ResourceBundle; 16 | import java.awt.Image; 17 | import java.io.IOException; 18 | import javax.imageio.ImageIO; 19 | import javax.swing.Icon; 20 | import javax.swing.ImageIcon; 21 | 22 | /** 23 | * This class implements static accessors to common editor resources. These 24 | * currently include icons and internationalized strings. 25 | * 26 | * @version $Id$ 27 | */ 28 | public final class Resources { 29 | // The resource bundle used by this class 30 | private static final ResourceBundle resourceBundle = 31 | ResourceBundle.getBundle( 32 | Resources.class.getPackage().getName() + ".resources.gui"); 33 | 34 | // Prevent instanciation 35 | private Resources() { 36 | } 37 | 38 | /** 39 | * Retrieves a string from the resource bundle in the default locale. 40 | * 41 | * @param key the key for the desired string 42 | * @return the string for the given key 43 | */ 44 | public static String getString(String key) { 45 | return resourceBundle.getString(key); 46 | } 47 | 48 | /** 49 | * Loads an image from the resources directory. This directory is part of 50 | * the distribution jar. 51 | * 52 | * @param filename the filename relative from the resources directory 53 | * @return A BufferedImage instance of the image 54 | * @throws IOException if an error occurs during reading 55 | * @throws IllegalArgumentException when the resource could not be found 56 | */ 57 | public static Image getImage(String filename) throws IOException, 58 | IllegalArgumentException { 59 | return ImageIO.read(Resources.class.getResourceAsStream( 60 | "resources/" + filename)); 61 | } 62 | 63 | /** 64 | * Loads the image using {@link #getImage(String)} and uses it to create 65 | * a new {@link ImageIcon} instance. 66 | * 67 | * @param filename the filename of the image relative from the 68 | * resources directory 69 | * @return the loaded icon, or null when an error occured 70 | * while loading the image 71 | */ 72 | public static Icon getIcon(String filename) { 73 | try { 74 | return new ImageIcon(getImage(filename)); 75 | } catch (IOException e) { 76 | System.out.println("Failed to load as image: " + filename); 77 | } catch (IllegalArgumentException e) { 78 | System.out.println("Failed to load resource: " + filename); 79 | } 80 | return null; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/AbstractFileAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import java.awt.event.ActionEvent; 16 | import javax.swing.AbstractAction; 17 | import javax.swing.JOptionPane; 18 | 19 | import tiled.mapeditor.MapEditor; 20 | import tiled.mapeditor.Resources; 21 | 22 | /** 23 | * This abstract file action asks to save the map if it has been modified. It 24 | * should be subclassed by any action that would discard the currently loaded 25 | * map. 26 | * 27 | * @version $Id$ 28 | */ 29 | public abstract class AbstractFileAction extends AbstractAction 30 | { 31 | protected final MapEditor editor; 32 | private final SaveAsAction saveAction; 33 | 34 | private static final String SAVE_CHANGES_TEXT = Resources.getString("action.map.save.changes.text"); 35 | private static final String SAVE_CHANGES_TITLE = Resources.getString("action.map.save.changes.title"); 36 | 37 | protected AbstractFileAction(MapEditor editor, 38 | SaveAction saveAction, 39 | String name, String description) 40 | { 41 | super(name); 42 | this.editor = editor; 43 | this.saveAction = saveAction; 44 | putValue(SHORT_DESCRIPTION, description); 45 | } 46 | 47 | public final void actionPerformed(ActionEvent e) { 48 | if (editor.unsavedChanges()) { 49 | int ret = JOptionPane.showConfirmDialog(editor.getAppFrame(), 50 | SAVE_CHANGES_TEXT, 51 | SAVE_CHANGES_TITLE, 52 | JOptionPane.YES_NO_CANCEL_OPTION); 53 | 54 | if (ret == JOptionPane.YES_OPTION) { 55 | saveAction.actionPerformed(e); 56 | 57 | // If saving was not cancelled and there are not still unsaved 58 | // changes (which would indicate an error occured), continue 59 | // to perform the action. 60 | if (!saveAction.isSavingCancelled() && !editor.unsavedChanges()) 61 | { 62 | doPerformAction(); 63 | } 64 | } else if (ret == JOptionPane.NO_OPTION){ 65 | doPerformAction(); 66 | } 67 | } 68 | else { 69 | doPerformAction(); 70 | } 71 | } 72 | 73 | /** 74 | * Actually performs the action, in the confidence that any existing map 75 | * has been either saved or discarded. 76 | */ 77 | protected abstract void doPerformAction(); 78 | } 79 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/AbstractLayerAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import java.awt.event.ActionEvent; 16 | import java.util.Vector; 17 | import javax.swing.AbstractAction; 18 | import javax.swing.Icon; 19 | 20 | import tiled.core.Map; 21 | import tiled.core.MapLayer; 22 | import tiled.mapeditor.MapEditor; 23 | import tiled.mapeditor.undo.MapLayerStateEdit; 24 | 25 | /** 26 | * Provides a common abstract class for actions that modify the layer 27 | * configuration. It makes sure the undo/redo information is properly 28 | * maintained. 29 | * 30 | * todo: These actions will need to listen to changing of the current selected 31 | * todo: layer index as well as changes to the opened map. Action should always 32 | * todo: be disabled when no map is opened. More specific checks should be 33 | * todo: included in subclasses. 34 | * 35 | * @version $Id$ 36 | */ 37 | public abstract class AbstractLayerAction extends AbstractAction 38 | { 39 | protected final MapEditor editor; 40 | 41 | protected AbstractLayerAction(MapEditor editor, 42 | String name, String description) 43 | { 44 | super(name); 45 | putValue(SHORT_DESCRIPTION, description); 46 | putValue(ACTION_COMMAND_KEY, name); 47 | this.editor = editor; 48 | } 49 | 50 | protected AbstractLayerAction(MapEditor editor, 51 | String name, String description, Icon icon) 52 | { 53 | this(editor, name, description); 54 | putValue(SMALL_ICON, icon); 55 | } 56 | 57 | /** 58 | * Wraps {@link #doPerformAction} in order to capture the layer vector 59 | * before and after the action is performed. 60 | */ 61 | public final void actionPerformed(ActionEvent e) { 62 | // Capture the layers before the operation is executed. 63 | Map map = editor.getCurrentMap(); 64 | Vector layersBefore = new Vector(map.getLayerVector()); 65 | 66 | doPerformAction(); 67 | 68 | // Capture the layers after the operation is executed and create the 69 | // layer state edit instance. 70 | Vector layersAfter = new Vector(map.getLayerVector()); 71 | MapLayerStateEdit mapLayerStateEdit = 72 | new MapLayerStateEdit(map, layersBefore, layersAfter, 73 | e.getActionCommand()); 74 | editor.getUndoSupport().postEdit(mapLayerStateEdit); 75 | } 76 | 77 | /** 78 | * Actually performs the action that modifies the layer configuration. 79 | */ 80 | protected abstract void doPerformAction(); 81 | } 82 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/AddLayerAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import tiled.mapeditor.Resources; 16 | import tiled.mapeditor.MapEditor; 17 | import tiled.core.Map; 18 | 19 | /** 20 | * Adds a layer to the current map and selects it. 21 | * 22 | * @version $Id$ 23 | */ 24 | public class AddLayerAction extends AbstractLayerAction 25 | { 26 | public AddLayerAction(MapEditor editor) { 27 | super(editor, 28 | Resources.getString("action.layer.add.name"), 29 | Resources.getString("action.layer.add.tooltip"), 30 | Resources.getIcon("gnome-new.png")); 31 | } 32 | 33 | protected void doPerformAction() { 34 | Map currentMap = editor.getCurrentMap(); 35 | currentMap.addLayer(); 36 | editor.setCurrentLayerIndex(currentMap.getTotalLayers() - 1); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/AddObjectGroupAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import tiled.core.Map; 16 | import tiled.mapeditor.MapEditor; 17 | import tiled.mapeditor.Resources; 18 | 19 | /** 20 | * Adds a object group layer to the current map and selects it. 21 | * 22 | * @version $Id$ 23 | */ 24 | public class AddObjectGroupAction extends AbstractLayerAction 25 | { 26 | public AddObjectGroupAction(MapEditor editor) { 27 | super(editor, 28 | Resources.getString("action.objectgroup.add.name"), 29 | Resources.getString("action.objectgroup.add.tooltip"), 30 | Resources.getIcon("gnome-new.png")); 31 | } 32 | 33 | protected void doPerformAction() { 34 | Map currentMap = editor.getCurrentMap(); 35 | currentMap.addObjectGroup(); 36 | editor.setCurrentLayerIndex(currentMap.getTotalLayers() - 1); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/CloneLayerAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import java.text.MessageFormat; 16 | 17 | import tiled.mapeditor.MapEditor; 18 | import tiled.mapeditor.Resources; 19 | import tiled.core.Map; 20 | import tiled.core.MapLayer; 21 | 22 | /** 23 | * Clones the current layer, adds the clone to the map at the top of the layer 24 | * stack and then selects it. 25 | * 26 | * @version $Id$ 27 | */ 28 | public class CloneLayerAction extends AbstractLayerAction 29 | { 30 | public CloneLayerAction(MapEditor editor) { 31 | super(editor, 32 | Resources.getString("action.layer.duplicate.name"), 33 | Resources.getString("action.layer.duplicate.tooltip"), 34 | Resources.getIcon("gimp-duplicate-16.png")); 35 | } 36 | 37 | protected void doPerformAction() { 38 | MapLayer currentLayer = editor.getCurrentLayer(); 39 | Map currentMap = editor.getCurrentMap(); 40 | 41 | if (currentLayer != null) { 42 | try { 43 | MapLayer clone = (MapLayer) currentLayer.clone(); 44 | String newName = Resources.getString( 45 | "action.layer.duplicate.newlayer.name"); 46 | clone.setName(MessageFormat.format(newName, new Object[]{clone.getName()})); 47 | currentMap.addLayer(clone); 48 | editor.setCurrentLayerIndex(currentMap.getTotalLayers() - 1); 49 | } catch (CloneNotSupportedException ex) { 50 | ex.printStackTrace(); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/CloseMapAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import javax.swing.KeyStroke; 16 | 17 | import tiled.mapeditor.MapEditor; 18 | import tiled.mapeditor.Resources; 19 | 20 | /** 21 | * Closes the currently opened map. 22 | * 23 | * @version $Id$ 24 | */ 25 | public class CloseMapAction extends AbstractFileAction 26 | { 27 | public CloseMapAction(MapEditor editor, SaveAction saveAction) { 28 | super(editor, saveAction, 29 | Resources.getString("action.map.close.name"), 30 | Resources.getString("action.map.close.tooltip")); 31 | 32 | putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control W")); 33 | } 34 | 35 | protected void doPerformAction() { 36 | editor.setCurrentMap(null); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/DeleteLayerAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import java.awt.event.ActionEvent; 16 | import javax.swing.AbstractAction; 17 | import javax.swing.undo.UndoableEdit; 18 | import tiled.mapeditor.MapEditor; 19 | import tiled.mapeditor.Resources; 20 | import tiled.core.Map; 21 | import tiled.mapeditor.undo.DeleteLayerEdit; 22 | 23 | /** 24 | * Deletes the selected layer and selects the layer that takes the same index. 25 | * 26 | * @version $Id$ 27 | */ 28 | public class DeleteLayerAction extends AbstractAction 29 | { 30 | MapEditor editor; 31 | 32 | public DeleteLayerAction(MapEditor editor) { 33 | super(Resources.getString("action.layer.delete.name"), 34 | Resources.getIcon("gnome-delete.png")); 35 | this.editor = editor; 36 | putValue(SHORT_DESCRIPTION, "action.layer.delete.name"); 37 | } 38 | 39 | public void actionPerformed(ActionEvent e) { 40 | Map map = editor.getCurrentMap(); 41 | int layerIndex = editor.getCurrentLayerIndex(); 42 | int totalLayers = map.getTotalLayers(); 43 | 44 | UndoableEdit layerDeleteEdit = new DeleteLayerEdit(editor, map, layerIndex); 45 | 46 | if (layerIndex >= 0) { 47 | map.removeLayer(layerIndex); 48 | 49 | // If the topmost layer was selected, the layer index is invalid 50 | // after removing that layer. The right thing to do is to reset it 51 | // to the new topmost layer. 52 | if (layerIndex == totalLayers - 1) { 53 | editor.setCurrentLayerIndex(totalLayers - 2); 54 | } 55 | } 56 | 57 | editor.getUndoSupport().postEdit(layerDeleteEdit); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/ExitAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import javax.swing.KeyStroke; 16 | 17 | import tiled.mapeditor.MapEditor; 18 | import tiled.mapeditor.Resources; 19 | 20 | /** 21 | * Exits the map editor. 22 | * 23 | * @version $Id$ 24 | */ 25 | public class ExitAction extends AbstractFileAction 26 | { 27 | public ExitAction(MapEditor editor, SaveAction saveAction) { 28 | super(editor, saveAction, 29 | Resources.getString("action.main.exit.name"), 30 | Resources.getString("action.main.exit.tooltip")); 31 | 32 | putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control Q")); 33 | } 34 | 35 | protected void doPerformAction() { 36 | editor.shutdown(); 37 | System.exit(0); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/MergeAllLayersAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import javax.swing.JOptionPane; 16 | 17 | import tiled.core.Map; 18 | import tiled.core.TileLayer; 19 | import tiled.mapeditor.MapEditor; 20 | import tiled.mapeditor.Resources; 21 | import tiled.util.TileMergeHelper; 22 | 23 | /** 24 | * Merges all layers of the map. Optionally it will create a new tileset with 25 | * merged tiles. 26 | * 27 | * @version $Id$ 28 | */ 29 | public class MergeAllLayersAction extends AbstractLayerAction 30 | { 31 | public MergeAllLayersAction(MapEditor editor) { 32 | super(editor, 33 | Resources.getString("action.layer.mergeall.name"), 34 | Resources.getString("action.layer.mergeall.tooltip")); 35 | } 36 | 37 | protected void doPerformAction() { 38 | Map map = editor.getCurrentMap(); 39 | 40 | // check if all layer's tiles have the same size as the map (otherwise, merging won't work and will be cancelled) 41 | if(!TileMergeHelper.areTileSizesUniform(map)) 42 | { 43 | JOptionPane.showMessageDialog(editor.getAppFrame(), "Layer tile sizes inconsistent", "The tile size of some layers is different to the default tile size of the map. Layers can't be merged.", JOptionPane.ERROR_MESSAGE); 44 | return; 45 | } 46 | 47 | 48 | int ret = JOptionPane.showConfirmDialog(editor.getAppFrame(), 49 | "Do you wish to merge tile images, and create a new tile set?", 50 | "Merge Tiles?", JOptionPane.YES_NO_CANCEL_OPTION); 51 | 52 | if (ret == JOptionPane.YES_OPTION) { 53 | TileMergeHelper tmh = new TileMergeHelper(map); 54 | int len = map.getTotalLayers(); 55 | //TODO: Add a dialog option: "Yes, visible only" 56 | TileLayer newLayer = tmh.merge(0, len, true); 57 | map.removeAllLayers(); 58 | map.addLayer(newLayer); 59 | newLayer.setName("Merged Layer"); 60 | map.addTileset(tmh.getSet()); 61 | editor.setCurrentLayerIndex(0); 62 | } 63 | else if (ret == JOptionPane.NO_OPTION) { 64 | while (map.getTotalLayers() > 1) { 65 | map.mergeLayerDown(editor.getCurrentLayerIndex()); 66 | } 67 | editor.setCurrentLayerIndex(0); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/MergeLayerDownAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import javax.swing.KeyStroke; 16 | 17 | import tiled.mapeditor.MapEditor; 18 | import tiled.mapeditor.Resources; 19 | import tiled.core.Map; 20 | 21 | /** 22 | * Merges the current layer with the one below and selects the merged layer. 23 | * 24 | * @version $Id$ 25 | */ 26 | public class MergeLayerDownAction extends AbstractLayerAction 27 | { 28 | public MergeLayerDownAction(MapEditor editor) { 29 | super(editor, 30 | Resources.getString("action.layer.mergedown.name"), 31 | Resources.getString("action.layer.mergedown.tooltip")); 32 | 33 | putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("shift control M")); 34 | } 35 | 36 | protected void doPerformAction() { 37 | Map map = editor.getCurrentMap(); 38 | int layerIndex = editor.getCurrentLayerIndex(); 39 | 40 | if (layerIndex > 0) { 41 | map.mergeLayerDown(layerIndex); 42 | editor.setCurrentLayerIndex(layerIndex - 1); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/MoveLayerDownAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import javax.swing.KeyStroke; 16 | 17 | import tiled.mapeditor.MapEditor; 18 | import tiled.mapeditor.Resources; 19 | import tiled.core.Map; 20 | 21 | /** 22 | * Swaps the currently selected layer with the layer below. 23 | * 24 | * @version $Id$ 25 | */ 26 | public class MoveLayerDownAction extends AbstractLayerAction 27 | { 28 | public MoveLayerDownAction(MapEditor editor) { 29 | super(editor, 30 | Resources.getString("action.layer.movedown.name"), 31 | Resources.getString("action.layer.movedown.tooltip"), 32 | Resources.getIcon("gnome-down.png")); 33 | 34 | putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("shift PAGE_DOWN")); 35 | } 36 | 37 | protected void doPerformAction() { 38 | Map map = editor.getCurrentMap(); 39 | int layerIndex = editor.getCurrentLayerIndex(); 40 | 41 | if (layerIndex > 0) { 42 | map.swapLayerDown(layerIndex); 43 | editor.setCurrentLayerIndex(layerIndex - 1); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/MoveLayerUpAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import javax.swing.KeyStroke; 16 | 17 | import tiled.mapeditor.MapEditor; 18 | import tiled.mapeditor.Resources; 19 | import tiled.core.Map; 20 | 21 | /** 22 | * Swaps the currently selected layer with the layer above. 23 | * 24 | * @version $Id$ 25 | */ 26 | public class MoveLayerUpAction extends AbstractLayerAction 27 | { 28 | public MoveLayerUpAction(MapEditor editor) { 29 | super(editor, 30 | Resources.getString("action.layer.moveup.name"), 31 | Resources.getString("action.layer.moveup.tooltip"), 32 | Resources.getIcon("gnome-up.png")); 33 | 34 | putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("shift PAGE_UP")); 35 | } 36 | 37 | protected void doPerformAction() { 38 | Map map = editor.getCurrentMap(); 39 | int layerIndex = editor.getCurrentLayerIndex(); 40 | int totalLayers = map.getTotalLayers(); 41 | 42 | if (layerIndex < totalLayers - 1) { 43 | map.swapLayerUp(layerIndex); 44 | editor.setCurrentLayerIndex(layerIndex + 1); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/NewMapAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import javax.swing.JFrame; 16 | import javax.swing.KeyStroke; 17 | 18 | import tiled.core.Map; 19 | import tiled.mapeditor.MapEditor; 20 | import tiled.mapeditor.Resources; 21 | import tiled.mapeditor.dialogs.NewMapDialog; 22 | 23 | /** 24 | * Creates a new map. 25 | */ 26 | public class NewMapAction extends AbstractFileAction 27 | { 28 | public NewMapAction(MapEditor editor, SaveAction saveAction) { 29 | super(editor, saveAction, 30 | Resources.getString("action.map.new.name"), 31 | Resources.getString("action.map.new.tooltip")); 32 | 33 | putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control N")); 34 | } 35 | 36 | protected void doPerformAction() { 37 | NewMapDialog nmd = new NewMapDialog((JFrame)editor.getAppFrame()); 38 | Map newMap = nmd.create(); 39 | if (newMap != null) { 40 | editor.setCurrentMap(newMap); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/OpenMapAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import javax.swing.JFileChooser; 16 | import javax.swing.JOptionPane; 17 | import javax.swing.KeyStroke; 18 | 19 | import tiled.io.MapReader; 20 | import tiled.mapeditor.MapEditor; 21 | import tiled.mapeditor.Resources; 22 | import tiled.mapeditor.util.TiledFileFilter; 23 | import tiled.util.TiledConfiguration; 24 | 25 | /** 26 | * Opens the map open dialog. 27 | * 28 | * @version $Id$ 29 | */ 30 | public class OpenMapAction extends AbstractFileAction 31 | { 32 | private static final String OPEN_ERROR_TITLE = Resources.getString("dialog.saveas.error.title"); 33 | 34 | public OpenMapAction(MapEditor editor, SaveAction saveAction) { 35 | super(editor, saveAction, 36 | Resources.getString("action.map.open.name"), 37 | Resources.getString("action.map.open.tooltip")); 38 | 39 | putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control O")); 40 | } 41 | 42 | protected void doPerformAction() { 43 | // Start at the location of the most recently loaded map file 44 | String startLocation = TiledConfiguration.fileDialogStartLocation(); 45 | 46 | JFileChooser chooser = new JFileChooser(startLocation); 47 | 48 | try { 49 | MapReader[] readers = editor.getPluginLoader().getReaders(); 50 | for (MapReader reader : readers) { 51 | chooser.addChoosableFileFilter(new TiledFileFilter( 52 | reader.getFilter(), reader.getName())); 53 | } 54 | } catch (Exception e) { 55 | JOptionPane.showMessageDialog(editor.getAppFrame(), 56 | "Error while loading plugins: " + e.getLocalizedMessage(), 57 | OPEN_ERROR_TITLE, 58 | JOptionPane.ERROR_MESSAGE); 59 | e.printStackTrace(); 60 | } 61 | 62 | chooser.addChoosableFileFilter( 63 | new TiledFileFilter(TiledFileFilter.FILTER_TMX)); 64 | 65 | int ret = chooser.showOpenDialog(editor.getAppFrame()); 66 | if (ret == JFileChooser.APPROVE_OPTION) { 67 | editor.loadMap(chooser.getSelectedFile().getAbsolutePath()); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/OpenRecentAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import java.io.File; 16 | 17 | import tiled.mapeditor.MapEditor; 18 | import tiled.mapeditor.Resources; 19 | 20 | /** 21 | * Opens one of the recently open maps. 22 | * 23 | * @version $Id$ 24 | */ 25 | public class OpenRecentAction extends AbstractFileAction 26 | { 27 | private final String path; 28 | 29 | public OpenRecentAction(MapEditor editor, SaveAction saveAction, String path) { 30 | super(editor, saveAction, 31 | path.substring(path.lastIndexOf(File.separatorChar) + 1), 32 | Resources.getString("action.map.open.tooltip")); 33 | 34 | this.path = path; 35 | } 36 | 37 | protected void doPerformAction() { 38 | editor.loadMap(path); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/SaveAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.actions; 14 | 15 | import java.awt.event.ActionEvent; 16 | 17 | import javax.swing.KeyStroke; 18 | 19 | import tiled.mapeditor.MapEditor; 20 | import tiled.mapeditor.Resources; 21 | import tiled.mapeditor.util.TiledFileFilter; 22 | import tiled.core.Map; 23 | 24 | /** 25 | * Tries to save the file if a filepath is already set in the main app, 26 | * otherwise prompts for a filename. 27 | * 28 | * @version $Id$ 29 | */ 30 | public class SaveAction extends SaveAsAction 31 | { 32 | public SaveAction(MapEditor editor) { 33 | super(editor); 34 | putValue(NAME, Resources.getString("action.map.save.name")); 35 | putValue(SHORT_DESCRIPTION, Resources.getString("action.map.save.tooltip")); 36 | putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control S")); 37 | } 38 | 39 | public void actionPerformed (ActionEvent e) 40 | { 41 | Map currentMap = editor.getCurrentMap(); 42 | String filePath = currentMap.getFilename(); 43 | 44 | // todo: Fix the case where the plugin cannot be determined by the 45 | // todo: current filename. This can happen when the user has used 46 | // todo: "Save As" to save the file using a non-standard extension. 47 | if (filePath != null) { 48 | // The plugin is determined by the extention. 49 | saveFile(new TiledFileFilter(TiledFileFilter.FILTER_EXT), 50 | filePath); 51 | } 52 | else { 53 | super.actionPerformed(e); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/actions/ShowLayerPropertiesAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.actions; 7 | 8 | import java.awt.event.ActionEvent; 9 | import javax.swing.AbstractAction; 10 | import tiled.core.MapLayer; 11 | import tiled.mapeditor.MapEditor; 12 | import tiled.mapeditor.Resources; 13 | import tiled.mapeditor.dialogs.LayerPropertiesDialog; 14 | import tiled.mapeditor.dialogs.PropertiesDialog; 15 | 16 | /** 17 | * 18 | * @author upachler 19 | */ 20 | public class ShowLayerPropertiesAction extends AbstractAction { 21 | 22 | private static final String ACTION_NAME = Resources.getString("menu.layer.properties"); 23 | private static final String ACTION_TOOLTIP = Resources.getString("menu.layer.properties.tooltip"); 24 | 25 | private MapEditor editor; 26 | 27 | public ShowLayerPropertiesAction(MapEditor editor){ 28 | super(ACTION_NAME); 29 | putValue(SHORT_DESCRIPTION, ACTION_TOOLTIP); 30 | this.editor = editor; 31 | } 32 | 33 | public void actionPerformed(ActionEvent e) { 34 | MapLayer layer = editor.getCurrentLayer(); 35 | PropertiesDialog lpd = 36 | new LayerPropertiesDialog(editor.getAppFrame(), layer, editor.getUndoSupport()); 37 | lpd.setTitle(layer.getName() + " " + Resources.getString("dialog.properties.title")); 38 | lpd.getProps(); 39 | editor.updateLayerOperations(); 40 | editor.getMapView().repaint(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/brush/AbstractBrush.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.brush; 14 | 15 | import java.awt.*; 16 | 17 | import tiled.core.MultilayerPlane; 18 | import tiled.view.MapView; 19 | 20 | 21 | public abstract class AbstractBrush extends MultilayerPlane implements Brush 22 | { 23 | protected int numLayers = 1; 24 | protected MultilayerPlane affectedMp; 25 | protected boolean paintingStarted = false; 26 | protected int initLayer; 27 | 28 | public AbstractBrush() { 29 | } 30 | 31 | public AbstractBrush(AbstractBrush ab) { 32 | numLayers = ab.numLayers; 33 | } 34 | 35 | /** 36 | * This will set the number of layers to affect, the default is 1 - the 37 | * layer specified in commitPaint. 38 | * 39 | * @see Brush#doPaint(int, int) 40 | * @param num the number of layers to affect. 41 | */ 42 | public void setAffectedLayers(int num) { 43 | numLayers = num; 44 | } 45 | 46 | public int getAffectedLayers() { 47 | return numLayers; 48 | } 49 | 50 | public void startPaint(MultilayerPlane mp, int x, int y, int button, int layer) { 51 | affectedMp = mp; 52 | initLayer = layer; 53 | paintingStarted = true; 54 | } 55 | 56 | public Rectangle doPaint(int x, int y) throws Exception { 57 | if (!paintingStarted) throw new Exception("Attempted to call doPaint() without calling startPaint()!"); 58 | return null; 59 | } 60 | 61 | public void endPaint() { 62 | paintingStarted = false; 63 | } 64 | 65 | public void drawPreview(Graphics2D g2d, Dimension dimension, MapView mv) { 66 | // todo: draw an off-map preview here 67 | } 68 | 69 | public abstract Shape getShape(); 70 | } 71 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/brush/Brush.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.brush; 14 | 15 | import java.awt.*; 16 | 17 | import tiled.core.MultilayerPlane; 18 | import tiled.view.MapView; 19 | 20 | 21 | public interface Brush 22 | { 23 | /** 24 | * Returns the number of layers affected by this brush. 25 | * 26 | * @return int 27 | */ 28 | public int getAffectedLayers(); 29 | 30 | /** 31 | * Returns the bounds of this brush. This is used for determining the area 32 | * to redraw when the brush moves. 33 | */ 34 | public Rectangle getBounds(); 35 | 36 | /** 37 | * Called before painting operation starts. This is when the mouse is 38 | * initially pressed. 39 | * 40 | * @param mp the MultilayerPlane to be affected. 41 | * @param x the tile x-coordinate where the user initiated the paint. 42 | * @param y the tile y-coordinate where the user initiated the paint. 43 | * @param button the mouse button that was used. 44 | * @param layer the selected layer. 45 | * 46 | * @see MultilayerPlane 47 | */ 48 | public void startPaint( 49 | MultilayerPlane mp, int x, int y, int button, int layer); 50 | 51 | /** 52 | * This is the main processing method for a brush. This method should only 53 | * be called between calls to startPaint and endPaint. 54 | * 55 | * @param x the tile x-coordinate of the mouse. 56 | * @param y the tile y-coordinate of the mouse. 57 | * 58 | * @return the rectangular region affected by the painting, used to 59 | * determine which area to redraw. 60 | * @throws Exception 61 | */ 62 | public Rectangle doPaint(int x, int y) throws Exception; 63 | 64 | /** 65 | * Called when painting operation finishes. This is when the mouse is 66 | * released. 67 | */ 68 | public void endPaint(); 69 | 70 | /** 71 | * Draws a preview of the editing operation when applicable. 72 | * 73 | * @param g2d The graphics context to draw to. 74 | * @param mv 75 | */ 76 | public void drawPreview(Graphics2D g2d, MapView mv); 77 | 78 | /** 79 | * Draws a preview of the editing operation when applicable. This is meant 80 | * for off-map brush preview. The map view is provided for drawing map-view 81 | * dependant previews. 82 | * 83 | * @param g2d The graphics context to draw to. 84 | * @param dimension The dimension within which the preview should be drawn 85 | * @param mv The active map view. 86 | */ 87 | public void drawPreview(Graphics2D g2d, Dimension dimension, MapView mv); 88 | 89 | /** 90 | * Returns wether this brush equals another brush. 91 | * 92 | * @param brush 93 | * @return boolean 94 | */ 95 | public boolean equals(Brush brush); 96 | } 97 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/brush/BrushException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.brush; 7 | 8 | import tiled.core.MapLayer; 9 | 10 | /** 11 | * 12 | * @author upachler 13 | */ 14 | public class BrushException extends Exception { 15 | private MapLayer layer; 16 | 17 | public BrushException(MapLayer layer) { 18 | this.layer = layer; 19 | } 20 | 21 | public MapLayer getLayer(){ 22 | return layer; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/brush/CustomBrush.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.brush; 14 | 15 | import java.awt.Graphics2D; 16 | import java.awt.Rectangle; 17 | import java.awt.Shape; 18 | import java.util.ListIterator; 19 | 20 | import tiled.core.MapLayer; 21 | import tiled.core.MultilayerPlane; 22 | import tiled.core.TileLayer; 23 | import tiled.view.MapView; 24 | 25 | public class CustomBrush extends AbstractBrush 26 | { 27 | public CustomBrush(MultilayerPlane mlp) { 28 | addAllLayers(mlp.getLayerVector()); 29 | fitBoundsToLayers(); 30 | } 31 | 32 | public CustomBrush(TileLayer tileLayer) { 33 | addLayer(tileLayer); 34 | fitBoundsToLayers(); 35 | } 36 | 37 | public void setAffectedLayers(int num) { 38 | } 39 | 40 | public int getAffectedLayers() { 41 | return getTotalLayers(); 42 | } 43 | 44 | public Shape getShape() { 45 | return getBounds(); 46 | } 47 | 48 | /** 49 | * Determines whether this brush is equal to another brush. 50 | */ 51 | public boolean equals(Brush b) { 52 | if (b instanceof CustomBrush) { 53 | if (b == this) return true; 54 | else { 55 | //TODO: THIS 56 | } 57 | } 58 | return false; 59 | } 60 | 61 | public void startPaint(MultilayerPlane mp, int x, int y, int button, int layer) { 62 | super.startPaint(mp, x, y, button, layer); 63 | } 64 | 65 | /** 66 | * The custom brush will merge its internal layers onto the layers of the 67 | * specified MultilayerPlane. 68 | * 69 | * @see tiled.core.TileLayer#mergeOnto(tiled.core.MapLayer) 70 | * @see tiled.mapeditor.brush.Brush#doPaint(int, int) 71 | * @throws Exception 72 | */ 73 | public Rectangle doPaint(int x, int y) throws Exception 74 | { 75 | int layer = initLayer; 76 | int centerx = x - bounds.width / 2; 77 | int centery = y - bounds.height / 2; 78 | 79 | super.doPaint(x, y); 80 | 81 | ListIterator itr = getLayers(); 82 | while (itr.hasNext()) { 83 | TileLayer tl = (TileLayer)itr.next(); 84 | TileLayer tm = (TileLayer)affectedMp.getLayer(layer++); 85 | if (tm != null && tm.isVisible()) { 86 | tl.setOffset(centerx, centery); 87 | tl.mergeOnto(tm); 88 | } 89 | } 90 | 91 | return new Rectangle(centerx, centery, bounds.width, bounds.height); 92 | } 93 | 94 | public void drawPreview(Graphics2D g2d, MapView mv) { 95 | mv.paintSubMap(this, g2d, 0.5f); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/brush/LayerInvisibleBrushException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.brush; 7 | 8 | import tiled.core.MapLayer; 9 | 10 | /** 11 | * 12 | * @author upachler 13 | */ 14 | public class LayerInvisibleBrushException extends BrushException { 15 | 16 | public LayerInvisibleBrushException(MapLayer ml) { 17 | super(ml); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/brush/LayerLockedBrushException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.brush; 7 | 8 | import tiled.core.MapLayer; 9 | 10 | /** 11 | * 12 | * @author upachler 13 | */ 14 | public class LayerLockedBrushException extends BrushException { 15 | 16 | public LayerLockedBrushException(MapLayer ml) { 17 | super(ml); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/brush/RandomBrush.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.brush; 14 | 15 | import java.awt.Rectangle; 16 | import java.awt.geom.Area; 17 | 18 | import tiled.core.MultilayerPlane; 19 | import tiled.core.TileLayer; 20 | import tiled.util.MersenneTwister; 21 | 22 | /** 23 | * @version $Id$ 24 | */ 25 | public class RandomBrush extends ShapeBrush 26 | { 27 | private final MersenneTwister mt; 28 | private double ratio = 0.5; 29 | 30 | public RandomBrush(Area shape) { 31 | super(shape); 32 | mt = new MersenneTwister(System.currentTimeMillis()); 33 | } 34 | 35 | public RandomBrush(AbstractBrush sb) { 36 | super(sb); 37 | mt = new MersenneTwister(System.currentTimeMillis()); 38 | if (sb instanceof RandomBrush) { 39 | ratio = ((RandomBrush)sb).ratio; 40 | } 41 | } 42 | 43 | public void setRatio(double r) { 44 | ratio = r; 45 | } 46 | 47 | public double getRatio() { 48 | return ratio; 49 | } 50 | 51 | /** 52 | * Uses the MersenneTwister to fill in a random amount of the area 53 | * of the brush. Uses the formula: x % 101 <= 100*ratio where, 'x' 54 | * is a random number, to determine if a specific tile should be 55 | * painted or not 56 | * 57 | * @see ShapeBrush#doPaint 58 | * @return a Rectangle of the bounds of the area that was modified 59 | * @param x The x-coordinate where the click occurred. 60 | * @param y The y-coordinate where the click occurred. 61 | */ 62 | public Rectangle doPaint(int x, int y) 63 | { 64 | Rectangle shapeBounds = shape.getBounds(); 65 | int centerx = x - shapeBounds.width / 2; 66 | int centery = y - shapeBounds.height / 2; 67 | 68 | for (int i = 0; i < numLayers; i++) { 69 | TileLayer tl = (TileLayer) affectedMp.getLayer(initLayer - i); 70 | if (tl != null) { 71 | for (int cy = 0; cy <= shapeBounds.height; cy++) { 72 | for (int cx = 0; cx < shapeBounds.width; cx++) { 73 | if (shape.contains(cx, cy) && 74 | mt.genrand() % 101 <= 100 * ratio) 75 | { 76 | tl.setTileAt( 77 | cx + centerx, cy + centery, paintTile); 78 | } 79 | } 80 | } 81 | } 82 | } 83 | 84 | return new Rectangle( 85 | centerx, centery, shapeBounds.width, shapeBounds.height); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/dialogs/PluginLogDialog.java: -------------------------------------------------------------------------------- 1 | package tiled.mapeditor.dialogs; 2 | 3 | import javax.swing.JDialog; 4 | 5 | public class PluginLogDialog extends JDialog { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/dungeon/Builder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.dungeon; 14 | 15 | import tiled.core.Map; 16 | 17 | abstract public class Builder 18 | { 19 | public static final int NORTH = 1; 20 | public static final int EAST = 2; 21 | public static final int SOUTH = 3; 22 | public static final int WEST = 4; 23 | 24 | protected int movesPerIteration = 0; 25 | protected int direction = NORTH; 26 | protected int wallTileId = 0, 27 | floorTileId = 0, 28 | doorTileId = 0; 29 | private int ttl; 30 | protected int mapx, mapy; 31 | 32 | public Builder() { 33 | } 34 | 35 | public Builder(int x, int y, int dir) { 36 | mapx = x; 37 | mapy = y; 38 | direction = dir; 39 | } 40 | 41 | public void decrementTtl() { 42 | ttl--; 43 | } 44 | 45 | public int getTtl() { 46 | return ttl; 47 | } 48 | 49 | public abstract void iterate(); 50 | public abstract Builder spawn(); 51 | public abstract void store(Map m); 52 | } 53 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/dungeon/CorridorBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.dungeon; 14 | 15 | import tiled.core.Map; 16 | 17 | public class CorridorBuilder extends Builder 18 | { 19 | public void iterate() { 20 | } 21 | 22 | public Builder spawn() { 23 | return null; 24 | } 25 | 26 | public void store(Map m) { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/back.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/cursor-pencil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/cursor-pencil.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/document-save-as.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/document-save-as.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/document-save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/document-save.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/empty.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/forward.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/forward.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-duplicate-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-duplicate-16.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-flip-horizontal-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-flip-horizontal-16.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-flip-vertical-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-flip-vertical-16.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-rotate-180-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-rotate-180-16.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-rotate-270-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-rotate-270-16.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-rotate-90-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-rotate-90-16.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-tool-bucket-fill-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-tool-bucket-fill-22.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-tool-color-picker-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-tool-color-picker-22.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-tool-eraser-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-tool-eraser-22.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-tool-move-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-tool-move-22.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-tool-object-move-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-tool-object-move-22.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-tool-pencil-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-tool-pencil-22.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gimp-tool-rect-select-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gimp-tool-rect-select-22.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gnome-delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gnome-delete.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gnome-down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gnome-down.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gnome-list-add-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gnome-list-add-22.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gnome-list-remove-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gnome-list-remove-22.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gnome-new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gnome-new.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gnome-up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gnome-up.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gnome-zoom-in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gnome-zoom-in.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gnome-zoom-out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gnome-zoom-out.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gtk-edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gtk-edit.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gui_de.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gui_de.properties -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gui_es.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gui_es.properties -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gui_fr.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gui_fr.properties -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/gui_it.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/gui_it.properties -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/insert-object.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/insert-object.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/lastframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/lastframe.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/logo.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/play.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/propertyflag-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/propertyflag-12.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/source.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/source.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/startframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/startframe.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/stock_animation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/stock_animation.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/stop.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/resources/visible.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeditor/tiled-java/3e77ba2f64f7a08287a3cad6365d01a44c09b954/src/tiled/mapeditor/resources/visible.png -------------------------------------------------------------------------------- /src/tiled/mapeditor/selection/ObjectSelection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.selection; 7 | 8 | import tiled.core.MapObject; 9 | import tiled.core.ObjectGroup; 10 | 11 | /** 12 | * 13 | * @author upachler 14 | */ 15 | public class ObjectSelection implements Selection{ 16 | private ObjectGroup layer; 17 | private MapObject object; 18 | 19 | public ObjectSelection(ObjectGroup layer, MapObject o) { 20 | this.layer = layer; 21 | this.object = o; 22 | } 23 | 24 | @Override 25 | public boolean equals(Object o){ 26 | if(!(o instanceof ObjectSelection)) 27 | return false; 28 | ObjectSelection os = (ObjectSelection)o; 29 | return os.getLayer() == layer && os.getObject() == object; 30 | } 31 | 32 | @Override 33 | public int hashCode() { 34 | int hash = 5; 35 | hash = 97 * hash + (this.layer != null ? this.layer.hashCode() : 0); 36 | hash = 97 * hash + (this.object != null ? this.object.hashCode() : 0); 37 | return hash; 38 | } 39 | 40 | public ObjectGroup getLayer(){ 41 | return layer; 42 | } 43 | 44 | public MapObject getObject(){ 45 | return object; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/selection/Selection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.selection; 7 | 8 | /** 9 | * This interface wraps a selection of some kind of object. A selection 10 | * is a reference to some document model's object, in tiled's case this 11 | * may be a MapObject or a rectangular area in a TileLayer. 12 | * @author upachler 13 | */ 14 | public interface Selection { 15 | } 16 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/selection/SelectionSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.selection; 7 | 8 | import java.util.HashSet; 9 | import java.util.Iterator; 10 | import java.util.Set; 11 | import java.util.Vector; 12 | 13 | /** 14 | * 15 | * @author upachler 16 | */ 17 | public class SelectionSet implements Iterable{ 18 | Set set = new HashSet(); 19 | private Vector listeners = new Vector(); 20 | 21 | public void addSelectionListener(SelectionSetListener l){ 22 | listeners.add(l); 23 | } 24 | 25 | public void removeSelectionListener(SelectionSetListener l){ 26 | listeners.remove(l); 27 | } 28 | 29 | /** 30 | * Adds a Selection to the selection set. 31 | * @param selection 32 | */ 33 | void addSelection(Selection selection){ 34 | addSelection(new Selection[]{selection}); 35 | } 36 | 37 | void addSelection(Selection[] selections){ 38 | for(Selection s : selections) 39 | set.add(s); 40 | fireSelectionAdded(selections); 41 | } 42 | 43 | void clearSelection() { 44 | if(set.size()==0) 45 | return; 46 | Selection[] a = set.toArray(new Selection[set.size()]); 47 | set.clear(); 48 | fireSelectionRemoved(a); 49 | } 50 | 51 | /** 52 | * clears the selection set and adds the given selection 53 | * 54 | */ 55 | void setSelection(Selection selection){ 56 | setSelection(new Selection[]{selection}); 57 | } 58 | 59 | void setSelection(Selection[] selections){ 60 | clearSelection(); 61 | addSelection(selections); 62 | } 63 | 64 | public Iterator iterator() { 65 | return set.iterator(); 66 | } 67 | 68 | private void fireSelectionAdded(Selection[] selections) { 69 | for(SelectionSetListener l : listeners) 70 | l.selectionAdded(this, selections); 71 | } 72 | 73 | private void fireSelectionRemoved(Selection[] a) { 74 | for(SelectionSetListener l : listeners) 75 | l.selectionRemoved(this, a); 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/selection/SelectionSetListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.selection; 7 | 8 | /** 9 | * 10 | * @author upachler 11 | */ 12 | public interface SelectionSetListener { 13 | 14 | public void selectionAdded(SelectionSet selectionSet, Selection[] selections); 15 | 16 | public void selectionRemoved(SelectionSet selectionSet, Selection[] selections); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/selection/ToolSemantic.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.selection; 7 | 8 | import tiled.mapeditor.MapEditor; 9 | 10 | /** 11 | * A tool semantic gives a tool a meaning. A tool is typically represented by 12 | * a single button in a tool bar, and is therefore percieved as atomic by the 13 | * user. However, the same tool might need to behave differently in different 14 | * circumstances, and therefore more than one ToolSemantic will be associated 15 | * with that tool. 16 | * For instance, a selection tool might have different semantics depending on 17 | * the type of layer that is currently selected. Selection might work different 18 | * for different layer types. 19 | * The ToolSemantic instance will be registered as listener for mouse events 20 | * with a MapView, which allows it to react to events generated by it 21 | * @author upachler 22 | */ 23 | public abstract class ToolSemantic { 24 | private MapEditor editor; 25 | 26 | ToolSemantic(MapEditor editor){ 27 | this.editor = editor; 28 | } 29 | 30 | /** 31 | * Activates this tool semantic. This basically means that the 32 | * user performed an action that makes this semantic the 33 | * currently active one (like selecting the tool associated with 34 | * this semantic in the tool bar). 35 | */ 36 | public void activate(){ 37 | } 38 | 39 | /** 40 | * Deactivates this tool semantic. This is called when the user selects 41 | * a different tool from the tool bar, or if a different semantic becomes 42 | * active for that tool. 43 | */ 44 | public void deactivate(){ 45 | } 46 | 47 | public MapEditor getEditor() { 48 | return editor; 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/undo/AddObjectEdit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2008 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.undo; 14 | 15 | import javax.swing.undo.AbstractUndoableEdit; 16 | import javax.swing.undo.CannotRedoException; 17 | import javax.swing.undo.CannotUndoException; 18 | 19 | import tiled.core.MapObject; 20 | import tiled.core.ObjectGroup; 21 | import tiled.mapeditor.Resources; 22 | 23 | /** 24 | * Adds an object to an object group. 25 | * 26 | * @version $Id$ 27 | */ 28 | public class AddObjectEdit extends AbstractUndoableEdit 29 | { 30 | private final ObjectGroup objectGroup; 31 | private final MapObject mapObject; 32 | 33 | public AddObjectEdit(ObjectGroup objectGroup, MapObject mapObject) { 34 | this.objectGroup = objectGroup; 35 | this.mapObject = mapObject; 36 | } 37 | 38 | public void undo() throws CannotUndoException { 39 | super.undo(); 40 | objectGroup.removeObject(mapObject); 41 | } 42 | 43 | public void redo() throws CannotRedoException { 44 | super.redo(); 45 | objectGroup.addObject(mapObject); 46 | } 47 | 48 | public String getPresentationName() { 49 | return Resources.getString("action.object.add.name"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/undo/ChangeObjectEdit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2008 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.undo; 14 | 15 | import java.awt.Rectangle; 16 | import java.util.Properties; 17 | import javax.swing.undo.AbstractUndoableEdit; 18 | import javax.swing.undo.CannotRedoException; 19 | import javax.swing.undo.CannotUndoException; 20 | 21 | import tiled.core.MapObject; 22 | import tiled.mapeditor.Resources; 23 | 24 | /** 25 | * Changes the attributes and properties of an object. 26 | */ 27 | public class ChangeObjectEdit extends AbstractUndoableEdit 28 | { 29 | private final MapObject mapObject; 30 | private State state; 31 | 32 | class State{ 33 | private String name; 34 | private String type; 35 | private String imageSource; 36 | private Rectangle bounds; 37 | private final Properties properties = new Properties(); 38 | 39 | public void retreive(MapObject o){ 40 | name = mapObject.getName(); 41 | type = mapObject.getType(); 42 | imageSource = mapObject.getImageSource(); 43 | bounds = new Rectangle(mapObject.getBounds()); 44 | properties.clear(); 45 | properties.putAll(mapObject.getProperties()); 46 | } 47 | 48 | public void apply(MapObject mapObject){ 49 | mapObject.setName(name); 50 | mapObject.setType(type); 51 | mapObject.setImageSource(imageSource); 52 | mapObject.setBounds(new Rectangle(bounds)); 53 | mapObject.getProperties().clear(); 54 | mapObject.getProperties().putAll(properties); 55 | } 56 | }; 57 | 58 | public ChangeObjectEdit(MapObject mapObject) { 59 | this.mapObject = mapObject; 60 | 61 | // Store the previous state so we can undo changes 62 | state = new State(); 63 | state.retreive(mapObject); 64 | } 65 | 66 | public void undo() throws CannotUndoException { 67 | super.undo(); 68 | 69 | // Store the current state so we can redo changes 70 | swap(); 71 | } 72 | 73 | public void redo() throws CannotRedoException { 74 | super.redo(); 75 | 76 | swap(); 77 | } 78 | 79 | private void swap() { 80 | State s = new State(); 81 | s.retreive(mapObject); 82 | state.apply(mapObject); 83 | state = s; 84 | } 85 | 86 | public String getPresentationName() { 87 | return Resources.getString("action.object.change.name"); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/undo/ChangePropertiesEdit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.undo; 7 | 8 | import java.util.Properties; 9 | import javax.swing.undo.AbstractUndoableEdit; 10 | import tiled.mapeditor.Resources; 11 | 12 | /** 13 | * 14 | * @author upachler 15 | */ 16 | public class ChangePropertiesEdit extends AbstractUndoableEdit { 17 | private boolean undone = false; 18 | private Properties backupProperties; 19 | private Properties properties; 20 | 21 | /// creates a new edit that stores a backup of the layer's old Properties 22 | /// object. Note that this object needs to be a clone of the the layer's 23 | /// property object in its state before the edit was performed. 24 | public ChangePropertiesEdit(Properties properties, Properties oldPropertiesCopy) { 25 | backupProperties = oldPropertiesCopy; 26 | this.properties = properties; 27 | } 28 | 29 | public void undo(){ 30 | super.undo(); 31 | assert !undone; 32 | swapProperties(); 33 | undone = true; 34 | } 35 | 36 | public void redo(){ 37 | super.redo(); 38 | assert undone; 39 | swapProperties(); 40 | undone = false; 41 | } 42 | 43 | private void swapProperties() { 44 | Properties newBackupProperties = (Properties) properties.clone(); 45 | properties.clear(); 46 | properties.putAll(backupProperties); 47 | backupProperties = newBackupProperties; 48 | } 49 | 50 | @Override 51 | public String getPresentationName() { 52 | return Resources.getString("edit.changeproperties.name"); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/undo/DeleteLayerEdit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.undo; 7 | 8 | import javax.swing.undo.AbstractUndoableEdit; 9 | import javax.swing.undo.CannotRedoException; 10 | import javax.swing.undo.CannotUndoException; 11 | import tiled.core.Map; 12 | import tiled.core.MapLayer; 13 | import tiled.mapeditor.MapEditor; 14 | import tiled.mapeditor.Resources; 15 | 16 | /** 17 | * 18 | * @author upachler 19 | */ 20 | public class DeleteLayerEdit extends AbstractUndoableEdit { 21 | private MapEditor editor; 22 | 23 | private Map map; 24 | private int index; 25 | private MapLayer layer = null; 26 | 27 | public DeleteLayerEdit(MapEditor editor, Map map, int index) { 28 | this.editor = editor; 29 | this.map = map; 30 | this.index = index; 31 | this.layer = map.getLayer(index); 32 | } 33 | 34 | public void undo() throws CannotUndoException { 35 | assert layer != null; 36 | super.undo(); 37 | map.insertLayer(index, layer); 38 | if(editor.getCurrentLayerIndex() >= map.getTotalLayers()) 39 | editor.setCurrentLayerIndex(map.getTotalLayers()-1); 40 | layer = null; 41 | } 42 | 43 | public void redo() throws CannotRedoException { 44 | assert layer == null; 45 | super.redo(); 46 | layer = map.getLayer(index); 47 | map.removeLayer(index); 48 | } 49 | 50 | public String getPresentationName() { 51 | return Resources.getString("action.layer.delete.name"); 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/undo/MapLayerEdit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.undo; 14 | 15 | import javax.swing.undo.AbstractUndoableEdit; 16 | import javax.swing.undo.CannotRedoException; 17 | import javax.swing.undo.CannotUndoException; 18 | import javax.swing.undo.UndoableEdit; 19 | 20 | import tiled.core.MapLayer; 21 | 22 | /** 23 | * @version $Id$ 24 | */ 25 | public class MapLayerEdit extends AbstractUndoableEdit 26 | { 27 | private final MapLayer editedLayer; 28 | private MapLayer layerUndo, layerRedo; 29 | private String name; 30 | private boolean inProgress; 31 | 32 | public MapLayerEdit(MapLayer layer, MapLayer before) { 33 | editedLayer = layer; 34 | start(before); 35 | } 36 | 37 | public MapLayerEdit(MapLayer layer, MapLayer before, MapLayer after) { 38 | this(layer, before); 39 | end(after); 40 | } 41 | 42 | public void start(MapLayer fml) { 43 | layerUndo = fml; 44 | inProgress = true; 45 | } 46 | 47 | public void end(MapLayer fml) { 48 | if (!inProgress) { 49 | new Exception("end called before start").printStackTrace(); 50 | } 51 | if (fml != null) { 52 | layerRedo = fml; 53 | inProgress = false; 54 | } 55 | } 56 | 57 | public MapLayer getStart() { 58 | return layerUndo; 59 | } 60 | 61 | /* inherited methods */ 62 | public void undo() throws CannotUndoException { 63 | if (editedLayer == null) { 64 | throw new CannotUndoException(); 65 | } 66 | layerUndo.copyTo(editedLayer); 67 | } 68 | 69 | public boolean canUndo() { 70 | return layerUndo != null && editedLayer != null; 71 | } 72 | 73 | public void redo() throws CannotRedoException { 74 | if (editedLayer == null) { 75 | throw new CannotRedoException(); 76 | } 77 | layerRedo.copyTo(editedLayer); 78 | } 79 | 80 | public boolean canRedo() { 81 | return layerRedo != null && editedLayer != null; 82 | } 83 | 84 | public void die() { 85 | layerUndo = null; 86 | layerRedo = null; 87 | inProgress = false; 88 | } 89 | 90 | public boolean addEdit(UndoableEdit anEdit) { 91 | if (inProgress && anEdit.getClass() == getClass()) { 92 | //TODO: absorb the edit 93 | //return true; 94 | } 95 | return false; 96 | } 97 | 98 | public void setPresentationName(String s) { 99 | name = s; 100 | } 101 | 102 | public String getPresentationName() { 103 | return name; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/undo/MapLayerStateEdit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.undo; 14 | 15 | import java.util.Vector; 16 | import javax.swing.undo.AbstractUndoableEdit; 17 | import javax.swing.undo.CannotRedoException; 18 | import javax.swing.undo.CannotUndoException; 19 | 20 | import tiled.core.Map; 21 | import tiled.core.MapLayer; 22 | 23 | /** 24 | * A change in the layer state. Used for adding, removing and rearranging 25 | * the layer stack of a map. 26 | */ 27 | public class MapLayerStateEdit extends AbstractUndoableEdit 28 | { 29 | private final Map map; 30 | private final Vector layersBefore; 31 | private final Vector layersAfter; 32 | private final String name; 33 | 34 | public MapLayerStateEdit(Map m, 35 | Vector before, 36 | Vector after, 37 | String name) { 38 | map = m; 39 | layersBefore = before; 40 | layersAfter = after; 41 | this.name = name; 42 | } 43 | 44 | public void undo() throws CannotUndoException { 45 | super.undo(); 46 | map.setLayerVector(layersBefore); 47 | } 48 | 49 | public void redo() throws CannotRedoException { 50 | super.redo(); 51 | map.setLayerVector(layersAfter); 52 | } 53 | 54 | public String getPresentationName() { 55 | return name; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/undo/MapViewportSettingsEdit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.undo; 7 | 8 | import java.util.logging.Level; 9 | import java.util.logging.Logger; 10 | import javax.swing.undo.AbstractUndoableEdit; 11 | import tiled.core.Map; 12 | import tiled.mapeditor.Resources; 13 | 14 | /** 15 | * 16 | * @author count 17 | */ 18 | public class MapViewportSettingsEdit extends AbstractUndoableEdit { 19 | private static class ViewportState implements Cloneable{ 20 | public int viewportWidth; 21 | public int viewportHeight; 22 | public float eyeDistance; 23 | public void readFrom(Map map){ 24 | viewportWidth = map.getViewportWidth(); 25 | viewportHeight = map.getViewportHeight(); 26 | eyeDistance = map.getEyeDistance(); 27 | } 28 | public void writeTo(Map map){ 29 | map.setViewportWidth(viewportWidth); 30 | map.setViewportHeight(viewportHeight); 31 | map.setEyeDistance(eyeDistance); 32 | } 33 | public ViewportState duplicate(){ 34 | try { 35 | return (ViewportState) clone(); 36 | } catch (CloneNotSupportedException ex) { 37 | Logger.getLogger(MapViewportSettingsEdit.class.getName()).log(Level.SEVERE, null, ex); 38 | return null; 39 | } 40 | } 41 | } 42 | private ViewportState backupState; 43 | private boolean undone = false; 44 | private Map map; 45 | 46 | public MapViewportSettingsEdit(Map map) { 47 | backupState = new ViewportState(); 48 | backupState.readFrom(map); 49 | this.map = map; 50 | } 51 | 52 | public void undo(){ 53 | super.undo(); 54 | assert !undone; 55 | swapViewportState(); 56 | undone = true; 57 | } 58 | 59 | public void redo(){ 60 | super.redo(); 61 | assert undone; 62 | swapViewportState(); 63 | undone = false; 64 | } 65 | 66 | private void swapViewportState() { 67 | ViewportState s = (ViewportState)backupState.duplicate(); 68 | s.readFrom(map); 69 | backupState.writeTo(map); 70 | backupState = s; 71 | } 72 | 73 | @Override 74 | public String getPresentationName() { 75 | return Resources.getString("edit.change.map.viewport.name"); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/undo/MoveLayerEdit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.undo; 14 | 15 | import java.awt.Point; 16 | import javax.swing.undo.AbstractUndoableEdit; 17 | import javax.swing.undo.CannotRedoException; 18 | import javax.swing.undo.CannotUndoException; 19 | 20 | import tiled.core.MapLayer; 21 | import tiled.mapeditor.Resources; 22 | 23 | /** 24 | * @version $Id$ 25 | */ 26 | public class MoveLayerEdit extends AbstractUndoableEdit 27 | { 28 | private final MapLayer layer; 29 | private final Point moveDist; 30 | 31 | public MoveLayerEdit(MapLayer layer, Point moveDist) { 32 | this.layer = layer; 33 | this.moveDist = moveDist; 34 | } 35 | 36 | public void undo() throws CannotUndoException { 37 | super.undo(); 38 | layer.translate(-moveDist.x, -moveDist.y); 39 | } 40 | 41 | public void redo() throws CannotRedoException { 42 | super.redo(); 43 | layer.translate(moveDist.x, moveDist.y); 44 | } 45 | 46 | public String getPresentationName() { 47 | return Resources.getString("action.layer.move.name"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/undo/MoveObjectEdit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2008 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.undo; 14 | 15 | import java.awt.Point; 16 | import javax.swing.undo.AbstractUndoableEdit; 17 | import javax.swing.undo.CannotRedoException; 18 | import javax.swing.undo.CannotUndoException; 19 | 20 | import tiled.core.MapObject; 21 | import tiled.mapeditor.Resources; 22 | 23 | /** 24 | * Moves an object. 25 | */ 26 | public class MoveObjectEdit extends AbstractUndoableEdit 27 | { 28 | private final MapObject mapObject; 29 | private final Point moveDist; 30 | 31 | public MoveObjectEdit(MapObject mapObject, Point moveDist) { 32 | this.mapObject = mapObject; 33 | this.moveDist = moveDist; 34 | } 35 | 36 | public void undo() throws CannotUndoException { 37 | super.undo(); 38 | mapObject.translate(-moveDist.x, -moveDist.y); 39 | } 40 | 41 | public void redo() throws CannotRedoException { 42 | super.redo(); 43 | mapObject.translate(moveDist.x, moveDist.y); 44 | } 45 | 46 | public String getPresentationName() { 47 | return Resources.getString("action.object.move.name"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/undo/RemoveObjectEdit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2008 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.undo; 14 | 15 | import javax.swing.undo.AbstractUndoableEdit; 16 | import javax.swing.undo.CannotRedoException; 17 | import javax.swing.undo.CannotUndoException; 18 | 19 | import tiled.core.MapObject; 20 | import tiled.core.ObjectGroup; 21 | import tiled.mapeditor.Resources; 22 | 23 | /** 24 | * Removes an object from an object group. 25 | * 26 | * @version $Id$ 27 | */ 28 | public class RemoveObjectEdit extends AbstractUndoableEdit 29 | { 30 | private final ObjectGroup objectGroup; 31 | private final MapObject mapObject; 32 | 33 | public RemoveObjectEdit(ObjectGroup objectGroup, MapObject mapObject) { 34 | this.objectGroup = objectGroup; 35 | this.mapObject = mapObject; 36 | } 37 | 38 | public void undo() throws CannotUndoException { 39 | super.undo(); 40 | objectGroup.addObject(mapObject); 41 | } 42 | 43 | public void redo() throws CannotRedoException { 44 | super.redo(); 45 | objectGroup.removeObject(mapObject); 46 | } 47 | 48 | public String getPresentationName() { 49 | return Resources.getString("action.object.remove.name"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/util/ConfirmableFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.util; 14 | 15 | import javax.swing.filechooser.FileFilter; 16 | 17 | /** 18 | * A file filter with an additional method to query the default extension used 19 | * by files filtered with this file filter. Used by the 20 | * {@link ConfirmingFileChooser} to add this default extension when left out. 21 | * 22 | * @version $Id$ 23 | */ 24 | public abstract class ConfirmableFileFilter extends FileFilter 25 | { 26 | /** 27 | * Returns the default extension used by files filtered with this file 28 | * filter. 29 | * 30 | * @return a string representing the default extension (ie. "tmx"), or 31 | * null when a default extension doesn't exist (ie. 32 | * when the filter determines the type using the extension) 33 | */ 34 | public abstract String getDefaultExtension(); 35 | } 36 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/util/ImageCellRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.util; 14 | 15 | import java.awt.Component; 16 | import java.awt.Image; 17 | import javax.swing.ImageIcon; 18 | import javax.swing.JList; 19 | import javax.swing.DefaultListCellRenderer; 20 | 21 | public class ImageCellRenderer extends DefaultListCellRenderer 22 | { 23 | public ImageCellRenderer() { 24 | setOpaque(true); 25 | } 26 | 27 | public Component getListCellRendererComponent(JList list, Object value, 28 | int index, boolean isSelected, boolean cellHasFocus) { 29 | super.getListCellRendererComponent( 30 | list, value, index, isSelected, cellHasFocus); 31 | 32 | Image img = (Image)value; 33 | if (img != null) { 34 | setIcon(new ImageIcon(img)); 35 | } else { 36 | setIcon(null); 37 | } 38 | setText(null); 39 | 40 | return this; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/util/MapEventAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.util; 14 | 15 | import java.awt.*; 16 | import java.util.LinkedList; 17 | import java.util.ListIterator; 18 | 19 | public class MapEventAdapter 20 | { 21 | public static final int ME_MAPACTIVE = 1; 22 | public static final int ME_MAPINACTIVE = 2; 23 | 24 | private LinkedList listeners; 25 | 26 | public MapEventAdapter() { 27 | listeners = new LinkedList(); 28 | } 29 | 30 | /** 31 | * Adds a Component to the list of listeners of map events. Checks that 32 | * the component is not already in the list. 33 | * 34 | * @param obj the listener to add 35 | */ 36 | public void addListener(Component obj) { 37 | /* Small sanity check - don't add it if it's already there. 38 | * Really only useful to the removeListener() func, as 39 | * LinkedList.remove() only removes the first instance of a given 40 | * object. 41 | */ 42 | if (listeners.indexOf(obj) == -1) { 43 | listeners.add(obj); 44 | } 45 | } 46 | 47 | /** 48 | * Removes a component from the list of listeners. 49 | * 50 | * @param obj the Component to remove 51 | */ 52 | public void removeListener(Component obj) { 53 | listeners.remove(obj); 54 | } 55 | 56 | /** 57 | * Fires an event to notify all listeners. 58 | * 59 | * @param type the event type 60 | */ 61 | public void fireEvent(int type) { 62 | //TODO: the idea is to extend this to allow for a multitude of 63 | // different event types at some point... 64 | if (type == ME_MAPACTIVE) { 65 | enableEvent(); 66 | } else if (type == ME_MAPINACTIVE) { 67 | disableEvent(); 68 | } 69 | } 70 | 71 | private void enableEvent() { 72 | Component c; 73 | ListIterator li = listeners.listIterator(); 74 | while (li.hasNext()) { 75 | c = (Component) li.next(); 76 | c.setEnabled(true); 77 | } 78 | } 79 | 80 | private void disableEvent(){ 81 | Component c; 82 | ListIterator li = listeners.listIterator(); 83 | while (li.hasNext()) { 84 | c = (Component) li.next(); 85 | c.setEnabled(false); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/util/MultisetListRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.util; 14 | 15 | import java.awt.*; 16 | import java.util.HashMap; 17 | import javax.swing.*; 18 | 19 | import tiled.core.Tile; 20 | import tiled.core.TileSet; 21 | import tiled.mapeditor.Resources; 22 | 23 | /** 24 | * This list renderer is used for rendering a list of tiles associated with a 25 | * certain map. The list renderer produces {@link ImageIcon} instances on 26 | * demand and caches them in a {@link HashMap}. 27 | * 28 | * todo: check whether assuming all tiles have an image is safe 29 | * 30 | * @version $Id$ 31 | */ 32 | public class MultisetListRenderer extends DefaultListCellRenderer 33 | { 34 | /** The icon to show for tilesets. */ 35 | private final Icon setIcon = Resources.getIcon("source.png"); 36 | 37 | /** The hash map used to match indexes to icons. */ 38 | private final HashMap tileImages = new HashMap(); 39 | 40 | /** The zoom level used for the tile image icons. */ 41 | private final double zoom; 42 | 43 | /** 44 | * Creates the list renderer for rendering a list of tiles. 45 | * 46 | * @param zoom the zoom level at which the tiles will be shown 47 | */ 48 | public MultisetListRenderer(double zoom) { 49 | this.zoom = zoom; 50 | } 51 | 52 | /** 53 | * @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean) 54 | */ 55 | public Component getListCellRendererComponent(JList list, Object value, 56 | int index, boolean isSelected, 57 | boolean cellHasFocus) { 58 | // Let the default list cell renderer do most of the work 59 | super.getListCellRendererComponent( 60 | list, value, index, isSelected, cellHasFocus); 61 | 62 | // Attempt to set an appropriate icon 63 | if (value instanceof Tile && index >= 0) { 64 | Tile tile = (Tile) value; 65 | if (!isSelected || zoom == 1) { 66 | // Use cached ImageIcon instance 67 | if (tileImages.containsKey(index)) { 68 | setIcon(tileImages.get(index)); 69 | } else { 70 | Icon icon = new ImageIcon(tile.getScaledImage(zoom)); 71 | setIcon(icon); 72 | tileImages.put(index, icon); 73 | } 74 | } else { 75 | // Selected entry always uses unscaled image 76 | setIcon(new ImageIcon(tile.getImage())); 77 | } 78 | } else if (value instanceof TileSet) { 79 | setIcon(setIcon); 80 | } 81 | 82 | return this; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/util/TileDialogListRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.util; 14 | 15 | import java.awt.Component; 16 | import java.awt.Image; 17 | import javax.swing.ImageIcon; 18 | import javax.swing.JList; 19 | import javax.swing.DefaultListCellRenderer; 20 | 21 | import tiled.core.*; 22 | import tiled.mapeditor.Resources; 23 | 24 | 25 | public class TileDialogListRenderer extends DefaultListCellRenderer 26 | { 27 | private static final String TILE = Resources.getString("general.tile.tile"); 28 | private static final String NOTILE = Resources.getString("general.tile.notile"); 29 | 30 | private double zoom = 1; 31 | 32 | public TileDialogListRenderer() { 33 | setOpaque(true); 34 | } 35 | 36 | public TileDialogListRenderer(double zoom) { 37 | this(); 38 | this.zoom = zoom; 39 | } 40 | 41 | public Component getListCellRendererComponent(JList list, Object value, 42 | int index, boolean isSelected, boolean cellHasFocus) { 43 | super.getListCellRendererComponent( 44 | list, value, index, isSelected, cellHasFocus); 45 | 46 | Tile tile = (Tile)value; 47 | 48 | if (tile != null) { 49 | Image scaledImage = tile.getScaledImage(zoom); 50 | if (scaledImage != null) { 51 | setIcon(new ImageIcon(scaledImage)); 52 | } 53 | setText(TILE + " " + tile.getId()); 54 | } else { 55 | setIcon(null); 56 | setText(NOTILE); 57 | } 58 | 59 | return this; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/util/TileRegionSelectionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.util; 14 | 15 | import java.util.EventObject; 16 | 17 | import tiled.core.TileLayer; 18 | 19 | /** 20 | * An event that describes the selection of a tile region. 21 | * 22 | * @version $Id$ 23 | */ 24 | public class TileRegionSelectionEvent extends EventObject 25 | { 26 | private final TileLayer tileLayer; 27 | 28 | public TileRegionSelectionEvent(Object source, TileLayer tileLayer) { 29 | super(source); 30 | this.tileLayer = tileLayer; 31 | } 32 | 33 | public TileLayer getTileRegion() { 34 | return tileLayer; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/util/TileSelectionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.util; 14 | 15 | import java.util.EventObject; 16 | 17 | import tiled.core.Tile; 18 | 19 | /** 20 | * An event that describes the selection of a tile. 21 | * 22 | * @version $Id$ 23 | */ 24 | public class TileSelectionEvent extends EventObject 25 | { 26 | private Tile tile; 27 | 28 | public TileSelectionEvent(Object source, Tile tile) { 29 | super(source); 30 | this.tile = tile; 31 | } 32 | 33 | public Tile getTile() { 34 | return tile; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/util/TileSelectionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.util; 14 | 15 | import java.util.EventListener; 16 | 17 | /** 18 | * @version $Id$ 19 | */ 20 | public interface TileSelectionListener extends EventListener 21 | { 22 | public void tileSelected(TileSelectionEvent e); 23 | 24 | public void tileRegionSelected(TileRegionSelectionEvent e); 25 | } 26 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/util/TransparentImageFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.util; 14 | 15 | import java.awt.image.RGBImageFilter; 16 | 17 | /** 18 | * This filter is used for filtering out a given "transparent" color from an 19 | * image. Sometimes known as magic pink. 20 | */ 21 | public class TransparentImageFilter extends RGBImageFilter 22 | { 23 | int trans; 24 | 25 | /** 26 | * @param col the color to make transparent 27 | */ 28 | public TransparentImageFilter(int col) { 29 | trans = col; 30 | 31 | // The filter doesn't depend on pixel location 32 | canFilterIndexColorModel = true; 33 | } 34 | 35 | /** 36 | * Filters the given pixel. It returns a transparent pixel for pixels that 37 | * match the transparency color, or the existing pixel for anything else. 38 | */ 39 | public int filterRGB(int x, int y, int rgb) { 40 | if (rgb == trans) { 41 | return 0; 42 | } else { 43 | return rgb; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/util/cutter/BasicTileCutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.util.cutter; 14 | 15 | import java.awt.Dimension; 16 | import java.awt.Image; 17 | import java.awt.image.BufferedImage; 18 | 19 | /** 20 | * Cuts tiles from a tileset image according to a regular rectangular pattern. 21 | * Supports a variable spacing between tiles and a margin around them. 22 | */ 23 | public class BasicTileCutter implements TileCutter 24 | { 25 | private int nextX, nextY; 26 | private BufferedImage image; 27 | private final int tileWidth; 28 | private final int tileHeight; 29 | private final int tileSpacing; 30 | private final int tileMargin; 31 | 32 | public BasicTileCutter(int tileWidth, int tileHeight, int tileSpacing, 33 | int tileMargin) 34 | { 35 | this.tileWidth = tileWidth; 36 | this.tileHeight = tileHeight; 37 | this.tileSpacing = tileSpacing; 38 | this.tileMargin = tileMargin; 39 | 40 | reset(); 41 | } 42 | 43 | public String getName() { 44 | return "Basic"; 45 | } 46 | 47 | public void setImage(BufferedImage image) { 48 | this.image = image; 49 | } 50 | 51 | public Image getNextTile() { 52 | if (nextY + tileHeight + tileMargin <= image.getHeight()) { 53 | BufferedImage tile = 54 | image.getSubimage(nextX, nextY, tileWidth, tileHeight); 55 | nextX += tileWidth + tileSpacing; 56 | 57 | if (nextX + tileWidth + tileMargin > image.getWidth()) { 58 | nextX = tileMargin; 59 | nextY += tileHeight + tileSpacing; 60 | } 61 | 62 | return tile; 63 | } 64 | 65 | return null; 66 | } 67 | 68 | public void reset() { 69 | nextX = tileMargin; 70 | nextY = tileMargin; 71 | } 72 | 73 | public Dimension getTileDimensions() { 74 | return new Dimension(tileWidth, tileHeight); 75 | } 76 | 77 | /** 78 | * Returns the spacing between tile images. 79 | * @return the spacing between tile images. 80 | */ 81 | public int getTileSpacing() { 82 | return tileSpacing; 83 | } 84 | 85 | /** 86 | * Returns the margin around the tile images. 87 | * @return the margin around the tile images. 88 | */ 89 | public int getTileMargin() { 90 | return tileMargin; 91 | } 92 | 93 | /** 94 | * Returns the number of tiles per row in the tileset image. 95 | * @return the number of tiles per row in the tileset image. 96 | */ 97 | public int getTilesPerRow() { 98 | return (image.getWidth() - 2 * tileMargin + tileSpacing) / 99 | (tileWidth + tileSpacing); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/util/cutter/BorderTileCutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.util.cutter; 14 | 15 | import java.awt.Dimension; 16 | import java.awt.Image; 17 | import java.awt.image.BufferedImage; 18 | 19 | /** 20 | * @version $Id$ 21 | */ 22 | public class BorderTileCutter implements TileCutter 23 | { 24 | public String getName() { 25 | return "Border"; 26 | } 27 | 28 | public void setImage(BufferedImage image) { 29 | // TODO Auto-generated method stub 30 | } 31 | 32 | public Image getNextTile() { 33 | // TODO Auto-generated method stub 34 | return null; 35 | } 36 | 37 | public void reset() { 38 | // TODO Auto-generated method stub 39 | } 40 | 41 | public Dimension getTileDimensions() { 42 | // TODO Auto-generated method stub 43 | return null; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/util/cutter/TileCutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.util.cutter; 14 | 15 | import java.awt.Dimension; 16 | import java.awt.Image; 17 | import java.awt.image.BufferedImage; 18 | 19 | /** 20 | * A generic interface to a class that implements tile cutting behavior. 21 | * 22 | * @version $Id$ 23 | */ 24 | public interface TileCutter 25 | { 26 | /** 27 | * Sets the image that this cutter should cut in tile images. 28 | * @param image the image that this cutter should cut 29 | */ 30 | public void setImage(BufferedImage image); 31 | 32 | /** 33 | * Retrieves the next tile image. 34 | * @return the next tile image, or null when no more tile 35 | * images are available 36 | */ 37 | public Image getNextTile(); 38 | 39 | /** 40 | * Resets the tile cutter so that the next call to getNextTile 41 | * will return the first tile. 42 | */ 43 | void reset(); 44 | 45 | /** 46 | * Returns the default tile dimensions of tiles cut by this cutter. 47 | * @return the default tile dimensions of tiles cut by this cutter. 48 | */ 49 | public Dimension getTileDimensions(); 50 | 51 | /** 52 | * Returns the name of this tile cutter. 53 | * @return the name of this tile cutter 54 | */ 55 | public String getName(); 56 | } 57 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/widget/BrushPreview.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.widget; 14 | 15 | import tiled.mapeditor.brush.AbstractBrush; 16 | 17 | import javax.swing.*; 18 | import java.awt.*; 19 | 20 | /** 21 | * @version $Id$ 22 | */ 23 | public class BrushPreview extends JPanel 24 | { 25 | private AbstractBrush brush; 26 | 27 | public BrushPreview() { 28 | setPreferredSize(new Dimension(22, 22)); 29 | } 30 | 31 | public void setBrush(AbstractBrush brush) { 32 | this.brush = brush; 33 | } 34 | 35 | public void paint(Graphics graphics) { 36 | if (brush != null) { 37 | brush.drawPreview((Graphics2D) graphics, getSize(), null); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/widget/ColorButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.widget; 14 | 15 | import java.awt.Color; 16 | import java.awt.Dimension; 17 | import java.awt.event.ActionListener; 18 | import java.awt.event.ActionEvent; 19 | import javax.swing.JButton; 20 | 21 | 22 | /** 23 | * A button with an associated color. The color is displayed as the background 24 | * of the button and clicking the button spawns a color chooser dialog to allow 25 | * changing the associated color. 26 | */ 27 | public class ColorButton extends JButton implements ActionListener 28 | { 29 | public ColorButton(Color initialColor) { 30 | setBackground(initialColor); 31 | addActionListener(this); 32 | } 33 | 34 | public ColorButton() { 35 | this(Color.white); 36 | } 37 | 38 | public Dimension getPreferredSize() { 39 | return new Dimension(40, 15); 40 | } 41 | 42 | /** 43 | * Sets the new color of this button. 44 | */ 45 | public void setColor(Color color) { 46 | setBackground(color); 47 | } 48 | 49 | /** 50 | * Gets the color of this button. 51 | */ 52 | public Color getColor() { 53 | return getBackground(); 54 | } 55 | 56 | public void actionPerformed(ActionEvent event) { 57 | // Spawn a color chooser dialog 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/widget/FloatDocument.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package tiled.mapeditor.widget; 7 | 8 | import javax.swing.text.AttributeSet; 9 | import javax.swing.text.BadLocationException; 10 | import javax.swing.text.PlainDocument; 11 | 12 | /** 13 | * 14 | * @author count 15 | */ 16 | public class FloatDocument extends PlainDocument { 17 | public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { 18 | if (str == null) 19 | return; 20 | 21 | try{ 22 | Float.parseFloat(str); 23 | }catch(NumberFormatException nfx){ 24 | return; 25 | } 26 | super.insertString(offs, str, a); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/widget/ImageViewPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.widget; 14 | 15 | import java.awt.*; 16 | 17 | import javax.swing.JPanel; 18 | 19 | public class ImageViewPanel extends JPanel 20 | { 21 | private final Image image; 22 | 23 | public ImageViewPanel(Image image) { 24 | this.image = image; 25 | } 26 | 27 | public Dimension getPreferredSize() { 28 | return new Dimension(150, 150); 29 | } 30 | 31 | public Dimension getPreferredScrollableViewportSize() { 32 | return getPreferredSize(); 33 | } 34 | 35 | public boolean getScrollableTracksViewportHeight() { 36 | return false; 37 | } 38 | 39 | public boolean getScrollableTracksViewportWidth() { 40 | return false; 41 | } 42 | 43 | public void paint(Graphics g) { 44 | g.drawImage(image, 0, 0, null); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/widget/IntegerSpinner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.widget; 14 | 15 | import java.awt.Dimension; 16 | import javax.swing.JSpinner; 17 | import javax.swing.SpinnerNumberModel; 18 | 19 | /** 20 | * The integer spinner is a variation on the JSpinner that is only to be used 21 | * for plain integer inputs. It offers some convenience constructors and 22 | * methods. 23 | * 24 | * @version $Id$ 25 | */ 26 | public class IntegerSpinner extends JSpinner 27 | { 28 | public IntegerSpinner() { 29 | super(new SpinnerNumberModel()); 30 | setPreferredSize(new Dimension(60, getPreferredSize().height)); 31 | } 32 | 33 | public IntegerSpinner(int val, int min, int max) { 34 | super(new SpinnerNumberModel(val, min, max, 1)); 35 | setPreferredSize(new Dimension(60, getPreferredSize().height)); 36 | } 37 | 38 | public IntegerSpinner(int val, int min) { 39 | this(val, min, Integer.MAX_VALUE); 40 | } 41 | 42 | public int intValue() { 43 | return ((Number)getValue()).intValue(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/widget/TButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.widget; 14 | 15 | import java.awt.Insets; 16 | import javax.swing.Action; 17 | import javax.swing.JButton; 18 | 19 | /** 20 | * Tiled button extends on JButton in that it allows for not accepting 21 | * any text from an attached action. It also doesn't display any margins. 22 | * 23 | * @version $Id$ 24 | */ 25 | public class TButton extends JButton 26 | { 27 | private boolean showText; 28 | 29 | public TButton() { 30 | setMargin(new Insets(0, 0, 0, 0)); 31 | } 32 | 33 | public TButton(boolean showText) { 34 | this(); 35 | this.showText = showText; 36 | } 37 | 38 | public TButton(Action action) { 39 | this(action, false); 40 | } 41 | 42 | public TButton(Action action, boolean showText) { 43 | this(showText); 44 | setAction(action); 45 | } 46 | 47 | public void setShowText(boolean showText) { 48 | this.showText = showText; 49 | } 50 | 51 | public void setText(String text) { 52 | if (showText) { 53 | super.setText(text); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/widget/TMenuItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.widget; 14 | 15 | import javax.swing.Action; 16 | import javax.swing.Icon; 17 | import javax.swing.JMenuItem; 18 | 19 | /** 20 | * Tiled menu item extends on JMenuItem in that it allows for not accepting 21 | * any icon from an attached action. 22 | * 23 | * @version $Id$ 24 | */ 25 | public class TMenuItem extends JMenuItem 26 | { 27 | private boolean showIcon; 28 | 29 | public TMenuItem(boolean showIcon) { 30 | this.showIcon = showIcon; 31 | } 32 | 33 | public TMenuItem(Action action) { 34 | this(action, false); 35 | } 36 | 37 | public TMenuItem(Action action, boolean showIcon) { 38 | this(showIcon); 39 | setAction(action); 40 | } 41 | 42 | public void setShowIcon(boolean showIcon) { 43 | this.showIcon = showIcon; 44 | } 45 | 46 | public void setIcon(Icon icon) { 47 | if (showIcon) { 48 | super.setIcon(icon); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/tiled/mapeditor/widget/VerticalStaticJPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.mapeditor.widget; 14 | 15 | import java.awt.Dimension; 16 | import java.awt.LayoutManager; 17 | import javax.swing.JPanel; 18 | 19 | 20 | /** 21 | * A variation on JPanel that will specify the preferred height as both the 22 | * minimum and maximum. 23 | */ 24 | public class VerticalStaticJPanel extends JPanel 25 | { 26 | public VerticalStaticJPanel() { 27 | } 28 | 29 | public VerticalStaticJPanel(LayoutManager manager) { 30 | super(manager); 31 | } 32 | 33 | public Dimension getMaximumSize() { 34 | return new Dimension(super.getMaximumSize().width, 35 | getPreferredSize().height); 36 | } 37 | 38 | public Dimension getMinimumSize() { 39 | return new Dimension(super.getMinimumSize().width, 40 | getPreferredSize().height); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tiled/util/TiledProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.util; 14 | 15 | /** 16 | * @version $Id$ 17 | */ 18 | public class TiledProperty 19 | { 20 | private String value; 21 | private String min; 22 | private String max; 23 | private String type; 24 | 25 | public TiledProperty() { 26 | } 27 | 28 | public TiledProperty(String value, String min, String max, String type) { 29 | set(value, min, max, type); 30 | } 31 | 32 | public void set(String value, String min, String max, String type) { 33 | this.value = value; 34 | this.min = min; 35 | this.max = max; 36 | this.type = type; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/tiled/util/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiled Map Editor, (c) 2004-2006 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Adam Turk 10 | * Bjorn Lindeijer 11 | */ 12 | 13 | package tiled.util; 14 | 15 | import java.io.File; 16 | import java.io.IOException; 17 | 18 | /** 19 | * Various utility functions. 20 | */ 21 | public class Util 22 | { 23 | /** 24 | * This function converts an int integer array to a 25 | * byte array. Each integer element is broken into 4 bytes and 26 | * stored in the byte array in litte endian byte order. 27 | * 28 | * @param integers an integer array 29 | * @return a byte array containing the values of the int array. The byte 30 | * array is 4x the length of the integer array. 31 | */ 32 | public static byte[] convertIntegersToBytes (int[] integers) { 33 | if (integers != null) { 34 | byte[] outputBytes = new byte[integers.length * 4]; 35 | 36 | for(int i = 0, k = 0; i < integers.length; i++) { 37 | int integerTemp = integers[i]; 38 | for(int j = 0; j < 4; j++, k++) { 39 | outputBytes[k] = (byte)((integerTemp >> (8 * j)) & 0xFF); 40 | } 41 | } 42 | return outputBytes; 43 | } else { 44 | return null; 45 | } 46 | } 47 | 48 | /** 49 | * This utility function will check the specified string to see if it 50 | * starts with one of the OS root designations. (Ex.: '/' on Unix, 'C:' on 51 | * Windows) 52 | * 53 | * @param filename a filename to check for absolute or relative path 54 | * @return true if the specified filename starts with a 55 | * filesystem root, false otherwise. 56 | */ 57 | public static boolean checkRoot(String filename) { 58 | File[] roots = File.listRoots(); 59 | 60 | for (File root : roots) { 61 | try { 62 | String canonicalRoot = root.getCanonicalPath().toLowerCase(); 63 | if (filename.toLowerCase().startsWith(canonicalRoot)) { 64 | return true; 65 | } 66 | } catch (IOException e) { 67 | // Do we care? 68 | } 69 | } 70 | 71 | return false; 72 | } 73 | } 74 | --------------------------------------------------------------------------------