Skip to content

Commit

Permalink
1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
wntr committed Mar 30, 2016
1 parent 55184e8 commit 0c61752
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_51_X64"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="lib/fastjson-1.1.6.jar"/>
<classpathentry kind="lib" path="lib/jna.jar"/>
<classpathentry kind="lib" path="lib/miglayout-swing.jar"/>
Expand Down
73 changes: 73 additions & 0 deletions src/net/fs/client/AddressCellRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package net.fs.client;

import java.awt.Color;
import java.awt.Component;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;

import net.miginfocom.swing.MigLayout;

public class AddressCellRenderer implements ListCellRenderer{

JPanel panel=null;

JLabel addressLabel;

Color color_normal=new Color(255,255,255);

Color color_selected=new Color(210,233,255);

JButton button_remove;

@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
if(panel==null){
init();
}
updateData( list, value, index, isSelected, cellHasFocus);
return panel;
}

void init(){
panel=new JPanel();
panel.setLayout(new MigLayout("insets 0 5 0 0","[grow,fill]rel[right]", "[]0[]"));
panel.setOpaque(true);
panel.setBackground(color_normal);
addressLabel=new JLabel("");
panel.add(addressLabel,"");
addressLabel.setOpaque(false);

button_remove=new JButton("x");
//panel.add(button_remove,"align right");
button_remove.setOpaque(false);
button_remove.setContentAreaFilled(false);
button_remove.setBorderPainted(false);
button_remove.setMargin(new Insets(0, 10, 0, 10));
button_remove.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
System.out.println(e);
}
});

}

void updateData(JList list, Object value, int index, boolean isSelected,boolean cellHasFocus){
addressLabel.setText(value.toString());
if(isSelected){
panel.setBackground(color_selected);
}else {
panel.setBackground(color_normal);
}
}

}
12 changes: 12 additions & 0 deletions src/net/fs/client/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

package net.fs.client;

import java.util.ArrayList;

public class ClientConfig {

String serverAddress="";
Expand All @@ -21,6 +23,8 @@ public class ClientConfig {
String protocal="tcp";

boolean autoStart=false;

ArrayList<String> recentAddressList=new ArrayList<String>();

public String getServerAddress() {
return serverAddress;
Expand Down Expand Up @@ -101,5 +105,13 @@ public boolean isAutoStart() {
public void setAutoStart(boolean autoStart) {
this.autoStart = autoStart;
}

public ArrayList<String> getRecentAddressList() {
return recentAddressList;
}

public void setRecentAddressList(ArrayList<String> recentAddressList) {
this.recentAddressList = recentAddressList;
}

}
122 changes: 100 additions & 22 deletions src/net/fs/client/ClientUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
Expand All @@ -47,6 +48,7 @@
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.UIManager;
Expand All @@ -59,6 +61,7 @@
import net.fs.utils.Tools;
import net.miginfocom.swing.MigLayout;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class ClientUI implements ClientUII, WindowListener {
Expand All @@ -67,7 +70,7 @@ public class ClientUI implements ClientUII, WindowListener {

JComponent mainPanel;

JTextField text_serverAddress;
JComboBox text_serverAddress;

MapClient mapClient;

Expand All @@ -89,7 +92,7 @@ public class ClientUI implements ClientUII, WindowListener {

int serverVersion = -1;

int localVersion = 2;
int localVersion = 3;

boolean checkingUpdate = false;

Expand Down Expand Up @@ -164,7 +167,7 @@ public class ClientUI implements ClientUII, WindowListener {
initUI();
checkQuanxian();
loadConfig();
mainFrame.setTitle("FinalSpeed 1.1测试版");
mainFrame.setTitle("FinalSpeed 1.12测试版");
mainFrame.addWindowListener(this);
mainPanel = (JPanel) mainFrame.getContentPane();
mainPanel.setLayout(new MigLayout("align center , insets 10 10 10 10"));
Expand Down Expand Up @@ -278,11 +281,52 @@ public void actionPerformed(ActionEvent e) {
p1.setLayout(new MigLayout("insets 0 0 0 0"));
pa.add(p1, "wrap");
p1.add(new JLabel("地址:"), "width 50::");
text_serverAddress = new JTextField();
text_serverAddress = new JComboBox();
text_serverAddress.setToolTipText("主机:端口号");
p1.add(text_serverAddress, "width 130::");
p1.add(text_serverAddress, "width 150::");
text_serverAddress.setEditable(true);
TextComponentPopupMenu.installToComponent(text_serverAddress);


ListCellRenderer renderer = new AddressCellRenderer();
text_serverAddress.setRenderer(renderer);
text_serverAddress.setEditable(true);

text_serverAddress.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
//System.out.println(text_serverAddress.getSelectedItem().toString());
}
});

for(int n=0;n<config.getRecentAddressList().size();n++){
text_serverAddress.addItem(config.getRecentAddressList().get(n));
}

if(config.getRecentAddressList().size()==0){
text_serverAddress.setSelectedItem("");
}

JButton button_removeAddress=createButton("删除");
p1.add(button_removeAddress, "");
button_removeAddress.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
String address=text_serverAddress.getSelectedItem().toString();
if(!address.equals("")){
int result=JOptionPane.showConfirmDialog(mainFrame, "确定删除吗?","消息", JOptionPane.YES_NO_OPTION);
if(result==JOptionPane.OK_OPTION){
text_serverAddress.removeItem(address);
String selectText="";
if(text_serverAddress.getModel().getSize()>0){
selectText=text_serverAddress.getModel().getElementAt(0).toString();
}
text_serverAddress.setSelectedItem(selectText);
}
}
}
});

JPanel panelr = new JPanel();
pa.add(panelr, "wrap");
Expand Down Expand Up @@ -424,15 +468,7 @@ public void actionPerformed(ActionEvent e) {
updateUISpeed(0, 0, 0);
setMessage(" ");

String server_addressTxt = config.getServerAddress();
if (config.getServerAddress() != null && !config.getServerAddress().equals("")) {
if (config.getServerPort() != 150
&& config.getServerPort() != 0) {
server_addressTxt += (":" + config.getServerPort());
}
}

text_serverAddress.setText(server_addressTxt);
text_serverAddress.setSelectedItem(getServerAddressFromConfig());

if (config.getRemoteAddress() != null && !config.getRemoteAddress().equals("") && config.getRemotePort() > 0) {
String remoteAddressTxt = config.getRemoteAddress() + ":" + config.getRemotePort();
Expand Down Expand Up @@ -516,9 +552,9 @@ public void actionPerformed(ActionEvent e) {
tcpEnvSuccess=false;
if (isVisible) {
mainFrame.setVisible(true);
JOptionPane.showMessageDialog(mainFrame, "启动ipfw/pf防火墙失败,请先安装.");
JOptionPane.showMessageDialog(mainFrame, "启动ipfw/pfctl防火墙失败,请先安装.");
}
MLog.println("启动ipfw/pf防火墙失败,请先安装.");
MLog.println("启动ipfw/pfctl防火墙失败,请先安装.");
//System.exit(0);
}

Expand Down Expand Up @@ -635,6 +671,17 @@ public void run() {


}

String getServerAddressFromConfig(){
String server_addressTxt = config.getServerAddress();
if (config.getServerAddress() != null && !config.getServerAddress().equals("")) {
if (config.getServerPort() != 150
&& config.getServerPort() != 0) {
server_addressTxt += (":" + config.getServerPort());
}
}
return server_addressTxt;
}

void checkFireWallOn() {
if (systemName.contains("os x")) {
Expand All @@ -643,19 +690,18 @@ void checkFireWallOn() {
final Process p = Runtime.getRuntime().exec(runFirewall, null);
osx_fw_ipfw = true;
} catch (IOException e) {
e.printStackTrace();
//e.printStackTrace();
}
runFirewall = "pfctl";
try {
final Process p = Runtime.getRuntime().exec(runFirewall, null);
osx_fw_pf = true;
} catch (IOException e) {
e.printStackTrace();
// e.printStackTrace();
}
success_firewall_osx = osx_fw_ipfw | osx_fw_pf;
} else if (systemName.contains("linux")) {
String runFirewall = "service iptables start";

} else if (systemName.contains("windows")) {
String runFirewall = "netsh advfirewall set allprofiles state on";
Thread standReadThread = null;
Expand Down Expand Up @@ -834,6 +880,13 @@ ClientConfig loadConfig() {
if (json.containsKey("auto_start")) {
cfg.setAutoStart(json.getBooleanValue("auto_start"));
}
if (json.containsKey("recent_address_list")) {
JSONArray list=json.getJSONArray("recent_address_list");
for (int i = 0; i < list.size(); i++) {
cfg.getRecentAddressList().add(list.get(i).toString());
}
}

config = cfg;
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -847,9 +900,12 @@ public void run() {
boolean success = false;
try {
int serverPort = 150;
String addressTxt = text_serverAddress.getText();
String addressTxt ="";
if(text_serverAddress.getSelectedItem()!=null){
addressTxt =text_serverAddress.getSelectedItem().toString();
}
addressTxt = addressTxt.trim().replaceAll(" ", "");
text_serverAddress.setText(addressTxt);

String serverAddress = addressTxt;
if (addressTxt.startsWith("[")) {
int index = addressTxt.lastIndexOf("]:");
Expand Down Expand Up @@ -880,6 +936,28 @@ public void run() {
json.put("socks5_port", config.getSocks5Port());
json.put("protocal", protocal);
json.put("auto_start", config.isAutoStart());


if(text_serverAddress.getModel().getSize()>0){
text_serverAddress.removeItem(addressTxt);
}
text_serverAddress.insertItemAt(addressTxt, 0);
text_serverAddress.setSelectedItem(addressTxt);;


JSONArray recentAddressList=new JSONArray();


int size=text_serverAddress.getModel().getSize();
for(int n=0;n<size;n++){
String address=text_serverAddress.getModel().getElementAt(n).toString();
if(!address.equals("")){
recentAddressList.add(address);
}
}
json.put("recent_address_list", recentAddressList);


saveFile(json.toJSONString().getBytes("utf-8"), configFilePath);
config.setServerAddress(serverAddress);
config.setServerPort(serverPort);
Expand Down
5 changes: 3 additions & 2 deletions src/net/fs/client/TextComponentPopupMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JPasswordField;
import javax.swing.JPopupMenu;
Expand All @@ -23,13 +24,13 @@ public class TextComponentPopupMenu extends JPopupMenu implements
private static final long serialVersionUID = 117096441855319758L;
private static TextComponentPopupMenu sharedInstance = null;

public static void installToComponent(JTextComponent c) {
public static void installToComponent(JComponent c) {
if (c instanceof JTextField && !(c instanceof JPasswordField)) {
c.addMouseListener(TextComponentPopupMenu.getSharedInstance());
}
}

public static void uninstallFromComponent(JTextComponent c) {
public static void uninstallFromComponent(JComponent c) {
if (c instanceof JTextField && !(c instanceof JPasswordField)) {
c.removeMouseListener(getSharedInstance());
}
Expand Down
Loading

0 comments on commit 0c61752

Please sign in to comment.