[go: up one dir, main page]

Menu

[r39]: / rmldonkey.rb  Maximize  Restore  History

Download this file

182 lines (149 with data), 7.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#encoding: UTF-8
# This file is part of Rmldonkey.
# Rmldonkey 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.
# Rmldonkey 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 Rmldonkey. If not, see <http://www.gnu.org/licenses/>.
# Copyright 2009-2014, Manuel Ramos Caro manuelramoscaro@yahoo.es
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
def initialize
super "Rmldonkey - Connection"
UIManager::setLookAndFeel( "org.jvnet.substance.skin.SubstanceRavenGraphiteGlassLookAndFeel" )
self.initUI
ConfigWebResources.new
end #initialize
def initUI
panel = JPanel.new
panel.setLayout nil
self.getContentPane.add panel
imagen_icon = ImageIcon.new java.awt.Toolkit::default_toolkit.get_image(java.lang.Object.new.java_class.resource("/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 java.awt.Toolkit::default_toolkit.get_image(java.lang.Object.new.java_class.resource("/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
self.setIconImage(java.awt.Toolkit::default_toolkit.get_image(java.lang.Object.new.java_class.resource("/01.png")))
end #initUI
end
#usage
#javax.swing.SwingUtilities.invokeLater(Logon.new)
Logon.new