Skip to content

Commit

Permalink
merging of Groups
Browse files Browse the repository at this point in the history
  • Loading branch information
ekatrukha committed Jun 26, 2024
1 parent 2576a2f commit 9afc3fd
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/main/java/bigtrace/BigTrace.java
Original file line number Diff line number Diff line change
Expand Up @@ -1572,8 +1572,8 @@ public static void main(String... args) throws Exception
BigTrace testI = new BigTrace();

//testI.run("");
testI.run("/home/eugene/Desktop/projects/BigTrace/BigTrace_data/ExM_MT.tif");
//testI.run("/home/eugene/Desktop/projects/BigTrace/BT_tracks/Snejana_small_example.tif");
//testI.run("/home/eugene/Desktop/projects/BigTrace/BigTrace_data/ExM_MT.tif");
testI.run("/home/eugene/Desktop/projects/BigTrace/BT_tracks/Snejana_small_example.tif");

/*
testI.roiManager.setLockMode(true);
Expand Down
188 changes: 143 additions & 45 deletions src/main/java/bigtrace/rois/Roi3DGroupManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JDialog;
Expand Down Expand Up @@ -56,10 +57,12 @@ public class Roi3DGroupManager < T extends RealType< T > & NativeType< T > > imp
JButton butEdit;
JButton butCopyNew;
JButton butDelete;
JButton butMerge;
JButton butSave;
JButton butLoad;



RoiManager3D <T> roiManager;

public ColorUserSettings selectColors = new ColorUserSettings();
Expand All @@ -80,14 +83,11 @@ public void initGUI()
listScroller = new JScrollPane(jlist);
listScroller.setPreferredSize(new Dimension(170, 400));
listScroller.setMinimumSize(new Dimension(170, 250));




for (int i = 0;i<roiManager.groups.size();i++)
{
listModel.addElement(roiManager.groups.get(i).getName());
}

}

presetList = new JPanel(new GridBagLayout());
//presetList.setBorder(new PanelTitle(" Groups Manager "));
Expand All @@ -98,6 +98,8 @@ public void initGUI()
butCopyNew.addActionListener(this);
butDelete = new JButton("Delete");
butDelete.addActionListener(this);
butMerge = new JButton("Merge");
butMerge.addActionListener(this);
butSave = new JButton("Save");
butSave.addActionListener(this);
butLoad = new JButton("Load");
Expand All @@ -122,6 +124,8 @@ public void initGUI()
cr.gridy++;
presetList.add(butDelete,cr);
cr.gridy++;
presetList.add(butMerge,cr);
cr.gridy++;
presetList.add(butSave,cr);
cr.gridy++;
presetList.add(butLoad,cr);
Expand All @@ -144,9 +148,71 @@ public void show()
dialog.setVisible(true);
}

/** show Group Properties dialog**/
void dialogMerge(int indList)
{

JPanel dialMerge = new JPanel(new GridBagLayout());
GridBagConstraints cd = new GridBagConstraints();
//make a selection list of non-selected groups
//ask user what he wants to do with ROIs
String [] sGroupToMerge = new String [roiManager.groups.size()-1];
int nCount = 0;
for(int i=0;i<roiManager.groups.size();i++)
{
if(i!=indList)
{
sGroupToMerge[nCount] = roiManager.groups.get( i ).getName();
nCount++;
}
}
JComboBox<String> cbGroup = new JComboBox<>(sGroupToMerge);

JCheckBox cbDeleteGroup = new JCheckBox();
cbDeleteGroup .setSelected( Prefs.get( "BigTrace.bMergeDeleteGroup", true ) );
cd.gridx=0;
cd.gridy=0;
cd.gridwidth = 2;
dialMerge.add(new JLabel("Move ROIs from group "+roiManager.groups.get( indList ).getName() +" to"),cd);
cd.gridy++;
dialMerge.add(cbGroup,cd);
if(indList!=0)
{
cd.gridwidth = 1;
cd.gridy++;
dialMerge.add(new JLabel("and delete this group"),cd);
cd.gridx++;
dialMerge.add(cbDeleteGroup,cd);

}
int reply = JOptionPane.showConfirmDialog(null, dialMerge, "Merge Groups",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

if (reply == JOptionPane.OK_OPTION)
{
boolean bDeleteGroup = false;
if(indList!=0)
{
bDeleteGroup = cbDeleteGroup.isSelected();
Prefs.set( "BigTrace.bMergeDeleteGroup", bDeleteGroup );
}
//get the index of the group to merge
int nGroupMergeInd = cbGroup.getSelectedIndex();
if(nGroupMergeInd>=indList)
{
nGroupMergeInd++;
}
roiManager.moveROIsGroups(indList,nGroupMergeInd);
//System.out.println(roiManager.groups.get(nGroupMergeInd).getName());
if(bDeleteGroup)
{
deleteGroupAndCorrectIndex(indList);
}
}
}

/** show Group Properties dialog**/
public boolean dialPropertiesShow(final Roi3DGroup preset, boolean bNameChangable)
public boolean dialogPropertiesShow(final Roi3DGroup preset, boolean bNameChangable)
{
JPanel dialProperties = new JPanel(new GridBagLayout());
GridBagConstraints cd = new GridBagConstraints();
Expand Down Expand Up @@ -193,8 +259,7 @@ public boolean dialPropertiesShow(final Roi3DGroup preset, boolean bNameChangabl
butLineColor.setIcon(new ColorIcon(newColor));
}

});

});

JButton butSaveAsDefault = new JButton ("Save as new default");

Expand Down Expand Up @@ -328,7 +393,7 @@ public void actionPerformed( ActionEvent e )
}

/** Save Groups dialog and saving **/
public void diagSaveGroups()
public void dialogSaveGroups()
{
String filename;
//int nGroupN, nGroup;
Expand Down Expand Up @@ -359,7 +424,6 @@ public void diagSaveGroups()

}


public void saveGroups (FileWriter writer)
{
int nGroupN, nGroup;
Expand All @@ -385,8 +449,8 @@ public void saveGroups (FileWriter writer)
}
}

/** Load Groups dialog and saving **/
public void diagLoadGroups()
/** Load Groups dialog **/
public void dialogLoadGroups()
{
String filename;

Expand Down Expand Up @@ -562,19 +626,22 @@ public int loadGroups(BufferedReader br)


@Override
public void valueChanged(ListSelectionEvent e) {
public void valueChanged(ListSelectionEvent e)
{
if (jlist.getSelectedIndex() == -1)
{
//No selection
// should not happen
//should not happen

} else if (jlist.getSelectedIndices().length > 1) {
//Multiple selection:

} else {
//Single selection:
//should not happen
}
else
{
//Single selection:
//undefined group, cannot edit or delete
if(jlist.getSelectedIndex() ==0)
if(jlist.getSelectedIndex() == 0)
{
//butEdit.setEnabled(false);
butDelete.setEnabled(false);
Expand All @@ -584,7 +651,9 @@ public void valueChanged(ListSelectionEvent e) {
//butEdit.setEnabled(true);
butDelete.setEnabled(true);
}

}
updateMergeButton();

}

Expand All @@ -608,7 +677,7 @@ public void actionPerformed(ActionEvent ae)
{
bNameChange = true;
}
if(dialPropertiesShow(roiManager.groups.get(indList),bNameChange))
if(dialogPropertiesShow(roiManager.groups.get(indList),bNameChange))
{
listModel.set(indList,roiManager.groups.get(indList).getName());
roiManager.updateROIsGroupDisplay(indList);
Expand All @@ -626,28 +695,32 @@ public void actionPerformed(ActionEvent ae)
{
newGroup = new Roi3DGroup(roiManager.groups.get(indList), roiManager.groups.get(indList).getName()+"_copy");
}
if(dialPropertiesShow(newGroup, true))
if(dialogPropertiesShow(newGroup, true))
{
addGroup(newGroup);
}

}
//DELETE
if(ae.getSource() == butDelete)
{

{
deleteGroup(indList);
}
//DELETE
if(ae.getSource() == butMerge)
{
dialogMerge(indList);
}
//SAVE
if(ae.getSource() == butSave)
{

diagSaveGroups();
dialogSaveGroups();
}
//LOAD
if(ae.getSource() == butLoad)
{
diagLoadGroups();
dialogLoadGroups();
}

}
Expand All @@ -658,6 +731,20 @@ public void addGroup(Roi3DGroup newGroup_)
{
roiManager.groups.add(newGroup_);
listModel.addElement(newGroup_.getName());
updateMergeButton();

}

void updateMergeButton()
{
if(roiManager.groups.size()<2)
{
butMerge.setEnabled( false );
}
else
{
butMerge.setEnabled( true );
}
}
/** deletes Group and asks what to do with ROIs **/
void deleteGroup(int indList)
Expand Down Expand Up @@ -694,36 +781,47 @@ void deleteGroup(int indList)
return;
if(input.equals("Mark these ROIs as *undefined*"))
{
roiManager.markROIsUndefined(indList);
//roiManager.markROIsUndefined(indList);
roiManager.moveROIsGroups( indList, 0 );
Prefs.set("BigTrace.DeleteGroup", 0);
}
else
{
roiManager.deleteROIGroup(indList);
Prefs.set("BigTrace.DeleteGroup", 1);
roiManager.deleteROIsBelongingToGroup(indList);

}
}
deleteGroupAndCorrectIndex(indList);

//correct indexing
for (Roi3D roi : roiManager.rois)
}
updateMergeButton();
}

void deleteGroupAndCorrectIndex(int indList)
{
//correct indexing
for (Roi3D roi : roiManager.rois)
{
if(roi.getGroupInd()>indList)
{
if(roi.getGroupInd()>indList)
{
roi.setGroupInd(roi.getGroupInd()-1);
}
}
//delete group itself
roiManager.groups.remove(indList);
listModel.removeElementAt(indList);
roi.setGroupInd(roi.getGroupInd()-1);
}
}

//delete group itself
roiManager.groups.remove(indList);
listModel.removeElementAt(indList);


//select previous Group
if(indList==0)
{
jlist.setSelectedIndex(0);
}
else
{
jlist.setSelectedIndex(indList-1);
}
//select previous Group
if(indList==0)
{
jlist.setSelectedIndex(0);
}
else
{
jlist.setSelectedIndex(indList-1);
}
}

Expand Down
22 changes: 17 additions & 5 deletions src/main/java/bigtrace/rois/RoiManager3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -1563,14 +1563,26 @@ public void selectClosestToLineRoi(Line3D clickLine)
}

/** marks ROIs of specific group as undefined and updates ROI indexes**/
public void markROIsUndefined(int nGroupN)
// public void markROIsUndefined(int nGroupN)
// {
// for (int i=0;i<rois.size();i++)
// {
// if(rois.get(i).getGroupInd()==nGroupN)
// {
// rois.get(i).setGroupInd(0);
// listModel.setElementAt(rois.get(i).getName(), i);
// }
// }
// }
/** moves ROIs from nGroupFrom index to group with nGroupTo index **/
public void moveROIsGroups(final int nGroupFrom, final int nGroupTo)
{
for (int i=0;i<rois.size();i++)
{
if(rois.get(i).getGroupInd()==nGroupN)
if(rois.get(i).getGroupInd() == nGroupFrom)
{
rois.get(i).setGroupInd(0);
listModel.setElementAt(rois.get(i).getName(), i);
rois.get(i).setGroupInd(nGroupTo);
listModel.setElementAt(getGroupPrefixRoiName(rois.get(i)), i);
}
}
}
Expand Down Expand Up @@ -1649,7 +1661,7 @@ public void applyGroupToROI(Roi3D roiIn, Roi3DGroup rGroup)


/** deletes ROIs of specific group **/
public void deleteROIGroup(int nGroupN)
public void deleteROIsBelongingToGroup(int nGroupN)
{
for (int i=(rois.size()-1);i>=0;i--)
{
Expand Down

0 comments on commit 9afc3fd

Please sign in to comment.