Skip to content

Commit b5ac4e0

Browse files
committed
- add option to auto resize device screen columns
1 parent 0073e13 commit b5ac4e0

File tree

5 files changed

+74
-67
lines changed

5 files changed

+74
-67
lines changed

src/main/java/com/jpage4500/devicemanager/ui/DeviceScreen.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ public void setupTable() {
289289
table.setDefaultRenderer(Device.class, new DeviceCellRenderer());
290290
table.setEmptyText("No Connected Devices!");
291291

292+
boolean autoResize = PreferenceUtils.getPreference(PreferenceUtils.PrefBoolean.PREF_DEVICE_AUTO_RESIZE, true);
293+
int flag = autoResize ? JTable.AUTO_RESIZE_ALL_COLUMNS : JTable.AUTO_RESIZE_OFF;
294+
table.setAutoResizeMode(flag);
295+
292296
// restore user-defined column sizes
293297
if (!table.restoreTable()) {
294298
// use some default column sizes
@@ -363,6 +367,15 @@ private JPopupMenu getPopupMenu(int row, int column) {
363367
adjuster.adjustColumn(column);
364368
});
365369
UiUtils.addPopupMenuItem(popupMenu, "Manage Columns", actionEvent -> SettingsDialog.showManageDeviceColumnsDialog(this));
370+
371+
boolean autoResize = PreferenceUtils.getPreference(PreferenceUtils.PrefBoolean.PREF_DEVICE_AUTO_RESIZE, true);
372+
String resizeDesc = autoResize ? "ON" : "OFF";
373+
UiUtils.addPopupMenuItem(popupMenu, "Auto Resize: " + resizeDesc, actionEvent -> {
374+
boolean update = !autoResize;
375+
PreferenceUtils.setPreference(PreferenceUtils.PrefBoolean.PREF_DEVICE_AUTO_RESIZE, update);
376+
int flag = update ? JTable.AUTO_RESIZE_ALL_COLUMNS : JTable.AUTO_RESIZE_OFF;
377+
table.setAutoResizeMode(flag);
378+
});
366379
return popupMenu;
367380
}
368381
return null;
@@ -942,7 +955,7 @@ private void extractApk(Device device, String key) {
942955
int pos = path.lastIndexOf('/');
943956
if (pos < 1) continue;
944957
DeviceFile file = new DeviceFile();
945-
file.name = path.substring(pos+1);
958+
file.name = path.substring(pos + 1);
946959
path = path.substring(0, pos);
947960

948961
File saveFile = new File(appFolder, file.name);

src/main/java/com/jpage4500/devicemanager/ui/dialog/SettingsDialog.java

+11-62
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import org.slf4j.LoggerFactory;
1515

1616
import javax.swing.*;
17-
import java.awt.event.MouseAdapter;
18-
import java.awt.event.MouseEvent;
1917
import java.io.File;
2018
import java.util.ArrayList;
2119
import java.util.List;
@@ -39,24 +37,24 @@ private SettingsDialog(DeviceScreen deviceScreen) {
3937
}
4038

4139
private void initalizeUi() {
42-
addButton("Manage Columns", "EDIT", () -> showManageDeviceColumnsDialog(deviceScreen));
43-
addButton("Custom Apps", "EDIT", this::showAppsSettings);
44-
addButton("Customize Toolbar", "EDIT", () -> showManageToolbar(deviceScreen));
45-
addButton("Download Location", "EDIT", this::showDownloadLocation);
46-
47-
addCheckbox("Minimize to System Tray", PreferenceUtils.PrefBoolean.PREF_EXIT_TO_TRAY, false, null);
48-
addCheckbox("Check for updates", PreferenceUtils.PrefBoolean.PREF_CHECK_UPDATES, true, isChecked -> deviceScreen.scheduleUpdateChecks());
49-
addCheckbox("Show background image", PreferenceUtils.PrefBoolean.PREF_SHOW_BACKGROUND, true, isChecked -> {
40+
UiUtils.addSettingButton(this, "Manage Columns", "EDIT", () -> showManageDeviceColumnsDialog(deviceScreen));
41+
UiUtils.addSettingButton(this, "Custom Apps", "EDIT", this::showAppsSettings);
42+
UiUtils.addSettingButton(this, "Customize Toolbar", "EDIT", () -> showManageToolbar(deviceScreen));
43+
UiUtils.addSettingButton(this, "Download Location", "EDIT", this::showDownloadLocation);
44+
45+
UiUtils.addSettingCheckbox(this, "Minimize to System Tray", PreferenceUtils.PrefBoolean.PREF_EXIT_TO_TRAY, false, null);
46+
UiUtils.addSettingCheckbox(this, "Check for updates", PreferenceUtils.PrefBoolean.PREF_CHECK_UPDATES, true, isChecked -> deviceScreen.scheduleUpdateChecks());
47+
UiUtils.addSettingCheckbox(this, "Show background image", PreferenceUtils.PrefBoolean.PREF_SHOW_BACKGROUND, true, isChecked -> {
5048
// force table background to be repainted
5149
deviceScreen.model.fireTableDataChanged();
5250
});
5351

54-
JButton logButton = addButton("Log Level", "EDIT", null);
52+
JButton logButton = UiUtils.addSettingButton(this, "Log Level", "EDIT", null);
5553
UiUtils.addClickListener(logButton, e -> toggleLogLevels(logButton));
5654
updateLogLevel(logButton);
5755

58-
addButton("View Logs", "VIEW", this::viewLogs);
59-
addButton("Reset Preferences", "RESET", this::resetPreferences);
56+
UiUtils.addSettingButton(this, "View Logs", "VIEW", this::viewLogs);
57+
UiUtils.addSettingButton(this, "Reset Preferences", "RESET", this::resetPreferences);
6058

6159
doLayout();
6260
invalidate();
@@ -102,55 +100,6 @@ private void toggleLogLevels(JButton logButton) {
102100
updateLogLevel(logButton);
103101
}
104102

105-
public interface ButtonListener {
106-
void onClicked();
107-
}
108-
109-
private JButton addButton(String label, String action, ButtonListener listener) {
110-
add(new JLabel(label));
111-
JButton button = new JButton(action);
112-
if (listener != null) {
113-
UiUtils.addClickListener(button, e -> {
114-
listener.onClicked();
115-
});
116-
}
117-
add(button, "wrap");
118-
return button;
119-
}
120-
121-
public interface CheckBoxListener {
122-
void onChecked(boolean isChecked);
123-
}
124-
125-
private void addCheckbox(String label, PreferenceUtils.PrefBoolean pref, boolean defaultValue, CheckBoxListener listener) {
126-
JLabel textLabel = new JLabel(label);
127-
add(textLabel);
128-
129-
JCheckBox checkbox = new JCheckBox();
130-
boolean currentChecked = PreferenceUtils.getPreference(pref, defaultValue);
131-
checkbox.setSelected(currentChecked);
132-
checkbox.setHorizontalTextPosition(SwingConstants.LEFT);
133-
add(checkbox, "align center, wrap");
134-
135-
checkbox.addActionListener(actionEvent -> {
136-
boolean selected = checkbox.isSelected();
137-
PreferenceUtils.setPreference(pref, selected);
138-
if (listener != null) listener.onChecked(selected);
139-
});
140-
141-
textLabel.addMouseListener(new MouseAdapter() {
142-
@Override
143-
public void mouseClicked(MouseEvent mouseEvent) {
144-
// TODO: fire checkbox action listener directly
145-
boolean selected = !checkbox.isSelected();
146-
checkbox.setSelected(selected);
147-
PreferenceUtils.setPreference(pref, selected);
148-
if (listener != null) listener.onChecked(selected);
149-
}
150-
});
151-
152-
}
153-
154103
private void resetPreferences() {
155104
if (!DialogHelper.showConfirmDialog(deviceScreen, "Reset Preferences", "Reset All Preferences?")) return;
156105

src/main/java/com/jpage4500/devicemanager/ui/views/CustomTable.java

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
import org.slf4j.LoggerFactory;
66

77
import javax.swing.*;
8-
import javax.swing.event.ChangeEvent;
9-
import javax.swing.event.ListSelectionEvent;
10-
import javax.swing.event.TableColumnModelEvent;
11-
import javax.swing.event.TableColumnModelListener;
128
import javax.swing.table.*;
139
import java.awt.*;
1410
import java.awt.dnd.DropTarget;

src/main/java/com/jpage4500/devicemanager/utils/PreferenceUtils.java

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public enum PrefBoolean {
4040
PREF_AUTO_FORMAT_MESSAGE,
4141
PREF_WRAP_MESSAGE,
4242
PREF_EXIT_TO_TRAY,
43+
PREF_DEVICE_AUTO_RESIZE,
4344
}
4445

4546
/**

src/main/java/com/jpage4500/devicemanager/utils/UiUtils.java

+48
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,52 @@ public static JMenuItem addMenuItem(JMenu menu, String label, ActionListener lis
139139
return menuItem;
140140
}
141141

142+
public interface ButtonListener {
143+
void onClicked();
144+
}
145+
146+
public static JButton addSettingButton(Container panel, String label, String action, ButtonListener listener) {
147+
panel.add(new JLabel(label));
148+
JButton button = new JButton(action);
149+
if (listener != null) {
150+
UiUtils.addClickListener(button, e -> {
151+
listener.onClicked();
152+
});
153+
}
154+
panel.add(button, "wrap");
155+
return button;
156+
}
157+
158+
public interface CheckBoxListener {
159+
void onChecked(boolean isChecked);
160+
}
161+
162+
public static JCheckBox addSettingCheckbox(Container panel, String label, PreferenceUtils.PrefBoolean pref, boolean defaultValue, CheckBoxListener listener) {
163+
JLabel textLabel = new JLabel(label);
164+
panel.add(textLabel);
165+
166+
JCheckBox checkbox = new JCheckBox();
167+
boolean currentChecked = PreferenceUtils.getPreference(pref, defaultValue);
168+
checkbox.setSelected(currentChecked);
169+
checkbox.setHorizontalTextPosition(SwingConstants.LEFT);
170+
panel.add(checkbox, "align center, wrap");
171+
172+
checkbox.addActionListener(actionEvent -> {
173+
boolean selected = checkbox.isSelected();
174+
PreferenceUtils.setPreference(pref, selected);
175+
if (listener != null) listener.onChecked(selected);
176+
});
177+
178+
textLabel.addMouseListener(new MouseAdapter() {
179+
@Override
180+
public void mouseClicked(MouseEvent mouseEvent) {
181+
// TODO: fire checkbox action listener directly
182+
boolean selected = !checkbox.isSelected();
183+
checkbox.setSelected(selected);
184+
PreferenceUtils.setPreference(pref, selected);
185+
if (listener != null) listener.onChecked(selected);
186+
}
187+
});
188+
return checkbox;
189+
}
142190
}

0 commit comments

Comments
 (0)