@Override public int getRowCount() { if (data.getCurProject().getAnimation(data.getCurrentAnimationIndex()) == null) { return 0; } return data.getCurProject().getAnimation(data.getCurrentAnimationIndex()).getFrames().size(); }
/** * Creates new form PreviewMapDialog * * @param parent * @param modal */ public PreviewMapDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); if (AppData.getInstance().getCurrentMap().getPreviewRender() == null) { PreviewRenderFactory.createPreviewRender(AppData.getInstance().getCurrentMap()); } initComponents(); initialize(); }
private void showTileCheckBoxActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_showTileCheckBoxActionPerformed // TODO add your handling code here: AppData.getInstance() .getCurrentMap() .getPreviewRender() .setShowTile(showTileCheckBox.isSelected()); AppData.getInstance().getCurrentMap().getPreviewRender().repaint(); } // GEN-LAST:event_showTileCheckBoxActionPerformed
public Object getValueAt(int rowIndex, int columnIndex) { Frame frame = data.getCurProject().getAnimation(data.getCurrentAnimationIndex()).getFrame(rowIndex); if (frame != null) { switch (columnIndex) { case 0: return rowIndex; case 1: return frame.getName(); case 2: return frame.getDelay(); } } return null; }
@Override public void setValueAt(Object v, int r, int c) { Frame frame = data.getCurProject().getAnimation(data.getCurrentAnimationIndex()).getFrame(r); if (frame != null) { switch (c) { case 1: frame.setName(v.toString()); break; case 2: frame.setDelay(Integer.parseInt(v.toString())); break; } } this.fireTableCellUpdated(r, c); }
/** * @param battlerPath * @throws IOException */ public void setBattlerPath(String battlerPath) throws IOException { int temp = battlerPath.lastIndexOf(File.separator); this.battlerPath = battlerPath.substring(temp + 1); if (!this.battlerPath.equals("")) { headImg = ImageIO.read( new File( AppData.getInstance().getCurProject().getPath() + File.separatorChar + "image" + File.separatorChar + "battler" + File.separatorChar + this.battlerPath)); } }
private void pathButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_pathButtonActionPerformed // TODO add your handling code here: JFileChooser ch = new JFileChooser( AppData.getInstance().getCurProject().getPath() + File.separatorChar + "image" + File.separatorChar + "tileset"); ch.setMultiSelectionEnabled(true); JFileChooserImagePreview preview = new JFileChooserImagePreview(ch); ch.addPropertyChangeListener(preview); ch.setAccessory(preview); int ret = ch.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { File[] files = ch.getSelectedFiles(); StringBuilder sbFileName = new StringBuilder(); for (int i = 0; i < files.length; i++) { sbFileName.append(files[i].getName()); if (i != files.length - 1) { sbFileName.append("|"); } } StringBuilder sbFilePath = new StringBuilder(); for (int i = 0; i < files.length; i++) { sbFilePath.append(files[i].getAbsolutePath()); if (i != files.length - 1) { sbFilePath.append("|"); } } tilesetPathTextField.setText(sbFilePath.toString()); tilesetNameTextField.setText(sbFileName.toString()); } // JFileChooser ch = new JFileChooser(AppData.getInstance().getCurProject().getPath() + // File.separatorChar + "image" + File.separatorChar + "tileset"); // JFileChooserImagePreview preview = new JFileChooserImagePreview(ch); // ch.addPropertyChangeListener(preview); // ch.setAccessory(preview); // int ret = ch.showOpenDialog(this); // if (ret == JFileChooser.APPROVE_OPTION) { // tilesetPathTextField.setText(ch.getSelectedFile().getAbsolutePath()); // int i = ch.getSelectedFile().getAbsolutePath().lastIndexOf(File.separator); // tilesetNameTextField.setText(ch.getSelectedFile().getAbsolutePath().substring(i + // 1)); // } } // GEN-LAST:event_pathButtonActionPerformed
private void setScreenButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_setScreenButtonActionPerformed // TODO add your handling code here: try { Integer.parseInt(ScreenWTextField.getText()); Integer.parseInt(ScreenHTextField.getText()); } catch (Exception e) { JOptionPane.showMessageDialog(this, "无效的屏幕大小!"); return; } AppData.getInstance() .getCurrentMap() .getPreviewRender() .setBound( Integer.parseInt(ScreenWTextField.getText()), Integer.parseInt(ScreenHTextField.getText())); } // GEN-LAST:event_setScreenButtonActionPerformed
/** * @param imgPath * @throws IOException */ public void setImgPath(String imgPath) throws IOException { int temp = imgPath.lastIndexOf(File.separator); this.imgPath = imgPath.substring(temp + 1); if (!this.imgPath.equals("")) { moveImg = ImageIO.read( new File( AppData.getInstance().getCurProject().getPath() + File.separatorChar + "image" + File.separatorChar + "character" + File.separatorChar + this.imgPath)); } // System.out.println("精灵图片: " + Project.getInstance().getPath() + File.separatorChar + // "image" + File.separatorChar + "character" + File.separatorChar + this.imgPath); }
private void savePreviewButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_savePreviewButtonActionPerformed // TODO add your handling code here: File f = new File( AppData.getInstance().getCurProject().getPath() + File.separator + "softdata" + File.separator + "snapshot"); if (!f.exists()) { f.mkdirs(); } SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); String datetime = tempDate.format(new java.util.Date()); File file = new File( f.getPath() + File.separator + AppData.getInstance().getCurrentMap().getName() + "_" + AppData.getInstance().getCurrentMap().getTileWidth() * AppData.getInstance().getCurrentMap().getWidth() + "x" + AppData.getInstance().getCurrentMap().getTileHeight() * AppData.getInstance().getCurrentMap().getHeight() + "_" + datetime + ".png"); try { ImageIO.write( AppData.getInstance().getCurrentMap().getPreviewRender().getBufferedImage(), "png", file); JOptionPane.showMessageDialog(this, "生成快照成功!位置:" + f.getPath()); } catch (IOException ex) { // ex.printStackTrace(); JOptionPane.showMessageDialog(this, "生成快照失败!"); } } // GEN-LAST:event_savePreviewButtonActionPerformed
/** @author Administrator */ public class FrameTableModel extends AbstractTableModel { private static final String COLUMN_NAME[] = {"ID", "帧名", "播放时间(ms)"}; private static final Class COLUMN_CLASS[] = {Integer.class, String.class, Integer.class}; /** */ public FrameTableModel() {} @Override public String getColumnName(int c) { return COLUMN_NAME[c]; } @Override public Class<?> getColumnClass(int c) { return COLUMN_CLASS[c]; } @Override public int getColumnCount() { return COLUMN_NAME.length; } private AppData data = AppData.getInstance(); public Object getValueAt(int rowIndex, int columnIndex) { Frame frame = data.getCurProject().getAnimation(data.getCurrentAnimationIndex()).getFrame(rowIndex); if (frame != null) { switch (columnIndex) { case 0: return rowIndex; case 1: return frame.getName(); case 2: return frame.getDelay(); } } return null; } @Override public boolean isCellEditable(int row, int col) { if (col == 0) { return false; } return true; } @Override public void setValueAt(Object v, int r, int c) { Frame frame = data.getCurProject().getAnimation(data.getCurrentAnimationIndex()).getFrame(r); if (frame != null) { switch (c) { case 1: frame.setName(v.toString()); break; case 2: frame.setDelay(Integer.parseInt(v.toString())); break; } } this.fireTableCellUpdated(r, c); } @Override public int getRowCount() { if (data.getCurProject().getAnimation(data.getCurrentAnimationIndex()) == null) { return 0; } return data.getCurProject().getAnimation(data.getCurrentAnimationIndex()).getFrames().size(); } }
/** * This method is called from within the constructor to initialize the form. WARNING: Do NOT * modify this code. The content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); ScreenWTextField = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); ScreenHTextField = new javax.swing.JTextField(); setScreenButton = new javax.swing.JButton(); previewScrollPane = new javax.swing.JScrollPane(); jPanel2 = new javax.swing.JPanel(); showCollideCheckBox = new javax.swing.JCheckBox(); showSpriteCheckBox = new javax.swing.JCheckBox(); showScreenCheckBox = new javax.swing.JCheckBox(); showTileCheckBox = new javax.swing.JCheckBox(); savePreviewButton = new javax.swing.JButton(); closePreviewButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance() .getContext() .getResourceMap(PreviewMapDialog.class); setTitle(resourceMap.getString("title")); // NOI18N jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("屏幕大小")); jPanel1.setName("jPanel1"); // NOI18N ScreenWTextField.setText("320"); ScreenWTextField.setName("ScreenWTextField"); // NOI18N jLabel1.setText("宽"); jLabel1.setName("jLabel1"); // NOI18N jLabel2.setText("高"); jLabel2.setName("jLabel2"); // NOI18N ScreenHTextField.setText("480"); ScreenHTextField.setName("ScreenHTextField"); // NOI18N setScreenButton.setText("确定设置"); setScreenButton.setName("setScreenButton"); // NOI18N setScreenButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { setScreenButtonActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel1Layout .createSequentialGroup() .addGap(8, 8, 8) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent( ScreenWTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent( ScreenHTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(setScreenButton) .addContainerGap())); jPanel1Layout.setVerticalGroup( jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel1Layout .createSequentialGroup() .addGroup( jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( ScreenHTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2) .addComponent( ScreenWTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1) .addComponent(setScreenButton)) .addContainerGap(6, Short.MAX_VALUE))); previewScrollPane.setName("previewScrollPane"); // NOI18N jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("显示设置")); jPanel2.setName("jPanel2"); // NOI18N showCollideCheckBox.setText("显示碰撞"); showCollideCheckBox.setName("showCollideCheckBox"); // NOI18N showCollideCheckBox.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { showCollideCheckBoxActionPerformed(evt); } }); showCollideCheckBox.setSelected( AppData.getInstance().getCurrentMap().getPreviewRender().isShowCollide()); showSpriteCheckBox.setSelected(true); showSpriteCheckBox.setText("显示精灵"); showSpriteCheckBox.setName("showSpriteCheckBox"); // NOI18N showSpriteCheckBox.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { showSpriteCheckBoxActionPerformed(evt); } }); showSpriteCheckBox.setSelected( AppData.getInstance().getCurrentMap().getPreviewRender().isShowSprite()); showScreenCheckBox.setSelected(true); showScreenCheckBox.setText("显示屏幕"); showScreenCheckBox.setName("showScreenCheckBox"); // NOI18N showScreenCheckBox.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { showScreenCheckBoxActionPerformed(evt); } }); showScreenCheckBox.setSelected( AppData.getInstance().getCurrentMap().getPreviewRender().isShowScreen()); showTileCheckBox.setText("显示瓷砖"); showTileCheckBox.setName("showTileCheckBox"); // NOI18N showTileCheckBox.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { showTileCheckBoxActionPerformed(evt); } }); showTileCheckBox.setSelected( AppData.getInstance().getCurrentMap().getPreviewRender().isShowTile()); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout .createSequentialGroup() .addContainerGap() .addComponent(showTileCheckBox) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE) .addComponent(showCollideCheckBox) .addGap(50, 50, 50) .addComponent(showSpriteCheckBox) .addGap(50, 50, 50) .addComponent(showScreenCheckBox) .addContainerGap())); jPanel2Layout.setVerticalGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel2Layout .createSequentialGroup() .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(showScreenCheckBox) .addComponent(showCollideCheckBox) .addComponent(showSpriteCheckBox) .addComponent(showTileCheckBox)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); savePreviewButton.setText("保存快照"); savePreviewButton.setName("savePreviewButton"); // NOI18N savePreviewButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { savePreviewButtonActionPerformed(evt); } }); closePreviewButton.setText("关闭"); closePreviewButton.setName("closePreviewButton"); // NOI18N closePreviewButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { closePreviewButtonActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout .createSequentialGroup() .addContainerGap() .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent( previewScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 768, Short.MAX_VALUE) .addGroup( javax.swing.GroupLayout.Alignment.LEADING, layout .createSequentialGroup() .addComponent( jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent( jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup( layout .createSequentialGroup() .addComponent(savePreviewButton) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 630, Short.MAX_VALUE) .addComponent(closePreviewButton))) .addContainerGap())); layout.setVerticalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addContainerGap() .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel1, 0, 55, Short.MAX_VALUE) .addComponent( jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent( previewScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 472, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(closePreviewButton) .addComponent(savePreviewButton)) .addContainerGap())); pack(); } // </editor-fold>//GEN-END:initComponents
private void initialize() { setLocationRelativeTo(null); previewScrollPane.setViewportView(AppData.getInstance().getCurrentMap().getPreviewRender()); AppData.getInstance().getCurrentMap().getPreviewRender().repaint(); }
/** @author Administrator */ public class NewTileSetDialog extends javax.swing.JDialog { /** * Creates new form NewTileSetDialog * * @param parent * @param modal */ public NewTileSetDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); initialize(); } private void initialize() { setLocationRelativeTo(null); getRootPane().setDefaultButton(okButton); if (!Preference.getIsAutoTile()) { autoTileCheckBox.setEnabled(false); autoTileLabel.setText("<html> <body> 此功能暂时关闭 </body> </html>"); } else { autoTileCheckBox.setEnabled(true); autoTileLabel.setText( "<html> <body> 注意:暂时只支持RMXP格式的自动元件,选中表示此图集为自动图集,非自动图集请勿选中! </body> </html>"); } } /** * This method is called from within the constructor to initialize the form. WARNING: Do NOT * modify this code. The content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); tilesetNameTextField = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); tilesetPathTextField = new javax.swing.JTextField(); okButton = new javax.swing.JButton(); cancleButton = new javax.swing.JButton(); pathButton = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); autoTileLabel = new javax.swing.JLabel(); autoTileCheckBox = new javax.swing.JCheckBox(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance() .getContext() .getResourceMap(NewTileSetDialog.class); setTitle(resourceMap.getString("title")); // NOI18N setResizable(false); jLabel1.setText("图集名称"); jLabel1.setName("jLabel1"); // NOI18N tilesetNameTextField.setName("tilesetNameTextField"); // NOI18N jLabel2.setText("图集路径"); jLabel2.setName("jLabel2"); // NOI18N tilesetPathTextField.setName("tilesetPathTextField"); // NOI18N okButton.setText("确定"); okButton.setName("okButton"); // NOI18N okButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); cancleButton.setText("取消"); cancleButton.setName("cancleButton"); // NOI18N cancleButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancleButtonActionPerformed(evt); } }); pathButton.setText("..."); pathButton.setName("pathButton"); // NOI18N pathButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { pathButtonActionPerformed(evt); } }); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("设置")); jPanel1.setName("jPanel1"); // NOI18N autoTileLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); autoTileLabel.setText( "<html> <body> 注意:暂时只支持RMXP格式的自动元件,选中表示此图集为自动图集,非自动图集请勿选中! </body> </html>"); // NOI18N autoTileLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP); autoTileLabel.setName("autoTileLabel"); // NOI18N autoTileLabel.setVerticalTextPosition(javax.swing.SwingConstants.TOP); autoTileCheckBox.setText("自动元件"); autoTileCheckBox.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); autoTileCheckBox.setName("autoTileCheckBox"); // NOI18N autoTileCheckBox.setVerticalAlignment(javax.swing.SwingConstants.TOP); autoTileCheckBox.setVerticalTextPosition(javax.swing.SwingConstants.TOP); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel1Layout .createSequentialGroup() .addComponent(autoTileCheckBox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent( autoTileLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE) .addContainerGap())); jPanel1Layout.setVerticalGroup( jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel1Layout .createSequentialGroup() .addGroup( jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(autoTileCheckBox) .addComponent( autoTileLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addContainerGap() .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout .createSequentialGroup() .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel2) .addComponent(jLabel1)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addGroup( javax.swing.GroupLayout.Alignment.LEADING, layout .createSequentialGroup() .addComponent( tilesetPathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement .UNRELATED) .addComponent( pathButton, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)) .addComponent( tilesetNameTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE))) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout .createSequentialGroup() .addComponent( okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent( cancleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap())); layout.linkSize( javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancleButton, okButton}); layout.setVerticalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addContainerGap() .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent( tilesetNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent( tilesetPathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(pathButton)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent( jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cancleButton) .addComponent(okButton)) .addContainerGap())); pack(); } // </editor-fold>//GEN-END:initComponents private void okButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_okButtonActionPerformed // TODO add your handling code here: String[] names = tilesetNameTextField.getText().split("\\|"); String[] paths = tilesetPathTextField.getText().split("\\|"); for (int n = 0; n < paths.length; n++) { TileSet newTileset = new TileSet(); String name, path; if (names[n].equals("")) { name = "未命名"; } else { name = names[n]; } if (paths[n].equals("")) { JOptionPane.showMessageDialog(this, "路径不能为空!"); return; } else { path = paths[n]; } newTileset.setName(name); newTileset.setAutoTile(autoTileCheckBox.isSelected()); newTileset.setMap(data.getCurrentMap()); try { newTileset.importTileBitmap( path, new TileCutter( data.getCurrentMap().getTileWidth(), data.getCurrentMap().getTileHeight())); } catch (IOException ex) { JOptionPane.showMessageDialog( this, ex.getLocalizedMessage(), "加载图集失败!" + paths[n], JOptionPane.WARNING_MESSAGE); } Pass pic = data.getMainFrame() .tscd .initCrossFile( path.substring(path.lastIndexOf(File.separatorChar) + 1), new Rectangle( data.getCurrentMap().getTileWidth(), data.getCurrentMap().getTileHeight())); if (pic != null) { for (int i = 0; i < pic.collides.length; i++) { for (int j = 0; j < pic.collides[0].length; j++) { newTileset.getTile(i + pic.collides.length * j).setCross(!pic.collides[i][j]); } } } if (data.addTileSet(newTileset)) { System.out.println("加载图元" + newTileset.getName() + "成功!"); } else { JOptionPane.showMessageDialog(this, "添加图集失败!" + paths[n]); } } dispose(); } // GEN-LAST:event_okButtonActionPerformed private AppData data = AppData.getInstance(); private void cancleButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_cancleButtonActionPerformed // TODO add your handling code here: dispose(); } // GEN-LAST:event_cancleButtonActionPerformed private void pathButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_pathButtonActionPerformed // TODO add your handling code here: JFileChooser ch = new JFileChooser( AppData.getInstance().getCurProject().getPath() + File.separatorChar + "image" + File.separatorChar + "tileset"); ch.setMultiSelectionEnabled(true); JFileChooserImagePreview preview = new JFileChooserImagePreview(ch); ch.addPropertyChangeListener(preview); ch.setAccessory(preview); int ret = ch.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { File[] files = ch.getSelectedFiles(); StringBuilder sbFileName = new StringBuilder(); for (int i = 0; i < files.length; i++) { sbFileName.append(files[i].getName()); if (i != files.length - 1) { sbFileName.append("|"); } } StringBuilder sbFilePath = new StringBuilder(); for (int i = 0; i < files.length; i++) { sbFilePath.append(files[i].getAbsolutePath()); if (i != files.length - 1) { sbFilePath.append("|"); } } tilesetPathTextField.setText(sbFilePath.toString()); tilesetNameTextField.setText(sbFileName.toString()); } // JFileChooser ch = new JFileChooser(AppData.getInstance().getCurProject().getPath() + // File.separatorChar + "image" + File.separatorChar + "tileset"); // JFileChooserImagePreview preview = new JFileChooserImagePreview(ch); // ch.addPropertyChangeListener(preview); // ch.setAccessory(preview); // int ret = ch.showOpenDialog(this); // if (ret == JFileChooser.APPROVE_OPTION) { // tilesetPathTextField.setText(ch.getSelectedFile().getAbsolutePath()); // int i = ch.getSelectedFile().getAbsolutePath().lastIndexOf(File.separator); // tilesetNameTextField.setText(ch.getSelectedFile().getAbsolutePath().substring(i + // 1)); // } } // GEN-LAST:event_pathButtonActionPerformed /** @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater( new Runnable() { public void run() { NewTileSetDialog dialog = new NewTileSetDialog(new javax.swing.JFrame(), true); dialog.addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox autoTileCheckBox; private javax.swing.JLabel autoTileLabel; private javax.swing.JButton cancleButton; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; private javax.swing.JButton okButton; private javax.swing.JButton pathButton; private javax.swing.JTextField tilesetNameTextField; private javax.swing.JTextField tilesetPathTextField; // End of variables declaration//GEN-END:variables }