⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tiledialog.java

📁 tiled地图编辑器是2d的,很不错的国外软件,使用起来很方便的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  Tiled Map Editor, (c) 2004-2006 * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  Adam Turk <aturk@biggeruniverse.com> *  Bjorn Lindeijer <b.lindeijer@xs4all.nl> *  Rainer Deyke <rainerd@eldwood.com> */package tiled.mapeditor.dialogs;import java.awt.*;import java.awt.event.*;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.util.Enumeration;import java.util.Iterator;import java.util.Properties;import java.util.Vector;import java.text.MessageFormat;import javax.imageio.ImageIO;import javax.swing.*;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import tiled.core.*;import tiled.mapeditor.Resources;import tiled.mapeditor.animation.AnimationDialog;import tiled.mapeditor.util.*;import tiled.mapeditor.widget.*;/** * @version $Id: TileDialog.java 689 2006-07-15 17:44:21Z bjorn $ */public class TileDialog extends JDialog    implements ActionListener, ListSelectionListener{    private Tile currentTile;    private TileSet tileset;    private Map map;    private JList tileList;    private JList imageList;    private JTable tileProperties;    private JButton okButton;    private JButton newTileButton;    private JButton deleteTileButton;    private JButton changeImageButton;    private JButton duplicateTileButton;    private JButton createTileButton;    //private JButton animationButton;    private String location;    private JTextField tilesetNameEntry;    private JTabbedPane tabs;    private int currentImageIndex = -1;    private static final String DIALOG_TITLE = Resources.getString("dialog.tile.title");    private static final String OK_BUTTON = Resources.getString("general.button.ok");    private static final String DELETE_BUTTON = Resources.getString("dialog.tile.button.deletetile");    private static final String CI_BUTTON = Resources.getString("dialog.tile.button.changeimage");    private static final String NEW_BUTTON = Resources.getString("dialog.tile.button.newtile");    private static final String CREATE_BUTTON = Resources.getString("dialog.tile.button.createtile");    private static final String DUPLICATE_BUTTON = Resources.getString("dialog.tile.button.duptile");    private static final String ANIMATION_BUTTON = Resources.getString("dialog.tile.button.animation");    private static final String PREVIEW_TAB = Resources.getString("general.button.preview");    private static final String TILES_TAB = Resources.getString("general.tile.tiles");    private static final String IMAGES_TAB = "Images";    private static final String NAME_LABEL = Resources.getString("dialog.newtileset.name.label");    private static final String ERROR_LOADING_IMAGE = Resources.getString("dialog.tile.image.load.error");    public TileDialog(Dialog parent, TileSet s, Map m) {        super(parent, DIALOG_TITLE + " '" + s.getName() + "'", true);        location = "";        tileset = s;    //unofficial        map = m;        //also unofficial        init();        setTileset(s);        setCurrentTile(null);        pack();        setLocationRelativeTo(getOwner());    }    private JPanel createTilePanel() {        // Create the buttons        deleteTileButton = new JButton(DELETE_BUTTON);        changeImageButton = new JButton(CI_BUTTON);        duplicateTileButton = new JButton(DUPLICATE_BUTTON);        newTileButton = new JButton(NEW_BUTTON);        //animationButton = new JButton(ANIMATION_BUTTON);        deleteTileButton.addActionListener(this);        changeImageButton.addActionListener(this);        duplicateTileButton.addActionListener(this);        newTileButton.addActionListener(this);        //animationButton.addActionListener(this);        tileList = new JList();        tileList.setCellRenderer(new TileDialogListRenderer());        // Tile properties table        tileProperties = new JTable(new PropertiesTableModel());        tileProperties.getSelectionModel().addListSelectionListener(this);        JScrollPane propScrollPane = new JScrollPane(tileProperties);        propScrollPane.setPreferredSize(new Dimension(150, 150));        // Tile list        tileList.addListSelectionListener(this);        JScrollPane sp = new JScrollPane();        sp.getViewport().setView(tileList);        sp.setPreferredSize(new Dimension(150, 150));        // The split pane        JSplitPane splitPane = new JSplitPane(                JSplitPane.HORIZONTAL_SPLIT, true);        splitPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));        splitPane.setResizeWeight(0.25);        splitPane.setLeftComponent(sp);        splitPane.setRightComponent(propScrollPane);        // The buttons        JPanel buttons = new VerticalStaticJPanel();        buttons.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));        buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));        buttons.add(newTileButton);        buttons.add(Box.createRigidArea(new Dimension(5, 0)));        buttons.add(deleteTileButton);        buttons.add(Box.createRigidArea(new Dimension(5, 0)));        buttons.add(changeImageButton);        buttons.add(Box.createRigidArea(new Dimension(5, 0)));        buttons.add(duplicateTileButton);        //buttons.add(Box.createRigidArea(new Dimension(5, 0)));        //buttons.add(animationButton);        buttons.add(Box.createRigidArea(new Dimension(5, 0)));        buttons.add(Box.createGlue());        // Putting it all together        JPanel mainPanel = new JPanel();        mainPanel.setLayout(new GridBagLayout());        mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));        GridBagConstraints c = new GridBagConstraints();        c.fill = GridBagConstraints.BOTH;        c.weightx = 1; c.weighty = 1;        mainPanel.add(splitPane, c);        c.weightx = 0; c.weighty = 0; c.gridy = 1;        mainPanel.add(buttons, c);        return mainPanel;    }    private JPanel createImagePanel()    {        imageList = new JList();        imageList.setCellRenderer(new ImageCellRenderer());        imageList.setLayoutOrientation(JList.HORIZONTAL_WRAP);        imageList.addListSelectionListener(this);        JScrollPane sp = new JScrollPane(imageList);        sp.setPreferredSize(new Dimension(150, 150));        // Buttons        createTileButton = new JButton(CREATE_BUTTON);        createTileButton.addActionListener(this);        JPanel buttons = new VerticalStaticJPanel();        buttons.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));        buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));        buttons.add(createTileButton);        JPanel mainPanel = new JPanel();        mainPanel.setLayout(new GridBagLayout());        mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));        GridBagConstraints c = new GridBagConstraints();        c.fill = GridBagConstraints.BOTH;        c.weightx = 1; c.weighty = 1;        mainPanel.add(sp, c);        c.weightx = 0; c.weighty = 0; c.gridy = 1;        mainPanel.add(buttons, c);        return mainPanel;    }    private void init() {        // Tileset name field at the top        JLabel nameLabel = new JLabel(NAME_LABEL);        tilesetNameEntry = new JTextField(32);        JPanel namePanel = new VerticalStaticJPanel();        namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.X_AXIS));        namePanel.add(nameLabel);        namePanel.add(Box.createRigidArea(new Dimension(5, 5)));        namePanel.add(tilesetNameEntry);        tabs = new JTabbedPane(JTabbedPane.TOP);        tabs.addTab(TILES_TAB, createTilePanel());        tabs.addTab(IMAGES_TAB, createImagePanel());        okButton = new JButton(OK_BUTTON);        JPanel buttons = new VerticalStaticJPanel();        buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));        buttons.add(Box.createGlue());        buttons.add(okButton);        JPanel mainPanel = new JPanel();        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));        mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));        mainPanel.add(namePanel);        mainPanel.add(Box.createRigidArea(new Dimension(0, 5)));        mainPanel.add(tabs);        mainPanel.add(Box.createRigidArea(new Dimension(0, 5)));        mainPanel.add(buttons);        getContentPane().add(mainPanel);        getRootPane().setDefaultButton(okButton);        // Create actionlisteners        okButton.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent actionEvent) {                tileset.setName(tilesetNameEntry.getText());                dispose();            }        });    }    private void changeImage() {        if (currentTile == null) {            return;        }        TileImageDialog d = new TileImageDialog(this, tileset,            currentTile.getImageId());        d.setVisible(true);        if (d.getImageId() >= 0) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -