update characterids when tag was moved or copied (copy with dependencies is not ready,yet)

This commit is contained in:
2015-04-29 23:19:47 +02:00
parent 81a4c2f664
commit a6847b6562
38 changed files with 479 additions and 100 deletions
@@ -850,7 +850,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
}
}
refreshTree(null);
refreshTree();
if (updateNeeded) {
View.execInEventDispatch(() -> {
@@ -1090,42 +1090,42 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
ret.addAll(new ImageExporter().exportImages(handler, selFile + File.separator + "images", images,
new ImageExportSettings(export.getValue(ImageExportMode.class)), evl));
}
if (export.isOptionEnabled(ShapeExportMode.class)) {
ret.addAll(new ShapeExporter().exportShapes(handler, selFile + File.separator + "shapes", shapes,
new ShapeExportSettings(export.getValue(ShapeExportMode.class), export.getZoom()), evl));
}
if (export.isOptionEnabled(MorphShapeExportMode.class)) {
ret.addAll(new MorphShapeExporter().exportMorphShapes(handler, selFile + File.separator + "morphshapes", morphshapes,
new MorphShapeExportSettings(export.getValue(MorphShapeExportMode.class), export.getZoom()), evl));
}
if (export.isOptionEnabled(TextExportMode.class)) {
ret.addAll(new TextExporter().exportTexts(handler, selFile + File.separator + TextExportSettings.EXPORT_FOLDER_NAME, texts,
new TextExportSettings(export.getValue(TextExportMode.class), Configuration.textExportSingleFile.get(), export.getZoom()), evl));
}
if (export.isOptionEnabled(MovieExportMode.class)) {
ret.addAll(new MovieExporter().exportMovies(handler, selFile + File.separator + "movies", movies,
new MovieExportSettings(export.getValue(MovieExportMode.class)), evl));
}
if (export.isOptionEnabled(SoundExportMode.class)) {
ret.addAll(new SoundExporter().exportSounds(handler, selFile + File.separator + "sounds", sounds,
new SoundExportSettings(export.getValue(SoundExportMode.class)), evl));
}
if (export.isOptionEnabled(BinaryDataExportMode.class)) {
ret.addAll(new BinaryDataExporter().exportBinaryData(handler, selFile + File.separator + "binaryData", binaryData,
new BinaryDataExportSettings(export.getValue(BinaryDataExportMode.class)), evl));
}
if (export.isOptionEnabled(FontExportMode.class)) {
ret.addAll(new FontExporter().exportFonts(handler, selFile + File.separator + "fonts", fonts,
new FontExportSettings(export.getValue(FontExportMode.class)), evl));
}
if (export.isOptionEnabled(SymbolClassExportMode.class)) {
ret.addAll(new SymbolClassExporter().exportNames(selFile, symbolNames, evl));
}
@@ -1176,7 +1176,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
}
}
}
return ret;
}
@@ -1187,42 +1187,42 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
new ImageExporter().exportImages(handler, selFile + File.separator + "images", swf.tags,
new ImageExportSettings(export.getValue(ImageExportMode.class)), evl);
}
if (export.isOptionEnabled(ShapeExportMode.class)) {
new ShapeExporter().exportShapes(handler, selFile + File.separator + "shapes", swf.tags,
new ShapeExportSettings(export.getValue(ShapeExportMode.class), export.getZoom()), evl);
}
if (export.isOptionEnabled(MorphShapeExportMode.class)) {
new MorphShapeExporter().exportMorphShapes(handler, selFile + File.separator + "morphshapes", swf.tags,
new MorphShapeExportSettings(export.getValue(MorphShapeExportMode.class), export.getZoom()), evl);
}
if (export.isOptionEnabled(TextExportMode.class)) {
new TextExporter().exportTexts(handler, selFile + File.separator + TextExportSettings.EXPORT_FOLDER_NAME, swf.tags,
new TextExportSettings(export.getValue(TextExportMode.class), Configuration.textExportSingleFile.get(), export.getZoom()), evl);
}
if (export.isOptionEnabled(MovieExportMode.class)) {
new MovieExporter().exportMovies(handler, selFile + File.separator + "movies", swf.tags,
new MovieExportSettings(export.getValue(MovieExportMode.class)), evl);
}
if (export.isOptionEnabled(SoundExportMode.class)) {
new SoundExporter().exportSounds(handler, selFile + File.separator + "sounds", swf.tags,
new SoundExportSettings(export.getValue(SoundExportMode.class)), evl);
}
if (export.isOptionEnabled(BinaryDataExportMode.class)) {
new BinaryDataExporter().exportBinaryData(handler, selFile + File.separator + "binaryData", swf.tags,
new BinaryDataExportSettings(export.getValue(BinaryDataExportMode.class)), evl);
}
if (export.isOptionEnabled(FontExportMode.class)) {
new FontExporter().exportFonts(handler, selFile + File.separator + "fonts", swf.tags,
new FontExportSettings(export.getValue(FontExportMode.class)), evl);
}
if (export.isOptionEnabled(SymbolClassExportMode.class)) {
new SymbolClassExporter().exportNames(selFile, swf.tags, evl);
}
@@ -2091,24 +2091,23 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
}
public void refreshTree() {
refreshTree(null);
refreshTree(new SWF[0]);
}
public void refreshTree(SWF swf) {
refreshTree(new SWF[]{swf});
}
public void refreshTree(SWF[] swfs) {
clear();
showCard(CARDEMPTYPANEL);
TreeItem treeItem = tagTree.getCurrentTreeItem();
TagTreeModel ttm = tagTree.getModel();
if (ttm != null) {
List<List<String>> expandedNodes = View.getExpandedNodes(tagTree);
ttm.updateSwf(swf);
View.expandTreeNodes(tagTree, expandedNodes);
}
tagTree.updateSwfs(swfs);
if (treeItem != null) {
SWF treeItemSwf = treeItem.getSwf().getRootSwf();
if (swfs.contains(treeItemSwf.swfList)) {
if (this.swfs.contains(treeItemSwf.swfList)) {
setTagTreeSelectedNode(treeItem);
}
}
@@ -2902,7 +2901,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
public static Timelined makeTimelined(final Tag tag) {
return makeTimelined(tag, -1);
}
public static Timelined makeTimelined(final Tag tag, final int fontFrameNum) {
return new Timelined() {
@@ -2915,6 +2914,19 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
return tim;
}
tim = new Timeline(tag.getSwf(), null, new ArrayList<>(), ((CharacterTag) tag).getCharacterId(), getRect());
initTimeline(tim);
return tim;
}
@Override
public void resetTimeline() {
if (tim != null) {
tim.reset(tag.getSwf(), null, new ArrayList<>(), ((CharacterTag) tag).getCharacterId(), getRect());
initTimeline(tim);
}
}
private void initTimeline(Timeline timeline) {
if (tag instanceof MorphShapeTag) {
tim.frameRate = MORPH_SHAPE_ANIMATION_FRAME_RATE;
int framesCnt = tim.frameRate * MORPH_SHAPE_ANIMATION_LENGTH;
@@ -2934,7 +2946,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
if (frame < 0 || frame >= pageCount) {
frame = 0;
}
Frame f = new Frame(tim, 0);
DepthState ds = new DepthState(tag.getSwf(), f);
ds.characterId = ((CharacterTag) tag).getCharacterId();
@@ -2952,7 +2964,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
tim.addFrame(f);
}
tim.displayRect = getRect();
return tim;
}
@Override
@@ -1190,7 +1190,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener {
SWF swf = tag.getSwf();
swf.clearImageCache();
swf.updateCharacters();
tag.getTimelined().getTimeline().reset();
tag.getTimelined().resetTimeline();
mainPanel.repaintTree();
mainPanel.setTagTreeSelectedNode(tag);
genericEditButton.setVisible(true);
@@ -1,16 +1,16 @@
/*
* Copyright (C) 2010-2015 JPEXS
*
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
*
* This program 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.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -104,7 +104,7 @@ import java.util.Map;
*/
public class TagIdClassMap {
private static final Map<Integer, Class> tagIdClassMap = new HashMap<>();
private static final Map<Integer, Class<?>> tagIdClassMap = new HashMap<>();
private static final Map<Class, Integer> classTagIdMap = new HashMap<>();
@@ -190,12 +190,12 @@ public class TagIdClassMap {
addTag(FontTextureInfo.ID, FontTextureInfo.class);
}
private static void addTag(int tagId, Class cl) {
private static void addTag(int tagId, Class<?> cl) {
tagIdClassMap.put(tagId, cl);
classTagIdMap.put(cl, tagId);
}
public static Class getClassByTagId(int tagId) {
public static Class<?> getClassByTagId(int tagId) {
return tagIdClassMap.get(tagId);
}
@@ -593,6 +593,15 @@ public class TagTree extends JTree {
return item;
}
public void updateSwfs(SWF[] swfs) {
TagTreeModel ttm = getModel();
if (ttm != null) {
List<List<String>> expandedNodes = View.getExpandedNodes(this);
ttm.updateSwf(null); // todo: honfika: update only the changed swfs, but there was an exception when i tried it
View.expandTreeNodes(this, expandedNodes);
}
}
@Override
public TagTreeModel getModel() {
return (TagTreeModel) super.getModel();
@@ -64,6 +64,8 @@ import javax.swing.tree.TreePath;
*/
public class TagTreeContextMenu extends JPopupMenu {
private static final Logger logger = Logger.getLogger(TagTreeContextMenu.class.getName());
private final MainPanel mainPanel;
private final TagTree tagTree;
@@ -336,7 +338,7 @@ public class TagTreeContextMenu extends JPopupMenu {
addTagMenu.removeAll();
if (allowedTagTypes != null) {
for (Integer tagId : allowedTagTypes) {
final Class cl = TagIdClassMap.getClassByTagId(tagId);
final Class<?> cl = TagIdClassMap.getClassByTagId(tagId);
JMenuItem tagItem = new JMenuItem(cl.getSimpleName());
tagItem.addActionListener((ActionEvent ae) -> {
addTagActionPerformed(ae, firstItem, cl);
@@ -368,13 +370,13 @@ public class TagTreeContextMenu extends JPopupMenu {
if (targetSwf != singleSwf) {
JMenuItem swfItem = new JMenuItem(targetSwf.getShortFileName());
swfItem.addActionListener((ActionEvent ae) -> {
copyTagActionPerformed(ae, items, targetSwf);
moveTagActionPerformed(ae, items, targetSwf);
});
moveTagMenu.add(swfItem);
swfItem = new JMenuItem(targetSwf.getShortFileName());
swfItem.addActionListener((ActionEvent ae) -> {
moveTagActionPerformed(ae, items, targetSwf);
copyTagActionPerformed(ae, items, targetSwf);
});
copyTagMenu.add(swfItem);
@@ -406,7 +408,7 @@ public class TagTreeContextMenu extends JPopupMenu {
}
}
private void addTagActionPerformed(ActionEvent evt, TreeItem firstItem, Class cl) {
private void addTagActionPerformed(ActionEvent evt, TreeItem firstItem, Class<?> cl) {
try {
SWF swf = firstItem.getSwf();
Tag t = (Tag) cl.getDeclaredConstructor(SWF.class).newInstance(new Object[]{swf});
@@ -430,14 +432,27 @@ public class TagTreeContextMenu extends JPopupMenu {
swf.tags.add(t);
}
}
timelined.getTimeline().reset();
timelined.resetTimeline();
swf.updateCharacters();
mainPanel.refreshTree(swf);
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException ex) {
Logger.getLogger(TagTreeContextMenu.class.getName()).log(Level.SEVERE, null, ex);
logger.log(Level.SEVERE, null, ex);
}
}
private void chechUniqueCharacterId(Tag tag) {
if (tag instanceof CharacterTag) {
CharacterTag characterTag = (CharacterTag) tag;
int characterId = characterTag.getCharacterId();
SWF swf = tag.getSwf();
if (swf.getCharacter(characterId) != null) {
int newCharacterId = swf.getNextCharacterId();
characterTag.setCharacterId(newCharacterId);
logger.log(Level.WARNING, "Target SWF already contained chatacter tag with id = {0} => id changed to {1}", new Object[]{characterId, newCharacterId});
}
}
}
private void moveTagActionPerformed(ActionEvent evt, List<TreeItem> items, SWF targetSwf) {
SWF sourceSwf = items.get(0).getSwf();
for (TreeItem item : items) {
@@ -445,6 +460,8 @@ public class TagTreeContextMenu extends JPopupMenu {
sourceSwf.tags.remove(tag);
tag.setSwf(targetSwf);
targetSwf.tags.add(tag);
chechUniqueCharacterId(tag);
targetSwf.updateCharacters();
tag.setModified(true);
}
@@ -456,9 +473,11 @@ public class TagTreeContextMenu extends JPopupMenu {
targetSwf.clearImageCache();
sourceSwf.updateCharacters();
targetSwf.updateCharacters();
mainPanel.refreshTree(null); // refresh all opened swfs
sourceSwf.resetTimelines(sourceSwf);
targetSwf.resetTimelines(targetSwf);
mainPanel.refreshTree(new SWF[]{sourceSwf, targetSwf});
}
private void copyTagActionPerformed(ActionEvent evt, List<TreeItem> items, SWF targetSwf) {
try {
for (TreeItem item : items) {
@@ -466,6 +485,8 @@ public class TagTreeContextMenu extends JPopupMenu {
Tag copyTag = tag.cloneTag();
copyTag.setSwf(targetSwf);
targetSwf.tags.add(copyTag);
chechUniqueCharacterId(copyTag);
targetSwf.updateCharacters();
copyTag.setModified(true);
}
@@ -475,10 +496,10 @@ public class TagTreeContextMenu extends JPopupMenu {
targetSwf.updateCharacters();
mainPanel.refreshTree(targetSwf);
} catch (IOException | InterruptedException ex) {
Logger.getLogger(TagTreeContextMenu.class.getName()).log(Level.SEVERE, null, ex);
logger.log(Level.SEVERE, null, ex);
}
}
private void copyTagWithDependenciesActionPerformed(ActionEvent evt, List<TreeItem> items, SWF targetSwf) {
try {
SWF sourceSwf = items.get(0).getSwf();
@@ -490,16 +511,22 @@ public class TagTreeContextMenu extends JPopupMenu {
Tag copyTag = tag.cloneTag();
copyTag.setSwf(targetSwf);
targetSwf.tags.add(copyTag);
chechUniqueCharacterId(copyTag);
targetSwf.updateCharacters();
targetSwf.getCharacters(); // force rebuild character id cache
copyTag.setModified(true);
copiedTags.add(tag);
}
for (Integer characterId : needed) {
Tag tag = (Tag) sourceSwf.getCharacter(characterId);
if (!copiedTags.contains(tag)) {
Tag copyTag = tag.cloneTag();
copyTag.setSwf(targetSwf);
targetSwf.tags.add(copyTag);
chechUniqueCharacterId(copyTag);
targetSwf.updateCharacters();
targetSwf.getCharacters(); // force rebuild character id cache
copyTag.setModified(true);
copiedTags.add(tag);
}
@@ -511,7 +538,7 @@ public class TagTreeContextMenu extends JPopupMenu {
targetSwf.updateCharacters();
mainPanel.refreshTree(targetSwf);
} catch (IOException | InterruptedException ex) {
Logger.getLogger(TagTreeContextMenu.class.getName()).log(Level.SEVERE, null, ex);
logger.log(Level.SEVERE, null, ex);
}
}
@@ -527,7 +554,7 @@ public class TagTreeContextMenu extends JPopupMenu {
mainPanel.loadFromBinaryTag(binaryDatas);
}
private void rawEditActionPerformed(ActionEvent evt) {
TreeItem itemr = tagTree.getCurrentTreeItem();
if (itemr == null) {
@@ -536,7 +563,7 @@ public class TagTreeContextMenu extends JPopupMenu {
mainPanel.showGenericTag((Tag) itemr);
}
private void jumpToCharacterActionPerformed(ActionEvent evt) {
TreeItem itemj = tagTree.getCurrentTreeItem();
if (itemj == null || !(itemj instanceof CharacterIdTag)) {
@@ -546,7 +573,7 @@ public class TagTreeContextMenu extends JPopupMenu {
CharacterIdTag characterIdTag = (CharacterIdTag) itemj;
mainPanel.setTagTreeSelectedNode(itemj.getSwf().getCharacter(characterIdTag.getCharacterId()));
}
private void expandRecursiveActionPerformed(ActionEvent evt) {
TreePath path = tagTree.getSelectionPath();
if (path == null) {
@@ -554,7 +581,7 @@ public class TagTreeContextMenu extends JPopupMenu {
}
View.expandTreeNodes(tagTree, path, true);
}
private void removeItemActionPerformed(ActionEvent evt, boolean removeDependencies) {
List<TreeItem> sel = tagTree.getSelected(tagTree);
@@ -600,11 +627,11 @@ public class TagTreeContextMenu extends JPopupMenu {
swf.removeTags(tagsToRemoveBySwf.get(swf), removeDependencies);
}
mainPanel.refreshTree(null);
mainPanel.refreshTree();
}
}
}
private void undoTagActionPerformed(ActionEvent evt) {
List<TreeItem> sel = tagTree.getSelected(tagTree);
@@ -616,14 +643,14 @@ public class TagTreeContextMenu extends JPopupMenu {
tag.getSwf().clearAllCache();
tagTree.getModel().updateNode(item);
} catch (InterruptedException | IOException ex) {
Logger.getLogger(TagTreeContextMenu.class.getName()).log(Level.SEVERE, null, ex);
logger.log(Level.SEVERE, null, ex);
}
}
}
mainPanel.repaintTree();
}
private void closeSwfActionPerformed(ActionEvent evt) {
List<TreeItem> sel = tagTree.getSelected(tagTree);
for (TreeItem item : sel) {
@@ -633,7 +660,7 @@ public class TagTreeContextMenu extends JPopupMenu {
// embedded swf
swf.binaryData.innerSwf = null;
swf.clearTagSwfs();
mainPanel.refreshTree(null);
mainPanel.refreshTree();
} else {
Main.closeFile(swf.swfList);
}