TileMangler/src/tm/modaldialog/TMStretchDialog.java
lif 37e9e9935c Rename to "TileMangler"
Prefer not to have edgy references to child sexual assault in our tools.
Consider that victims of such violence may well grow up to become ROM
hackers just as often as the rest of us. Let's not be rude to them!
2024-02-01 20:32:34 -08:00

135 lines
No EOL
3.5 KiB
Java

/*
*
* Copyright (C) 2003 Kent Hansen.
*
* This file is part of Tile Mangler.
*
* Tile Mangler 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.
*
* Tile Mangler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
package tm.modaldialog;
import tm.utils.DecimalNumberVerifier;
import javax.swing.*;
import java.awt.*;
/**
*
* The dialog where user can enter new dimensions for the current selection.
*
**/
public class TMStretchDialog extends TMModalDialog {
private JLabel colsLabel;
private JLabel rowsLabel;
private JTextField colsField;
private JTextField rowsField;
/**
*
* Creates the stretch dialog.
*
**/
public TMStretchDialog(Frame owner, tm.utils.Xlator xl) {
super(owner, "Stretch_Image_Dialog_Title", xl);
}
/**
*
*
*
**/
public int getCols() {
return Integer.parseInt(colsField.getText());
}
/**
*
*
*
**/
public int getRows() {
return Integer.parseInt(rowsField.getText());
}
/**
*
*
*
**/
protected JPanel getDialogPane() {
colsLabel = new JLabel(xlate("Columns_Prompt"));
rowsLabel = new JLabel(xlate("Rows_Prompt"));
colsField = new JTextField();
rowsField = new JTextField();
JPanel colsPane = new JPanel();
colsPane.setLayout(new BoxLayout(colsPane, BoxLayout.X_AXIS));
colsPane.add(colsLabel);
colsPane.add(colsField);
JPanel rowsPane = new JPanel();
rowsPane.setLayout(new BoxLayout(rowsPane, BoxLayout.X_AXIS));
rowsPane.add(rowsLabel);
rowsPane.add(rowsField);
JPanel p = new JPanel();
GridBagLayout gbl = new GridBagLayout();
p.setLayout(gbl);
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
buildConstraints(gbc, 0, 0, 1, 1, 100, 50);
gbl.setConstraints(colsPane, gbc);
p.add(colsPane);
buildConstraints(gbc, 0, 1, 1, 1, 100, 50);
gbl.setConstraints(rowsPane, gbc);
p.add(rowsPane);
p.setPreferredSize(new Dimension(200, 60));
colsField.setColumns(3);
rowsField.setColumns(3);
colsField.addKeyListener(new DecimalNumberVerifier());
colsField.getDocument().addDocumentListener(new TMDocumentListener());
rowsField.addKeyListener(new DecimalNumberVerifier());
rowsField.getDocument().addDocumentListener(new TMDocumentListener());
return p;
}
public int showDialog(int initialCols, int initialRows) {
colsField.setText(Integer.toString(initialCols));
rowsField.setText(Integer.toString(initialRows));
maybeEnableOKButton();
SwingUtilities.invokeLater( new Runnable() {
public void run() {
colsField.requestFocus();
}
});
return super.showDialog();
}
public boolean inputOK() {
return (!colsField.getText().equals("") && !rowsField.getText().equals("")
&& (getCols() > 0) && (getRows() > 0));
}
}