percent during loading

This commit is contained in:
Jindra Petk
2013-01-18 21:47:04 +01:00
parent c20a1655af
commit ec29467863
7 changed files with 111 additions and 19 deletions

View File

@@ -18,7 +18,7 @@ package com.jpexs.asdec;
/**
*
* @author Jindra
* @author JPEXS
*/
public interface EventListener {

View File

@@ -139,10 +139,16 @@ public class Main {
}
public static void startWork(String name) {
startWork(name, -1);
}
public static void startWork(String name,int percent) {
working = true;
if (mainFrame != null) {
if (mainFrame.abcPanel != null) {
mainFrame.setStatus(name);
mainFrame.setStatus(name);
if(percent==-1){
mainFrame.hidePercent();
}else{
mainFrame.setPercent(percent);
}
}
/*if (actionMainFrame != null) {
@@ -150,6 +156,11 @@ public class Main {
}*/
if (loadingDialog != null) {
loadingDialog.setDetail(name);
if(percent==-1){
loadingDialog.hidePercent();
}else{
loadingDialog.setPercent(percent);
}
}
if (Main.isCommandLineMode()) {
System.out.println(name);
@@ -163,9 +174,6 @@ public class Main {
mainFrame.setStatus("");
}
}
/*if (actionMainFrame != null) {
actionMainFrame.setStatus("");
}*/
if (loadingDialog != null) {
loadingDialog.setDetail("");
}
@@ -174,7 +182,13 @@ public class Main {
public static SWF parseSWF(String file) throws Exception {
FileInputStream fis = new FileInputStream(file);
InputStream bis = new BufferedInputStream(fis);
SWF locswf = new SWF(bis);
SWF locswf = new SWF(bis, new PercentListener() {
@Override
public void percent(int p) {
startWork("Reading SWF",p);
}
});
locswf.addEventListener(new EventListener() {
public void handleEvent(String event, Object data) {
if (event.equals("export")) {

View File

@@ -0,0 +1,9 @@
package com.jpexs.asdec;
/**
*
* @author JPEXS
*/
public interface PercentListener {
public void percent(int p);
}

View File

@@ -174,13 +174,17 @@ public class SWF {
}
public SWF(InputStream is) throws IOException {
this(is, null);
}
/**
* Construct SWF from stream
*
* @param is Stream to read SWF from
* @throws IOException
*/
public SWF(InputStream is) throws IOException {
public SWF(InputStream is, PercentListener listener) throws IOException {
byte hdr[] = new byte[3];
is.read(hdr);
String shdr = new String(hdr);
@@ -188,9 +192,9 @@ public class SWF {
throw new IOException("Invalid SWF file");
}
version = is.read();
SWFInputStream sis = new SWFInputStream(is, version, 4);
SWFInputStream sis = new SWFInputStream(is, version, 4);
fileSize = sis.readUI32();
if (hdr[0] == 'C') {
sis = new SWFInputStream(new InflaterInputStream(is), version, 8);
compressed = true;
@@ -218,8 +222,10 @@ public class SWF {
}
if (listener != null) {
sis.addPercentListener(listener);
}
sis.setPercentMax(fileSize);
displayRect = sis.readRECT();
// FIXED8 (16 bit fixed point) frameRate
int tmpFirstByetOfFrameRate = sis.readUI8();

View File

@@ -52,6 +52,23 @@ public class SWFInputStream extends InputStream {
private long pos;
private int version;
private static final Logger log = Logger.getLogger(SWFInputStream.class.getName());
private List<PercentListener> listeners = new ArrayList<PercentListener>();
private long percentMax;
public void addPercentListener(PercentListener listener) {
listeners.add(listener);
}
public void removePercentListener(PercentListener listener) {
int index = listeners.indexOf(listener);
if (index > -1) {
listeners.remove(index);
}
}
public void setPercentMax(long percentMax){
this.percentMax=percentMax;
}
/**
* Constructor
@@ -92,9 +109,8 @@ public class SWFInputStream extends InputStream {
*/
@Override
public int read() throws IOException {
pos++;
bitPos = 0;
return is.read();
return readNoBitReset();
}
@Override
@@ -108,9 +124,19 @@ public class SWFInputStream extends InputStream {
private void alignByte() {
bitPos = 0;
}
private int lastPercent = -1;
private int readNoBitReset() throws IOException {
pos++;
pos++;
if(percentMax>0){
int percent = (int) (pos * 100 / percentMax);
if (lastPercent != percent) {
for (PercentListener pl : listeners) {
pl.percent(percent);
}
lastPercent = percent;
}
}
return is.read();
}

View File

@@ -24,6 +24,8 @@ import java.awt.event.WindowEvent;
import java.awt.image.ImageObserver;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;
/**
@@ -33,14 +35,26 @@ import javax.swing.SwingConstants;
*/
public class LoadingDialog extends JFrame implements ImageObserver {
private JLabel loadingLabel = new JLabel("");
private JLabel loadingLabel = new JLabel("",JLabel.CENTER);
private LoadingPanel loadingPanel;
String load = "Loading, please wait...";
JProgressBar progressBar = new JProgressBar(0,100);
public void setDetail(String d) {
loadingLabel.setText("<html><center>" + load + "<br>" + d + "</center></html>");
loadingLabel.setHorizontalAlignment( SwingConstants.CENTER );
}
public void setPercent(int percent){
progressBar.setValue(percent);
progressBar.setVisible(true);
}
public void hidePercent(){
if(progressBar.isVisible()){
progressBar.setVisible(false);
}
}
/**
* Constructor
*/
@@ -53,7 +67,17 @@ public class LoadingDialog extends JFrame implements ImageObserver {
loadingPanel = new LoadingPanel(50, 50);
loadingPanel.setPreferredSize(new Dimension(100, 100));
add(loadingPanel, BorderLayout.WEST);
add(loadingLabel, BorderLayout.CENTER);
JPanel pan=new JPanel();
pan.setLayout(null);
pan.setPreferredSize(new Dimension(120,150));
loadingLabel.setBounds(0, 20, 125, 50);
progressBar.setBounds(0, 70, 125, 25);
pan.add(loadingLabel);
pan.add(progressBar);
add(pan, BorderLayout.CENTER);
progressBar.setVisible(false);
progressBar.setStringPainted(true);
//progressBar.setVisible(false);
View.centerScreen(this);
View.setWindowIcon(this);
loadingLabel.setHorizontalAlignment(SwingConstants.LEFT);

View File

@@ -57,6 +57,7 @@ import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JTabbedPane;
import javax.swing.border.BevelBorder;
@@ -73,7 +74,19 @@ public class MainFrame extends JFrame implements ActionListener {
public LoadingPanel loadingPanel = new LoadingPanel(20, 20);
public JLabel statusLabel = new JLabel("");
public JPanel statusPanel = new JPanel();
public JProgressBar progressBar = new JProgressBar(0, 100);
public void setPercent(int percent){
progressBar.setValue(percent);
progressBar.setVisible(true);
}
public void hidePercent(){
if(progressBar.isVisible()){
progressBar.setVisible(false);
}
}
public void setStatus(String s) {
if (s.equals("")) {
loadingPanel.setVisible(false);
@@ -277,7 +290,7 @@ public class MainFrame extends JFrame implements ActionListener {
statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
statusPanel.setLayout(new BorderLayout());
statusPanel.add(loadingPanel, BorderLayout.WEST);
statusPanel.add(statusLabel, BorderLayout.CENTER);
statusPanel.add(statusLabel, BorderLayout.CENTER);
loadingPanel.setVisible(false);
add(statusPanel, BorderLayout.SOUTH);
View.centerScreen(this);