|
|
|
@ -7,11 +7,9 @@ import com.fr.design.mainframe.share.ui.online.CarouselStateManger;
|
|
|
|
|
import com.fr.design.mainframe.share.ui.widgetfilter.FilterPane; |
|
|
|
|
import com.fr.form.share.base.DataLoad; |
|
|
|
|
import com.fr.form.share.bean.OnlineShareWidget; |
|
|
|
|
import com.fr.form.share.constants.ShareComponentConstants; |
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
import com.fr.form.share.exception.NetWorkFailedException; |
|
|
|
|
import com.fr.general.http.HttpClient; |
|
|
|
|
import com.fr.module.ModuleContext; |
|
|
|
|
import com.fr.stable.EncodeConstants; |
|
|
|
|
import com.fr.third.springframework.web.util.UriUtils; |
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
|
import javax.swing.JPanel; |
|
|
|
@ -24,7 +22,8 @@ import java.awt.Rectangle;
|
|
|
|
|
import java.awt.event.AWTEventListener; |
|
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.net.URL; |
|
|
|
|
import java.net.HttpURLConnection; |
|
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
|
import java.util.concurrent.ScheduledExecutorService; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
@ -34,10 +33,12 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
*/ |
|
|
|
|
public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane { |
|
|
|
|
private static final String CAROUSEL_PREVIEW = "carousel_preview"; |
|
|
|
|
private static final int CAROUSE_IMAGE_LOAD_TIMEOUT = 2000; |
|
|
|
|
private OnlineShareWidget[] showWidgets; |
|
|
|
|
|
|
|
|
|
private PreviewDialog previewDialog; |
|
|
|
|
private JPanel widgetPane; |
|
|
|
|
private final CountDownLatch countDownLatch = new CountDownLatch(1); |
|
|
|
|
|
|
|
|
|
private final AWTEventListener awtEventListener; |
|
|
|
|
|
|
|
|
@ -82,11 +83,11 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane
|
|
|
|
|
|
|
|
|
|
protected void fireAfterDataLoad() { |
|
|
|
|
super.fireAfterDataLoad(); |
|
|
|
|
CarouselStateManger.getInstance().countDown(); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void animate() throws InterruptedException { |
|
|
|
|
CarouselStateManger.getInstance().countDownLatchAwait(); |
|
|
|
|
countDownLatch.await(); |
|
|
|
|
AtomicInteger integer = new AtomicInteger(showWidgets.length - 1); |
|
|
|
|
showCurrentLoadBlock(integer, widgetPane); |
|
|
|
|
this.repaint(); |
|
|
|
@ -94,6 +95,22 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane
|
|
|
|
|
previewDialog.setVisible(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Image getPreviewImage(String url) throws NetWorkFailedException { |
|
|
|
|
HttpClient httpClient = new HttpClient(url); |
|
|
|
|
httpClient.setTimeout(CAROUSE_IMAGE_LOAD_TIMEOUT); |
|
|
|
|
httpClient.asGet(); |
|
|
|
|
int responseCode = httpClient.getResponseCode(); |
|
|
|
|
if (responseCode != HttpURLConnection.HTTP_OK) { |
|
|
|
|
throw new NetWorkFailedException(); |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
return ImageIO.read(httpClient.getResponseStream()); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
throw new NetWorkFailedException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void showCurrentLoadBlock(AtomicInteger integer, JPanel widgetPane) { |
|
|
|
|
ScheduledExecutorService service = createToastScheduleExecutorService(); |
|
|
|
|
OnlineShareWidget shareWidget = showWidgets[integer.get()]; |
|
|
|
@ -101,7 +118,13 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane
|
|
|
|
|
this.doLayout(); |
|
|
|
|
this.validate(); |
|
|
|
|
this.repaint(); |
|
|
|
|
previewDialog.setImage(getPreviewImage(shareWidget), widgetPane.getLocationOnScreen()); |
|
|
|
|
try { |
|
|
|
|
previewDialog.setImage(getPreviewImage(shareWidget.getPicPath()), widgetPane.getLocationOnScreen()); |
|
|
|
|
} catch (NetWorkFailedException e) { |
|
|
|
|
this.stopCarouse(integer, false); |
|
|
|
|
this.switchPane(PaneStatue.DISCONNECTED); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
//展示弹出框
|
|
|
|
|
service.schedule(new Runnable() { |
|
|
|
|
@Override |
|
|
|
@ -146,11 +169,18 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void stopCarouse(AtomicInteger integer) { |
|
|
|
|
this.stopCarouse(integer, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void stopCarouse(AtomicInteger integer, boolean showExtra) { |
|
|
|
|
previewDialog.setVisible(false); |
|
|
|
|
loadRestShowWidgets(integer.get() - 1); |
|
|
|
|
if (showExtra) { |
|
|
|
|
loadRestShowWidgets(integer.get() - 1); |
|
|
|
|
} |
|
|
|
|
java.awt.Toolkit.getDefaultToolkit().removeAWTEventListener(awtEventListener); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void loadRestShowWidgets(int startIndex) { |
|
|
|
|
for (int i = startIndex; i >= 0; i--) { |
|
|
|
|
OnlineShareWidget shareWidget = showWidgets[i]; |
|
|
|
@ -161,15 +191,6 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane
|
|
|
|
|
this.repaint(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Image getPreviewImage(OnlineShareWidget widget) { |
|
|
|
|
try { |
|
|
|
|
return ImageIO.read(new URL(UriUtils.encodePath(widget.getPicPath(), EncodeConstants.ENCODING_UTF_8))); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
return ShareComponentConstants.DEFAULT_COVER; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ScheduledExecutorService createToastScheduleExecutorService() { |
|
|
|
|
return ModuleContext.getExecutor().newSingleThreadScheduledExecutor(new NamedThreadFactory(CAROUSEL_PREVIEW)); |
|
|
|
|
} |
|
|
|
|