Browse Source

REPORT-1384 按钮控件自定义颜色样式

master
kerry 8 years ago
parent
commit
7fb5702556
  1. 53
      designer_base/src/com/fr/design/style/background/BackgroundButtonPane.java
  2. 34
      designer_base/src/com/fr/design/style/background/BackgroundFactory.java
  3. 29
      designer_base/src/com/fr/design/style/background/impl/ImageBackgroundPane.java
  4. 80
      designer_base/src/com/fr/design/style/background/impl/ImageButtonBackgroundPane.java
  5. 13
      designer_form/src/com/fr/design/mainframe/widget/accessibles/AccessibleImgBackgroundEditor.java

53
designer_base/src/com/fr/design/style/background/BackgroundButtonPane.java

@ -0,0 +1,53 @@
package com.fr.design.style.background;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.general.Background;
import com.fr.general.Inter;
/**
* Created by ibm on 2017/1/5.
*/
public class BackgroundButtonPane extends BackgroundPane {
public BackgroundButtonPane() {
super();
}
protected void initTabPane() {
int index = 0;
for (Class<? extends Background> key : BackgroundFactory.buttonKindsOfKey()) {
BackgroundUIWrapper wrapper = BackgroundFactory.getButtonWrapper(key);
wrapper.setIndex(index++);
tabbedPane.addTab(Inter.getLocText(wrapper.getTitle()), FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane());
}
}
protected BackgroundUIWrapper getBackgroundUIWrapper(Background background) {
return BackgroundFactory.getButtonWrapper(background == null ? null : background.getClass());
}
protected BackgroundDetailPane getTabItemPane(Background background, int index) {
BackgroundDetailPane quickPane = cacheMap.get(index);
if (quickPane == null) {
quickPane = BackgroundFactory.createButtonIfAbsent(background == null ? null : background.getClass());
quickPane.addChangeListener(backgroundChangeListener);
cacheMap.put(index, quickPane);
}
tabbedPane.setComponentAt(index, quickPane);
tabbedPane.setSelectedIndex(index);
return quickPane;
}
protected BackgroundDetailPane getTabItemPaneByIndex(int index) {
BackgroundDetailPane quickPane = cacheMap.get(index);
if (quickPane == null) {
quickPane = BackgroundFactory.createButtonIfAbsent(index);
tabbedPane.setComponentAt(index, quickPane);
cacheMap.put(index, quickPane);
quickPane.addChangeListener(backgroundChangeListener);
}
return quickPane;
}
}

34
designer_base/src/com/fr/design/style/background/BackgroundFactory.java

@ -3,7 +3,6 @@ package com.fr.design.style.background;
import com.fr.base.background.*; import com.fr.base.background.*;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.fun.BackgroundQuickUIProvider;
import com.fr.design.fun.BackgroundUIProvider; import com.fr.design.fun.BackgroundUIProvider;
import com.fr.design.style.background.gradient.GradientBackgroundPane; import com.fr.design.style.background.gradient.GradientBackgroundPane;
import com.fr.design.style.background.impl.*; import com.fr.design.style.background.impl.*;
@ -21,6 +20,7 @@ public class BackgroundFactory {
private static Map<Class<? extends Background>, BackgroundUIWrapper> map = new LinkedHashMap<>(); private static Map<Class<? extends Background>, BackgroundUIWrapper> map = new LinkedHashMap<>();
private static Map<Class<? extends Background>, BackgroundUIWrapper> browser = new LinkedHashMap<>(); private static Map<Class<? extends Background>, BackgroundUIWrapper> browser = new LinkedHashMap<>();
private static Map<Class<? extends Background>, BackgroundUIWrapper> button = new LinkedHashMap<>();
static { static {
registerUniversal(map); registerUniversal(map);
@ -29,6 +29,7 @@ public class BackgroundFactory {
registerBrowserImageBackground(browser); registerBrowserImageBackground(browser);
registerExtra(map); registerExtra(map);
registerExtra(browser); registerExtra(browser);
registerButtonBackground(button);
} }
private static void registerUniversal(Map<Class<? extends Background>, BackgroundUIWrapper> map) { private static void registerUniversal(Map<Class<? extends Background>, BackgroundUIWrapper> map) {
@ -54,6 +55,14 @@ public class BackgroundFactory {
.setType(ImageBackgroundPane4Browser.class).setTitle(Inter.getLocText("Image"))); .setType(ImageBackgroundPane4Browser.class).setTitle(Inter.getLocText("Image")));
} }
private static void registerButtonBackground(Map<Class<? extends Background>, BackgroundUIWrapper> map){
map.put(ColorBackground.class, BackgroundUIWrapper.create()
.setType(ColorBackgroundPane.class).setTitle(Inter.getLocText("Color")));
map.put(ImageBackground.class, BackgroundUIWrapper.create()
.setType(ImageButtonBackgroundPane.class).setTitle(Inter.getLocText("Image")));
}
private static void registerExtra(Map<Class<? extends Background>, BackgroundUIWrapper> map) { private static void registerExtra(Map<Class<? extends Background>, BackgroundUIWrapper> map) {
Set<BackgroundUIProvider> set = ExtraDesignClassManager.getInstance().getArray(BackgroundUIProvider.MARK_STRING); Set<BackgroundUIProvider> set = ExtraDesignClassManager.getInstance().getArray(BackgroundUIProvider.MARK_STRING);
for (BackgroundUIProvider provider : set) { for (BackgroundUIProvider provider : set) {
@ -85,6 +94,29 @@ public class BackgroundFactory {
return new NullBackgroundPane(); return new NullBackgroundPane();
} }
public static Set<Class<? extends Background>> buttonKindsOfKey() {
return button.keySet();
}
public static BackgroundUIWrapper getButtonWrapper(Class<? extends Background> category) {
return button.get(category);
}
public static BackgroundDetailPane createButtonIfAbsent(Class<? extends Background> category) {
BackgroundUIWrapper wrapper = button.get(category);
return createByWrapper(wrapper);
}
public static BackgroundDetailPane createButtonIfAbsent(int index) {
for (BackgroundUIWrapper wrapper : button.values()) {
if (wrapper.getIndex() == index) {
return createByWrapper(wrapper);
}
}
return new NullBackgroundPane();
}
public static Set<Class<? extends Background>> browserKindsOfKey() { public static Set<Class<? extends Background>> browserKindsOfKey() {
return browser.keySet(); return browser.keySet();
} }

29
designer_base/src/com/fr/design/style/background/impl/ImageBackgroundPane.java

@ -28,11 +28,11 @@ import java.io.File;
*/ */
public class ImageBackgroundPane extends BackgroundDetailPane { public class ImageBackgroundPane extends BackgroundDetailPane {
private ImagePreviewPane previewPane = null; protected ImagePreviewPane previewPane = null;
private Style imageStyle = null; private Style imageStyle = null;
private ChangeListener changeListener = null; private ChangeListener changeListener = null;
private ImageFileChooser imageFileChooser = null; private ImageFileChooser imageFileChooser = null;
private UILabel imageSizeLabel = new UILabel(); protected UILabel imageSizeLabel = new UILabel();
protected JRadioButton defaultRadioButton = null; protected JRadioButton defaultRadioButton = null;
protected JRadioButton tiledRadioButton = null; protected JRadioButton tiledRadioButton = null;
@ -49,14 +49,20 @@ public class ImageBackgroundPane extends BackgroundDetailPane {
JPanel previewOwnerPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("Preview")); JPanel previewOwnerPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("Preview"));
previewOwnerPane.setLayout(new BorderLayout()); previewOwnerPane.setLayout(new BorderLayout());
previewContainerPane.add(previewOwnerPane, BorderLayout.CENTER); previewContainerPane.add(previewOwnerPane, BorderLayout.CENTER);
previewContainerPane.add(initSelectFilePane(), BorderLayout.EAST);
previewPane = new ImagePreviewPane(); previewPane = new ImagePreviewPane();
previewOwnerPane.add(new JScrollPane(previewPane)); previewOwnerPane.add(new JScrollPane(previewPane));
previewPane.addChangeListener(imageSizeChangeListener); previewPane.addChangeListener(imageSizeChangeListener);
// init image file chooser.
imageFileChooser = new ImageFileChooser();
imageFileChooser.setMultiSelectionEnabled(false);
}
public JPanel initSelectFilePane(){
JPanel selectFilePane = FRGUIPaneFactory.createBorderLayout_L_Pane(); JPanel selectFilePane = FRGUIPaneFactory.createBorderLayout_L_Pane();
previewContainerPane.add(selectFilePane, BorderLayout.EAST);
selectFilePane.setBorder(BorderFactory.createEmptyBorder(8, 2, 4, 0)); selectFilePane.setBorder(BorderFactory.createEmptyBorder(8, 2, 4, 0));
UIButton selectPictureButton = new UIButton( UIButton selectPictureButton = new UIButton(
@ -91,10 +97,7 @@ public class ImageBackgroundPane extends BackgroundDetailPane {
layoutBG.add(adjustRadioButton); layoutBG.add(adjustRadioButton);
defaultRadioButton.setSelected(true); defaultRadioButton.setSelected(true);
return selectFilePane;
// init image file chooser.
imageFileChooser = new ImageFileChooser();
imageFileChooser.setMultiSelectionEnabled(false);
} }
protected JRadioButton[] imageLayoutButtons() { protected JRadioButton[] imageLayoutButtons() {
@ -121,8 +124,7 @@ public class ImageBackgroundPane extends BackgroundDetailPane {
CoreGraphHelper.waitForImage(image); CoreGraphHelper.waitForImage(image);
previewPane.setImage(image); previewPane.setImage(image);
setImageStyle(); imageStyleRepaint();
previewPane.setImageStyle(imageStyle);
previewPane.repaint(); previewPane.repaint();
} else { } else {
previewPane.setImage(null); previewPane.setImage(null);
@ -133,6 +135,11 @@ public class ImageBackgroundPane extends BackgroundDetailPane {
} }
}; };
public void imageStyleRepaint(){
setImageStyle();
previewPane.setImageStyle(imageStyle);
}
private void setImageStyle() { private void setImageStyle() {
if (tiledRadioButton.isSelected()) { if (tiledRadioButton.isSelected()) {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_TILED); imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_TILED);

80
designer_base/src/com/fr/design/style/background/impl/ImageButtonBackgroundPane.java

@ -0,0 +1,80 @@
package com.fr.design.style.background.impl;
import com.fr.base.BaseUtils;
import com.fr.base.Style;
import com.fr.base.background.ImageBackground;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.general.Background;
import com.fr.general.Inter;
import com.fr.stable.Constants;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Created by ibm on 2017/1/5.
*/
public class ImageButtonBackgroundPane extends ImageBackgroundPane {
private UIButton chooseButton;
private UIButton clearButton;
public ImageButtonBackgroundPane(){
super();
Style imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_CENTER);
previewPane.setImageStyle(imageStyle);
}
public JPanel initSelectFilePane(){
JPanel choosePane = new JPanel(new BorderLayout(0, 10));
choosePane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
JPanel choosePane1 = new JPanel(new BorderLayout(0, 10));
initButton();
choosePane.add(chooseButton, BorderLayout.NORTH);
choosePane1.add(clearButton,BorderLayout.NORTH);
choosePane.add(choosePane1,BorderLayout.CENTER);
imageSizeLabel.setHorizontalAlignment(SwingConstants.CENTER);
choosePane1.add(imageSizeLabel,BorderLayout.CENTER);
this.add(choosePane,BorderLayout.EAST);
return choosePane;
}
private void initButton() {
chooseButton = new UIButton(Inter.getLocText("Image-Select_Picture"));
chooseButton.addActionListener(selectPictureActionListener);
clearButton = new UIButton(Inter.getLocText("Clear"));
clearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
previewPane.setImage(null);
previewPane.repaint();
}
});
}
public void imageStyleRepaint(){
}
public void populate(Background background) {
if(background != null && background instanceof ImageBackground){
ImageBackground imageBackground = (ImageBackground) background;
if(imageBackground.getImage() != null) {
previewPane.setImage(imageBackground.getImage());
}
}
}
public Background update() {
if(previewPane.getImage() == null) {
return null;
}
return new ImageBackground(previewPane.getImage());
}
}

13
designer_form/src/com/fr/design/mainframe/widget/accessibles/AccessibleImgBackgroundEditor.java

@ -1,17 +1,16 @@
package com.fr.design.mainframe.widget.accessibles; package com.fr.design.mainframe.widget.accessibles;
import java.awt.Dimension; import java.awt.Dimension;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import com.fr.base.background.ColorBackground;
import com.fr.base.background.ImageBackground;
import com.fr.design.mainframe.widget.wrappers.BackgroundWrapper; import com.fr.design.mainframe.widget.wrappers.BackgroundWrapper;
import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.frpane.ImgChoosePane; import com.fr.design.style.background.BackgroundButtonPane;
import com.fr.general.Background;
public class AccessibleImgBackgroundEditor extends UneditableAccessibleEditor { public class AccessibleImgBackgroundEditor extends UneditableAccessibleEditor {
private ImgChoosePane choosePane; private BackgroundButtonPane choosePane;
public AccessibleImgBackgroundEditor() { public AccessibleImgBackgroundEditor() {
super(new BackgroundWrapper()); super(new BackgroundWrapper());
@ -20,7 +19,7 @@ public class AccessibleImgBackgroundEditor extends UneditableAccessibleEditor {
@Override @Override
protected void showEditorPane() { protected void showEditorPane() {
if (choosePane == null) { if (choosePane == null) {
choosePane = new ImgChoosePane(); choosePane = new BackgroundButtonPane();
choosePane.setPreferredSize(new Dimension(600, 400)); choosePane.setPreferredSize(new Dimension(600, 400));
} }
BasicDialog dlg = choosePane.showWindow(SwingUtilities.getWindowAncestor(this)); BasicDialog dlg = choosePane.showWindow(SwingUtilities.getWindowAncestor(this));
@ -32,7 +31,7 @@ public class AccessibleImgBackgroundEditor extends UneditableAccessibleEditor {
fireStateChanged(); fireStateChanged();
} }
}); });
choosePane.populate(getValue() instanceof ImageBackground ? (ImageBackground) getValue() : null); choosePane.populate(getValue() instanceof Background ? (Background) getValue() : new ColorBackground());
dlg.setVisible(true); dlg.setVisible(true);
} }
} }
Loading…
Cancel
Save