Browse Source

无JIRA任务,代码规范

master
plough 7 years ago
parent
commit
086c073544
  1. 174
      designer_base/src/com/fr/design/web/CustomIconPane.java
  2. 17
      designer_form/src/com/fr/design/mainframe/FormArea.java
  3. 10
      designer_form/src/com/fr/design/mainframe/JForm.java

174
designer_base/src/com/fr/design/web/CustomIconPane.java

@ -6,18 +6,15 @@ import com.fr.base.Icon;
import com.fr.base.IconManager; import com.fr.base.IconManager;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.ibutton.UIBasicButtonUI;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.imenu.UIBasicMenuItemUI;
import com.fr.design.gui.itextarea.DescriptionTextArea; import com.fr.design.gui.itextarea.DescriptionTextArea;
import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.utils.ColorRoutines;
import com.fr.design.utils.ThemeUtils;
import com.fr.form.ui.WidgetManager; import com.fr.form.ui.WidgetManager;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.Inter; import com.fr.general.Inter;
@ -30,7 +27,6 @@ import javax.swing.*;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.plaf.ButtonUI;
import javax.swing.plaf.basic.BasicButtonUI; import javax.swing.plaf.basic.BasicButtonUI;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -50,14 +46,14 @@ public class CustomIconPane extends BasicPane {
private ListMap iconButtonMap = null; private ListMap iconButtonMap = null;
private JPanel iconPane = null; private JPanel iconPane = null;
private ButtonGroup bg; private ButtonGroup bg;
private JScrollPane jsPane; private UIScrollPane jsPane;
// 老一次次去拿真麻烦 // 老一次次去拿真麻烦
private IconManager iconManager = null; private IconManager iconManager = null;
private int width = 180; private static final int THE_WIDTH = 180;
private int horizontalCount = 6; private static final int HORIZONTAL_COUNT = 6;
private int heightPer = 29; private static final int HEIGHT_PER = 29;
private int gap = 10; private static final int GAP = 10;
public CustomIconPane() { public CustomIconPane() {
this.initComponents(); this.initComponents();
@ -75,7 +71,7 @@ public class CustomIconPane extends BasicPane {
// 开始加图标选择按钮 // 开始加图标选择按钮
initIcons(); initIcons();
jsPane = new JScrollPane(iconPane); jsPane = new UIScrollPane(iconPane);
refreshIconPane(false); refreshIconPane(false);
jsPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); jsPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
@ -141,10 +137,7 @@ public class CustomIconPane extends BasicPane {
}else { }else {
// add failed // add failed
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_Custom_Icon_Message2"), Inter.getLocText("FR-Designer_Tooltips"), JOptionPane.WARNING_MESSAGE);
Inter.getLocText("FR-Designer_Custom_Icon_Message2"),
Inter.getLocText("FR-Designer_Tooltips"),
JOptionPane.WARNING_MESSAGE);
} }
} }
}).setVisible(true); }).setVisible(true);
@ -195,6 +188,7 @@ public class CustomIconPane extends BasicPane {
try { try {
oldIcon= iconManager.getIcon(selectedIconName); oldIcon= iconManager.getIcon(selectedIconName);
} catch (CloneNotSupportedException e1) { } catch (CloneNotSupportedException e1) {
// do nothing
} }
if (oldIcon == null) { if (oldIcon == null) {
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
@ -221,10 +215,7 @@ public class CustomIconPane extends BasicPane {
// 失败了再弄回去 // 失败了再弄回去
iconManager.addIcon(oldIcon, true); iconManager.addIcon(oldIcon, true);
// edit failed // edit failed
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_Custom_Icon_Message2"), Inter.getLocText("FR-Designer_Tooltips"), JOptionPane.WARNING_MESSAGE);
Inter.getLocText("FR-Designer_Custom_Icon_Message2"),
Inter.getLocText("FR-Designer_Tooltips"),
JOptionPane.WARNING_MESSAGE);
} }
} }
}); });
@ -278,8 +269,8 @@ public class CustomIconPane extends BasicPane {
// 不知道怎么动态布局,就这么傻傻的调一下大小 // 不知道怎么动态布局,就这么傻傻的调一下大小
private void refreshIconPane(boolean down) { private void refreshIconPane(boolean down) {
iconPane.setPreferredSize(new Dimension(width, (iconButtonMap.size() / horizontalCount + 1) * heightPer + gap)); iconPane.setPreferredSize(new Dimension(THE_WIDTH, (iconButtonMap.size() / HORIZONTAL_COUNT + 1) * HEIGHT_PER + GAP));
JScrollBar jsBar = jsPane.getVerticalScrollBar(); JScrollBar jsBar = jsPane.createVerticalScrollBar();
try { try {
if (down) { if (down) {
// 将滚动条滚到最后 // 将滚动条滚到最后
@ -288,16 +279,17 @@ public class CustomIconPane extends BasicPane {
jsBar.setValue(0); jsBar.setValue(0);
} }
} catch (RuntimeException re) { } catch (RuntimeException re) {
return;
} }
} }
private class IconButton extends JToggleButton implements ActionListener{ private class IconButton extends JToggleButton implements ActionListener{
private String iconName; private String iconName;
private Image iconImage = null; private Image iconImage = null;
private static final int ICON_BUTTON_SIZE = 24;
public IconButton(String name) { public IconButton(String name) {
this.iconName = name; this.iconName = name;
this.addActionListener(this); this.addActionListener(this);
this.setCursor(new Cursor(Cursor.HAND_CURSOR)); this.setCursor(new Cursor(Cursor.HAND_CURSOR));
this.setBorder(null); this.setBorder(null);
this.iconImage = WidgetManager.getProviderInstance().getIconManager().getIconImage(name); this.iconImage = WidgetManager.getProviderInstance().getIconManager().getIconImage(name);
@ -332,7 +324,7 @@ public class CustomIconPane extends BasicPane {
@Override @Override
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
return new Dimension(24, 24); return new Dimension(ICON_BUTTON_SIZE, ICON_BUTTON_SIZE);
} }
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
@ -363,75 +355,79 @@ public class CustomIconPane extends BasicPane {
private String oldName = null; private String oldName = null;
protected EditIconDialog() { protected EditIconDialog() {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); init();
double p = TableLayout.PREFERRED; }
double rowSize[] = {p, p};
double columnSize[] = {p, p, p};
UIButton browseButton = new UIButton(Inter.getLocText("FR-Designer_Custom_Icon_SelectIcon"));
browseButton.setPreferredSize(new java.awt.Dimension(80, 25));
browseButton.setToolTipText(Inter.getLocText("FR-Designer_Click_this_button"));
browseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser jf = new JFileChooser();
// carl:不知道是否只要png格式,反正导出时全部都转成png了
FileNameExtensionFilter fileFilter = new FileNameExtensionFilter("Icon Image File", "jpg", "jpeg", "png", "gif");
jf.setFileFilter(fileFilter);
if (JFileChooser.APPROVE_OPTION == jf.showOpenDialog(DesignerContext.getDesignerFrame())) { private void init() {
String path = jf.getSelectedFile().getAbsolutePath(); this.setLayout(FRGUIPaneFactory.createBorderLayout());
// 将图片转化到16 × 16大小 double p = TableLayout.PREFERRED;
Image image = BaseUtils.readImage(path); double rowSize[] = {p, p};
BufferedImage bufferedImage = CoreGraphHelper.createBufferedImage(IconManager.DEFAULT_ICONWIDTH, double columnSize[] = {p, p, p};
IconManager.DEFAULT_ICONHEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bufferedImage.createGraphics(); UIButton browseButton = new UIButton(Inter.getLocText("FR-Designer_Custom_Icon_SelectIcon"));
g2d.drawImage(image, 0, 0, IconManager.DEFAULT_ICONWIDTH, IconManager.DEFAULT_ICONHEIGHT, null); browseButton.setPreferredSize(new Dimension(80, 25));
bufferedImage.flush(); browseButton.setToolTipText(Inter.getLocText("FR-Designer_Click_this_button"));
g2d.dispose(); nameTextField = new UITextField(20);
iconImage = bufferedImage;
if (iconImage != null) { browseButton.addActionListener(new ActionListener() {
showImageLabel.setIcon(new ImageIcon(iconImage)); public void actionPerformed(ActionEvent e) {
} onBrowseButtonClicked();
}
}
});
nameTextField = new UITextField(20);
// 焦点丢失时看看名称是否已经存在
nameTextField.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
} }
public void focusLost(FocusEvent e) {
if (oldName != null && ComparatorUtils.equals(oldName, nameTextField.getText())) {
return;
}
if (WidgetManager.getProviderInstance().getIconManager().contains(nameTextField.getText())) {
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
Inter.getLocText("FR-Designer_Custom_Icon_Message3"),
Inter.getLocText("FR-Designer_Tooltips"),
JOptionPane.WARNING_MESSAGE);
}
}
}); });
JPanel imagePane = new JPanel(); // 焦点丢失时看看名称是否已经存在
imagePane.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 0)); nameTextField.addFocusListener(new FocusListener() {
showImageLabel = new UILabel(); public void focusGained(FocusEvent e) {
showImageLabel.setPreferredSize(new Dimension(20,20)); }
imagePane.add(showImageLabel); public void focusLost(FocusEvent e) {
imagePane.add(browseButton); if (oldName != null && ComparatorUtils.equals(oldName, nameTextField.getText())) {
Component[][] components = { return;
{new UILabel(Inter.getLocText("FR-Designer_Name") + ":"), nameTextField}, }
{new UILabel(Inter.getLocText("FR-Designer_Icon") + ":"), imagePane} if (WidgetManager.getProviderInstance().getIconManager().contains(nameTextField.getText())) {
}; JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
Inter.getLocText("FR-Designer_Custom_Icon_Message3"),
JPanel centerPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); Inter.getLocText("FR-Designer_Tooltips"),
this.add(centerPane,BorderLayout.CENTER); JOptionPane.WARNING_MESSAGE);
} }
}
@Override });
JPanel imagePane = new JPanel();
imagePane.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 0));
showImageLabel = new UILabel();
showImageLabel.setPreferredSize(new Dimension(20,20));
imagePane.add(showImageLabel);
imagePane.add(browseButton);
Component[][] components = {{new UILabel(Inter.getLocText("FR-Designer_Name") + ":"), nameTextField}, {new UILabel(Inter.getLocText("FR-Designer_Icon") + ":"), imagePane}};
JPanel centerPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
this.add(centerPane,BorderLayout.CENTER);
}
private void onBrowseButtonClicked() {
JFileChooser jf = new JFileChooser();
// carl:不知道是否只要png格式,反正导出时全部都转成png了
FileNameExtensionFilter fileFilter = new FileNameExtensionFilter("Icon Image File", "jpg", "jpeg", "png", "gif");
jf.setFileFilter(fileFilter);
if (JFileChooser.APPROVE_OPTION == jf.showOpenDialog(DesignerContext.getDesignerFrame())) {
String path = jf.getSelectedFile().getAbsolutePath();
// 将图片转化到16 × 16大小
Image image = BaseUtils.readImage(path);
BufferedImage bufferedImage = CoreGraphHelper.createBufferedImage(IconManager.DEFAULT_ICONWIDTH,
IconManager.DEFAULT_ICONHEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bufferedImage.createGraphics();
g2d.drawImage(image, 0, 0, IconManager.DEFAULT_ICONWIDTH, IconManager.DEFAULT_ICONHEIGHT, null);
bufferedImage.flush();
g2d.dispose();
iconImage = bufferedImage;
if (iconImage != null) {
showImageLabel.setIcon(new ImageIcon(iconImage));
}
}
}
@Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return Inter.getLocText(new String[]{"Add", "Icon"}); return Inter.getLocText(new String[]{"Add", "Icon"});
} }

17
designer_form/src/com/fr/design/mainframe/FormArea.java

@ -120,10 +120,7 @@ public class FormArea extends JComponent implements ScrollRulerComponent {
slidePane = JFormSliderPane.getInstance(); slidePane = JFormSliderPane.getInstance();
slidePane.setPreferredSize(new Dimension(200, 20)); slidePane.setPreferredSize(new Dimension(200, 20));
JPanel resizePane = TableLayoutHelper.createCommonTableLayoutPane( JPanel resizePane = TableLayoutHelper.createCommonTableLayoutPane(new JComponent[][]{{ tipsPane, new UILabel(), widthPane, new UILabel(Inter.getLocText("FR-Designer_Indent-Pixel")), new UILabel("x"), heightPane, new UILabel(Inter.getLocText("FR-Designer_Indent-Pixel")), new UILabel(), slidePane }}, rowSize, columnSize, RESIZE_PANE_GAP);
new JComponent[][]{{ tipsPane, new UILabel(), widthPane, new UILabel(Inter.getLocText("FR-Designer_Indent-Pixel")), new UILabel("x"),
heightPane, new UILabel(Inter.getLocText("FR-Designer_Indent-Pixel")), new UILabel(), slidePane }},
rowSize, columnSize, RESIZE_PANE_GAP);
this.add(FormRulerLayout.BOTTOM, resizePane); this.add(FormRulerLayout.BOTTOM, resizePane);
setWidgetsConfig(); setWidgetsConfig();
// 先初始话滑块及对应事件,然后获取分辨率调整容器的显示大小 // 先初始话滑块及对应事件,然后获取分辨率调整容器的显示大小
@ -439,16 +436,20 @@ public class FormArea extends JComponent implements ScrollRulerComponent {
int id = evt.getID(); int id = evt.getID();
switch (id) { switch (id) {
case MouseEvent.MOUSE_WHEEL: { case MouseEvent.MOUSE_WHEEL: {
int value = this.verScrollBar.getValue() + evt.getWheelRotation() * ROTATIONS; onMouseWheelScroll(evt);
value = Math.max(0, Math.min(value, verticalMax));
doLayout(); //加dolayout是因为每次滚动都要重置 Max的大小
this.verScrollBar.setValue(value);
break; break;
} }
default: default:
} }
} }
private void onMouseWheelScroll(MouseWheelEvent evt) {
int value = this.verScrollBar.getValue() + evt.getWheelRotation() * ROTATIONS;
value = Math.max(0, Math.min(value, verticalMax));
doLayout(); //加dolayout是因为每次滚动都要重置 Max的大小
this.verScrollBar.setValue(value);
}
/** /**
* 返回表单容器的中心designer * 返回表单容器的中心designer
* getFormEditor. * getFormEditor.

10
designer_form/src/com/fr/design/mainframe/JForm.java

@ -467,15 +467,9 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm {
@Override @Override
public ShortCut[] shortcut4TemplateMenu() { public ShortCut[] shortcut4TemplateMenu() {
if (this.index == FORM_TAB) { if (this.index == FORM_TAB) {
return (ShortCut[]) ArrayUtils.addAll( new ShortCut[]{ return (ShortCut[]) ArrayUtils.addAll(new ShortCut[]{new TemplateParameterAction(this), new FormMobileAttrAction(this)}, new ShortCut[0]);
new TemplateParameterAction(this),
new FormMobileAttrAction(this)
}, new ShortCut[0]);
} else { } else {
return (ShortCut[]) ArrayUtils.addAll( new ShortCut[]{ return (ShortCut[]) ArrayUtils.addAll(new ShortCut[]{new TemplateParameterAction(this), new FormMobileAttrAction(this)}, this.elementCaseDesign.shortcut4TemplateMenu());
new TemplateParameterAction(this),
new FormMobileAttrAction(this)
}, this.elementCaseDesign.shortcut4TemplateMenu());
} }
} }

Loading…
Cancel
Save