From e9582c6962b9b83795723814cf046c8997e92037 Mon Sep 17 00:00:00 2001 From: obo Date: Wed, 15 Nov 2023 14:14:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E9=99=A4=E4=B8=80=E6=B3=A2=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widgettheme/theme/panel/ImageUtils.java | 34 +++- .../panel/WidgetThemeECReportPreviewPane.java | 157 ++++++++++++------ .../widgettheme/BaseStyleSettingPane.java | 89 +++++----- 3 files changed, 170 insertions(+), 110 deletions(-) diff --git a/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ImageUtils.java b/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ImageUtils.java index c07cfcecea..63da90e6f7 100644 --- a/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ImageUtils.java +++ b/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ImageUtils.java @@ -29,18 +29,44 @@ public class ImageUtils { for (int xx = 0; xx < width; xx++) { for (int yy = 0; yy < height; yy++) { - dealRasterPixels(raster, xx, yy, color); + int[] pixels = raster.getPixel(xx, yy, (int[]) null); + setRedPixels(pixels, color); + setGreenPixels(pixels, color); + setBluePixels(pixels, color); + raster.setPixel(xx, yy, pixels); } } return image; } - private static void dealRasterPixels(WritableRaster raster, int x, int y, Color color) { - int[] pixels = raster.getPixel(x, y, (int[]) null); + /** + * 处理红像素 + * + * @param pixels 像素数组 + * @param color 颜色 + */ + private static void setRedPixels(int[] pixels, Color color) { pixels[0] = pixels[0] > 0 && pixels[0] < 255 ? color.getRed() : 255; + } + + /** + * 处理绿像素 + * + * @param pixels 像素数组 + * @param color 颜色 + */ + private static void setGreenPixels(int[] pixels, Color color) { pixels[1] = pixels[1] > 0 && pixels[1] < 255 ? color.getGreen() : 255; + } + + /** + * 处理蓝像素 + * + * @param pixels 像素数组 + * @param color 颜色 + */ + private static void setBluePixels(int[] pixels, Color color) { pixels[2] = pixels[2] > 0 && pixels[2] < 255 ? color.getBlue() : 255; - raster.setPixel(x, y, pixels); } /** diff --git a/designer-base/src/main/java/com/fr/widgettheme/theme/panel/WidgetThemeECReportPreviewPane.java b/designer-base/src/main/java/com/fr/widgettheme/theme/panel/WidgetThemeECReportPreviewPane.java index e34ca83d88..39cd48a566 100644 --- a/designer-base/src/main/java/com/fr/widgettheme/theme/panel/WidgetThemeECReportPreviewPane.java +++ b/designer-base/src/main/java/com/fr/widgettheme/theme/panel/WidgetThemeECReportPreviewPane.java @@ -77,11 +77,7 @@ public class WidgetThemeECReportPreviewPane extends UINoOpaquePanel implements T bigTitleCell.setPreferredSize(new Dimension(615, 46)); headerTitleCellList.add(bigTitleCell); northPane.add(bigTitleCell, BorderLayout.NORTH); - CornerPreviewCell cornerCell = new CornerPreviewCell(new String[]{Toolkit.i18nText("Fine-Design_Basic_Column_Name"), - Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Profile_Pane_EC_Data"), Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Profile_Pane_Row_Name")}, - new Point2D[]{new Point(159, 71), new Point(225, 49)}); - cornerCell.setBorderSourceFlag(CellBorderSourceFlag.INVALID_BORDER_SOURCE); - cornerCell.setPreferredSize(new Dimension(225, 71)); + CornerPreviewCell cornerCell = createCornerPreviewCell(); titleCellList.add(cornerCell); northPane.add(cornerCell, BorderLayout.WEST); JPanel centerPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane(); @@ -93,15 +89,7 @@ public class WidgetThemeECReportPreviewPane extends UINoOpaquePanel implements T centerPane.add(cell, BorderLayout.NORTH); JPanel eastSouthPane = new UINoOpaquePanel(new GridLayout()); for (int c = 0; c < CONTENT_ROW_COUNT; c++) { - PreviewCell headerCell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header")); - int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; - if (c > 0) { - flag |= CellBorderSourceFlag.LEFT_BORDER_SOURCE_INNER; - } - if (c < CONTENT_ROW_COUNT - 1) { - flag |= CellBorderSourceFlag.RIGHT_BORDER_SOURCE_INNER; - } - headerCell.setBorderSourceFlag(flag); + PreviewCell headerCell = createPreviewCellHeader(c); headerCellList.add(headerCell); eastSouthPane.add(headerCell); } @@ -109,6 +97,37 @@ public class WidgetThemeECReportPreviewPane extends UINoOpaquePanel implements T return northPane; } + /** + * 创建CornerPreviewCell + */ + private CornerPreviewCell createCornerPreviewCell() { + CornerPreviewCell cornerCell = new CornerPreviewCell(new String[]{Toolkit.i18nText("Fine-Design_Basic_Column_Name"), + Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Profile_Pane_EC_Data"), Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Profile_Pane_Row_Name")}, + new Point2D[]{new Point(159, 71), new Point(225, 49)}); + cornerCell.setBorderSourceFlag(CellBorderSourceFlag.INVALID_BORDER_SOURCE); + cornerCell.setPreferredSize(new Dimension(225, 71)); + return cornerCell; + } + + /** + * 创建预览单元格标题 + * + * @param c 文本行数 + * @return PreviewCell + */ + private PreviewCell createPreviewCellHeader(int c) { + PreviewCell headerCell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header")); + int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; + if (c > 0) { + flag |= CellBorderSourceFlag.LEFT_BORDER_SOURCE_INNER; + } + if (c < CONTENT_ROW_COUNT - 1) { + flag |= CellBorderSourceFlag.RIGHT_BORDER_SOURCE_INNER; + } + headerCell.setBorderSourceFlag(flag); + return headerCell; + } + private JPanel createCenterPane() { JPanel centerPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane(); JPanel westPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane(); @@ -117,21 +136,8 @@ public class WidgetThemeECReportPreviewPane extends UINoOpaquePanel implements T titleCellList.add(cell1); cell1.setPreferredSize(new Dimension(112, 93)); westPane.add(cell1, BorderLayout.WEST); - JPanel gridPane = new UINoOpaquePanel(new GridLayout(3, 1)); - for (int r = 0; r < 3; r++) { - PreviewCell cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header")); - int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; - if (r > 0) { - flag |= CellBorderSourceFlag.TOP_BORDER_SOURCE_INNER; - } - if (r < COL_COUNT - 1) { - flag |= CellBorderSourceFlag.BOTTOM_BORDER_SOURCE_INNER; - } - cell.setBorderSourceFlag(flag); - cell.setPreferredSize(new Dimension(113, 31)); - headerCellList.add(cell); - gridPane.add(cell); - } + JPanel gridPane = createGridPane(); + westPane.add(gridPane, BorderLayout.CENTER); JPanel innerCenterPane = new UINoOpaquePanel(new GridLayout(3, 3)); centerPane.add(innerCenterPane, BorderLayout.CENTER); @@ -140,41 +146,82 @@ public class WidgetThemeECReportPreviewPane extends UINoOpaquePanel implements T int r = i / CONTENT_ROW_COUNT; int c = i % CONTENT_ROW_COUNT; if (c == CONTENT_ROW_COUNT - 1) { - cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Highlight_Text")); - int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; - if (r != 0) { - flag |= CellBorderSourceFlag.TOP_BORDER_SOURCE_INNER; - } - if (r != COL_COUNT - 1) { - flag |= CellBorderSourceFlag.BOTTOM_BORDER_SOURCE_INNER; - } - cell.setBorderSourceFlag(flag); + cell = createPreviewCellHighlight(r); highLightCellList.add(cell); } else { - cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Main_Text")); - int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; - if (r > 0) { - flag |= CellBorderSourceFlag.TOP_BORDER_SOURCE_INNER; - } - if (r < COL_COUNT - 1) { - flag |= CellBorderSourceFlag.BOTTOM_BORDER_SOURCE_INNER; - } - if (c > 0) { - flag |= CellBorderSourceFlag.LEFT_BORDER_SOURCE_INNER; - } - if (c < CONTENT_ROW_COUNT - 2) { - flag |= CellBorderSourceFlag.RIGHT_BORDER_SOURCE_INNER; - } - cell.setBorderSourceFlag(flag); - + cell = createPreviewCellMain(r, c); contentCellList.add(cell); } cell.setPreferredSize(new Dimension(123, 31)); innerCenterPane.add(cell); } + return centerPane; + } + /** + * 创建高亮预览单元格 + * + * @param r 计算标志位 + * @return 单元格 + */ + private PreviewCell createPreviewCellHighlight(int r) { + PreviewCell cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Highlight_Text")); + int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; + if (r != 0) { + flag |= CellBorderSourceFlag.TOP_BORDER_SOURCE_INNER; + } + if (r != COL_COUNT - 1) { + flag |= CellBorderSourceFlag.BOTTOM_BORDER_SOURCE_INNER; + } + cell.setBorderSourceFlag(flag); + return cell; + } - return centerPane; + /** + * 创建正文预览单元格 + * + * @param r 计算标志位 + * @param c 计算标志位 + * @return 单元格 + */ + private PreviewCell createPreviewCellMain(int r, int c) { + PreviewCell cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Main_Text")); + int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; + if (r > 0) { + flag |= CellBorderSourceFlag.TOP_BORDER_SOURCE_INNER; + } + if (r < COL_COUNT - 1) { + flag |= CellBorderSourceFlag.BOTTOM_BORDER_SOURCE_INNER; + } + if (c > 0) { + flag |= CellBorderSourceFlag.LEFT_BORDER_SOURCE_INNER; + } + if (c < 1) { + flag |= CellBorderSourceFlag.RIGHT_BORDER_SOURCE_INNER; + } + cell.setBorderSourceFlag(flag); + return cell; + } + + private JPanel createGridPane() { + int rowCount = 3; + int columnCount = 1; + JPanel gridPane = new UINoOpaquePanel(new GridLayout(rowCount, columnCount)); + for (int r = 0; r < rowCount; r++) { + PreviewCell cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header")); + int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; + if (r > 0) { + flag |= CellBorderSourceFlag.TOP_BORDER_SOURCE_INNER; + } + if (r < COL_COUNT - 1) { + flag |= CellBorderSourceFlag.BOTTOM_BORDER_SOURCE_INNER; + } + cell.setBorderSourceFlag(flag); + cell.setPreferredSize(new Dimension(113, 31)); + headerCellList.add(cell); + gridPane.add(cell); + } + return gridPane; } private JPanel createSouthPane(){ diff --git a/designer-form/src/main/java/com/fr/design/widgettheme/BaseStyleSettingPane.java b/designer-form/src/main/java/com/fr/design/widgettheme/BaseStyleSettingPane.java index ebe94c2740..61531848a9 100644 --- a/designer-form/src/main/java/com/fr/design/widgettheme/BaseStyleSettingPane.java +++ b/designer-form/src/main/java/com/fr/design/widgettheme/BaseStyleSettingPane.java @@ -31,7 +31,9 @@ import javax.swing.ButtonGroup; import javax.swing.JPanel; import java.awt.BorderLayout; import java.awt.Component; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 样式设置pane抽象类 @@ -64,14 +66,15 @@ public abstract class BaseStyleSettingPane extends BasicBeanPa // 按钮背景设置 protected ButtonStyleDefinedPane buttonStyleDefinedPane; - + private Map labelMap; + private Map paneMap; public BaseStyleSettingPane(List styleSettingList) { this.styleSettingList = styleSettingList; initStyleEditor(); initPane(); initDefaultValue(); - + initLabelMap(); } protected void initPane() { @@ -82,33 +85,20 @@ public abstract class BaseStyleSettingPane extends BasicBeanPa protected void initStyleEditor() { - styleSettingList.forEach(it -> { - switch (it) { - case STYLE_TYPE: - initStyle(); - break; - case THEME_COLOR: - colorSelectBox = new NewColorSelectBox(160, true); - break; - case LINE_TYPE: - lineComboBox = new LineComboBox(WidgetThemeDisplayConstants.BORDER_LINE_STYLE_ARRAY); - break; - case FONT_SIZE: - fontSizePane = new FontSizeComboPane(); - break; - case BORDER_RADIUS: - borderRadiusSpinner = new UIBoundSpinner(0, Integer.MAX_VALUE, 1); - break; - case FONT: - frFontPane = new FRFontPane(); - break; - case BTN_BACKGROUND: - buttonStyleDefinedPane = new ButtonStyleDefinedPane(); - break; - default: - break; - } - }); + initStyle(); + colorSelectBox = new NewColorSelectBox(160, true); + lineComboBox = new LineComboBox(WidgetThemeDisplayConstants.BORDER_LINE_STYLE_ARRAY); + fontSizePane = new FontSizeComboPane(); + borderRadiusSpinner = new UIBoundSpinner(0, Integer.MAX_VALUE, 1); + frFontPane = new FRFontPane(); + buttonStyleDefinedPane = new ButtonStyleDefinedPane(); + paneMap.put(StyleSetting.STYLE_TYPE, createStyleTypePane()); + paneMap.put(StyleSetting.THEME_COLOR, colorSelectBox); + paneMap.put(StyleSetting.LINE_TYPE, lineComboBox); + paneMap.put(StyleSetting.FONT_SIZE, fontSizePane); + paneMap.put(StyleSetting.BORDER_RADIUS, borderRadiusSpinner); + paneMap.put(StyleSetting.FONT, frFontPane); + paneMap.put(StyleSetting.BTN_BACKGROUND, buttonStyleDefinedPane); } /** @@ -151,7 +141,7 @@ public abstract class BaseStyleSettingPane extends BasicBeanPa double f = TableLayout.FILL; double p = TableLayout.PREFERRED; - + int columnCount = 2; double[] rowSize = new double[size]; for (int i = 0; i < size; i++) { rowSize[i] = p; @@ -159,9 +149,9 @@ public abstract class BaseStyleSettingPane extends BasicBeanPa double[] columnSize = {p, f}; - int[][] rowCount = new int[size][2]; + int[][] rowCount = new int[size][columnCount]; for (int i = 0; i < size; i++) { - for (int j = 0; j < 2; j++) { + for (int j = 0; j < columnCount; j++) { rowCount[i][j] = 1; } } @@ -180,24 +170,10 @@ public abstract class BaseStyleSettingPane extends BasicBeanPa } protected Component[] createComponentByStyleSetting(StyleSetting styleSetting) { - switch (styleSetting) { - case THEME_COLOR: - return new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Color")), colorSelectBox}; - case FONT_SIZE: - return new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Font_Size")), fontSizePane}; - case FONT: - return new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Font")), frFontPane}; - case STYLE_TYPE: - return new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Style")), createStyleTypePane()}; - case LINE_TYPE: - return new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Border_Line")), lineComboBox}; - case BORDER_RADIUS: - return new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Border_Radius")), borderRadiusSpinner}; - case BTN_BACKGROUND: - return new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Theme_Widget_Background")), buttonStyleDefinedPane}; - default: - return null; - } + Component[] components = new Component[2]; + components[0] = labelMap.get(styleSetting); + components[1] = paneMap.get(styleSetting); + return components; } protected void switchCard() { @@ -297,5 +273,16 @@ public abstract class BaseStyleSettingPane extends BasicBeanPa } } - + /** + * 初始化枚举和UILabel对应的map + */ + private void initLabelMap() { + labelMap.put(StyleSetting.THEME_COLOR, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Color"))); + labelMap.put(StyleSetting.FONT_SIZE, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Font_Size"))); + labelMap.put(StyleSetting.FONT, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Font"))); + labelMap.put(StyleSetting.STYLE_TYPE, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Style"))); + labelMap.put(StyleSetting.LINE_TYPE, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Border_Line"))); + labelMap.put(StyleSetting.BORDER_RADIUS, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Border_Radius"))); + labelMap.put(StyleSetting.BTN_BACKGROUND, new UILabel(Toolkit.i18nText("Fine-Design_Theme_Widget_Background"))); + } }