|
|
@ -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.design.mainframe.share.ui.widgetfilter.FilterPane; |
|
|
|
import com.fr.form.share.base.DataLoad; |
|
|
|
import com.fr.form.share.base.DataLoad; |
|
|
|
import com.fr.form.share.bean.OnlineShareWidget; |
|
|
|
import com.fr.form.share.bean.OnlineShareWidget; |
|
|
|
import com.fr.form.share.constants.ShareComponentConstants; |
|
|
|
import com.fr.form.share.exception.NetWorkFailedException; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.general.http.HttpClient; |
|
|
|
import com.fr.module.ModuleContext; |
|
|
|
import com.fr.module.ModuleContext; |
|
|
|
import com.fr.stable.EncodeConstants; |
|
|
|
|
|
|
|
import com.fr.third.springframework.web.util.UriUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
import javax.imageio.ImageIO; |
|
|
|
import javax.swing.JPanel; |
|
|
|
import javax.swing.JPanel; |
|
|
@ -24,7 +22,8 @@ import java.awt.Rectangle; |
|
|
|
import java.awt.event.AWTEventListener; |
|
|
|
import java.awt.event.AWTEventListener; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.io.IOException; |
|
|
|
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.ScheduledExecutorService; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
@ -34,10 +33,12 @@ import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane { |
|
|
|
public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane { |
|
|
|
private static final String CAROUSEL_PREVIEW = "carousel_preview"; |
|
|
|
private static final String CAROUSEL_PREVIEW = "carousel_preview"; |
|
|
|
|
|
|
|
private static final int CAROUSE_IMAGE_LOAD_TIMEOUT = 2000; |
|
|
|
private OnlineShareWidget[] showWidgets; |
|
|
|
private OnlineShareWidget[] showWidgets; |
|
|
|
|
|
|
|
|
|
|
|
private PreviewDialog previewDialog; |
|
|
|
private PreviewDialog previewDialog; |
|
|
|
private JPanel widgetPane; |
|
|
|
private JPanel widgetPane; |
|
|
|
|
|
|
|
private final CountDownLatch countDownLatch = new CountDownLatch(1); |
|
|
|
|
|
|
|
|
|
|
|
private final AWTEventListener awtEventListener; |
|
|
|
private final AWTEventListener awtEventListener; |
|
|
|
|
|
|
|
|
|
|
@ -46,13 +47,18 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane |
|
|
|
awtEventListener = event -> { |
|
|
|
awtEventListener = event -> { |
|
|
|
if (event instanceof MouseEvent) { |
|
|
|
if (event instanceof MouseEvent) { |
|
|
|
if (((MouseEvent) event).getClickCount() > 0) { |
|
|
|
if (((MouseEvent) event).getClickCount() > 0) { |
|
|
|
Point selectPanePoint = OnlineEmbedFilterSelectPane.this.getLocationOnScreen(); |
|
|
|
try { |
|
|
|
Dimension selectPaneDimension = OnlineEmbedFilterSelectPane.this.getSize(); |
|
|
|
Point selectPanePoint = OnlineEmbedFilterSelectPane.this.getLocationOnScreen(); |
|
|
|
Rectangle selectPaneRec = new Rectangle(selectPanePoint.x, selectPanePoint.y, selectPaneDimension.width, selectPaneDimension.height); |
|
|
|
Dimension selectPaneDimension = OnlineEmbedFilterSelectPane.this.getSize(); |
|
|
|
if (CarouselStateManger.getInstance().running() && |
|
|
|
Rectangle selectPaneRec = new Rectangle(selectPanePoint.x, selectPanePoint.y, selectPaneDimension.width, selectPaneDimension.height); |
|
|
|
!selectPaneRec.contains(((MouseEvent) event).getLocationOnScreen())) { |
|
|
|
if (CarouselStateManger.getInstance().running() && |
|
|
|
CarouselStateManger.getInstance().stop(); |
|
|
|
!selectPaneRec.contains(((MouseEvent) event).getLocationOnScreen())) { |
|
|
|
|
|
|
|
CarouselStateManger.getInstance().stop(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
//忽略
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -77,17 +83,34 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane |
|
|
|
|
|
|
|
|
|
|
|
protected void fireAfterDataLoad() { |
|
|
|
protected void fireAfterDataLoad() { |
|
|
|
super.fireAfterDataLoad(); |
|
|
|
super.fireAfterDataLoad(); |
|
|
|
CarouselStateManger.getInstance().countDown(); |
|
|
|
countDownLatch.countDown(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void animate() throws InterruptedException { |
|
|
|
public void animate() throws InterruptedException { |
|
|
|
CarouselStateManger.getInstance().countDownLatchAwait(); |
|
|
|
countDownLatch.await(); |
|
|
|
AtomicInteger integer = new AtomicInteger(showWidgets.length-1); |
|
|
|
AtomicInteger integer = new AtomicInteger(showWidgets.length - 1); |
|
|
|
showCurrentLoadBlock(integer, widgetPane); |
|
|
|
showCurrentLoadBlock(integer, widgetPane); |
|
|
|
this.repaint(); |
|
|
|
this.repaint(); |
|
|
|
|
|
|
|
CarouselStateManger.getInstance().start(); |
|
|
|
previewDialog.setVisible(true); |
|
|
|
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) { |
|
|
|
private void showCurrentLoadBlock(AtomicInteger integer, JPanel widgetPane) { |
|
|
|
ScheduledExecutorService service = createToastScheduleExecutorService(); |
|
|
|
ScheduledExecutorService service = createToastScheduleExecutorService(); |
|
|
|
OnlineShareWidget shareWidget = showWidgets[integer.get()]; |
|
|
|
OnlineShareWidget shareWidget = showWidgets[integer.get()]; |
|
|
@ -95,7 +118,13 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane |
|
|
|
this.doLayout(); |
|
|
|
this.doLayout(); |
|
|
|
this.validate(); |
|
|
|
this.validate(); |
|
|
|
this.repaint(); |
|
|
|
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() { |
|
|
|
service.schedule(new Runnable() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -114,6 +143,7 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane |
|
|
|
if (!CarouselStateManger.getInstance().isSuspend()) { |
|
|
|
if (!CarouselStateManger.getInstance().isSuspend()) { |
|
|
|
showCurrentLoadBlock(integer, widgetPane); |
|
|
|
showCurrentLoadBlock(integer, widgetPane); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
previewDialog.setVisible(false); |
|
|
|
pollingCarouselState(integer, widgetPane); |
|
|
|
pollingCarouselState(integer, widgetPane); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -130,6 +160,7 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!CarouselStateManger.getInstance().isSuspend()) { |
|
|
|
if (!CarouselStateManger.getInstance().isSuspend()) { |
|
|
|
|
|
|
|
previewDialog.setVisible(true); |
|
|
|
showCurrentLoadBlock(integer, widgetPane); |
|
|
|
showCurrentLoadBlock(integer, widgetPane); |
|
|
|
service.shutdown(); |
|
|
|
service.shutdown(); |
|
|
|
} |
|
|
|
} |
|
|
@ -138,11 +169,18 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void stopCarouse(AtomicInteger integer) { |
|
|
|
private void stopCarouse(AtomicInteger integer) { |
|
|
|
|
|
|
|
this.stopCarouse(integer, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void stopCarouse(AtomicInteger integer, boolean showExtra) { |
|
|
|
previewDialog.setVisible(false); |
|
|
|
previewDialog.setVisible(false); |
|
|
|
loadRestShowWidgets(integer.get() - 1); |
|
|
|
if (showExtra) { |
|
|
|
|
|
|
|
loadRestShowWidgets(integer.get() - 1); |
|
|
|
|
|
|
|
} |
|
|
|
java.awt.Toolkit.getDefaultToolkit().removeAWTEventListener(awtEventListener); |
|
|
|
java.awt.Toolkit.getDefaultToolkit().removeAWTEventListener(awtEventListener); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void loadRestShowWidgets(int startIndex) { |
|
|
|
private void loadRestShowWidgets(int startIndex) { |
|
|
|
for (int i = startIndex; i >= 0; i--) { |
|
|
|
for (int i = startIndex; i >= 0; i--) { |
|
|
|
OnlineShareWidget shareWidget = showWidgets[i]; |
|
|
|
OnlineShareWidget shareWidget = showWidgets[i]; |
|
|
@ -153,15 +191,6 @@ public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane |
|
|
|
this.repaint(); |
|
|
|
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() { |
|
|
|
private ScheduledExecutorService createToastScheduleExecutorService() { |
|
|
|
return ModuleContext.getExecutor().newSingleThreadScheduledExecutor(new NamedThreadFactory(CAROUSEL_PREVIEW)); |
|
|
|
return ModuleContext.getExecutor().newSingleThreadScheduledExecutor(new NamedThreadFactory(CAROUSEL_PREVIEW)); |
|
|
|
} |
|
|
|
} |
|
|
|