-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
346 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
app/src/main/java/muon/screens/appwin/UserInputDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package muon.screens.appwin; | ||
|
||
import muon.util.IconCode; | ||
import muon.util.IconFont; | ||
|
||
import javax.swing.*; | ||
import javax.swing.border.EmptyBorder; | ||
import java.awt.*; | ||
import java.awt.event.WindowAdapter; | ||
import java.awt.event.WindowEvent; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class UserInputDialog extends JDialog { | ||
private JLabel lblUser; | ||
private java.util.List<String> inputs; | ||
private List<JPasswordField> txtInputs; | ||
private JPanel userInputContainer; | ||
private JButton loginButton; | ||
private JPanel container; | ||
|
||
public UserInputDialog(Window window) { | ||
super(window); | ||
initUi(); | ||
setContentPane(container); | ||
addWindowListener(new WindowAdapter() { | ||
@Override | ||
public void windowActivated(WindowEvent e) { | ||
txtInputs.get(0).requestFocusInWindow(); | ||
} | ||
}); | ||
} | ||
|
||
public synchronized List<String> getInputs(String label, String[] prompt, boolean[] echo) { | ||
inputs = Collections.emptyList(); | ||
try { | ||
SwingUtilities.invokeAndWait(() -> { | ||
showPrompt(label, prompt, echo); | ||
}); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
return inputs; | ||
} | ||
|
||
private void initUi() { | ||
container = new JPanel(new GridBagLayout()); | ||
loginButton = new JButton("Login"); | ||
loginButton.addActionListener(e -> { | ||
inputs = this.txtInputs.stream().map(txt -> new String(txt.getPassword())).toList(); | ||
setVisible(false); | ||
}); | ||
|
||
var iconLabel = new JLabel(); | ||
iconLabel.setFont(IconFont.getSharedInstance().getIconFont(48.0f)); | ||
iconLabel.setText(IconCode.RI_ACCOUNT_CIRCLE_FILL.getValue()); | ||
|
||
lblUser = new JLabel(); | ||
lblUser.setText("user"); | ||
lblUser.setBorder(new EmptyBorder(0, 0, 8, 0)); | ||
lblUser.setFont(new Font(Font.DIALOG, Font.BOLD, 16)); | ||
lblUser.setAlignmentX(Component.LEFT_ALIGNMENT); | ||
|
||
var iconPanel = new JPanel(new BorderLayout(10, 0)); | ||
iconPanel.setAlignmentX(Component.LEFT_ALIGNMENT); | ||
iconPanel.add(iconLabel, BorderLayout.WEST); | ||
iconPanel.add(lblUser, BorderLayout.CENTER); | ||
|
||
var hbox = Box.createHorizontalBox(); | ||
hbox.add(Box.createHorizontalGlue()); | ||
hbox.add(loginButton); | ||
hbox.setMaximumSize(new Dimension(Short.MAX_VALUE, hbox.getPreferredSize().height)); | ||
hbox.setAlignmentX(Component.LEFT_ALIGNMENT); | ||
|
||
userInputContainer = new JPanel(); | ||
userInputContainer.setAlignmentX(Component.LEFT_ALIGNMENT); | ||
userInputContainer.setLayout(new BoxLayout(userInputContainer, BoxLayout.Y_AXIS)); | ||
|
||
var vbox = Box.createVerticalBox(); | ||
vbox.add(iconPanel); | ||
vbox.add(Box.createRigidArea(new Dimension(10, 20))); | ||
vbox.add(userInputContainer); | ||
vbox.add(Box.createRigidArea(new Dimension(10, 10))); | ||
vbox.add(hbox); | ||
|
||
container.add(vbox, new GridBagConstraints()); | ||
} | ||
|
||
private void showPrompt(String label, String[] prompt, boolean[] echo) { | ||
var len = prompt.length; | ||
lblUser.setText(label); | ||
txtInputs = new ArrayList<>(len); | ||
userInputContainer.removeAll(); | ||
userInputContainer.setAlignmentX(Component.LEFT_ALIGNMENT); | ||
|
||
for (var i = 0; i < len; i++) { | ||
var txtInput = new JPasswordField(20); | ||
txtInput.addActionListener(e -> { | ||
loginButton.doClick(); | ||
}); | ||
txtInput.setAlignmentX(Component.LEFT_ALIGNMENT); | ||
if (echo[i]) { | ||
txtInput.setEchoChar('*'); | ||
} | ||
txtInputs.add(txtInput); | ||
var lbl = new JLabel(prompt[i]); | ||
lbl.setBorder(new EmptyBorder(0, 0, 10, 0)); | ||
lbl.setHorizontalAlignment(JLabel.LEFT); | ||
lbl.setAlignmentX(Component.LEFT_ALIGNMENT); | ||
userInputContainer.add(lbl); | ||
userInputContainer.add(txtInput); | ||
} | ||
this.pack(); | ||
this.setLocationRelativeTo(this.getOwner()); | ||
this.setVisible(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../main/java/muon/screens/appwin/tabs/filebrowser/transfer/foreground/FileListRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package muon.screens.appwin.tabs.filebrowser.transfer.foreground; | ||
|
||
import muon.dto.file.FileInfo; | ||
import muon.styles.AppTheme; | ||
import muon.util.IconCode; | ||
import muon.util.IconFont; | ||
|
||
import javax.swing.*; | ||
import javax.swing.border.EmptyBorder; | ||
import java.awt.*; | ||
|
||
public class FileListRenderer<F> implements ListCellRenderer<FileInfo> { | ||
private JPanel panel1, panel2; | ||
private JLabel lblIcon, lblText, lblInfo; | ||
|
||
public FileListRenderer() { | ||
panel1 = new JPanel(new BorderLayout(5, 10)); | ||
panel1.setBorder(new EmptyBorder(0, 0, 5, 0)); | ||
lblIcon = new JLabel(); | ||
lblIcon.setForeground(AppTheme.INSTANCE.getDarkForeground()); | ||
lblIcon.setFont(IconFont.getSharedInstance().getIconFont(32.0f)); | ||
|
||
lblText = new JLabel(); | ||
lblText.setFont(new Font(Font.DIALOG, Font.PLAIN, 12)); | ||
lblText.setForeground(AppTheme.INSTANCE.getForeground()); | ||
|
||
lblInfo = new JLabel(); | ||
lblInfo.setFont(new Font(Font.DIALOG, Font.PLAIN, 11)); | ||
lblInfo.setForeground(AppTheme.INSTANCE.getDarkForeground()); | ||
|
||
panel2 = new JPanel(new BorderLayout(5, 0)); | ||
|
||
panel2.add(lblText, BorderLayout.NORTH); | ||
panel2.add(lblInfo); | ||
|
||
panel1.add(lblIcon, BorderLayout.WEST); | ||
panel1.add(panel2); | ||
|
||
} | ||
|
||
@Override | ||
public Component getListCellRendererComponent(JList<? extends FileInfo> list, FileInfo value, int index, boolean isSelected, boolean cellHasFocus) { | ||
lblIcon.setText(value.isDirectory() ? IconCode.RI_FOLDER_FILL.getValue() : IconCode.RI_FILE_FILL.getValue()); | ||
lblText.setText(value.getName()); | ||
lblInfo.setText(value.isDirectory() ? "Folder" : value.getSize() + ""); | ||
return panel1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.