Browse Source

REPORT-6441 ctrl快捷键失灵 同步到10

master
yaoh.wu 7 years ago
parent
commit
9230383687
  1. 126
      designer_base/src/com/fr/design/gui/imenu/UIHeadMenu.java
  2. 610
      designer_base/src/com/fr/design/gui/imenu/UIMenu.java
  3. 118
      designer_base/src/com/fr/design/gui/imenu/UIScrollMenu.java
  4. 65
      designer_form/src/com/fr/design/mainframe/FormParaWidgetPane.java

126
designer_base/src/com/fr/design/gui/imenu/UIHeadMenu.java

@ -3,10 +3,22 @@ package com.fr.design.gui.imenu;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.utils.gui.GUIPaintUtils; import com.fr.design.utils.gui.GUIPaintUtils;
import javax.swing.*; import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.MenuElement;
import javax.swing.border.Border; import javax.swing.border.Border;
import java.awt.*; import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.RenderingHints;
import java.awt.Shape;
/**
* @author null
*/
public class UIHeadMenu extends UIMenu { public class UIHeadMenu extends UIMenu {
private static final float REC = 8f; private static final float REC = 8f;
private JPopupMenu popupMenu; private JPopupMenu popupMenu;
@ -15,6 +27,7 @@ public class UIHeadMenu extends UIMenu {
super(name); super(name);
} }
@Override
public JPopupMenu getPopupMenu() { public JPopupMenu getPopupMenu() {
ensurePopupMenuCreated(); ensurePopupMenuCreated();
popupMenu.setBackground(UIConstants.NORMAL_BACKGROUND); popupMenu.setBackground(UIConstants.NORMAL_BACKGROUND);
@ -44,16 +57,17 @@ public class UIHeadMenu extends UIMenu {
return popupMenu; return popupMenu;
} }
@Override
protected void ensurePopupMenuCreated() { protected void ensurePopupMenuCreated() {
if (popupMenu == null) { if (popupMenu == null) {
this.popupMenu = new JPopupMenu() { this.popupMenu = new JPopupMenu() {
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
float wdith = getWidth(); float width = getWidth();
float heigth = getHeight(); float height = getHeight();
Shape shape = GUIPaintUtils.paintShape(g2d, wdith, heigth, REC); Shape shape = GUIPaintUtils.paintShape(g2d, width, height, REC);
g2d.setClip(shape); g2d.setClip(shape);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
super.paintComponent(g2d); super.paintComponent(g2d);
@ -65,7 +79,7 @@ public class UIHeadMenu extends UIMenu {
} }
/** /**
*画界面 * 画界面
*/ */
@Override @Override
public void updateUI() { public void updateUI() {
@ -74,8 +88,10 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 判断popupmeu是否隐藏 * 判断popupmeu是否隐藏
* @return 如果隐藏 返回true *
* @return 如果隐藏 返回true
*/ */
@Override
public boolean isPopupMenuVisible() { public boolean isPopupMenuVisible() {
ensurePopupMenuCreated(); ensurePopupMenuCreated();
return popupMenu.isVisible(); return popupMenu.isVisible();
@ -84,9 +100,11 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 设置popupmenu位置 * 设置popupmenu位置
* @param x *
* @param y * @param x x
* @param y y
*/ */
@Override
public void setMenuLocation(int x, int y) { public void setMenuLocation(int x, int y) {
super.setMenuLocation(x, y); super.setMenuLocation(x, y);
if (popupMenu != null) { if (popupMenu != null) {
@ -96,9 +114,11 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 向popupmenu添加 JMenuItem * 向popupmenu添加 JMenuItem
*
* @param menuItem 菜单项 * @param menuItem 菜单项
* @return 菜单项 * @return 菜单项
*/ */
@Override
public JMenuItem add(JMenuItem menuItem) { public JMenuItem add(JMenuItem menuItem) {
ensurePopupMenuCreated(); ensurePopupMenuCreated();
return popupMenu.add(menuItem); return popupMenu.add(menuItem);
@ -106,9 +126,11 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 添加组件 * 添加组件
* @param c 组件 *
* @return 组件 * @param c 组件
* @return 组件
*/ */
@Override
public Component add(Component c) { public Component add(Component c) {
ensurePopupMenuCreated(); ensurePopupMenuCreated();
popupMenu.add(c); popupMenu.add(c);
@ -117,10 +139,12 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 向指定位置添加组件 * 向指定位置添加组件
* @param c 组件 *
* @param index 位置 * @param c 组件
* @return 组件 * @param index 位置
* @return 组件
*/ */
@Override
public Component add(Component c, int index) { public Component add(Component c, int index) {
ensurePopupMenuCreated(); ensurePopupMenuCreated();
popupMenu.add(c, index); popupMenu.add(c, index);
@ -131,6 +155,7 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 添加分隔符 * 添加分隔符
*/ */
@Override
public void addSeparator() { public void addSeparator() {
ensurePopupMenuCreated(); ensurePopupMenuCreated();
popupMenu.addSeparator(); popupMenu.addSeparator();
@ -138,9 +163,11 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 添加menuitem到指定位置 * 添加menuitem到指定位置
* @param s 字符 *
* @param pos 位置 * @param s 字符
* @param pos 位置
*/ */
@Override
public void insert(String s, int pos) { public void insert(String s, int pos) {
if (pos < 0) { if (pos < 0) {
throw new IllegalArgumentException("index less than zero."); throw new IllegalArgumentException("index less than zero.");
@ -152,10 +179,12 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 添加么会特么到指定位置 * 添加么会特么到指定位置
* @param mi 菜单项 *
* @param pos 位置 * @param mi 菜单项
* @return 菜单项 * @param pos 位置
* @return 菜单项
*/ */
@Override
public JMenuItem insert(JMenuItem mi, int pos) { public JMenuItem insert(JMenuItem mi, int pos) {
if (pos < 0) { if (pos < 0) {
throw new IllegalArgumentException("index less than zero."); throw new IllegalArgumentException("index less than zero.");
@ -167,10 +196,12 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 添加到指定位置 * 添加到指定位置
* @param a 事件 *
* @param pos 位置 * @param a 事件
* @return 菜单项 * @param pos 位置
* @return 菜单项
*/ */
@Override
public JMenuItem insert(Action a, int pos) { public JMenuItem insert(Action a, int pos) {
if (pos < 0) { if (pos < 0) {
throw new IllegalArgumentException("index less than zero."); throw new IllegalArgumentException("index less than zero.");
@ -185,9 +216,11 @@ public class UIHeadMenu extends UIMenu {
} }
/** /**
* 添加分隔符到指定位置 * 添加分隔符到指定位置
* @param index 指定位置 *
* @param index 指定位置
*/ */
@Override
public void insertSeparator(int index) { public void insertSeparator(int index) {
if (index < 0) { if (index < 0) {
throw new IllegalArgumentException("index less than zero."); throw new IllegalArgumentException("index less than zero.");
@ -200,8 +233,10 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 移除 * 移除
* @param item 菜单项 *
* @param item 菜单项
*/ */
@Override
public void remove(JMenuItem item) { public void remove(JMenuItem item) {
if (popupMenu != null) { if (popupMenu != null) {
popupMenu.remove(item); popupMenu.remove(item);
@ -210,8 +245,10 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 移除指定位置菜单项 * 移除指定位置菜单项
* @param pos 指定位置 *
* @param pos 指定位置
*/ */
@Override
public void remove(int pos) { public void remove(int pos) {
if (pos < 0) { if (pos < 0) {
throw new IllegalArgumentException("index less than zero."); throw new IllegalArgumentException("index less than zero.");
@ -226,8 +263,10 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 移除组件 * 移除组件
* @param c 组件 *
* @param c 组件
*/ */
@Override
public void remove(Component c) { public void remove(Component c) {
if (popupMenu != null) { if (popupMenu != null) {
popupMenu.remove(c); popupMenu.remove(c);
@ -237,6 +276,7 @@ public class UIHeadMenu extends UIMenu {
/** /**
* 移除所有 * 移除所有
*/ */
@Override
public void removeAll() { public void removeAll() {
if (popupMenu != null) { if (popupMenu != null) {
popupMenu.removeAll(); popupMenu.removeAll();
@ -244,31 +284,45 @@ public class UIHeadMenu extends UIMenu {
} }
/** /**
* 组件总数 * 组件总数
* @return 组件总数 *
* @return 组件总数
*/ */
@Override
public int getMenuComponentCount() { public int getMenuComponentCount() {
return (popupMenu == null) ? 0 : popupMenu.getComponentCount(); return (popupMenu == null) ? 0 : popupMenu.getComponentCount();
} }
/** /**
* 指定位置组件 * 指定位置组件
* @param n 指定位置 *
* @return 组件 * @param n 指定位置
* @return 组件
*/ */
@Override
public Component getMenuComponent(int n) { public Component getMenuComponent(int n) {
return (popupMenu == null) ? null : popupMenu.getComponent(n); return (popupMenu == null) ? null : popupMenu.getComponent(n);
} }
/** /**
* 所有组件 * 所有组件
* @return 所有组件 *
* @return 所有组件
*/ */
@Override
public Component[] getMenuComponents() { public Component[] getMenuComponents() {
return (popupMenu == null) ? new Component[0] : popupMenu.getComponents(); return (popupMenu == null) ? new Component[0] : popupMenu.getComponents();
} }
@Override
public MenuElement[] getSubElements() {
if (popupMenu == null) {
return new MenuElement[0];
} else {
MenuElement[] result = new MenuElement[1];
result[0] = popupMenu;
return result;
}
}
} }

610
designer_base/src/com/fr/design/gui/imenu/UIMenu.java

@ -3,285 +3,341 @@ package com.fr.design.gui.imenu;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.*; import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.MenuElement;
import javax.swing.border.Border; import javax.swing.border.Border;
import java.awt.*; import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
/**
* @author null
*/
public class UIMenu extends JMenu { public class UIMenu extends JMenu {
private static final float REC = 8f; private static final float REC = 8f;
private JPopupMenu popupMenu; private JPopupMenu popupMenu;
public UIMenu(String name) { public UIMenu(String name) {
super(name); super(name);
setName(name); setName(name);
setRolloverEnabled(true); setRolloverEnabled(true);
setBackground(UIConstants.NORMAL_BACKGROUND); setBackground(UIConstants.NORMAL_BACKGROUND);
} }
@Override @Override
public String getText() { public String getText() {
if (this.getParent() instanceof JPopupMenu) { if (this.getParent() instanceof JPopupMenu) {
return StringUtils.BLANK + super.getText(); return StringUtils.BLANK + super.getText();
} }
return " " + super.getText(); return " " + super.getText();
} }
public JPopupMenu getPopupMenu() { @Override
ensurePopupMenuCreated(); public JPopupMenu getPopupMenu() {
popupMenu.setOpaque(false); ensurePopupMenuCreated();
popupMenu.setBorder(new Border() { popupMenu.setOpaque(false);
popupMenu.setBorder(new Border() {
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { @Override
Graphics2D g2d = (Graphics2D) g; public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
int rec = (int) REC; Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); int rec = (int) REC;
g2d.setColor(UIConstants.UIPOPUPMENU_LINE_COLOR); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
g2d.drawRoundRect(x, y, width - 1, height - 1,rec, rec); g2d.setColor(UIConstants.UIPOPUPMENU_LINE_COLOR);
if (!(UIMenu.this.getParent() instanceof JPopupMenu)) { g2d.drawRoundRect(x, y, width - 1, height - 1, rec, rec);
g.setColor(UIConstants.NORMAL_BACKGROUND); if (!(UIMenu.this.getParent() instanceof JPopupMenu)) {
g.drawLine(1, 0, UIMenu.this.getWidth() - 2, 0); g.setColor(UIConstants.NORMAL_BACKGROUND);
} g.drawLine(1, 0, UIMenu.this.getWidth() - 2, 0);
} }
}
@Override
public boolean isBorderOpaque() { @Override
return false; public boolean isBorderOpaque() {
} return false;
}
@Override
public Insets getBorderInsets(Component c) { @Override
return new Insets(5, 2, 10, 10); public Insets getBorderInsets(Component c) {
} return new Insets(5, 2, 10, 10);
}); }
return popupMenu; });
} return popupMenu;
}
protected void ensurePopupMenuCreated() {
if (popupMenu == null) { protected void ensurePopupMenuCreated() {
this.popupMenu = new JPopupMenu() { if (popupMenu == null) {
@Override this.popupMenu = new JPopupMenu() {
protected void paintComponent(Graphics g) { @Override
Graphics2D g2d = (Graphics2D) g; protected void paintComponent(Graphics g) {
int rec = (int) REC; Graphics2D g2d = (Graphics2D) g;
Shape shape = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), REC, REC); int rec = (int) REC;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Shape shape = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), REC, REC);
g2d.setColor(UIConstants.NORMAL_BACKGROUND); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.fillRoundRect(0, 0, getWidth(), getHeight(), rec, rec); g2d.setColor(UIConstants.NORMAL_BACKGROUND);
g2d.setClip(shape); g2d.fillRoundRect(0, 0, getWidth(), getHeight(), rec, rec);
super.paintComponent(g2d); g2d.setClip(shape);
} super.paintComponent(g2d);
}
};
popupMenu.setInvoker(this); };
popupMenu.setInvoker(this);
popupListener = createWinListener(popupMenu);
} popupListener = createWinListener(popupMenu);
} }
}
/**
*画界面 /**
*/ * 画界面
@Override */
public void updateUI() { @Override
setUI(new UIMenuUI()); public void updateUI() {
} setUI(new UIMenuUI());
}
/**
* 判断popupmeu是否隐藏 /**
* @return 如果隐藏 返回true * 判断popupmeu是否隐藏
*/ *
public boolean isPopupMenuVisible() { * @return 如果隐藏 返回true
ensurePopupMenuCreated(); */
return popupMenu.isVisible(); @Override
} public boolean isPopupMenuVisible() {
ensurePopupMenuCreated();
return popupMenu.isVisible();
/** }
* 设置popupmenu位置
* @param x
* @param y /**
*/ * 设置popupmenu位置
public void setMenuLocation(int x, int y) { *
super.setMenuLocation(x, y); * @param x x
if (popupMenu != null) { * @param y y
popupMenu.setLocation(x, y); */
} @Override
} public void setMenuLocation(int x, int y) {
super.setMenuLocation(x, y);
/** if (popupMenu != null) {
* 向popupmenu添加 JMenuItem popupMenu.setLocation(x, y);
* @param menuItem 菜单项 }
* @return 菜单项 }
*/
public JMenuItem add(JMenuItem menuItem) { /**
ensurePopupMenuCreated(); * 向popupmenu添加 JMenuItem
return popupMenu.add(menuItem); *
} * @param menuItem 菜单项
* @return 菜单项
/** */
* 添加组件 @Override
* @param c 组件 public JMenuItem add(JMenuItem menuItem) {
* @return 组件 ensurePopupMenuCreated();
*/ return popupMenu.add(menuItem);
public Component add(Component c) { }
ensurePopupMenuCreated();
popupMenu.add(c); /**
return c; * 添加组件
} *
* @param c 组件
/** * @return 组件
* 向指定位置添加组件 */
* @param c 组件 @Override
* @param index 位置 public Component add(Component c) {
* @return 组件 ensurePopupMenuCreated();
*/ popupMenu.add(c);
public Component add(Component c, int index) { return c;
ensurePopupMenuCreated(); }
popupMenu.add(c, index);
return c; /**
} * 向指定位置添加组件
*
* @param c 组件
/** * @param index 位置
* 添加分隔符 * @return 组件
*/ */
public void addSeparator() { @Override
ensurePopupMenuCreated(); public Component add(Component c, int index) {
popupMenu.addSeparator(); ensurePopupMenuCreated();
} popupMenu.add(c, index);
return c;
/** }
* 添加menuitem到指定位置
* @param s 字符
* @param pos 位置 /**
*/ * 添加分隔符
public void insert(String s, int pos) { */
if (pos < 0) { @Override
throw new IllegalArgumentException("index less than zero."); public void addSeparator() {
} ensurePopupMenuCreated();
popupMenu.addSeparator();
ensurePopupMenuCreated(); }
popupMenu.insert(new JMenuItem(s), pos);
} /**
* 添加menuitem到指定位置
/** *
* 添加么会特么到指定位置 * @param s 字符
* @param mi 菜单项 * @param pos 位置
* @param pos 位置 */
* @return 菜单项 @Override
*/ public void insert(String s, int pos) {
public JMenuItem insert(JMenuItem mi, int pos) { if (pos < 0) {
if (pos < 0) { throw new IllegalArgumentException("index less than zero.");
throw new IllegalArgumentException("index less than zero."); }
}
ensurePopupMenuCreated(); ensurePopupMenuCreated();
popupMenu.insert(mi, pos); popupMenu.insert(new JMenuItem(s), pos);
return mi; }
}
/**
/** * 添加么会特么到指定位置
* 添加到指定位置 *
* @param a 事件 * @param mi 菜单项
* @param pos 位置 * @param pos 位置
* @return 菜单项 * @return 菜单项
*/ */
public JMenuItem insert(Action a, int pos) { @Override
if (pos < 0) { public JMenuItem insert(JMenuItem mi, int pos) {
throw new IllegalArgumentException("index less than zero."); if (pos < 0) {
} throw new IllegalArgumentException("index less than zero.");
}
ensurePopupMenuCreated(); ensurePopupMenuCreated();
JMenuItem mi = new JMenuItem(a); popupMenu.insert(mi, pos);
mi.setHorizontalTextPosition(JButton.TRAILING); return mi;
mi.setVerticalTextPosition(JButton.CENTER); }
popupMenu.insert(mi, pos);
return mi; /**
} * 添加到指定位置
*
/** * @param a 事件
* 添加分隔符到指定位置 * @param pos 位置
* @param index 指定位置 * @return 菜单项
*/ */
public void insertSeparator(int index) { @Override
if (index < 0) { public JMenuItem insert(Action a, int pos) {
throw new IllegalArgumentException("index less than zero."); if (pos < 0) {
} throw new IllegalArgumentException("index less than zero.");
}
ensurePopupMenuCreated(); ensurePopupMenuCreated();
popupMenu.insert(new JPopupMenu.Separator(), index); JMenuItem mi = new JMenuItem(a);
} mi.setHorizontalTextPosition(JButton.TRAILING);
mi.setVerticalTextPosition(JButton.CENTER);
popupMenu.insert(mi, pos);
/** return mi;
* 移除 }
* @param item 菜单项
*/ /**
public void remove(JMenuItem item) { * 添加分隔符到指定位置
if (popupMenu != null) { *
popupMenu.remove(item); * @param index 指定位置
} */
} @Override
public void insertSeparator(int index) {
/** if (index < 0) {
* 移除指定位置菜单项 throw new IllegalArgumentException("index less than zero.");
* @param pos 指定位置 }
*/
public void remove(int pos) { ensurePopupMenuCreated();
if (pos < 0) { popupMenu.insert(new JPopupMenu.Separator(), index);
throw new IllegalArgumentException("index less than zero."); }
}
if (pos > getItemCount()) {
throw new IllegalArgumentException("index greater than the number of items."); /**
} * 移除
if (popupMenu != null) { *
popupMenu.remove(pos); * @param item 菜单项
} */
} @Override
public void remove(JMenuItem item) {
/** if (popupMenu != null) {
* 移除组件 popupMenu.remove(item);
* @param c 组件 }
*/ }
public void remove(Component c) {
if (popupMenu != null) { /**
popupMenu.remove(c); * 移除指定位置菜单项
} *
} * @param pos 指定位置
*/
/** @Override
* 移除所有 public void remove(int pos) {
*/ if (pos < 0) {
public void removeAll() { throw new IllegalArgumentException("index less than zero.");
if (popupMenu != null) { }
popupMenu.removeAll(); if (pos > getItemCount()) {
} throw new IllegalArgumentException("index greater than the number of items.");
} }
if (popupMenu != null) {
/** popupMenu.remove(pos);
* 组件总数 }
* @return 组件总数 }
*/
public int getMenuComponentCount() { /**
return (popupMenu == null) ? 0 : popupMenu.getComponentCount(); * 移除组件
} *
* @param c 组件
/** */
* 指定位置组件 @Override
* @param n 指定位置 public void remove(Component c) {
* @return 组件 if (popupMenu != null) {
*/ popupMenu.remove(c);
public Component getMenuComponent(int n) { }
return (popupMenu == null) ? null : popupMenu.getComponent(n); }
}
/**
/** * 移除所有
* 所有组件 */
* @return 所有组件 @Override
*/ public void removeAll() {
public Component[] getMenuComponents() { if (popupMenu != null) {
return (popupMenu == null) ? new Component[0] : popupMenu.getComponents(); popupMenu.removeAll();
} }
}
/**
* 组件总数
*
* @return 组件总数
*/
@Override
public int getMenuComponentCount() {
return (popupMenu == null) ? 0 : popupMenu.getComponentCount();
}
/**
* 指定位置组件
*
* @param n 指定位置
* @return 组件
*/
@Override
public Component getMenuComponent(int n) {
return (popupMenu == null) ? null : popupMenu.getComponent(n);
}
/**
* 所有组件
*
* @return 所有组件
*/
@Override
public Component[] getMenuComponents() {
return (popupMenu == null) ? new Component[0] : popupMenu.getComponents();
}
@Override
public MenuElement[] getSubElements() {
if (popupMenu == null) {
return new MenuElement[0];
} else {
MenuElement[] result = new MenuElement[1];
result[0] = popupMenu;
return result;
}
}
} }

118
designer_base/src/com/fr/design/gui/imenu/UIScrollMenu.java

@ -1,16 +1,22 @@
package com.fr.design.gui.imenu; package com.fr.design.gui.imenu;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.MenuElement;
import java.awt.Component;
import java.awt.ComponentOrientation;
/** /**
* Created with IntelliJ IDEA. * Created with IntelliJ IDEA.
* User: richie * User: richie
* Date: 13-12-5 * Date: 13-12-5
* Time: 上午11:11 * Time: 上午11:11
*
* @author richie
*/ */
import javax.swing.*;
import java.awt.*;
public class UIScrollMenu extends UIMenu { public class UIScrollMenu extends UIMenu {
// Covers the one in the JMenu because the method that creates it in JMenu is private // Covers the one in the JMenu because the method that creates it in JMenu is private
/** /**
@ -49,6 +55,7 @@ public class UIScrollMenu extends UIMenu {
/** /**
* Lazily creates the popup menu. This method will create the popup using the <code>JScrollPopupMenu</code> class. * Lazily creates the popup menu. This method will create the popup using the <code>JScrollPopupMenu</code> class.
*/ */
@Override
protected void ensurePopupMenuCreated() { protected void ensurePopupMenuCreated() {
if (popupMenu == null) { if (popupMenu == null) {
this.popupMenu = new UIScrollPopUpMenu(); this.popupMenu = new UIScrollPopUpMenu();
@ -62,17 +69,20 @@ public class UIScrollMenu extends UIMenu {
////////////////////////////// //////////////////////////////
/** /**
*画界面 * 画界面
*/ */
@Override
public void updateUI() { public void updateUI() {
setUI(new UIMenuUI()); setUI(new UIMenuUI());
} }
/** /**
* 判断popupmeu是否隐藏 * 判断popupmeu是否隐藏
* @return 如果隐藏 返回true *
* @return 如果隐藏 返回true
*/ */
@Override
public boolean isPopupMenuVisible() { public boolean isPopupMenuVisible() {
ensurePopupMenuCreated(); ensurePopupMenuCreated();
return popupMenu.isVisible(); return popupMenu.isVisible();
@ -81,9 +91,11 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 设置popupmenu位置 * 设置popupmenu位置
*
* @param x * @param x
* @param y * @param y
*/ */
@Override
public void setMenuLocation(int x, int y) { public void setMenuLocation(int x, int y) {
super.setMenuLocation(x, y); super.setMenuLocation(x, y);
if (popupMenu != null) { if (popupMenu != null) {
@ -93,9 +105,11 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 向popupmenu添加 JMenuItem * 向popupmenu添加 JMenuItem
*
* @param menuItem 菜单项 * @param menuItem 菜单项
* @return 菜单项 * @return 菜单项
*/ */
@Override
public JMenuItem add(JMenuItem menuItem) { public JMenuItem add(JMenuItem menuItem) {
ensurePopupMenuCreated(); ensurePopupMenuCreated();
return popupMenu.add(menuItem); return popupMenu.add(menuItem);
@ -103,9 +117,11 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 添加组件 * 添加组件
* @param c 组件 *
* @return 组件 * @param c 组件
* @return 组件
*/ */
@Override
public Component add(Component c) { public Component add(Component c) {
ensurePopupMenuCreated(); ensurePopupMenuCreated();
popupMenu.add(c); popupMenu.add(c);
@ -114,10 +130,12 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 向指定位置添加组件 * 向指定位置添加组件
* @param c 组件 *
* @param index 位置 * @param c 组件
* @return 组件 * @param index 位置
* @return 组件
*/ */
@Override
public Component add(Component c, int index) { public Component add(Component c, int index) {
ensurePopupMenuCreated(); ensurePopupMenuCreated();
popupMenu.add(c, index); popupMenu.add(c, index);
@ -128,6 +146,7 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 添加分隔符 * 添加分隔符
*/ */
@Override
public void addSeparator() { public void addSeparator() {
ensurePopupMenuCreated(); ensurePopupMenuCreated();
popupMenu.addSeparator(); popupMenu.addSeparator();
@ -135,9 +154,11 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 添加menuitem到指定位置 * 添加menuitem到指定位置
* @param s 字符 *
* @param pos 位置 * @param s 字符
* @param pos 位置
*/ */
@Override
public void insert(String s, int pos) { public void insert(String s, int pos) {
if (pos < 0) { if (pos < 0) {
throw new IllegalArgumentException("index less than zero."); throw new IllegalArgumentException("index less than zero.");
@ -149,10 +170,12 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 添加么会特么到指定位置 * 添加么会特么到指定位置
* @param mi 菜单项 *
* @param pos 位置 * @param mi 菜单项
* @return 菜单项 * @param pos 位置
* @return 菜单项
*/ */
@Override
public JMenuItem insert(JMenuItem mi, int pos) { public JMenuItem insert(JMenuItem mi, int pos) {
if (pos < 0) { if (pos < 0) {
throw new IllegalArgumentException("index less than zero."); throw new IllegalArgumentException("index less than zero.");
@ -164,10 +187,12 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 添加到指定位置 * 添加到指定位置
* @param a 事件 *
* @param pos 位置 * @param a 事件
* @return 菜单项 * @param pos 位置
* @return 菜单项
*/ */
@Override
public JMenuItem insert(Action a, int pos) { public JMenuItem insert(Action a, int pos) {
if (pos < 0) { if (pos < 0) {
throw new IllegalArgumentException("index less than zero."); throw new IllegalArgumentException("index less than zero.");
@ -182,9 +207,11 @@ public class UIScrollMenu extends UIMenu {
} }
/** /**
* 添加分隔符到指定位置 * 添加分隔符到指定位置
* @param index 指定位置 *
* @param index 指定位置
*/ */
@Override
public void insertSeparator(int index) { public void insertSeparator(int index) {
if (index < 0) { if (index < 0) {
throw new IllegalArgumentException("index less than zero."); throw new IllegalArgumentException("index less than zero.");
@ -197,8 +224,10 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 移除 * 移除
* @param item 菜单项 *
* @param item 菜单项
*/ */
@Override
public void remove(JMenuItem item) { public void remove(JMenuItem item) {
if (popupMenu != null) { if (popupMenu != null) {
popupMenu.remove(item); popupMenu.remove(item);
@ -207,8 +236,10 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 移除指定位置菜单项 * 移除指定位置菜单项
* @param pos 指定位置 *
* @param pos 指定位置
*/ */
@Override
public void remove(int pos) { public void remove(int pos) {
if (pos < 0) { if (pos < 0) {
throw new IllegalArgumentException("index less than zero."); throw new IllegalArgumentException("index less than zero.");
@ -223,8 +254,10 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 移除组件 * 移除组件
* @param c 组件 *
* @param c 组件
*/ */
@Override
public void remove(Component c) { public void remove(Component c) {
if (popupMenu != null) { if (popupMenu != null) {
popupMenu.remove(c); popupMenu.remove(c);
@ -234,6 +267,7 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 移除所有 * 移除所有
*/ */
@Override
public void removeAll() { public void removeAll() {
if (popupMenu != null) { if (popupMenu != null) {
popupMenu.removeAll(); popupMenu.removeAll();
@ -241,34 +275,42 @@ public class UIScrollMenu extends UIMenu {
} }
/** /**
* 组件总数 * 组件总数
* @return 组件总数 *
* @return 组件总数
*/ */
@Override
public int getMenuComponentCount() { public int getMenuComponentCount() {
return (popupMenu == null) ? 0 : popupMenu.getComponentCount(); return (popupMenu == null) ? 0 : popupMenu.getComponentCount();
} }
/** /**
* 指定位置组件 * 指定位置组件
* @param n 指定位置 *
* @return 组件 * @param n 指定位置
* @return 组件
*/ */
@Override
public Component getMenuComponent(int n) { public Component getMenuComponent(int n) {
return (popupMenu == null) ? null : popupMenu.getComponent(n); return (popupMenu == null) ? null : popupMenu.getComponent(n);
} }
/** /**
* 所有组件 * 所有组件
* @return 所有组件 *
* @return 所有组件
*/ */
@Override
public Component[] getMenuComponents() { public Component[] getMenuComponents() {
return (popupMenu == null) ? new Component[0] : popupMenu.getComponents(); return (popupMenu == null) ? new Component[0] : popupMenu.getComponents();
} }
/** /**
* 取得弹出菜单 * 取得弹出菜单
* @return 菜单 *
* @return 菜单
*/ */
@Override
public JPopupMenu getPopupMenu() { public JPopupMenu getPopupMenu() {
ensurePopupMenuCreated(); ensurePopupMenuCreated();
return popupMenu; return popupMenu;
@ -276,17 +318,21 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 得到子元素 * 得到子元素
* @return 子元素 *
* @return 子元素
*/ */
@Override
public MenuElement[] getSubElements() { public MenuElement[] getSubElements() {
return popupMenu == null ? new MenuElement[0] : new MenuElement[]{popupMenu}; return popupMenu == null ? new MenuElement[0] : new MenuElement[]{popupMenu};
} }
/** /**
* 设置所有组件方位 * 设置所有组件方位
*
* @param o 方位 * @param o 方位
*/ */
@Override
public void applyComponentOrientation(ComponentOrientation o) { public void applyComponentOrientation(ComponentOrientation o) {
super.applyComponentOrientation(o); super.applyComponentOrientation(o);
@ -301,8 +347,10 @@ public class UIScrollMenu extends UIMenu {
/** /**
* 设置所有组件方位 * 设置所有组件方位
*
* @param o 方位 * @param o 方位
*/ */
@Override
public void setComponentOrientation(ComponentOrientation o) { public void setComponentOrientation(ComponentOrientation o) {
super.setComponentOrientation(o); super.setComponentOrientation(o);
if (popupMenu != null) { if (popupMenu != null) {

65
designer_form/src/com/fr/design/mainframe/FormParaWidgetPane.java

@ -16,7 +16,10 @@ import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.imenu.UIPopupMenu; import com.fr.design.gui.imenu.UIPopupMenu;
import com.fr.design.module.DesignModuleFactory; import com.fr.design.module.DesignModuleFactory;
import com.fr.design.utils.gui.LayoutUtils; import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.*; import com.fr.form.ui.UserDefinedWidgetConfig;
import com.fr.form.ui.Widget;
import com.fr.form.ui.WidgetConfig;
import com.fr.form.ui.WidgetInfoConfig;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralContext; import com.fr.general.GeneralContext;
import com.fr.general.Inter; import com.fr.general.Inter;
@ -27,16 +30,26 @@ import com.fr.plugin.observer.PluginEvent;
import com.fr.plugin.observer.PluginEventListener; import com.fr.plugin.observer.PluginEventListener;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import javax.swing.*; import javax.swing.JComponent;
import java.awt.*; import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ComponentAdapter; import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent; import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
/**
* @author null
*/
public class FormParaWidgetPane extends JPanel { public class FormParaWidgetPane extends JPanel {
private static FormParaWidgetPane THIS; private static FormParaWidgetPane THIS;
private final static int BORDER = 5; private final static int BORDER = 5;
@ -69,28 +82,28 @@ public class FormParaWidgetPane extends JPanel {
private UILabel paraLabel; private UILabel paraLabel;
private FormDesigner designer; private FormDesigner designer;
static { static {
GeneralContext.listenPluginRunningChanged(new PluginEventListener() { GeneralContext.listenPluginRunningChanged(new PluginEventListener() {
@Override @Override
public void on(PluginEvent event) { public void on(PluginEvent event) {
synchronized (FormParaWidgetPane.class) { synchronized (FormParaWidgetPane.class) {
THIS = null; THIS = null;
} }
} }
}, new PluginFilter() { }, new PluginFilter() {
@Override @Override
public boolean accept(PluginContext context) { public boolean accept(PluginContext context) {
return context.contain(PluginModule.ExtraDesign, FormWidgetOptionProvider.XML_TAG); return context.contain(PluginModule.ExtraDesign, FormWidgetOptionProvider.XML_TAG);
} }
}); });
} }
public static synchronized final FormParaWidgetPane getInstance(FormDesigner designer) { public static synchronized FormParaWidgetPane getInstance(FormDesigner designer) {
if (THIS == null) { if (THIS == null) {
THIS = new FormParaWidgetPane(); THIS = new FormParaWidgetPane();
} }
@ -102,21 +115,22 @@ public class FormParaWidgetPane extends JPanel {
public FormParaWidgetPane() { public FormParaWidgetPane() {
setLayout(new FlowLayout(FlowLayout.LEFT)); setLayout(new FlowLayout(FlowLayout.LEFT));
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().addComponentListener(new ComponentAdapter() { DesignerContext.getDesignerFrame().getCenterTemplateCardPane().addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
if (FormParaWidgetPane.this.getParent() != null) { if (FormParaWidgetPane.this.getParent() != null) {
JPanel fother = (JPanel) FormParaWidgetPane.this.getParent(); JPanel parent = (JPanel) FormParaWidgetPane.this.getParent();
int delta_wdith = 0; int deltaWidth = 0;
for (int i = 0; i < fother.getComponentCount() - 1; i++) { for (int i = 0; i < parent.getComponentCount() - 1; i++) {
delta_wdith += fother.getComponent(i).getWidth(); deltaWidth += parent.getComponent(i).getWidth();
} }
if (delta_wdith == 0) { if (deltaWidth == 0) {
return; return;
} }
Dimension d = fother.getSize(); Dimension d = parent.getSize();
setPreferredSize(new Dimension(d.width - delta_wdith, d.height)); setPreferredSize(new Dimension(d.width - deltaWidth, d.height));
LayoutUtils.layoutContainer(fother); LayoutUtils.layoutContainer(parent);
} }
} }
}); });
@ -158,7 +172,7 @@ public class FormParaWidgetPane extends JPanel {
} }
private void initChartTypePopUp() { private void initChartTypePopUp() {
if (chartTypePopupMenu == null){ if (chartTypePopupMenu == null) {
JPanel componentsPara = new JPanel(new FlowLayout(FlowLayout.LEFT)); JPanel componentsPara = new JPanel(new FlowLayout(FlowLayout.LEFT));
WidgetOption[] chartOptions = loadChartOptions(); WidgetOption[] chartOptions = loadChartOptions();
for (WidgetOption chartOption : chartOptions) { for (WidgetOption chartOption : chartOptions) {
@ -223,9 +237,7 @@ public class FormParaWidgetPane extends JPanel {
predifinedwidgeList.clear(); predifinedwidgeList.clear();
if (designer != null) { if (designer != null) {
WidgetOption[] designerPre = designer.getDesignerMode().getPredefinedWidgetOptions(); WidgetOption[] designerPre = designer.getDesignerMode().getPredefinedWidgetOptions();
for (int i = 0; i < designerPre.length; i++) { predifinedwidgeList.addAll(Arrays.asList(designerPre));
predifinedwidgeList.add(designerPre[i]);
}
} }
WidgetInfoConfig mgr = WidgetInfoConfig.getInstance(); WidgetInfoConfig mgr = WidgetInfoConfig.getInstance();
Iterator<String> nameIt = mgr.getWidgetConfigNameIterator(); Iterator<String> nameIt = mgr.getWidgetConfigNameIterator();
@ -360,6 +372,7 @@ public class FormParaWidgetPane extends JPanel {
} }
} }
@Override
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {
if (designer.getParaComponent() != null) { if (designer.getParaComponent() != null) {
return; return;
@ -367,7 +380,7 @@ public class FormParaWidgetPane extends JPanel {
designer.addParaComponent(); designer.addParaComponent();
JPanel pane = FormWidgetDetailPane.getInstance(designer); JPanel pane = FormWidgetDetailPane.getInstance(designer);
EastRegionContainerPane.getInstance().replaceDownPane(pane); EastRegionContainerPane.getInstance().replaceWidgetLibPane(pane);
this.setEnabled(false); this.setEnabled(false);
designer.addDesignerEditListener(new paraButtonDesignerAdapter(this)); designer.addDesignerEditListener(new paraButtonDesignerAdapter(this));
@ -378,6 +391,7 @@ public class FormParaWidgetPane extends JPanel {
} }
} }
@Override
public void setEnabled(boolean b) { public void setEnabled(boolean b) {
super.setEnabled(b); super.setEnabled(b);
paraLabel.setForeground(b ? Color.BLACK : new Color(198, 198, 198)); paraLabel.setForeground(b ? Color.BLACK : new Color(198, 198, 198));
@ -397,6 +411,7 @@ public class FormParaWidgetPane extends JPanel {
* *
* @param evt 事件 * @param evt 事件
*/ */
@Override
public void fireCreatorModified(DesignerEvent evt) { public void fireCreatorModified(DesignerEvent evt) {
button.setEnabled(designer.getParaComponent() == null); button.setEnabled(designer.getParaComponent() == null);
} }
@ -404,14 +419,14 @@ public class FormParaWidgetPane extends JPanel {
private WidgetOption[] loadWidgetOptions() { private WidgetOption[] loadWidgetOptions() {
if (widgetOptions == null) { if (widgetOptions == null) {
widgetOptions = (WidgetOption[]) ArrayUtils.addAll(WidgetOption.getFormWidgetIntance(), ExtraDesignClassManager.getInstance().getFormWidgetOptions()); widgetOptions = ArrayUtils.addAll(WidgetOption.getFormWidgetIntance(), ExtraDesignClassManager.getInstance().getFormWidgetOptions());
} }
return widgetOptions; return widgetOptions;
} }
private WidgetOption[] loadLayoutOptions() { private WidgetOption[] loadLayoutOptions() {
if (layoutOptions == null) { if (layoutOptions == null) {
layoutOptions = (WidgetOption[]) ArrayUtils.addAll(FormWidgetOption.getFormLayoutInstance(), ExtraDesignClassManager.getInstance().getFormWidgetContainerOptions()); layoutOptions = ArrayUtils.addAll(FormWidgetOption.getFormLayoutInstance(), ExtraDesignClassManager.getInstance().getFormWidgetContainerOptions());
} }
return layoutOptions; return layoutOptions;
} }

Loading…
Cancel
Save