Fixed File did not appear modified when only header was modified

Width and Height in new File dialog instead of rect.
Unit selection.
This commit is contained in:
Jindra Petřík
2022-11-06 10:57:44 +01:00
parent 730a09f6d6
commit 40ea9175b1
7 changed files with 64 additions and 32 deletions

View File

@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- Better tag error handling - these tags now got error icon
- Show in Hex dump command from other views for tags
- Show in Taglist command from dump view for tags
- Create new empty SWF file
### Fixed
- Flash viewer - subtract blend mode
@@ -23,6 +24,7 @@ All notable changes to this project will be documented in this file.
- [#1785] AS1/2 try..catch block in for..in
- [#1770] Links in basictag info (like needed/dependent characters) were barely visible on most themes
- Show in Resource command from Hex dump not working for tags inside DefineSprite
- File did not appear modified when only header was modified
### Changed
- [#1455] All tag types are now allowed inside DefineSprite

View File

@@ -364,6 +364,8 @@ public final class SWF implements SWFContainerItem, Timelined {
private Map<String, ASMSource> asmsCache;
private Set<Integer> cyclicCharacters = null;
private boolean headerModified = false;
private static final DecompilerPool decompilerPool = new DecompilerPool();
@@ -383,6 +385,14 @@ public final class SWF implements SWFContainerItem, Timelined {
*/
public static final Color ERROR_COLOR = Color.red;
public void setHeaderModified(boolean headerModified) {
this.headerModified = headerModified;
}
public boolean isHeaderModified() {
return headerModified;
}
public void updateCharacters() {
characters = null;
characterIdTags = null;
@@ -1132,10 +1142,14 @@ public final class SWF implements SWFContainerItem, Timelined {
}
@Override
public boolean isModified() {
public boolean isModified() {
if (isModified) {
return true;
}
if (headerModified) {
return true;
}
for (Tag tag : getTags()) {
if (tag.isModified()) {

View File

@@ -45,6 +45,6 @@ public class HeaderItem implements TreeItem {
@Override
public boolean isModified() {
return false; //??
return swf.isHeaderModified();
}
}

View File

@@ -230,8 +230,10 @@ public class HeaderInfoPanel extends JPanel implements TagEditorPanel {
swf.displayRect.Xmax = (int) xMaxEditor.getModel().getValue();
swf.displayRect.Ymin = (int) yMinEditor.getModel().getValue();
swf.displayRect.Ymax = (int) yMaxEditor.getModel().getValue();
swf.setHeaderModified(true);
load(swf);
Main.getMainFrame().getPanel().repaintTree();
setEditMode(false);
}

View File

@@ -1493,6 +1493,8 @@ public class Main {
);
swf.compression = newFileDialog.getCompression();
swf.version = newFileDialog.getVersionNumber();
swf.frameRate = newFileDialog.getFrameRate();
swf.setHeaderModified(true);
Tag t;
t = new FileAttributesTag(swf);
t.setTimelined(swf);
@@ -1507,6 +1509,9 @@ public class Main {
list.add(swf);
swf.swfList = list;
mainFrame.getPanel().load(list, true);
//select first frame
mainFrame.getPanel().setTagTreeSelectedNode(mainFrame.getPanel().getCurrentTree(), swf.getTimeline().getFrame(0));
}
}

View File

@@ -50,6 +50,8 @@ public class NewFileDialog extends AppDialog {
private final JPanel compressionEditorPanel = new JPanel();
private final JComboBox<ComboBoxItem<SWFCompression>> compressionComboBox = new JComboBox<>();
private final JComboBox<String> unitComboBox = new JComboBox<>();
private final JPanel versionEditorPanel = new JPanel();
@@ -71,13 +73,9 @@ public class NewFileDialog extends AppDialog {
private final JPanel displayRectEditorPanel = new JPanel();
private final JSpinner xMinEditor = new JSpinner();
private final JSpinner xMaxEditor = new JSpinner();
private final JSpinner yMinEditor = new JSpinner();
private final JSpinner yMaxEditor = new JSpinner();
private final JSpinner widthEditor = new JSpinner();
private final JSpinner heightEditor = new JSpinner();
private final JPanel warningPanel = new JPanel();
@@ -104,7 +102,7 @@ public class NewFileDialog extends AppDialog {
TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED,
TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED,
TableLayout.PREFERRED}
}));
}));
FlowLayout layout = new FlowLayout(SwingConstants.WEST);
layout.setHgap(0);
@@ -134,20 +132,19 @@ public class NewFileDialog extends AppDialog {
frameRateEditor.setPreferredSize(new Dimension(80, frameRateEditor.getPreferredSize().height));
frameRateEditorPanel.add(frameRateEditor);
unitComboBox.addItem(translate("unit.pixels"));
unitComboBox.addItem(translate("unit.twips"));
displayRectEditorPanel.setLayout(layout);
displayRectEditorPanel.setMinimumSize(new Dimension(10, displayRectEditorPanel.getMinimumSize().height));
xMinEditor.setPreferredSize(new Dimension(80, xMinEditor.getPreferredSize().height));
xMaxEditor.setPreferredSize(new Dimension(80, xMaxEditor.getPreferredSize().height));
yMinEditor.setPreferredSize(new Dimension(80, yMinEditor.getPreferredSize().height));
yMaxEditor.setPreferredSize(new Dimension(80, yMaxEditor.getPreferredSize().height));
displayRectEditorPanel.add(xMinEditor);
displayRectEditorPanel.add(new JLabel(","));
displayRectEditorPanel.add(yMinEditor);
displayRectEditorPanel.add(new JLabel(" => "));
displayRectEditorPanel.add(xMaxEditor);
displayRectEditorPanel.add(new JLabel(","));
displayRectEditorPanel.add(yMaxEditor);
displayRectEditorPanel.add(new JLabel(" twips"));
widthEditor.setPreferredSize(new Dimension(80, widthEditor.getPreferredSize().height));
heightEditor.setPreferredSize(new Dimension(80, heightEditor.getPreferredSize().height));
displayRectEditorPanel.add(widthEditor);
displayRectEditorPanel.add(new JLabel("x"));
displayRectEditorPanel.add(heightEditor);
displayRectEditorPanel.add(unitComboBox);
warningLabel.setIcon(View.getIcon("warning16"));
warningPanel.setLayout(layout);
@@ -187,7 +184,7 @@ public class NewFileDialog extends AppDialog {
propertiesPanel.add(gfxCheckBox, "1,2");
propertiesPanel.add(new JLabel(AppStrings.translate("header.framerate")), "0,3");
propertiesPanel.add(frameRateEditorPanel, "1,3");
propertiesPanel.add(new JLabel(AppStrings.translate("header.displayrect")), "0,4");
propertiesPanel.add(new JLabel(translate("canvas.size")), "0,4");
propertiesPanel.add(displayRectEditorPanel, "1,4");
propertiesPanel.add(warningPanel, "0,5,1,5");
propertiesPanel.add(new JLabel(translate("background.color")), "0,6");
@@ -207,15 +204,16 @@ public class NewFileDialog extends AppDialog {
buttonsPanel.add(cancelButton);
cnt.add(buttonsPanel, BorderLayout.SOUTH);
//TableLayoutHelper.addTableSpaces(tl, 10);
TableLayoutHelper.addTableSpaces(tl, 4);
pack();
setResizable(false);
View.centerScreen(this);
View.setWindowIcon(this);
setModal(true);
xMaxEditor.setValue(20 * 550);
yMaxEditor.setValue(20 * 400);
widthEditor.setValue(550);
heightEditor.setValue(400);
unitComboBox.setSelectedIndex(0);
frameRateEditor.setValue(24);
compressionComboBox.setSelectedIndex(1);
versionEditor.setValue(17);
@@ -287,21 +285,25 @@ public class NewFileDialog extends AppDialog {
return gfxCheckBox.isSelected();
}
public int getFrameRate() {
return (int) ((Number) (frameRateEditor.getModel().getValue())).floatValue();
public float getFrameRate() {
return ((Number) (frameRateEditor.getModel().getValue())).floatValue();
}
public int getXMin() {
return (int) xMinEditor.getModel().getValue();
return 0;
}
public int getXMax() {
return (int) xMaxEditor.getModel().getValue();
return getUnitMultiplier() * (int) widthEditor.getModel().getValue();
}
public int getYMin() {
return (int) yMinEditor.getModel().getValue();
return 0;
}
public int getYmax() {
return (int) yMaxEditor.getModel().getValue();
return getUnitMultiplier() * (int)heightEditor.getModel().getValue();
}
private int getUnitMultiplier() {
return unitComboBox.getSelectedIndex() == 0 ? 20 : 1;
}
public Color getBackgroundColor() {

View File

@@ -16,3 +16,10 @@
dialog.title = New file
background.color = Background color:
width = Width
height = Height
unit.pixels = Pixels
unit.twips = Twips
canvas.size = Canvas size: