Removed unnecessary tools.
This commit is contained in:
@ -1,757 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.configurator;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.ToolTipManager;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import javolution.util.FastList;
|
||||
|
||||
import com.l2jserver.tools.configurator.ConfigUserInterface.ConfigFile.ConfigComment;
|
||||
import com.l2jserver.tools.configurator.ConfigUserInterface.ConfigFile.ConfigProperty;
|
||||
import com.l2jserver.tools.i18n.LanguageControl;
|
||||
import com.l2jserver.tools.images.ImagesTable;
|
||||
|
||||
/**
|
||||
* @author KenM
|
||||
*/
|
||||
public class ConfigUserInterface extends JFrame implements ActionListener
|
||||
{
|
||||
private static final long serialVersionUID = 2609592249095305857L;
|
||||
|
||||
public static final String EOL = System.getProperty("line.separator");
|
||||
|
||||
private final JTabbedPane _tabPane = new JTabbedPane();
|
||||
|
||||
private List<ConfigFile> _configs = new FastList<>();
|
||||
|
||||
private ResourceBundle _bundle;
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// couldn't care less
|
||||
}
|
||||
|
||||
final ResourceBundle bundle = ResourceBundle.getBundle("configurator.Configurator", Locale.getDefault(), LanguageControl.INSTANCE);
|
||||
|
||||
SwingUtilities.invokeLater(() ->
|
||||
{
|
||||
ConfigUserInterface cui = new ConfigUserInterface(bundle);
|
||||
cui.setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
public ConfigUserInterface(ResourceBundle bundle)
|
||||
{
|
||||
setBundle(bundle);
|
||||
setTitle(bundle.getString("toolName"));
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setSize(750, 500);
|
||||
setLayout(new GridBagLayout());
|
||||
|
||||
setDefaultLookAndFeelDecorated(true);
|
||||
setIconImage(ImagesTable.getImage("l2j.png").getImage());
|
||||
|
||||
GridBagConstraints cons = new GridBagConstraints();
|
||||
cons.fill = GridBagConstraints.HORIZONTAL;
|
||||
cons.gridx = 0;
|
||||
cons.gridy = 0;
|
||||
cons.weighty = 0;
|
||||
cons.weightx = 1;
|
||||
|
||||
JMenuBar menubar = new JMenuBar();
|
||||
|
||||
JMenu fileMenu = new JMenu(bundle.getString("fileMenu"));
|
||||
JMenu helpMenu = new JMenu(bundle.getString("helpMenu"));
|
||||
|
||||
JMenuItem exitItem = new JMenuItem(bundle.getString("exitItem"));
|
||||
exitItem.setActionCommand("exit");
|
||||
exitItem.addActionListener(this);
|
||||
fileMenu.add(exitItem);
|
||||
|
||||
JMenuItem aboutItem = new JMenuItem(bundle.getString("aboutItem"));
|
||||
aboutItem.setActionCommand("about");
|
||||
aboutItem.addActionListener(this);
|
||||
helpMenu.add(aboutItem);
|
||||
|
||||
menubar.add(fileMenu);
|
||||
menubar.add(helpMenu);
|
||||
|
||||
setJMenuBar(menubar);
|
||||
|
||||
JToolBar toolBar = new JToolBar();
|
||||
toolBar.setFloatable(false);
|
||||
toolBar.setRollover(true);
|
||||
toolBar.add(createToolButton("disk.png", bundle.getString("save"), "save"));
|
||||
this.add(toolBar, cons);
|
||||
|
||||
cons.gridy++;
|
||||
cons.fill = GridBagConstraints.BOTH;
|
||||
cons.weighty = 1;
|
||||
loadConfigs();
|
||||
buildInterface();
|
||||
this.add(_tabPane, cons);
|
||||
}
|
||||
|
||||
private JButton createToolButton(String image, String text, String action)
|
||||
{
|
||||
JButton button = new JButton(text, ImagesTable.getImage(image));
|
||||
button.setActionCommand(action);
|
||||
button.addActionListener(this);
|
||||
return button;
|
||||
}
|
||||
|
||||
private void buildInterface()
|
||||
{
|
||||
ToolTipManager.sharedInstance().setDismissDelay(Integer.MAX_VALUE);
|
||||
ToolTipManager.sharedInstance().setInitialDelay(0);
|
||||
ToolTipManager.sharedInstance().setReshowDelay(0);
|
||||
|
||||
GridBagConstraints cons = new GridBagConstraints();
|
||||
cons.fill = GridBagConstraints.NONE;
|
||||
cons.anchor = GridBagConstraints.FIRST_LINE_START;
|
||||
cons.insets = new Insets(2, 2, 2, 2);
|
||||
for (ConfigFile cf : getConfigs())
|
||||
{
|
||||
JPanel panel = new JPanel()
|
||||
{
|
||||
private static final long serialVersionUID = -323928678804839054L;
|
||||
|
||||
@Override
|
||||
public void scrollRectToVisible(Rectangle r)
|
||||
{
|
||||
}
|
||||
};
|
||||
panel.setLayout(new GridBagLayout());
|
||||
|
||||
cons.gridy = 0;
|
||||
cons.weighty = 0;
|
||||
for (ConfigComment cc : cf.getConfigProperties())
|
||||
{
|
||||
if (!(cc instanceof ConfigProperty))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ConfigProperty cp = (ConfigProperty) cc;
|
||||
cons.gridx = 0;
|
||||
|
||||
JLabel keyLabel = new JLabel(cp.getDisplayName() + ':', ImagesTable.getImage("help.png"), SwingConstants.LEFT);
|
||||
String comments = "<b>" + cp.getName() + ":</b><br>" + cp.getComments();
|
||||
comments = comments.replace(EOL, "<br>");
|
||||
comments = "<html>" + comments + "</html>";
|
||||
keyLabel.setToolTipText(comments);
|
||||
cons.weightx = 0;
|
||||
panel.add(keyLabel, cons);
|
||||
cons.gridx++;
|
||||
|
||||
JComponent valueComponent = cp.getValueComponent();
|
||||
valueComponent.setToolTipText(comments);
|
||||
cons.weightx = 1;
|
||||
panel.add(valueComponent, cons);
|
||||
cons.gridx++;
|
||||
cons.gridy++;
|
||||
}
|
||||
cons.gridy++;
|
||||
cons.weighty = 1;
|
||||
panel.add(new JLabel(), cons); // filler
|
||||
_tabPane.addTab(cf.getName(), new JScrollPane(panel));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfigs()
|
||||
{
|
||||
File configsDir = new File("config");
|
||||
for (File file : configsDir.listFiles())
|
||||
{
|
||||
if (file.getName().endsWith(".properties") && file.isFile() && file.canWrite())
|
||||
{
|
||||
try
|
||||
{
|
||||
parsePropertiesFile(file);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(ConfigUserInterface.this, getBundle().getString("errorReading") + file.getName(), getBundle().getString("error"), JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
private void parsePropertiesFile(File file) throws IOException
|
||||
{
|
||||
try (FileInputStream fis = new FileInputStream(file);
|
||||
InputStreamReader isr = new InputStreamReader(fis);
|
||||
LineNumberReader lnr = new LineNumberReader(isr))
|
||||
{
|
||||
String line;
|
||||
StringBuilder commentBuffer = new StringBuilder();
|
||||
ConfigFile cf = new ConfigFile(file);
|
||||
while ((line = lnr.readLine()) != null)
|
||||
{
|
||||
line = line.trim();
|
||||
if (line.isEmpty())
|
||||
{
|
||||
// blank line, reset comments
|
||||
if (commentBuffer.length() > 0)
|
||||
{
|
||||
cf.addConfigComment(commentBuffer.toString());
|
||||
}
|
||||
commentBuffer.setLength(0);
|
||||
}
|
||||
else if (line.charAt(0) == '#')
|
||||
{
|
||||
if (commentBuffer.length() > 0)
|
||||
{
|
||||
commentBuffer.append(EOL);
|
||||
}
|
||||
commentBuffer.append(line.substring(1));
|
||||
}
|
||||
else if (line.indexOf('=') >= 0)
|
||||
{
|
||||
String[] kv = line.split("=");
|
||||
String key = kv[0].trim();
|
||||
StringBuilder value = new StringBuilder();
|
||||
if (kv.length > 1)
|
||||
{
|
||||
value.append(kv[1].trim());
|
||||
}
|
||||
|
||||
if (line.indexOf('\\') >= 0)
|
||||
{
|
||||
while (((line = lnr.readLine()) != null) && (line.indexOf('\\') >= 0))
|
||||
{
|
||||
value.append(EOL + line);
|
||||
}
|
||||
value.append(EOL + line);
|
||||
}
|
||||
|
||||
String comments = commentBuffer.toString();
|
||||
commentBuffer.setLength(0); // reset
|
||||
|
||||
cf.addConfigProperty(key, parseValue(value.toString()), comments);
|
||||
}
|
||||
}
|
||||
getConfigs().add(cf);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
private Object parseValue(String value)
|
||||
{
|
||||
if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("true"))
|
||||
{
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* try { double parseDouble = Double.parseDouble(value); return parseDouble; } catch (NumberFormatException e) { // not a double, ignore }
|
||||
*/
|
||||
|
||||
// localhost -> 127.0.0.1
|
||||
if (value.equals("localhost"))
|
||||
{
|
||||
value = "127.0.0.1";
|
||||
}
|
||||
|
||||
String[] parts = value.split("\\.");
|
||||
if (parts.length == 4)
|
||||
{
|
||||
boolean ok = true;
|
||||
for (int i = 0; (i < 4) && ok; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
int parseInt = Integer.parseInt(parts[i]);
|
||||
if ((parseInt < 0) || (parseInt > 255))
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
try
|
||||
{
|
||||
InetAddress address = InetAddress.getByName(value);
|
||||
return address;
|
||||
}
|
||||
catch (UnknownHostException e)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static class ConfigFile
|
||||
{
|
||||
private final File _file;
|
||||
private String _name;
|
||||
private final List<ConfigComment> _configs = new FastList<>();
|
||||
|
||||
public ConfigFile(File file)
|
||||
{
|
||||
_file = file;
|
||||
int lastIndex = file.getName().lastIndexOf('.');
|
||||
setName(file.getName().substring(0, lastIndex));
|
||||
}
|
||||
|
||||
public void addConfigProperty(String name, Object value, ValueType type, String comments)
|
||||
{
|
||||
_configs.add(new ConfigProperty(name, value, type, comments));
|
||||
}
|
||||
|
||||
public void addConfigComment(String comment)
|
||||
{
|
||||
_configs.add(new ConfigComment(comment));
|
||||
}
|
||||
|
||||
public void addConfigProperty(String name, Object value, String comments)
|
||||
{
|
||||
this.addConfigProperty(name, value, ValueType.firstTypeMatch(value), comments);
|
||||
}
|
||||
|
||||
public List<ConfigComment> getConfigProperties()
|
||||
{
|
||||
return _configs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name The name to set.
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
public void save() throws IOException
|
||||
{
|
||||
try (FileOutputStream fos = new FileOutputStream(_file);
|
||||
OutputStreamWriter osw = new OutputStreamWriter(fos);
|
||||
BufferedWriter bufWriter = new BufferedWriter(osw))
|
||||
{
|
||||
for (ConfigComment cc : _configs)
|
||||
{
|
||||
cc.save(bufWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigComment
|
||||
{
|
||||
|
||||
private String _comments;
|
||||
|
||||
/**
|
||||
* @param comments
|
||||
*/
|
||||
public ConfigComment(String comments)
|
||||
{
|
||||
_comments = comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the comments.
|
||||
*/
|
||||
public String getComments()
|
||||
{
|
||||
return _comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param comments The comments to set.
|
||||
*/
|
||||
public void setComments(String comments)
|
||||
{
|
||||
_comments = comments;
|
||||
}
|
||||
|
||||
public void save(Writer writer) throws IOException
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('#');
|
||||
sb.append(getComments().replace(EOL, EOL + "#"));
|
||||
sb.append(EOL + EOL);
|
||||
writer.write(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigProperty extends ConfigComment
|
||||
{
|
||||
private String _propname;
|
||||
private Object _value;
|
||||
private ValueType _type;
|
||||
private JComponent _component;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param value
|
||||
* @param type
|
||||
* @param comments
|
||||
*/
|
||||
public ConfigProperty(String name, Object value, ValueType type, String comments)
|
||||
{
|
||||
super(comments);
|
||||
if (!type.getType().isAssignableFrom(value.getClass()))
|
||||
{
|
||||
throw new IllegalArgumentException("Value Instance Type doesn't match the type argument.");
|
||||
}
|
||||
_propname = name;
|
||||
_type = type;
|
||||
_value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return _propname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getDisplayName()
|
||||
{
|
||||
return unCamelize(_propname);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name The name to set.
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
_propname = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the value.
|
||||
*/
|
||||
public Object getValue()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value The value to set.
|
||||
*/
|
||||
public void setValue(String value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the type.
|
||||
*/
|
||||
public ValueType getType()
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type The type to set.
|
||||
*/
|
||||
public void setType(ValueType type)
|
||||
{
|
||||
_type = type;
|
||||
}
|
||||
|
||||
public JComponent getValueComponent()
|
||||
{
|
||||
if (_component == null)
|
||||
{
|
||||
_component = createValueComponent();
|
||||
}
|
||||
return _component;
|
||||
}
|
||||
|
||||
public JComponent createValueComponent()
|
||||
{
|
||||
switch (getType())
|
||||
{
|
||||
case BOOLEAN:
|
||||
boolean bool = (Boolean) getValue();
|
||||
JCheckBox checkBox = new JCheckBox();
|
||||
checkBox.setSelected(bool);
|
||||
return checkBox;
|
||||
case IPv4:
|
||||
return new JIPTextField((Inet4Address) getValue());
|
||||
case DOUBLE:
|
||||
case INTEGER:
|
||||
case STRING:
|
||||
default:
|
||||
String val = getValue().toString();
|
||||
JTextArea textArea = new JTextArea(val);
|
||||
textArea.setFont(UIManager.getFont("TextField.font"));
|
||||
int rows = 1;
|
||||
for (int i = 0; i < val.length(); i++)
|
||||
{
|
||||
if (val.charAt(i) == '\\')
|
||||
{
|
||||
rows++;
|
||||
}
|
||||
}
|
||||
textArea.setRows(rows);
|
||||
textArea.setColumns(Math.max(val.length() / rows, 20));
|
||||
return textArea;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Writer writer) throws IOException
|
||||
{
|
||||
String value;
|
||||
if (getValueComponent() instanceof JCheckBox)
|
||||
{
|
||||
value = Boolean.toString(((JCheckBox) getValueComponent()).isSelected());
|
||||
value = value.substring(0, 1).toUpperCase() + value.substring(1);
|
||||
}
|
||||
else if (getValueComponent() instanceof JIPTextField)
|
||||
{
|
||||
value = ((JIPTextField) getValueComponent()).getText();
|
||||
}
|
||||
else if (getValueComponent() instanceof JTextArea)
|
||||
{
|
||||
value = ((JTextArea) getValueComponent()).getText();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("Unhandled component value");
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('#');
|
||||
sb.append(getComments().replace(EOL, EOL + "#"));
|
||||
sb.append(EOL);
|
||||
sb.append(getName());
|
||||
sb.append(" = ");
|
||||
sb.append(value);
|
||||
sb.append(EOL);
|
||||
sb.append(EOL);
|
||||
writer.write(sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static enum ValueType
|
||||
{
|
||||
BOOLEAN(Boolean.class),
|
||||
DOUBLE(Double.class),
|
||||
INTEGER(Integer.class),
|
||||
IPv4(Inet4Address.class),
|
||||
STRING(String.class);
|
||||
|
||||
private final Class<?> _type;
|
||||
|
||||
private ValueType(Class<?> type)
|
||||
{
|
||||
_type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the type.
|
||||
*/
|
||||
public Class<?> getType()
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
public static ValueType firstTypeMatch(Object value)
|
||||
{
|
||||
for (ValueType vt : ValueType.values())
|
||||
{
|
||||
if (vt.getType() == value.getClass())
|
||||
{
|
||||
return vt;
|
||||
}
|
||||
}
|
||||
throw new NoSuchElementException("No match for: " + value.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
String cmd = e.getActionCommand();
|
||||
|
||||
StringBuilder errors = new StringBuilder();
|
||||
|
||||
if (cmd.equals("save"))
|
||||
{
|
||||
for (ConfigFile cf : ConfigUserInterface.this.getConfigs())
|
||||
{
|
||||
try
|
||||
{
|
||||
cf.save();
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
e1.printStackTrace();
|
||||
errors.append(getBundle().getString("errorSaving") + cf.getName() + ".properties. " + getBundle().getString("reason") + e1.getLocalizedMessage() + EOL);
|
||||
}
|
||||
}
|
||||
if (errors.length() == 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(ConfigUserInterface.this, getBundle().getString("success"), "OK", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(ConfigUserInterface.this, errors, getBundle().getString("error"), JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(2);
|
||||
}
|
||||
}
|
||||
else if (cmd.equals("exit"))
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
else if (cmd.equals("about"))
|
||||
{
|
||||
JOptionPane.showMessageDialog(ConfigUserInterface.this, getBundle().getString("credits") + EOL + "http://www.l2jserver.com" + EOL + EOL + getBundle().getString("icons") + EOL + EOL + getBundle().getString("langText") + EOL + getBundle().getString("translation"), getBundle().getString("aboutItem"), JOptionPane.INFORMATION_MESSAGE, ImagesTable.getImage("l2jserverlogo.png"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param configs The configuration to set.
|
||||
*/
|
||||
public void setConfigs(List<ConfigFile> configs)
|
||||
{
|
||||
_configs = configs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the configuration.
|
||||
*/
|
||||
public List<ConfigFile> getConfigs()
|
||||
{
|
||||
return _configs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param keyName
|
||||
* @return Returns the configuration setting name in a human readable form.
|
||||
*/
|
||||
public static String unCamelize(final String keyName)
|
||||
{
|
||||
Pattern p = Pattern.compile("\\p{Lu}");
|
||||
Matcher m = p.matcher(keyName);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int last = 0;
|
||||
while (m.find())
|
||||
{
|
||||
if (m.start() != (last + 1))
|
||||
{
|
||||
m.appendReplacement(sb, " " + m.group());
|
||||
}
|
||||
last = m.start();
|
||||
}
|
||||
m.appendTail(sb);
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bundle The bundle to set.
|
||||
*/
|
||||
public void setBundle(ResourceBundle bundle)
|
||||
{
|
||||
_bundle = bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the bundle.
|
||||
*/
|
||||
public ResourceBundle getBundle()
|
||||
{
|
||||
return _bundle;
|
||||
}
|
||||
}
|
@ -1,328 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.configurator;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.PlainDocument;
|
||||
|
||||
/**
|
||||
* @author KenM
|
||||
*/
|
||||
public class JIPTextField extends JPanel implements FocusListener
|
||||
{
|
||||
/**
|
||||
* Comment for <code>serialVersionUID</code>
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JTextField[] _textFields;
|
||||
private List<FocusListener> _focusListeners;
|
||||
|
||||
public JIPTextField(String textIp)
|
||||
{
|
||||
super.addFocusListener(this);
|
||||
|
||||
initIPTextField(textIp);
|
||||
|
||||
for (JTextField _textField : _textFields)
|
||||
{
|
||||
_textField.addFocusListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public JIPTextField()
|
||||
{
|
||||
this("...");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
public JIPTextField(Inet4Address value)
|
||||
{
|
||||
this(value.getHostAddress());
|
||||
}
|
||||
|
||||
private void initIPTextField(String textIp)
|
||||
{
|
||||
final ActionListener nextfocusaction = evt -> ((Component) evt.getSource()).transferFocus();
|
||||
|
||||
setLayout(new GridBagLayout());
|
||||
_textFields = new JTextField[4];
|
||||
|
||||
GridBagConstraints cons = new GridBagConstraints();
|
||||
cons.anchor = GridBagConstraints.PAGE_START;
|
||||
cons.fill = GridBagConstraints.HORIZONTAL;
|
||||
cons.insets = new Insets(1, 1, 1, 1);
|
||||
cons.gridx = 0;
|
||||
cons.gridy = 0;
|
||||
|
||||
MaxLengthDocument previous = null;
|
||||
String[] parts = textIp.split("\\.");
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
String str = parts[i];
|
||||
if (i > 0)
|
||||
{
|
||||
JLabel dot = new JLabel(".");
|
||||
cons.weightx = 0;
|
||||
add(dot, cons);
|
||||
cons.gridx++;
|
||||
}
|
||||
MaxLengthDocument maxDoc = new MaxLengthDocument(3);
|
||||
_textFields[i] = new JTextField(maxDoc, str, 3);
|
||||
if (previous != null)
|
||||
{
|
||||
previous.setNext(_textFields[i]);
|
||||
}
|
||||
previous = maxDoc;
|
||||
// ic.weightx = 1;
|
||||
add(_textFields[i], cons);
|
||||
_textFields[i].addActionListener(nextfocusaction);
|
||||
cons.gridx++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFocusListener(FocusListener fl)
|
||||
{
|
||||
if (_focusListeners == null)
|
||||
{
|
||||
_focusListeners = new LinkedList<>();
|
||||
}
|
||||
|
||||
if ((fl != null) && !_focusListeners.contains(fl))
|
||||
{
|
||||
_focusListeners.add(fl);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFocusListener(FocusListener fl)
|
||||
{
|
||||
if (_focusListeners != null)
|
||||
{
|
||||
_focusListeners.remove(fl);
|
||||
}
|
||||
}
|
||||
|
||||
public String getText()
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (_textFields[i].getText().length() == 0)
|
||||
{
|
||||
str.append('0');
|
||||
}
|
||||
else
|
||||
{
|
||||
str.append(_textFields[i].getText());
|
||||
}
|
||||
|
||||
if (i < 3)
|
||||
{
|
||||
str.append('.');
|
||||
}
|
||||
}
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
public void setText(String str)
|
||||
{
|
||||
try
|
||||
{
|
||||
// make sure string is not null; throw a NullPointerException otherwise
|
||||
str.length();
|
||||
|
||||
InetAddress ip = InetAddress.getByName(str);
|
||||
byte b[] = ip.getAddress();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
// byte always have a sign in Java, IP addresses aren't
|
||||
if (b[i] >= 0)
|
||||
{
|
||||
_textFields[i].setText(Byte.toString(b[i]));
|
||||
}
|
||||
else
|
||||
{
|
||||
_textFields[i].setText(Integer.toString(b[i] + 256));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
catch (UnknownHostException ex)
|
||||
{
|
||||
}
|
||||
catch (NullPointerException npe)
|
||||
{
|
||||
}
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
_textFields[i].setText("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled)
|
||||
{
|
||||
for (JTextField _textField : _textFields)
|
||||
{
|
||||
if (_textField != null)
|
||||
{
|
||||
_textField.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (!_textFields[i].getText().isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isCorrect()
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (_textFields[i].getText().length() == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusGained(FocusEvent event)
|
||||
{
|
||||
if (_focusListeners != null)
|
||||
{
|
||||
for (FocusListener fl : _focusListeners)
|
||||
{
|
||||
fl.focusGained(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusLost(FocusEvent event)
|
||||
{
|
||||
if (isCorrect() || isEmpty())
|
||||
{
|
||||
if (_focusListeners != null)
|
||||
{
|
||||
for (FocusListener fl : _focusListeners)
|
||||
{
|
||||
fl.focusLost(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MaxLengthDocument extends PlainDocument
|
||||
{
|
||||
|
||||
/**
|
||||
* Comment for <code>serialVersionUID</code>
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final int _max;
|
||||
private JTextField _next;
|
||||
|
||||
public MaxLengthDocument(int maxLength)
|
||||
{
|
||||
this(maxLength, null);
|
||||
}
|
||||
|
||||
public MaxLengthDocument(int maxLength, JTextField next)
|
||||
{
|
||||
_max = maxLength;
|
||||
setNext(next);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertString(int offset, String str, AttributeSet a) throws BadLocationException
|
||||
{
|
||||
if ((getLength() + str.length()) > _max)
|
||||
{
|
||||
if (getNext() != null)
|
||||
{
|
||||
if (getNext().getText().length() > 0)
|
||||
{
|
||||
getNext().select(0, getNext().getText().length());
|
||||
}
|
||||
else
|
||||
{
|
||||
getNext().getDocument().insertString(0, str, a);
|
||||
}
|
||||
getNext().requestFocusInWindow();
|
||||
}
|
||||
else
|
||||
{
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
super.insertString(offset, str, a);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param next The next to set.
|
||||
*/
|
||||
public void setNext(JTextField next)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the next.
|
||||
*/
|
||||
public JTextField getNext()
|
||||
{
|
||||
return _next;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
/**
|
||||
* @author mrTJO
|
||||
*/
|
||||
public interface DBOutputInterface
|
||||
{
|
||||
public void setProgressIndeterminate(boolean value);
|
||||
|
||||
public void setProgressMaximum(int maxValue);
|
||||
|
||||
public void setProgressValue(int value);
|
||||
|
||||
public void setFrameVisible(boolean value);
|
||||
|
||||
public void appendToProgressArea(String text);
|
||||
|
||||
public Connection getConnection();
|
||||
|
||||
public int requestConfirm(String title, String message, int type);
|
||||
|
||||
public void showMessage(String title, String message, int type);
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller;
|
||||
|
||||
import java.awt.HeadlessException;
|
||||
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import com.l2jserver.tools.dbinstaller.console.DBInstallerConsole;
|
||||
import com.l2jserver.tools.dbinstaller.gui.DBConfigGUI;
|
||||
|
||||
/**
|
||||
* Contains main class for Database Installer If system doesn't support the graphical UI, start the installer in console mode.
|
||||
* @author mrTJO
|
||||
*/
|
||||
public class LauncherGS
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String mode = "l2jgs";
|
||||
String dir = "../sql/game/";
|
||||
String cleanUp = "gs_cleanup.sql";
|
||||
|
||||
try
|
||||
{
|
||||
// Set OS Look And Feel
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
new DBConfigGUI(mode, dir, cleanUp);
|
||||
}
|
||||
catch (HeadlessException e)
|
||||
{
|
||||
new DBInstallerConsole(mode, dir, cleanUp);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller;
|
||||
|
||||
import java.awt.HeadlessException;
|
||||
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import com.l2jserver.tools.dbinstaller.console.DBInstallerConsole;
|
||||
import com.l2jserver.tools.dbinstaller.gui.DBConfigGUI;
|
||||
|
||||
/**
|
||||
* Contains main class for Database Installer If system doesn't support the graphical UI, start the installer in console mode.
|
||||
* @author mrTJO
|
||||
*/
|
||||
public class LauncherLS
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String mode = "l2jls";
|
||||
String dir = "../sql/login/";
|
||||
String cleanUp = "ls_cleanup.sql";
|
||||
|
||||
try
|
||||
{
|
||||
// Set OS Look And Feel
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
new DBConfigGUI(mode, dir, cleanUp);
|
||||
}
|
||||
catch (HeadlessException e)
|
||||
{
|
||||
new DBInstallerConsole(mode, dir, cleanUp);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,147 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import com.l2jserver.tools.dbinstaller.util.mysql.DBDumper;
|
||||
import com.l2jserver.tools.dbinstaller.util.mysql.ScriptExecutor;
|
||||
import com.l2jserver.util.file.filter.SQLFilter;
|
||||
|
||||
/**
|
||||
* @author mrTJO
|
||||
*/
|
||||
public class RunTasks extends Thread
|
||||
{
|
||||
DBOutputInterface _frame;
|
||||
boolean _cleanInstall;
|
||||
String _db;
|
||||
String _sqlDir;
|
||||
String _cleanUpFile;
|
||||
|
||||
public RunTasks(DBOutputInterface frame, String db, String sqlDir, String cleanUpFile, boolean cleanInstall)
|
||||
{
|
||||
_frame = frame;
|
||||
_db = db;
|
||||
_cleanInstall = cleanInstall;
|
||||
_sqlDir = sqlDir;
|
||||
_cleanUpFile = cleanUpFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
new DBDumper(_frame, _db);
|
||||
ScriptExecutor exec = new ScriptExecutor(_frame);
|
||||
|
||||
File clnFile = new File(_cleanUpFile);
|
||||
File updDir = new File(_sqlDir, "updates");
|
||||
File[] files = updDir.listFiles(new SQLFilter());
|
||||
|
||||
Preferences prefs = Preferences.userRoot();
|
||||
|
||||
if (_cleanInstall)
|
||||
{
|
||||
if (clnFile.exists())
|
||||
{
|
||||
_frame.appendToProgressArea("Cleaning Database...");
|
||||
exec.execSqlFile(clnFile);
|
||||
_frame.appendToProgressArea("Database Cleaned!");
|
||||
}
|
||||
else
|
||||
{
|
||||
_frame.appendToProgressArea("Database Cleaning Script Not Found!");
|
||||
}
|
||||
|
||||
if (updDir.exists())
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (File cf : files)
|
||||
{
|
||||
sb.append(cf.getName() + ';');
|
||||
}
|
||||
prefs.put(_db + "_upd", sb.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_cleanInstall && updDir.exists())
|
||||
{
|
||||
_frame.appendToProgressArea("Installing Updates...");
|
||||
|
||||
for (File cf : files)
|
||||
{
|
||||
if (!prefs.get(_db + "_upd", "").contains(cf.getName()))
|
||||
{
|
||||
exec.execSqlFile(cf, true);
|
||||
prefs.put(_db + "_upd", prefs.get(_db + "_upd", "") + cf.getName() + ";");
|
||||
}
|
||||
}
|
||||
_frame.appendToProgressArea("Database Updates Installed!");
|
||||
}
|
||||
}
|
||||
|
||||
_frame.appendToProgressArea("Installing Database Content...");
|
||||
exec.execSqlBatch(new File(_sqlDir));
|
||||
_frame.appendToProgressArea("Database Installation Complete!");
|
||||
|
||||
File cusDir = new File(_sqlDir, "custom");
|
||||
if (cusDir.exists())
|
||||
{
|
||||
int ch = _frame.requestConfirm("Install Custom", "Do you want to install custom tables?", JOptionPane.YES_NO_OPTION);
|
||||
if (ch == 0)
|
||||
{
|
||||
_frame.appendToProgressArea("Installing Custom Tables...");
|
||||
exec.execSqlBatch(cusDir);
|
||||
_frame.appendToProgressArea("Custom Tables Installed!");
|
||||
}
|
||||
}
|
||||
|
||||
File modDir = new File(_sqlDir, "mods");
|
||||
if (modDir.exists())
|
||||
{
|
||||
int ch = _frame.requestConfirm("Install Mods", "Do you want to install mod tables?", JOptionPane.YES_NO_OPTION);
|
||||
if (ch == 0)
|
||||
{
|
||||
_frame.appendToProgressArea("Installing Mods Tables...");
|
||||
exec.execSqlBatch(modDir);
|
||||
_frame.appendToProgressArea("Mods Tables Installed!");
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_frame.getConnection().close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Cannot close MySQL Connection: " + e.getMessage(), "Connection Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
_frame.setFrameVisible(false);
|
||||
_frame.showMessage("Done!", "Database Installation Complete!", JOptionPane.INFORMATION_MESSAGE);
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller.console;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.Scanner;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import com.l2jserver.tools.dbinstaller.DBOutputInterface;
|
||||
import com.l2jserver.tools.dbinstaller.RunTasks;
|
||||
import com.l2jserver.tools.dbinstaller.util.CloseShieldedInputStream;
|
||||
import com.l2jserver.tools.dbinstaller.util.mysql.MySqlConnect;
|
||||
|
||||
/**
|
||||
* @author mrTJO
|
||||
*/
|
||||
public class DBInstallerConsole implements DBOutputInterface
|
||||
{
|
||||
Connection _con;
|
||||
|
||||
public DBInstallerConsole(String db, String dir, String cleanUp)
|
||||
{
|
||||
System.out.println("Welcome to L2J DataBase installer");
|
||||
Preferences prop = Preferences.userRoot();
|
||||
RunTasks rt = null;
|
||||
try (Scanner scn = new Scanner(new CloseShieldedInputStream(System.in)))
|
||||
{
|
||||
while (_con == null)
|
||||
{
|
||||
System.out.printf("%s (%s): ", "Host", prop.get("dbHost_" + db, "localhost"));
|
||||
String dbHost = scn.nextLine();
|
||||
System.out.printf("%s (%s): ", "Port", prop.get("dbPort_" + db, "3306"));
|
||||
String dbPort = scn.nextLine();
|
||||
System.out.printf("%s (%s): ", "Username", prop.get("dbUser_" + db, "root"));
|
||||
String dbUser = scn.nextLine();
|
||||
System.out.printf("%s (%s): ", "Password", "");
|
||||
String dbPass = scn.nextLine();
|
||||
System.out.printf("%s (%s): ", "Database", prop.get("dbDbse_" + db, db));
|
||||
String dbDbse = scn.nextLine();
|
||||
|
||||
dbHost = dbHost.isEmpty() ? prop.get("dbHost_" + db, "localhost") : dbHost;
|
||||
dbPort = dbPort.isEmpty() ? prop.get("dbPort_" + db, "3306") : dbPort;
|
||||
dbUser = dbUser.isEmpty() ? prop.get("dbUser_" + db, "root") : dbUser;
|
||||
dbDbse = dbDbse.isEmpty() ? prop.get("dbDbse_" + db, db) : dbDbse;
|
||||
|
||||
MySqlConnect connector = new MySqlConnect(dbHost, dbPort, dbUser, dbPass, dbDbse, true);
|
||||
|
||||
_con = connector.getConnection();
|
||||
}
|
||||
|
||||
System.out.print("(C)lean install, (U)pdate or (E)xit? ");
|
||||
String resp = scn.next();
|
||||
if (resp.equalsIgnoreCase("c"))
|
||||
{
|
||||
System.out.print("Do you really want to destroy your db (Y/N)?");
|
||||
if (scn.next().equalsIgnoreCase("y"))
|
||||
{
|
||||
rt = new RunTasks(this, db, dir, cleanUp, true);
|
||||
}
|
||||
}
|
||||
else if (resp.equalsIgnoreCase("u"))
|
||||
{
|
||||
rt = new RunTasks(this, db, dir, cleanUp, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (rt != null)
|
||||
{
|
||||
rt.run();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendToProgressArea(String text)
|
||||
{
|
||||
System.out.println(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection()
|
||||
{
|
||||
return _con;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgressIndeterminate(boolean value)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgressMaximum(int maxValue)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgressValue(int value)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFrameVisible(boolean value)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int requestConfirm(String title, String message, int type)
|
||||
{
|
||||
System.out.print(message);
|
||||
String res = "";
|
||||
try (Scanner scn = new Scanner(new CloseShieldedInputStream(System.in)))
|
||||
{
|
||||
res = scn.next();
|
||||
}
|
||||
return res.equalsIgnoreCase("y") ? 0 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(String title, String message, int type)
|
||||
{
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller.gui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SpringLayout;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import com.l2jserver.tools.dbinstaller.RunTasks;
|
||||
import com.l2jserver.tools.dbinstaller.util.mysql.MySqlConnect;
|
||||
import com.l2jserver.tools.dbinstaller.util.swing.SpringUtilities;
|
||||
import com.l2jserver.tools.images.ImagesTable;
|
||||
|
||||
/**
|
||||
* @author mrTJO
|
||||
*/
|
||||
public class DBConfigGUI extends JFrame
|
||||
{
|
||||
private static final long serialVersionUID = -8391792251140797076L;
|
||||
|
||||
JTextField _dbHost;
|
||||
JTextField _dbPort;
|
||||
JTextField _dbUser;
|
||||
JPasswordField _dbPass;
|
||||
JTextField _dbDbse;
|
||||
|
||||
String _db;
|
||||
String _dir;
|
||||
String _cleanUp;
|
||||
|
||||
Preferences _prop;
|
||||
|
||||
public DBConfigGUI(String db, String dir, String cleanUp)
|
||||
{
|
||||
super("L2J Database Installer");
|
||||
setLayout(new SpringLayout());
|
||||
setDefaultLookAndFeelDecorated(true);
|
||||
setIconImage(ImagesTable.getImage("l2j.png").getImage());
|
||||
|
||||
_db = db;
|
||||
_dir = dir;
|
||||
_cleanUp = cleanUp;
|
||||
|
||||
int width = 260;
|
||||
int height = 220;
|
||||
Dimension resolution = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds((resolution.width - width) / 2, (resolution.height - height) / 2, width, height);
|
||||
setResizable(false);
|
||||
|
||||
_prop = Preferences.userRoot();
|
||||
|
||||
// Host
|
||||
JLabel labelDbHost = new JLabel("Host: ", SwingConstants.LEFT);
|
||||
add(labelDbHost);
|
||||
_dbHost = new JTextField(15);
|
||||
_dbHost.setText(_prop.get("dbHost_" + db, "localhost"));
|
||||
labelDbHost.setLabelFor(_dbHost);
|
||||
add(_dbHost);
|
||||
|
||||
// Port
|
||||
JLabel labelDbPort = new JLabel("Port: ", SwingConstants.LEFT);
|
||||
add(labelDbPort);
|
||||
_dbPort = new JTextField(15);
|
||||
_dbPort.setText(_prop.get("dbPort_" + db, "3306"));
|
||||
labelDbPort.setLabelFor(_dbPort);
|
||||
add(_dbPort);
|
||||
|
||||
// Username
|
||||
JLabel labelDbUser = new JLabel("Username: ", SwingConstants.LEFT);
|
||||
add(labelDbUser);
|
||||
_dbUser = new JTextField(15);
|
||||
_dbUser.setText(_prop.get("dbUser_" + db, "root"));
|
||||
labelDbUser.setLabelFor(_dbUser);
|
||||
add(_dbUser);
|
||||
|
||||
// Password
|
||||
JLabel labelDbPass = new JLabel("Password: ", SwingConstants.LEFT);
|
||||
add(labelDbPass);
|
||||
_dbPass = new JPasswordField(15);
|
||||
_dbPass.setText(_prop.get("dbPass_" + db, ""));
|
||||
labelDbPass.setLabelFor(_dbPass);
|
||||
add(_dbPass);
|
||||
|
||||
// Database
|
||||
JLabel labelDbDbse = new JLabel("Database: ", SwingConstants.LEFT);
|
||||
add(labelDbDbse);
|
||||
_dbDbse = new JTextField(15);
|
||||
_dbDbse.setText(_prop.get("dbDbse_" + db, db));
|
||||
labelDbDbse.setLabelFor(_dbDbse);
|
||||
add(_dbDbse);
|
||||
|
||||
ActionListener cancelListener = e -> System.exit(0);
|
||||
|
||||
// Cancel
|
||||
JButton btnCancel = new JButton("Cancel");
|
||||
btnCancel.addActionListener(cancelListener);
|
||||
add(btnCancel);
|
||||
|
||||
ActionListener connectListener = e ->
|
||||
{
|
||||
MySqlConnect connector = new MySqlConnect(_dbHost.getText(), _dbPort.getText(), _dbUser.getText(), new String(_dbPass.getPassword()), _dbDbse.getText(), false);
|
||||
|
||||
if (connector.getConnection() != null)
|
||||
{
|
||||
_prop.put("dbHost_" + _db, _dbHost.getText());
|
||||
_prop.put("dbPort_" + _db, _dbPort.getText());
|
||||
_prop.put("dbUser_" + _db, _dbUser.getText());
|
||||
_prop.put("dbDbse_" + _db, _dbDbse.getText());
|
||||
|
||||
boolean cleanInstall = false;
|
||||
DBInstallerGUI dbi = new DBInstallerGUI(connector.getConnection());
|
||||
setVisible(false);
|
||||
|
||||
Object[] options =
|
||||
{
|
||||
"Full Install",
|
||||
"Upgrade",
|
||||
"Exit"
|
||||
};
|
||||
int n = JOptionPane.showOptionDialog(null, "Select Installation Type", "Installation Type", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
|
||||
|
||||
if ((n == 2) || (n == -1))
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
int conf = JOptionPane.showConfirmDialog(null, "Do you really want to destroy your db?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
|
||||
|
||||
if (conf == 1)
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
cleanInstall = true;
|
||||
}
|
||||
|
||||
dbi.setVisible(true);
|
||||
|
||||
RunTasks task = new RunTasks(dbi, _db, _dir, _cleanUp, cleanInstall);
|
||||
task.setPriority(Thread.MAX_PRIORITY);
|
||||
task.start();
|
||||
}
|
||||
};
|
||||
|
||||
// Connect
|
||||
JButton btnConnect = new JButton("Connect");
|
||||
btnConnect.addActionListener(connectListener);
|
||||
add(btnConnect);
|
||||
|
||||
SpringUtilities.makeCompactGrid(getContentPane(), 6, 2, 5, 5, 5, 5);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
import java.sql.Connection;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
import com.l2jserver.tools.dbinstaller.DBOutputInterface;
|
||||
import com.l2jserver.tools.images.ImagesTable;
|
||||
|
||||
/**
|
||||
* @author mrTJO
|
||||
*/
|
||||
public class DBInstallerGUI extends JFrame implements DBOutputInterface
|
||||
{
|
||||
private static final long serialVersionUID = -1005504757826370170L;
|
||||
|
||||
private final JProgressBar _progBar;
|
||||
private final JTextArea _progArea;
|
||||
private final Connection _con;
|
||||
|
||||
public DBInstallerGUI(Connection con)
|
||||
{
|
||||
super("L2J Database Installer");
|
||||
setLayout(new BorderLayout());
|
||||
setDefaultLookAndFeelDecorated(true);
|
||||
setIconImage(ImagesTable.getImage("l2j.png").getImage());
|
||||
|
||||
_con = con;
|
||||
|
||||
int width = 480;
|
||||
int height = 360;
|
||||
Dimension resolution = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds((resolution.width - width) / 2, (resolution.height - height) / 2, width, height);
|
||||
setResizable(false);
|
||||
|
||||
_progBar = new JProgressBar();
|
||||
_progBar.setIndeterminate(true);
|
||||
add(_progBar, BorderLayout.PAGE_START);
|
||||
|
||||
_progArea = new JTextArea();
|
||||
JScrollPane scrollPane = new JScrollPane(_progArea);
|
||||
|
||||
_progArea.setEditable(false);
|
||||
appendToProgressArea("Connected");
|
||||
|
||||
add(scrollPane, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgressIndeterminate(boolean value)
|
||||
{
|
||||
_progBar.setIndeterminate(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgressMaximum(int maxValue)
|
||||
{
|
||||
_progBar.setMaximum(maxValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgressValue(int value)
|
||||
{
|
||||
_progBar.setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendToProgressArea(String text)
|
||||
{
|
||||
_progArea.append(text + System.getProperty("line.separator"));
|
||||
_progArea.setCaretPosition(_progArea.getDocument().getLength());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection()
|
||||
{
|
||||
return _con;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFrameVisible(boolean value)
|
||||
{
|
||||
setVisible(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int requestConfirm(String title, String message, int type)
|
||||
{
|
||||
return JOptionPane.showConfirmDialog(null, message, title, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(String title, String message, int type)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, message, title, type);
|
||||
}
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Prevent the underlying input stream to close.
|
||||
* @author Joe Cheng, Zoey76
|
||||
*/
|
||||
public class CloseShieldedInputStream extends InputStream
|
||||
{
|
||||
private InputStream _in = null;
|
||||
|
||||
/**
|
||||
* Instantiates a new close shielded input stream.
|
||||
* @param in the in
|
||||
*/
|
||||
public CloseShieldedInputStream(InputStream in)
|
||||
{
|
||||
_in = in;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
_in = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int read() throws IOException
|
||||
{
|
||||
if (_in == null)
|
||||
{
|
||||
throw new IOException("Stream is null!");
|
||||
}
|
||||
return _in.read();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int read(byte b[]) throws IOException
|
||||
{
|
||||
if (_in == null)
|
||||
{
|
||||
throw new IOException("Stream is null!");
|
||||
}
|
||||
return _in.read(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int read(byte b[], int off, int len) throws IOException
|
||||
{
|
||||
if (_in == null)
|
||||
{
|
||||
throw new IOException("Stream is null!");
|
||||
}
|
||||
return _in.read(b, off, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public long skip(long n) throws IOException
|
||||
{
|
||||
if (_in == null)
|
||||
{
|
||||
throw new IOException("Stream is null!");
|
||||
}
|
||||
return _in.skip(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void mark(int readlimit)
|
||||
{
|
||||
if (_in != null)
|
||||
{
|
||||
_in.mark(readlimit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean markSupported()
|
||||
{
|
||||
if (_in == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _in.markSupported();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void reset() throws IOException
|
||||
{
|
||||
if (_in == null)
|
||||
{
|
||||
throw new IOException("Stream is null!");
|
||||
}
|
||||
_in.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the underlying stream.
|
||||
* @return the underlying stream
|
||||
*/
|
||||
public InputStream getUnderlyingStream()
|
||||
{
|
||||
return _in;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller.util;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author mrTJO
|
||||
*/
|
||||
public class FileWriterStdout extends BufferedWriter
|
||||
{
|
||||
public FileWriterStdout(FileWriter fileWriter)
|
||||
{
|
||||
super(fileWriter);
|
||||
}
|
||||
|
||||
public void println() throws IOException
|
||||
{
|
||||
append(System.getProperty("line.separator"));
|
||||
}
|
||||
|
||||
public void println(String line) throws IOException
|
||||
{
|
||||
append(line + System.getProperty("line.separator"));
|
||||
}
|
||||
|
||||
public void print(String text) throws IOException
|
||||
{
|
||||
append(text);
|
||||
}
|
||||
}
|
@ -1,216 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller.util.mysql;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Formatter;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.l2jserver.tools.dbinstaller.DBOutputInterface;
|
||||
import com.l2jserver.tools.dbinstaller.util.FileWriterStdout;
|
||||
|
||||
/**
|
||||
* @author mrTJO
|
||||
*/
|
||||
public class DBDumper
|
||||
{
|
||||
DBOutputInterface _frame;
|
||||
String _db;
|
||||
|
||||
public DBDumper(DBOutputInterface frame, String db)
|
||||
{
|
||||
_frame = frame;
|
||||
_db = db;
|
||||
createDump();
|
||||
}
|
||||
|
||||
public void createDump()
|
||||
{
|
||||
try (Formatter form = new Formatter())
|
||||
{
|
||||
Connection con = _frame.getConnection();
|
||||
try (Statement s = con.createStatement();
|
||||
ResultSet rset = s.executeQuery("SHOW TABLES"))
|
||||
{
|
||||
File dump = new File("dumps", form.format("%1$s_dump_%2$tY%2$tm%2$td-%2$tH%2$tM%2$tS.sql", _db, new GregorianCalendar().getTime()).toString());
|
||||
new File("dumps").mkdir();
|
||||
dump.createNewFile();
|
||||
|
||||
_frame.appendToProgressArea("Writing dump " + dump.getName());
|
||||
if (rset.last())
|
||||
{
|
||||
int rows = rset.getRow();
|
||||
rset.beforeFirst();
|
||||
if (rows > 0)
|
||||
{
|
||||
_frame.setProgressIndeterminate(false);
|
||||
_frame.setProgressMaximum(rows);
|
||||
}
|
||||
}
|
||||
|
||||
try (FileWriter fileWriter = new FileWriter(dump);
|
||||
FileWriterStdout fws = new FileWriterStdout(fileWriter))
|
||||
{
|
||||
while (rset.next())
|
||||
{
|
||||
_frame.setProgressValue(rset.getRow());
|
||||
_frame.appendToProgressArea("Dumping Table " + rset.getString(1));
|
||||
fws.println("CREATE TABLE `" + rset.getString(1) + "`");
|
||||
fws.println("(");
|
||||
try (Statement desc = con.createStatement();
|
||||
ResultSet dset = desc.executeQuery("DESC " + rset.getString(1)))
|
||||
{
|
||||
Map<String, List<String>> keys = new HashMap<>();
|
||||
boolean isFirst = true;
|
||||
while (dset.next())
|
||||
{
|
||||
if (!isFirst)
|
||||
{
|
||||
fws.println(",");
|
||||
}
|
||||
fws.print("\t`" + dset.getString(1) + "`");
|
||||
fws.print(" " + dset.getString(2));
|
||||
if (dset.getString(3).equals("NO"))
|
||||
{
|
||||
fws.print(" NOT NULL");
|
||||
}
|
||||
if (!dset.getString(4).isEmpty())
|
||||
{
|
||||
if (!keys.containsKey(dset.getString(4)))
|
||||
{
|
||||
keys.put(dset.getString(4), new ArrayList<String>());
|
||||
}
|
||||
keys.get(dset.getString(4)).add(dset.getString(1));
|
||||
}
|
||||
if (dset.getString(5) != null)
|
||||
{
|
||||
fws.print(" DEFAULT '" + dset.getString(5) + "'");
|
||||
}
|
||||
if (!dset.getString(6).isEmpty())
|
||||
{
|
||||
fws.print(" " + dset.getString(6));
|
||||
}
|
||||
isFirst = false;
|
||||
}
|
||||
if (keys.containsKey("PRI"))
|
||||
{
|
||||
fws.println(",");
|
||||
fws.print("\tPRIMARY KEY (");
|
||||
isFirst = true;
|
||||
for (String key : keys.get("PRI"))
|
||||
{
|
||||
if (!isFirst)
|
||||
{
|
||||
fws.print(", ");
|
||||
}
|
||||
fws.print("`" + key + "`");
|
||||
isFirst = false;
|
||||
}
|
||||
fws.print(")");
|
||||
}
|
||||
if (keys.containsKey("MUL"))
|
||||
{
|
||||
fws.println(",");
|
||||
isFirst = true;
|
||||
for (String key : keys.get("MUL"))
|
||||
{
|
||||
if (!isFirst)
|
||||
{
|
||||
fws.println(", ");
|
||||
}
|
||||
fws.print("\tKEY `key_" + key + "` (`" + key + "`)");
|
||||
isFirst = false;
|
||||
}
|
||||
}
|
||||
fws.println();
|
||||
fws.println(");");
|
||||
fws.flush();
|
||||
}
|
||||
|
||||
try (Statement desc = con.createStatement();
|
||||
ResultSet dset = desc.executeQuery("SELECT * FROM " + rset.getString(1)))
|
||||
{
|
||||
boolean isFirst = true;
|
||||
int cnt = 0;
|
||||
while (dset.next())
|
||||
{
|
||||
if ((cnt % 100) == 0)
|
||||
{
|
||||
fws.println("INSERT INTO `" + rset.getString(1) + "` VALUES ");
|
||||
}
|
||||
else
|
||||
{
|
||||
fws.println(",");
|
||||
}
|
||||
|
||||
fws.print("\t(");
|
||||
boolean isInFirst = true;
|
||||
for (int i = 1; i <= dset.getMetaData().getColumnCount(); i++)
|
||||
{
|
||||
if (!isInFirst)
|
||||
{
|
||||
fws.print(", ");
|
||||
}
|
||||
|
||||
if (dset.getString(i) == null)
|
||||
{
|
||||
fws.print("NULL");
|
||||
}
|
||||
else
|
||||
{
|
||||
fws.print("'" + dset.getString(i).replace("\'", "\\\'") + "'");
|
||||
}
|
||||
isInFirst = false;
|
||||
}
|
||||
fws.print(")");
|
||||
isFirst = false;
|
||||
|
||||
if ((cnt % 100) == 99)
|
||||
{
|
||||
fws.println(";");
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
if (!isFirst && ((cnt % 100) != 0))
|
||||
{
|
||||
fws.println(";");
|
||||
}
|
||||
fws.println();
|
||||
fws.flush();
|
||||
}
|
||||
}
|
||||
fws.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
_frame.appendToProgressArea("Dump Complete!");
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller.util.mysql;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Formatter;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
/**
|
||||
* @author mrTJO
|
||||
*/
|
||||
public class MySqlConnect
|
||||
{
|
||||
Connection con = null;
|
||||
|
||||
public MySqlConnect(String host, String port, String user, String password, String db, boolean console)
|
||||
{
|
||||
try (Formatter form = new Formatter())
|
||||
{
|
||||
Class.forName("com.mysql.jdbc.Driver").newInstance();
|
||||
final String formattedText = form.format("jdbc:mysql://%1$s:%2$s", host, port).toString();
|
||||
con = DriverManager.getConnection(formattedText, user, password);
|
||||
|
||||
try (Statement s = con.createStatement())
|
||||
{
|
||||
s.execute("CREATE DATABASE IF NOT EXISTS `" + db + "`");
|
||||
s.execute("USE `" + db + "`");
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
if (console)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "MySQL Error: " + e.getMessage(), "Connection Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
catch (InstantiationException e)
|
||||
{
|
||||
if (console)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Instantiation Exception: " + e.getMessage(), "Connection Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
if (console)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Illegal Access: " + e.getMessage(), "Connection Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
if (console)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Cannot find MySQL Connector: " + e.getMessage(), "Connection Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getConnection()
|
||||
{
|
||||
return con;
|
||||
}
|
||||
|
||||
public Statement getStatement()
|
||||
{
|
||||
try
|
||||
{
|
||||
return con.createStatement();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
System.out.println("Statement Null");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller.util.mysql;
|
||||
|
||||
import java.awt.HeadlessException;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import com.l2jserver.tools.dbinstaller.DBOutputInterface;
|
||||
import com.l2jserver.util.file.filter.SQLFilter;
|
||||
|
||||
/**
|
||||
* @author mrTJO
|
||||
*/
|
||||
public class ScriptExecutor
|
||||
{
|
||||
DBOutputInterface _frame;
|
||||
|
||||
public ScriptExecutor(DBOutputInterface frame)
|
||||
{
|
||||
_frame = frame;
|
||||
}
|
||||
|
||||
public void execSqlBatch(File dir)
|
||||
{
|
||||
execSqlBatch(dir, false);
|
||||
}
|
||||
|
||||
public void execSqlBatch(File dir, boolean skipErrors)
|
||||
{
|
||||
File[] file = dir.listFiles(new SQLFilter());
|
||||
Arrays.sort(file);
|
||||
_frame.setProgressIndeterminate(false);
|
||||
_frame.setProgressMaximum(file.length - 1);
|
||||
for (int i = 0; i < file.length; i++)
|
||||
{
|
||||
_frame.setProgressValue(i);
|
||||
execSqlFile(file[i], skipErrors);
|
||||
}
|
||||
}
|
||||
|
||||
public void execSqlFile(File file)
|
||||
{
|
||||
execSqlFile(file, false);
|
||||
}
|
||||
|
||||
public void execSqlFile(File file, boolean skipErrors)
|
||||
{
|
||||
_frame.appendToProgressArea("Installing " + file.getName());
|
||||
String line = "";
|
||||
Connection con = _frame.getConnection();
|
||||
try (Statement stmt = con.createStatement();
|
||||
Scanner scn = new Scanner(file))
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (scn.hasNextLine())
|
||||
{
|
||||
line = scn.nextLine();
|
||||
if (line.startsWith("--"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (line.contains("--"))
|
||||
{
|
||||
line = line.split("--")[0];
|
||||
}
|
||||
|
||||
line = line.trim();
|
||||
if (!line.isEmpty())
|
||||
{
|
||||
sb.append(line + System.getProperty("line.separator"));
|
||||
}
|
||||
|
||||
if (line.endsWith(";"))
|
||||
{
|
||||
stmt.execute(sb.toString());
|
||||
sb = new StringBuilder();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "File Not Found!: " + e.getMessage(), "Installer Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
if (!skipErrors)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object[] options =
|
||||
{
|
||||
"Continue",
|
||||
"Abort"
|
||||
};
|
||||
|
||||
int n = JOptionPane.showOptionDialog(null, "MySQL Error: " + e.getMessage(), "Script Error", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
|
||||
if (n == 1)
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
catch (HeadlessException h)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,226 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of Oracle or the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package com.l2jserver.tools.dbinstaller.util.swing;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
|
||||
import javax.swing.Spring;
|
||||
import javax.swing.SpringLayout;
|
||||
|
||||
/**
|
||||
* A 1.4 file that provides utility methods for creating form- or grid-style layouts with SpringLayout.<br>
|
||||
* These utilities are used by several programs, such as SpringBox and SpringCompactGrid.
|
||||
*/
|
||||
public class SpringUtilities
|
||||
{
|
||||
/**
|
||||
* A debugging utility that prints to stdout the component's minimum, preferred, and maximum sizes.
|
||||
* @param c
|
||||
*/
|
||||
public static void printSizes(Component c)
|
||||
{
|
||||
System.out.println("minimumSize = " + c.getMinimumSize());
|
||||
System.out.println("preferredSize = " + c.getPreferredSize());
|
||||
System.out.println("maximumSize = " + c.getMaximumSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* Aligns the first <code>rows</code> * <code>cols</code> components of <code>parent</code> in a grid. Each component is as big as the maximum preferred width and height of the components. The parent is made just big enough to fit them all.
|
||||
* @param parent
|
||||
* @param rows number of rows
|
||||
* @param cols number of columns
|
||||
* @param initialX x location to start the grid at
|
||||
* @param initialY y location to start the grid at
|
||||
* @param xPad x padding between cells
|
||||
* @param yPad y padding between cells
|
||||
*/
|
||||
public static void makeGrid(Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad)
|
||||
{
|
||||
SpringLayout layout;
|
||||
try
|
||||
{
|
||||
layout = (SpringLayout) parent.getLayout();
|
||||
}
|
||||
catch (ClassCastException exc)
|
||||
{
|
||||
System.err.println("The first argument to makeGrid must use SpringLayout.");
|
||||
return;
|
||||
}
|
||||
|
||||
Spring xPadSpring = Spring.constant(xPad);
|
||||
Spring yPadSpring = Spring.constant(yPad);
|
||||
Spring initialXSpring = Spring.constant(initialX);
|
||||
Spring initialYSpring = Spring.constant(initialY);
|
||||
int max = rows * cols;
|
||||
|
||||
// Calculate Springs that are the max of the width/height so that all
|
||||
// cells have the same size.
|
||||
Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0)).getWidth();
|
||||
Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0)).getWidth();
|
||||
for (int i = 1; i < max; i++)
|
||||
{
|
||||
SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
|
||||
|
||||
maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
|
||||
maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
|
||||
}
|
||||
|
||||
// Apply the new width/height Spring. This forces all the
|
||||
// components to have the same size.
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
|
||||
|
||||
cons.setWidth(maxWidthSpring);
|
||||
cons.setHeight(maxHeightSpring);
|
||||
}
|
||||
|
||||
// Then adjust the x/y constraints of all the cells so that they
|
||||
// are aligned in a grid.
|
||||
SpringLayout.Constraints lastCons = null;
|
||||
SpringLayout.Constraints lastRowCons = null;
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
|
||||
if ((i % cols) == 0)
|
||||
{ // start of new row
|
||||
lastRowCons = lastCons;
|
||||
cons.setX(initialXSpring);
|
||||
}
|
||||
else
|
||||
{
|
||||
// x position depends on previous component
|
||||
if (lastCons != null)
|
||||
{
|
||||
cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST), xPadSpring));
|
||||
}
|
||||
}
|
||||
|
||||
if ((i / cols) == 0)
|
||||
{
|
||||
// first row
|
||||
cons.setY(initialYSpring);
|
||||
}
|
||||
else
|
||||
{
|
||||
// y position depends on previous row
|
||||
if (lastRowCons != null)
|
||||
{
|
||||
cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH), yPadSpring));
|
||||
}
|
||||
}
|
||||
lastCons = cons;
|
||||
}
|
||||
|
||||
// Set the parent's size.
|
||||
SpringLayout.Constraints pCons = layout.getConstraints(parent);
|
||||
if (lastCons != null)
|
||||
{
|
||||
pCons.setConstraint(SpringLayout.SOUTH, Spring.sum(Spring.constant(yPad), lastCons.getConstraint(SpringLayout.SOUTH)));
|
||||
pCons.setConstraint(SpringLayout.EAST, Spring.sum(Spring.constant(xPad), lastCons.getConstraint(SpringLayout.EAST)));
|
||||
}
|
||||
}
|
||||
|
||||
/* Used by makeCompactGrid. */
|
||||
private static SpringLayout.Constraints getConstraintsForCell(int row, int col, Container parent, int cols)
|
||||
{
|
||||
SpringLayout layout = (SpringLayout) parent.getLayout();
|
||||
Component c = parent.getComponent((row * cols) + col);
|
||||
return layout.getConstraints(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aligns the first <code>rows</code> * <code>cols</code> components of <code>parent</code> in a grid. Each component in a column is as wide as the maximum preferred width of the components in that column; height is similarly determined for each row. The parent is made just big enough to fit
|
||||
* them all.
|
||||
* @param parent
|
||||
* @param rows number of rows
|
||||
* @param cols number of columns
|
||||
* @param initialX x location to start the grid at
|
||||
* @param initialY y location to start the grid at
|
||||
* @param xPad x padding between cells
|
||||
* @param yPad y padding between cells
|
||||
*/
|
||||
public static void makeCompactGrid(Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad)
|
||||
{
|
||||
SpringLayout layout;
|
||||
try
|
||||
{
|
||||
layout = (SpringLayout) parent.getLayout();
|
||||
}
|
||||
catch (ClassCastException exc)
|
||||
{
|
||||
System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Align all cells in each column and make them the same width.
|
||||
Spring x = Spring.constant(initialX);
|
||||
for (int c = 0; c < cols; c++)
|
||||
{
|
||||
Spring width = Spring.constant(0);
|
||||
for (int r = 0; r < rows; r++)
|
||||
{
|
||||
width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
|
||||
}
|
||||
for (int r = 0; r < rows; r++)
|
||||
{
|
||||
SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
|
||||
constraints.setX(x);
|
||||
constraints.setWidth(width);
|
||||
}
|
||||
x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
|
||||
}
|
||||
|
||||
// Align all cells in each row and make them the same height.
|
||||
Spring y = Spring.constant(initialY);
|
||||
for (int r = 0; r < rows; r++)
|
||||
{
|
||||
Spring height = Spring.constant(0);
|
||||
for (int c = 0; c < cols; c++)
|
||||
{
|
||||
height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
|
||||
}
|
||||
for (int c = 0; c < cols; c++)
|
||||
{
|
||||
SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
|
||||
constraints.setY(y);
|
||||
constraints.setHeight(height);
|
||||
}
|
||||
y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
|
||||
}
|
||||
|
||||
// Set the parent's size.
|
||||
SpringLayout.Constraints pCons = layout.getConstraints(parent);
|
||||
pCons.setConstraint(SpringLayout.SOUTH, y);
|
||||
pCons.setConstraint(SpringLayout.EAST, x);
|
||||
}
|
||||
}
|
@ -18,7 +18,6 @@
|
||||
*/
|
||||
package com.l2jserver.tools.gsregistering;
|
||||
|
||||
import java.awt.HeadlessException;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -28,19 +27,14 @@ import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.L2DatabaseFactory;
|
||||
import com.l2jserver.Server;
|
||||
import com.l2jserver.loginserver.GameServerTable;
|
||||
import com.l2jserver.tools.i18n.LanguageControl;
|
||||
import com.l2jserver.util.Util;
|
||||
|
||||
/**
|
||||
@ -50,7 +44,6 @@ import com.l2jserver.util.Util;
|
||||
public abstract class BaseGameServerRegister
|
||||
{
|
||||
private boolean _loaded = false;
|
||||
private ResourceBundle _bundle;
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
@ -58,221 +51,7 @@ public abstract class BaseGameServerRegister
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Locale locale = null;
|
||||
boolean gui = true;
|
||||
boolean interactive = true;
|
||||
boolean force = false;
|
||||
boolean fallback = false;
|
||||
BaseTask task = null;
|
||||
|
||||
ResourceBundle bundle = null;
|
||||
try
|
||||
{
|
||||
locale = Locale.getDefault();
|
||||
bundle = ResourceBundle.getBundle("gsregister.GSRegister", locale, LanguageControl.INSTANCE);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
System.out.println("FATAL: Failed to load default translation.");
|
||||
System.exit(666);
|
||||
}
|
||||
|
||||
String arg;
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
arg = args[i];
|
||||
|
||||
// --cmd : no gui
|
||||
if (arg.equals("-c") || arg.equals("--cmd"))
|
||||
{
|
||||
gui = false;
|
||||
}
|
||||
// --force : Forces GameServer register operations to overwrite a server if necessary
|
||||
else if (arg.equals("-f") || arg.equals("--force"))
|
||||
{
|
||||
force = true;
|
||||
}
|
||||
// --fallback : If an register operation fails due to ID already being in use it will then try to register first available ID
|
||||
else if (arg.equals("-b") || arg.equals("--fallback"))
|
||||
{
|
||||
fallback = true;
|
||||
}
|
||||
// --register <id> <hexid_dest_dir> : Register GameServer with ID <id> and output hexid on <hexid_dest_dir>
|
||||
// Fails if <id> already in use, unless -force is used (overwrites)
|
||||
else if (arg.equals("-r") || arg.equals("--register"))
|
||||
{
|
||||
gui = false;
|
||||
interactive = false;
|
||||
int id = Integer.parseInt(args[++i]);
|
||||
String dir = args[++i];
|
||||
|
||||
task = new RegisterTask(id, dir, force, fallback);
|
||||
}
|
||||
// --unregister <id> : Removes GameServer denoted by <id>
|
||||
else if (arg.equals("-u") || arg.equals("--unregister"))
|
||||
{
|
||||
gui = false;
|
||||
interactive = false;
|
||||
String gsId = args[++i];
|
||||
if (gsId.equalsIgnoreCase("all"))
|
||||
{
|
||||
task = new UnregisterAllTask();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
int id = Integer.parseInt(gsId);
|
||||
task = new UnregisterTask(id);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
if (bundle != null)
|
||||
{
|
||||
System.out.printf(bundle.getString("wrongUnregisterArg") + Config.EOL, gsId);
|
||||
}
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
// --language <locale> : Sets the app to use the specified locale, overriding auto-detection
|
||||
else if (arg.equals("-l") || arg.equals("--language"))
|
||||
{
|
||||
String loc = args[++i];
|
||||
Locale[] availableLocales = Locale.getAvailableLocales();
|
||||
Locale l;
|
||||
for (int j = 0; (j < availableLocales.length) && (locale == null); j++)
|
||||
{
|
||||
l = availableLocales[j];
|
||||
if (l.toString().equals(loc))
|
||||
{
|
||||
locale = l;
|
||||
}
|
||||
}
|
||||
if (locale == null)
|
||||
{
|
||||
System.out.println("Specified locale '" + loc + "' was not found, using default behaviour.");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
bundle = ResourceBundle.getBundle("gsregister.GSRegister", locale, LanguageControl.INSTANCE);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
System.out.println("Failed to load translation ''");
|
||||
}
|
||||
}
|
||||
}
|
||||
// --help : Prints usage/arguments/credits
|
||||
else if (arg.equals("-h") || arg.equals("--help"))
|
||||
{
|
||||
gui = false;
|
||||
interactive = false;
|
||||
|
||||
BaseGameServerRegister.printHelp(bundle);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (gui)
|
||||
{
|
||||
BaseGameServerRegister.startGUI(bundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (interactive)
|
||||
{
|
||||
BaseGameServerRegister.startCMD(bundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
// if there is a task, do it, else the app has already finished
|
||||
if (task != null)
|
||||
{
|
||||
task.setBundle(bundle);
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (HeadlessException e)
|
||||
{
|
||||
BaseGameServerRegister.startCMD(bundle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the help.
|
||||
* @param bundle the bundle
|
||||
*/
|
||||
private static void printHelp(ResourceBundle bundle)
|
||||
{
|
||||
String[] help =
|
||||
{
|
||||
bundle.getString("purpose"),
|
||||
"",
|
||||
bundle.getString("options"),
|
||||
"-b, --fallback\t\t\t\t" + bundle.getString("fallbackOpt"),
|
||||
"-c, --cmd\t\t\t\t" + bundle.getString("cmdOpt"),
|
||||
"-f, --force\t\t\t\t" + bundle.getString("forceOpt"),
|
||||
"-h, --help\t\t\t\t" + bundle.getString("helpOpt"),
|
||||
"-l, --language\t\t\t\t" + bundle.getString("languageOpt"),
|
||||
"-r, --register <id> <hexid_dest_dir>\t" + bundle.getString("registerOpt1"),
|
||||
"\t\t\t\t\t" + bundle.getString("registerOpt2"),
|
||||
"\t\t\t\t\t" + bundle.getString("registerOpt3"),
|
||||
"",
|
||||
"-u, --unregister <id>|all\t\t" + bundle.getString("unregisterOpt"),
|
||||
"",
|
||||
bundle.getString("credits"),
|
||||
bundle.getString("bugReports") + " http://www.l2jserver.com"
|
||||
|
||||
/*
|
||||
* "-b, --fallback\t\t\t\tIf an register operation fails due to ID already being in use it will then try to register first available ID", "-c, --cmd\t\t\t\tForces application to run in command-line mode even if the GUI is supported.",
|
||||
* "-f, --force\t\t\t\tForces GameServer register operations to overwrite a server if necessary", "-h, --help\t\t\t\tPrints this help message", "-l, --language <locale>\t\t\t\tAsks the application to use the specified locale, overriding auto-detection",
|
||||
* "-r, --register <id> <hexid_dest_dir>\tRegister GameServer with ID <id> and output hexid on <hexid_dest_dir>", "\t\t\t\t\tUse a negative value on <id> to register the first available ID", "\t\t\t\t\tFails if <id> already in use, unless --force is used (overwrites)", "",
|
||||
* "-u, --unregister <id>|all\t\tRemoves GameServer denoted by <id>, use \"all\" for removing all registered GameServers", "", "Copyright (C) L2J Team 2008-2012.", "Report bugs: http://www.l2jserver.com"
|
||||
*/
|
||||
};
|
||||
|
||||
for (String str : help)
|
||||
{
|
||||
System.out.println(str);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the GUI.
|
||||
* @param bundle the bundle.
|
||||
*/
|
||||
private static void startGUI(final ResourceBundle bundle)
|
||||
{
|
||||
try
|
||||
{
|
||||
// avoid that ugly Metal LaF
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// couldn't care less
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(() ->
|
||||
{
|
||||
GUserInterface gui = new GUserInterface(bundle);
|
||||
gui.getFrame().setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the CMD.
|
||||
* @param bundle the bundle.
|
||||
*/
|
||||
private static void startCMD(final ResourceBundle bundle)
|
||||
{
|
||||
GameServerRegister cmdUi = new GameServerRegister(bundle);
|
||||
GameServerRegister cmdUi = new GameServerRegister();
|
||||
try
|
||||
{
|
||||
cmdUi.consoleUI();
|
||||
@ -283,15 +62,6 @@ public abstract class BaseGameServerRegister
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new base game server register.
|
||||
* @param bundle the bundle.
|
||||
*/
|
||||
public BaseGameServerRegister(ResourceBundle bundle)
|
||||
{
|
||||
setBundle(bundle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load.
|
||||
*/
|
||||
@ -314,24 +84,6 @@ public abstract class BaseGameServerRegister
|
||||
return _loaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bundle.
|
||||
* @param bundle the bundle to set.
|
||||
*/
|
||||
public void setBundle(ResourceBundle bundle)
|
||||
{
|
||||
_bundle = bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bundle.
|
||||
* @return the bundle.
|
||||
*/
|
||||
public ResourceBundle getBundle()
|
||||
{
|
||||
return _bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the error.
|
||||
* @param msg the msg.
|
||||
@ -459,143 +211,6 @@ public abstract class BaseGameServerRegister
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class RegisterTask.
|
||||
*/
|
||||
private static class RegisterTask extends BaseTask
|
||||
{
|
||||
private final int _id;
|
||||
private final String _outDir;
|
||||
private boolean _force;
|
||||
private boolean _fallback;
|
||||
|
||||
/**
|
||||
* Instantiates a new register task.
|
||||
* @param id the id.
|
||||
* @param outDir the out dir.
|
||||
* @param force the force.
|
||||
* @param fallback the fallback.
|
||||
*/
|
||||
public RegisterTask(int id, String outDir, boolean force, boolean fallback)
|
||||
{
|
||||
_id = id;
|
||||
_outDir = outDir;
|
||||
_force = force;
|
||||
_fallback = fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the actions.
|
||||
* @param force the force.
|
||||
* @param fallback the fallback.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public void setActions(boolean force, boolean fallback)
|
||||
{
|
||||
_force = force;
|
||||
_fallback = fallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_id < 0)
|
||||
{
|
||||
int registeredId = BaseGameServerRegister.registerFirstAvailable(_outDir);
|
||||
|
||||
if (registeredId < 0)
|
||||
{
|
||||
System.out.println(getBundle().getString("noFreeId"));
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.printf(getBundle().getString("registrationOk") + Config.EOL, registeredId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.printf(getBundle().getString("checkingIdInUse") + Config.EOL, _id);
|
||||
if (GameServerTable.getInstance().hasRegisteredGameServerOnId(_id))
|
||||
{
|
||||
System.out.println(getBundle().getString("yes"));
|
||||
if (_force)
|
||||
{
|
||||
System.out.printf(getBundle().getString("forcingRegistration") + Config.EOL, _id);
|
||||
BaseGameServerRegister.unregisterGameServer(_id);
|
||||
BaseGameServerRegister.registerGameServer(_id, _outDir);
|
||||
System.out.printf(getBundle().getString("registrationOk") + Config.EOL, _id);
|
||||
}
|
||||
else if (_fallback)
|
||||
{
|
||||
System.out.println(getBundle().getString("fallingBack"));
|
||||
int registeredId = BaseGameServerRegister.registerFirstAvailable(_outDir);
|
||||
|
||||
if (registeredId < 0)
|
||||
{
|
||||
System.out.println(getBundle().getString("noFreeId"));
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.printf(getBundle().getString("registrationOk") + Config.EOL, registeredId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(getBundle().getString("noAction"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(getBundle().getString("no"));
|
||||
BaseGameServerRegister.registerGameServer(_id, _outDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
showError(getBundle().getString("sqlErrorRegister"), e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
showError(getBundle().getString("ioErrorRegister"), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class UnregisterTask.
|
||||
*/
|
||||
private static class UnregisterTask extends BaseTask
|
||||
{
|
||||
private final int _id;
|
||||
|
||||
/**
|
||||
* Instantiates a new unregister task.
|
||||
* @param id the task id.
|
||||
*/
|
||||
public UnregisterTask(int id)
|
||||
{
|
||||
_id = id;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
System.out.printf(getBundle().getString("removingGsId") + Config.EOL, _id);
|
||||
try
|
||||
{
|
||||
BaseGameServerRegister.unregisterGameServer(_id);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
showError(getBundle().getString("sqlErrorRegister"), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class UnregisterAllTask.
|
||||
*/
|
||||
|
@ -1,387 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.gsregistering;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.loginserver.GameServerTable;
|
||||
import com.l2jserver.tools.images.ImagesTable;
|
||||
|
||||
/**
|
||||
* @author KenM
|
||||
*/
|
||||
public class GUserInterface extends BaseGameServerRegister implements ActionListener
|
||||
{
|
||||
private final JFrame _frame;
|
||||
private final JTableModel _dtm;
|
||||
protected final JProgressBar _progressBar;
|
||||
|
||||
public JTable _gsTable;
|
||||
|
||||
public GUserInterface(ResourceBundle bundle)
|
||||
{
|
||||
super(bundle);
|
||||
|
||||
_frame = new JFrame();
|
||||
getFrame().setTitle(getBundle().getString("toolName"));
|
||||
getFrame().setSize(600, 400);
|
||||
getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
getFrame().setLayout(new GridBagLayout());
|
||||
GridBagConstraints cons = new GridBagConstraints();
|
||||
|
||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||
getFrame().setIconImage(ImagesTable.getImage("l2j.png").getImage());
|
||||
|
||||
JMenuBar menubar = new JMenuBar();
|
||||
getFrame().setJMenuBar(menubar);
|
||||
|
||||
JMenu fileMenu = new JMenu(getBundle().getString("fileMenu"));
|
||||
|
||||
JMenuItem exitItem = new JMenuItem(getBundle().getString("exitItem"));
|
||||
exitItem.addActionListener(this);
|
||||
exitItem.setActionCommand("exit");
|
||||
|
||||
fileMenu.add(exitItem);
|
||||
|
||||
JMenu helpMenu = new JMenu(getBundle().getString("helpMenu"));
|
||||
|
||||
JMenuItem aboutItem = new JMenuItem(getBundle().getString("aboutItem"));
|
||||
aboutItem.addActionListener(this);
|
||||
aboutItem.setActionCommand("about");
|
||||
|
||||
helpMenu.add(aboutItem);
|
||||
|
||||
menubar.add(fileMenu);
|
||||
menubar.add(helpMenu);
|
||||
|
||||
JButton btnRegister = new JButton(getBundle().getString("btnRegister"), ImagesTable.getImage("add.png"));
|
||||
btnRegister.addActionListener(this);
|
||||
btnRegister.setActionCommand("register");
|
||||
getFrame().add(btnRegister, cons);
|
||||
|
||||
cons.gridx = 1;
|
||||
cons.anchor = GridBagConstraints.LINE_END;
|
||||
JButton btnRemoveAll = new JButton(getBundle().getString("btnRemoveAll"), ImagesTable.getImage("cross.png"));
|
||||
btnRemoveAll.addActionListener(this);
|
||||
btnRemoveAll.setActionCommand("removeAll");
|
||||
getFrame().add(btnRemoveAll, cons);
|
||||
|
||||
String name = getBundle().getString("gsName");
|
||||
String action = getBundle().getString("gsAction");
|
||||
|
||||
_dtm = new JTableModel(new Object[]
|
||||
{
|
||||
"ID",
|
||||
name,
|
||||
action
|
||||
});
|
||||
_gsTable = new JTable(_dtm);
|
||||
_gsTable.addMouseListener(new JTableButtonMouseListener(_gsTable));
|
||||
|
||||
_gsTable.getColumnModel().getColumn(0).setMaxWidth(30);
|
||||
|
||||
TableColumn actionCollumn = _gsTable.getColumnModel().getColumn(2);
|
||||
actionCollumn.setCellRenderer(new ButtonCellRenderer());
|
||||
|
||||
cons.fill = GridBagConstraints.BOTH;
|
||||
cons.gridx = 0;
|
||||
cons.gridy = 1;
|
||||
cons.weighty = 1.0;
|
||||
cons.weightx = 1.0;
|
||||
cons.gridwidth = 2;
|
||||
JLayeredPane layer = new JLayeredPane();
|
||||
layer.setLayout(new BoxLayout(layer, BoxLayout.PAGE_AXIS));
|
||||
layer.add(new JScrollPane(_gsTable), 0);
|
||||
_progressBar = new JProgressBar();
|
||||
_progressBar.setIndeterminate(true);
|
||||
_progressBar.setVisible(false);
|
||||
layer.add(_progressBar, BorderLayout.CENTER, 1);
|
||||
// layer.setV
|
||||
getFrame().add(layer, cons);
|
||||
|
||||
refreshAsync();
|
||||
}
|
||||
|
||||
public void refreshAsync()
|
||||
{
|
||||
Thread t = new Thread(() -> GUserInterface.this.refreshServers(), "LoaderThread");
|
||||
t.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load()
|
||||
{
|
||||
SwingUtilities.invokeLater(() -> _progressBar.setVisible(true));
|
||||
|
||||
super.load();
|
||||
|
||||
SwingUtilities.invokeLater(() -> _progressBar.setVisible(false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(String msg, Throwable t)
|
||||
{
|
||||
String title;
|
||||
if (getBundle() != null)
|
||||
{
|
||||
title = getBundle().getString("error");
|
||||
msg += Config.EOL + getBundle().getString("reason") + ' ' + t.getLocalizedMessage();
|
||||
}
|
||||
else
|
||||
{
|
||||
title = "Error";
|
||||
msg += Config.EOL + "Cause: " + t.getLocalizedMessage();
|
||||
}
|
||||
JOptionPane.showMessageDialog(getFrame(), msg, title, JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
protected void refreshServers()
|
||||
{
|
||||
if (!isLoaded())
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
// load succeeded?
|
||||
if (isLoaded())
|
||||
{
|
||||
SwingUtilities.invokeLater(() ->
|
||||
{
|
||||
int size = GameServerTable.getInstance().getServerNames().size();
|
||||
if (size == 0)
|
||||
{
|
||||
String title = getBundle().getString("error");
|
||||
String msg = getBundle().getString("noServerNames");
|
||||
JOptionPane.showMessageDialog(getFrame(), msg, title, JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(1);
|
||||
}
|
||||
// reset
|
||||
_dtm.setRowCount(0);
|
||||
|
||||
for (final int id : GameServerTable.getInstance().getRegisteredGameServers().keySet())
|
||||
{
|
||||
String name = GameServerTable.getInstance().getServerNameById(id);
|
||||
JButton button = new JButton(getBundle().getString("btnRemove"), ImagesTable.getImage("cross.png"));
|
||||
button.addActionListener(e ->
|
||||
{
|
||||
String sid = String.valueOf(id);
|
||||
String sname = GameServerTable.getInstance().getServerNameById(id);
|
||||
|
||||
int choice = JOptionPane.showConfirmDialog(getFrame(), getBundle().getString("confirmRemoveText").replace("%d", sid).replace("%s", sname), getBundle().getString("confirmRemoveTitle"), JOptionPane.YES_NO_OPTION);
|
||||
if (choice == JOptionPane.YES_OPTION)
|
||||
{
|
||||
try
|
||||
{
|
||||
BaseGameServerRegister.unregisterGameServer(id);
|
||||
GUserInterface.this.refreshAsync();
|
||||
}
|
||||
catch (SQLException e1)
|
||||
{
|
||||
GUserInterface.this.showError(getBundle().getString("errorUnregister"), e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
_dtm.addRow(new Object[]
|
||||
{
|
||||
id,
|
||||
name,
|
||||
button
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
String cmd = e.getActionCommand();
|
||||
|
||||
if (cmd.equals("register"))
|
||||
{
|
||||
RegisterDialog rd = new RegisterDialog(this);
|
||||
rd.setVisible(true);
|
||||
}
|
||||
else if (cmd.equals("exit"))
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
else if (cmd.equals("about"))
|
||||
{
|
||||
JOptionPane.showMessageDialog(getFrame(), getBundle().getString("credits") + Config.EOL + "http://www.l2jserver.com" + Config.EOL + Config.EOL + getBundle().getString("icons") + Config.EOL + Config.EOL + getBundle().getString("langText") + Config.EOL + getBundle().getString("translation"), getBundle().getString("aboutItem"), JOptionPane.INFORMATION_MESSAGE, ImagesTable.getImage("l2jserverlogo.png"));
|
||||
}
|
||||
else if (cmd.equals("removeAll"))
|
||||
{
|
||||
int choice = JOptionPane.showConfirmDialog(getFrame(), getBundle().getString("confirmRemoveAllText"), getBundle().getString("confirmRemoveTitle"), JOptionPane.YES_NO_OPTION);
|
||||
if (choice == JOptionPane.YES_OPTION)
|
||||
{
|
||||
try
|
||||
{
|
||||
BaseGameServerRegister.unregisterAllGameServers();
|
||||
refreshAsync();
|
||||
}
|
||||
catch (SQLException e1)
|
||||
{
|
||||
GUserInterface.this.showError(getBundle().getString("errorUnregister"), e1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the frame.
|
||||
*/
|
||||
public JFrame getFrame()
|
||||
{
|
||||
return _frame;
|
||||
}
|
||||
|
||||
protected class ButtonCellRenderer implements TableCellRenderer
|
||||
{
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
|
||||
{
|
||||
return (Component) value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward mouse-events from table to buttons inside.<br>
|
||||
* Buttons animate properly.
|
||||
* @author KenM
|
||||
*/
|
||||
private class JTableButtonMouseListener implements MouseListener
|
||||
{
|
||||
private final JTable _table;
|
||||
|
||||
public JTableButtonMouseListener(JTable table)
|
||||
{
|
||||
_table = table;
|
||||
}
|
||||
|
||||
private void forwardEvent(MouseEvent e)
|
||||
{
|
||||
TableColumnModel columnModel = _table.getColumnModel();
|
||||
int column = columnModel.getColumnIndexAtX(e.getX());
|
||||
int row = e.getY() / _table.getRowHeight();
|
||||
Object value;
|
||||
|
||||
if ((row >= _table.getRowCount()) || (row < 0) || (column >= _table.getColumnCount()) || (column < 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
value = _table.getValueAt(row, column);
|
||||
|
||||
if (value instanceof JButton)
|
||||
{
|
||||
final JButton b = (JButton) value;
|
||||
if (e.getID() == MouseEvent.MOUSE_PRESSED)
|
||||
{
|
||||
b.getModel().setPressed(true);
|
||||
b.getModel().setArmed(true);
|
||||
_table.repaint();
|
||||
}
|
||||
else if (e.getID() == MouseEvent.MOUSE_RELEASED)
|
||||
{
|
||||
b.doClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e)
|
||||
{
|
||||
forwardEvent(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e)
|
||||
{
|
||||
forwardEvent(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e)
|
||||
{
|
||||
forwardEvent(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
forwardEvent(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e)
|
||||
{
|
||||
forwardEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
private class JTableModel extends DefaultTableModel
|
||||
{
|
||||
private static final long serialVersionUID = -5907903982876753479L;
|
||||
|
||||
public JTableModel(Object[] columnNames)
|
||||
{
|
||||
super(columnNames, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int column)
|
||||
{
|
||||
return getValueAt(0, column).getClass();
|
||||
}
|
||||
}
|
||||
}
|
@ -23,7 +23,6 @@ import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.loginserver.GameServerTable;
|
||||
@ -38,18 +37,15 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
BaseGameServerRegister.main(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bundle
|
||||
*/
|
||||
public GameServerRegister(ResourceBundle bundle)
|
||||
public GameServerRegister()
|
||||
{
|
||||
super(bundle);
|
||||
super();
|
||||
load();
|
||||
|
||||
int size = GameServerTable.getInstance().getServerNames().size();
|
||||
if (size == 0)
|
||||
{
|
||||
System.out.println(getBundle().getString("noServerNames"));
|
||||
System.out.println("No available names for GameServer, verify servername.xml file exists in the LoginServer folder.");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
@ -65,15 +61,15 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
hr();
|
||||
System.out.println("GSRegister");
|
||||
System.out.println(Config.EOL);
|
||||
System.out.println("1 - " + getBundle().getString("cmdMenuRegister"));
|
||||
System.out.println("2 - " + getBundle().getString("cmdMenuListNames"));
|
||||
System.out.println("3 - " + getBundle().getString("cmdMenuRemoveGS"));
|
||||
System.out.println("4 - " + getBundle().getString("cmdMenuRemoveAll"));
|
||||
System.out.println("5 - " + getBundle().getString("cmdMenuExit"));
|
||||
System.out.println("1 - Register GameServer");
|
||||
System.out.println("2 - List GameServers Names and IDs");
|
||||
System.out.println("3 - Remove GameServer");
|
||||
System.out.println("4 - Remove ALL GameServers");
|
||||
System.out.println("5 - Exit");
|
||||
|
||||
do
|
||||
{
|
||||
System.out.print(getBundle().getString("yourChoice") + ' ');
|
||||
System.out.print("Choice: ");
|
||||
choice = _in.readLine();
|
||||
try
|
||||
{
|
||||
@ -98,14 +94,14 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
System.exit(0);
|
||||
break;
|
||||
default:
|
||||
System.out.printf(getBundle().getString("invalidChoice") + Config.EOL, choice);
|
||||
System.out.printf("Invalid Choice: %s" + Config.EOL, choice);
|
||||
choiceOk = false;
|
||||
}
|
||||
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
System.out.printf(getBundle().getString("invalidChoice") + Config.EOL, choice);
|
||||
System.out.printf("Invalid Choice: %s" + Config.EOL, choice);
|
||||
}
|
||||
}
|
||||
while (!choiceOk);
|
||||
@ -143,8 +139,8 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
|
||||
String id;
|
||||
boolean inUse;
|
||||
String gsInUse = getBundle().getString("gsInUse");
|
||||
String gsFree = getBundle().getString("gsFree");
|
||||
String gsInUse = "In Use";
|
||||
String gsFree = "Free";
|
||||
int gsStatusMaxLen = Math.max(gsInUse.length(), gsFree.length()) + 2;
|
||||
for (Entry<Integer, String> e : GameServerTable.getInstance().getServerNames().entrySet())
|
||||
{
|
||||
@ -182,16 +178,16 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
*/
|
||||
private void unregisterAllGS() throws IOException
|
||||
{
|
||||
if (yesNoQuestion(getBundle().getString("confirmRemoveAllText")))
|
||||
if (yesNoQuestion("Are you sure you want to remove ALL GameServers?"))
|
||||
{
|
||||
try
|
||||
{
|
||||
BaseGameServerRegister.unregisterAllGameServers();
|
||||
System.out.println(getBundle().getString("unregisterAllOk"));
|
||||
System.out.println("All GameServers were successfully removed.");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
showError(getBundle().getString("sqlErrorUnregisterAll"), e);
|
||||
showError("An SQL error occurred while trying to remove ALL GameServers.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -203,9 +199,9 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
{
|
||||
hr();
|
||||
System.out.println(question);
|
||||
System.out.println("1 - " + getBundle().getString("yes"));
|
||||
System.out.println("2 - " + getBundle().getString("no"));
|
||||
System.out.print(getBundle().getString("yourChoice") + ' ');
|
||||
System.out.println("1 - Yes");
|
||||
System.out.println("2 - No");
|
||||
System.out.print("Choice: ");
|
||||
String choice;
|
||||
choice = _in.readLine();
|
||||
if (choice != null)
|
||||
@ -220,7 +216,7 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.printf(getBundle().getString("invalidChoice") + Config.EOL, choice);
|
||||
System.out.printf("Invalid Choice: %s" + Config.EOL, choice);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -237,7 +233,7 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
|
||||
do
|
||||
{
|
||||
System.out.print(getBundle().getString("enterDesiredId") + ' ');
|
||||
System.out.print("Enter desired ID: ");
|
||||
line = _in.readLine();
|
||||
try
|
||||
{
|
||||
@ -245,7 +241,7 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
System.out.printf(getBundle().getString("invalidChoice") + Config.EOL, line);
|
||||
System.out.printf("Invalid Choice: %s" + Config.EOL, line);
|
||||
}
|
||||
}
|
||||
while (id == Integer.MIN_VALUE);
|
||||
@ -253,27 +249,27 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
String name = GameServerTable.getInstance().getServerNameById(id);
|
||||
if (name == null)
|
||||
{
|
||||
System.out.printf(getBundle().getString("noNameForId") + Config.EOL, id);
|
||||
System.out.printf("No name for ID: %d" + Config.EOL, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GameServerTable.getInstance().hasRegisteredGameServerOnId(id))
|
||||
{
|
||||
System.out.printf(getBundle().getString("confirmRemoveText") + Config.EOL, id, name);
|
||||
System.out.printf("Are you sure you want to remove GameServer %d - %s?" + Config.EOL, id, name);
|
||||
try
|
||||
{
|
||||
BaseGameServerRegister.unregisterGameServer(id);
|
||||
System.out.printf(getBundle().getString("unregisterOk") + Config.EOL, id);
|
||||
System.out.printf("GameServer ID: %d was successfully removed from LoginServer." + Config.EOL, id);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
showError(getBundle().getString("sqlErrorUnregister"), e);
|
||||
showError("An SQL error occurred while trying to remove the GameServer.", e);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.printf(getBundle().getString("noServerForId") + Config.EOL, id);
|
||||
System.out.printf("No GameServer is registered on ID: %d" + Config.EOL, id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -286,7 +282,7 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
|
||||
do
|
||||
{
|
||||
System.out.println(getBundle().getString("enterDesiredId"));
|
||||
System.out.println("Enter desired ID:");
|
||||
line = _in.readLine();
|
||||
try
|
||||
{
|
||||
@ -294,7 +290,7 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
System.out.printf(getBundle().getString("invalidChoice") + Config.EOL, line);
|
||||
System.out.printf("Invalid Choice: %s" + Config.EOL, line);
|
||||
}
|
||||
}
|
||||
while (id == Integer.MIN_VALUE);
|
||||
@ -302,13 +298,13 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
String name = GameServerTable.getInstance().getServerNameById(id);
|
||||
if (name == null)
|
||||
{
|
||||
System.out.printf(getBundle().getString("noNameForId") + Config.EOL, id);
|
||||
System.out.printf("No name for ID: %d" + Config.EOL, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GameServerTable.getInstance().hasRegisteredGameServerOnId(id))
|
||||
{
|
||||
System.out.println(getBundle().getString("idIsNotFree"));
|
||||
System.out.println("This ID is not available.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -318,7 +314,7 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
showError(getBundle().getString("ioErrorRegister"), e);
|
||||
showError("An error saving the hexid file occurred while trying to register the GameServer.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -328,16 +324,8 @@ public class GameServerRegister extends BaseGameServerRegister
|
||||
public void showError(String msg, Throwable t)
|
||||
{
|
||||
String title;
|
||||
if (getBundle() != null)
|
||||
{
|
||||
title = getBundle().getString("error");
|
||||
msg += Config.EOL + getBundle().getString("reason") + ' ' + t.getLocalizedMessage();
|
||||
}
|
||||
else
|
||||
{
|
||||
title = "Error";
|
||||
msg += Config.EOL + "Cause: " + t.getLocalizedMessage();
|
||||
}
|
||||
title = "Error";
|
||||
msg += Config.EOL + "Reason: " + t.getLocalizedMessage();
|
||||
System.out.println(title + ": " + msg);
|
||||
}
|
||||
}
|
@ -1,199 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.gsregistering;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextPane;
|
||||
import javax.swing.WindowConstants;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import com.l2jserver.loginserver.GameServerTable;
|
||||
|
||||
/**
|
||||
* @author KenM
|
||||
*/
|
||||
public class RegisterDialog extends JDialog implements ActionListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final ResourceBundle _bundle;
|
||||
private final JComboBox<ComboServer> _combo;
|
||||
private final GUserInterface _owner;
|
||||
|
||||
public RegisterDialog(final GUserInterface owner)
|
||||
{
|
||||
super(owner.getFrame(), true);
|
||||
_owner = owner;
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
_bundle = owner.getBundle();
|
||||
setTitle(_bundle.getString("registerGS"));
|
||||
setResizable(false);
|
||||
setLayout(new GridBagLayout());
|
||||
GridBagConstraints cons = new GridBagConstraints();
|
||||
cons.weightx = 0.5;
|
||||
cons.weighty = 0.5;
|
||||
cons.gridx = 0;
|
||||
cons.gridy = 0;
|
||||
cons.fill = GridBagConstraints.BOTH;
|
||||
|
||||
final JLabel label = new JLabel(_bundle.getString("serverName"));
|
||||
this.add(label, cons);
|
||||
|
||||
_combo = new JComboBox<>();
|
||||
_combo.setEditable(false);
|
||||
for (Map.Entry<Integer, String> entry : GameServerTable.getInstance().getServerNames().entrySet())
|
||||
{
|
||||
if (!GameServerTable.getInstance().hasRegisteredGameServerOnId(entry.getKey()))
|
||||
{
|
||||
_combo.addItem(new ComboServer(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
}
|
||||
cons.gridx = 1;
|
||||
cons.gridy = 0;
|
||||
this.add(_combo, cons);
|
||||
|
||||
cons.gridx = 0;
|
||||
cons.gridy = 1;
|
||||
cons.gridwidth = 2;
|
||||
JTextPane textPane = new JTextPane();
|
||||
textPane.setText(_bundle.getString("saveHexId"));
|
||||
textPane.setEditable(false);
|
||||
textPane.setBackground(label.getBackground());
|
||||
this.add(textPane, cons);
|
||||
cons.gridwidth = 1;
|
||||
|
||||
JButton btnSave = new JButton(_bundle.getString("save"));
|
||||
btnSave.setActionCommand("save");
|
||||
btnSave.addActionListener(this);
|
||||
cons.gridx = 0;
|
||||
cons.gridy = 2;
|
||||
this.add(btnSave, cons);
|
||||
|
||||
JButton btnCancel = new JButton(_bundle.getString("cancel"));
|
||||
btnCancel.setActionCommand("cancel");
|
||||
btnCancel.addActionListener(this);
|
||||
cons.gridx = 1;
|
||||
cons.gridy = 2;
|
||||
this.add(btnCancel, cons);
|
||||
|
||||
final double leftSize = Math.max(label.getPreferredSize().getWidth(), btnSave.getPreferredSize().getWidth());
|
||||
final double rightSize = Math.max(_combo.getPreferredSize().getWidth(), btnCancel.getPreferredSize().getWidth());
|
||||
|
||||
final double height = _combo.getPreferredSize().getHeight() + (4 * textPane.getPreferredSize().getHeight()) + btnSave.getPreferredSize().getHeight();
|
||||
this.setSize((int) (leftSize + rightSize + 30), (int) (height + 20));
|
||||
|
||||
setLocationRelativeTo(owner.getFrame());
|
||||
}
|
||||
|
||||
class ComboServer
|
||||
{
|
||||
private final int _id;
|
||||
private final String _name;
|
||||
|
||||
public ComboServer(int id, String name)
|
||||
{
|
||||
_id = id;
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the id.
|
||||
*/
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
String cmd = e.getActionCommand();
|
||||
|
||||
if (cmd.equals("save"))
|
||||
{
|
||||
ComboServer server = (ComboServer) _combo.getSelectedItem();
|
||||
int gsId = server.getId();
|
||||
|
||||
JFileChooser fc = new JFileChooser();
|
||||
// fc.setS
|
||||
fc.setDialogTitle(_bundle.getString("hexidDest"));
|
||||
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
fc.setFileFilter(new FileFilter()
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean accept(File f)
|
||||
{
|
||||
return f.isDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
fc.showOpenDialog(this);
|
||||
|
||||
try
|
||||
{
|
||||
BaseGameServerRegister.registerGameServer(gsId, fc.getSelectedFile().getAbsolutePath());
|
||||
_owner.refreshAsync();
|
||||
setVisible(false);
|
||||
}
|
||||
catch (IOException e1)
|
||||
{
|
||||
_owner.showError(_bundle.getString("ioErrorRegister"), e1);
|
||||
}
|
||||
}
|
||||
else if (cmd.equals("cancel"))
|
||||
{
|
||||
setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.i18n;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.PropertyResourceBundle;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.ResourceBundle.Control;
|
||||
|
||||
/**
|
||||
* @author KenM
|
||||
*/
|
||||
public class LanguageControl extends Control
|
||||
{
|
||||
public static final String LANGUAGES_DIRECTORY = "../languages/";
|
||||
|
||||
public static final LanguageControl INSTANCE = new LanguageControl();
|
||||
|
||||
/**
|
||||
* prevent instancing, allows sub-classing
|
||||
*/
|
||||
protected LanguageControl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IOException
|
||||
{
|
||||
if ((baseName == null) || (locale == null) || (format == null) || (loader == null))
|
||||
{
|
||||
throw new NullPointerException();
|
||||
}
|
||||
ResourceBundle bundle = null;
|
||||
if (format.equals("java.properties"))
|
||||
{
|
||||
format = "properties";
|
||||
String bundleName = toBundleName(baseName, locale);
|
||||
String resourceName = LANGUAGES_DIRECTORY + toResourceName(bundleName, format);
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(resourceName);
|
||||
BufferedInputStream bis = new BufferedInputStream(fis))
|
||||
{
|
||||
bundle = new PropertyResourceBundle(bis);
|
||||
}
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tools.images;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import javolution.util.FastMap;
|
||||
|
||||
/**
|
||||
* Usage of this class causes images to be loaded and kept in memory, and therefore should only be used by helper applications.<br>
|
||||
* Some icons from famfamfam (http://www.famfamfam.com/) credit *MUST* be given.
|
||||
* @author KenM
|
||||
*/
|
||||
public class ImagesTable
|
||||
{
|
||||
private static final Map<String, ImageIcon> IMAGES = new FastMap<>();
|
||||
|
||||
public static final String IMAGES_DIRECTORY = "../images/";
|
||||
|
||||
public static ImageIcon getImage(String name)
|
||||
{
|
||||
if (!IMAGES.containsKey(name))
|
||||
{
|
||||
IMAGES.put(name, new ImageIcon(IMAGES_DIRECTORY + name));
|
||||
}
|
||||
return IMAGES.get(name);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user