mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-17 11:54:33 +01:00
Made PasswordAuthorizationDialog react to ESC key. Some code cleanup and a pitch of lambda sugar
This commit is contained in:
parent
9165af4751
commit
fa6c931e7c
@ -35,8 +35,6 @@ import processing.app.Sketch;
|
|||||||
import processing.app.helpers.OSUtils;
|
import processing.app.helpers.OSUtils;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -70,12 +68,9 @@ public class FindReplace extends javax.swing.JFrame {
|
|||||||
|
|
||||||
getRootPane().setDefaultButton(findButton);
|
getRootPane().setDefaultButton(findButton);
|
||||||
|
|
||||||
Base.registerWindowCloseKeys(getRootPane(), new ActionListener() {
|
Base.registerWindowCloseKeys(getRootPane(), e -> {
|
||||||
@Override
|
setVisible(false);
|
||||||
public void actionPerformed(ActionEvent e) {
|
Base.FIND_DIALOG_STATE = findDialogState();
|
||||||
setVisible(false);
|
|
||||||
Base.FIND_DIALOG_STATE = findDialogState();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Base.setIcon(this);
|
Base.setIcon(this);
|
||||||
@ -91,7 +86,7 @@ public class FindReplace extends javax.swing.JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> findDialogState() {
|
private Map<String, Object> findDialogState() {
|
||||||
Map<String, Object> state = new HashMap<String, Object>();
|
Map<String, Object> state = new HashMap<>();
|
||||||
state.put(FIND_TEXT, findField.getText());
|
state.put(FIND_TEXT, findField.getText());
|
||||||
state.put(REPLACE_TEXT, replaceField.getText());
|
state.put(REPLACE_TEXT, replaceField.getText());
|
||||||
state.put(IGNORE_CASE, ignoreCaseBox.isSelected());
|
state.put(IGNORE_CASE, ignoreCaseBox.isSelected());
|
||||||
|
@ -5,22 +5,17 @@ import processing.app.Base;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.WindowEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import static processing.app.I18n._;
|
import static processing.app.I18n._;
|
||||||
|
|
||||||
public class PasswordAuthorizationDialog extends JDialog {
|
public class PasswordAuthorizationDialog extends JDialog {
|
||||||
|
|
||||||
protected final JButton uploadButton;
|
private final JPasswordField passwordField;
|
||||||
protected final JButton cancelButton;
|
|
||||||
protected final JLabel typePasswordLabel;
|
|
||||||
protected final JLabel passwordLabel;
|
|
||||||
protected final JLabel icon;
|
|
||||||
protected final JPasswordField passwordField;
|
|
||||||
|
|
||||||
protected boolean cancelled;
|
private boolean cancelled;
|
||||||
protected String password;
|
private String password;
|
||||||
|
|
||||||
public PasswordAuthorizationDialog(Frame parent, String dialogText) {
|
public PasswordAuthorizationDialog(Frame parent, String dialogText) {
|
||||||
super(parent, true);
|
super(parent, true);
|
||||||
@ -28,12 +23,12 @@ public class PasswordAuthorizationDialog extends JDialog {
|
|||||||
this.cancelled = false;
|
this.cancelled = false;
|
||||||
this.password = null;
|
this.password = null;
|
||||||
|
|
||||||
typePasswordLabel = new JLabel();
|
JLabel typePasswordLabel = new JLabel();
|
||||||
icon = new JLabel();
|
JLabel icon = new JLabel();
|
||||||
passwordLabel = new JLabel();
|
JLabel passwordLabel = new JLabel();
|
||||||
passwordField = new JPasswordField();
|
passwordField = new JPasswordField();
|
||||||
uploadButton = new JButton();
|
JButton uploadButton = new JButton();
|
||||||
cancelButton = new JButton();
|
JButton cancelButton = new JButton();
|
||||||
|
|
||||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
@ -44,68 +39,58 @@ public class PasswordAuthorizationDialog extends JDialog {
|
|||||||
passwordLabel.setText(_("Password:"));
|
passwordLabel.setText(_("Password:"));
|
||||||
|
|
||||||
passwordField.setText("");
|
passwordField.setText("");
|
||||||
passwordField.addActionListener(new ActionListener() {
|
passwordField.addActionListener(PasswordAuthorizationDialog.this::uploadButtonPressed);
|
||||||
public void actionPerformed(ActionEvent evt) {
|
|
||||||
uploadButtonPressed(evt);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
uploadButton.setText(_("Upload"));
|
uploadButton.setText(_("Upload"));
|
||||||
uploadButton.addActionListener(new ActionListener() {
|
uploadButton.addActionListener(PasswordAuthorizationDialog.this::uploadButtonPressed);
|
||||||
public void actionPerformed(ActionEvent evt) {
|
|
||||||
uploadButtonPressed(evt);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
cancelButton.setText(_("Cancel"));
|
cancelButton.setText(_("Cancel"));
|
||||||
cancelButton.addActionListener(new ActionListener() {
|
cancelButton.addActionListener(PasswordAuthorizationDialog.this::cancelButtonPressed);
|
||||||
public void actionPerformed(ActionEvent evt) {
|
|
||||||
cancelButtonPressed(evt);
|
Base.registerWindowCloseKeys(getRootPane(), this::cancelButtonPressed);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
GroupLayout layout = new GroupLayout(getContentPane());
|
GroupLayout layout = new GroupLayout(getContentPane());
|
||||||
getContentPane().setLayout(layout);
|
getContentPane().setLayout(layout);
|
||||||
layout.setHorizontalGroup(
|
layout.setHorizontalGroup(
|
||||||
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addComponent(icon, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE)
|
.addComponent(icon, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE)
|
||||||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||||
.addComponent(typePasswordLabel)
|
.addComponent(typePasswordLabel)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addComponent(passwordLabel)
|
.addComponent(passwordLabel)
|
||||||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, 300, GroupLayout.PREFERRED_SIZE)))
|
.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, 300, GroupLayout.PREFERRED_SIZE)))
|
||||||
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||||
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||||
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||||
.addComponent(cancelButton)
|
.addComponent(cancelButton)
|
||||||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(uploadButton)
|
.addComponent(uploadButton)
|
||||||
.addContainerGap())
|
.addContainerGap())
|
||||||
);
|
);
|
||||||
layout.setVerticalGroup(
|
layout.setVerticalGroup(
|
||||||
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addComponent(typePasswordLabel)
|
.addComponent(typePasswordLabel)
|
||||||
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addGap(53, 53, 53)
|
.addGap(53, 53, 53)
|
||||||
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(passwordLabel)
|
.addComponent(passwordLabel)
|
||||||
.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||||
.addGap(18, 18, 18))
|
.addGap(18, 18, 18))
|
||||||
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(icon)
|
.addComponent(icon)
|
||||||
.addGap(9, 9, 9)))
|
.addGap(9, 9, 9)))
|
||||||
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(uploadButton)
|
.addComponent(uploadButton)
|
||||||
.addComponent(cancelButton))
|
.addComponent(cancelButton))
|
||||||
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||||
);
|
);
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
@ -113,12 +98,12 @@ public class PasswordAuthorizationDialog extends JDialog {
|
|||||||
|
|
||||||
private void cancelButtonPressed(ActionEvent event) {
|
private void cancelButtonPressed(ActionEvent event) {
|
||||||
this.cancelled = true;
|
this.cancelled = true;
|
||||||
this.dispose();
|
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uploadButtonPressed(ActionEvent event) {
|
private void uploadButtonPressed(ActionEvent event) {
|
||||||
this.password = new String(passwordField.getPassword());
|
this.password = new String(passwordField.getPassword());
|
||||||
this.dispose();
|
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
@ -128,4 +113,4 @@ public class PasswordAuthorizationDialog extends JDialog {
|
|||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user