diff --git a/designer-base/src/com/fr/design/gui/itextfield/PlaceholderTextField.java b/designer-base/src/com/fr/design/gui/itextfield/PlaceholderTextField.java index 3ff686099..30204aee7 100644 --- a/designer-base/src/com/fr/design/gui/itextfield/PlaceholderTextField.java +++ b/designer-base/src/com/fr/design/gui/itextfield/PlaceholderTextField.java @@ -1,12 +1,9 @@ package com.fr.design.gui.itextfield; import javax.swing.text.Document; -import java.awt.*; public class PlaceholderTextField extends UITextField { - private String placeholder; - public PlaceholderTextField() { } @@ -28,27 +25,4 @@ public class PlaceholderTextField extends UITextField { public PlaceholderTextField(final String pText, final int pColumns) { super(pText, pColumns); } - - public String getPlaceholder() { - return placeholder; - } - - @Override - protected void paintComponent(final Graphics pG) { - super.paintComponent(pG); - if (placeholder.length() == 0 || getText().length() > 0) { - return; - } - final Graphics2D g = (Graphics2D) pG; - g.setRenderingHint( - RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - g.setColor(getDisabledTextColor()); - g.drawString(placeholder, getInsets().left, pG.getFontMetrics() - .getMaxAscent() + getInsets().top + 1); - } - - public void setPlaceholder(final String s) { - placeholder = s; - } } \ No newline at end of file diff --git a/designer-realize/src/com/fr/design/report/freeze/UIIntNumberField.java b/designer-base/src/com/fr/design/gui/itextfield/UIIntNumberField.java similarity index 97% rename from designer-realize/src/com/fr/design/report/freeze/UIIntNumberField.java rename to designer-base/src/com/fr/design/gui/itextfield/UIIntNumberField.java index c42c5b1d8..59e5e8825 100644 --- a/designer-realize/src/com/fr/design/report/freeze/UIIntNumberField.java +++ b/designer-base/src/com/fr/design/gui/itextfield/UIIntNumberField.java @@ -1,4 +1,4 @@ -package com.fr.design.report.freeze; +package com.fr.design.gui.itextfield; import com.fr.design.gui.itextfield.UINumberField; diff --git a/designer-base/src/com/fr/design/gui/itextfield/UITextField.java b/designer-base/src/com/fr/design/gui/itextfield/UITextField.java index e4f5b9d87..98823bee9 100644 --- a/designer-base/src/com/fr/design/gui/itextfield/UITextField.java +++ b/designer-base/src/com/fr/design/gui/itextfield/UITextField.java @@ -7,6 +7,7 @@ import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.stable.Constants; +import com.fr.stable.StringUtils; import javax.swing.*; import javax.swing.event.DocumentEvent; @@ -22,9 +23,10 @@ public class UITextField extends JTextField implements UIObserver, GlobalNameObs private boolean isRoundBorder = true; private int rectDirection = Constants.NULL; private UIObserverListener uiObserverListener; - private String textFeildName = ""; + private String textFieldName = StringUtils.EMPTY; private GlobalNameListener globalNameListener = null; private Dimension preferredSize = null; + private String placeholder = StringUtils.EMPTY; //有些情况下setText的时候不希望触发attributeChange,添加一个属性标识 private boolean isSetting = false; @@ -81,6 +83,15 @@ public class UITextField extends JTextField implements UIObserver, GlobalNameObs } } + public String getPlaceholder() { + return placeholder; + } + + public void setPlaceholder(String placeholder) { + this.placeholder = placeholder; + } + + public boolean isSetting() { return isSetting; } @@ -94,7 +105,7 @@ public class UITextField extends JTextField implements UIObserver, GlobalNameObs } public void setGlobalName(String name) { - textFeildName = name; + textFieldName = name; } protected void attributeChange() { @@ -102,7 +113,7 @@ public class UITextField extends JTextField implements UIObserver, GlobalNameObs return; } if (globalNameListener != null && shouldResponseNameListener()) { - globalNameListener.setGlobalName(textFeildName); + globalNameListener.setGlobalName(textFieldName); } if (uiObserverListener != null) { uiObserverListener.doChange(); @@ -141,6 +152,21 @@ public class UITextField extends JTextField implements UIObserver, GlobalNameObs this.setUI(new UITextFieldUI(this)); } + @Override + protected void paintComponent(final Graphics pG) { + super.paintComponent(pG); + if (placeholder.length() == 0 || getText().length() > 0) { + return; + } + final Graphics2D g = (Graphics2D) pG; + g.setRenderingHint( + RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + g.setColor(getDisabledTextColor()); + g.drawString(placeholder, getInsets().left, pG.getFontMetrics() + .getMaxAscent() + getInsets().top + 1); + } + @Override protected void paintBorder(Graphics g) { if (!isBorderPainted) { diff --git a/designer-base/src/com/fr/env/EnvListPane.java b/designer-base/src/com/fr/env/EnvListPane.java index 1927f127a..92bab2929 100644 --- a/designer-base/src/com/fr/env/EnvListPane.java +++ b/designer-base/src/com/fr/env/EnvListPane.java @@ -14,8 +14,7 @@ import com.fr.stable.Nameable; import com.fr.stable.StringUtils; import com.fr.stable.core.PropertyChangeAdapter; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; +import javax.swing.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -62,7 +61,7 @@ public class EnvListPane extends JListControlPane { NameableCreator local = new NameObjectCreator(Inter.getLocText("Env-Local_Directory"), "com/fr/design/images/data/bind/localconnect.png", LocalEnvConfig.class, LocalEnvPane.class); NameableCreator remote = new NameObjectCreator(Inter.getLocText("Env-Remote_Server"), "com/fr/design/images/data/bind/distanceconnect.png", - RemoteEnvConfig.class, RemoteEnvPane.class); + RemoteEnvConfig.class, RemoteEnvPane2.class); return new NameableCreator[]{local, remote}; } diff --git a/designer-base/src/com/fr/env/RemoteEnv.java b/designer-base/src/com/fr/env/RemoteEnv.java index c52890ecb..ffb42c122 100644 --- a/designer-base/src/com/fr/env/RemoteEnv.java +++ b/designer-base/src/com/fr/env/RemoteEnv.java @@ -2,11 +2,12 @@ package com.fr.env; import com.fr.base.EnvException; import com.fr.base.TableData; +import com.fr.base.operator.connect.ConnectOperator; import com.fr.base.operator.file.FileOperator; import com.fr.base.remote.RemoteDeziConstants; import com.fr.common.rpc.RemoteCallServerConfig; import com.fr.common.rpc.netty.MessageSendExecutor; -import com.fr.common.rpc.serialize.SerializeProtocol; +import com.fr.common.rpc.netty.RemoteCallClient; import com.fr.core.env.EnvConstants; import com.fr.core.env.EnvContext; import com.fr.core.env.resource.RemoteEnvConfig; @@ -49,7 +50,7 @@ import com.fr.third.guava.base.Strings; import com.fr.third.guava.collect.ImmutableMap; import com.fr.web.ResourceConstants; -import javax.swing.JOptionPane; +import javax.swing.*; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; @@ -57,7 +58,7 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import java.awt.Component; +import java.awt.*; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -79,24 +80,41 @@ import static com.fr.third.guava.base.Preconditions.checkArgument; /** * @author null */ -public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurable { +public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurable { private static final String CERT_KEY = "javax.net.ssl.trustStore"; private static final String PWD_KEY = "javax.net.ssl.trustStorePassword"; private static final String HTTPS_PREFIX = "https:"; private final static String[] FILE_TYPE = {"cptx", "cpt", "frm", "form", "cht", "chart"}; private String buildFilePath; - private RemoteEnvConfig env; + private RemoteEnvConfig config; + public RemoteEnv(RemoteEnvConfig config) { + this.config = config; + } public RemoteEnv(String path, String userName, String password) { - env = new RemoteEnvConfig(path, userName, password); + config = new RemoteEnvConfig(path, userName, password); + } + + @Override + public void connect() throws Exception { + } @Override - public void connect() { - // FIXME:richie ip地址属于测试的,带实际修改为RemoteEnv配置的地址 - MessageSendExecutor.getInstance().setRpcServerLoader("127.0.0.1", RemoteCallServerConfig.getInstance().getPort(), RemoteCallServerConfig.getInstance().getSerializeProtocol()); + public void connectOnce() throws Exception { + RemoteCallClient.getInstance().loadOnce(config.getHost(), config.getPort(), RemoteCallServerConfig.getInstance().getSerializeProtocol(), 10 * 1000); + ConnectOperator operator = RemoteCallClient.getInstance().execute(ConnectOperator.class); + boolean result = false; + try { + result = operator.connect(config.getUsername(), config.getPassword()); + } catch (Exception ignore) { + + } + if (!result) { + throw new Exception("Cannot connect to the remote server!"); + } } @Override @@ -112,16 +130,16 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl @Override public String getPath() { - return env.getPath(); + return config.getPath(); } @Override public String getUser() { - return env.getUsername(); + return config.getUsername(); } public String getPassword() { - return env.getPassword(); + return config.getPassword(); } @Override diff --git a/designer-base/src/com/fr/env/RemoteEnvPane2.java b/designer-base/src/com/fr/env/RemoteEnvPane2.java new file mode 100644 index 000000000..11bd73cef --- /dev/null +++ b/designer-base/src/com/fr/env/RemoteEnvPane2.java @@ -0,0 +1,145 @@ +package com.fr.env; + +import com.fr.core.env.resource.RemoteEnvConfig; +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.border.UITitledBorder; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.ipasswordfield.UIPassWordField; +import com.fr.design.gui.itextfield.UIIntNumberField; +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; +import com.fr.log.FineLoggerFactory; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.concurrent.ExecutionException; + +/** + * 远程环境设置界面,暂时命名为2,待做完功能直接替代掉老的RemoteEnvPane + */ +public class RemoteEnvPane2 extends BasicBeanPane { + + private UITextField hostTextField; + private UIIntNumberField portTextField; + private UITextField usernameTextField; + private UIPassWordField passwordTextField; + + public RemoteEnvPane2() { + initComponents(); + } + + private void initComponents() { + setLayout(new BorderLayout()); + + JPanel contentPanel = new JPanel(new BorderLayout()); + add(contentPanel, BorderLayout.CENTER); + + contentPanel.setBorder( + BorderFactory.createCompoundBorder( + new EmptyBorder(6, 0, 0, 0), + UITitledBorder.createBorderWithTitle(Inter.getLocText("Fine-Designer_Basic_Remote_Env_Config"))) + ); + + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] rowSize = new double[]{p, p, p, p, p}; + double[] columnSize = new double[]{p, f}; + UIButton testConnectionButton = new UIButton(Inter.getLocText("Fine-Designer_Basic_Remote_Env_Try")); + hostTextField = new UITextField(); + hostTextField.setPlaceholder("192.168.100.200"); + portTextField = new UIIntNumberField(); + portTextField.setPlaceholder("39999"); + JPanel valuePane = TableLayoutHelper.createTableLayoutPane( + new Component[][]{ + {new UILabel(Inter.getLocText("Fine-Designer_Basic_Remote_Env_Host") + ":", SwingConstants.RIGHT), hostTextField}, + {new UILabel(Inter.getLocText("Fine-Designer_Basic_Remote_Env_Port") + ":", SwingConstants.RIGHT),portTextField}, + {new UILabel(Inter.getLocText("Fine-Designer_Basic_Remote_Env_User") + ":", SwingConstants.RIGHT), usernameTextField = new UITextField()}, + {new UILabel(Inter.getLocText("Fine-Designer_Basic_Remote_Env_Password") + ":", SwingConstants.RIGHT), passwordTextField = new UIPassWordField()}, + {null, GUICoreUtils.createFlowPane(testConnectionButton, FlowLayout.LEFT)} + }, + rowSize, columnSize + ); + testConnectionButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + tryConnectRemoteEnv(); + } + }); + contentPanel.add(valuePane, BorderLayout.CENTER); + } + + private void tryConnectRemoteEnv() { + final RemoteEnv remoteEnv = new RemoteEnv(this.updateBean()); + new SwingWorker() { + + @Override + protected Void doInBackground() throws Exception { + remoteEnv.connectOnce(); + return null; + } + + @Override + protected void done() { + try { + get(); + showConnectMessage(); + } catch (Exception e) { + showCannotConnectMessage(); + } + } + }.execute(); + } + + private void showCannotConnectMessage() { + JOptionPane.showMessageDialog( + this, + Inter.getLocText("Fine-Designer_Basic_Remote_Connect_Failed"), + UIManager.getString("OptionPane.messageDialogTitle", this.getLocale()), + JOptionPane.ERROR_MESSAGE + ); + } + + private void showConnectMessage() { + JOptionPane.showMessageDialog( + this, + Inter.getLocText("Fine-Designer_Basic_Remote_Connect_Successful"), + UIManager.getString("OptionPane.messageDialogTitle", this.getLocale()), + JOptionPane.INFORMATION_MESSAGE + ); + } + + @Override + protected String title4PopupWindow() { + return "RemoteEnv"; + } + + @Override + public void populateBean(RemoteEnvConfig config) { + if (config == null) { + return; + } + hostTextField.setText(config.getPath()); + if (config.getPort() != 0) { + portTextField.setValue(config.getPort()); + } + usernameTextField.setText(config.getUsername()); + passwordTextField.setText(config.getPassword()); + } + + @Override + public RemoteEnvConfig updateBean() { + RemoteEnvConfig config = new RemoteEnvConfig(); + config.setHost(hostTextField.getText()); + config.setPort((int) portTextField.getValue()); + config.setUsername(usernameTextField.getText()); + config.setPassword(passwordTextField.getText()); + return config; + } +} diff --git a/designer-realize/src/com/fr/design/report/freeze/RowSpinner.java b/designer-realize/src/com/fr/design/report/freeze/RowSpinner.java index 17df3be52..da652a0e4 100644 --- a/designer-realize/src/com/fr/design/report/freeze/RowSpinner.java +++ b/designer-realize/src/com/fr/design/report/freeze/RowSpinner.java @@ -1,6 +1,7 @@ package com.fr.design.report.freeze; import com.fr.design.gui.ispinner.UISpinner; +import com.fr.design.gui.itextfield.UIIntNumberField; import com.fr.design.gui.itextfield.UINumberField; /**