diff --git a/GUI/src/main/java/cz/fidentis/analyst/project/FaceStatePanel.form b/GUI/src/main/java/cz/fidentis/analyst/project/FaceStatePanel.form index 496cdadcc21e3b3ed2ec86e24c132d701d7359ef..e7dae1ad568b1474ef15b4d8173ac644dc1ae2c6 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/project/FaceStatePanel.form +++ b/GUI/src/main/java/cz/fidentis/analyst/project/FaceStatePanel.form @@ -46,7 +46,7 @@ <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo"> - <TitledBorder title="<FaceStatePanel.filePanel.border.title>"> + <TitledBorder title="File info"> <ResourceString PropertyName="titleX" bundle="cz/fidentis/analyst/project/Bundle.properties" key="FaceStatePanel.filePanel.border.title" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> <Font PropertyName="font" name="Dialog" size="12" style="1"/> </TitledBorder> @@ -132,7 +132,7 @@ <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo"> - <TitledBorder title="<FaceStatePanel.facePanel.border.title>"> + <TitledBorder title="Face info"> <ResourceString PropertyName="titleX" bundle="cz/fidentis/analyst/project/Bundle.properties" key="FaceStatePanel.facePanel.border.title" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> <Font PropertyName="font" name="Dialog" size="12" style="1"/> </TitledBorder> @@ -263,7 +263,7 @@ <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo"> - <TitledBorder title="<FaceStatePanel.photoPanel.border.title>"> + <TitledBorder title="Photo"> <ResourceString PropertyName="titleX" bundle="cz/fidentis/analyst/project/Bundle.properties" key="FaceStatePanel.photoPanel.border.title" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> <Font PropertyName="font" name="Dialog" size="12" style="1"/> </TitledBorder> diff --git a/GUI/src/main/java/cz/fidentis/analyst/project/FaceStatePanel.java b/GUI/src/main/java/cz/fidentis/analyst/project/FaceStatePanel.java index 4cd359e1b845209d1a302cb783913dc497c6d668..814b860e9fd5ca1cc6bb3de94edcfc487134ca6c 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/project/FaceStatePanel.java +++ b/GUI/src/main/java/cz/fidentis/analyst/project/FaceStatePanel.java @@ -1,10 +1,6 @@ package cz.fidentis.analyst.project; import cz.fidentis.analyst.core.ControlPanel; -import cz.fidentis.analyst.project.events.FaceDeselected; -import cz.fidentis.analyst.project.events.ProjectListener; -import cz.fidentis.analyst.project.events.FaceSelected; -import cz.fidentis.analyst.project.events.ProjectEvent; import cz.fidentis.analyst.face.HumanFace; import java.awt.Image; import java.awt.event.ActionListener; @@ -19,7 +15,7 @@ import javax.swing.ImageIcon; * * @author Matej Kovar */ -public class FaceStatePanel extends ControlPanel implements ProjectListener { +public class FaceStatePanel extends ControlPanel { private final ImageIcon notCheck = new ImageIcon(FaceStatePanel.class.getClassLoader().getResource("/" + "notCheck16x16.png")); private final ImageIcon check = new ImageIcon(FaceStatePanel.class.getClassLoader().getResource("/" + "check16x16.png")); @@ -372,15 +368,21 @@ public class FaceStatePanel extends ControlPanel implements ProjectListener { faceNotLoadedLabel.setVisible(false); loadFaceButton.setVisible(false); } - - @Override - public void acceptEvent(ProjectEvent event) { - if (event.getClass() == FaceSelected.class) { - FaceSelected evt = (FaceSelected)event; - this.showFaceState(evt.getFace(), evt.getName(), evt.getPath()); - } else if (event.getClass() == FaceDeselected.class){ + + /** + * Face from list is (de)selected + * @param selected true if face is selected, false if deselected + * @param face HumanFace + * @param name String name of face + * @param path Path to face + */ + public void newSelection(boolean selected, HumanFace face, String name, Path path) { + + if (selected) { + this.showFaceState(face, name, path); + } else { this.deselectFace(); - } + } } // Variables declaration - do not modify//GEN-BEGIN:variables diff --git a/GUI/src/main/java/cz/fidentis/analyst/project/FilterPanel.form b/GUI/src/main/java/cz/fidentis/analyst/project/FilterPanel.form index 7e703acc9e585d41e14d98fd86cc8f1f04ef9c82..c8e1b487a3fe9dc0aae95a17f2430572efd0a0a1 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/project/FilterPanel.form +++ b/GUI/src/main/java/cz/fidentis/analyst/project/FilterPanel.form @@ -38,7 +38,7 @@ <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo"> - <TitledBorder title="<FilterPanel.filterPanel.border.title>"> + <TitledBorder title="Filter settings"> <ResourceString PropertyName="titleX" bundle="cz/fidentis/analyst/project/Bundle.properties" key="FilterPanel.filterPanel.border.title" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> <Font PropertyName="font" name="Dialog" size="12" style="1"/> </TitledBorder> diff --git a/GUI/src/main/java/cz/fidentis/analyst/project/FilterPanel.java b/GUI/src/main/java/cz/fidentis/analyst/project/FilterPanel.java index 40911de855153597dd1246e4d32772b2f622d9d8..4a56dafd0156ca3363690dfdd0148eed4ef69108 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/project/FilterPanel.java +++ b/GUI/src/main/java/cz/fidentis/analyst/project/FilterPanel.java @@ -1,9 +1,6 @@ package cz.fidentis.analyst.project; import cz.fidentis.analyst.core.ControlPanel; -import cz.fidentis.analyst.project.events.AllFacesLoaded; -import cz.fidentis.analyst.project.events.ProjectEvent; -import cz.fidentis.analyst.project.events.ProjectListener; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JCheckBox; @@ -12,7 +9,7 @@ import javax.swing.JCheckBox; * * @author Matej Kovar */ -public class FilterPanel extends ControlPanel implements ProjectListener { +public class FilterPanel extends ControlPanel { private boolean kdTreeFilter = false; private boolean featurePointsFilter = false; @@ -29,7 +26,6 @@ public class FilterPanel extends ControlPanel implements ProjectListener { this.setName(NAME); initComponents(); loadAllModelsButton.addActionListener(listenerLoadAllFaces); - //applyFilterButton.addActionListener(buttonListener); } /** @@ -210,18 +206,6 @@ public class FilterPanel extends ControlPanel implements ProjectListener { loadAllModelsButton.setVisible(!isAllFacesLoaded); applyFilterButton.setEnabled(isAllFacesLoaded); } - - @Override - public void acceptEvent(ProjectEvent event) { - - if (event.getClass() == AllFacesLoaded.class) { - - AllFacesLoaded evt = (AllFacesLoaded)event; - this.checkAllFacesLoaded(evt.isAllFacesLoaded()); - } - } - - // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox alphabetical; diff --git a/GUI/src/main/java/cz/fidentis/analyst/project/ProjectPanel.java b/GUI/src/main/java/cz/fidentis/analyst/project/ProjectPanel.java index 2d7a4632242493780688a205ea645d69ab5c736d..bfea4b25deb5e15b4c50c57644cac8c7257b2803 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/project/ProjectPanel.java +++ b/GUI/src/main/java/cz/fidentis/analyst/project/ProjectPanel.java @@ -1,16 +1,10 @@ package cz.fidentis.analyst.project; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.eventbus.EventBus; import cz.fidentis.analyst.Project; import cz.fidentis.analyst.ProjectConfiguration; import cz.fidentis.analyst.core.FaceTab; -import cz.fidentis.analyst.project.events.AllFacesLoaded; -import cz.fidentis.analyst.project.events.FaceDeselected; -import cz.fidentis.analyst.project.events.FaceSelected; -import cz.fidentis.analyst.project.events.ProjectListener; import cz.fidentis.analyst.face.HumanFace; -import cz.fidentis.analyst.face.events.HumanFaceEvent; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; @@ -48,7 +42,9 @@ public class ProjectPanel extends JPanel { private ObjectMapper mapper = new ObjectMapper(); - private final transient EventBus eventBus; + private FaceStatePanel faceStatePanel; + + private FilterPanel filterPanel; /** * Creates new form ProjectPanel @@ -58,9 +54,7 @@ public class ProjectPanel extends JPanel { project = new Project(); initComponents(); - eventBus = new EventBus(); - openExistingOrNewProject(); } /** @@ -303,11 +297,18 @@ public class ProjectPanel extends JPanel { ); }// </editor-fold>//GEN-END:initComponents + public void setFaceStatePanel(FaceStatePanel faceStatePanel) { + this.faceStatePanel = faceStatePanel; + } + + public void setFilterPanel(FilterPanel filterPanel) { + this.filterPanel = filterPanel; + } + public boolean isProjectSaved() { return project.isSaved(); } - private void newProjectButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_newProjectButtonMouseClicked if (loadNewProject()) { newProject(); @@ -413,42 +414,8 @@ public class ProjectPanel extends JPanel { private void addButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addButtonMouseClicked loadModel(false); }//GEN-LAST:event_addButtonMouseClicked - - /** - * Registers listeners (objects concerned in the project changes) to receive events. - * If listener is {@code null}, no exception is thrown and no action is taken. - * - * @param listener Listener concerned in the project changes. - */ - public void registerListener(ProjectListener listener) { - if (eventBus != null) { - eventBus.register(listener); - } - } - - /** - * Unregisters listeners from receiving events. - * - * @param listener Registered listener - */ - public void unregisterListener(ProjectListener listener) { - if (eventBus != null) { - eventBus.unregister(listener); - } - } /** - * Broadcast event to registered listeners. - * - * @param evt Event to be triggered. - */ - public void announceEvent(HumanFaceEvent evt) { - if (evt != null && eventBus != null) { - eventBus.post(evt); - } - } - - /** * Removes selected faces (those which are checked in check boxes) */ private void removeSelectedFaces() { @@ -542,9 +509,8 @@ public class ProjectPanel extends JPanel { model.addRowWithName(name, preview); - if (eventBus != null) { - eventBus.post(new AllFacesLoaded(false)); - } + filterPanel.checkAllFacesLoaded(false); + } else { JOptionPane.showMessageDialog(this, String.format("Model with name %s is already loaded", name)); } @@ -692,18 +658,10 @@ public class ProjectPanel extends JPanel { * @param selected Boolean true if some face is selected from list, false otherwise */ private void checkFaceState(String faceName, boolean selected) { - - if (eventBus != null) { - - if (selected) { - HumanFace face = project.getFaceByName(faceName); - Path path = project.getCfg().getPathToFaceByName(faceName); - eventBus.post(new FaceSelected(face, faceName, path)); - } else { - eventBus.post(new FaceDeselected()); - } - - } + + HumanFace face = project.getFaceByName(faceName); + Path path = project.getCfg().getPathToFaceByName(faceName); + faceStatePanel.newSelection(selected, face, faceName, path); } @@ -759,7 +717,7 @@ public class ProjectPanel extends JPanel { * Asks user whether he wants to create new empty project, or open existing * project */ - private void openExistingOrNewProject() { + public void openExistingOrNewProject() { ImageIcon newProjectImage = new ImageIcon(ProjectTopComp.class.getClassLoader().getResource("/" + "new.png")); ImageIcon existingProjectImage = new ImageIcon(ProjectTopComp.class.getClassLoader().getResource("/" + "open.png")); Object[] options = {newProjectImage, existingProjectImage}; @@ -915,7 +873,7 @@ public class ProjectPanel extends JPanel { } /** - * Checks whether all faces from list are loaded to project and informs listeners + * Checks whether all faces from list are loaded to project */ public void areAllFacesLoadedToProject() { @@ -923,20 +881,17 @@ public class ProjectPanel extends JPanel { HumanFace face = project.getFaceByName(model.getValueAt(i, 1).toString()); if (face == null) { - if (eventBus != null) { - eventBus.post(new AllFacesLoaded(false)); - } + filterPanel.checkAllFacesLoaded(false); return; } } - if (eventBus != null) { - eventBus.post(new AllFacesLoaded(true)); - } + filterPanel.checkAllFacesLoaded(true); + } /** - * Loads all faces from list to project and informs project listeners about it + * Loads all faces from list to project */ public void loadAllFaces() { @@ -947,9 +902,8 @@ public class ProjectPanel extends JPanel { } - if (eventBus != null) { - eventBus.post(new AllFacesLoaded(true)); - } + filterPanel.checkAllFacesLoaded(true); + } // Variables declaration - do not modify//GEN-BEGIN:variables diff --git a/GUI/src/main/java/cz/fidentis/analyst/project/ProjectTopComp.java b/GUI/src/main/java/cz/fidentis/analyst/project/ProjectTopComp.java index f2b68bd7e3d2bcec48f647cd06392d5941eb049b..f9581d2e833f5933c5963a125cecacf4e9ed1513 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/project/ProjectTopComp.java +++ b/GUI/src/main/java/cz/fidentis/analyst/project/ProjectTopComp.java @@ -5,7 +5,6 @@ import cz.fidentis.analyst.core.OutputWindowThread; import cz.fidentis.analyst.core.TopControlPanel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import javax.swing.AbstractAction; import javax.swing.GroupLayout; import javax.swing.JScrollPane; import javax.swing.LayoutStyle; @@ -74,46 +73,40 @@ public final class ProjectTopComp extends TopComponent { // Face State Panel // Listener for loading currently selected face (to show face state) - ActionListener listenerLoadFace = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - projectPanel.loadCurrentlySelectedFace(); - } + ActionListener listenerLoadFace = (ActionEvent e) -> { + projectPanel.loadCurrentlySelectedFace(); }; FaceStatePanel facePanel = new FaceStatePanel(listenerLoadFace); this.controlPanel.addTab(facePanel.getName(), facePanel.getIcon(), facePanel); this.controlPanel.setSelectedComponent(facePanel); - projectPanel.registerListener(facePanel); + projectPanel.setFaceStatePanel(facePanel); // Filter Panel // Listener for loading all faces - to enable filtering - ActionListener listenerLoadAllFaces = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - projectPanel.loadAllFaces(); - } + ActionListener listenerLoadAllFaces = (ActionEvent e) -> { + projectPanel.loadAllFaces(); }; FilterPanel filterPanel = new FilterPanel(listenerLoadAllFaces); this.controlPanel.addTab(filterPanel.getName(), filterPanel.getIcon(), filterPanel); // Listener for applying filter on faces - ActionListener listenerFilter = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - projectPanel.applyFilter(filterPanel.isFeaturePointsFilter(), filterPanel.isKdTreeFilter(), filterPanel.isAlphabeticalFilter()); - } + ActionListener listenerFilter = (ActionEvent e) -> { + projectPanel.applyFilter(filterPanel.isFeaturePointsFilter(), filterPanel.isKdTreeFilter(), filterPanel.isAlphabeticalFilter()); }; - - projectPanel.registerListener(filterPanel); + filterPanel.setFilterActionListener(listenerFilter); + projectPanel.setFilterPanel(filterPanel); this.openAtTabPosition(0); this.toFront(); this.requestActive(); + // Asks user whether he wants to create new project or open existing + projectPanel.openExistingOrNewProject(); + } private void initComponents() { diff --git a/GUI/src/main/java/cz/fidentis/analyst/project/events/AllFacesLoaded.java b/GUI/src/main/java/cz/fidentis/analyst/project/events/AllFacesLoaded.java deleted file mode 100644 index 437dc46ddf4c5ddb5ac1e6a9e0cbef4fa6e360d5..0000000000000000000000000000000000000000 --- a/GUI/src/main/java/cz/fidentis/analyst/project/events/AllFacesLoaded.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package cz.fidentis.analyst.project.events; - -/** - * - * @author Matej Kovar - */ -public class AllFacesLoaded extends ProjectEvent { - - private boolean allFacesLoaded; - - /** - * All faces loaded event constructor - * @param allFacesLoaded Boolean - */ - public AllFacesLoaded(boolean allFacesLoaded) { - this.allFacesLoaded = allFacesLoaded; - } - - public boolean isAllFacesLoaded() { - return allFacesLoaded; - } - -} diff --git a/GUI/src/main/java/cz/fidentis/analyst/project/events/FaceDeselected.java b/GUI/src/main/java/cz/fidentis/analyst/project/events/FaceDeselected.java deleted file mode 100644 index 89cf01a5d3642c5c4b755e85931896e6409e1cf1..0000000000000000000000000000000000000000 --- a/GUI/src/main/java/cz/fidentis/analyst/project/events/FaceDeselected.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package cz.fidentis.analyst.project.events; - -/** - * - * @author Matej Kovar - */ -public class FaceDeselected extends ProjectEvent { - -} diff --git a/GUI/src/main/java/cz/fidentis/analyst/project/events/FaceSelected.java b/GUI/src/main/java/cz/fidentis/analyst/project/events/FaceSelected.java deleted file mode 100644 index be9579a70239e01eb8457b958b602d81d882862f..0000000000000000000000000000000000000000 --- a/GUI/src/main/java/cz/fidentis/analyst/project/events/FaceSelected.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package cz.fidentis.analyst.project.events; - -import cz.fidentis.analyst.face.HumanFace; -import java.nio.file.Path; - -/** - * - * @author Matej Kovar - */ -public class FaceSelected extends ProjectEvent { - - private HumanFace face; - private String name; - private Path path; - - /** - * Face selected event constructor - * @param face HumanFace - * @param name String - * @param path Path - */ - public FaceSelected(HumanFace face, String name, Path path) { - this.face = face; - this.name = name; - this.path = path; - } - - public HumanFace getFace() { - return face; - } - - public String getName() { - return name; - } - - public Path getPath() { - return path; - } -} diff --git a/GUI/src/main/java/cz/fidentis/analyst/project/events/ProjectEvent.java b/GUI/src/main/java/cz/fidentis/analyst/project/events/ProjectEvent.java deleted file mode 100644 index be8fbabc839bba262e3f2899a9320906559a366e..0000000000000000000000000000000000000000 --- a/GUI/src/main/java/cz/fidentis/analyst/project/events/ProjectEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package cz.fidentis.analyst.project.events; - -/** - * - * @author Matej Kovar - */ -public class ProjectEvent { - -} diff --git a/GUI/src/main/java/cz/fidentis/analyst/project/events/ProjectListener.java b/GUI/src/main/java/cz/fidentis/analyst/project/events/ProjectListener.java deleted file mode 100644 index 24097e6d8f4d298a8f05d148cfa1a49d98983738..0000000000000000000000000000000000000000 --- a/GUI/src/main/java/cz/fidentis/analyst/project/events/ProjectListener.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package cz.fidentis.analyst.project.events; - -import com.google.common.eventbus.Subscribe; - -/** - * - * @author Matej Kovar - */ -public interface ProjectListener { - - /** - * Subscription method, which is invoked when an event appears. - * - * @param event A fired event. - */ - @Subscribe - void acceptEvent(ProjectEvent event); -}