diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/ProductNewsContentCellRender.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/ProductNewsContentCellRender.java index 7ef00e6ba..f86253d0c 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/ProductNewsContentCellRender.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/ProductNewsContentCellRender.java @@ -1,6 +1,5 @@ package com.fr.design.mainframe.alphafine.component; -import com.fr.design.DesignerEnvManager; import com.fr.design.gui.ilable.UILabel; import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.design.mainframe.alphafine.AlphaFineUtil; @@ -28,6 +27,21 @@ public class ProductNewsContentCellRender implements ListCellRenderer { 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; public ProductNewsContentCellRender(String[] segmentationResult) { @@ -58,7 +72,7 @@ public class ProductNewsContentCellRender implements ListCellRenderer { @Override protected void paintComponent(Graphics g) { 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); } }; @@ -73,7 +87,7 @@ public class ProductNewsContentCellRender implements ListCellRenderer { textPane.setBackground(Color.WHITE); textPane.add(infoPane, BorderLayout.CENTER); panel.add(textPane, BorderLayout.CENTER); - panel.setPreferredSize(new Dimension(500, 80)); + panel.setPreferredSize(DEFAULT_DIMENSION); return panel; } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/ProductNewsImagePanel.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/ProductNewsImagePanel.java index 69ed4eaed..e87b6f199 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/ProductNewsImagePanel.java +++ b/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.svg.SVGLoader; import com.fr.design.DesignerEnvManager; -import com.fr.design.constants.UIConstants; 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.Dimension; import java.awt.Graphics; @@ -15,7 +11,6 @@ import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; -import java.awt.geom.RoundRectangle2D; import java.util.Set; 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 COVER_COLOR = new Color(116, 181, 249, 26); + private ProductNews productNews; private int width = 200; @@ -48,17 +45,20 @@ public class ProductNewsImagePanel extends JPanel { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); -// g2.setComposite(AlphaComposite.Src); -// g2.fill(new RoundRectangle2D.Float(0, 0, getWidth(), getHeight(), 5, 5)); -// g2.setComposite(AlphaComposite.SrcAtop); + Color defaultColor = g2.getColor(); - 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 readSet = DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().getReadSet(); if (!readSet.contains(productNews.getId())) { g2.drawImage(NEW_TIP_IMAGE, 0, 0, this); } - Color defaultColor = g2.getColor(); g2.setColor(BACKGROUND_COLOR); g2.fillRect(0, getHeight() - BACKGROUND_HEIGHT, getWidth(), BACKGROUND_HEIGHT); g2.setColor(Color.WHITE); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ProductNewsSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ProductNewsSearchManager.java index 3c211deeb..c205a624b 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ProductNewsSearchManager.java +++ b/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.JSONObject; import com.fr.log.FineLoggerFactory; +import org.jetbrains.annotations.Nullable; + +import java.awt.Image; import java.net.URL; import java.util.ArrayList; import java.util.Date; @@ -59,7 +62,7 @@ public class ProductNewsSearchManager { JSONObject obj = jsonArray.getJSONObject(i); ProductNews productNews = new ProductNews(). 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"))). setStatus(ProductNews.Status.parseCode(obj.getInt("status"))).setTarget( ProductNews.Target.parseCode(obj.getInt("target"))). @@ -72,4 +75,14 @@ public class ProductNewsSearchManager { public List getCachedProductNewsList() { 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; + } }