Browse Source

REPORT-62623 && REPORT-62399 && REPORT-62547 && REPORT-62626 && REPORT-62400 && REPORT-62542 && REPORT-62544

feature/x
kerry 3 years ago
parent
commit
fd7a89abd3
  1. 12
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/CarouselStateManger.java
  2. 57
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/embed/OnlineEmbedFilterSelectPane.java

12
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/CarouselStateManger.java

@ -4,14 +4,11 @@ package com.fr.design.mainframe.share.ui.online;
import com.fr.general.ComparatorUtils;
import com.fr.stable.StringUtils;
import java.util.concurrent.CountDownLatch;
/**
* Created by kerry on 2021/10/22
*/
public class CarouselStateManger {
private static final String START_CAROUSEL ="START_CAROUSEL";
public static final String RIGHT_CLICK ="RIGHT_CLICK";
public static final String DOWNLOAD_COMPONENT ="DOWNLOAD_COMPONENT";
public static final String FIRST_DRAG_ANIMATE ="FIRST_DRAG_ANIMATE";
@ -19,7 +16,6 @@ public class CarouselStateManger {
private CarouseState state;
private final CountDownLatch countDownLatch = new CountDownLatch(1);
private String suspendEvent;
@ -36,14 +32,6 @@ public class CarouselStateManger {
}
public void countDown() {
countDownLatch.countDown();
}
public void countDownLatchAwait() throws InterruptedException {
countDownLatch.await();
}
public void start() {
this.state = CarouseState.RUNNING;
}

57
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/embed/OnlineEmbedFilterSelectPane.java

@ -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));
}

Loading…
Cancel
Save