|
|
|
@ -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; |
|
|
|
|
|
|
|
|
@ -46,6 +47,7 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane
|
|
|
|
|
awtEventListener = event -> { |
|
|
|
|
if (event instanceof MouseEvent) { |
|
|
|
|
if (((MouseEvent) event).getClickCount() > 0) { |
|
|
|
|
try { |
|
|
|
|
Point selectPanePoint = OnlineEmbedFilterSelectPane.this.getLocationOnScreen(); |
|
|
|
|
Dimension selectPaneDimension = OnlineEmbedFilterSelectPane.this.getSize(); |
|
|
|
|
Rectangle selectPaneRec = new Rectangle(selectPanePoint.x, selectPanePoint.y, selectPaneDimension.width, selectPaneDimension.height); |
|
|
|
@ -53,6 +55,10 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane
|
|
|
|
|
!selectPaneRec.contains(((MouseEvent) event).getLocationOnScreen())) { |
|
|
|
|
CarouselStateManger.getInstance().stop(); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
//忽略
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
@ -77,17 +83,34 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane
|
|
|
|
|
|
|
|
|
|
protected void fireAfterDataLoad() { |
|
|
|
|
super.fireAfterDataLoad(); |
|
|
|
|
CarouselStateManger.getInstance().countDown(); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void animate() throws InterruptedException { |
|
|
|
|
CarouselStateManger.getInstance().countDownLatchAwait(); |
|
|
|
|
AtomicInteger integer = new AtomicInteger(showWidgets.length-1); |
|
|
|
|
countDownLatch.await(); |
|
|
|
|
AtomicInteger integer = new AtomicInteger(showWidgets.length - 1); |
|
|
|
|
showCurrentLoadBlock(integer, widgetPane); |
|
|
|
|
this.repaint(); |
|
|
|
|
CarouselStateManger.getInstance().start(); |
|
|
|
|
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()]; |
|
|
|
@ -95,7 +118,13 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane
|
|
|
|
|
this.doLayout(); |
|
|
|
|
this.validate(); |
|
|
|
|
this.repaint(); |
|
|
|
|
previewDialog.setImage(getPreviewImage(shareWidget)); |
|
|
|
|
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 |
|
|
|
@ -114,6 +143,7 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane
|
|
|
|
|
if (!CarouselStateManger.getInstance().isSuspend()) { |
|
|
|
|
showCurrentLoadBlock(integer, widgetPane); |
|
|
|
|
} else { |
|
|
|
|
previewDialog.setVisible(false); |
|
|
|
|
pollingCarouselState(integer, widgetPane); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -130,6 +160,7 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (!CarouselStateManger.getInstance().isSuspend()) { |
|
|
|
|
previewDialog.setVisible(true); |
|
|
|
|
showCurrentLoadBlock(integer, widgetPane); |
|
|
|
|
service.shutdown(); |
|
|
|
|
} |
|
|
|
@ -138,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); |
|
|
|
|
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]; |
|
|
|
@ -153,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)); |
|
|
|
|
} |
|
|
|
|