|
|
|
@ -11,19 +11,31 @@ import com.fr.design.designer.creator.cardlayout.XWCardLayout;
|
|
|
|
|
import com.fr.design.designer.creator.cardlayout.XWCardTagLayout; |
|
|
|
|
import com.fr.design.dialog.BasicPane; |
|
|
|
|
import com.fr.design.dialog.FineJOptionPane; |
|
|
|
|
import com.fr.design.file.HistoryTemplateListCache; |
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
import com.fr.design.gui.ispinner.UISpinner; |
|
|
|
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
|
|
|
import com.fr.design.mainframe.FormDesigner; |
|
|
|
|
import com.fr.design.mainframe.JForm; |
|
|
|
|
import com.fr.design.mainframe.JTemplate; |
|
|
|
|
import com.fr.design.mainframe.WidgetPropertyPane; |
|
|
|
|
import com.fr.design.utils.ComponentUtils; |
|
|
|
|
import com.fr.design.widget.WidgetBoundsPaneFactory; |
|
|
|
|
import com.fr.form.ui.PaddingMargin; |
|
|
|
|
import com.fr.form.ui.Widget; |
|
|
|
|
import com.fr.form.ui.container.WFitLayout; |
|
|
|
|
import com.fr.form.ui.container.WLayout; |
|
|
|
|
import com.fr.general.IOUtils; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
|
import javax.swing.plaf.basic.BasicButtonUI; |
|
|
|
|
import java.awt.*; |
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
|
|
|
|
import javax.swing.JOptionPane; |
|
|
|
|
import java.awt.Rectangle; |
|
|
|
|
import static com.fr.design.i18n.Toolkit.i18nText; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -37,6 +49,7 @@ public class WidgetBoundPane extends BasicPane {
|
|
|
|
|
protected XCreator creator; |
|
|
|
|
protected UISpinner width; |
|
|
|
|
protected UISpinner height; |
|
|
|
|
protected AspectRatioLockedButton ratioLockedButton; |
|
|
|
|
|
|
|
|
|
public WidgetBoundPane(XCreator source) { |
|
|
|
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
|
|
@ -59,13 +72,20 @@ public class WidgetBoundPane extends BasicPane {
|
|
|
|
|
public void initBoundPane() { |
|
|
|
|
width = new UIBoundSpinner(0, Integer.MAX_VALUE, 1, 0d); |
|
|
|
|
height = new UIBoundSpinner(0, Integer.MAX_VALUE, 1, 0d); |
|
|
|
|
width.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size")); |
|
|
|
|
height.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size")); |
|
|
|
|
width.setGlobalName(i18nText("Fine-Design_Form_Coords_And_Size")); |
|
|
|
|
height.setGlobalName(i18nText("Fine-Design_Form_Coords_And_Size")); |
|
|
|
|
if (creator.acceptType(XWCardLayout.class)) { |
|
|
|
|
width.setEnabled(false); |
|
|
|
|
height.setEnabled(false); |
|
|
|
|
} |
|
|
|
|
this.add(WidgetBoundsPaneFactory.createBoundsPane(width, height)); |
|
|
|
|
|
|
|
|
|
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
if (jTemplate.isJWorkBook() || !((JForm)jTemplate).isSelectRootPane()) { |
|
|
|
|
ratioLockedButton = new AspectRatioLockedButton(width, height, creator); |
|
|
|
|
ratioLockedButton.setLockEnabled(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.add(WidgetBoundsPaneFactory.createBoundsPane(width, height, ratioLockedButton)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -82,6 +102,9 @@ public class WidgetBoundPane extends BasicPane {
|
|
|
|
|
Rectangle bounds = new Rectangle(creator.getBounds()); |
|
|
|
|
width.setValue(bounds.width); |
|
|
|
|
height.setValue(bounds.height); |
|
|
|
|
if (ratioLockedButton != null) { |
|
|
|
|
ratioLockedButton.populate(creator); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void fix() { |
|
|
|
@ -97,6 +120,9 @@ public class WidgetBoundPane extends BasicPane {
|
|
|
|
|
if (bounds.height != h) { |
|
|
|
|
limitHeight(wabs, h, bounds, rec); |
|
|
|
|
} |
|
|
|
|
if (ratioLockedButton != null) { |
|
|
|
|
ratioLockedButton.setLocked(creator.toData().isAspectRatioLocked()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -116,11 +142,11 @@ public class WidgetBoundPane extends BasicPane {
|
|
|
|
|
PaddingMargin margin = wabs.getMargin(); |
|
|
|
|
if (bounds.width != w) { |
|
|
|
|
if (bounds.width == rec.width - margin.getLeft() - margin.getRight()) { |
|
|
|
|
FineJOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Beyond_Bounds")); |
|
|
|
|
FineJOptionPane.showMessageDialog(null, i18nText("Fine-Design_Form_Beyond_Bounds")); |
|
|
|
|
width.setValue(bounds.width); |
|
|
|
|
return; |
|
|
|
|
} else if (w < minWidth) { |
|
|
|
|
FineJOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Min_Width") + Integer.toString(minWidth)); |
|
|
|
|
FineJOptionPane.showMessageDialog(null, i18nText("Fine-Design_Form_Min_Width") + Integer.toString(minWidth)); |
|
|
|
|
width.setValue(bounds.width); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -137,11 +163,11 @@ public class WidgetBoundPane extends BasicPane {
|
|
|
|
|
int minHeight = (int) (MINHEIGHT * ((WFitLayout) wabs).getResolutionScaling()); |
|
|
|
|
if (bounds.height != h) { |
|
|
|
|
if (bounds.height == rec.height - margin.getTop() - margin.getBottom()) { |
|
|
|
|
FineJOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Beyond_Bounds")); |
|
|
|
|
FineJOptionPane.showMessageDialog(null, i18nText("Fine-Design_Form_Beyond_Bounds")); |
|
|
|
|
height.setValue(bounds.height); |
|
|
|
|
return; |
|
|
|
|
} else if (h < minHeight) { |
|
|
|
|
FineJOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Min_Height") + Integer.toString(minHeight)); |
|
|
|
|
FineJOptionPane.showMessageDialog(null, i18nText("Fine-Design_Form_Min_Height") + Integer.toString(minHeight)); |
|
|
|
|
height.setValue(bounds.height); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -165,4 +191,109 @@ public class WidgetBoundPane extends BasicPane {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected static class AspectRatioLockedButton extends UIButton { |
|
|
|
|
|
|
|
|
|
private final Icon enabledLocked = IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_lock_enabled.png"); |
|
|
|
|
private final Icon disabledLocked = IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_lock_disabled.png"); |
|
|
|
|
private final Icon enabledUnLocked = IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_unlock_enabled.png"); |
|
|
|
|
private final Icon disabledUnLocked = IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_unlock_disabled.png"); |
|
|
|
|
|
|
|
|
|
private UISpinner mWidthSpinner; |
|
|
|
|
private UISpinner mHeightSpinner; |
|
|
|
|
private XCreator mCreator; |
|
|
|
|
|
|
|
|
|
protected double width4Backup = 0; |
|
|
|
|
protected double height4Backup = 0; |
|
|
|
|
|
|
|
|
|
public AspectRatioLockedButton(UISpinner widthSpinner, UISpinner heightSpinner, XCreator creator) { |
|
|
|
|
setUI(new BasicButtonUI()); |
|
|
|
|
setBorderPainted(false); |
|
|
|
|
setBorder(null); |
|
|
|
|
setContentAreaFilled(false); |
|
|
|
|
setPreferredSize(new Dimension(24, 24)); |
|
|
|
|
|
|
|
|
|
this.mWidthSpinner = widthSpinner; |
|
|
|
|
this.mHeightSpinner = heightSpinner; |
|
|
|
|
this.mCreator = creator; |
|
|
|
|
|
|
|
|
|
addActionListener(new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
setSelected(!isSelected()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
addChangeListener(new ChangeListener() { |
|
|
|
|
@Override |
|
|
|
|
public void stateChanged(ChangeEvent e) { |
|
|
|
|
mCreator.toData().setAspectRatioLocked(isLocked()); |
|
|
|
|
|
|
|
|
|
setToolTipText(isLockEnabled() ? null : i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Button_ToolTip")); |
|
|
|
|
|
|
|
|
|
if (isLocked() && isLockEnabled()) { |
|
|
|
|
width4Backup = mWidthSpinner.getValue(); |
|
|
|
|
height4Backup = mHeightSpinner.getValue(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
mWidthSpinner.addChangeListener(new ChangeListener() { |
|
|
|
|
@Override |
|
|
|
|
public void stateChanged(ChangeEvent e) { |
|
|
|
|
if (isLockEnabled() && isLocked() && width4Backup > 0 && height4Backup > 0) { |
|
|
|
|
mHeightSpinner.setValue(mWidthSpinner.getValue() * width4Backup / height4Backup, false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
mHeightSpinner.addChangeListener(new ChangeListener() { |
|
|
|
|
@Override |
|
|
|
|
public void stateChanged(ChangeEvent e) { |
|
|
|
|
if (isLockEnabled() && isLocked() && width4Backup > 0 && height4Backup > 0) { |
|
|
|
|
mWidthSpinner.setValue(mHeightSpinner.getValue() * height4Backup / width4Backup, false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Icon getIcon() { |
|
|
|
|
if (this.isLocked()) { |
|
|
|
|
if (this.isLockEnabled()) { |
|
|
|
|
return enabledLocked; |
|
|
|
|
} else { |
|
|
|
|
return disabledLocked; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (this.isLockEnabled()) { |
|
|
|
|
return enabledUnLocked; |
|
|
|
|
} else { |
|
|
|
|
return disabledUnLocked; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setLocked(boolean locked) { |
|
|
|
|
this.setSelected(locked); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isLocked() { |
|
|
|
|
return this.isSelected(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isLockEnabled() { |
|
|
|
|
return this.isEnabled(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setLockEnabled(boolean enabled) { |
|
|
|
|
this.setEnabled(enabled); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void populate(XCreator creator) { |
|
|
|
|
Rectangle bounds = new Rectangle(creator.getBounds()); |
|
|
|
|
mCreator = creator; |
|
|
|
|
width4Backup = bounds.width; |
|
|
|
|
height4Backup = bounds.height; |
|
|
|
|
Widget widget = creator.toData(); |
|
|
|
|
setLocked(widget.isAspectRatioLocked()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|