diff --git a/designer/src/com/fr/design/cell/bar/DynamicScrollBar.java b/designer/src/com/fr/design/cell/bar/DynamicScrollBar.java index bf61f7a5e..11f8e51b0 100644 --- a/designer/src/com/fr/design/cell/bar/DynamicScrollBar.java +++ b/designer/src/com/fr/design/cell/bar/DynamicScrollBar.java @@ -59,6 +59,10 @@ public class DynamicScrollBar extends JScrollBar { }); } + public void setDpi(int dpi){ + this.dpi = dpi; + } + public ElementCasePane getReportPane() { return reportPane; } @@ -112,6 +116,8 @@ public class DynamicScrollBar extends JScrollBar { } } + + private abstract class DynamicScrollBarHelper extends BarHelper { protected abstract DynamicUnitList getSizeList(); diff --git a/designer/src/com/fr/design/mainframe/ElementCasePane.java b/designer/src/com/fr/design/mainframe/ElementCasePane.java index d55fcd447..17dfa8442 100644 --- a/designer/src/com/fr/design/mainframe/ElementCasePane.java +++ b/designer/src/com/fr/design/mainframe/ElementCasePane.java @@ -12,8 +12,6 @@ import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.event.*; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.lang.reflect.Constructor; import java.util.Set; diff --git a/designer/src/com/fr/design/mainframe/JWorkBook.java b/designer/src/com/fr/design/mainframe/JWorkBook.java index 5978a506f..0a7535067 100644 --- a/designer/src/com/fr/design/mainframe/JWorkBook.java +++ b/designer/src/com/fr/design/mainframe/JWorkBook.java @@ -1,9 +1,6 @@ package com.fr.design.mainframe; -import com.fr.base.BaseUtils; -import com.fr.base.DynamicUnitList; -import com.fr.base.FRContext; -import com.fr.base.Parameter; +import com.fr.base.*; import com.fr.design.DesignModelAdapter; import com.fr.design.ExtraDesignClassManager; import com.fr.design.actions.AllowAuthorityEditAction; @@ -14,6 +11,7 @@ import com.fr.design.actions.report.ReportExportAttrAction; import com.fr.design.actions.report.ReportMobileAttrAction; import com.fr.design.actions.report.ReportParameterAction; import com.fr.design.actions.report.ReportWebAttrAction; +import com.fr.design.cell.bar.DynamicScrollBar; import com.fr.design.constants.UIConstants; import com.fr.design.data.datapane.TableDataTreePane; import com.fr.design.designer.TargetComponent; @@ -70,6 +68,7 @@ import com.fr.stable.module.Module; import com.fr.stable.project.ProjectConstants; import javax.swing.*; +import javax.swing.Icon; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileOutputStream; @@ -334,20 +333,51 @@ public class JWorkBook extends JTemplate { public void setScale(int resolution) { //更新resolution this.resolution = resolution; - reportComposite.centerCardPane.editingComponet.elementCasePane.getGrid().getGridMouseAdapter().setResolution(resolution); - reportComposite.centerCardPane.editingComponet.elementCasePane.getGrid().setResolution(resolution); - //更新Grid - Grid grid = reportComposite.centerCardPane.editingComponet.elementCasePane.getGrid(); - DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(reportComposite.centerCardPane.editingComponet.elementCasePane.getEditingElementCase()); - DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(reportComposite.centerCardPane.editingComponet.elementCasePane.getEditingElementCase()); - grid.setVerticalExtent(GridUtils.getExtentValue(0, rowHeightList, grid.getHeight(), resolution)); - grid.setHorizontalExtent(GridUtils.getExtentValue(0, columnWidthList, grid.getWidth(), resolution)); - reportComposite.centerCardPane.editingComponet.elementCasePane.getGrid().updateUI(); - //更新Column和Row - reportComposite.centerCardPane.editingComponet.elementCasePane.getGridColumn().setResolution(resolution); - reportComposite.centerCardPane.editingComponet.elementCasePane.getGridColumn().updateUI(); - reportComposite.centerCardPane.editingComponet.elementCasePane.getGridRow().setResolution(resolution); - reportComposite.centerCardPane.editingComponet.elementCasePane.getGridRow().updateUI(); + if (reportComposite.centerCardPane.editingComponet.elementCasePane != null){ + reportComposite.centerCardPane.editingComponet.elementCasePane.getGrid().getGridMouseAdapter().setResolution(resolution); + reportComposite.centerCardPane.editingComponet.elementCasePane.getGrid().setResolution(resolution); + //更新Grid + Grid grid = reportComposite.centerCardPane.editingComponet.elementCasePane.getGrid(); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(reportComposite.centerCardPane.editingComponet.elementCasePane.getEditingElementCase()); + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(reportComposite.centerCardPane.editingComponet.elementCasePane.getEditingElementCase()); + grid.setVerticalExtent(GridUtils.getExtentValue(0, rowHeightList, grid.getHeight(), resolution)); + grid.setHorizontalExtent(GridUtils.getExtentValue(0, columnWidthList, grid.getWidth(), resolution)); + reportComposite.centerCardPane.editingComponet.elementCasePane.getGrid().updateUI(); + //更新Column和Row + ((DynamicScrollBar)reportComposite.centerCardPane.editingComponet.elementCasePane.getVerticalScrollBar()).setDpi(resolution); + ((DynamicScrollBar)reportComposite.centerCardPane.editingComponet.elementCasePane.getHorizontalScrollBar()).setDpi(resolution); + reportComposite.centerCardPane.editingComponet.elementCasePane.getGridColumn().setResolution(resolution); + reportComposite.centerCardPane.editingComponet.elementCasePane.getGridColumn().updateUI(); + reportComposite.centerCardPane.editingComponet.elementCasePane.getGridRow().setResolution(resolution); + reportComposite.centerCardPane.editingComponet.elementCasePane.getGridRow().updateUI(); + } + if (reportComposite.centerCardPane.polyDezi != null){ + reportComposite.centerCardPane.polyDezi.setResolution(resolution); + reportComposite.centerCardPane.polyDezi.updateUI(); + } +// reportComposite.centerCardPane.editingComponet.elementCasePane.getGrid().setVerticalValue(10); + + HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().fireTargetModified(); + } + @Override + public int selfAdaptUpdate(){ + ElementCasePane reportPane = reportComposite.centerCardPane.editingComponet.elementCasePane.getGrid().getElementCasePane(); + int column = reportPane.getSelection().getSelectedColumns()[0]; + double columnLength = reportPane.getSelection().getSelectedColumns().length; + double columnExtent = reportPane.getGrid().getHorizontalExtent(); + int row = reportPane.getSelection().getSelectedRows()[0]; + double rowLength = reportPane.getSelection().getSelectedRows().length; + double rowExtent = reportPane.getGrid().getVerticalExtent(); + if (columnLength == 0||rowLength == 0){ + return resolution; + } + double time =(columnExtent/columnLength)<(rowExtent/rowLength) ? (columnExtent/columnLength) : (rowExtent/rowLength); + if (reportPane.isHorizontalScrollBarVisible()) { + reportPane.getVerticalScrollBar().setValue(row); + reportPane.getHorizontalScrollBar().setValue(column); + } + + return (int) (time * reportComposite.centerCardPane.editingComponet.elementCasePane.getGrid().getResolution()); } @Override diff --git a/designer/src/com/fr/design/mainframe/ReportComponent.java b/designer/src/com/fr/design/mainframe/ReportComponent.java index 6ca268545..42342f24e 100644 --- a/designer/src/com/fr/design/mainframe/ReportComponent.java +++ b/designer/src/com/fr/design/mainframe/ReportComponent.java @@ -27,9 +27,13 @@ import com.fr.design.selection.Selectedable; */ public abstract class ReportComponent extends TargetComponent implements Selectedable { protected E elementCasePane; +// protected P polyElementCasePane; public E getEditingElementCasePane() { return elementCasePane; } +// public P getEditingPolyElementCasePane() { +// return polyElementCasePane; +// } public ReportComponent(T t) { super(t); } diff --git a/designer/src/com/fr/design/mainframe/ReportComponentCardPane.java b/designer/src/com/fr/design/mainframe/ReportComponentCardPane.java index 54c7f7657..cc45cf5e9 100644 --- a/designer/src/com/fr/design/mainframe/ReportComponentCardPane.java +++ b/designer/src/com/fr/design/mainframe/ReportComponentCardPane.java @@ -25,7 +25,7 @@ public class ReportComponentCardPane extends JComponent implements TargetModifie private CardLayout cl; private WorkSheetDesigner sheetDezi; - private PolyDesigner polyDezi; + protected PolyDesigner polyDezi; public ReportComponentCardPane() { this.setLayout(cl = new CardLayout()); diff --git a/designer/src/com/fr/design/mainframe/ReportComponentComposite.java b/designer/src/com/fr/design/mainframe/ReportComponentComposite.java index d51db1770..36418924b 100644 --- a/designer/src/com/fr/design/mainframe/ReportComponentComposite.java +++ b/designer/src/com/fr/design/mainframe/ReportComponentComposite.java @@ -1,11 +1,15 @@ package com.fr.design.mainframe; import java.awt.BorderLayout; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; 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; @@ -15,6 +19,7 @@ import com.fr.design.designer.EditingState; import com.fr.design.event.TargetModifiedListener; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.icontainer.UIModeControlContainer; +import com.fr.design.gui.ispinner.UIBasicSpinner; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.general.Inter; import com.fr.grid.Grid; @@ -60,25 +65,28 @@ public class ReportComponentComposite extends JComponent { CellElementRegion = FRGUIPaneFactory.createBorderLayout_S_Pane(); this.add(CellElementRegion, BorderLayout.NORTH); this.add(createSouthControlPane(), BorderLayout.SOUTH); - jSliderContainer.getShowVal().getDocument().addDocumentListener(jSliderContainerListener); + jSliderContainer.getShowVal().addChangeListener(showValSpinnerChangeListener); + jSliderContainer.getSelfAdaptButton().addItemListener(selfAdaptButtonItemListener); } - DocumentListener jSliderContainerListener = new DocumentListener() { + ChangeListener showValSpinnerChangeListener = new ChangeListener() { @Override - public void insertUpdate(DocumentEvent e) { - double value = Integer.parseInt(jSliderContainer.getShowVal().getText().substring(0, jSliderContainer.getShowVal().getText().indexOf("%"))); + public void stateChanged(ChangeEvent e) { + double value = (int) ((UIBasicSpinner)e.getSource()).getValue(); value = value>MAX ? MAX : value; value = value { addlistener(); } + public static void main(String[] args){ + JFrame jf = new JFrame("test"); + jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + JPanel content = (JPanel)jf.getContentPane(); + content.setLayout(new BorderLayout()); + content.add(new BarCodePane(),BorderLayout.CENTER); + GUICoreUtils.centerWindow(jf); + jf.setSize(270, 400); + jf.setVisible(true); + } + private void initComponents() { barCodePreviewPane = new BarCodePreviewPane(); this.barWidthSpinner = new UIBasicSpinner(new SpinnerNumberModel(1, 1, 100, 0.1)); diff --git a/designer/src/com/fr/grid/AbstractGridHeaderMouseHandler.java b/designer/src/com/fr/grid/AbstractGridHeaderMouseHandler.java index 42f7417b5..b68ddd197 100644 --- a/designer/src/com/fr/grid/AbstractGridHeaderMouseHandler.java +++ b/designer/src/com/fr/grid/AbstractGridHeaderMouseHandler.java @@ -41,7 +41,6 @@ public abstract class AbstractGridHeaderMouseHandler extends MouseInputAdapter { protected static final int SEPARATOR_GAP = 5; private GridHeader gHeader; - private int dragType = GridUtils.DRAG_NONE; //james 是否为选定多行的drag private boolean isMultiSelectDragPermited = false; @@ -53,10 +52,16 @@ public abstract class AbstractGridHeaderMouseHandler extends MouseInputAdapter { private int dragIndex = 0; private JToolTip tip = null; private JWindow tipWindow = null; + protected int resolution = ScreenResolution.getScreenResolution(); public AbstractGridHeaderMouseHandler(GridHeader gHeader) { this.gHeader = gHeader; - } + if (gHeader instanceof GridColumn){ + this.resolution = ((GridColumn)gHeader).getResolution(); + }else { + this.resolution = ((GridRow)gHeader).getResolution(); + } + } public void setStartMultiSelectIndex(int index) { this.startMultiSelectIndex = index; @@ -98,7 +103,7 @@ public abstract class AbstractGridHeaderMouseHandler extends MouseInputAdapter { @Override public boolean run(MouseEvent evt, int index, double tmpSize1, double tmpSize2, int tmpIncreaseSize, int oldEndValueSize, ElementCase report, DynamicUnitList sizeList) { - int resolution = ScreenResolution.getScreenResolution(); +// int resolution = ScreenResolution.getScreenResolution(); // richer:这边这么做的原因是调整了行高列宽后需要通知聚合块改变边界 Method method = null; try { @@ -142,7 +147,7 @@ public abstract class AbstractGridHeaderMouseHandler extends MouseInputAdapter { private ScrollAction PRESS_ACTION = new ScrollAction() { @Override public boolean run(MouseEvent evt, int index, double tmpSize1, double tmpSize2, int tmpIncreaseSize, int oldEndValueSize, ElementCase report, DynamicUnitList sizeList) { - int resolution = ScreenResolution.getScreenResolution(); +// int resolution = ScreenResolution.getScreenResolution(); if (isOnSeparatorLineIncludeZero(evt, tmpSize2, tmpIncreaseSize) || isOnNormalSeparatorLine(evt, tmpSize2)) { dragType = GridUtils.DRAG_CELL_SIZE; @@ -177,7 +182,7 @@ public abstract class AbstractGridHeaderMouseHandler extends MouseInputAdapter { double tmpIncreaseSize = 0; double oldEndValueSize = 0; - int resolution = ScreenResolution.getScreenResolution(); +// int resolution = ScreenResolution.getScreenResolution(); for (int index = beginValue; index < endValue; index++) { // denny: // beginValue @@ -215,7 +220,7 @@ public abstract class AbstractGridHeaderMouseHandler extends MouseInputAdapter { ePane.getGrid().stopEditing();// james 停止当前的所有编辑 // peter:选中格子位置. - ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(ePane, evt.getX(), evt.getY()); + ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow_withresolution(ePane, evt.getX(), evt.getY(),resolution); iterateScrollBar(ePane, evt, PRESS_ACTION); @@ -255,7 +260,7 @@ public abstract class AbstractGridHeaderMouseHandler extends MouseInputAdapter { * @param evtY */ private void doShiftSelectHeader(ElementCasePane ePane, double evtX, double evtY) { - ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(ePane, evtX, evtY); + ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow_withresolution(ePane, evtX, evtY, resolution); int selectedCellPointX = selectedCellPoint.getColumn();// column. int selectedCellPointY = selectedCellPoint.getRow();// row. CellSelection cs = ((CellSelection) ePane.getSelection()).clone(); @@ -294,7 +299,7 @@ public abstract class AbstractGridHeaderMouseHandler extends MouseInputAdapter { private String createToolTipString(double doubleValue, double totalDoubleValue) { int unitType = DesignerEnvManager.getEnvManager().getReportLengthUnit(); - int resolution = ScreenResolution.getScreenResolution(); +// int resolution = ScreenResolution.getScreenResolution(); FU ulen = FU.valueOfPix((int) doubleValue, resolution); FU tulen = FU.valueOfPix((int) totalDoubleValue, resolution); String unit; @@ -317,11 +322,11 @@ public abstract class AbstractGridHeaderMouseHandler extends MouseInputAdapter { unit = Inter.getLocText("Unit_MM"); } StringBuilder sb = new StringBuilder(); - sb.append(Utils.convertNumberStringToString(new Float(len))) - .append('/').append(Utils.convertNumberStringToString(new Float(tlen))) + sb.append(String.format("%.2f", new Double(len))) + .append('/').append(String.format("%.2f", new Double(tlen))) .append(unit).append('(') - .append(Utils.doubleToString(doubleValue)).append('/') - .append(Utils.doubleToString(totalDoubleValue)) + .append((int)(doubleValue)).append('/') + .append((int)(totalDoubleValue)) .append(Inter.getLocText("px")) .append(')'); return sb.toString(); @@ -401,7 +406,7 @@ public abstract class AbstractGridHeaderMouseHandler extends MouseInputAdapter { if (!this.isMultiSelectDragPermited) { return; } - ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(ePane, evt.getX(), evt.getY()); + ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow_withresolution(ePane, evt.getX(), evt.getY(), resolution); endMultiSelectIndex = getColumnOrRowByGridHeader(selectedCellPoint); resetGridSelectionByDrag(cs, ePane, startMultiSelectIndex, endMultiSelectIndex); cs.setSelectedType(doChooseFrom()); @@ -421,7 +426,7 @@ public abstract class AbstractGridHeaderMouseHandler extends MouseInputAdapter { iterateScrollBar(ePane, evt, DRAG_ACTION); DynamicUnitList sizeList = getSizeList(report); - int resolution = ScreenResolution.getScreenResolution(); +// int resolution = ScreenResolution.getScreenResolution(); this.setToolTipText2(this.createToolTipString(sizeList.get(dragIndex).toPixD(resolution), sizeList.getRangeValue(0, dragIndex + 1).toPixD(resolution))); } @@ -472,7 +477,7 @@ public abstract class AbstractGridHeaderMouseHandler extends MouseInputAdapter { double tmpSize1 = 0; double tmpSize2; double tmpIncreaseSize = 0; - int resolution = ScreenResolution.getScreenResolution(); +// int resolution = ScreenResolution.getScreenResolution(); for (int i = beginValue; i < endValue; i++) { if (i == 0) { diff --git a/designer/src/com/fr/grid/Grid.java b/designer/src/com/fr/grid/Grid.java index 6bade0e2e..01a2bb1d8 100644 --- a/designer/src/com/fr/grid/Grid.java +++ b/designer/src/com/fr/grid/Grid.java @@ -141,6 +141,10 @@ public class Grid extends BaseGridComponent { this.resolution = resolution; } + public int getResolution() { + return this.resolution; + } + /** * 应用界面设置 * diff --git a/designer/src/com/fr/grid/GridColumn.java b/designer/src/com/fr/grid/GridColumn.java index eedf8bcaf..165a5727a 100644 --- a/designer/src/com/fr/grid/GridColumn.java +++ b/designer/src/com/fr/grid/GridColumn.java @@ -10,6 +10,7 @@ import com.fr.base.ScreenResolution; import com.fr.design.ExtraDesignClassManager; import com.fr.design.fun.GridUIProcessor; import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.mainframe.JSliderPane; import com.fr.stable.StableUtils; import javax.swing.plaf.ComponentUI; @@ -22,11 +23,15 @@ import javax.swing.plaf.ComponentUI; */ public class GridColumn extends GridHeader { - private int resolution = ScreenResolution.getScreenResolution(); + public int resolution = ScreenResolution.getScreenResolution(); + + private GridColumnMouseHandler gridColumnMouseHandler; @Override protected void initByConstructor() { - GridColumnMouseHandler gridColumnMouseHandler = new GridColumnMouseHandler(this); + resolution = ScreenResolution.getScreenResolution(); + this.setResolution(resolution); + gridColumnMouseHandler = new GridColumnMouseHandler(this); this.addMouseListener(gridColumnMouseHandler); this.addMouseMotionListener(gridColumnMouseHandler); this.updateUI(); @@ -39,6 +44,12 @@ public class GridColumn extends GridHeader { @Override public void updateUI() { + this.removeMouseListener(gridColumnMouseHandler); + this.removeMouseMotionListener(gridColumnMouseHandler); + gridColumnMouseHandler = new GridColumnMouseHandler(this); + this.addMouseListener(gridColumnMouseHandler); + this.addMouseMotionListener(gridColumnMouseHandler); +// gridColumnMouseHandler.setResolution(resolution); this.setUI(new GridColumnUI(resolution)); } @@ -46,6 +57,11 @@ public class GridColumn extends GridHeader { this.resolution = resolution; } + @Override + public int getResolution() { + return this.resolution; + } + /** * Gets the preferred size. */ diff --git a/designer/src/com/fr/grid/GridColumnMouseHandler.java b/designer/src/com/fr/grid/GridColumnMouseHandler.java index b7864bf05..2d93d01d2 100644 --- a/designer/src/com/fr/grid/GridColumnMouseHandler.java +++ b/designer/src/com/fr/grid/GridColumnMouseHandler.java @@ -9,6 +9,7 @@ import java.awt.event.MouseEvent; import javax.swing.SwingUtilities; import com.fr.base.DynamicUnitList; +import com.fr.base.ScreenResolution; import com.fr.design.gui.imenu.UIPopupMenu; import com.fr.design.mainframe.ElementCasePane; import com.fr.grid.selection.CellSelection; @@ -22,8 +23,15 @@ import com.fr.stable.ColumnRow; */ public class GridColumnMouseHandler extends AbstractGridHeaderMouseHandler { + private int resolution; + public GridColumnMouseHandler(GridColumn gridColumn) { super(gridColumn); + this.resolution = gridColumn.resolution; + } + + public void setResolution(int resolution){ + this.resolution = resolution; } @Override @@ -86,7 +94,6 @@ public class GridColumnMouseHandler extends AbstractGridHeaderMouseHandler { /** * Checks whether is on zero separator line. * - * @param evtX event x */ @Override protected boolean isOnSeparatorLineIncludeZero(MouseEvent evt, double tmpWidth2, double tmpIncreaseWidth) { diff --git a/designer/src/com/fr/grid/GridHeader.java b/designer/src/com/fr/grid/GridHeader.java index 754257e2f..b0dca649d 100644 --- a/designer/src/com/fr/grid/GridHeader.java +++ b/designer/src/com/fr/grid/GridHeader.java @@ -1,5 +1,7 @@ package com.fr.grid; +import com.fr.base.ScreenResolution; + import java.awt.Color; @@ -12,6 +14,8 @@ public abstract class GridHeader extends BaseGridComponent { private Color selectedForeground = Color.black; private Color selectedBackground = new Color(253, 216, 153); + protected int resolution; + public GridHeader() { //清除所有的Key Action. this.getInputMap().clear(); @@ -23,6 +27,14 @@ public abstract class GridHeader extends BaseGridComponent { initByConstructor(); } + public void setResolution(int resolution){ + this.resolution = resolution; + } + + public int getResolution(){ + return this.resolution; + } + protected abstract void initByConstructor(); protected abstract T getDisplay(int index) ; diff --git a/designer/src/com/fr/grid/GridRow.java b/designer/src/com/fr/grid/GridRow.java index 4c42ce630..28a97e170 100644 --- a/designer/src/com/fr/grid/GridRow.java +++ b/designer/src/com/fr/grid/GridRow.java @@ -23,10 +23,13 @@ public class GridRow extends GridHeader { private static final int MAX = 5; private int resolution = ScreenResolution.getScreenResolution(); + private GridRowMouseHandler gridRowMouseHandler; @Override protected void initByConstructor() { - GridRowMouseHandler gridRowMouseHandler = new GridRowMouseHandler(this); + resolution = ScreenResolution.getScreenResolution(); + this.setResolution(resolution); + gridRowMouseHandler = new GridRowMouseHandler(this); this.addMouseListener(gridRowMouseHandler); this.addMouseMotionListener(gridRowMouseHandler); this.updateUI(); @@ -39,6 +42,11 @@ public class GridRow extends GridHeader { @Override public void updateUI() { + this.removeMouseListener(gridRowMouseHandler); + this.removeMouseMotionListener(gridRowMouseHandler); + gridRowMouseHandler = new GridRowMouseHandler(this); + this.addMouseListener(gridRowMouseHandler); + this.addMouseMotionListener(gridRowMouseHandler); this.setUI(new GridRowUI(resolution)); } @@ -46,6 +54,10 @@ public class GridRow extends GridHeader { this.resolution = resolution; } + public int getResolution() { + return this.resolution; + } + /** * Gets the preferred size. diff --git a/designer_base/src/com/fr/design/mainframe/JSliderPane.java b/designer_base/src/com/fr/design/mainframe/JSliderPane.java index 18ab15a0b..c4cdf377f 100644 --- a/designer_base/src/com/fr/design/mainframe/JSliderPane.java +++ b/designer_base/src/com/fr/design/mainframe/JSliderPane.java @@ -1,11 +1,15 @@ package com.fr.design.mainframe; import com.fr.base.BaseUtils; +import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.islider.UISlider; +import com.fr.design.gui.ispinner.UIBasicSpinner; import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.Inter; @@ -13,8 +17,6 @@ import javax.swing.*; import javax.swing.border.MatteBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; import javax.swing.plaf.basic.BasicSliderUI; import java.awt.*; import java.awt.event.*; @@ -29,6 +31,9 @@ public class JSliderPane extends JPanel { private static final int SIX = 6; private static final int TEN = 10; private static final int ONEEIGHT = 18; + private static final int FONTSIZE = 14; + private static final int SPINNERWIDTH= 45; + private static final int SPINNERHEIGHT = 20; private static final int TWOFIVE = 25; private static final int FOURTEN = 40; private static final int HALFHUNDRED = 50; @@ -37,11 +42,14 @@ public class JSliderPane extends JPanel { private static final int THREEHUNDRED = 300; private static final int FOURHUNDRED = 400; private static final int DIALOGWIDTH = 150; - private static final int DIALOGHEIGHT = 200; + private static final int DIALOGHEIGHT = 240; + private static final int SHOWVALBUTTONWIDTH = 70; + private static final int SHOWVALBUTTONHEIGHTH = 25; public int showValue = 100; public double resolutionTimes = 1.0; private static JSliderPane THIS; private UITextField showVal; + private JSpinner showValSpinner; private UISlider slider; private int times; private int sliderValue; @@ -59,6 +67,7 @@ public class JSliderPane extends JPanel { private boolean isButtonOrIsTxt = true; private PopupPane dialog; private int upButtonX; + private JPanel dialogContentPanel; public JSliderPane() { @@ -67,11 +76,18 @@ public class JSliderPane extends JPanel { slider.setUI(new JSliderPaneUI(slider)); slider.addChangeListener(listener); - showVal = new UITextField(); - showVal.setText("100%"); - showVal.setPreferredSize(new Dimension(FOURTEN,ONEEIGHT)); - showVal.getDocument().addDocumentListener(showValDocumentListener); - + showValSpinner = new UIBasicSpinner(new SpinnerNumberModel(HUNDRED, TEN, FOURHUNDRED, 1)); + showValSpinner.setEnabled(true); + showValSpinner.addChangeListener(showValSpinnerChangeListener); + showValSpinner.setPreferredSize(new Dimension(SPINNERWIDTH, SPINNERHEIGHT)); + //MoMeak:控制只能输入10-400,但是用起来感觉不舒服,先注释掉吧 +// JSpinner.NumberEditor editor = new JSpinner.NumberEditor(showValSpinner, "0"); +// showValSpinner.setEditor(editor); +// JFormattedTextField textField = ((JSpinner.NumberEditor) showValSpinner.getEditor()).getTextField(); +// textField.setEditable(true); +// DefaultFormatterFactory factory = (DefaultFormatterFactory) textField .getFormatterFactory(); +// NumberFormatter formatter = (NumberFormatter) factory.getDefaultFormatter(); +// formatter.setAllowsInvalid(false); downButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/data/source/moveDown.png")); upButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/data/source/moveUp.png")); downButton.setActionCommand("less"); @@ -79,25 +95,20 @@ public class JSliderPane extends JPanel { downButton.addActionListener(buttonActionListener); upButton.addActionListener(buttonActionListener); - JPanel panel = new JPanel(new FlowLayout(1,1,0)); - - showValButton = new UIButton(showVal.getText()); + showValButton = new UIButton(showValSpinner.getValue()+"%"); showValButton.setBorderPainted(false); - showValButton.setPreferredSize(new Dimension(HALFHUNDRED,TWOFIVE)); + showValButton.setPreferredSize(new Dimension(SHOWVALBUTTONWIDTH,SHOWVALBUTTONHEIGHTH)); + showValButton.addActionListener(showValButtonActionListener); - showValButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - popupDialog(); - } - }); + initUIRadioButton(); + initPane(); + JPanel panel = new JPanel(new FlowLayout(1,1,0)); panel.add(downButton); panel.add(slider); panel.add(upButton); panel.add(showValButton); this.add(panel,BorderLayout.NORTH); this.setBounds(0,0,THREEHUNDRED,ONEEIGHT); - } public static final JSliderPane getInstance() { @@ -116,6 +127,13 @@ public class JSliderPane extends JPanel { twoFiveButton = new UIRadioButton("25%"); selfAdaptButton = new UIRadioButton(Inter.getLocText("FR-Designer_Scale_selfAdaptButton")); customButton = new UIRadioButton(Inter.getLocText("FR-Designer_Scale_customButton")); + twoHundredButton.addItemListener(radioButtonItemListener); + oneHundredButton.addItemListener(radioButtonItemListener); + SevenFiveButton.addItemListener(radioButtonItemListener); + fiveTenButton.addItemListener(radioButtonItemListener); + twoFiveButton.addItemListener(radioButtonItemListener); + //TODO +// selfAdaptButton.addItemListener(); ButtonGroup bg=new ButtonGroup();// 初始化按钮组 bg.add(twoHundredButton);// 加入按钮组 @@ -125,8 +143,53 @@ public class JSliderPane extends JPanel { bg.add(twoFiveButton); bg.add(selfAdaptButton); bg.add(customButton); + customButton.setSelected(true); + } + + private void initPane(){ + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = { p, f }; + double[] rowSize = { p,p,p,p,p,p,p}; + Component[][] components = new Component[][]{ + new Component[]{twoHundredButton,null}, + new Component[]{oneHundredButton,null}, + new Component[]{SevenFiveButton,null}, + new Component[]{fiveTenButton,null}, + new Component[]{twoFiveButton,null}, + new Component[]{selfAdaptButton,null}, + new Component[]{customButton,createSpinnerPanel()} + }; + dialogContentPanel = TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); + } + + private JPanel createSpinnerPanel(){ + JPanel spinnerPanel = new JPanel(new FlowLayout()); + spinnerPanel.add(showValSpinner); + UILabel percent = new UILabel("%"); + percent.setFont(new Font("Dialog", Font.PLAIN, FONTSIZE)); + spinnerPanel.add(percent); + return spinnerPanel; } + ActionListener showValButtonActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + popupDialog(); + } + }; + + ChangeListener showValSpinnerChangeListener = new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + int val = (int) ((UIBasicSpinner)e.getSource()).getValue(); + isButtonOrIsTxt = true; + resolutionTimes = divide(showValue,100,2); + refreshSlider(val); + refreshBottun(val); + } + }; + //定义一个监听器,用于监听所有滑动条 ChangeListener listener = new ChangeListener() @@ -134,13 +197,13 @@ public class JSliderPane extends JPanel { public void stateChanged( ChangeEvent event) { //取出滑动条的值,并在文本中显示出来 if (!isButtonOrIsTxt){ - JSlider source = (JSlider) event.getSource(); + customButton.setSelected(true); EventQueue.invokeLater(new Runnable() { public void run() { sliderValue = slider.getValue(); getTimes(sliderValue); showValue = times; - showVal.setText(times + "%"); + showValSpinner.setValue(times); } }); }else { @@ -149,28 +212,18 @@ public class JSliderPane extends JPanel { } }; - DocumentListener showValDocumentListener = new DocumentListener() { + ItemListener radioButtonItemListener = new ItemListener() { @Override - public void insertUpdate(DocumentEvent e) { - isButtonOrIsTxt = true; - resolutionTimes = divide(showValue,100,2); - refreshSlider(); - refreshBottun(); - } - - @Override - public void removeUpdate(DocumentEvent e) { -// refreshSlider(); - } - - @Override - public void changedUpdate(DocumentEvent e) { -// refreshSlider(); + public void itemStateChanged(ItemEvent e) { + JRadioButton temp=(JRadioButton)e.getSource(); + if(temp.isSelected()){ + showValSpinner.setValue(Integer.valueOf(temp.getText().substring(0, temp.getText().indexOf("%")))); + } } }; - private void refreshSlider(){ - showValue = Integer.parseInt(showVal.getText().substring(0, showVal.getText().indexOf("%"))); + private void refreshSlider(int val){ + showValue = val; if (showValue >HUNDRED){ slider.setValue((int)(showValue+TWOHUNDRED)/SIX); }else if (showValue = TEN ){ showValue = newDownVal; - showVal.setText(newDownVal + "%"); + showValSpinner.setValue(newDownVal); }else { showValue = newDownVal; - showVal.setText(TEN + "%"); + showValSpinner.setValue(TEN); } } if(e.getActionCommand().equals("more")){ int newUpVal = showValue + TEN; if (newUpVal <= FOURHUNDRED ){ showValue = newUpVal; - showVal.setText(newUpVal + "%"); + showValSpinner.setValue(newUpVal); }else { showValue = newUpVal; - showVal.setText(FOURHUNDRED + "%"); + showValSpinner.setValue(FOURHUNDRED); } } isButtonOrIsTxt = true; + customButton.setSelected(true); } }; @@ -241,38 +295,42 @@ public class JSliderPane extends JPanel { } - public UITextField getShowVal(){ - return this.showVal; + public JSpinner getShowVal(){ + return this.showValSpinner; + } + + public UIRadioButton getSelfAdaptButton(){ + return this.selfAdaptButton; } private void popupDialog(){ Point btnCoords = upButton.getLocationOnScreen(); if (dialog == null){ - dialog = new PopupPane(upButton,showVal); + dialog = new PopupPane(upButton,dialogContentPanel); if (upButtonX == 0) { upButtonX = btnCoords.x; - GUICoreUtils.showPopupMenu(dialog, upButton, - DIALOGWIDTH + upButton.getWidth() +HALFHUNDRED, -DIALOGHEIGHT); + GUICoreUtils.showPopupMenu(dialog, upButton, - DIALOGWIDTH + upButton.getWidth() + SHOWVALBUTTONWIDTH , -DIALOGHEIGHT); } }else { if (upButtonX == 0) { upButtonX = btnCoords.x; - GUICoreUtils.showPopupMenu(dialog, upButton, - DIALOGWIDTH + upButton.getWidth() +HALFHUNDRED, -DIALOGHEIGHT); + GUICoreUtils.showPopupMenu(dialog, upButton, - DIALOGWIDTH + upButton.getWidth() +SHOWVALBUTTONWIDTH, -DIALOGHEIGHT); } else { - GUICoreUtils.showPopupMenu(dialog, upButton, - DIALOGWIDTH + upButton.getWidth() +HALFHUNDRED, -DIALOGHEIGHT); + GUICoreUtils.showPopupMenu(dialog, upButton, - DIALOGWIDTH + upButton.getWidth() +SHOWVALBUTTONWIDTH, -DIALOGHEIGHT); } } } public static void main(String[] args) { - JFrame jf = new JFrame("test"); - jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - JPanel content = (JPanel)jf.getContentPane(); - content.setLayout(new BorderLayout()); - content.add(JSliderPane.getInstance(),BorderLayout.CENTER); - GUICoreUtils.centerWindow(jf); - jf.setSize(400, 80); - jf.setVisible(true); +// JFrame jf = new JFrame("test"); +// jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); +// JPanel content = (JPanel)jf.getContentPane(); +// content.setLayout(new BorderLayout()); +// content.add(JSliderPane.getInstance(),BorderLayout.CENTER); +// GUICoreUtils.centerWindow(jf); +// jf.setSize(400, 80); +// jf.setVisible(true); } } @@ -345,66 +403,25 @@ class JSliderPaneUI extends BasicSliderUI { } } -class Dialog extends JDialog { -// private Container container; -// private static final int UPLABELHEIGHT = 25; -// private static final int HALFHUNDRED = 50; -// private static final int DIALOGWIDTH = 150; -// private static final int DIALOGHEIGHT = 200; -// private static final int UPLABELWIDTH = 300; -// private int minHeight; // 对话框最小高度 -// private JComponent contentPane; -// private JComponent centerPane; -// private UILabel upLabel; - -// public Dialog(UIButton b,UITextField j) { -// super(DesignerContext.getDesignerFrame()); -// container = getContentPane(); -// setUndecorated(true); -// contentPane = new JPanel(new BorderLayout()); -// centerPane = new JPanel(new BorderLayout()); -// upLabel = new UILabel(Inter.getLocText("FR-Designer_Scale_EnlargeOrReduce")); -// upLabel.setOpaque(true); -// upLabel.setPreferredSize(new Dimension(UPLABELWIDTH,UPLABELHEIGHT)); -// upLabel.setBackground(Color.LIGHT_GRAY); -// upLabel.setBorder(BorderFactory.createLineBorder(Color.gray,1)); -// upLabel.setBorder(new MatteBorder(0,0,1,0,Color.gray)); -// centerPane.add(j,BorderLayout.NORTH); -// contentPane.add(upLabel,BorderLayout.NORTH); -// contentPane.add(centerPane,BorderLayout.CENTER); -//// contentPane.setBorder(BorderFactory.createLineBorder(Color.gray,1)); -// contentPane.setBorder(new MatteBorder(1,1,1,1,Color.darkGray)); -//// contentPane.add(new JPanel()) -// container.add(contentPane, BorderLayout.CENTER); -// minHeight = container.getPreferredSize().height; -// setSize(DIALOGWIDTH, DIALOGHEIGHT); -//// validate(); -// Point btnCoords = b.getLocationOnScreen(); -// -// this.setLocation(btnCoords.x - DIALOGWIDTH + b.getWidth() +HALFHUNDRED, btnCoords.y -DIALOGHEIGHT); -//// initListener(); -// -// this.setVisible(true); -// } -} + class PopupPane extends JPopupMenu { private JComponent contentPane; private static final int UPLABELHEIGHT = 25; private static final int HALFHUNDRED = 50; private static final int DIALOGWIDTH = 150; - private static final int DIALOGHEIGHT = 200; + private static final int DIALOGHEIGHT = 240; private static final int UPLABELWIDTH = 300; private JComponent centerPane; private UILabel upLabel; - PopupPane(UIButton b,UITextField j) { + PopupPane(UIButton b,JPanel dialogContentPanel) { contentPane = 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.setPreferredSize(new Dimension(UPLABELWIDTH,UPLABELHEIGHT)); upLabel.setBackground(Color.LIGHT_GRAY); upLabel.setBorder(new MatteBorder(0,0,1,0,Color.gray)); - centerPane.add(j,BorderLayout.NORTH); + centerPane.add(dialogContentPanel,BorderLayout.NORTH); contentPane.add(upLabel,BorderLayout.NORTH); contentPane.add(centerPane,BorderLayout.CENTER); // contentPane.setBorder(new MatteBorder(1,1,1,1,Color.darkGray)); diff --git a/designer_base/src/com/fr/design/mainframe/JTemplate.java b/designer_base/src/com/fr/design/mainframe/JTemplate.java index a5023be82..309fac533 100644 --- a/designer_base/src/com/fr/design/mainframe/JTemplate.java +++ b/designer_base/src/com/fr/design/mainframe/JTemplate.java @@ -217,6 +217,8 @@ public abstract class JTemplate> ex public abstract int getScale(); + public abstract int selfAdaptUpdate(); + protected abstract DesignModelAdapter createDesignModel(); /** diff --git a/designer_form/src/com/fr/design/mainframe/FormArea.java b/designer_form/src/com/fr/design/mainframe/FormArea.java index 0d0e05f04..b7853183e 100644 --- a/designer_form/src/com/fr/design/mainframe/FormArea.java +++ b/designer_form/src/com/fr/design/mainframe/FormArea.java @@ -31,6 +31,7 @@ import com.fr.design.designer.creator.XWFitLayout; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.frpane.UINumberSlidePane; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.ispinner.UIBasicSpinner; import com.fr.design.gui.itextfield.UINumberField; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; @@ -153,11 +154,13 @@ public class FormArea extends JComponent implements ScrollRulerComponent { private void initTransparent() { initCalculateSize(); - slidePane.getShowVal().getDocument().addDocumentListener(new DocumentListener() { - @Override - public void insertUpdate(DocumentEvent e) { -// slidePane.getShowVal().getDocument() - double value = Integer.parseInt(slidePane.getShowVal().getText().substring(0, slidePane.getShowVal().getText().indexOf("%"))); + slidePane.getShowVal().addChangeListener(showValSpinnerChangeListener); + } + + ChangeListener showValSpinnerChangeListener = new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + double value = (int) ((UIBasicSpinner)e.getSource()).getValue(); value = value>SHOWVALMAX ? SHOWVALMAX : value; value = value implements BaseJForm { return 0; } + @Override + public int selfAdaptUpdate() { + return 0; + } + /** * 创建权限细粒度编辑面板 *