click display arrangement

Added options to NOT automatically rearrange all the windows in the
click display every time the display size changes
This commit is contained in:
Douglas Gillespie 2024-02-02 09:07:55 +00:00
parent c4192a7323
commit 0dc47fcb0b
4 changed files with 148 additions and 3 deletions

View File

@ -407,9 +407,14 @@ public class ClickDisplayManager implements PamSettings {
public Serializable getSettingsReference() {
cdmp.countEverything(this);
cdmp.saveDisplayLocations(getWindowList());
return cdmp;
}
public void restoreWindowSizes() {
cdmp.restoreWindowSizes(getWindowList());
}
public int countDisplays(Class displayType) {
int count = 0;
ArrayList<ClickDisplay> dw = getWindowList();

View File

@ -1,8 +1,13 @@
package clickDetector;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import Layout.PamInternalFrame;
import clickDetector.IDI_Display.IDIHistogramImage;
import PamController.PamController;
@ -35,6 +40,10 @@ public class ClickDisplayManagerParameters2 implements Cloneable, Serializable,
private boolean initialised = false;
private boolean manualWindowSizes = false;
private ArrayList<WindowSizeData> windowSizes = new ArrayList();
public ClickDisplayManagerParameters2() {
setDefaults();
}
@ -159,6 +168,11 @@ public class ClickDisplayManagerParameters2 implements Cloneable, Serializable,
return null;
}
/**
* This populates the serialised settings with lists of how many displays of
* each type there are.
* @param clickDisplayManager
*/
public void countEverything(ClickDisplayManager clickDisplayManager) {
lastMode = PamController.getInstance().getRunMode();
if (lastMode >= NMODES) lastMode = 0;
@ -208,4 +222,101 @@ public class ClickDisplayManagerParameters2 implements Cloneable, Serializable,
return ps;
}
/**
* Save windows sizes in an array list.
* @param windowList
*/
public void saveDisplayLocations(ArrayList<ClickDisplay> windowList) {
if (windowList == null) {
return;
}
getWindowSizes(); // make sure the array is created
windowSizes.clear();
for (ClickDisplay disp : windowList) {
Point loc = disp.getFrame().getLocation();
Dimension sz = disp.getFrame().getSize();
String cls = disp.getClass().toString();
windowSizes.add(new WindowSizeData(cls, loc, sz));
}
}
/**
* Try to restore window locations and sizes from a stored list.
* @param windowList
* @return
*/
public boolean restoreWindowSizes(ArrayList<ClickDisplay> windowList){
if (windowSizes == null || windowList == null) {
return false;
}
int resized = 0;
for (ClickDisplay disp : windowList) {
PamInternalFrame frame = disp.getFrame();
String cls = disp.getClass().toString();
// find an element in the list with that class.
WindowSizeData sizeData = null;
for (int i = 0; i < windowSizes.size(); i++) {
if (windowSizes.get(i).windowClass.equals(cls)) {
sizeData = windowSizes.remove(i);
break;
}
}
if (sizeData != null) {
frame.setLocation(sizeData.location);
frame.setSize(sizeData.size);
resized ++;
}
}
return resized > 0;
}
/**
* @return the windowSizes
*/
public ArrayList<WindowSizeData> getWindowSizes() {
if (windowSizes == null) {
windowSizes = new ArrayList<>();
}
return windowSizes;
}
/**
* @return the manualWindowSizes
*/
public boolean isManualWindowSizes() {
return manualWindowSizes;
}
/**
* @param manualWindowSizes the manualWindowSizes to set
*/
public void setManualWindowSizes(boolean manualWindowSizes) {
this.manualWindowSizes = manualWindowSizes;
}
private class WindowSizeData implements Serializable {
static public final long serialVersionUID = 1;
protected String windowClass;
public WindowSizeData(String windowClass, Point location, Dimension size) {
super();
this.windowClass = windowClass;
this.location = location;
this.size = size;
}
protected Point location;
protected Dimension size;
}
}

View File

@ -72,9 +72,19 @@ public class ClickTabPanel extends JDesktopPane implements ComponentListener {
public void componentMoved(ComponentEvent e) {
}
/**
* This get's called during startup when the window is created and will
* automatically resize everything. IT may get called 2 or 3 times at startup
* as components such as the side bar sort themselves out.
*/
public void componentResized(ComponentEvent e) {
// if (++resizeCount < 5) {
arrangeWindows();
if (clickTabPanelControl.clickDisplayManager.cdmp.isManualWindowSizes() == false) {
arrangeWindows();
}
else {
clickTabPanelControl.clickDisplayManager.restoreWindowSizes();
}
// }
}

View File

@ -26,6 +26,7 @@ import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
@ -117,11 +118,29 @@ public class ClickTabPanelControl implements PamTabPanel {
menu.add(clickDisplayManager.getModulesMenu());
menuItem = new JMenuItem("Arrange Windows ...");
menu.add(clickControl.angleVetoes.getDisplayMenuItem(parentFrame));
menu.addSeparator();
JCheckBoxMenuItem autoArrange = new JCheckBoxMenuItem("Auto arrange windows");
autoArrange.setSelected(clickDisplayManager.cdmp.isManualWindowSizes() == false);
autoArrange.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clickDisplayManager.cdmp.setManualWindowSizes(autoArrange.isSelected() == false);
if (autoArrange.isSelected()) {
clickPanel.arrangeWindows();
}
}
});
autoArrange.setToolTipText("Automatically arrange windows in a standard layout whenever the display dimensions change");
menu.add(autoArrange);
menuItem = new JMenuItem("Arrange Windows Now");
menuItem.addActionListener(new ArrangeWindows(parentFrame));
menuItem.setToolTipText("Automatically arrange windows in a standard layout");
menu.add(menuItem);
menu.add(clickControl.angleVetoes.getDisplayMenuItem(parentFrame));
return menu;
}