Fixed Not updating Morphshape end bounds

Fixed SVG import - linear gradients
Adding morhpshape with/without updating bounds
Fixed nullpointer on gradient linestyle morphshape import
This commit is contained in:
Jindra Petřík
2023-11-05 21:11:10 +01:00
parent 4d0a8c0011
commit 7e30e7335b
7 changed files with 117 additions and 53 deletions
@@ -4430,19 +4430,26 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
replace(items, false);
}
public boolean replaceMorphShape(MorphShapeTag morphShape, boolean create) {
public boolean replaceMorphShape(MorphShapeTag morphShape, boolean create, boolean fill) {
File fileStart = showImportFileChooser("filter.images|*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.svg", true, AppStrings.translate("dialog.morphshape.startShape"));
if (fileStart == null) {
return false;
}
DefineShape4Tag shapeStart = new DefineShape4Tag(morphShape.getSwf());
SWF.addTagBefore(shapeStart, morphShape);
DefineShape4Tag shapeEnd = new DefineShape4Tag(morphShape.getSwf());
SWF.addTagBefore(shapeEnd, morphShape);
shapeStart.shapeBounds = Helper.deepCopy(morphShape.startBounds);
shapeEnd.shapeBounds = Helper.deepCopy(morphShape.endBounds);
if (morphShape instanceof DefineMorphShape2Tag) {
DefineMorphShape2Tag ms2 = (DefineMorphShape2Tag) morphShape;
shapeStart.edgeBounds = Helper.deepCopy(ms2.startEdgeBounds);
shapeEnd.edgeBounds = Helper.deepCopy(ms2.endEdgeBounds);
}
File selfileStart = Helper.fixDialogFile(fileStart);
byte[] dataStart = null;
@@ -4460,9 +4467,9 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
try {
Tag newStartTag;
if (svgTextStart != null) {
newStartTag = new SvgImporter().importSvg(shapeStart, shapeEnd, svgTextStart, false);
newStartTag = new SvgImporter().importSvg(shapeStart, shapeEnd, svgTextStart, fill);
} else {
newStartTag = new ShapeImporter().importImage(shapeStart, dataStart, 0, false);
newStartTag = new ShapeImporter().importImage(shapeStart, dataStart, 0, fill);
}
newStartTag.getTimelined().removeTag(newStartTag);
@@ -4487,9 +4494,9 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
Tag newEndTag;
if (svgTextEnd != null) {
newEndTag = new SvgImporter().importSvg(shapeEnd, svgTextEnd, false);
newEndTag = new SvgImporter().importSvg(shapeEnd, svgTextEnd, fill);
} else {
newEndTag = new ShapeImporter().importImage(shapeEnd, dataEnd, 0, false);
newEndTag = new ShapeImporter().importImage(shapeEnd, dataEnd, 0, fill);
}
newEndTag.getTimelined().removeTag(newEndTag);
}
@@ -4544,7 +4551,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
file = showImportFileChooser("filter.images|*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.svg", true);
}
if (ti0 instanceof MorphShapeTag) {
return replaceMorphShape((MorphShapeTag) ti0, create);
return replaceMorphShape((MorphShapeTag) ti0, create, true);
}
if (ti0 instanceof DefineVideoStreamTag) {
file = showImportFileChooser("filter.movies|*.flv", false);
@@ -4741,8 +4748,11 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
return false;
}
if ((item instanceof ShapeTag) || (item instanceof MorphShapeTag)) {
Tag st = (Tag) item;
if (item instanceof MorphShapeTag) {
return replaceMorphShape((MorphShapeTag) item, false, false);
}
if (item instanceof ShapeTag) {
ShapeTag st = (ShapeTag) item;
String filter = "filter.images|*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.svg";
File selectedFile = showImportFileChooser(filter, true);
if (selectedFile != null) {
@@ -4757,20 +4767,11 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
}
try {
Tag newTag = null;
if (st instanceof ShapeTag) {
if (svgText != null) {
newTag = new SvgImporter().importSvg((ShapeTag) st, svgText, false);
} else {
newTag = new ShapeImporter().importImage((ShapeTag) st, data, 0, false);
}
}
if (st instanceof MorphShapeTag) {
if (svgText != null) {
newTag = new SvgImporter().importSvg((MorphShapeTag) st, svgText, false);
} else {
newTag = new ShapeImporter().importImage((MorphShapeTag) st, data, 0, false);
}
}
if (svgText != null) {
newTag = new SvgImporter().importSvg(st, svgText, false);
} else {
newTag = new ShapeImporter().importImage(st, data, 0, false);
}
SWF swf = st.getSwf();
if (newTag != null) {
refreshTree(swf);
@@ -192,6 +192,8 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
private JButton replaceShapeButton;
private JButton replaceMorphShapeButton;
private JButton replaceMorphShapeUpdateBoundsButton;
private JButton replaceShapeUpdateBoundsButton;
@@ -1310,10 +1312,20 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
replaceMorphShapeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainPanel.replaceMorphShape((MorphShapeTag) mainPanel.getCurrentTree().getCurrentTreeItem(), false);
mainPanel.replaceMorphShape((MorphShapeTag) mainPanel.getCurrentTree().getCurrentTreeItem(), false, true);
}
});
replaceMorphShapeButton.setVisible(false);
replaceMorphShapeUpdateBoundsButton = new JButton(mainPanel.translate("button.replaceNoFill"), View.getIcon("importmorphshape16"));
replaceMorphShapeUpdateBoundsButton.setMargin(new Insets(3, 3, 3, 10));
replaceMorphShapeUpdateBoundsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainPanel.replaceMorphShape((MorphShapeTag) mainPanel.getCurrentTree().getCurrentTreeItem(), false, false);
}
});
replaceMorphShapeUpdateBoundsButton.setVisible(false);
replaceShapeUpdateBoundsButton = new JButton(mainPanel.translate("button.replaceNoFill"), View.getIcon("importshape16"));
replaceShapeUpdateBoundsButton.setMargin(new Insets(3, 3, 3, 10));
@@ -1375,8 +1387,9 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
displayEditButtonsPanel.add(displayEditEditPointsButton);
//displayEditButtonsPanel.add(fixPathsButton);
displayEditButtonsPanel.add(replaceShapeButton);
displayEditButtonsPanel.add(replaceMorphShapeButton);
displayEditButtonsPanel.add(replaceShapeUpdateBoundsButton);
displayEditButtonsPanel.add(replaceMorphShapeButton);
displayEditButtonsPanel.add(replaceMorphShapeUpdateBoundsButton);
displayEditButtonsPanel.add(morphShowPanel);
return displayEditButtonsPanel;
}
@@ -1737,10 +1750,11 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
replaceImageAlphaButton.setVisible(showAlpha);
replaceSpriteButton.setVisible(showSprite);
replaceShapeButton.setVisible(showShape);
replaceMorphShapeButton.setVisible(showMorphShape);
replaceMorphShapeButton.setVisible(showMorphShape);
morphShowPanel.setVisible(showMorphShape);
displayEditEditPointsButton.setVisible(showShape || showMorphShape);
replaceShapeUpdateBoundsButton.setVisible(showShape);
replaceMorphShapeUpdateBoundsButton.setVisible(showMorphShape);
replaceSoundButton.setVisible(showSound);
replaceMovieButton.setVisible(showMovie);
prevFontsButton.setVisible(false);
@@ -2333,6 +2347,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
if (displayEditTag instanceof MorphShapeTag) {
replaceMorphShapeButton.setVisible(true);
replaceMorphShapeUpdateBoundsButton.setVisible(true);
displayEditEditPointsButton.setVisible(true);
}
@@ -2384,8 +2399,9 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
displayEditSaveButton.setVisible(true);
displayEditCancelButton.setVisible(true);
replaceShapeButton.setVisible(false);
replaceMorphShapeButton.setVisible(false);
replaceMorphShapeButton.setVisible(false);
replaceShapeUpdateBoundsButton.setVisible(false);
replaceMorphShapeUpdateBoundsButton.setVisible(false);
displayEditEditPointsButton.setVisible(false);
mainPanel.setEditingStatus();
}
@@ -2418,6 +2434,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
replaceShapeButton.setVisible(false);
replaceMorphShapeButton.setVisible(false);
replaceShapeUpdateBoundsButton.setVisible(false);
replaceMorphShapeUpdateBoundsButton.setVisible(false);
displayEditEditPointsButton.setVisible(false);
if ((displayEditTag instanceof MorphShapeTag) && (morphDisplayMode == MORPH_ANIMATE)) {
@@ -2519,6 +2536,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
replaceShapeButton.setVisible(false);
replaceMorphShapeButton.setVisible(false);
replaceShapeUpdateBoundsButton.setVisible(false);
replaceMorphShapeUpdateBoundsButton.setVisible(false);
displayEditEditPointsButton.setVisible(false);
morphShowPanel.setVisible(false);
@@ -2815,6 +2833,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
if (displayEditTag instanceof MorphShapeTag) {
morphShowPanel.setVisible(true);
replaceMorphShapeButton.setVisible(true);
replaceMorphShapeUpdateBoundsButton.setVisible(true);
displayEditEditPointsButton.setVisible(true);
}
@@ -353,7 +353,7 @@ public class TagTreeContextMenu extends JPopupMenu {
replaceNoFillMenuItem = new JMenuItem(mainPanel.translate("button.replaceNoFill"));
replaceNoFillMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent e) {
mainPanel.replaceNoFillButtonActionPerformed(getCurrentItem());
}
});
@@ -1046,6 +1046,7 @@ public class TagTreeContextMenu extends JPopupMenu {
if (canReplace.test(it -> it instanceof MorphShapeTag)) {
replaceMenuItem.setVisible(true);
replaceNoFillMenuItem.setVisible(true);
}
if (canReplace.test(it -> it instanceof DefineBinaryDataTag)) {
@@ -3830,7 +3831,7 @@ public class TagTreeContextMenu extends JPopupMenu {
remove = !mainPanel.replaceNoFill(tag);
break;
case MORPH_SHAPE:
remove = !mainPanel.replaceMorphShape((MorphShapeTag) tag, true);
remove = !mainPanel.replaceMorphShape((MorphShapeTag) tag, true, false);
break;
case FONT:
remove = !mainPanel.fontEmbed(tag, true);