toolbar fixes
This commit is contained in:
parent
f63636eae3
commit
2de5cf6bc4
@ -9,7 +9,7 @@ import javax.swing.*;
|
||||
*/
|
||||
public class MainApp {
|
||||
|
||||
public static final String APP_VERSION = "0.0.2";
|
||||
public static final String APP_VERSION = "0.0.3";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Set look and feel to system default
|
||||
|
||||
@ -213,6 +213,23 @@ public class AppConfig {
|
||||
setEditorFontStyle(font.getStyle());
|
||||
}
|
||||
|
||||
// Toolbar configuration
|
||||
public int getToolbarButtonSize() {
|
||||
return Integer.parseInt(properties.getProperty("toolbar.button.size", "30"));
|
||||
}
|
||||
|
||||
public void setToolbarButtonSize(int size) {
|
||||
properties.setProperty("toolbar.button.size", String.valueOf(size));
|
||||
}
|
||||
|
||||
public int getToolbarIconSize() {
|
||||
return Integer.parseInt(properties.getProperty("toolbar.icon.size", "24"));
|
||||
}
|
||||
|
||||
public void setToolbarIconSize(int size) {
|
||||
properties.setProperty("toolbar.icon.size", String.valueOf(size));
|
||||
}
|
||||
|
||||
// --- External editor configuration ---
|
||||
/** Path to external editor binary (empty = use internal editor) */
|
||||
public String getExternalEditorPath() {
|
||||
|
||||
@ -333,14 +333,21 @@ public class MainWindow extends JFrame {
|
||||
|
||||
// Load custom shortcuts from config
|
||||
List<AppConfig.ToolbarShortcut> shortcuts = config.getToolbarShortcuts();
|
||||
int btnSize = config.getToolbarButtonSize();
|
||||
int iconSize = config.getToolbarIconSize();
|
||||
|
||||
for (AppConfig.ToolbarShortcut s : shortcuts) {
|
||||
JButton btn = new JButton();
|
||||
btn.setPreferredSize(new Dimension(btnSize, btnSize));
|
||||
btn.setMinimumSize(new Dimension(btnSize, btnSize));
|
||||
btn.setMaximumSize(new Dimension(btnSize, btnSize));
|
||||
|
||||
boolean hasIcon = false;
|
||||
if (s.iconPath != null && !s.iconPath.isEmpty()) {
|
||||
try {
|
||||
File iconFile = new File(s.iconPath);
|
||||
if (iconFile.exists()) {
|
||||
btn.setIcon(new ImageIcon(new ImageIcon(s.iconPath).getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH)));
|
||||
btn.setIcon(new ImageIcon(new ImageIcon(s.iconPath).getImage().getScaledInstance(iconSize, iconSize, Image.SCALE_SMOOTH)));
|
||||
hasIcon = true;
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
@ -652,6 +659,9 @@ public class MainWindow extends JFrame {
|
||||
if (rightPanel != null) rightPanel.applyMarkedColor(mark);
|
||||
}
|
||||
|
||||
// Refresh toolbar if sizes changed
|
||||
SwingUtilities.invokeLater(() -> createToolBar());
|
||||
|
||||
// Re-propagate AppConfig to panels so they can pick up sorting and other config changes
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
try {
|
||||
|
||||
@ -27,6 +27,8 @@ public class SettingsDialog extends JDialog {
|
||||
private final Font originalGlobalFont;
|
||||
private final Font originalEditorFont;
|
||||
private final String originalExternalEditorPath;
|
||||
private final int originalToolbarButtonSize;
|
||||
private final int originalToolbarIconSize;
|
||||
|
||||
// Appearance controls
|
||||
private JButton appearanceFontBtn;
|
||||
@ -54,6 +56,8 @@ public class SettingsDialog extends JDialog {
|
||||
this.originalGlobalFont = config.getGlobalFont();
|
||||
this.originalEditorFont = config.getEditorFont();
|
||||
this.originalExternalEditorPath = config.getExternalEditorPath();
|
||||
this.originalToolbarButtonSize = config.getToolbarButtonSize();
|
||||
this.originalToolbarIconSize = config.getToolbarIconSize();
|
||||
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
setSize(700, 420);
|
||||
@ -64,6 +68,7 @@ public class SettingsDialog extends JDialog {
|
||||
model.addElement("Appearance");
|
||||
model.addElement("Editor");
|
||||
model.addElement("Sorting");
|
||||
model.addElement("Toolbar");
|
||||
categoryList = new JList<>(model);
|
||||
categoryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
categoryList.setSelectedIndex(0);
|
||||
@ -75,6 +80,7 @@ public class SettingsDialog extends JDialog {
|
||||
cards.add(buildAppearancePanel(), "Appearance");
|
||||
cards.add(buildEditorPanel(), "Editor");
|
||||
cards.add(buildSortingPanel(), "Sorting");
|
||||
cards.add(buildToolbarPanel(), "Toolbar");
|
||||
|
||||
categoryList.addListSelectionListener(e -> {
|
||||
if (!e.getValueIsAdjusting()) {
|
||||
@ -153,6 +159,17 @@ public class SettingsDialog extends JDialog {
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
|
||||
// Collect Toolbar settings
|
||||
JPanel toolbarHolder = (JPanel) panels.get("Toolbar");
|
||||
if (toolbarHolder != null) {
|
||||
try {
|
||||
JSpinner bs = (JSpinner) toolbarHolder.getClientProperty("buttonSize");
|
||||
JSpinner is = (JSpinner) toolbarHolder.getClientProperty("iconSize");
|
||||
if (bs != null) config.setToolbarButtonSize((Integer) bs.getValue());
|
||||
if (is != null) config.setToolbarIconSize((Integer) is.getValue());
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
|
||||
// Save external editor path
|
||||
if (externalEditorField != null) {
|
||||
config.setExternalEditorPath(externalEditorField.getText());
|
||||
@ -173,6 +190,8 @@ public class SettingsDialog extends JDialog {
|
||||
config.setGlobalFont(originalGlobalFont);
|
||||
config.setEditorFont(originalEditorFont);
|
||||
config.setExternalEditorPath(originalExternalEditorPath);
|
||||
config.setToolbarButtonSize(originalToolbarButtonSize);
|
||||
config.setToolbarIconSize(originalToolbarIconSize);
|
||||
|
||||
// Notify UI to revert changes
|
||||
if (onChange != null) onChange.run();
|
||||
@ -459,6 +478,45 @@ public class SettingsDialog extends JDialog {
|
||||
return p;
|
||||
}
|
||||
|
||||
private JPanel buildToolbarPanel() {
|
||||
JPanel p = new JPanel(new BorderLayout(8, 8));
|
||||
JPanel grid = new JPanel(new GridBagLayout());
|
||||
grid.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
|
||||
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.insets = new Insets(4, 4, 4, 4);
|
||||
gbc.weightx = 1.0;
|
||||
|
||||
int row = 0;
|
||||
|
||||
// Button size
|
||||
gbc.gridx = 0; gbc.gridy = row; gbc.weightx = 0.0;
|
||||
grid.add(new JLabel("Button size (px):"), gbc);
|
||||
|
||||
JSpinner buttonSizeSpinner = new JSpinner(new SpinnerNumberModel(config.getToolbarButtonSize(), 16, 128, 1));
|
||||
gbc.gridx = 1; gbc.gridy = row++; gbc.weightx = 1.0;
|
||||
grid.add(buttonSizeSpinner, gbc);
|
||||
|
||||
// Icon size
|
||||
gbc.gridx = 0; gbc.gridy = row; gbc.weightx = 0.0;
|
||||
grid.add(new JLabel("Icon size (px):"), gbc);
|
||||
|
||||
JSpinner iconSizeSpinner = new JSpinner(new SpinnerNumberModel(config.getToolbarIconSize(), 16, 128, 1));
|
||||
gbc.gridx = 1; gbc.gridy = row++; gbc.weightx = 1.0;
|
||||
grid.add(iconSizeSpinner, gbc);
|
||||
|
||||
p.add(grid, BorderLayout.NORTH);
|
||||
|
||||
// Save action will be done on OK; store controls in a holder
|
||||
JPanel holder = new JPanel();
|
||||
holder.putClientProperty("buttonSize", buttonSizeSpinner);
|
||||
holder.putClientProperty("iconSize", iconSizeSpinner);
|
||||
panels.put("Toolbar", holder);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
private static String capitalize(String s) {
|
||||
if (s == null || s.isEmpty()) return s;
|
||||
return s.substring(0,1).toUpperCase() + s.substring(1).toLowerCase();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user