Browse Source

REPORT-70456 无封面图的运营文档获取报错

feature/x
hades 2 years ago
parent
commit
5971e699ef
  1. 20
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/ProductNewsContentCellRender.java
  2. 20
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/ProductNewsImagePanel.java
  3. 15
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ProductNewsSearchManager.java

20
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/ProductNewsContentCellRender.java

@ -1,6 +1,5 @@
package com.fr.design.mainframe.alphafine.component; package com.fr.design.mainframe.alphafine.component;
import com.fr.design.DesignerEnvManager;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.AlphaFineUtil; import com.fr.design.mainframe.alphafine.AlphaFineUtil;
@ -28,6 +27,21 @@ public class ProductNewsContentCellRender implements ListCellRenderer<Object> {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd"); private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd");
/**
* 透明灰色背景 Y方向偏移
*/
private static final int GRAY_BACKGROUND_Y_GAP = 39;
/**
* 透明灰色背景 高度
*/
private static final int GRAY_BACKGROUND_HEIGHT = 23;
/**
* 单行产品动态的高度与宽度尺寸
*/
private static final Dimension DEFAULT_DIMENSION = new Dimension(500, 100);
private String[] segmentationResult; private String[] segmentationResult;
public ProductNewsContentCellRender(String[] segmentationResult) { public ProductNewsContentCellRender(String[] segmentationResult) {
@ -58,7 +72,7 @@ public class ProductNewsContentCellRender implements ListCellRenderer<Object> {
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
g.setColor(AlphaFineConstants.BACKGROUND_COLOR); g.setColor(AlphaFineConstants.BACKGROUND_COLOR);
g.fillRect(0, getHeight() - 27, getWidth(), 23); g.fillRect(0, getHeight() - GRAY_BACKGROUND_Y_GAP, getWidth(), GRAY_BACKGROUND_HEIGHT);
super.paintComponent(g); super.paintComponent(g);
} }
}; };
@ -73,7 +87,7 @@ public class ProductNewsContentCellRender implements ListCellRenderer<Object> {
textPane.setBackground(Color.WHITE); textPane.setBackground(Color.WHITE);
textPane.add(infoPane, BorderLayout.CENTER); textPane.add(infoPane, BorderLayout.CENTER);
panel.add(textPane, BorderLayout.CENTER); panel.add(textPane, BorderLayout.CENTER);
panel.setPreferredSize(new Dimension(500, 80)); panel.setPreferredSize(DEFAULT_DIMENSION);
return panel; return panel;
} }
} }

20
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/ProductNewsImagePanel.java

@ -3,11 +3,7 @@ package com.fr.design.mainframe.alphafine.component;
import com.fr.base.GraphHelper; import com.fr.base.GraphHelper;
import com.fr.base.svg.SVGLoader; import com.fr.base.svg.SVGLoader;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.constants.UIConstants;
import com.fr.design.mainframe.alphafine.model.ProductNews; import com.fr.design.mainframe.alphafine.model.ProductNews;
import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory;
import java.awt.AlphaComposite;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
@ -15,7 +11,6 @@ import java.awt.Graphics2D;
import java.awt.Image; import java.awt.Image;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.geom.RoundRectangle2D;
import java.util.Set; import java.util.Set;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -32,6 +27,8 @@ public class ProductNewsImagePanel extends JPanel {
private static final Color BACKGROUND_COLOR = new Color(116, 181, 249); private static final Color BACKGROUND_COLOR = new Color(116, 181, 249);
private static final Color COVER_COLOR = new Color(116, 181, 249, 26);
private ProductNews productNews; private ProductNews productNews;
private int width = 200; private int width = 200;
@ -48,17 +45,20 @@ public class ProductNewsImagePanel extends JPanel {
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
// g2.setComposite(AlphaComposite.Src); Color defaultColor = g2.getColor();
// g2.fill(new RoundRectangle2D.Float(0, 0, getWidth(), getHeight(), 5, 5));
// g2.setComposite(AlphaComposite.SrcAtop);
g2.drawImage(productNews.getImage(), 0, 0, getWidth(), getHeight(), this); Image image = productNews.getImage();
if (image != null) {
g2.drawImage(productNews.getImage(), 0, 0, getWidth(), getHeight(), this);
} else {
g2.setColor(COVER_COLOR);
g2.fillRect(0, 0, getWidth(), getHeight());
}
Set<Long> readSet = DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().getReadSet(); Set<Long> readSet = DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().getReadSet();
if (!readSet.contains(productNews.getId())) { if (!readSet.contains(productNews.getId())) {
g2.drawImage(NEW_TIP_IMAGE, 0, 0, this); g2.drawImage(NEW_TIP_IMAGE, 0, 0, this);
} }
Color defaultColor = g2.getColor();
g2.setColor(BACKGROUND_COLOR); g2.setColor(BACKGROUND_COLOR);
g2.fillRect(0, getHeight() - BACKGROUND_HEIGHT, getWidth(), BACKGROUND_HEIGHT); g2.fillRect(0, getHeight() - BACKGROUND_HEIGHT, getWidth(), BACKGROUND_HEIGHT);
g2.setColor(Color.WHITE); g2.setColor(Color.WHITE);

15
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ProductNewsSearchManager.java

@ -9,6 +9,9 @@ import com.fr.json.JSONArray;
import com.fr.json.JSONFactory; import com.fr.json.JSONFactory;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import org.jetbrains.annotations.Nullable;
import java.awt.Image;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -59,7 +62,7 @@ public class ProductNewsSearchManager {
JSONObject obj = jsonArray.getJSONObject(i); JSONObject obj = jsonArray.getJSONObject(i);
ProductNews productNews = new ProductNews(). ProductNews productNews = new ProductNews().
setId(obj.getLong("id")).setTitle(obj.getString("title")). setId(obj.getLong("id")).setTitle(obj.getString("title")).
setImage(ImageIO.read(new URL(obj.getString("pic")))). setImage(getCoverImage(obj.getString("pic"))).
setUrl(obj.getString("url")).setTag(ProductNews.Tag.parseCode(obj.getInt("tag"))). setUrl(obj.getString("url")).setTag(ProductNews.Tag.parseCode(obj.getInt("tag"))).
setStatus(ProductNews.Status.parseCode(obj.getInt("status"))).setTarget( setStatus(ProductNews.Status.parseCode(obj.getInt("status"))).setTarget(
ProductNews.Target.parseCode(obj.getInt("target"))). ProductNews.Target.parseCode(obj.getInt("target"))).
@ -72,4 +75,14 @@ public class ProductNewsSearchManager {
public List<ProductNews> getCachedProductNewsList() { public List<ProductNews> getCachedProductNewsList() {
return productNewsList; return productNewsList;
} }
@Nullable
private Image getCoverImage(String url) {
try {
return ImageIO.read(new URL(url));
} catch (Exception e) {
FineLoggerFactory.getLogger().warn(e.getMessage(), e);
}
return null;
}
} }

Loading…
Cancel
Save