001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.vmd.game.editor.tiledlayer;
043:
044: import java.awt.BorderLayout;
045: import java.awt.Color;
046: import java.awt.Dialog;
047: import java.awt.event.ActionEvent;
048: import java.awt.event.ActionListener;
049: import java.beans.PropertyChangeEvent;
050: import java.beans.PropertyChangeListener;
051: import java.util.Set;
052: import javax.swing.JScrollPane;
053: import org.netbeans.modules.vmd.game.dialog.NewAnimatedTileDialog;
054: import org.netbeans.modules.vmd.game.model.Editable;
055: import org.netbeans.modules.vmd.game.model.Tile;
056: import org.netbeans.modules.vmd.game.model.TiledLayer;
057: import org.netbeans.modules.vmd.game.model.TiledLayerListener;
058: import org.openide.DialogDescriptor;
059: import org.openide.DialogDisplayer;
060: import org.openide.util.NbBundle;
061:
062: /**
063: *
064: * @author kherink
065: */
066: public class TiledLayerEditor extends javax.swing.JPanel implements
067: TiledLayerListener, PropertyChangeListener {
068:
069: private TiledLayer tiledLayer;
070: private TiledLayerEditorComponent editorComponent;
071: private JScrollPane editorScroll;
072:
073: /**
074: * Creates new form TiledLayerEditor
075: */
076: public TiledLayerEditor(final TiledLayer tiledLayer) {
077: this .tiledLayer = tiledLayer;
078: this .tiledLayer.addTiledLayerListener(this );
079: this .tiledLayer.addPropertyChangeListener(this );
080: this .editorComponent = new TiledLayerEditorComponent(
081: this .tiledLayer);
082: initComponents();
083:
084: this .getAccessibleContext().setAccessibleName(
085: NbBundle.getMessage(TiledLayerEditor.class,
086: "TiledLayerEditor.accessible.name"));
087: this .getAccessibleContext().setAccessibleDescription(
088: NbBundle.getMessage(TiledLayerEditor.class,
089: "TiledLayerEditor.accessible.description"));
090:
091: this .toggleButtonPaint.addActionListener(new ActionListener() {
092: public void actionPerformed(ActionEvent e) {
093: if (toggleButtonPaint.isSelected()) {
094: editorComponent
095: .setEditMode(TiledLayerEditorComponent.EDIT_MODE_PAINT);
096: }
097: }
098: });
099: this .toggleButtonSelect.addActionListener(new ActionListener() {
100: public void actionPerformed(ActionEvent e) {
101: if (toggleButtonSelect.isSelected()) {
102: editorComponent
103: .setEditMode(TiledLayerEditorComponent.EDIT_MODE_SELECT);
104: }
105: }
106: });
107:
108: this .toggleButtonPaint.setSelected(true);
109:
110: this .buttonAddAnimatedTile
111: .addActionListener(new ActionListener() {
112: public void actionPerformed(ActionEvent e) {
113: NewAnimatedTileDialog dialog = new NewAnimatedTileDialog(
114: tiledLayer.getImageResource(),
115: tiledLayer.getTileWidth(), tiledLayer
116: .getTileHeight());
117: DialogDescriptor dd = new DialogDescriptor(
118: dialog,
119: NbBundle
120: .getMessage(
121: TiledLayerEditor.class,
122: "TiledLayerEditor.newAnimatedTileButton.txt"));
123: dd.setButtonListener(dialog);
124: dd.setValid(false);
125: dialog.setDialogDescriptor(dd);
126: Dialog d = DialogDisplayer.getDefault()
127: .createDialog(dd);
128: d.setVisible(true);
129: }
130: });
131: this .textFieldName.setBackground(this .textFieldName.getParent()
132: .getBackground());
133: this .textFieldRows.setBackground(this .textFieldRows.getParent()
134: .getBackground());
135: this .textFieldCols.setBackground(this .textFieldCols.getParent()
136: .getBackground());
137:
138: this .editorScroll = new JScrollPane();
139: this .editorScroll.getViewport().setBackground(Color.WHITE);
140: this .editorScroll.setViewportView(this .editorComponent);
141: this .editorScroll
142: .setColumnHeaderView(this .editorComponent.rulerHorizontal);
143: this .editorScroll
144: .setRowHeaderView(this .editorComponent.rulerVertical);
145: this .editorScroll.setCorner(JScrollPane.UPPER_LEFT_CORNER,
146: this .editorComponent.getGridButton());
147: this .jPanel2.add(this .editorScroll, BorderLayout.CENTER);
148:
149: JScrollPane scrollAnimTiles = new JScrollPane(
150: new AnimatedTileList(editorComponent));
151: scrollAnimTiles.setBorder(null);
152: this .panelAnimatedTiles.add(scrollAnimTiles,
153: BorderLayout.CENTER);
154: }
155:
156: /** This method is called from within the constructor to
157: * initialize the form.
158: * WARNING: Do NOT modify this code. The content of this method is
159: * always regenerated by the Form Editor.
160: */
161: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
162: private void initComponents() {
163:
164: buttonGroupMouseMode = new javax.swing.ButtonGroup();
165: jPanel1 = new javax.swing.JPanel();
166: jLabel1 = new javax.swing.JLabel();
167: textFieldName = new javax.swing.JTextField();
168: toggleButtonPaint = new javax.swing.JToggleButton();
169: toggleButtonSelect = new javax.swing.JToggleButton();
170: jLabel2 = new javax.swing.JLabel();
171: textFieldRows = new javax.swing.JTextField();
172: jLabel3 = new javax.swing.JLabel();
173: textFieldCols = new javax.swing.JTextField();
174: jSplitPane1 = new javax.swing.JSplitPane();
175: jPanel2 = new javax.swing.JPanel();
176: panelAnimatedTiles = new javax.swing.JPanel();
177: buttonAddAnimatedTile = new javax.swing.JButton();
178:
179: setLayout(new java.awt.BorderLayout());
180:
181: jLabel1.setText(org.openide.util.NbBundle.getMessage(
182: TiledLayerEditor.class,
183: "TiledLayerEditor.tiledLayerLabel.txt")); // NOI18N
184:
185: textFieldName.setEditable(false);
186: textFieldName
187: .setHorizontalAlignment(javax.swing.JTextField.LEFT);
188: textFieldName.setText(this .tiledLayer.getName());
189: textFieldName.setBorder(null);
190:
191: buttonGroupMouseMode.add(toggleButtonPaint);
192: toggleButtonPaint
193: .setIcon(new javax.swing.ImageIcon(
194: getClass()
195: .getResource(
196: "/org/netbeans/modules/vmd/game/editor/tiledlayer/res/drawing_mode_16.png"))); // NOI18N
197: toggleButtonPaint.setToolTipText(org.openide.util.NbBundle
198: .getMessage(TiledLayerEditor.class,
199: "TiledLayerEditor.paintModeButton.tooltip")); // NOI18N
200: toggleButtonPaint.setBorder(null);
201: toggleButtonPaint.setBorderPainted(false);
202: toggleButtonPaint.setRolloverEnabled(true);
203:
204: buttonGroupMouseMode.add(toggleButtonSelect);
205: toggleButtonSelect
206: .setIcon(new javax.swing.ImageIcon(
207: getClass()
208: .getResource(
209: "/org/netbeans/modules/vmd/game/editor/tiledlayer/res/selection_mode_16.png"))); // NOI18N
210: toggleButtonSelect.setToolTipText(org.openide.util.NbBundle
211: .getMessage(TiledLayerEditor.class,
212: "TiledLayerEditor.selectModeButton.tooltip")); // NOI18N
213: toggleButtonSelect.setBorder(null);
214: toggleButtonSelect.setBorderPainted(false);
215: toggleButtonSelect.setRolloverEnabled(true);
216:
217: jLabel2.setText(org.openide.util.NbBundle.getMessage(
218: TiledLayerEditor.class,
219: "TiledLayerEditor.tiledLayerRowsLabel.txt")); // NOI18N
220:
221: textFieldRows.setEditable(false);
222: textFieldRows
223: .setHorizontalAlignment(javax.swing.JTextField.LEFT);
224: textFieldRows.setText(Integer.toString(this .tiledLayer
225: .getRowCount()));
226: textFieldRows.setBorder(null);
227:
228: jLabel3.setText(org.openide.util.NbBundle.getMessage(
229: TiledLayerEditor.class,
230: "TiledLayerEditor.tiledLayerColsLabel.txt")); // NOI18N
231:
232: textFieldCols.setEditable(false);
233: textFieldCols
234: .setHorizontalAlignment(javax.swing.JTextField.LEFT);
235: textFieldCols.setText(Integer.toString(this .tiledLayer
236: .getColumnCount()));
237: textFieldCols.setBorder(null);
238:
239: org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(
240: jPanel1);
241: jPanel1.setLayout(jPanel1Layout);
242: jPanel1Layout
243: .setHorizontalGroup(jPanel1Layout
244: .createParallelGroup(
245: org.jdesktop.layout.GroupLayout.LEADING)
246: .add(
247: jPanel1Layout
248: .createSequentialGroup()
249: .addContainerGap()
250: .add(
251: toggleButtonPaint,
252: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
253: 26,
254: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
255: .addPreferredGap(
256: org.jdesktop.layout.LayoutStyle.RELATED)
257: .add(
258: toggleButtonSelect,
259: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
260: 23,
261: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
262: .addPreferredGap(
263: org.jdesktop.layout.LayoutStyle.UNRELATED)
264: .add(jLabel1)
265: .addPreferredGap(
266: org.jdesktop.layout.LayoutStyle.RELATED)
267: .add(
268: textFieldName,
269: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
270: 0, Short.MAX_VALUE)
271: .add(36, 36, 36)
272: .add(jLabel2)
273: .add(6, 6, 6)
274: .add(
275: textFieldRows,
276: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
277: 41,
278: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
279: .addPreferredGap(
280: org.jdesktop.layout.LayoutStyle.RELATED)
281: .add(jLabel3)
282: .add(6, 6, 6)
283: .add(
284: textFieldCols,
285: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
286: 41,
287: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
288: .addContainerGap()));
289:
290: jPanel1Layout.linkSize(new java.awt.Component[] {
291: toggleButtonPaint, toggleButtonSelect },
292: org.jdesktop.layout.GroupLayout.HORIZONTAL);
293:
294: jPanel1Layout
295: .setVerticalGroup(jPanel1Layout
296: .createParallelGroup(
297: org.jdesktop.layout.GroupLayout.LEADING)
298: .add(
299: jPanel1Layout
300: .createSequentialGroup()
301: .add(5, 5, 5)
302: .add(
303: textFieldRows,
304: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
305: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
306: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
307: .add(
308: jPanel1Layout.createSequentialGroup()
309: .add(5, 5, 5).add(jLabel2))
310: .add(
311: jPanel1Layout.createSequentialGroup()
312: .add(5, 5, 5).add(jLabel3))
313: .add(
314: jPanel1Layout
315: .createSequentialGroup()
316: .add(5, 5, 5)
317: .add(
318: textFieldCols,
319: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
320: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
321: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
322: .add(
323: jPanel1Layout
324: .createSequentialGroup()
325: .add(5, 5, 5)
326: .add(
327: jPanel1Layout
328: .createParallelGroup(
329: org.jdesktop.layout.GroupLayout.LEADING)
330: .add(
331: org.jdesktop.layout.GroupLayout.TRAILING,
332: textFieldName,
333: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
334: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
335: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
336: .add(
337: org.jdesktop.layout.GroupLayout.TRAILING,
338: jLabel1)))
339: .add(
340: jPanel1Layout
341: .createParallelGroup(
342: org.jdesktop.layout.GroupLayout.BASELINE)
343: .add(
344: toggleButtonSelect,
345: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
346: 25,
347: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
348: .add(
349: toggleButtonPaint,
350: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
351: 25,
352: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)));
353:
354: add(jPanel1, java.awt.BorderLayout.NORTH);
355:
356: jSplitPane1.setBorder(null);
357: jSplitPane1.setDividerSize(5);
358: jSplitPane1.setResizeWeight(1.0);
359: jSplitPane1.setContinuousLayout(true);
360:
361: jPanel2.setBackground(new java.awt.Color(255, 255, 255));
362: jPanel2.setToolTipText("");
363: jPanel2.setPreferredSize(new java.awt.Dimension(10000, 10000));
364: jPanel2.setLayout(new java.awt.BorderLayout());
365: jSplitPane1.setLeftComponent(jPanel2);
366:
367: panelAnimatedTiles.setBorder(javax.swing.BorderFactory
368: .createEtchedBorder());
369: panelAnimatedTiles.setLayout(new java.awt.BorderLayout());
370:
371: buttonAddAnimatedTile
372: .setIcon(new javax.swing.ImageIcon(
373: getClass()
374: .getResource(
375: "/org/netbeans/modules/vmd/game/editor/tiledlayer/res/new_animated_tile_16.png"))); // NOI18N
376: buttonAddAnimatedTile.setText(org.openide.util.NbBundle
377: .getMessage(TiledLayerEditor.class,
378: "TiledLayerEditor.newAnimatedTileButton.txt")); // NOI18N
379: buttonAddAnimatedTile.setToolTipText(org.openide.util.NbBundle
380: .getMessage(TiledLayerEditor.class,
381: "TiledLayerEditor.newAnimTileButton.tooltip")); // NOI18N
382: panelAnimatedTiles.add(buttonAddAnimatedTile,
383: java.awt.BorderLayout.NORTH);
384:
385: jSplitPane1.setRightComponent(panelAnimatedTiles);
386:
387: add(jSplitPane1, java.awt.BorderLayout.CENTER);
388: }// </editor-fold>//GEN-END:initComponents
389:
390: // Variables declaration - do not modify//GEN-BEGIN:variables
391: public javax.swing.JButton buttonAddAnimatedTile;
392: public javax.swing.ButtonGroup buttonGroupMouseMode;
393: public javax.swing.JLabel jLabel1;
394: public javax.swing.JLabel jLabel2;
395: public javax.swing.JLabel jLabel3;
396: public javax.swing.JPanel jPanel1;
397: private javax.swing.JPanel jPanel2;
398: public javax.swing.JSplitPane jSplitPane1;
399: public javax.swing.JPanel panelAnimatedTiles;
400: public javax.swing.JTextField textFieldCols;
401: public javax.swing.JTextField textFieldName;
402: public javax.swing.JTextField textFieldRows;
403: public javax.swing.JToggleButton toggleButtonPaint;
404: public javax.swing.JToggleButton toggleButtonSelect;
405:
406: // End of variables declaration//GEN-END:variables
407:
408: public void setPaintTile(Tile tile) {
409: this .editorComponent.setPaintTileIndex(tile.getIndex());
410: }
411:
412: public void propertyChange(PropertyChangeEvent evt) {
413: if (evt.getSource() == this .tiledLayer) {
414: if (evt.getPropertyName().equals(Editable.PROPERTY_NAME)) {
415: textFieldName.setText(this .tiledLayer.getName());
416: }
417: }
418: }
419:
420: public void updateTextLabels() {
421: textFieldRows.setText(Integer.toString(this .tiledLayer
422: .getRowCount()));
423: textFieldCols.setText(Integer.toString(this .tiledLayer
424: .getColumnCount()));
425: }
426:
427: public void tileChanged(TiledLayer t, int row, int col) {
428: }
429:
430: public void tilesChanged(TiledLayer t, Set positions) {
431: }
432:
433: public void tilesStructureChanged(TiledLayer source) {
434: this .updateTextLabels();
435: }
436:
437: public void columnsInserted(TiledLayer t, int index, int count) {
438: this .updateTextLabels();
439: }
440:
441: public void columnsRemoved(TiledLayer t, int index, int count) {
442: this .updateTextLabels();
443: }
444:
445: public void rowsInserted(TiledLayer t, int index, int count) {
446: this .updateTextLabels();
447: }
448:
449: public void rowsRemoved(TiledLayer t, int index, int count) {
450: this.updateTextLabels();
451: }
452:
453: }
|