Lanlan
5 years ago
50 changed files with 1402 additions and 455 deletions
@ -0,0 +1,53 @@ |
|||||||
|
package com.fr.design.base.clipboard; |
||||||
|
|
||||||
|
import com.fr.design.fun.ClipboardHandlerProvider; |
||||||
|
import com.fr.form.main.ExtraFormClassManager; |
||||||
|
import com.fr.plugin.injectable.PluginModule; |
||||||
|
|
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
/** |
||||||
|
* created by Harrison on 2020/05/14 |
||||||
|
**/ |
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"}) |
||||||
|
public abstract class ClipboardFilter { |
||||||
|
|
||||||
|
public static <T> T cut(T selection) { |
||||||
|
|
||||||
|
Class<?> clazz = selection.getClass(); |
||||||
|
ExtraFormClassManager manager = PluginModule.getAgent(PluginModule.ExtraForm); |
||||||
|
Set<ClipboardHandlerProvider> providers = manager.getArray(ClipboardHandlerProvider.XML_TAG); |
||||||
|
for (ClipboardHandlerProvider provider : providers) { |
||||||
|
if (provider.support(clazz)) { |
||||||
|
selection = ((ClipboardHandlerProvider<T>) provider).cut(selection); |
||||||
|
} |
||||||
|
} |
||||||
|
return selection; |
||||||
|
} |
||||||
|
|
||||||
|
public static <T> T copy(T selection) { |
||||||
|
|
||||||
|
Class<?> clazz = selection.getClass(); |
||||||
|
ExtraFormClassManager manager = PluginModule.getAgent(PluginModule.ExtraForm); |
||||||
|
Set<ClipboardHandlerProvider> providers = manager.getArray(ClipboardHandlerProvider.XML_TAG); |
||||||
|
for (ClipboardHandlerProvider provider : providers) { |
||||||
|
if (provider.support(clazz)) { |
||||||
|
selection = ((ClipboardHandlerProvider<T>) provider).copy(selection); |
||||||
|
} |
||||||
|
} |
||||||
|
return selection; |
||||||
|
} |
||||||
|
|
||||||
|
public static <T> T paste(T selection) { |
||||||
|
|
||||||
|
Class<?> clazz = selection.getClass(); |
||||||
|
ExtraFormClassManager manager = PluginModule.getAgent(PluginModule.ExtraForm); |
||||||
|
Set<ClipboardHandlerProvider> providers = manager.getArray(ClipboardHandlerProvider.XML_TAG); |
||||||
|
for (ClipboardHandlerProvider provider : providers) { |
||||||
|
if (provider.support(clazz)) { |
||||||
|
selection = ((ClipboardHandlerProvider<T>) provider).paste(selection); |
||||||
|
} |
||||||
|
} |
||||||
|
return selection; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,68 @@ |
|||||||
|
package com.fr.design.base.clipboard; |
||||||
|
|
||||||
|
import java.awt.datatransfer.Clipboard; |
||||||
|
import java.awt.datatransfer.ClipboardOwner; |
||||||
|
import java.awt.datatransfer.DataFlavor; |
||||||
|
import java.awt.datatransfer.FlavorListener; |
||||||
|
import java.awt.datatransfer.Transferable; |
||||||
|
import java.awt.datatransfer.UnsupportedFlavorException; |
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
|
/** |
||||||
|
* created by Harrison on 2020/05/11 |
||||||
|
**/ |
||||||
|
public class DesignerClipboard extends Clipboard { |
||||||
|
|
||||||
|
private Clipboard clipboard; |
||||||
|
|
||||||
|
public DesignerClipboard(Clipboard clipboard) { |
||||||
|
super(clipboard.getName()); |
||||||
|
this.clipboard = clipboard; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public synchronized void setContents(Transferable contents, ClipboardOwner owner) { |
||||||
|
//处理 contents/owner
|
||||||
|
Transferable filtered = ClipboardFilter.copy(contents); |
||||||
|
clipboard.setContents(filtered, owner); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public synchronized Transferable getContents(Object requestor) { |
||||||
|
Transferable contents = clipboard.getContents(requestor); |
||||||
|
//处理 contents
|
||||||
|
Transferable filtered = ClipboardFilter.paste(contents); |
||||||
|
return filtered; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public DataFlavor[] getAvailableDataFlavors() { |
||||||
|
return clipboard.getAvailableDataFlavors(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isDataFlavorAvailable(DataFlavor flavor) { |
||||||
|
return clipboard.isDataFlavorAvailable(flavor); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { |
||||||
|
return clipboard.getData(flavor); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public synchronized void addFlavorListener(FlavorListener listener) { |
||||||
|
clipboard.addFlavorListener(listener); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public synchronized void removeFlavorListener(FlavorListener listener) { |
||||||
|
clipboard.removeFlavorListener(listener); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public synchronized FlavorListener[] getFlavorListeners() { |
||||||
|
return clipboard.getFlavorListeners(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
package com.fr.design.fun; |
||||||
|
|
||||||
|
import com.fr.stable.fun.mark.Mutable; |
||||||
|
|
||||||
|
/** |
||||||
|
* created by Harrison on 2020/05/14 |
||||||
|
**/ |
||||||
|
public interface ClipboardHandlerProvider<T> extends Mutable { |
||||||
|
|
||||||
|
String XML_TAG = "ClipboardHandlerProvider"; |
||||||
|
|
||||||
|
int CURRENT_LEVEL = 1; |
||||||
|
|
||||||
|
/** |
||||||
|
* 剪切 |
||||||
|
* |
||||||
|
* @param selection 选中 |
||||||
|
* @return 处理后的内容 |
||||||
|
*/ |
||||||
|
T cut(T selection); |
||||||
|
|
||||||
|
/** |
||||||
|
* 复制 |
||||||
|
* |
||||||
|
* @param selection 选中 |
||||||
|
* @return 处理后的内容 |
||||||
|
*/ |
||||||
|
T copy(T selection); |
||||||
|
|
||||||
|
/** |
||||||
|
* 粘贴 |
||||||
|
* |
||||||
|
* @param selection 选中 |
||||||
|
* @return 处理后的内容 |
||||||
|
*/ |
||||||
|
T paste(T selection); |
||||||
|
|
||||||
|
/** |
||||||
|
* 支持的类型 |
||||||
|
* |
||||||
|
* @param selection 内容 |
||||||
|
* @return 是否 |
||||||
|
*/ |
||||||
|
boolean support(Object selection); |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.fr.design.fun.impl; |
||||||
|
|
||||||
|
import com.fr.design.fun.ClipboardHandlerProvider; |
||||||
|
import com.fr.stable.fun.impl.AbstractProvider; |
||||||
|
import com.fr.stable.fun.mark.API; |
||||||
|
|
||||||
|
/** |
||||||
|
* created by Harrison on 2020/05/14 |
||||||
|
**/ |
||||||
|
@API(level = ClipboardHandlerProvider.CURRENT_LEVEL) |
||||||
|
public abstract class AbstractClipboardHandlerProvider<T> extends AbstractProvider implements ClipboardHandlerProvider<T> { |
||||||
|
|
||||||
|
@Override |
||||||
|
public int currentAPILevel() { |
||||||
|
return ClipboardHandlerProvider.CURRENT_LEVEL; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,99 @@ |
|||||||
|
package com.fr.design.mainframe.mobile.ui; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.design.constants.LayoutConstants; |
||||||
|
import com.fr.design.gui.ibutton.UIToggleButton; |
||||||
|
import com.fr.design.gui.icombobox.UIComboBox; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.utils.gui.GUICoreUtils; |
||||||
|
import com.fr.general.FRFont; |
||||||
|
import com.fr.stable.Constants; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.FlowLayout; |
||||||
|
import java.awt.Font; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
public class MobileStyleFontConfigPane extends JPanel { |
||||||
|
private static final int MAX_FONT_SIZE = 18; |
||||||
|
private static final int MIN_FONT_SIZE = 12; |
||||||
|
private static final Dimension BUTTON_SIZE = new Dimension(20, 18); |
||||||
|
|
||||||
|
public static Vector<Integer> getFontSizes() { |
||||||
|
Vector<Integer> FONT_SIZES = new Vector<Integer>(); |
||||||
|
for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++) { |
||||||
|
FONT_SIZES.add(i); |
||||||
|
} |
||||||
|
return FONT_SIZES; |
||||||
|
} |
||||||
|
|
||||||
|
private UIComboBox fontSizeComboBox; |
||||||
|
private UIToggleButton underline; |
||||||
|
private UIToggleButton italic; |
||||||
|
private UIToggleButton bold; |
||||||
|
|
||||||
|
public MobileStyleFontConfigPane() { |
||||||
|
this.initComponent(); |
||||||
|
} |
||||||
|
|
||||||
|
private void initComponent() { |
||||||
|
|
||||||
|
fontSizeComboBox = new UIComboBox(getFontSizes()); |
||||||
|
fontSizeComboBox.setSelectedItem(16); |
||||||
|
fontSizeComboBox.setPreferredSize(new Dimension(60, 20)); |
||||||
|
fontSizeComboBox.setEditable(true); |
||||||
|
underline = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/underline.png")); |
||||||
|
italic = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic.png")); |
||||||
|
bold = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold.png")); |
||||||
|
|
||||||
|
this.setButtonsTips(); |
||||||
|
this.setButtonsSize(BUTTON_SIZE); |
||||||
|
|
||||||
|
Component[] components_font = new Component[]{ |
||||||
|
fontSizeComboBox, underline, italic, bold |
||||||
|
}; |
||||||
|
|
||||||
|
JPanel buttonPane = new JPanel(new BorderLayout()); |
||||||
|
buttonPane.add(GUICoreUtils.createFlowPane(components_font, FlowLayout.LEFT, LayoutConstants.HGAP_LARGE)); |
||||||
|
|
||||||
|
this.setLayout(new BorderLayout(0,0)); |
||||||
|
this.add(buttonPane, BorderLayout.CENTER); |
||||||
|
} |
||||||
|
|
||||||
|
private void setButtonsTips() { |
||||||
|
underline.setToolTipText(Toolkit.i18nText("Fine-Design_Report_Underline")); |
||||||
|
italic.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Italic")); |
||||||
|
bold.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Bold")); |
||||||
|
} |
||||||
|
|
||||||
|
private void setButtonsSize(Dimension size) { |
||||||
|
underline.setPreferredSize(size); |
||||||
|
italic.setPreferredSize(size); |
||||||
|
bold.setPreferredSize(size); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public void populateBean(FRFont frFont) { |
||||||
|
fontSizeComboBox.setSelectedItem(frFont.getSize()); |
||||||
|
bold.setSelected(frFont.isBold()); |
||||||
|
italic.setSelected(frFont.isItalic()); |
||||||
|
underline.setSelected(frFont.getUnderline() != Constants.LINE_NONE); |
||||||
|
} |
||||||
|
|
||||||
|
public FRFont updateBean() { |
||||||
|
int style = Font.PLAIN; |
||||||
|
style += this.bold.isSelected() ? Font.BOLD : Font.PLAIN; |
||||||
|
style += this.italic.isSelected() ? Font.ITALIC : Font.PLAIN; |
||||||
|
return FRFont.getInstance( |
||||||
|
FRFont.DEFAULT_FONTNAME, |
||||||
|
style, |
||||||
|
Float.parseFloat(fontSizeComboBox.getSelectedItem().toString()), |
||||||
|
Color.BLACK, |
||||||
|
underline.isSelected() ? Constants.LINE_THIN : Constants.LINE_NONE |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
package com.fr.design.base.clipboard; |
||||||
|
|
||||||
|
import com.fr.design.fun.ClipboardHandlerProvider; |
||||||
|
import com.fr.form.main.ExtraFormClassManager; |
||||||
|
import com.fr.plugin.injectable.PluginModule; |
||||||
|
import com.fr.stable.fun.mark.Mutable; |
||||||
|
import org.easymock.EasyMock; |
||||||
|
import org.junit.After; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.powermock.api.easymock.PowerMock; |
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest; |
||||||
|
import org.powermock.modules.junit4.PowerMockRunner; |
||||||
|
|
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
@PrepareForTest(PluginModule.class) |
||||||
|
@RunWith(PowerMockRunner.class) |
||||||
|
public class ClipboardFilterTest { |
||||||
|
|
||||||
|
|
||||||
|
@Before |
||||||
|
public void setUp() throws Exception { |
||||||
|
|
||||||
|
Set<Mutable> providers = new HashSet<>(); |
||||||
|
providers.add(new TestClipboardHandlerProvider<Object>()); |
||||||
|
|
||||||
|
ExtraFormClassManager formClassManager = EasyMock.mock(ExtraFormClassManager.class); |
||||||
|
EasyMock.expect(formClassManager.getArray(ClipboardHandlerProvider.XML_TAG)) |
||||||
|
.andReturn(providers) |
||||||
|
.anyTimes(); |
||||||
|
EasyMock.replay(formClassManager); |
||||||
|
|
||||||
|
PowerMock.mockStatic(PluginModule.class); |
||||||
|
EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraForm)) |
||||||
|
.andReturn(formClassManager) |
||||||
|
.anyTimes(); |
||||||
|
PowerMock.replayAll(); |
||||||
|
} |
||||||
|
|
||||||
|
@After |
||||||
|
public void tearDown() throws Exception { |
||||||
|
|
||||||
|
PowerMock.resetAll(); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testClipboard() { |
||||||
|
|
||||||
|
ClipboardFilter.cut("cut"); |
||||||
|
String paste1 = ClipboardFilter.paste("paste"); |
||||||
|
Assert.assertNull(paste1); |
||||||
|
|
||||||
|
ClipboardFilter.copy("copy"); |
||||||
|
String paste2 = ClipboardFilter.paste("paste"); |
||||||
|
Assert.assertNull(paste2); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,75 @@ |
|||||||
|
package com.fr.design.base.clipboard; |
||||||
|
|
||||||
|
import com.fr.design.fun.ClipboardHandlerProvider; |
||||||
|
import com.fr.design.mainframe.DesignerContext; |
||||||
|
import com.fr.design.mainframe.dnd.ArrayListTransferable; |
||||||
|
import com.fr.form.main.ExtraFormClassManager; |
||||||
|
import com.fr.plugin.injectable.PluginModule; |
||||||
|
import com.fr.stable.fun.mark.Mutable; |
||||||
|
import com.fr.third.guava.collect.Lists; |
||||||
|
import org.easymock.EasyMock; |
||||||
|
import org.junit.After; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.powermock.api.easymock.PowerMock; |
||||||
|
import org.powermock.core.classloader.annotations.PowerMockIgnore; |
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest; |
||||||
|
import org.powermock.modules.junit4.PowerMockRunner; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.datatransfer.Clipboard; |
||||||
|
import java.awt.datatransfer.DataFlavor; |
||||||
|
import java.awt.datatransfer.Transferable; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
@PrepareForTest(PluginModule.class) |
||||||
|
@RunWith(PowerMockRunner.class) |
||||||
|
@PowerMockIgnore("javax.swing.*") |
||||||
|
public class DesignerClipboardTest { |
||||||
|
|
||||||
|
@Before |
||||||
|
public void setUp() throws Exception { |
||||||
|
|
||||||
|
Set<Mutable> providers = new HashSet<>(); |
||||||
|
|
||||||
|
ExtraFormClassManager formClassManager = EasyMock.mock(ExtraFormClassManager.class); |
||||||
|
EasyMock.expect(formClassManager.getArray(ClipboardHandlerProvider.XML_TAG)) |
||||||
|
.andReturn(providers) |
||||||
|
.anyTimes(); |
||||||
|
EasyMock.replay(formClassManager); |
||||||
|
|
||||||
|
PowerMock.mockStatic(PluginModule.class); |
||||||
|
EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraForm)) |
||||||
|
.andReturn(formClassManager) |
||||||
|
.anyTimes(); |
||||||
|
PowerMock.replayAll(); |
||||||
|
} |
||||||
|
|
||||||
|
@After |
||||||
|
public void tearDown() throws Exception { |
||||||
|
|
||||||
|
PowerMock.resetAll(); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testClipboard() throws Exception { |
||||||
|
|
||||||
|
JPanel panel = new JPanel(); |
||||||
|
Clipboard clipboard = DesignerContext.getClipboard(panel); |
||||||
|
|
||||||
|
ArrayList<String> transferData = Lists.newArrayList("test", "test2"); |
||||||
|
ArrayListTransferable transferable = new ArrayListTransferable(transferData); |
||||||
|
clipboard.setContents(transferable, null); |
||||||
|
|
||||||
|
Transferable filterTransferable = clipboard.getContents(null); |
||||||
|
DataFlavor[] flavors = transferable.getTransferDataFlavors(); |
||||||
|
ArrayList<String> transferData2 = (ArrayList<String>) filterTransferable.getTransferData(flavors[0]); |
||||||
|
|
||||||
|
Assert.assertEquals(transferData.get(0), transferData2.get(0)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
package com.fr.design.base.clipboard; |
||||||
|
|
||||||
|
import com.fr.design.fun.impl.AbstractClipboardHandlerProvider; |
||||||
|
|
||||||
|
/** |
||||||
|
* created by Harrison on 2020/05/15 |
||||||
|
**/ |
||||||
|
class TestClipboardHandlerProvider<T> extends AbstractClipboardHandlerProvider<T> { |
||||||
|
|
||||||
|
@Override |
||||||
|
public T cut(T selection) { |
||||||
|
return selection; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public T copy(T selection) { |
||||||
|
return selection; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public T paste(T selection) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean support(Object selection) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
package com.fr.design.form.util; |
||||||
|
|
||||||
|
|
||||||
|
import com.fr.design.ExtraDesignClassManager; |
||||||
|
import com.fr.design.fun.FormAdaptiveConfigUIProcessor; |
||||||
|
import com.fr.stable.Constants; |
||||||
|
import com.fr.stable.unit.PT; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-04-16 |
||||||
|
*/ |
||||||
|
public class FontTransformUtil { |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取设计器字体显示dpi |
||||||
|
* @return dpi |
||||||
|
*/ |
||||||
|
public static int getDesignerFontResolution() { |
||||||
|
int dpi = Constants.FR_PAINT_RESOLUTION; |
||||||
|
FormAdaptiveConfigUIProcessor adaptiveConfigUI = ExtraDesignClassManager.getInstance().getSingle(FormAdaptiveConfigUIProcessor.MARK_STRING); |
||||||
|
if (adaptiveConfigUI != null) { |
||||||
|
dpi = adaptiveConfigUI.fontResolution(); |
||||||
|
} |
||||||
|
return dpi; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* pt值转px |
||||||
|
* @param value pt值 |
||||||
|
* @return px值 |
||||||
|
*/ |
||||||
|
public static double pt2px(double value) { |
||||||
|
return PT.pt2pix(value, getDesignerFontResolution()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* px值转pt |
||||||
|
* @param value px值 |
||||||
|
* @return pt值 |
||||||
|
*/ |
||||||
|
public static double px2pt(double value) { |
||||||
|
return value * (double) Constants.DEFAULT_FONT_PAINT_RESOLUTION / (double) getDesignerFontResolution(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
package com.fr.design.fun; |
||||||
|
|
||||||
|
import com.fr.design.designer.beans.events.DesignerEvent; |
||||||
|
import com.fr.stable.fun.mark.Mutable; |
||||||
|
|
||||||
|
/** |
||||||
|
* created by Harrison on 2020/05/14 |
||||||
|
**/ |
||||||
|
public interface DesignerEditListenerProvider extends Mutable { |
||||||
|
|
||||||
|
String XML_TAG = "DesignerEditListenerProvider"; |
||||||
|
|
||||||
|
int CURRENT_LEVEL = 1; |
||||||
|
|
||||||
|
/** |
||||||
|
* 触发设计器事件 |
||||||
|
* |
||||||
|
* @param evt 事件 |
||||||
|
*/ |
||||||
|
void fireCreatorModified(DesignerEvent evt); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.fr.design.fun.impl; |
||||||
|
|
||||||
|
import com.fr.design.fun.DesignerEditListenerProvider; |
||||||
|
import com.fr.stable.fun.impl.AbstractProvider; |
||||||
|
import com.fr.stable.fun.mark.API; |
||||||
|
|
||||||
|
/** |
||||||
|
* created by Harrison on 2020/05/14 |
||||||
|
**/ |
||||||
|
@API(level = DesignerEditListenerProvider.CURRENT_LEVEL) |
||||||
|
public abstract class AbstractDesignerEditListenerProvider extends AbstractProvider implements DesignerEditListenerProvider { |
||||||
|
|
||||||
|
@Override |
||||||
|
public int currentAPILevel() { |
||||||
|
return DesignerEditListenerProvider.CURRENT_LEVEL; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,102 @@ |
|||||||
|
package com.fr.design.designer.beans.models; |
||||||
|
|
||||||
|
import com.fr.design.designer.beans.events.CreatorEventListenerTable; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.fun.ClipboardHandlerProvider; |
||||||
|
import com.fr.design.fun.impl.AbstractClipboardHandlerProvider; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.form.main.ExtraFormClassManager; |
||||||
|
import com.fr.plugin.injectable.PluginModule; |
||||||
|
import com.fr.stable.fun.mark.Mutable; |
||||||
|
import org.easymock.EasyMock; |
||||||
|
import org.easymock.IAnswer; |
||||||
|
import org.junit.After; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.powermock.api.easymock.PowerMock; |
||||||
|
import org.powermock.core.classloader.annotations.PowerMockIgnore; |
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest; |
||||||
|
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; |
||||||
|
import org.powermock.modules.junit4.PowerMockRunner; |
||||||
|
import org.powermock.reflect.Whitebox; |
||||||
|
|
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
@PrepareForTest(PluginModule.class) |
||||||
|
@SuppressStaticInitializationFor({"com.fr.design.mainframe.FormDesigner"}) |
||||||
|
@PowerMockIgnore("javax.swing.*") |
||||||
|
@RunWith(PowerMockRunner.class) |
||||||
|
public class SelectionModelTest { |
||||||
|
|
||||||
|
@Before |
||||||
|
public void setUp() throws Exception { |
||||||
|
|
||||||
|
AbstractClipboardHandlerProvider provider = EasyMock.mock(AbstractClipboardHandlerProvider.class); |
||||||
|
EasyMock.expect(provider.cut(EasyMock.anyObject())).andAnswer(new IAnswer<Object>() { |
||||||
|
@Override |
||||||
|
public Object answer() throws Throwable { |
||||||
|
return null; |
||||||
|
} |
||||||
|
}).anyTimes(); |
||||||
|
EasyMock.expect(provider.copy(EasyMock.anyObject())).andAnswer(new IAnswer<Object>() { |
||||||
|
@Override |
||||||
|
public Object answer() throws Throwable { |
||||||
|
return EasyMock.getCurrentArguments()[0]; |
||||||
|
} |
||||||
|
}).anyTimes(); |
||||||
|
EasyMock.expect(provider.support(EasyMock.anyObject())).andReturn(true).anyTimes(); |
||||||
|
EasyMock.expect(provider.paste(EasyMock.anyObject())).andReturn(null).anyTimes(); |
||||||
|
EasyMock.replay(provider); |
||||||
|
|
||||||
|
Set<Mutable> providers = new HashSet<>(); |
||||||
|
providers.add(provider); |
||||||
|
|
||||||
|
ExtraFormClassManager formClassManager = EasyMock.mock(ExtraFormClassManager.class); |
||||||
|
EasyMock.expect(formClassManager.getArray(ClipboardHandlerProvider.XML_TAG)) |
||||||
|
.andReturn(providers) |
||||||
|
.anyTimes(); |
||||||
|
EasyMock.expect(formClassManager.getArray("DesignerEditListenerProvider")) |
||||||
|
.andReturn(new HashSet<Mutable>()) |
||||||
|
.anyTimes(); |
||||||
|
|
||||||
|
|
||||||
|
EasyMock.replay(formClassManager); |
||||||
|
|
||||||
|
PowerMock.mockStatic(PluginModule.class); |
||||||
|
EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraForm)) |
||||||
|
.andReturn(formClassManager) |
||||||
|
.anyTimes(); |
||||||
|
PowerMock.replayAll(); |
||||||
|
} |
||||||
|
|
||||||
|
@After |
||||||
|
public void tearDown() throws Exception { |
||||||
|
|
||||||
|
PowerMock.resetAll(); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testPaste() { |
||||||
|
|
||||||
|
FormDesigner formDesigner = EasyMock.partialMockBuilder(FormDesigner.class).createMock(); |
||||||
|
XCreator xCreator = EasyMock.mock(XCreator.class); |
||||||
|
EasyMock.expect(xCreator.acceptType(EasyMock.anyObject(Class[].class))).andReturn(true).anyTimes(); |
||||||
|
CreatorEventListenerTable table = new CreatorEventListenerTable(); |
||||||
|
Whitebox.setInternalState(formDesigner, "edit", table); |
||||||
|
EasyMock.replay(formDesigner, xCreator); |
||||||
|
|
||||||
|
SelectionModel model = new SelectionModel(formDesigner); |
||||||
|
model.cutSelectedCreator2ClipBoard(); |
||||||
|
boolean paste1 = model.pasteFromClipBoard(); |
||||||
|
Assert.assertFalse(paste1); |
||||||
|
|
||||||
|
model.setSelectedCreator(xCreator); |
||||||
|
model.copySelectedCreator2ClipBoard(); |
||||||
|
boolean paste2 = model.pasteFromClipBoard(); |
||||||
|
Assert.assertFalse(paste2); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,68 @@ |
|||||||
|
package com.fr.design.form.util; |
||||||
|
|
||||||
|
import com.fr.design.ExtraDesignClassManager; |
||||||
|
import com.fr.design.fun.FormAdaptiveConfigUIProcessor; |
||||||
|
import com.fr.stable.Constants; |
||||||
|
import org.easymock.EasyMock; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.powermock.api.easymock.PowerMock; |
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest; |
||||||
|
import org.powermock.modules.junit4.PowerMockRunner; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-05-14 |
||||||
|
*/ |
||||||
|
@RunWith(PowerMockRunner.class) |
||||||
|
@PrepareForTest(ExtraDesignClassManager.class) |
||||||
|
public class FontTransformUtilTest { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testGetDesignerFontResolution() { |
||||||
|
mockEnvironment(Constants.DEFAULT_FONT_PAINT_RESOLUTION); |
||||||
|
Assert.assertEquals(Constants.DEFAULT_FONT_PAINT_RESOLUTION, FontTransformUtil.getDesignerFontResolution()); |
||||||
|
|
||||||
|
mockEnvironment(Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION); |
||||||
|
Assert.assertEquals(Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION, FontTransformUtil.getDesignerFontResolution()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testPt2px() { |
||||||
|
mockEnvironment(Constants.DEFAULT_FONT_PAINT_RESOLUTION); |
||||||
|
Assert.assertEquals(12, (int) FontTransformUtil.pt2px(12)); |
||||||
|
|
||||||
|
mockEnvironment(Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION); |
||||||
|
Assert.assertEquals(16, (int) FontTransformUtil.pt2px(12)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testPx2pt() { |
||||||
|
mockEnvironment(Constants.DEFAULT_FONT_PAINT_RESOLUTION); |
||||||
|
Assert.assertEquals(12, (int) FontTransformUtil.px2pt(12)); |
||||||
|
|
||||||
|
mockEnvironment(Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION); |
||||||
|
Assert.assertEquals(9, (int) FontTransformUtil.px2pt(12)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void mockEnvironment(int dpi) { |
||||||
|
ExtraDesignClassManager mockDesignManager = EasyMock.mock(ExtraDesignClassManager.class); |
||||||
|
EasyMock.expect(mockDesignManager.getSingle(FormAdaptiveConfigUIProcessor.MARK_STRING)) |
||||||
|
.andReturn(mockProcessor(dpi)).anyTimes(); |
||||||
|
EasyMock.replay(mockDesignManager); |
||||||
|
|
||||||
|
PowerMock.mockStatic(ExtraDesignClassManager.class); |
||||||
|
EasyMock.expect(ExtraDesignClassManager.getInstance()).andReturn(mockDesignManager).once(); |
||||||
|
PowerMock.replayAll(ExtraDesignClassManager.class); |
||||||
|
} |
||||||
|
|
||||||
|
private FormAdaptiveConfigUIProcessor mockProcessor(int dpi) { |
||||||
|
FormAdaptiveConfigUIProcessor processor = EasyMock.mock(FormAdaptiveConfigUIProcessor.class); |
||||||
|
EasyMock.expect(processor.fontResolution()).andReturn(dpi).once(); |
||||||
|
EasyMock.replay(processor); |
||||||
|
return processor; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue