include Java
require 'conectaTelnet'
require 'includes'
require 'profileStore'
require 'main'
require 'rbconfig'
#### debug purpose
#puts "Ruby Info:"
#puts " RUBY_PLATFORM: #{RUBY_PLATFORM}"
#puts " RUBY_VERSION: #{RUBY_VERSION}"
#puts " RbConfig::CONFIG['RUBY_INSTALL_NAME']:#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
#puts " RbConfig::CONFIG['host_os']: #{RbConfig::CONFIG['host_os']}"
class Logon < JFrame
UIManager::setLookAndFeel( "org.jvnet.substance.skin.SubstanceRavenGraphiteGlassLookAndFeel" )
def initialize
super "Rmldonkey - Connection"
self.initUI
end #initialize
def initUI
panel = JPanel.new
panel.setLayout nil
self.getContentPane.add panel
imagen_icon = ImageIcon.new "mldonkey.png"
imagen_logo = JLabel.new imagen_icon
imagen_logo.setBounds 55, 1, imagen_icon.getIconWidth, imagen_icon.getIconHeight
imagen_icon = ImageIcon.new(imagen_icon.getImage.getScaledInstance(imagen_icon.getIconWidth - 10,imagen_icon.getIconHeight - 10,java.awt.Image::SCALE_DEFAULT))
imagen_logo.setIcon(imagen_icon)
icono_fondo_principal = ImageIcon.new "fondo_00.png"
fondo_principal = JLabel.new icono_fondo_principal
fondo_principal.setBounds(0,0,300,400)
icono_fondo_principal = ImageIcon.new(icono_fondo_principal.getImage().getScaledInstance(300,400,java.awt.Image::SCALE_FAST))
fondo_principal.setIcon(icono_fondo_principal)
profile = ReadProfile.new
if profile.ExistProfile
# puts "***with profile***"
@server = profile.readServer
@port = profile.readPort
@user = profile.readUser
@pass = profile.readPass
else
# puts "*** without profile***"
# we charge default profile for a mldonkey conection
@server = "127.0.0.1"
@port = "4000"
@user = "admin"
@pass = ""
end #if profile.ExistProfile
etiqueta_host = javax.swing.JLabel.new
etiqueta_host.setText("Server")
etiqueta_host.setBounds 30,190,150,22
texto_host = javax.swing.JTextField.new
texto_host.setText(@server)
texto_host.setBounds 130, 190, 150,22
etiqueta_port = javax.swing.JLabel.new
etiqueta_port.setText("Port")
etiqueta_port.setBounds 30,215,150,22
texto_port = javax.swing.JTextField.new
texto_port.setText(@port)
texto_port.setBounds 130, 215, 150,22
etiqueta_usuario = javax.swing.JLabel.new
etiqueta_usuario.setText("User")
etiqueta_usuario.setBounds 30,240,150,22
texto_usuario = javax.swing.JTextField.new
texto_usuario.setText(@user)
texto_usuario.setBounds 130, 240, 150,22
etiqueta_password = javax.swing.JLabel.new
etiqueta_password.setText("Password")
etiqueta_password.setBounds 30,265,150,22
texto_password = javax.swing.JPasswordField.new
texto_password.setText(@pass)
texto_password.setBounds 130, 265, 150,22
remember_check = javax.swing.JCheckBox.new("Remember this connection...")
remember_check.setSelected(true)
remember_check.setOpaque(false)
remember_check.setBounds 30, 295, 300,20
botonOk = javax.swing.JButton.new "OK"
botonOk.setBounds 35, 320, 110,40
botonOk.add_action_listener do |e|
$conexion = ConectaTelnet.new(texto_host.getText,texto_port.getText,texto_usuario.getText,texto_password.getText)
if $conexion.estado_conectatelnet == true
#debug purpose
#JOptionPane.showMessageDialog panel, "Conexion OK", "Information", JOptionPane::INFORMATION_MESSAGE
#Here we have a connection and now we store the profile
if remember_check.isSelected
save_profile = SaveProfile.new
texto_usuario_getText = texto_usuario.getText
if texto_usuario_getText == ""
texto_usuario_getText = " "
end #texto_usuario_getText = texto_usuario.getText
texto_password_getText = texto_password.getText
if texto_password_getText == ""
texto_password_getText = " "
end #texto_password_getText = texto_password.getText
save_profile.saveFile(texto_host.getText,texto_port.getText,texto_usuario_getText,texto_password_getText)
end #if remember_check.isSelected
self.setDefaultCloseOperation JFrame::DISPOSE_ON_CLOSE
self.dispose
UIManager.put("swing.boldMetal", false)
javax.swing.SwingUtilities.invokeLater(Main.new)
else
JOptionPane.showMessageDialog panel, $conexion.conectatelnet_error_msg.to_s, "Error", JOptionPane::ERROR_MESSAGE
end #if conexion
end #botonOk.add_action_listener
botonCerrar = javax.swing.JButton.new "Close"
botonCerrar.setBounds 160, 320, 110,40
botonCerrar.add_action_listener do |e|
#debug purpose
#JOptionPane.showMessageDialog panel, "Hit Close",
#"Information", JOptionPane::INFORMATION_MESSAGE
self.dispose
end #botonCerrar.add_action_listener
panel.add imagen_logo
panel.add etiqueta_host
panel.add etiqueta_port
panel.add etiqueta_usuario
panel.add etiqueta_password
panel.add texto_host
panel.add texto_port
panel.add texto_usuario
panel.add texto_password
panel.add remember_check
panel.add botonOk
panel.add botonCerrar
panel.add fondo_principal
self.setDefaultCloseOperation JFrame::EXIT_ON_CLOSE
self.setSize java.awt.Dimension.new(300,400)
self.setResizable(false)
self.setLocationRelativeTo nil
self.setVisible true
app_icon = Toolkit.getDefaultToolkit.getImage("01.png")
self.setIconImage(app_icon)
end #initUI
end
#usage
Logon.new