Simple editor - fixed timeline offset

This commit is contained in:
Jindra Petřík
2025-05-22 19:49:10 +02:00
parent 16700bcaca
commit 31c8715fd3
3 changed files with 56 additions and 47 deletions
@@ -48,10 +48,14 @@ public class TimelineDepthPanel extends JPanel {
maxDepth = timeline == null ? 0 : timeline.getMaxDepth();
String maxDepthStr = Integer.toString(maxDepth);
setFont(getFont().deriveFont(FONT_SIZE));
int yofs = TimelineBodyPanel.FRAME_HEIGHT - (scrollOffset % TimelineBodyPanel.FRAME_HEIGHT);
int height = yofs + maxDepth * TimelineBodyPanel.FRAME_HEIGHT + 1;
int maxDepthW = getFontMetrics(getFont()).stringWidth(maxDepthStr);
Dimension dim = new Dimension(maxDepthW + 2 * PADDING, Integer.MAX_VALUE);
Dimension dim = new Dimension(maxDepthW + 2 * PADDING, height);
setSize(dim);
setPreferredSize(dim);
setMinimumSize(new Dimension(maxDepthW + 2 * PADDING, 0));
revalidate();
}
public void scroll(int offset) {
@@ -20,9 +20,9 @@ import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.gui.FasterScrollPane;
import com.jpexs.decompiler.flash.timeline.Timeline;
import com.jpexs.decompiler.flash.timeline.Timelined;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.SystemColor;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
@@ -48,22 +48,22 @@ public class TimelinePanel extends JPanel {
private Timeline timeline;
private Timelined timelined;
public static final int FRAME_WIDTH = 8;
public static final int FRAME_HEIGHT = 18;
private JScrollPane timelineBodyScrollPane;
private final JScrollPane timelineBodyScrollPane;
public TimelinePanel(EasySwfPanel swfPanel, UndoManager undoManager) {
timelineBodyPanel = new TimelineBodyPanel(swfPanel, undoManager);
setLayout(new BorderLayout());
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
timelineBodyScrollPane = new FasterScrollPane(timelineBodyPanel);
depthPanel = new TimelineDepthPanel();
timelineBodyPanel.addChangeListener(new Runnable() {
@Override
public void run() {
@@ -73,23 +73,29 @@ public class TimelinePanel extends JPanel {
}
});
timePanel = new TimelineTimePanel();
timePanel = new TimelineTimePanel(depthPanel);
JPanel row1Panel = new JPanel();
row1Panel.setLayout(new BorderLayout());
JPanel sepPanel = new JPanel();
sepPanel.setBackground(getBackgroundColor());
sepPanel.setPreferredSize(new Dimension(depthPanel.getWidth(), timePanel.getHeight()));
row1Panel.add(sepPanel, BorderLayout.WEST);
row1Panel.add(timePanel, BorderLayout.CENTER);
gbc.anchor = GridBagConstraints.LINE_START;
gbc.gridx = 1;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1;
add(timePanel, gbc);
JPanel row2Panel = new JPanel();
row2Panel.setLayout(new BorderLayout());
row2Panel.add(depthPanel, BorderLayout.WEST);
row2Panel.add(timelineBodyScrollPane, BorderLayout.CENTER);
gbc.anchor = GridBagConstraints.FIRST_LINE_START;
gbc.gridx = 0;
gbc.gridy++;
gbc.fill = GridBagConstraints.VERTICAL;
gbc.weightx = 0;
gbc.weighty = 1;
add(depthPanel, gbc);
add(row1Panel, BorderLayout.NORTH);
add(row2Panel, BorderLayout.CENTER);
gbc.anchor = GridBagConstraints.FIRST_LINE_START;
gbc.gridx++;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1;
gbc.weighty = 1;
add(timelineBodyScrollPane, gbc);
timelineBodyScrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {
@Override
@@ -122,13 +128,13 @@ public class TimelinePanel extends JPanel {
}
});
}
public static Color getBackgroundColor() {
if (Configuration.useRibbonInterface.get()) {
return SubstanceLookAndFeel.getCurrentSkin().getColorScheme(DecorationAreaType.GENERAL, ColorSchemeAssociationKind.FILL, ComponentState.ENABLED).getBackgroundFillColor();
} else {
return SystemColor.control;
}
}
}
public Timeline getTimeline() {
@@ -146,31 +152,31 @@ public class TimelinePanel extends JPanel {
public void setDepth(int depth) {
timelineBodyPanel.depthSelect(depth);
}
public void setDepths(List<Integer> depths) {
timelineBodyPanel.depthsSelect(depths);
}
public void setFrame(int frame, int depth) {
timelineBodyPanel.frameSelect(frame, depth);
}
public void setFrame(int frame, List<Integer> depths) {
timelineBodyPanel.frameSelect(frame, depths);
}
public void refresh() {
timelineBodyPanel.refresh();
}
public void addChangeListener(Runnable l) {
timelineBodyPanel.addChangeListener(l);
}
public void removeChangeListener(Runnable l) {
timelineBodyPanel.removeChangeListener(l);
}
public void setTimelined(Timelined timelined) {
this.timelined = timelined;
if (timelined == null) {
@@ -182,6 +188,6 @@ public class TimelinePanel extends JPanel {
depthPanel.setTimeline(timelined.getTimeline());
timePanel.setTimeline(timelined.getTimeline());
timelineBodyPanel.frameSelect(0, 0);
}
}
}
}
@@ -33,38 +33,37 @@ import javax.swing.JPanel;
*/
public class TimelineTimePanel extends JPanel implements MouseListener {
public static final Color borderColor = Color.black;
public static final Color BORDER_COLOR = Color.black;
public static final int lineLength = 3;
public static final int LINE_LENGTH = 3;
public static final int lineTextSpace = 3;
public static final int LINE_TEXT_SPACE = 3;
public static final Color fontColor = Color.black;
public static final Color FONT_COLOR = Color.black;
public float fontSize = 10.0f;
private int scrollOffset = 0;
private int selectedFrame = -1;
private int leftPos = 0;
private Timeline timeline;
private final List<FrameSelectionListener> listeners = new ArrayList<>();
private final TimelineDepthPanel depthPanel;
public TimelineTimePanel() {
public TimelineTimePanel(TimelineDepthPanel depthPanel) {
Dimension dim = new Dimension(Integer.MAX_VALUE, TimelineBodyPanel.FRAME_HEIGHT);
setSize(dim);
setPreferredSize(dim);
setMinimumSize(new Dimension(0, TimelineBodyPanel.FRAME_HEIGHT));
addMouseListener(this);
this.depthPanel = depthPanel;
}
public void setTimeline(Timeline timeline) {
int maxDepth = timeline == null ? 0 : timeline.getMaxDepth();
String maxDepthStr = Integer.toString(maxDepth);
setFont(getFont().deriveFont(TimelineDepthPanel.FONT_SIZE));
int maxDepthW = getFontMetrics(getFont()).stringWidth(maxDepthStr);
leftPos = maxDepthW + 2 * TimelineDepthPanel.PADDING;
this.timeline = timeline;
}
@@ -98,10 +97,10 @@ public class TimelineTimePanel extends JPanel implements MouseListener {
int end_f = (scrollOffset + clip.x + clip.width) / frameWidth;
g.setColor(TimelineBodyPanel.getBackgroundColor());
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(borderColor);
g.setColor(BORDER_COLOR);
int xofs = -scrollOffset % frameWidth;
for (int f = 0; f <= end_f; f++) {
g.drawLine(xofs + f * frameWidth + 1, TimelineBodyPanel.FRAME_HEIGHT - 1, xofs + f * frameWidth + 1, TimelineBodyPanel.FRAME_HEIGHT - lineLength);
g.drawLine(xofs + f * frameWidth + 1, TimelineBodyPanel.FRAME_HEIGHT - 1, xofs + f * frameWidth + 1, TimelineBodyPanel.FRAME_HEIGHT - LINE_LENGTH);
}
g.setFont(g.getFont().deriveFont(fontSize));
for (int f = 0; f <= end_f; f++) {
@@ -112,7 +111,7 @@ public class TimelineTimePanel extends JPanel implements MouseListener {
g.setColor(TimelineBodyPanel.SELECTED_BORDER_COLOR);
g.drawRect(xofs + f * frameWidth + 1, 0, frameWidth, TimelineBodyPanel.FRAME_HEIGHT - 1);
}
g.setColor(fontColor);
g.setColor(FONT_COLOR);
if (timeline != null && timeline.timelined instanceof ButtonTag) {
if (f < 5) {
@@ -132,13 +131,13 @@ public class TimelineTimePanel extends JPanel implements MouseListener {
break;
}
int w = g.getFontMetrics().stringWidth(timeStr);
g.drawString(timeStr, xofs + f * frameWidth + frameWidth / 2 - w / 2 + 1, TimelineBodyPanel.FRAME_HEIGHT - lineLength - lineTextSpace);
g.drawString(timeStr, xofs + f * frameWidth + frameWidth / 2 - w / 2 + 1, TimelineBodyPanel.FRAME_HEIGHT - LINE_LENGTH - LINE_TEXT_SPACE);
}
} else {
if ((cur_f + 1) % 5 == 0 || cur_f == 0) {
String timeStr = Integer.toString(cur_f + 1);
int w = g.getFontMetrics().stringWidth(timeStr);
g.drawString(timeStr, xofs + f * frameWidth + frameWidth / 2 - w / 2 + 1, TimelineBodyPanel.FRAME_HEIGHT - lineLength - lineTextSpace);
g.drawString(timeStr, xofs + f * frameWidth + frameWidth / 2 - w / 2 + 1, TimelineBodyPanel.FRAME_HEIGHT - LINE_LENGTH - LINE_TEXT_SPACE);
}
}
}