Set position - OK button not enabled when frame selected or no selection

This commit is contained in:
Jindra Petřík
2022-10-29 14:20:32 +02:00
parent eb9735c841
commit 279b3cc8a0

View File

@@ -64,12 +64,12 @@ import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.plaf.basic.BasicLabelUI;
import javax.swing.plaf.basic.BasicTreeUI;
import javax.swing.tree.DefaultTreeCellRenderer;
@@ -377,30 +377,29 @@ public class SelectTagPositionDialog extends AppDialog {
int rows[] = getSelectionRows();
if (rows.length == 1) {
int row = rows[0];
Object selection = getLastSelectedPathComponent();
boolean onFrame = false;
if (selection != null && (((MyTreeNode)selection).getData() instanceof MyFrame)) { // && !isCollapsed(row)) {
if (selection != null && (((MyTreeNode) selection).getData() instanceof MyFrame)) { // && !isCollapsed(row)) {
onFrame = true;
return;
}
}
Rectangle rect = this.getRowBounds(row);
int sideWidth = 6;
int sideHeight = 6;
int offsetX = -5;
int lineStartX = offsetX + rect.x;
int backStartX = getWidth() + offsetX;
if (onFrame) {
g.fillRect(lineStartX, rect.y + rect.height - 1, getWidth() - lineStartX, 1);
} else {
g.fillRect(lineStartX, rect.y, getWidth() - lineStartX, 1);
} else {
g.fillRect(lineStartX, rect.y, getWidth() - lineStartX, 1);
}
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(getForeground());
GeneralPath path = new GeneralPath();
if (onFrame) {
path.moveTo(backStartX - 6, rect.y + rect.height - 1 - 6);
path.lineTo(backStartX, rect.y + rect.height - 1);
@@ -428,6 +427,7 @@ public class SelectTagPositionDialog extends AppDialog {
positionTree.setRootVisible(false);
positionTree.setShowsRootHandles(true);
positionTree.addTreeSelectionListener(this::spriteValueChanged);
positionTree.addTreeSelectionListener(this::positionTreeValueChanged);
previewPanel = new PreviewPanel(Main.getMainFrame().getPanel(), null);
previewPanel.setReadOnly(true);
@@ -451,6 +451,15 @@ public class SelectTagPositionDialog extends AppDialog {
View.setWindowIcon(this);
}
public void positionTreeValueChanged(TreeSelectionEvent e) {
MyTreeNode node = (MyTreeNode) positionTree.getLastSelectedPathComponent();
boolean enabled = true;
if (node == null || (node.getData() instanceof MyFrame)) {
enabled = false;
}
okButton.setEnabled(enabled);
}
private int getCurrentSelectedFrame() {
TreePath path = positionTree.getSelectionPath();
for (int i = path.getPathCount() - 1; i >= 0; i--) {
@@ -462,7 +471,7 @@ public class SelectTagPositionDialog extends AppDialog {
}
return -1;
}
private Timelined getCurrentSelectedTimelined() {
TreePath path = positionTree.getSelectionPath();
for (int i = path.getPathCount() - 1 - 1 /*sprite can be last, use its parent*/; i >= 0; i--) {
@@ -471,7 +480,7 @@ public class SelectTagPositionDialog extends AppDialog {
return swf;
}
if (node.getData() instanceof DefineSpriteTag) {
return (Timelined) node.getData();
return (Timelined) node.getData();
}
}
return null;
@@ -485,7 +494,7 @@ public class SelectTagPositionDialog extends AppDialog {
return;
}
MyTreeNode tnode = (MyTreeNode) selection.getLastPathComponent();
if (tnode.getData() instanceof Tag) {
if (tnode.getData() instanceof Tag) {
MainPanel.showPreview((TreeItem) tnode.getData(), previewPanel, getCurrentSelectedFrame() - 1, getCurrentSelectedTimelined());
} else if (tnode.getData() instanceof MyFrame) {
int f = ((MyFrame) tnode.getData()).frame;
@@ -507,7 +516,7 @@ public class SelectTagPositionDialog extends AppDialog {
}
private void okButtonActionPerformed(ActionEvent evt) {
MyTreeNode node = (MyTreeNode)positionTree.getLastSelectedPathComponent();
MyTreeNode node = (MyTreeNode) positionTree.getLastSelectedPathComponent();
if (node.getData() instanceof MyFrame) {
return;
}
@@ -515,10 +524,10 @@ public class SelectTagPositionDialog extends AppDialog {
selectedTag = null;
} else {
selectedTag = (Tag) node.getData();
}
}
selectedTimelined = getCurrentSelectedTimelined();
result = OK_OPTION;
previewPanel.clear();
setVisible(false);
@@ -530,8 +539,10 @@ public class SelectTagPositionDialog extends AppDialog {
}
/**
* Gets current selected tag to determine position. null = end of timeline position
* @return
* Gets current selected tag to determine position. null = end of timeline
* position
*
* @return
*/
public Tag getSelectedTag() {
return selectedTag;
@@ -539,7 +550,8 @@ public class SelectTagPositionDialog extends AppDialog {
/**
* Gets selected timelined
* @return
*
* @return
*/
public Timelined getSelectedTimelined() {
return selectedTimelined;