Skip to content

Commit

Permalink
add reset btn to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukaru-san committed Apr 22, 2022
1 parent fc5d6ef commit f254b7d
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/jcrop/handler/KeyAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public KeyAction(String actionCommand, Callable<Object> targetFunc) {

@Override
public void actionPerformed(ActionEvent e) {
System.out.println(e.getActionCommand() + " pressed");
try {
targetFunc.call();
} catch (Exception ex) {
Expand Down
7 changes: 6 additions & 1 deletion src/toolset/Constants.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package toolset;

import java.awt.Font;

public class Constants {

public static String SAVE_PATH = System.getProperty("user.home") + "/.yukaru/jshot/";
public static String SAVE_FILE = "jshot.save";

public static Font SETTINGS_BTN_FONT = new Font("Arial", Font.PLAIN, 12);

public static int SETTINGS_WINDOW_WIDTH = 500;
public static int SETTINGS_WINDOW_HEIGHT = 350;
public static int SETTINGS_WINDOW_HEIGHT = 400;
public static int SETTINGS_COLORWINDOW_WIDTH = 650;
public static int SETTINGS_COLORWINDOW_HEIGHT = 500;

Expand Down
4 changes: 1 addition & 3 deletions src/toolset/PainterSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ private static void loadSettings() {

f.close();
o.close();

System.out.println("Using saved data.");

} catch (Exception e) {
// Use default data instead
data = new SettingsData();
System.out.println("Using default data.");
}

// Prepare data-reliant objects
Expand Down
5 changes: 5 additions & 0 deletions src/toolset/SettingsData.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class SettingsData implements Serializable {

// Load default data on creation
public SettingsData() {
applyDefault();
}

// Applies the default settings
public void applyDefault() {
fontSize = 16;
fontName = "Arial";
strokeWidth = 3;
Expand Down
97 changes: 73 additions & 24 deletions src/ui/SettingsPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class SettingsPopup extends JDialog {

// Outside reference
ScreenshotWindow screenshotWindow;

// Panel references
private JPanel settingsPanel;
private JPanel colorPanel;
Expand Down Expand Up @@ -113,9 +113,10 @@ public void focusLost(FocusEvent e) {
box.setPopupVisible(false);
lastFont = autocompleteText(editor.getText());
editor.setText(lastFont);

PainterSettings.data.fontName = lastFont;
PainterSettings.font = new Font(PainterSettings.data.fontName, Font.BOLD, PainterSettings.data.fontSize);
PainterSettings.font = new Font(PainterSettings.data.fontName, Font.BOLD,
PainterSettings.data.fontSize);
PainterSettings.saveSettings();
}
});
Expand Down Expand Up @@ -175,20 +176,26 @@ private void initializeSettingsPanel() {
e.printStackTrace();
}

// Add font components
// Create the pannel
settingsPanel = new JPanel();
settingsPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
settingsPanel.setBorder(new EmptyBorder(0, 10, 10, 10));
getContentPane().add(settingsPanel, BorderLayout.CENTER);
settingsPanel.setLayout(new GridLayout(0, 2, 0, 0));
settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.Y_AXIS));

// Create sub panel
JPanel upperPanel = new JPanel();
upperPanel.setLayout(new GridLayout(0, 2, 0, 0));
settingsPanel.add(upperPanel);

// Add font components
JLabel font_lbl = new JLabel("Font");
settingsPanel.add(font_lbl);
upperPanel.add(font_lbl);

JPanel font_pnl = new JPanel();
font_pnl.setBorder(new EmptyBorder(10, 10, 10, 10));
settingsPanel.add(font_pnl);
upperPanel.add(font_pnl);
font_pnl.setLayout(new GridLayout(0, 1, 0, 0));
settingsPanel.add(font_pnl);
upperPanel.add(font_pnl);

JComboBox<String> box = new JComboBox<String>(fonts);
box.getModel().setSelectedItem(lastFont);
Expand All @@ -199,11 +206,11 @@ private void initializeSettingsPanel() {
applyAdvancedFontSettings(box);

JLabel fsize_lbl = new JLabel("Font size");
settingsPanel.add(fsize_lbl);
upperPanel.add(fsize_lbl);

JPanel fsize_pnl = new JPanel();
fsize_pnl.setBorder(new EmptyBorder(10, 10, 10, 10));
settingsPanel.add(fsize_pnl);
upperPanel.add(fsize_pnl);
fsize_pnl.setLayout(new GridLayout(0, 1, 0, 0));

JSpinner fsize_input = new JSpinner();
Expand All @@ -221,11 +228,11 @@ public void stateChanged(ChangeEvent e) {

// Add stroke size components
JLabel ssize_lbl = new JLabel("Stroke size");
settingsPanel.add(ssize_lbl);
upperPanel.add(ssize_lbl);

JPanel ssize_pnl = new JPanel();
ssize_pnl.setBorder(new EmptyBorder(10, 10, 10, 10));
settingsPanel.add(ssize_pnl);
upperPanel.add(ssize_pnl);
ssize_pnl.setLayout(new GridLayout(0, 1, 0, 0));

JSpinner ssize_input = new JSpinner();
Expand All @@ -245,11 +252,11 @@ public void stateChanged(ChangeEvent e) {

// Add highlighted stroke size components
JLabel h_ssize_lbl = new JLabel("Highlighted stroke size");
settingsPanel.add(h_ssize_lbl);
upperPanel.add(h_ssize_lbl);

JPanel h_ssize_pnl = new JPanel();
h_ssize_pnl.setBorder(new EmptyBorder(10, 10, 10, 10));
settingsPanel.add(h_ssize_pnl);
upperPanel.add(h_ssize_pnl);
h_ssize_pnl.setLayout(new GridLayout(0, 1, 0, 0));

JSpinner h_ssize_input = new JSpinner();
Expand All @@ -269,11 +276,11 @@ public void stateChanged(ChangeEvent e) {

// Add color components
JLabel color_lbl = new JLabel("Color");
settingsPanel.add(color_lbl);
upperPanel.add(color_lbl);

JPanel color_in_pnl = new JPanel();
color_in_pnl.setBorder(new EmptyBorder(10, 10, 10, 10));
settingsPanel.add(color_in_pnl);
upperPanel.add(color_in_pnl);
color_in_pnl.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

color_preview = new JPanel();
Expand All @@ -295,11 +302,11 @@ public void actionPerformed(ActionEvent e) {

// Add highlighted color components
JLabel h_color_lbl = new JLabel("Highlight color");
settingsPanel.add(h_color_lbl);
upperPanel.add(h_color_lbl);

JPanel h_color_in_pnl = new JPanel();
h_color_in_pnl.setBorder(new EmptyBorder(10, 10, 10, 10));
settingsPanel.add(h_color_in_pnl);
upperPanel.add(h_color_in_pnl);
h_color_in_pnl.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

h_color_preview = new JPanel();
Expand All @@ -319,6 +326,51 @@ public void actionPerformed(ActionEvent e) {
});
h_color_in_pnl.add(h_color_input);

// create the lower part's panel
JPanel lowerPanel = new JPanel();
lowerPanel.setLayout(new GridLayout(0, 2, 10, 0));
lowerPanel.setBorder(new EmptyBorder(0, 100, 0, 100));
lowerPanel.setPreferredSize(new Dimension(0, 50));
settingsPanel.add(lowerPanel);

// Reset btn - resets all default values and applies them
JButton reset_btn = new JButton("reset");
reset_btn.setFont(Constants.SETTINGS_BTN_FONT);
reset_btn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
PainterSettings.data.applyDefault();
PainterSettings.saveSettings();

fsize_input.setValue(PainterSettings.data.fontSize);
h_ssize_input.setValue(PainterSettings.data.h_strokeWidth);
color_preview.setBackground(PainterSettings.data.color);
h_color_preview.setBackground(PainterSettings.data.h_color);

JTextComponent editor = (JTextComponent) box.getEditor().getEditorComponent();
lastFont = PainterSettings.data.fontName;
editor.setText(lastFont);

repaint();
}

});
lowerPanel.add(reset_btn);

// Exit btn
JButton exit_btn = new JButton("exit");
exit_btn.setFont(Constants.SETTINGS_BTN_FONT);
exit_btn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {

}

});
lowerPanel.add(exit_btn);

setVisible(true);
}

Expand All @@ -342,12 +394,9 @@ private void initializeColorPanel() {
btns_pnl.setPreferredSize(new Dimension(0, 50));
colorPanel.add(btns_pnl);

// Btn font
Font font = new Font("Arial", Font.PLAIN, 12);

// Add OK btn
JButton ok_btn = new JButton("Ok");
ok_btn.setFont(font);
ok_btn.setFont(Constants.SETTINGS_BTN_FONT);
ok_btn.addActionListener(new ActionListener() {

@Override
Expand All @@ -373,7 +422,7 @@ public void actionPerformed(ActionEvent e) {

// Add cancel btn
JButton cancel_btn = new JButton("cancel");
cancel_btn.setFont(font);
cancel_btn.setFont(Constants.SETTINGS_BTN_FONT);
cancel_btn.addActionListener(new ActionListener() {

@Override
Expand Down

0 comments on commit f254b7d

Please sign in to comment.