📄 optionschatjpanel.java
字号:
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jPasswordField1, jTextField1});
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jPasswordField1, jTextField1});
jPanel10.add(jPanel2, java.awt.BorderLayout.CENTER);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jCheckBox1)
.addContainerGap(44, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
.addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(103, 103, 103))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jCheckBox1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
add(jPanel1, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
private void jCheckBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCheckBox1ItemStateChanged
// TODO add your handling code here:
updateGUIState();
}//GEN-LAST:event_jCheckBox1ItemStateChanged
private void jPanel6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel6MouseClicked
// TODO add your handling code here:
if (jPanel6.isEnabled() == false) {
return;
}
final java.awt.Color color = javax.swing.JColorChooser.showDialog(this, "Choose a color", this.jPanel6.getBackground());
if(null == color) return;
jPanel6.setBackground(color);
}//GEN-LAST:event_jPanel6MouseClicked
private void jPanel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel7MouseClicked
if (jPanel7.isEnabled() == false) {
return;
}
final java.awt.Color color = javax.swing.JColorChooser.showDialog(this, "Choose a color", this.jPanel7.getBackground());
if(null == color) return;
jPanel7.setBackground(color);
}//GEN-LAST:event_jPanel7MouseClicked
private void jPanel8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel8MouseClicked
if (jPanel8.isEnabled() == false) {
return;
}
final java.awt.Color color = javax.swing.JColorChooser.showDialog(this, "Choose a color", this.jPanel8.getBackground());
if(null == color) return;
jPanel8.setBackground(color);
}//GEN-LAST:event_jPanel8MouseClicked
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
this.jPanel6.setBackground(JStockOptions.DEFAULT_CHAT_SYSTEM_MESSAGE_COLOR);
this.jPanel7.setBackground(JStockOptions.DEFAULT_CHAT_OWN_MESSAGE_COLOR);
this.jPanel8.setBackground(JStockOptions.DEFAULT_CHAT_OTHER_MESSAGE_COLOR);
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
ChangeChatPasswordJDialog changeChatPasswordJDialog = new ChangeChatPasswordJDialog(MainFrame.getMe(), true);
if (changeChatPasswordJDialog.doModal() == false) {
return;
}
// In changeChatPasswordJDialog, jStockOptions had been updated to latest password.
this.jPasswordField1.setText(Utils.decrypt(MainFrame.getJStockOptions().getChatPassword()));
MainFrame.getMe().stopChatServiceManager();
MainFrame.getMe().startChatServiceManager();
}//GEN-LAST:event_jButton2ActionPerformed
private boolean shouldjButton2Enabled() {
final JStockOptions options = MainFrame.getJStockOptions();
final String newUsername = jTextField1.getText();
final String newPassword = new String(jPasswordField1.getPassword());
return (
jCheckBox1.isSelected() &&
newUsername.equals(options.getChatUsername()) &&
MainFrame.getMe().isChatLogin() &&
newPassword.equals(Utils.decrypt(options.getChatPassword()))
);
}
private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyTyped
SwingUtilities.invokeLater(new Runnable() {
public void run() {
jButton2.setEnabled(shouldjButton2Enabled());
}
});
}//GEN-LAST:event_jTextField1KeyTyped
private void jPasswordField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPasswordField1KeyTyped
// TODO add your handling code here:
SwingUtilities.invokeLater(new Runnable() {
public void run() {
jButton2.setEnabled(shouldjButton2Enabled());
}
});
}//GEN-LAST:event_jPasswordField1KeyTyped
private void updateGUIState() {
jLabel2.setEnabled(jCheckBox1.isSelected());
jTextField1.setEnabled(jCheckBox1.isSelected());
jLabel1.setEnabled(jCheckBox1.isSelected());
jLabel6.setEnabled(jCheckBox1.isSelected());
this.jPasswordField1.setEnabled(jCheckBox1.isSelected());
jLabel7.setEnabled(jCheckBox1.isSelected());
jButton2.setEnabled(shouldjButton2Enabled());
jCheckBox2.setEnabled(jCheckBox1.isSelected());
jCheckBox3.setEnabled(jCheckBox1.isSelected());
jLabel3.setEnabled(jCheckBox1.isSelected());
jPanel6.setEnabled(jCheckBox1.isSelected());
jLabel4.setEnabled(jCheckBox1.isSelected());
jPanel7.setEnabled(jCheckBox1.isSelected());
jLabel5.setEnabled(jCheckBox1.isSelected());
jPanel8.setEnabled(jCheckBox1.isSelected());
jButton1.setEnabled(jCheckBox1.isSelected());
}
@Override
public void set(JStockOptions jStockOptions) {
this.jCheckBox1.setSelected(jStockOptions.isChatEnabled());
this.jTextField1.setText(jStockOptions.getChatUsername());
this.jPasswordField1.setText(Utils.decrypt(jStockOptions.getChatPassword()));
this.jCheckBox2.setSelected(jStockOptions.isChatSoundNotificationEnabled());
this.jCheckBox3.setSelected(jStockOptions.isChatFlashNotificationEnabled());
this.jPanel6.setBackground(jStockOptions.getChatSystemMessageColor());
this.jPanel7.setBackground(jStockOptions.getChatOwnMessageColor());
this.jPanel8.setBackground(jStockOptions.getChatOtherMessageColor());
this.updateGUIState();
}
@Override
public boolean apply(JStockOptions jStockOptions) {
final MainFrame m = MainFrame.getMe();
if (this.jCheckBox1.isSelected())
{
if (this.jTextField1.getText().length() <= 0) {
JOptionPane.showMessageDialog(this, "Username field may not be empty.", "Empty username", JOptionPane.WARNING_MESSAGE);
this.jTextField1.requestFocus();
return false;
}
final char[] password = this.jPasswordField1.getPassword();
if (password == null || password.length <= 0) {
JOptionPane.showMessageDialog(this, "Password field may not be empty.", "Empty password", JOptionPane.WARNING_MESSAGE);
this.jPasswordField1.requestFocus();
return false;
}
final String newPasswordString = new String(jPasswordField1.getPassword());
String oldUsername = jStockOptions.getChatUsername();
String oldPassword = Utils.decrypt(jStockOptions.getChatPassword());
boolean oldFlag = jStockOptions.isChatEnabled();
jStockOptions.setChatEnabled(true);
jStockOptions.setChatUsername(this.jTextField1.getText());
jStockOptions.setChatPassword(Utils.encrypt(newPasswordString));
jStockOptions.setChatSoundNotificationEnabled(this.jCheckBox2.isSelected());
jStockOptions.setChatFlashNotificationEnabled(this.jCheckBox3.isSelected());
jStockOptions.setChatSystemMessageColor(jPanel6.getBackground());
jStockOptions.setChatOwnMessageColor(jPanel7.getBackground());
jStockOptions.setChatOtherMessageColor(jPanel8.getBackground());
if ((oldFlag != jStockOptions.isChatEnabled()) || (oldUsername.equals(jStockOptions.getChatUsername()) == false) || (oldPassword.equals(newPasswordString) == false))
{
if (m != null)
{
// Only restart chatting service, if the username is different.
m.stopChatServiceManager();
m.startChatServiceManager();
}
}
}
else
{
if(m != null) {
m.stopChatServiceManager();
}
jStockOptions.setChatEnabled(false);
jStockOptions.setChatUsername(this.jTextField1.getText());
jStockOptions.setChatPassword(Utils.encrypt(new String(jPasswordField1.getPassword())));
jStockOptions.setChatSoundNotificationEnabled(this.jCheckBox2.isSelected());
jStockOptions.setChatFlashNotificationEnabled(this.jCheckBox3.isSelected());
jStockOptions.setChatSystemMessageColor(jPanel6.getBackground());
jStockOptions.setChatOwnMessageColor(jPanel7.getBackground());
jStockOptions.setChatOtherMessageColor(jPanel8.getBackground());
}
m.updateChatJPanelUIAccordingToOptions();
return true;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JCheckBox jCheckBox2;
private javax.swing.JCheckBox jCheckBox3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel10;
private javax.swing.JPanel jPanel11;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JPanel jPanel8;
private javax.swing.JPanel jPanel9;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
private org.jdesktop.swingx.JXHeader jXHeader1;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -