setIcon(ICON_NAME, true);
}
@Override
public void actionPerformed(ActionEvent arg0) {
Animation animation = factory.getActiveAnimation();
Sprite sprite = factory.getActiveSprite();
if (animation == null || sprite == null) {
Dialogs.warning(parent,
Messages.getString("OffsetSpriteAction.NO_SPRITE")); //$NON-NLS-1$
return;
}
int baseOffsetX = sprite.offsetX;
int baseOffsetY = sprite.offsetY;
// ===================================================
SpriteView view = new SpriteView(sprite);
// ---------------------------------------------------
JLabel offsxlabel = new JLabel(
Messages.getString("OffsetSpriteAction.LABEL_X_OFFSET")); //$NON-NLS-1$
JLabel offsylabel = new JLabel(
Messages.getString("OffsetSpriteAction.LABEL_Y_OFFSET")); //$NON-NLS-1$
SpinnerModel offsxmodel = new SpinnerNumberModel(baseOffsetX,
MIN_OFFSET_VALUE, MAX_OFFSET_VALUE, 1);
SpinnerModel offsymodel = new SpinnerNumberModel(baseOffsetY,
MIN_OFFSET_VALUE, MAX_OFFSET_VALUE, 1);
JSpinner offsxspin = new JSpinner(offsxmodel);
JSpinner offsyspin = new JSpinner(offsymodel);
// ---------------------------------------------------
ChangeListener listener = new OffsetSpriteListener(offsxmodel,
offsymodel, view, sprite);
offsxmodel.addChangeListener(listener);
offsymodel.addChangeListener(listener);
// ===================================================
JPanel panel = new JPanel();
GroupLayout layout = new GroupLayout(panel);
panel.setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(layout
.createParallelGroup()
.addComponent(view, MIN_SPRITE_SIZE, MIN_SPRITE_SIZE,
GroupLayout.DEFAULT_SIZE)
.addGroup(
layout.createSequentialGroup()
.addGroup(
layout.createParallelGroup(
Alignment.TRAILING, false)
.addComponent(offsxlabel)
.addComponent(offsylabel))
.addGroup(
layout.createParallelGroup(
Alignment.LEADING, false)
.addComponent(offsxspin)
.addComponent(offsyspin))));
layout.setVerticalGroup(layout
.createSequentialGroup()
.addComponent(view, MIN_SPRITE_SIZE, MIN_SPRITE_SIZE,
GroupLayout.DEFAULT_SIZE)
.addGroup(
layout.createParallelGroup(Alignment.BASELINE)
.addComponent(offsxlabel)
.addComponent(offsxspin))
.addGroup(
layout.createParallelGroup(Alignment.BASELINE)
.addComponent(offsylabel)
.addComponent(offsyspin)));
// ---------------------------------------------------
int result = JOptionPane
.showConfirmDialog(
parent,
panel,
Messages.getString("OffsetSpriteAction.TITLE"), JOptionPane.YES_NO_OPTION, //$NON-NLS-1$
JOptionPane.PLAIN_MESSAGE);
if (result != JOptionPane.YES_OPTION) {
sprite.offsetX = baseOffsetX;
sprite.offsetY = baseOffsetY;
} else {
animation.translate(0, 0);
}
factory.updateSprites();
}