Browse Source

代码格式化

master
MoMeak 7 years ago
parent
commit
9024ca56b8
  1. 2
      designer/src/com/fr/design/mainframe/ElementCasePane.java
  2. 54
      designer/src/com/fr/design/mainframe/ReportComponentComposite.java
  3. 265
      designer/src/com/fr/poly/PolyDesigner.java
  4. 158
      designer_base/src/com/fr/design/mainframe/JFormSliderPane.java
  5. 176
      designer_base/src/com/fr/design/mainframe/JSliderPane.java

2
designer/src/com/fr/design/mainframe/ElementCasePane.java

@ -297,7 +297,7 @@ public abstract class ElementCasePane<T extends TemplateElementCase> extends Tar
if(DesignerContext.getReferencedElementCasePane() == null){ if(DesignerContext.getReferencedElementCasePane() == null){
return; return;
} }
((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setNotShowingTableSelectPane(true); ((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setNotShowingTableSelectPane(true);
((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setCursor(UIConstants.CELL_DEFAULT_CURSOR); ((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setCursor(UIConstants.CELL_DEFAULT_CURSOR);
DesignerContext.setReferencedElementCasePane(null); DesignerContext.setReferencedElementCasePane(null);

54
designer/src/com/fr/design/mainframe/ReportComponentComposite.java

@ -1,17 +1,5 @@
package com.fr.design.mainframe; package com.fr.design.mainframe;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.base.ScreenResolution; import com.fr.base.ScreenResolution;
import com.fr.design.designer.EditingState; import com.fr.design.designer.EditingState;
@ -23,9 +11,15 @@ import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.grid.Grid; import com.fr.grid.Grid;
import com.fr.main.impl.WorkBook; import com.fr.main.impl.WorkBook;
import com.fr.poly.PolyArea;
import com.fr.report.report.TemplateReport; import com.fr.report.report.TemplateReport;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
/** /**
* 整个报表编辑区域 包括滚动条中间的grid或者聚合块下面的sheetTab * 整个报表编辑区域 包括滚动条中间的grid或者聚合块下面的sheetTab
* *
@ -56,7 +50,6 @@ public class ReportComponentComposite extends JComponent {
/** /**
* Constructor with workbook.. * Constructor with workbook..
*
*/ */
public ReportComponentComposite(JWorkBook jwb) { public ReportComponentComposite(JWorkBook jwb) {
setFocusable(true); setFocusable(true);
@ -80,22 +73,24 @@ public class ReportComponentComposite extends JComponent {
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
} }
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
if( e.isControlDown()){ if (e.isControlDown()) {
isCtrl = true ; isCtrl = true;
} }
} }
@Override @Override
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
isCtrl = false ; isCtrl = false;
} }
}; };
MouseWheelListener showValSpinnerMouseWheelListener = new MouseWheelListener() { MouseWheelListener showValSpinnerMouseWheelListener = new MouseWheelListener() {
@Override @Override
public void mouseWheelMoved(MouseWheelEvent e) { public void mouseWheelMoved(MouseWheelEvent e) {
if (isCtrl){ if (isCtrl) {
int dir = e.getWheelRotation(); int dir = e.getWheelRotation();
int old_resolution = (int) jSliderContainer.getShowVal().getValue(); int old_resolution = (int) jSliderContainer.getShowVal().getValue();
jSliderContainer.getShowVal().setValue(old_resolution - (dir * MIN)); jSliderContainer.getShowVal().setValue(old_resolution - (dir * MIN));
@ -106,10 +101,10 @@ public class ReportComponentComposite extends JComponent {
ChangeListener showValSpinnerChangeListener = new ChangeListener() { ChangeListener showValSpinnerChangeListener = new ChangeListener() {
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
double value = (int) ((UIBasicSpinner)e.getSource()).getValue(); double value = (int) ((UIBasicSpinner) e.getSource()).getValue();
value = value > MAX ? MAX : value; value = value > MAX ? MAX : value;
value = value < MIN ? MIN : value; value = value < MIN ? MIN : value;
int resolution = (int) (ScreenResolution.getScreenResolution()*value/HUND); int resolution = (int) (ScreenResolution.getScreenResolution() * value / HUND);
HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().setScale(resolution); HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().setScale(resolution);
} }
}; };
@ -117,9 +112,9 @@ public class ReportComponentComposite extends JComponent {
ItemListener selfAdaptButtonItemListener = new ItemListener() { ItemListener selfAdaptButtonItemListener = new ItemListener() {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
if (jSliderContainer.getSelfAdaptButton().isSelected()){ if (jSliderContainer.getSelfAdaptButton().isSelected()) {
int resolution = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().selfAdaptUpdate(); int resolution = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().selfAdaptUpdate();
jSliderContainer.getShowVal().setValue(resolution*HUND/ScreenResolution.getScreenResolution()); jSliderContainer.getShowVal().setValue(resolution * HUND / ScreenResolution.getScreenResolution());
} }
} }
}; };
@ -166,11 +161,10 @@ public class ReportComponentComposite extends JComponent {
} }
/** /**
* 移除选中状态 * 移除选中状态
* *
* @date 2015-2-5-上午11:41:44 * @date 2015-2-5-上午11:41:44
* */
*/
public void removeSelection() { public void removeSelection() {
if (centerCardPane.editingComponet instanceof WorkSheetDesigner) { if (centerCardPane.editingComponet instanceof WorkSheetDesigner) {
((WorkSheetDesigner) centerCardPane.editingComponet).removeSelection(); ((WorkSheetDesigner) centerCardPane.editingComponet).removeSelection();
@ -188,7 +182,7 @@ public class ReportComponentComposite extends JComponent {
return sheetNameTab.getSelectedIndex(); return sheetNameTab.getSelectedIndex();
} }
public JSliderPane getjSliderContainer(){ public JSliderPane getjSliderContainer() {
return this.jSliderContainer; return this.jSliderContainer;
} }
@ -240,8 +234,8 @@ public class ReportComponentComposite extends JComponent {
splitpane.setBorder(null); splitpane.setBorder(null);
splitpane.setDividerSize(3); splitpane.setDividerSize(3);
splitpane.setResizeWeight(1); splitpane.setResizeWeight(1);
southPane.add(hbarContainer,BorderLayout.NORTH); southPane.add(hbarContainer, BorderLayout.NORTH);
southPane.add(splitpane,BorderLayout.CENTER); southPane.add(splitpane, BorderLayout.CENTER);
return southPane; return southPane;
} }

265
designer/src/com/fr/poly/PolyDesigner.java

@ -3,20 +3,6 @@
*/ */
package com.fr.poly; package com.fr.poly;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.KeyStroke;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.base.GraphHelper; import com.fr.base.GraphHelper;
@ -47,11 +33,7 @@ import com.fr.design.utils.gui.LayoutUtils;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.grid.selection.Selection; import com.fr.grid.selection.Selection;
import com.fr.poly.actions.DeleteBlockAction; import com.fr.poly.actions.DeleteBlockAction;
import com.fr.poly.creator.BlockCreator; import com.fr.poly.creator.*;
import com.fr.poly.creator.BlockEditor;
import com.fr.poly.creator.ECBlockCreator;
import com.fr.poly.creator.ECBlockEditor;
import com.fr.poly.creator.PolyElementCasePane;
import com.fr.poly.hanlder.DataEditingListener; import com.fr.poly.hanlder.DataEditingListener;
import com.fr.poly.hanlder.PolyDesignerDropTarget; import com.fr.poly.hanlder.PolyDesignerDropTarget;
import com.fr.poly.model.AddedData; import com.fr.poly.model.AddedData;
@ -61,13 +43,21 @@ import com.fr.report.block.Block;
import com.fr.report.poly.PolyWorkSheet; import com.fr.report.poly.PolyWorkSheet;
import com.fr.report.poly.TemplateBlock; import com.fr.report.poly.TemplateBlock;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.CoreGraphHelper;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.unit.FU; import com.fr.stable.unit.FU;
import com.fr.stable.unit.OLDPIX; import com.fr.stable.unit.OLDPIX;
import com.fr.stable.unit.UNIT; import com.fr.stable.unit.UNIT;
import com.fr.stable.unit.UnitRectangle; import com.fr.stable.unit.UnitRectangle;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
/** /**
* @author richer * @author richer
* @since 6.5.3 聚合报表的设计块不包括底部和右边的滚动条以及左边和上边的像素标识条 * @since 6.5.3 聚合报表的设计块不包括底部和右边的滚动条以及左边和上边的像素标识条
@ -85,6 +75,7 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
public static enum SelectionType { public static enum SelectionType {
NONE, INNER, BLOCK NONE, INNER, BLOCK
} }
public JComponent polyArea; public JComponent polyArea;
private SelectionType selectedtype = SelectionType.NONE; private SelectionType selectedtype = SelectionType.NONE;
private AddingData addingData; private AddingData addingData;
@ -105,7 +96,7 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
private JComponent[] toolBarComponent = null; private JComponent[] toolBarComponent = null;
private JPanel ployareaPane; private JPanel ployareaPane;
private JSliderPane jSliderContainer; private JSliderPane jSliderContainer;
private int resolution = (int) (ScreenResolution.getScreenResolution()* JSliderPane.getInstance().resolutionTimes); private int resolution = (int) (ScreenResolution.getScreenResolution() * JSliderPane.getInstance().resolutionTimes);
private float time; private float time;
private boolean isCtrl = false; private boolean isCtrl = false;
@ -148,7 +139,7 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
} }
private void initComponents() { private void initComponents() {
jSliderContainer = ((JWorkBook)HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()).reportComposite.getjSliderContainer(); jSliderContainer = ((JWorkBook) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()).reportComposite.getjSliderContainer();
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
ployareaPane = new JPanel(new PolyDesignerLayout()); ployareaPane = new JPanel(new PolyDesignerLayout());
polyArea = new PolyArea(this, resolution); polyArea = new PolyArea(this, resolution);
@ -171,15 +162,17 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
} }
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
if( e.isControlDown()){ if (e.isControlDown()) {
isCtrl = true ; isCtrl = true;
} }
} }
@Override @Override
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
isCtrl = false ; isCtrl = false;
} }
}; };
@ -201,16 +194,17 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
return this.resolution; return this.resolution;
} }
public void updateUI(){ public void updateUI() {
((PolyArea)this.polyArea).setResolution(resolution); ((PolyArea) this.polyArea).setResolution(resolution);
polyArea.repaint(); polyArea.repaint();
// this.polyArea = (JComponent) new PolyArea(this, resolution); // this.polyArea = (JComponent) new PolyArea(this, resolution);
} }
/** /**
* 是否含有聚和报表块 * 是否含有聚和报表块
* @param targetComponent 目标组件 *
* @return 是则返回true * @param targetComponent 目标组件
* @return 是则返回true
*/ */
public boolean containsBlocks(TargetComponent targetComponent) { public boolean containsBlocks(TargetComponent targetComponent) {
for (int i = 0, count = this.getTarget().getBlockCount(); i < count; i++) { for (int i = 0, count = this.getTarget().getBlockCount(); i < count; i++) {
@ -243,21 +237,23 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
} }
public JPanel getPloyAreaPane(){ public JPanel getPloyAreaPane() {
return this.ployareaPane; return this.ployareaPane;
} }
/** /**
* 增加组件 * 增加组件
* @param currentEditor 组件 *
* @param currentEditor 组件
*/ */
public void addEditor(BlockEditor currentEditor) { public void addEditor(BlockEditor currentEditor) {
this.polyArea.add(currentEditor); this.polyArea.add(currentEditor);
} }
/** /**
* 移除组件 * 移除组件
* @param currentEditor 组件 *
* @param currentEditor 组件
*/ */
public void removeEditor(BlockEditor currentEditor) { public void removeEditor(BlockEditor currentEditor) {
this.polyArea.remove(currentEditor); this.polyArea.remove(currentEditor);
@ -265,7 +261,8 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
/** /**
* 权限编辑状态 * 权限编辑状态
* @return 权限编辑面板 *
* @return 权限编辑面板
*/ */
public AuthorityEditPane createAuthorityEditPane() { public AuthorityEditPane createAuthorityEditPane() {
if (elementCasePane == null) { if (elementCasePane == null) {
@ -280,7 +277,7 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
@Override @Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
this.time = (float)resolution/ScreenResolution.getScreenResolution(); this.time = (float) resolution / ScreenResolution.getScreenResolution();
resetEditorComponentBounds(); resetEditorComponentBounds();
LayoutUtils.layoutRootContainer(this); LayoutUtils.layoutRootContainer(this);
g.setColor(Color.black); g.setColor(Color.black);
@ -292,15 +289,16 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
private void resetEditorComponentBounds() { private void resetEditorComponentBounds() {
if (selection != null) { if (selection != null) {
selection.setResolution(this.resolution); selection.setResolution(this.resolution);
selection.getEditor().setBounds((int) (selection.getEditorBounds().x*time), (int) (selection.getEditorBounds().y*time), selection.getEditor().setBounds((int) (selection.getEditorBounds().x * time), (int) (selection.getEditorBounds().y * time),
(int) (selection.getEditorBounds().width*time), (int) (selection.getEditorBounds().height*time)); (int) (selection.getEditorBounds().width * time), (int) (selection.getEditorBounds().height * time));
LayoutUtils.layoutRootContainer(this); LayoutUtils.layoutRootContainer(this);
} }
} }
/** /**
* 增加组件 * 增加组件
* @param creator 组件 *
* @param creator 组件
*/ */
public void addBlockCreator(BlockCreator creator) { public void addBlockCreator(BlockCreator creator) {
TemplateBlock block = creator.getValue(); TemplateBlock block = creator.getValue();
@ -386,7 +384,8 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
/** /**
* 选中的是否是报表块 * 选中的是否是报表块
* @return 是则返回true *
* @return 是则返回true
*/ */
public boolean isSelectedECBolck() { public boolean isSelectedECBolck() {
return this.selection instanceof ECBlockCreator; return this.selection instanceof ECBlockCreator;
@ -410,7 +409,6 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
} }
/** /**
* @return * @return
*/ */
@ -461,6 +459,7 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
/** /**
* 黏贴 * 黏贴
*
* @return 黏贴成功返回true * @return 黏贴成功返回true
*/ */
public boolean paste() { public boolean paste() {
@ -520,6 +519,7 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
/** /**
* 删除 * 删除
*
* @return 删除成功返回true * @return 删除成功返回true
*/ */
public boolean delete() { public boolean delete() {
@ -559,6 +559,7 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
/** /**
* 剪切 * 剪切
*
* @return 剪切成功返回true * @return 剪切成功返回true
*/ */
public boolean cut() { public boolean cut() {
@ -569,8 +570,9 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
/** /**
* 移动 * 移动
* @param x 横坐标 *
* @param y 纵坐标 * @param x 横坐标
* @param y 纵坐标
*/ */
public void move(int x, int y) { public void move(int x, int y) {
if (selection == null) { if (selection == null) {
@ -672,11 +674,11 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
int id = evt.getID(); int id = evt.getID();
switch (id) { switch (id) {
case MouseEvent.MOUSE_WHEEL: { case MouseEvent.MOUSE_WHEEL: {
if (isCtrl){ if (isCtrl) {
int dir = evt.getWheelRotation(); int dir = evt.getWheelRotation();
int old_resolution = (int) jSliderContainer.getShowVal().getValue(); int old_resolution = (int) jSliderContainer.getShowVal().getValue();
jSliderContainer.getShowVal().setValue(old_resolution - (dir * MIN)); jSliderContainer.getShowVal().setValue(old_resolution - (dir * MIN));
}else { } else {
int rotations = evt.getWheelRotation(); int rotations = evt.getWheelRotation();
this.getVerticalScrollBar().setValue(this.getVerticalScrollBar().getValue() + rotations * ROTATIONS); this.getVerticalScrollBar().setValue(this.getVerticalScrollBar().getValue() + rotations * ROTATIONS);
} }
@ -687,7 +689,8 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
/** /**
* 开始编辑 * 开始编辑
* @param blockName 聚合块名称 *
* @param blockName 聚合块名称
*/ */
public void startEditing(String blockName) { public void startEditing(String blockName) {
if (StringUtils.isBlank(blockName)) { if (StringUtils.isBlank(blockName)) {
@ -877,9 +880,9 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
if (!ComparatorUtils.equals(selectedtype, type) || type == SelectionType.NONE) { if (!ComparatorUtils.equals(selectedtype, type) || type == SelectionType.NONE) {
selectedtype = type; selectedtype = type;
JTemplate<?, ?> jt = DesignerContext.getDesignerFrame().getSelectedJTemplate(); JTemplate<?, ?> jt = DesignerContext.getDesignerFrame().getSelectedJTemplate();
if(jt != null){ if (jt != null) {
jt.setComposite(); jt.setComposite();
} }
DesignerContext.getDesignerFrame().resetToolkitByPlus(DesignerContext.getDesignerFrame().getSelectedJTemplate()); DesignerContext.getDesignerFrame().resetToolkitByPlus(DesignerContext.getDesignerFrame().getSelectedJTemplate());
if (BaseUtils.isAuthorityEditing()) { if (BaseUtils.isAuthorityEditing()) {
EastRegionContainerPane.getInstance().replaceDownPane(RolesAlreadyEditedPane.getInstance()); EastRegionContainerPane.getInstance().replaceDownPane(RolesAlreadyEditedPane.getInstance());
@ -918,8 +921,9 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
} }
/** /**
* 是否选中聚合块本身 * 是否选中聚合块本身
* @return 是则返回true *
* @return 是则返回true
*/ */
public boolean isChooseBlock() { public boolean isChooseBlock() {
return selectedtype == SelectionType.BLOCK; return selectedtype == SelectionType.BLOCK;
@ -967,89 +971,82 @@ public class PolyDesigner extends ReportComponent<PolyWorkSheet, PolyElementCase
/** /**
* 计算滚动条的值和max * 计算滚动条的值和max
* @param oldmax 之前最大值 *
* @param max 当前最大值 * @param oldmax 之前最大值
* @param newValue 当前value * @param max 当前最大值
* @param oldValue 之前value * @param newValue 当前value
* @param visi designer的大小 * @param oldValue 之前value
* @param visi designer的大小
* @param orientation 滚动条方向 * @param orientation 滚动条方向
* @return 计算后的值和max * @return 计算后的值和max
*/ */
public Point calculateScroll(int oldmax, int max, int newValue, int oldValue, int visi, int orientation) { public Point calculateScroll(int oldmax, int max, int newValue, int oldValue, int visi, int orientation) {
return new Point(newValue, max); return new Point(newValue, max);
} }
/** /**
* 获取当前聚合报表区域左上角x坐标 * 获取当前聚合报表区域左上角x坐标
* *
* @return 当前聚合报表区域左上角x坐标 * @return 当前聚合报表区域左上角x坐标
* */
*/ public double getAreaLocationX() {
public double getAreaLocationX(){ return polyArea.getLocationOnScreen().getX();
return polyArea.getLocationOnScreen().getX(); }
}
/**
/** * 获取当前聚合报表区域左上角y坐标
* 获取当前聚合报表区域左上角y坐标 *
* * @return 当前聚合报表区域左上角y坐标
* @return 当前聚合报表区域左上角y坐标 */
* public double getAreaLocationY() {
*/ return polyArea.getLocationOnScreen().getY();
public double getAreaLocationY(){ }
return polyArea.getLocationOnScreen().getY();
} /**
* 检测指定块是否与其他的块有重叠区域
/** *
* 检测指定块是否与其他的块有重叠区域 * @param creator 指定的块编辑器
* * @return 是否与其他的块有重叠区域
* @param creator 指定的块编辑器 */
* public boolean intersectsAllBlock(BlockCreator creator) {
* @return 是否与其他的块有重叠区域 return intersectsAllBlock(creator.getValue());
* }
*/
public boolean intersectsAllBlock(BlockCreator creator){ /**
return intersectsAllBlock(creator.getValue()); * 检测指定块是否与其他的块有重叠区域
} *
* @param block 指定的块
/** * @return 是否与其他的块有重叠区域
* 检测指定块是否与其他的块有重叠区域 */
* public boolean intersectsAllBlock(TemplateBlock block) {
* @param block 指定的块 UnitRectangle rec = block.getBounds();
* String blockName = block.getBlockName();
* @return 是否与其他的块有重叠区域 return intersectsAllBlock(rec, blockName);
* }
*/
public boolean intersectsAllBlock(TemplateBlock block){ /**
UnitRectangle rec = block.getBounds(); * 检测指定块是否与其他的块有重叠区域
String blockName = block.getBlockName(); *
return intersectsAllBlock(rec, blockName); * @param rec 指定的块区域
} * @param blockName 指定的块名称
* @return 是否与其他的块有重叠区域
/** */
* 检测指定块是否与其他的块有重叠区域 public boolean intersectsAllBlock(UnitRectangle rec, String blockName) {
* PolyWorkSheet worksheet = this.getTarget();
* @param rec 指定的块区域 int count = worksheet.getBlockCount();
* @param blockName 指定的块名称 for (int i = 0; i < count; i++) {
* Block temp_block = worksheet.getBlock(i);
* @return 是否与其他的块有重叠区域 UnitRectangle temp_rect = temp_block.getBounds();
*
*/ if (ComparatorUtils.equals(blockName, temp_block.getBlockName())) {
public boolean intersectsAllBlock(UnitRectangle rec, String blockName){ continue;
PolyWorkSheet worksheet = this.getTarget(); }
int count = worksheet.getBlockCount();
for (int i = 0; i < count; i++) { if (temp_rect.intersects(rec)) {
Block temp_block = worksheet.getBlock(i); return true;
UnitRectangle temp_rect = temp_block.getBounds(); }
}
if(ComparatorUtils.equals(blockName, temp_block.getBlockName())){
continue; return false;
} }
if(temp_rect.intersects(rec)){
return true;
}
}
return false;
}
} }

158
designer_base/src/com/fr/design/mainframe/JFormSliderPane.java

@ -16,9 +16,11 @@ import javax.swing.*;
import javax.swing.border.MatteBorder; import javax.swing.border.MatteBorder;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.plaf.basic.BasicSliderUI;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
@ -31,7 +33,7 @@ public class JFormSliderPane extends JPanel {
private static final int TEN = 10; private static final int TEN = 10;
private static final int ONE_EIGHT = 18; private static final int ONE_EIGHT = 18;
private static final int FONT_SIZE = 14; private static final int FONT_SIZE = 14;
private static final int SPINNER_WIDTH= 45; private static final int SPINNER_WIDTH = 45;
private static final int SPINNER_HEIGHT = 20; private static final int SPINNER_HEIGHT = 20;
private static final int HALF_HUNDRED = 50; private static final int HALF_HUNDRED = 50;
private static final int HUNDRED = 100; private static final int HUNDRED = 100;
@ -69,7 +71,7 @@ public class JFormSliderPane extends JPanel {
public JFormSliderPane() { public JFormSliderPane() {
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
slider = new UISlider(0,HUNDRED,HALF_HUNDRED); slider = new UISlider(0, HUNDRED, HALF_HUNDRED);
slider.setUI(new JSliderPaneUI(slider)); slider.setUI(new JSliderPaneUI(slider));
slider.addChangeListener(listener); slider.addChangeListener(listener);
@ -92,20 +94,20 @@ public class JFormSliderPane extends JPanel {
downButton.addActionListener(buttonActionListener); downButton.addActionListener(buttonActionListener);
upButton.addActionListener(buttonActionListener); upButton.addActionListener(buttonActionListener);
showValButton = new UIButton(showValSpinner.getValue()+"%"); showValButton = new UIButton(showValSpinner.getValue() + "%");
showValButton.setBorderPainted(false); showValButton.setBorderPainted(false);
showValButton.setPreferredSize(new Dimension(SHOWVALBUTTON_WIDTH,SHOWVALBUTTON_HEIGHTH)); showValButton.setPreferredSize(new Dimension(SHOWVALBUTTON_WIDTH, SHOWVALBUTTON_HEIGHTH));
showValButton.addActionListener(showValButtonActionListener); showValButton.addActionListener(showValButtonActionListener);
initUIRadioButton(); initUIRadioButton();
initPane(); initPane();
JPanel panel = new JPanel(new FlowLayout(1,1,0)); JPanel panel = new JPanel(new FlowLayout(1, 1, 0));
panel.add(downButton); panel.add(downButton);
panel.add(slider); panel.add(slider);
panel.add(upButton); panel.add(upButton);
panel.add(showValButton); panel.add(showValButton);
this.add(panel,BorderLayout.NORTH); this.add(panel, BorderLayout.NORTH);
this.setBounds(0,0,THREE_HUNDRED,ONE_EIGHT); this.setBounds(0, 0, THREE_HUNDRED, ONE_EIGHT);
} }
public static final JFormSliderPane getInstance() { public static final JFormSliderPane getInstance() {
@ -116,7 +118,7 @@ public class JFormSliderPane extends JPanel {
return THIS; return THIS;
} }
private void initUIRadioButton(){ private void initUIRadioButton() {
twoHundredButton = new UIRadioButton("200%"); twoHundredButton = new UIRadioButton("200%");
oneHundredButton = new UIRadioButton("100%"); oneHundredButton = new UIRadioButton("100%");
SevenFiveButton = new UIRadioButton("75%"); SevenFiveButton = new UIRadioButton("75%");
@ -132,7 +134,7 @@ public class JFormSliderPane extends JPanel {
//TODO //TODO
// selfAdaptButton.addItemListener(); // selfAdaptButton.addItemListener();
ButtonGroup bg=new ButtonGroup();// 初始化按钮组 ButtonGroup bg = new ButtonGroup();// 初始化按钮组
bg.add(twoHundredButton);// 加入按钮组 bg.add(twoHundredButton);// 加入按钮组
bg.add(oneHundredButton); bg.add(oneHundredButton);
bg.add(SevenFiveButton); bg.add(SevenFiveButton);
@ -143,24 +145,24 @@ public class JFormSliderPane extends JPanel {
customButton.setSelected(true); customButton.setSelected(true);
} }
private void initPane(){ private void initPane() {
double p = TableLayout.PREFERRED; double p = TableLayout.PREFERRED;
double f = TableLayout.FILL; double f = TableLayout.FILL;
double[] columnSize = { p, f }; double[] columnSize = {p, f};
double[] rowSize = { p,p,p,p,p,p,p}; double[] rowSize = {p, p, p, p, p, p, p};
Component[][] components = new Component[][]{ Component[][] components = new Component[][]{
new Component[]{twoHundredButton,null}, new Component[]{twoHundredButton, null},
new Component[]{oneHundredButton,null}, new Component[]{oneHundredButton, null},
new Component[]{SevenFiveButton,null}, new Component[]{SevenFiveButton, null},
new Component[]{fiveTenButton,null}, new Component[]{fiveTenButton, null},
new Component[]{twoFiveButton,null}, new Component[]{twoFiveButton, null},
// new Component[]{selfAdaptButton,null}, // new Component[]{selfAdaptButton,null},
new Component[]{customButton,createSpinnerPanel()} new Component[]{customButton, createSpinnerPanel()}
}; };
dialogContentPanel = TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); dialogContentPanel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
} }
private JPanel createSpinnerPanel(){ private JPanel createSpinnerPanel() {
JPanel spinnerPanel = new JPanel(new FlowLayout()); JPanel spinnerPanel = new JPanel(new FlowLayout());
spinnerPanel.add(showValSpinner); spinnerPanel.add(showValSpinner);
UILabel percent = new UILabel("%"); UILabel percent = new UILabel("%");
@ -179,14 +181,14 @@ public class JFormSliderPane extends JPanel {
ChangeListener showValSpinnerChangeListener = new ChangeListener() { ChangeListener showValSpinnerChangeListener = new ChangeListener() {
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
int val = (int) ((UIBasicSpinner)e.getSource()).getValue(); int val = (int) ((UIBasicSpinner) e.getSource()).getValue();
isButtonOrIsTxt = true; isButtonOrIsTxt = true;
resolutionTimes = divide(showValue,100,2); resolutionTimes = divide(showValue, 100, 2);
if (val > FOUR_HUNDRED){ if (val > FOUR_HUNDRED) {
showValSpinner.setValue(FOUR_HUNDRED); showValSpinner.setValue(FOUR_HUNDRED);
val = FOUR_HUNDRED; val = FOUR_HUNDRED;
} }
if (val < TEN){ if (val < TEN) {
showValSpinner.setValue(TEN); showValSpinner.setValue(TEN);
val = TEN; val = TEN;
} }
@ -197,11 +199,10 @@ public class JFormSliderPane extends JPanel {
//定义一个监听器,用于监听所有滑动条 //定义一个监听器,用于监听所有滑动条
ChangeListener listener = new ChangeListener() ChangeListener listener = new ChangeListener() {
{ public void stateChanged(ChangeEvent event) {
public void stateChanged( ChangeEvent event) {
//取出滑动条的值,并在文本中显示出来 //取出滑动条的值,并在文本中显示出来
if (!isButtonOrIsTxt){ if (!isButtonOrIsTxt) {
customButton.setSelected(true); customButton.setSelected(true);
EventQueue.invokeLater(new Runnable() { EventQueue.invokeLater(new Runnable() {
public void run() { public void run() {
@ -211,50 +212,50 @@ public class JFormSliderPane extends JPanel {
showValSpinner.setValue(times); showValSpinner.setValue(times);
} }
}); });
}else { } else {
isButtonOrIsTxt = false; isButtonOrIsTxt = false;
} }
} }
}; };
ItemListener radioButtonItemListener = new ItemListener() { ItemListener radioButtonItemListener = new ItemListener() {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
JRadioButton temp=(JRadioButton)e.getSource(); JRadioButton temp = (JRadioButton) e.getSource();
if(temp.isSelected()){ if (temp.isSelected()) {
showValSpinner.setValue(Integer.valueOf(temp.getText().substring(0, temp.getText().indexOf("%")))); showValSpinner.setValue(Integer.valueOf(temp.getText().substring(0, temp.getText().indexOf("%"))));
} }
} }
}; };
private void refreshSlider(int val){ private void refreshSlider(int val) {
showValue = val; showValue = val;
if (showValue >HUNDRED){ if (showValue > HUNDRED) {
slider.setValue((int)(showValue+TWO_HUNDRED)/SIX); slider.setValue((int) (showValue + TWO_HUNDRED) / SIX);
}else if (showValue <HUNDRED){ } else if (showValue < HUNDRED) {
slider.setValue((int)((showValue-TEN)/ONEPOINTEIGHT)); slider.setValue((int) ((showValue - TEN) / ONEPOINTEIGHT));
}else if (showValue == HUNDRED){ } else if (showValue == HUNDRED) {
slider.setValue(HALF_HUNDRED); slider.setValue(HALF_HUNDRED);
} }
} }
private void refreshBottun(int val){ private void refreshBottun(int val) {
showValButton.setText(val+"%"); showValButton.setText(val + "%");
} }
public double getResolutionTimes(){ public double getResolutionTimes() {
return this.resolutionTimes; return this.resolutionTimes;
} }
public int getshowValue(){ public int getshowValue() {
return this.showValue; return this.showValue;
} }
public static double divide(double v1, double v2,int scale) { public static double divide(double v1, double v2, int scale) {
BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2)); BigDecimal b2 = new BigDecimal(Double.toString(v2));
return b1.divide(b2,scale).doubleValue(); return b1.divide(b2, scale).doubleValue();
} }
ActionListener buttonActionListener = new ActionListener() { ActionListener buttonActionListener = new ActionListener() {
@ -262,22 +263,22 @@ public class JFormSliderPane extends JPanel {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showValue = (int) showValSpinner.getValue(); showValue = (int) showValSpinner.getValue();
isButtonOrIsTxt = true; isButtonOrIsTxt = true;
if(e.getActionCommand().equals("less")){ if (e.getActionCommand().equals("less")) {
int newDownVal = showValue - TEN; int newDownVal = showValue - TEN;
if (newDownVal >= TEN ){ if (newDownVal >= TEN) {
showValue = newDownVal; showValue = newDownVal;
showValSpinner.setValue(newDownVal); showValSpinner.setValue(newDownVal);
}else { } else {
showValue = newDownVal; showValue = newDownVal;
showValSpinner.setValue(TEN); showValSpinner.setValue(TEN);
} }
} }
if(e.getActionCommand().equals("more")){ if (e.getActionCommand().equals("more")) {
int newUpVal = showValue + TEN; int newUpVal = showValue + TEN;
if (newUpVal <= FOUR_HUNDRED ){ if (newUpVal <= FOUR_HUNDRED) {
showValue = newUpVal; showValue = newUpVal;
showValSpinner.setValue(newUpVal); showValSpinner.setValue(newUpVal);
}else { } else {
showValue = newUpVal; showValue = newUpVal;
showValSpinner.setValue(FOUR_HUNDRED); showValSpinner.setValue(FOUR_HUNDRED);
} }
@ -288,51 +289,49 @@ public class JFormSliderPane extends JPanel {
}; };
private void getTimes(int value) {
private void getTimes(int value){ if (value == HALF_HUNDRED) {
if (value == HALF_HUNDRED){ times = HUNDRED;
times=HUNDRED; } else if (value < HALF_HUNDRED) {
}else if (value < HALF_HUNDRED){ times = (int) Math.round(ONEPOINTEIGHT * value + TEN);
times = (int) Math.round(ONEPOINTEIGHT*value + TEN); } else {
}else { times = (int) (SIX * value - TWO_HUNDRED);
times = (int) (SIX*value - TWO_HUNDRED);
} }
} }
public JSpinner getShowVal(){ public JSpinner getShowVal() {
return this.showValSpinner; return this.showValSpinner;
} }
public UIRadioButton getSelfAdaptButton(){ public UIRadioButton getSelfAdaptButton() {
return this.selfAdaptButton; return this.selfAdaptButton;
} }
private void popupDialog(){ private void popupDialog() {
Point btnCoords = upButton.getLocationOnScreen(); Point btnCoords = upButton.getLocationOnScreen();
if (dialog == null){ if (dialog == null) {
dialog = new FormPopupPane(upButton,dialogContentPanel); dialog = new FormPopupPane(upButton, dialogContentPanel);
if (upButtonX == 0) { if (upButtonX == 0) {
upButtonX = btnCoords.x; upButtonX = btnCoords.x;
GUICoreUtils.showPopupMenu(dialog, upButton, - DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH , -DIALOG_HEIGHT); GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT);
} }
}else { } else {
if (upButtonX == 0) { if (upButtonX == 0) {
upButtonX = btnCoords.x; upButtonX = btnCoords.x;
GUICoreUtils.showPopupMenu(dialog, upButton, - DIALOG_WIDTH + upButton.getWidth() +SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT);
} else { } else {
GUICoreUtils.showPopupMenu(dialog, upButton, - DIALOG_WIDTH + upButton.getWidth() +SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT);
} }
} }
} }
public static void main(String[] args) public static void main(String[] args) {
{
JFrame jf = new JFrame("test"); JFrame jf = new JFrame("test");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel content = (JPanel)jf.getContentPane(); JPanel content = (JPanel) jf.getContentPane();
content.setLayout(new BorderLayout()); content.setLayout(new BorderLayout());
content.add(JFormSliderPane.getInstance(),BorderLayout.CENTER); content.add(JFormSliderPane.getInstance(), BorderLayout.CENTER);
GUICoreUtils.centerWindow(jf); GUICoreUtils.centerWindow(jf);
jf.setSize(400, 80); jf.setSize(400, 80);
jf.setVisible(true); jf.setVisible(true);
@ -349,17 +348,18 @@ class FormPopupPane extends JPopupMenu {
private static final int UPLABEL_WIDTH = 300; private static final int UPLABEL_WIDTH = 300;
private JComponent centerPane; private JComponent centerPane;
private UILabel upLabel; private UILabel upLabel;
FormPopupPane(UIButton b,JPanel dialogContentPanel) {
FormPopupPane(UIButton b, JPanel dialogContentPanel) {
contentPane = new JPanel(new BorderLayout()); contentPane = new JPanel(new BorderLayout());
centerPane = new JPanel(new BorderLayout()); centerPane = new JPanel(new BorderLayout());
upLabel = new UILabel(" " + Inter.getLocText("FR-Designer_Scale_EnlargeOrReduce")); upLabel = new UILabel(" " + Inter.getLocText("FR-Designer_Scale_EnlargeOrReduce"));
upLabel.setOpaque(true); upLabel.setOpaque(true);
upLabel.setPreferredSize(new Dimension(UPLABEL_WIDTH,UPLABEL_HEIGHT)); upLabel.setPreferredSize(new Dimension(UPLABEL_WIDTH, UPLABEL_HEIGHT));
upLabel.setBackground(Color.LIGHT_GRAY); upLabel.setBackground(Color.LIGHT_GRAY);
upLabel.setBorder(new MatteBorder(0,0,1,0,Color.gray)); upLabel.setBorder(new MatteBorder(0, 0, 1, 0, Color.gray));
centerPane.add(dialogContentPanel,BorderLayout.NORTH); centerPane.add(dialogContentPanel, BorderLayout.NORTH);
contentPane.add(upLabel,BorderLayout.NORTH); contentPane.add(upLabel, BorderLayout.NORTH);
contentPane.add(centerPane,BorderLayout.CENTER); contentPane.add(centerPane, BorderLayout.CENTER);
// contentPane.setBorder(new MatteBorder(1,1,1,1,Color.darkGray)); // contentPane.setBorder(new MatteBorder(1,1,1,1,Color.darkGray));
this.add(contentPane, BorderLayout.CENTER); this.add(contentPane, BorderLayout.CENTER);
this.setPreferredSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT)); this.setPreferredSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT));

176
designer_base/src/com/fr/design/mainframe/JSliderPane.java

@ -18,7 +18,10 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.plaf.basic.BasicSliderUI; import javax.swing.plaf.basic.BasicSliderUI;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
@ -31,7 +34,7 @@ public class JSliderPane extends JPanel {
private static final int TEN = 10; private static final int TEN = 10;
private static final int ONE_EIGHT = 18; private static final int ONE_EIGHT = 18;
private static final int FONT_SIZE = 14; private static final int FONT_SIZE = 14;
private static final int SPINNER_WIDTH= 45; private static final int SPINNER_WIDTH = 45;
private static final int SPINNER_HEIGHT = 20; private static final int SPINNER_HEIGHT = 20;
private static final int HALF_HUNDRED = 50; private static final int HALF_HUNDRED = 50;
private static final int HUNDRED = 100; private static final int HUNDRED = 100;
@ -69,7 +72,7 @@ public class JSliderPane extends JPanel {
public JSliderPane() { public JSliderPane() {
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
slider = new UISlider(0,HUNDRED,HALF_HUNDRED); slider = new UISlider(0, HUNDRED, HALF_HUNDRED);
slider.setUI(new JSliderPaneUI(slider)); slider.setUI(new JSliderPaneUI(slider));
slider.addChangeListener(listener); slider.addChangeListener(listener);
@ -92,19 +95,19 @@ public class JSliderPane extends JPanel {
downButton.addActionListener(buttonActionListener); downButton.addActionListener(buttonActionListener);
upButton.addActionListener(buttonActionListener); upButton.addActionListener(buttonActionListener);
showValButton = new UIButton(showValSpinner.getValue()+"%"); showValButton = new UIButton(showValSpinner.getValue() + "%");
showValButton.setBorderPainted(false); showValButton.setBorderPainted(false);
showValButton.setPreferredSize(new Dimension(SHOWVALBUTTON_WIDTH,SHOWVALBUTTON_HEIGHTH)); showValButton.setPreferredSize(new Dimension(SHOWVALBUTTON_WIDTH, SHOWVALBUTTON_HEIGHTH));
showValButton.addActionListener(showValButtonActionListener); showValButton.addActionListener(showValButtonActionListener);
initUIRadioButton(); initUIRadioButton();
initPane(); initPane();
JPanel panel = new JPanel(new FlowLayout(1,1,0)); JPanel panel = new JPanel(new FlowLayout(1, 1, 0));
panel.add(downButton); panel.add(downButton);
panel.add(slider); panel.add(slider);
panel.add(upButton); panel.add(upButton);
panel.add(showValButton); panel.add(showValButton);
this.add(panel,BorderLayout.NORTH); this.add(panel, BorderLayout.NORTH);
this.setBounds(0,0,THREE_HUNDRED,ONE_EIGHT); this.setBounds(0, 0, THREE_HUNDRED, ONE_EIGHT);
} }
public static final JSliderPane getInstance() { public static final JSliderPane getInstance() {
@ -115,7 +118,7 @@ public class JSliderPane extends JPanel {
return THIS; return THIS;
} }
private void initUIRadioButton(){ private void initUIRadioButton() {
twoHundredButton = new UIRadioButton("200%"); twoHundredButton = new UIRadioButton("200%");
oneHundredButton = new UIRadioButton("100%"); oneHundredButton = new UIRadioButton("100%");
SevenFiveButton = new UIRadioButton("75%"); SevenFiveButton = new UIRadioButton("75%");
@ -131,7 +134,7 @@ public class JSliderPane extends JPanel {
//TODO //TODO
// selfAdaptButton.addItemListener(); // selfAdaptButton.addItemListener();
ButtonGroup bg=new ButtonGroup();// 初始化按钮组 ButtonGroup bg = new ButtonGroup();// 初始化按钮组
bg.add(twoHundredButton);// 加入按钮组 bg.add(twoHundredButton);// 加入按钮组
bg.add(oneHundredButton); bg.add(oneHundredButton);
bg.add(SevenFiveButton); bg.add(SevenFiveButton);
@ -142,24 +145,24 @@ public class JSliderPane extends JPanel {
customButton.setSelected(true); customButton.setSelected(true);
} }
private void initPane(){ private void initPane() {
double p = TableLayout.PREFERRED; double p = TableLayout.PREFERRED;
double f = TableLayout.FILL; double f = TableLayout.FILL;
double[] columnSize = { p, f }; double[] columnSize = {p, f};
double[] rowSize = { p,p,p,p,p,p,p}; double[] rowSize = {p, p, p, p, p, p, p};
Component[][] components = new Component[][]{ Component[][] components = new Component[][]{
new Component[]{twoHundredButton,null}, new Component[]{twoHundredButton, null},
new Component[]{oneHundredButton,null}, new Component[]{oneHundredButton, null},
new Component[]{SevenFiveButton,null}, new Component[]{SevenFiveButton, null},
new Component[]{fiveTenButton,null}, new Component[]{fiveTenButton, null},
new Component[]{twoFiveButton,null}, new Component[]{twoFiveButton, null},
new Component[]{selfAdaptButton,null}, new Component[]{selfAdaptButton, null},
new Component[]{customButton,createSpinnerPanel()} new Component[]{customButton, createSpinnerPanel()}
}; };
dialogContentPanel = TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); dialogContentPanel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
} }
private JPanel createSpinnerPanel(){ private JPanel createSpinnerPanel() {
JPanel spinnerPanel = new JPanel(new FlowLayout()); JPanel spinnerPanel = new JPanel(new FlowLayout());
spinnerPanel.add(showValSpinner); spinnerPanel.add(showValSpinner);
UILabel percent = new UILabel("%"); UILabel percent = new UILabel("%");
@ -178,14 +181,14 @@ public class JSliderPane extends JPanel {
ChangeListener showValSpinnerChangeListener = new ChangeListener() { ChangeListener showValSpinnerChangeListener = new ChangeListener() {
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
int val = (int) ((UIBasicSpinner)e.getSource()).getValue(); int val = (int) ((UIBasicSpinner) e.getSource()).getValue();
isButtonOrIsTxt = true; isButtonOrIsTxt = true;
resolutionTimes = divide(showValue,100,2); resolutionTimes = divide(showValue, 100, 2);
if (val > FOUR_HUNDRED){ if (val > FOUR_HUNDRED) {
showValSpinner.setValue(FOUR_HUNDRED); showValSpinner.setValue(FOUR_HUNDRED);
val = FOUR_HUNDRED; val = FOUR_HUNDRED;
} }
if (val < TEN){ if (val < TEN) {
showValSpinner.setValue(TEN); showValSpinner.setValue(TEN);
val = TEN; val = TEN;
} }
@ -196,11 +199,10 @@ public class JSliderPane extends JPanel {
//定义一个监听器,用于监听所有滑动条 //定义一个监听器,用于监听所有滑动条
ChangeListener listener = new ChangeListener() ChangeListener listener = new ChangeListener() {
{ public void stateChanged(ChangeEvent event) {
public void stateChanged( ChangeEvent event) {
//取出滑动条的值,并在文本中显示出来 //取出滑动条的值,并在文本中显示出来
if (!isButtonOrIsTxt){ if (!isButtonOrIsTxt) {
customButton.setSelected(true); customButton.setSelected(true);
EventQueue.invokeLater(new Runnable() { EventQueue.invokeLater(new Runnable() {
public void run() { public void run() {
@ -210,50 +212,50 @@ public class JSliderPane extends JPanel {
showValSpinner.setValue(times); showValSpinner.setValue(times);
} }
}); });
}else { } else {
isButtonOrIsTxt = false; isButtonOrIsTxt = false;
} }
} }
}; };
ItemListener radioButtonItemListener = new ItemListener() { ItemListener radioButtonItemListener = new ItemListener() {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
JRadioButton temp=(JRadioButton)e.getSource(); JRadioButton temp = (JRadioButton) e.getSource();
if(temp.isSelected()){ if (temp.isSelected()) {
showValSpinner.setValue(Integer.valueOf(temp.getText().substring(0, temp.getText().indexOf("%")))); showValSpinner.setValue(Integer.valueOf(temp.getText().substring(0, temp.getText().indexOf("%"))));
} }
} }
}; };
private void refreshSlider(int val){ private void refreshSlider(int val) {
showValue = val; showValue = val;
if (showValue >HUNDRED){ if (showValue > HUNDRED) {
slider.setValue((int)(showValue+TWO_HUNDRED)/SIX); slider.setValue((int) (showValue + TWO_HUNDRED) / SIX);
}else if (showValue <HUNDRED){ } else if (showValue < HUNDRED) {
slider.setValue((int)((showValue-TEN)/ONEPOINTEIGHT)); slider.setValue((int) ((showValue - TEN) / ONEPOINTEIGHT));
}else if (showValue == HUNDRED){ } else if (showValue == HUNDRED) {
slider.setValue(HALF_HUNDRED); slider.setValue(HALF_HUNDRED);
} }
} }
private void refreshBottun(int val){ private void refreshBottun(int val) {
showValButton.setText(val+"%"); showValButton.setText(val + "%");
} }
public double getResolutionTimes(){ public double getResolutionTimes() {
return this.resolutionTimes; return this.resolutionTimes;
} }
public int getshowValue(){ public int getshowValue() {
return this.showValue; return this.showValue;
} }
public static double divide(double v1, double v2,int scale) { public static double divide(double v1, double v2, int scale) {
BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2)); BigDecimal b2 = new BigDecimal(Double.toString(v2));
return b1.divide(b2,scale).doubleValue(); return b1.divide(b2, scale).doubleValue();
} }
ActionListener buttonActionListener = new ActionListener() { ActionListener buttonActionListener = new ActionListener() {
@ -261,22 +263,22 @@ public class JSliderPane extends JPanel {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showValue = (int) showValSpinner.getValue(); showValue = (int) showValSpinner.getValue();
isButtonOrIsTxt = true; isButtonOrIsTxt = true;
if(e.getActionCommand().equals("less")){ if (e.getActionCommand().equals("less")) {
int newDownVal = showValue - TEN; int newDownVal = showValue - TEN;
if (newDownVal >= TEN ){ if (newDownVal >= TEN) {
showValue = newDownVal; showValue = newDownVal;
showValSpinner.setValue(newDownVal); showValSpinner.setValue(newDownVal);
}else { } else {
showValue = newDownVal; showValue = newDownVal;
showValSpinner.setValue(TEN); showValSpinner.setValue(TEN);
} }
} }
if(e.getActionCommand().equals("more")){ if (e.getActionCommand().equals("more")) {
int newUpVal = showValue + TEN; int newUpVal = showValue + TEN;
if (newUpVal <= FOUR_HUNDRED ){ if (newUpVal <= FOUR_HUNDRED) {
showValue = newUpVal; showValue = newUpVal;
showValSpinner.setValue(newUpVal); showValSpinner.setValue(newUpVal);
}else { } else {
showValue = newUpVal; showValue = newUpVal;
showValSpinner.setValue(FOUR_HUNDRED); showValSpinner.setValue(FOUR_HUNDRED);
} }
@ -287,51 +289,49 @@ public class JSliderPane extends JPanel {
}; };
private void getTimes(int value) {
private void getTimes(int value){ if (value == HALF_HUNDRED) {
if (value == HALF_HUNDRED){ times = HUNDRED;
times=HUNDRED; } else if (value < HALF_HUNDRED) {
}else if (value < HALF_HUNDRED){ times = (int) Math.round(ONEPOINTEIGHT * value + TEN);
times = (int) Math.round(ONEPOINTEIGHT*value + TEN); } else {
}else { times = (int) (SIX * value - TWO_HUNDRED);
times = (int) (SIX*value - TWO_HUNDRED);
} }
} }
public JSpinner getShowVal(){ public JSpinner getShowVal() {
return this.showValSpinner; return this.showValSpinner;
} }
public UIRadioButton getSelfAdaptButton(){ public UIRadioButton getSelfAdaptButton() {
return this.selfAdaptButton; return this.selfAdaptButton;
} }
private void popupDialog(){ private void popupDialog() {
Point btnCoords = upButton.getLocationOnScreen(); Point btnCoords = upButton.getLocationOnScreen();
if (dialog == null){ if (dialog == null) {
dialog = new PopupPane(upButton,dialogContentPanel); dialog = new PopupPane(upButton, dialogContentPanel);
if (upButtonX == 0) { if (upButtonX == 0) {
upButtonX = btnCoords.x; upButtonX = btnCoords.x;
GUICoreUtils.showPopupMenu(dialog, upButton, - DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH , -DIALOG_HEIGHT); GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT);
} }
}else { } else {
if (upButtonX == 0) { if (upButtonX == 0) {
upButtonX = btnCoords.x; upButtonX = btnCoords.x;
GUICoreUtils.showPopupMenu(dialog, upButton, - DIALOG_WIDTH + upButton.getWidth() +SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT);
} else { } else {
GUICoreUtils.showPopupMenu(dialog, upButton, - DIALOG_WIDTH + upButton.getWidth() +SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT);
} }
} }
} }
public static void main(String[] args) public static void main(String[] args) {
{
JFrame jf = new JFrame("test"); JFrame jf = new JFrame("test");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel content = (JPanel)jf.getContentPane(); JPanel content = (JPanel) jf.getContentPane();
content.setLayout(new BorderLayout()); content.setLayout(new BorderLayout());
content.add(JSliderPane.getInstance(),BorderLayout.CENTER); content.add(JSliderPane.getInstance(), BorderLayout.CENTER);
GUICoreUtils.centerWindow(jf); GUICoreUtils.centerWindow(jf);
jf.setSize(400, 80); jf.setSize(400, 80);
jf.setVisible(true); jf.setVisible(true);
@ -359,11 +359,10 @@ class JSliderPaneUI extends BasicSliderUI {
public Dimension getThumbSize() { public Dimension getThumbSize() {
Dimension size = new Dimension(); Dimension size = new Dimension();
if ( slider.getOrientation() == JSlider.VERTICAL ) { if (slider.getOrientation() == JSlider.VERTICAL) {
size.width = VERTICAL_WIDTH; size.width = VERTICAL_WIDTH;
size.height = VERTICAL_HEIGHT; size.height = VERTICAL_HEIGHT;
} } else {
else {
size.width = VERTICAL_WIDTH; size.width = VERTICAL_WIDTH;
size.height = VERTICAL_HEIGHT; size.height = VERTICAL_HEIGHT;
} }
@ -377,14 +376,13 @@ class JSliderPaneUI extends BasicSliderUI {
int h = knobBounds.height; int h = knobBounds.height;
g.translate(knobBounds.x, knobBounds.y); g.translate(knobBounds.x, knobBounds.y);
if ( slider.isEnabled() ) { if (slider.isEnabled()) {
g.setColor(slider.getBackground()); g.setColor(slider.getBackground());
} } else {
else {
g.setColor(slider.getBackground().darker()); g.setColor(slider.getBackground().darker());
} }
g.setColor(Color.darkGray); g.setColor(Color.darkGray);
g.fillRect(0, 1, w-SIX, h+1); g.fillRect(0, 1, w - SIX, h + 1);
} }
/** */ /** */
@ -399,8 +397,8 @@ class JSliderPaneUI extends BasicSliderUI {
cy = (trackBounds.height / 2); cy = (trackBounds.height / 2);
cw = trackBounds.width; cw = trackBounds.width;
g.setColor(Color.lightGray); g.setColor(Color.lightGray);
g.drawLine(0, cy, cw+FIVE, cy); g.drawLine(0, cy, cw + FIVE, cy);
g.drawLine(FIVE+cw/2, cy-FOUR, FIVE+cw/2, cy+FOUR); g.drawLine(FIVE + cw / 2, cy - FOUR, FIVE + cw / 2, cy + FOUR);
} else { } else {
super.paintTrack(g); super.paintTrack(g);
} }
@ -416,17 +414,18 @@ class PopupPane extends JPopupMenu {
private static final int UPLABEL_WIDTH = 300; private static final int UPLABEL_WIDTH = 300;
private JComponent centerPane; private JComponent centerPane;
private UILabel upLabel; private UILabel upLabel;
PopupPane(UIButton b,JPanel dialogContentPanel) {
PopupPane(UIButton b, JPanel dialogContentPanel) {
contentPane = new JPanel(new BorderLayout()); contentPane = new JPanel(new BorderLayout());
centerPane = new JPanel(new BorderLayout()); centerPane = new JPanel(new BorderLayout());
upLabel = new UILabel(" " + Inter.getLocText("FR-Designer_Scale_EnlargeOrReduce")); upLabel = new UILabel(" " + Inter.getLocText("FR-Designer_Scale_EnlargeOrReduce"));
upLabel.setOpaque(true); upLabel.setOpaque(true);
upLabel.setPreferredSize(new Dimension(UPLABEL_WIDTH,UPLABEL_HEIGHT)); upLabel.setPreferredSize(new Dimension(UPLABEL_WIDTH, UPLABEL_HEIGHT));
upLabel.setBackground(Color.LIGHT_GRAY); upLabel.setBackground(Color.LIGHT_GRAY);
upLabel.setBorder(new MatteBorder(0,0,1,0,Color.gray)); upLabel.setBorder(new MatteBorder(0, 0, 1, 0, Color.gray));
centerPane.add(dialogContentPanel,BorderLayout.NORTH); centerPane.add(dialogContentPanel, BorderLayout.NORTH);
contentPane.add(upLabel,BorderLayout.NORTH); contentPane.add(upLabel, BorderLayout.NORTH);
contentPane.add(centerPane,BorderLayout.CENTER); contentPane.add(centerPane, BorderLayout.CENTER);
// contentPane.setBorder(new MatteBorder(1,1,1,1,Color.darkGray)); // contentPane.setBorder(new MatteBorder(1,1,1,1,Color.darkGray));
this.add(contentPane, BorderLayout.CENTER); this.add(contentPane, BorderLayout.CENTER);
this.setPreferredSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT)); this.setPreferredSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT));
@ -434,5 +433,4 @@ class PopupPane extends JPopupMenu {
} }
} }
Loading…
Cancel
Save