Browse Source

新加一个类

master
MoMeak 7 years ago
parent
commit
68ea276b8f
  1. 21
      designer_base/src/com/fr/design/actions/UpdateAction.java
  2. 58
      designer_base/src/com/fr/design/gui/imenu/UIMenuItem.java
  3. 103
      designer_base/src/com/fr/design/gui/imenu/UIMenuItemEastAttr.java
  4. 12
      designer_base/src/com/fr/design/gui/imenu/UIPopupMenu.java
  5. 10
      designer_base/src/com/fr/design/menu/MenuDef.java

21
designer_base/src/com/fr/design/actions/UpdateAction.java

@ -11,6 +11,7 @@ import com.fr.design.constants.UIConstants;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.imenu.UICheckBoxMenuItem;
import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.gui.imenu.UIMenuItemEastAttr;
import com.fr.design.gui.imenu.UIPopupMenu;
import com.fr.design.menu.ShortCut;
import com.fr.design.selection.SelectionListener;
@ -49,11 +50,6 @@ public abstract class UpdateAction extends ShortCut implements Action {
*/
private boolean enabled = true;
/**
* Specifies whether action is rePaint; the default is false.
*/
private boolean rePaint = false;
/**
* Contains the array of key bindings.
* august:关键词key是Action里面的final常量Action.NAMEAction.SMALL_ICON等等
@ -255,10 +251,18 @@ public abstract class UpdateAction extends ShortCut implements Action {
this.putValue(UIMenuItem.class.getName(), object);
}
((UIMenuItem) object).setRePaint(this.rePaint);
return (UIMenuItem) object;
}
public UIMenuItemEastAttr createMenuItemEastAttr() {
UIMenuItem menuItem = new UIMenuItemEastAttr(this);
// 设置名字用作单元测
menuItem.setName(getName());
Object object = menuItem;
this.putValue(UIMenuItem.class.getName(), object);
return (UIMenuItemEastAttr) object;
}
/**
* Gets component on toolbar.
*
@ -324,7 +328,10 @@ public abstract class UpdateAction extends ShortCut implements Action {
public void intoJPopupMenu(JPopupMenu menu) {
update();
if (menu instanceof UIPopupMenu){
this.rePaint = ((UIPopupMenu) menu).getRePaint();
if (((UIPopupMenu) menu).getRePaint()){
menu.add(this.createMenuItemEastAttr());
return;
}
}
menu.add(this.createMenuItem());
}

58
designer_base/src/com/fr/design/gui/imenu/UIMenuItem.java

@ -1,22 +1,20 @@
package com.fr.design.gui.imenu;
import com.fr.design.constants.UIConstants;
import com.fr.design.utils.gui.GUIPaintUtils;
import com.fr.stable.Constants;
import com.fr.stable.StringUtils;
import sun.swing.SwingUtilities2;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.basic.BasicMenuItemUI;
import java.awt.*;
public class UIMenuItem extends JMenuItem {
private boolean rePaint = false;
import com.fr.design.constants.UIConstants;
import com.fr.stable.Constants;
import com.fr.stable.StringUtils;
import com.fr.design.utils.gui.GUIPaintUtils;
import sun.swing.SwingUtilities2;
public UIMenuItem() {
this(StringUtils.BLANK);
}
public class UIMenuItem extends JMenuItem{
public UIMenuItem() {
this(StringUtils.BLANK);
}
public UIMenuItem(String string) {
this(string, null);
@ -40,10 +38,6 @@ public class UIMenuItem extends JMenuItem {
setAction(action);
}
public void setRePaint(boolean rePaint){
this.rePaint = rePaint;
}
@Override
public String getText() {
return StringUtils.BLANK + super.getText();
@ -53,34 +47,21 @@ public class UIMenuItem extends JMenuItem {
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem,Color bgColor) {
if(menuItem.getIcon() == null) {
if (!rePaint){
super.paintBackground(g, menuItem, bgColor);
return;
}
}
if (rePaint){
menuItem.setIcon(null);
super.paintBackground(g, menuItem, bgColor);
return;
}
ButtonModel model = menuItem.getModel();
Color oldColor = g.getColor();
int menuWidth = menuItem.getWidth();
int menuHeight = menuItem.getHeight();
g.setColor(UIConstants.NORMAL_BACKGROUND);
g.fillRect(0, 0, menuWidth, menuHeight);
if (menuItem.isOpaque()) {
if (!rePaint) {
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) {
GUIPaintUtils.fillPaint((Graphics2D) g, 30, 0, menuWidth - 30, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7);
} else {
GUIPaintUtils.fillPaint((Graphics2D) g, 30, 0, menuWidth - 30, menuHeight, true, Constants.NULL, menuItem.getBackground(), 7);
}
if(menuItem.isOpaque()) {
if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) {
GUIPaintUtils.fillPaint((Graphics2D)g, 30, 0, menuWidth - 30, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7);
} else {
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) {
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 0);
} else {
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.TOOLBARUI_BACKGROUND, 0);
}
GUIPaintUtils.fillPaint((Graphics2D)g, 30, 0, menuWidth - 30, menuHeight, true, Constants.NULL, menuItem.getBackground(), 7);
}
g.setColor(oldColor);
}
@ -111,9 +92,6 @@ public class UIMenuItem extends JMenuItem {
-1, textRect.x - 1, textRect.y +
fm.getAscent() - 1);
}
} else if (rePaint) {
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
-1, 0, textRect.y + fm.getAscent());
} else {
// *** paint the text normally
if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) {
@ -124,6 +102,6 @@ public class UIMenuItem extends JMenuItem {
}
}
}
}

103
designer_base/src/com/fr/design/gui/imenu/UIMenuItemEastAttr.java

@ -0,0 +1,103 @@
package com.fr.design.gui.imenu;
import com.fr.design.constants.UIConstants;
import com.fr.design.utils.gui.GUIPaintUtils;
import com.fr.stable.Constants;
import com.fr.stable.StringUtils;
import sun.swing.SwingUtilities2;
import javax.swing.*;
import javax.swing.plaf.basic.BasicMenuItemUI;
import java.awt.*;
/**
* 右侧属性面板悬浮元素超级链接弹窗重绘
*/
public class UIMenuItemEastAttr extends UIMenuItem {
public UIMenuItemEastAttr() {
this(StringUtils.BLANK);
}
public UIMenuItemEastAttr(String string) {
this(string, null);
}
public UIMenuItemEastAttr(String string, Icon pageSmallIcon) {
super(string, pageSmallIcon);
setBackground(UIConstants.NORMAL_BACKGROUND);
setUI(new UIMenuItemEastAttrUI());
}
public UIMenuItemEastAttr(String string, int key) {
super(string, key);
setBackground(UIConstants.NORMAL_BACKGROUND);
setUI(new UIMenuItemEastAttrUI());
}
public UIMenuItemEastAttr(Action action) {
this();
setAction(action);
}
@Override
public String getText() {
return StringUtils.BLANK + super.getText();
}
private class UIMenuItemEastAttrUI extends BasicMenuItemUI {
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem,Color bgColor) {
if(menuItem.getIcon() != null) {
menuItem.setIcon(null);
}
ButtonModel model = menuItem.getModel();
Color oldColor = g.getColor();
int menuWidth = menuItem.getWidth();
int menuHeight = menuItem.getHeight();
g.setColor(UIConstants.NORMAL_BACKGROUND);
g.fillRect(0, 0, menuWidth, menuHeight);
if (menuItem.isOpaque()) {
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) {
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 0);
} else {
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.TOOLBARUI_BACKGROUND, 0);
}
g.setColor(oldColor);
}
else if (model.isArmed() || (menuItem instanceof JMenu &&
model.isSelected())) {
GUIPaintUtils.fillPaint((Graphics2D)g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7);
g.setColor(oldColor);
}
}
protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) {
ButtonModel model = menuItem.getModel();
FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g);
if(!model.isEnabled()) {
// *** paint the text disabled
if ( UIManager.get("MenuItem.disabledForeground") instanceof Color ) {
g.setColor( UIManager.getColor("MenuItem.disabledForeground") );
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g,text,
-1, textRect.x, textRect.y + fm.getAscent());
} else {
g.setColor(menuItem.getBackground().brighter());
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
-1, textRect.x, textRect.y + fm.getAscent());
g.setColor(menuItem.getBackground().darker());
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g,text,
-1, textRect.x - 1, textRect.y +
fm.getAscent() - 1);
}
} else {
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
-1, -4, textRect.y + fm.getAscent());
}
}
}
}

12
designer_base/src/com/fr/design/gui/imenu/UIPopupMenu.java

@ -9,26 +9,26 @@ import com.fr.design.constants.UIConstants;
public class UIPopupMenu extends JPopupMenu {
private boolean onlyText = false;
private boolean rePaint = false;
private boolean isEastAttr = false;
public UIPopupMenu() {
super();
setBackground(UIConstants.NORMAL_BACKGROUND);
}
public UIPopupMenu(boolean rePaint) {
public UIPopupMenu(boolean isEastAttr) {
super();
this.rePaint = rePaint;
this.isEastAttr = isEastAttr;
setBackground(UIConstants.TOOLBARUI_BACKGROUND);
}
public boolean getRePaint() {
return this.rePaint;
return this.isEastAttr;
}
@Override
protected void paintBorder(Graphics g) {
if (rePaint) {
if (isEastAttr) {
g.setColor(UIConstants.POP_DIALOG_BORDER);
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
} else {
@ -42,7 +42,7 @@ public class UIPopupMenu extends JPopupMenu {
if (onlyText) {
return super.getInsets();
}
if (rePaint) {
if (isEastAttr) {
return new Insets(0, 1, 1, 1);
} else {
return new Insets(10, 2, 10, 10);

10
designer_base/src/com/fr/design/menu/MenuDef.java

@ -28,7 +28,7 @@ public class MenuDef extends ShortCut {
private static final int MENU_DEFAULTWDITH = 156;
protected String name;
//右侧属性表弹出框重绘
protected Boolean rePaint = false;
protected Boolean isEastAttr = false;
protected char mnemonic;
protected String iconPath;
protected String tooltip;
@ -68,11 +68,11 @@ public class MenuDef extends ShortCut {
}
public boolean getRePaint() {
return rePaint;
return isEastAttr;
}
public void setRePaint(boolean rePaint) {
this.rePaint = rePaint;
this.isEastAttr = rePaint;
}
public char getMnemonic() {
@ -401,8 +401,8 @@ public class MenuDef extends ShortCut {
if (!button.isEnabled()) {
return;
}
if (rePaint) {
popupMenu = new UIPopupMenu(rePaint);
if (isEastAttr) {
popupMenu = new UIPopupMenu(isEastAttr);
popupMenu.setInvoker(button);
MenuDef.this.updateEastPopupMenu(popupMenu);
popupMenu.setPopupSize(new Dimension(MENU_DEFAULTWDITH, popupMenu.getPreferredSize().height));

Loading…
Cancel
Save