X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fgui%2FSelectorDisplay.java;h=0f2b66b4610c93a102c7289414fac6af2c27c703;hb=4d5796d02a15808311c09448d79e6e7d1de9d636;hp=28e0a95b14a2dc6e3915a6f1f62d9e50d422a7f7;hpb=52bf9e8686c916be37a26a0b75340393d4478b05;p=GpsPrune.git diff --git a/tim/prune/gui/SelectorDisplay.java b/tim/prune/gui/SelectorDisplay.java index 28e0a95..0f2b66b 100644 --- a/tim/prune/gui/SelectorDisplay.java +++ b/tim/prune/gui/SelectorDisplay.java @@ -16,14 +16,13 @@ import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollBar; import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; import javax.swing.border.EtchedBorder; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import tim.prune.DataSubscriber; import tim.prune.I18nManager; -import tim.prune.data.DataPoint; -import tim.prune.data.Photo; import tim.prune.data.TrackInfo; /** @@ -39,12 +38,21 @@ public class SelectorDisplay extends GenericDisplay private JScrollBar _scroller = null; private boolean _ignoreScrollEvents = false; - // Photos - private JList _photoList = null; - private PhotoListModel _photoListModel = null; + // Panel containing lists + private JPanel _listsPanel = null; + private int _visiblePanels = 1; // Waypoints + private JPanel _waypointListPanel = null; private JList _waypointList = null; private WaypointListModel _waypointListModel = null; + // Photos + private JPanel _photoListPanel = null; + private JList _photoList = null; + private MediaListModel _photoListModel = null; + // Audio files + private JPanel _audioListPanel = null; + private JList _audioList = null; + private MediaListModel _audioListModel = null; // scrollbar interval private static final int SCROLLBAR_INTERVAL = 50; @@ -79,22 +87,22 @@ public class SelectorDisplay extends GenericDisplay _trackpointsLabel = new JLabel(I18nManager.getText("details.notrack")); trackDetailsPanel.add(_trackpointsLabel); _filenameLabel = new JLabel(""); + _filenameLabel.setMinimumSize(new Dimension(120, 10)); trackDetailsPanel.add(_filenameLabel); // Scroll bar _scroller = new JScrollBar(JScrollBar.HORIZONTAL, 0, SCROLLBAR_INTERVAL, 0, 100); _scroller.addAdjustmentListener(new AdjustmentListener() { - public void adjustmentValueChanged(AdjustmentEvent e) - { + public void adjustmentValueChanged(AdjustmentEvent e) { selectPoint(e.getValue()); } }); _scroller.setEnabled(false); // Add panel for waypoints / photos - JPanel listsPanel = new JPanel(); - listsPanel.setLayout(new GridLayout(0, 1)); - listsPanel.setBorder(BorderFactory.createCompoundBorder( + _listsPanel = new JPanel(); + _listsPanel.setLayout(new GridLayout(0, 1)); + _listsPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(3, 3, 3, 3)) ); _waypointListModel = new WaypointListModel(_trackInfo.getTrack()); @@ -104,27 +112,37 @@ public class SelectorDisplay extends GenericDisplay public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) selectWaypoint(_waypointList.getSelectedIndex()); - }}); - JPanel waypointListPanel = new JPanel(); - waypointListPanel.setLayout(new BorderLayout()); - waypointListPanel.add(new JLabel(I18nManager.getText("details.waypointsphotos.waypoints")), BorderLayout.NORTH); - waypointListPanel.add(new JScrollPane(_waypointList), BorderLayout.CENTER); - listsPanel.add(waypointListPanel); + } + }); + _waypointListPanel = makeListPanel("details.lists.waypoints", _waypointList); + _listsPanel.add(_waypointListPanel); // photo list - _photoListModel = new PhotoListModel(_trackInfo.getPhotoList()); + _photoListModel = new MediaListModel(_trackInfo.getPhotoList()); _photoList = new JList(_photoListModel); _photoList.setVisibleRowCount(NUM_LIST_ENTRIES); _photoList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { - if (!e.getValueIsAdjusting()) selectPhoto(_photoList.getSelectedIndex()); + if (!e.getValueIsAdjusting()) { + selectPhoto(_photoList.getSelectedIndex()); + } + }}); + _photoListPanel = makeListPanel("details.lists.photos", _photoList); + // don't add photo list (because there aren't any photos yet) + + // List for audio clips + _audioListModel = new MediaListModel(_trackInfo.getAudioList()); + _audioList = new JList(_audioListModel); + _audioList.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) + { + if (!e.getValueIsAdjusting()) { + selectAudio(_audioList.getSelectedIndex()); + } }}); - JPanel photoListPanel = new JPanel(); - photoListPanel.setLayout(new BorderLayout()); - photoListPanel.add(new JLabel(I18nManager.getText("details.waypointsphotos.photos")), BorderLayout.NORTH); - photoListPanel.add(new JScrollPane(_photoList), BorderLayout.CENTER); - listsPanel.add(photoListPanel); - listsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); + _audioListPanel = makeListPanel("details.lists.audio", _audioList); + // don't add audio list either + _listsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); // add the controls to the main panel mainPanel.add(trackDetailsPanel); @@ -135,7 +153,7 @@ public class SelectorDisplay extends GenericDisplay // add the main panel at the top add(mainPanel, BorderLayout.NORTH); // and lists in the centre - add(listsPanel, BorderLayout.CENTER); + add(_listsPanel, BorderLayout.CENTER); // set preferred width to be small setPreferredSize(new Dimension(100, 100)); } @@ -147,9 +165,8 @@ public class SelectorDisplay extends GenericDisplay */ private void selectPoint(int inValue) { - if (_track != null && !_ignoreScrollEvents) - { - _trackInfo.getSelection().selectPoint(inValue); + if (_track != null && !_ignoreScrollEvents) { + _trackInfo.selectPoint(inValue); } } @@ -163,6 +180,14 @@ public class SelectorDisplay extends GenericDisplay _trackInfo.selectPhoto(inPhotoIndex); } + /** + * Select the specified audio clip + * @param inIndex index of selected audio clip + */ + private void selectAudio(int inIndex) + { + _trackInfo.selectAudio(inIndex); + } /** * Select the specified waypoint @@ -170,8 +195,7 @@ public class SelectorDisplay extends GenericDisplay */ private void selectWaypoint(int inWaypointIndex) { - if (inWaypointIndex >= 0) - { + if (inWaypointIndex >= 0) { _trackInfo.selectPoint(_waypointListModel.getWaypoint(inWaypointIndex)); } } @@ -200,8 +224,7 @@ public class SelectorDisplay extends GenericDisplay } else if (numFiles > 1) { - _filenameLabel.setText(I18nManager.getText("details.track.numfiles") + ": " - + numFiles); + _filenameLabel.setText(I18nManager.getText("details.track.numfiles") + ": " + numFiles); } else _filenameLabel.setText(""); } @@ -217,7 +240,7 @@ public class SelectorDisplay extends GenericDisplay } else { - _scroller.setMaximum(_track.getNumPoints() + SCROLLBAR_INTERVAL); + _scroller.setMaximum(_track.getNumPoints() -1 + SCROLLBAR_INTERVAL); if (currentPointIndex >= 0) _scroller.setValue(currentPointIndex); _scroller.setEnabled(true); @@ -230,10 +253,11 @@ public class SelectorDisplay extends GenericDisplay { _waypointListModel.fireChanged(); } - if ((inUpdateType | + if ((inUpdateType & (DataSubscriber.DATA_ADDED_OR_REMOVED | DataSubscriber.DATA_EDITED | DataSubscriber.PHOTOS_MODIFIED)) > 0) { _photoListModel.fireChanged(); + _audioListModel.fireChanged(); } // Deselect selected waypoint if selected point has since changed if (_waypointList.getSelectedIndex() >= 0) @@ -246,24 +270,81 @@ public class SelectorDisplay extends GenericDisplay _waypointList.clearSelection(); } } - // Do the same for the photos - if (_photoList.getSelectedIndex() >= 0) + // Hide photo list if no photos loaded, same for audio + redrawLists(_photoListModel.getSize() > 0, _audioListModel.getSize() > 0); + + // Make sure correct photo is selected + if (_photoListModel.getSize() > 0) { - DataPoint trackPoint = _trackInfo.getCurrentPoint(); - Photo selectedPhoto = _photoListModel.getPhoto(_photoList.getSelectedIndex()); - // Get selected Photo, if it's still there - DataPoint photoPoint = null; - if (selectedPhoto != null) { - photoPoint = _photoListModel.getPhoto(_photoList.getSelectedIndex()).getDataPoint(); + int photoIndex = _trackInfo.getSelection().getCurrentPhotoIndex(); + int listSelection = _photoList.getSelectedIndex(); + // Change listbox selection if indexes not equal + if (listSelection != photoIndex) + { + if (photoIndex < 0) { + _photoList.clearSelection(); + } + else { + _photoList.setSelectedIndex(photoIndex); + } } - // Compare selected photo with selected point - if ( (photoPoint != null && (trackPoint == null || !photoPoint.equals(trackPoint))) - || (_trackInfo.getSelection().getCurrentPhotoIndex() < 0) ) + } + // Same for audio clips + if (_audioListModel.getSize() > 0) + { + int audioIndex = _trackInfo.getSelection().getCurrentAudioIndex(); + int listSelection = _audioList.getSelectedIndex(); + // Change listbox selection if indexes not equal + if (listSelection != audioIndex) { - // photo is selected in list but different from current point - deselect - _photoList.clearSelection(); - _trackInfo.getSelection().deselectPhoto(); + if (audioIndex < 0) { + _audioList.clearSelection(); + } + else { + _audioList.setSelectedIndex(audioIndex); + } } } } + + /** + * Make one of the three list panels + * @param inNameKey key for heading text + * @param inList list object + * @return panel object + */ + private static JPanel makeListPanel(String inNameKey, JList inList) + { + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + panel.add(new JLabel(I18nManager.getText(inNameKey)), BorderLayout.NORTH); + inList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + panel.add(new JScrollPane(inList), BorderLayout.CENTER); + return panel; + } + + /** + * Redraw the list panels in the display according to which ones should be shown + * @param inShowPhotos true to show photo list + * @param inShowAudio true to show audio list + */ + private void redrawLists(boolean inShowPhotos, boolean inShowAudio) + { + // exit if same as last time + int panels = 1 + (inShowPhotos?2:0) + (inShowAudio?4:0); + if (panels == _visiblePanels) return; + _visiblePanels = panels; + // remove all panels and re-add them + _listsPanel.removeAll(); + _listsPanel.setLayout(new GridLayout(0, 1)); + _listsPanel.add(_waypointListPanel); + if (inShowPhotos) { + _listsPanel.add(_photoListPanel); + } + if (inShowAudio) { + _listsPanel.add(_audioListPanel); + } + _listsPanel.invalidate(); + _listsPanel.getParent().validate(); + } }