zoom, snapshot for original Flash Player too

Issue #686 disabled right click menu for original Flash Player
This commit is contained in:
Jindra Petřík
2014-09-28 19:59:39 +02:00
parent 3990e55548
commit 963919b3e8
9 changed files with 1655 additions and 1338 deletions
@@ -79,12 +79,7 @@ import javax.swing.JPanel;
public final class ImagePanel extends JPanel implements ActionListener, MediaDisplay {
static final String ACTION_SELECT_BKCOLOR = "SELECTCOLOR";
static final String ACTION_ZOOMIN = "ZOOMIN";
static final String ACTION_ZOOMOUT = "ZOOMOUT";
static final String ACTION_ZOOMFIT = "ZOOMFIT";
static final String ACTION_ZOOMNONE = "ZOOMNONE";
static final String ACTION_SNAPSHOT = "SNAPSHOT";
private Timelined timelined;
private boolean stillFrame = false;
@@ -101,12 +96,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
private int time = 0;
private int selectedDepth = -1;
private double zoom = 1.0;
private double realZoom = 1.0;
private JLabel percentLabel = new JLabel("100%");
private JPanel zoomPanel;
public static final int ZOOM_DECADE_STEPS = 10;
public static final double ZOOM_MULTIPLIER = Math.pow(10, 1.0 / ZOOM_DECADE_STEPS);
public void selectDepth(int depth) {
if (depth != selectedDepth) {
@@ -332,52 +322,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
iconPanel = new IconPanel();
//labelPan.add(label, new GridBagConstraints());
add(iconPanel, BorderLayout.CENTER);
JPanel bottomPanel = new JPanel(new BorderLayout());
JPanel buttonsPanel = new JPanel(new FlowLayout());
JButton selectColorButton = new JButton(View.getIcon("color16"));
selectColorButton.addActionListener(this);
selectColorButton.setActionCommand(ACTION_SELECT_BKCOLOR);
selectColorButton.setToolTipText(AppStrings.translate("button.selectbkcolor.hint"));
JButton zoomInButton = new JButton(View.getIcon("zoomin16"));
zoomInButton.addActionListener(this);
zoomInButton.setActionCommand(ACTION_ZOOMIN);
zoomInButton.setToolTipText(AppStrings.translate("button.zoomin.hint"));
JButton zoomOutButton = new JButton(View.getIcon("zoomout16"));
zoomOutButton.addActionListener(this);
zoomOutButton.setActionCommand(ACTION_ZOOMOUT);
zoomOutButton.setToolTipText(AppStrings.translate("button.zoomout.hint"));
JButton zoomFitButton = new JButton(View.getIcon("zoomfit16"));
zoomFitButton.addActionListener(this);
zoomFitButton.setActionCommand(ACTION_ZOOMFIT);
zoomFitButton.setToolTipText(AppStrings.translate("button.zoomfit.hint"));
JButton zoomNoneButton = new JButton(View.getIcon("zoomnone16"));
zoomNoneButton.addActionListener(this);
zoomNoneButton.setActionCommand(ACTION_ZOOMNONE);
zoomNoneButton.setToolTipText(AppStrings.translate("button.zoomnone.hint"));
JButton snapshotButton = new JButton(View.getIcon("snapshot16"));
snapshotButton.addActionListener(this);
snapshotButton.setActionCommand(ACTION_SNAPSHOT);
snapshotButton.setToolTipText(AppStrings.translate("button.snapshot.hint"));
zoomPanel = new JPanel(new FlowLayout());
updateZoom();
zoomPanel.add(percentLabel);
zoomPanel.add(zoomInButton);
zoomPanel.add(zoomOutButton);
zoomPanel.add(zoomNoneButton);
zoomPanel.add(zoomFitButton);
zoomPanel.add(selectColorButton);
buttonsPanel.add(zoomPanel);
buttonsPanel.add(snapshotButton);
bottomPanel.add(buttonsPanel, BorderLayout.EAST);
add(bottomPanel, BorderLayout.SOUTH);
add(iconPanel, BorderLayout.CENTER);
add(debugLabel, BorderLayout.NORTH);
iconPanel.addMouseListener(new MouseAdapter() {
@@ -458,116 +403,27 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
});
}
private static double roundZoom(double realZoom, int mantisa) {
double l10 = Math.log10(realZoom);
int lg = (int) (-Math.floor(l10) + mantisa - 1);
if (lg < 0) {
lg = 0;
}
BigDecimal bd = new BigDecimal(String.valueOf(realZoom)).setScale(lg, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
}
private void updateZoom() {
double pctzoom = roundZoom(realZoom * 100, 3);
String r = "" + pctzoom;
zoom = pctzoom / 100.0;
if (r.endsWith(".0")) {
r = r.substring(0, r.length() - 2);
}
percentLabel.setText("" + r + "%");
@Override
public void zoom(double zoom){
this.zoom = zoom;
drawFrame();
}
private void putImageToClipBoard(BufferedImage img) {
if (img == null) {
return;
}
TransferableImage trans = new TransferableImage(img);
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
c.setContents(trans, new ClipboardOwner() {
@Override
public void lostOwnership(Clipboard clipboard, Transferable contents) {
}
});
}
private class TransferableImage implements Transferable {
Image img;
public TransferableImage(Image img) {
this.img = img;
}
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
if (flavor.equals(DataFlavor.imageFlavor) && img != null) {
return img;
} else {
throw new UnsupportedFlavorException(flavor);
}
}
@Override
public DataFlavor[] getTransferDataFlavors() {
DataFlavor[] flavors = new DataFlavor[1];
flavors[ 0] = DataFlavor.imageFlavor;
return flavors;
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
DataFlavor[] flavors = getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++) {
if (flavor.equals(flavors[ i])) {
return true;
}
}
return false;
}
}
@Override
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand()) {
case ACTION_SELECT_BKCOLOR:
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
Color newColor = JColorChooser.showDialog(null, AppStrings.translate("dialog.selectbkcolor.title"), View.swfBackgroundColor);
if (newColor != null) {
View.swfBackgroundColor = newColor;
setBackground(newColor);
repaint();
}
}
});
break;
case ACTION_ZOOMIN:
realZoom *= ZOOM_MULTIPLIER;
updateZoom();
break;
case ACTION_ZOOMOUT:
realZoom /= ZOOM_MULTIPLIER;
updateZoom();
break;
case ACTION_ZOOMNONE:
realZoom = 1.0;
updateZoom();
break;
case ACTION_ZOOMFIT:
realZoom = zoomToFit();
updateZoom();
break;
case ACTION_SNAPSHOT:
putImageToClipBoard(iconPanel.getLastImage());
break;
}
}
private double zoomToFit() {
@Override
public BufferedImage printScreen() {
return iconPanel.getLastImage();
}
public void zoomToFit() {
if (timelined instanceof BoundedTag) {
RECT bounds = ((BoundedTag) timelined).getRect(new HashSet<BoundedTag>());
double w1 = bounds.getWidth() / SWF.unitDivisor;
@@ -585,9 +441,8 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
} else {
w = w2;
}
return (double) w / (double) w1;
}
return 1;
zoom = (double) w / (double) w1;
}
}
public void setImage(byte[] data) {
@@ -603,9 +458,15 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
} catch (IOException ex) {
Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex);
}
zoomPanel.setVisible(false);
}
@Override
public boolean zoomAvailable() {
return timelined!=null;
}
public synchronized void setTimelined(final Timelined drawable, final SWF swf, int frame) {
pause();
if (drawable instanceof ButtonTag) {
@@ -629,7 +490,6 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
}
time = 0;
play();
zoomPanel.setVisible(true);
}
public void setImage(SerializableImage image) {
@@ -642,7 +502,6 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
stillFrame = true;
iconPanel.setImg(image);
iconPanel.setOutlines(new ArrayList<DepthState>(), new ArrayList<Shape>());
zoomPanel.setVisible(false);
}
@Override
@@ -905,4 +764,16 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
public boolean isLoaded() {
return loaded;
}
@Override
public boolean screenAvailable() {
return true;
}
@Override
public double getZoom() {
return zoom;
}
}
@@ -118,7 +118,6 @@ public class PreviewPanel extends JSplitPane implements ActionListener {
private final MainPanel mainPanel;
private final JPanel viewerCards;
private PlayerControls flashControls;
private final FlashPlayerPanel flashPanel;
private File tempFile;
@@ -270,7 +269,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener {
JPanel flashPlayPanel = new JPanel(new BorderLayout());
flashPlayPanel.add(flashPanel, BorderLayout.CENTER);
JPanel bottomPanel = new JPanel(new BorderLayout());
/*JPanel bottomPanel = new JPanel(new BorderLayout());
JPanel buttonsPanel = new JPanel(new FlowLayout());
JButton selectColorButton = new JButton(View.getIcon("color16"));
selectColorButton.addActionListener(mainPanel);
@@ -279,11 +278,11 @@ public class PreviewPanel extends JSplitPane implements ActionListener {
buttonsPanel.add(selectColorButton);
bottomPanel.add(buttonsPanel, BorderLayout.EAST);
flashPlayPanel.add(bottomPanel, BorderLayout.SOUTH);
flashPlayPanel.add(bottomPanel, BorderLayout.SOUTH);*/
JPanel flashPlayPanel2 = new JPanel(new BorderLayout());
flashPlayPanel2.add(flashPlayPanel, BorderLayout.CENTER);
flashPlayPanel2.add(flashControls = new PlayerControls(flashPanel), BorderLayout.SOUTH);
flashPlayPanel2.add(new PlayerControls(flashPanel), BorderLayout.SOUTH);
leftComponent = flashPlayPanel2;
} else {
JPanel swtPanel = new JPanel(new BorderLayout());
@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.base.SoundTag;
import com.jpexs.helpers.SoundPlayer;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -190,6 +191,34 @@ public class SoundTagPlayer implements MediaDisplay {
return player.isPlaying();
}
@Override
public boolean screenAvailable() {
return false;
}
@Override
public void zoom(double zoom) {
}
@Override
public boolean zoomAvailable() {
return false;
}
@Override
public void zoomToFit() {
}
@Override
public double getZoom() {
return 0;
}
@Override
public synchronized void gotoFrame(int frame) {
pause();
@@ -216,4 +245,11 @@ public class SoundTagPlayer implements MediaDisplay {
return true;
}
@Override
public BufferedImage printScreen() {
return null;
}
}
@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.gui.player;
import com.jpexs.decompiler.flash.gui.FlashUnsupportedException;
import com.jpexs.decompiler.flash.gui.View;
import com.jpexs.helpers.CancellableWorker;
import com.jpexs.helpers.utf8.Utf8Helper;
import com.sun.jna.Native;
@@ -29,21 +30,30 @@ import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT.HANDLE;
import com.sun.jna.platform.win32.WinUser;
import com.sun.jna.ptr.IntByReference;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.image.BufferedImage;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPopupMenu;
import org.pushingpixels.substance.internal.contrib.jgoodies.looks.common.ShadowPopupFactory;
/**
*
@@ -72,11 +82,81 @@ public class FlashPlayerPanel extends Panel implements Closeable, MediaDisplay {
private static final int CMD_CALL = 11;
private static final int CMD_GETVARIABLE = 12;
private static final int CMD_SETVARIABLE = 13;
private static final int CMD_CHECKCLICK = 14;
private static final int CMD_ZOOM = 15;
private static final int PIPE_TIMEOUT_MS = 1000;
private int frameRate;
public boolean specialPlayback = false;
private boolean specialPlaying = false;
private JPopupMenu rightClickMenu = null;
private Timer rightClickTimer;
@Override
public boolean screenAvailable() {
return true;
}
@Override
public boolean zoomAvailable() {
return true;
}
@Override
public void zoomToFit() {
//TODO
}
@Override
public double getZoom() {
return 0;
}
private synchronized int checkClick(Point ret) throws IOException{
if(pipe!=null){
writeToPipe(new byte[]{CMD_CHECKCLICK});
byte res[] = new byte[1];
readFromPipe(res);
int button = res[0];
if(button>0){
res = new byte[4];
readFromPipe(res);
ret.x = ((res[0] & 0xff) << 8) + (res[1] & 0xff);
ret.y = ((res[2] & 0xff) << 8) + (res[3] & 0xff);
}
return button;
}
return 0;
}
private double zoom = 1.0;
@Override
public synchronized void zoom(double zoom){
if(pipe!=null){
try {
long zoomint = Math.round(100/(zoom/this.zoom));
if(zoom==1.0){
zoomint = 0;
}
this.zoom = zoom;
writeToPipe(new byte[]{CMD_ZOOM});
writeToPipe(new byte[]{(byte) ((zoomint >> 8) & 0xff), (byte) (zoomint & 0xff)});
} catch (IOException ex) {
//ignore
}
}
}
public synchronized String getVariable(String name) throws IOException {
if (pipe != null) {
writeToPipe(new byte[]{CMD_GETVARIABLE});
@@ -181,16 +261,22 @@ public class FlashPlayerPanel extends Panel implements Closeable, MediaDisplay {
public synchronized void setBackground(Color color) {
try {
writeToPipe(new byte[]{CMD_BGCOLOR});
writeToPipe(new byte[]{(byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()});
} catch (IOException ex) {
writeToPipe(new byte[]{(byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()});
} catch (IOException ex) {
}
}
public void setRightClickMenu(JPopupMenu menu){
rightClickMenu = menu;
}
public FlashPlayerPanel(Component frame) {
if (!Platform.isWindows()) {
throw new FlashUnsupportedException();
}
this.frame = frame;
this.frame = frame;
//this.add(rightClickMenu);
addComponentListener(new ComponentListener() {
@Override
public void componentResized(ComponentEvent e) {
@@ -263,6 +349,10 @@ public class FlashPlayerPanel extends Panel implements Closeable, MediaDisplay {
}
public synchronized void stopSWF() {
if(rightClickTimer!=null){
rightClickTimer.cancel();
rightClickTimer = null;
}
displaySWF("-", null, 1);
stopped = true;
}
@@ -271,8 +361,21 @@ public class FlashPlayerPanel extends Panel implements Closeable, MediaDisplay {
return stopped;
}
@Override
public BufferedImage printScreen() {
Point screenloc = getLocationOnScreen();
try {
return new Robot().createScreenCapture(new Rectangle(screenloc.x, screenloc.y, getWidth(), getHeight()));
} catch (AWTException ex) {
return null;
}
}
public synchronized void displaySWF(String flash, Color bgColor, int frameRate) {
try {
zoom = 1.0;
this.flash = flash;
repaint();
this.frameRate = frameRate;
@@ -292,12 +395,48 @@ public class FlashPlayerPanel extends Panel implements Closeable, MediaDisplay {
if (specialPlayback) {
play();
}
if(rightClickTimer!=null){
rightClickTimer.cancel();
}
rightClickTimer = new Timer();
rightClickTimer.schedule(new TimerTask() {
@Override
public void run() {
try {
final Point pt = new Point();
final int button = checkClick(pt);
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
if(rightClickMenu!=null){
if(button == 2){
ShadowPopupFactory.uninstall();
rightClickMenu.show(FlashPlayerPanel.this, pt.x, pt.y);
ShadowPopupFactory.install();
}
if(button == 1){
rightClickMenu.setVisible(false);
}
}
}
});
} catch (IOException ex) {
//ignore
}
}
}, 100,100);
} catch (IOException ex) {
}
}
@Override
public void close() throws IOException {
if(rightClickTimer!=null){
rightClickTimer.cancel();
rightClickTimer = null;
}
Kernel32.INSTANCE.CloseHandle(pipe);
Kernel32.INSTANCE.TerminateProcess(process, 0);
}
@@ -1,46 +1,59 @@
/*
* Copyright (C) 2010-2014 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/>.
*/
package com.jpexs.decompiler.flash.gui.player;
import java.awt.Color;
/**
*
* @author JPEXS
*/
public interface MediaDisplay {
public int getCurrentFrame();
public int getTotalFrames();
public void pause();
public void play();
public void rewind();
public boolean isPlaying();
public void gotoFrame(int frame);
public void setBackground(Color color);
public int getFrameRate();
public boolean isLoaded();
}
/*
* Copyright (C) 2010-2014 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/>.
*/
package com.jpexs.decompiler.flash.gui.player;
import java.awt.Color;
import java.awt.image.BufferedImage;
/**
*
* @author JPEXS
*/
public interface MediaDisplay {
public int getCurrentFrame();
public int getTotalFrames();
public void zoom(double zoom);
public void pause();
public void play();
public void rewind();
public boolean isPlaying();
public void gotoFrame(int frame);
public void setBackground(Color color);
public int getFrameRate();
public boolean isLoaded();
public BufferedImage printScreen();
public boolean screenAvailable();
public boolean zoomAvailable();
public void zoomToFit();
public double getZoom();
}
@@ -17,20 +17,33 @@
package com.jpexs.decompiler.flash.gui.player;
import com.jpexs.decompiler.flash.gui.AppStrings;
import com.jpexs.decompiler.flash.gui.ImagePanel;
import com.jpexs.decompiler.flash.gui.View;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
@@ -43,6 +56,12 @@ public class PlayerControls extends JPanel implements ActionListener {
static final String ACTION_PAUSE = "PAUSE";
static final String ACTION_STOP = "STOP";
static final String ACTION_SELECT_BKCOLOR = "SELECTCOLOR";
static final String ACTION_ZOOMIN = "ZOOMIN";
static final String ACTION_ZOOMOUT = "ZOOMOUT";
static final String ACTION_ZOOMFIT = "ZOOMFIT";
static final String ACTION_ZOOMNONE = "ZOOMNONE";
static final String ACTION_SNAPSHOT = "SNAPSHOT";
private final JButton pauseButton;
private boolean paused = false;
@@ -53,17 +72,78 @@ public class PlayerControls extends JPanel implements ActionListener {
private final JLabel totalTimeLabel;
private static final Icon pauseIcon = View.getIcon("pause16");
private static final Icon playIcon = View.getIcon("play16");
private JLabel percentLabel = new JLabel("100%");
private JPanel zoomPanel;
private JPanel graphicControls;
private JPanel playbackControls;
private double realZoom = 1.0;
private JButton zoomFitButton;
public static final int ZOOM_DECADE_STEPS = 10;
public static final double ZOOM_MULTIPLIER = Math.pow(10, 1.0 / ZOOM_DECADE_STEPS);
public PlayerControls(MediaDisplay display) {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
graphicControls = new JPanel(new BorderLayout());
JPanel graphicButtonsPanel = new JPanel(new FlowLayout());
JButton selectColorButton = new JButton(View.getIcon("color16"));
selectColorButton.addActionListener(this);
selectColorButton.setActionCommand(ACTION_SELECT_BKCOLOR);
selectColorButton.setToolTipText(AppStrings.translate("button.selectbkcolor.hint"));
JButton zoomInButton = new JButton(View.getIcon("zoomin16"));
zoomInButton.addActionListener(this);
zoomInButton.setActionCommand(ACTION_ZOOMIN);
zoomInButton.setToolTipText(AppStrings.translate("button.zoomin.hint"));
JButton zoomOutButton = new JButton(View.getIcon("zoomout16"));
zoomOutButton.addActionListener(this);
zoomOutButton.setActionCommand(ACTION_ZOOMOUT);
zoomOutButton.setToolTipText(AppStrings.translate("button.zoomout.hint"));
zoomFitButton = new JButton(View.getIcon("zoomfit16"));
zoomFitButton.addActionListener(this);
zoomFitButton.setActionCommand(ACTION_ZOOMFIT);
zoomFitButton.setToolTipText(AppStrings.translate("button.zoomfit.hint"));
JButton zoomNoneButton = new JButton(View.getIcon("zoomnone16"));
zoomNoneButton.addActionListener(this);
zoomNoneButton.setActionCommand(ACTION_ZOOMNONE);
zoomNoneButton.setToolTipText(AppStrings.translate("button.zoomnone.hint"));
JButton snapshotButton = new JButton(View.getIcon("snapshot16"));
snapshotButton.addActionListener(this);
snapshotButton.setActionCommand(ACTION_SNAPSHOT);
snapshotButton.setToolTipText(AppStrings.translate("button.snapshot.hint"));
zoomPanel = new JPanel(new FlowLayout());
//updateZoom();
zoomPanel.add(percentLabel);
zoomPanel.add(zoomInButton);
zoomPanel.add(zoomOutButton);
zoomPanel.add(zoomNoneButton);
zoomPanel.add(zoomFitButton);
zoomPanel.add(selectColorButton);
graphicButtonsPanel.add(zoomPanel);
graphicButtonsPanel.add(snapshotButton);
graphicControls.add(graphicButtonsPanel,BorderLayout.EAST);
add(graphicControls);
graphicControls.setVisible(display.screenAvailable());
playbackControls = new JPanel();
this.display = display;
JPanel controlPanel = new JPanel(new BorderLayout());
timeLabel = new JLabel("00:00.00");
totalTimeLabel = new JLabel("00:00.00");
controlPanel.add(timeLabel, BorderLayout.WEST);
controlPanel.add(totalTimeLabel, BorderLayout.EAST);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
JPanel buttonsPanel = new JPanel();
buttonsPanel.setLayout(new FlowLayout());
playbackControls.setLayout(new BoxLayout(playbackControls, BoxLayout.Y_AXIS));
JPanel buttonsPanel = new JPanel(new FlowLayout());
pauseButton = new JButton(AppStrings.translate("preview.pause"), pauseIcon);
pauseButton.setMargin(new Insets(0, 0, 0, 0));
@@ -93,8 +173,8 @@ public class PlayerControls extends JPanel implements ActionListener {
}
}
});
add(progress);
add(controlPanel);
playbackControls.add(progress);
playbackControls.add(controlPanel);
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
@@ -102,6 +182,7 @@ public class PlayerControls extends JPanel implements ActionListener {
update();
}
}, 100, 100);
add(playbackControls);
}
private String formatMs(long ms) {
@@ -133,7 +214,12 @@ public class PlayerControls extends JPanel implements ActionListener {
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
public void run() {
double zoom = display.getZoom();
zoomFitButton.setVisible(zoom!=0.0);
percentLabel.setVisible(zoom!=0.0);
zoomPanel.setVisible(display.zoomAvailable());
graphicControls.setVisible(display.screenAvailable());
int totalFrames = display.getTotalFrames();
int currentFrame = display.getCurrentFrame();
int frameRate = display.getFrameRate();
@@ -149,11 +235,11 @@ public class PlayerControls extends JPanel implements ActionListener {
timeLabel.setText(formatMs((currentFrame * 1000) / frameRate));
totalTimeLabel.setText(formatMs(((totalFrames - 1) * 1000) / frameRate));
}
if (totalFrames <= 1 && isVisible()) {
setVisible(false);
if (totalFrames <= 1 && playbackControls.isVisible()) {
playbackControls.setVisible(false);
}
if (totalFrames > 1 && !isVisible()) {
setVisible(true);
if (totalFrames > 1 && !playbackControls.isVisible()) {
playbackControls.setVisible(true);
}
if (display.isPlaying() == paused) {
paused = !paused;
@@ -171,6 +257,27 @@ public class PlayerControls extends JPanel implements ActionListener {
}
private static double roundZoom(double realZoom, int mantisa) {
double l10 = Math.log10(realZoom);
int lg = (int) (-Math.floor(l10) + mantisa - 1);
if (lg < 0) {
lg = 0;
}
BigDecimal bd = new BigDecimal(String.valueOf(realZoom)).setScale(lg, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
}
private void updateZoom() {
double pctzoom = roundZoom(realZoom * 100, 3);
String r = "" + pctzoom;
double zoom = pctzoom / 100.0;
if (r.endsWith(".0")) {
r = r.substring(0, r.length() - 2);
}
percentLabel.setText("" + r + "%");
display.zoom(zoom);
}
@Override
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand()) {
@@ -185,6 +292,88 @@ public class PlayerControls extends JPanel implements ActionListener {
display.pause();
display.rewind();
break;
case ACTION_SELECT_BKCOLOR:
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
Color newColor = JColorChooser.showDialog(null, AppStrings.translate("dialog.selectbkcolor.title"), View.swfBackgroundColor);
if (newColor != null) {
View.swfBackgroundColor = newColor;
display.setBackground(newColor);
}
}
});
break;
case ACTION_ZOOMIN:
realZoom *= ZOOM_MULTIPLIER;
updateZoom();
break;
case ACTION_ZOOMOUT:
realZoom /= ZOOM_MULTIPLIER;
updateZoom();
break;
case ACTION_ZOOMNONE:
realZoom = 1.0;
updateZoom();
break;
case ACTION_ZOOMFIT:
display.zoomToFit();
//updateZoom();
break;
case ACTION_SNAPSHOT:
putImageToClipBoard(display.printScreen());
break;
}
}
private class TransferableImage implements Transferable {
Image img;
public TransferableImage(Image img) {
this.img = img;
}
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
if (flavor.equals(DataFlavor.imageFlavor) && img != null) {
return img;
} else {
throw new UnsupportedFlavorException(flavor);
}
}
@Override
public DataFlavor[] getTransferDataFlavors() {
DataFlavor[] flavors = new DataFlavor[1];
flavors[ 0] = DataFlavor.imageFlavor;
return flavors;
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
DataFlavor[] flavors = getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++) {
if (flavor.equals(flavors[ i])) {
return true;
}
}
return false;
}
}
private void putImageToClipBoard(BufferedImage img) {
if (img == null) {
return;
}
TransferableImage trans = new TransferableImage(img);
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
c.setContents(trans, new ClipboardOwner() {
@Override
public void lostOwnership(Clipboard clipboard, Transferable contents) {
}
});
}
}