Browse Source

ct

feature/big-screen
neil 5 years ago
parent
commit
e26b97cdc4
  1. 60
      designer-base/src/main/java/com/fr/design/gui/ibutton/UIColorButton.java

60
designer-base/src/main/java/com/fr/design/gui/ibutton/UIColorButton.java

@ -1,19 +1,5 @@
package com.fr.design.gui.ibutton; package com.fr.design.gui.ibutton;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
import com.fr.base.Utils; import com.fr.base.Utils;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.event.GlobalNameListener; import com.fr.design.event.GlobalNameListener;
@ -21,9 +7,21 @@ import com.fr.design.event.GlobalNameObserver;
import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener; import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.ipoppane.PopupHider; import com.fr.design.gui.ipoppane.PopupHider;
import com.fr.general.ComparatorUtils;
import com.fr.design.style.color.ColorControlWindow; import com.fr.design.style.color.ColorControlWindow;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class UIColorButton extends UIButton implements PopupHider, UIObserver, GlobalNameObserver { public class UIColorButton extends UIButton implements PopupHider, UIObserver, GlobalNameObserver {
private static final int SIZE = 16; private static final int SIZE = 16;
@ -36,7 +34,7 @@ public class UIColorButton extends UIButton implements PopupHider, UIObserver, G
private EventListenerList colorChangeListenerList = new EventListenerList(); private EventListenerList colorChangeListenerList = new EventListenerList();
private boolean isEventBanned = false; private boolean isEventBanned = false;
private String colorButtonName = ""; private String colorButtonName = "";
private UIObserverListener uiColorObserverListener; private UIObserverListener uiObserverListener;
private GlobalNameListener globalNameListener = null; private GlobalNameListener globalNameListener = null;
public UIColorButton() { public UIColorButton() {
@ -60,13 +58,13 @@ public class UIColorButton extends UIButton implements PopupHider, UIObserver, G
this.addColorChangeListener(new ChangeListener() { this.addColorChangeListener(new ChangeListener() {
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
if (uiColorObserverListener == null) { if (uiObserverListener == null) {
return; return;
} }
if (globalNameListener != null && shouldResponseNameListener()) { if (globalNameListener != null && shouldResponseNameListener()) {
globalNameListener.setGlobalName(colorButtonName); globalNameListener.setGlobalName(colorButtonName);
} }
uiColorObserverListener.doChange(); uiObserverListener.doChange();
} }
}); });
} }
@ -136,10 +134,9 @@ public class UIColorButton extends UIButton implements PopupHider, UIObserver, G
public void hidePopupMenu() { public void hidePopupMenu() {
if (popupWin != null) { if (popupWin != null) {
popupWin.setVisible(false); popupWin.setVisible(false);
repaint();
} }
popupWin = null; popupWin = null;
repaint();
} }
private ColorControlWindow getColorControlWindow() { private ColorControlWindow getColorControlWindow() {
@ -169,6 +166,7 @@ public class UIColorButton extends UIButton implements PopupHider, UIObserver, G
/** /**
* 移除监听 * 移除监听
* Removes an old ColorChangeListener. * Removes an old ColorChangeListener.
*
* @param changeListener 监听列表 * @param changeListener 监听列表
*/ */
public void removeColorChangeListener(ChangeListener changeListener) { public void removeColorChangeListener(ChangeListener changeListener) {
@ -199,7 +197,7 @@ public class UIColorButton extends UIButton implements PopupHider, UIObserver, G
* @param listener 观察者监听事件 * @param listener 观察者监听事件
*/ */
public void registerChangeListener(UIObserverListener listener) { public void registerChangeListener(UIObserverListener listener) {
uiColorObserverListener = listener; uiObserverListener = listener;
} }
/** /**
@ -228,24 +226,4 @@ public class UIColorButton extends UIButton implements PopupHider, UIObserver, G
public boolean shouldResponseNameListener() { public boolean shouldResponseNameListener() {
return true; return true;
} }
/**
* 主函数
*
* @param args 参数
*/
public static void main(String... args) {
LayoutManager layoutManager = null;
JFrame jf = new JFrame("test");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel content = (JPanel) jf.getContentPane();
content.setLayout(layoutManager);
UIColorButton bb = new UIColorButton(UIConstants.FONT_ICON);
bb.setBounds(20, 20, bb.getPreferredSize().width, bb.getPreferredSize().height);
content.add(bb);
GUICoreUtils.centerWindow(jf);
jf.setSize(400, 400);
jf.setVisible(true);
}
} }
Loading…
Cancel
Save