Search in sources :

Example 1 with BoundedDateAxis

use of fr.jmmc.oiexplorer.core.gui.chart.BoundedDateAxis in project aspro by JMMC-OpenDev.

the class ObservabilityPanel method updateDateAxisBounds.

/**
 * Update the data axis range i.e. zoom on date range
 * @param lower lower value in milliseconds
 * @param upper upper value in milliseconds
 */
private void updateDateAxisBounds(final long lower, final long upper) {
    final BoundedDateAxis dateAxis = (BoundedDateAxis) this.xyPlot.getRangeAxis();
    // add a margin of 1 ms :
    dateAxis.setBounds(new DateRange(lower - 1l, upper + 1l));
    dateAxis.setRange(lower - 1l, upper + 1l);
}
Also used : DateRange(org.jfree.data.time.DateRange) BoundedDateAxis(fr.jmmc.oiexplorer.core.gui.chart.BoundedDateAxis)

Example 2 with BoundedDateAxis

use of fr.jmmc.oiexplorer.core.gui.chart.BoundedDateAxis in project aspro by JMMC-OpenDev.

the class ObservabilityPanel method updateDateAxis.

/**
 * Update the date axis i.e. the horizontal axis
 * @param label axis label with units
 * @param from starting date
 * @param to ending date
 * @param doBaseLineLimits flag to plot baseline limits
 */
private void updateDateAxis(final String label, final Date from, final Date to, final boolean doBaseLineLimits) {
    // update the Range axis (horizontal):
    final BoundedDateAxis dateAxis = (BoundedDateAxis) this.xyPlot.getRangeAxis();
    dateAxis.setLabel(label);
    if (doBaseLineLimits) {
        dateAxis.setStandardTickUnits(HA_TICK_UNITS);
    } else {
        dateAxis.setStandardTickUnits(HH_MM_TICK_UNITS);
    }
    dateAxis.setTickLabelInsets(ChartUtils.TICK_LABEL_INSETS);
    // use the range [0;24]:
    updateDateAxisBounds(from.getTime(), to.getTime());
}
Also used : BoundedDateAxis(fr.jmmc.oiexplorer.core.gui.chart.BoundedDateAxis)

Example 3 with BoundedDateAxis

use of fr.jmmc.oiexplorer.core.gui.chart.BoundedDateAxis in project aspro by JMMC-OpenDev.

the class ObservabilityPanel method initComponents.

/**
 * Initialize the components (once)
 */
private void initComponents() {
    this.chart = AsproChartUtils.createXYBarChart();
    this.xyPlot = (XYPlot) this.chart.getPlot();
    // change the Range axis (horizontal):
    this.xyPlot.setRangeAxis(new BoundedDateAxis(""));
    // create new JMMC annotation (moving position):
    this.aJMMC = AsproChartUtils.createJMMCAnnotation();
    // define sliding adapter :
    this.slidingXYPlotAdapter = new SlidingXYPlotAdapter(this.chart, this.xyPlot, SlidingXYPlotAdapter.MAX_VIEW_ITEMS, this.aJMMC);
    // add listener :
    this.chart.addProgressListener(this);
    // show tooltips
    this.chartPanel = ChartUtils.createChartPanel(this.chart, true);
    // intercept component resize events:
    this.chartPanel.addComponentListener(new PanelResizeAdapter());
    // zoom options :
    this.chartPanel.setDomainZoomable(true);
    // date axis :
    this.chartPanel.setRangeZoomable(true);
    this.chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(final ChartMouseEvent event) {
            final ChartEntity entity = event.getEntity();
            int seriesIndex = -1;
            // only support click on ranges (not text annotations):
            if (entity instanceof XYItemEntity) {
                final XYItemEntity itemEntity = (XYItemEntity) entity;
                seriesIndex = itemEntity.getSeriesIndex();
            } else if (entity instanceof ClickableXYAnnotationEntity) {
                final ClickableXYAnnotationEntity anEntity = (ClickableXYAnnotationEntity) entity;
                seriesIndex = anEntity.getRendererIndex();
                // TODO: finalize interactions
                if (false) {
                    // get object reference:
                    final Object ref = anEntity.getReference();
                    if (ref instanceof Observations) {
                        final Observations obsGroup = (Observations) ref;
                        logger.info("clicked on group [" + obsGroup.getGroupId() + " for " + obsGroup.getTargetId() + "]");
                        StatusBar.show("obs log : " + obsGroup.first().getObsId());
                    /*
                                TODO: show group in table ?
                             */
                    }
                }
            } else if (entity instanceof XYAnnotationEntity) {
                final XYAnnotationEntity anEntity = (XYAnnotationEntity) entity;
                seriesIndex = anEntity.getRendererIndex();
            }
            if (seriesIndex != -1) {
                final ObservationCollectionObsData chartData = getChartData();
                // do not change selection if baseline limits displayed:
                if ((chartData != null) && !chartData.getFirstObsData().isDoBaseLineLimits()) {
                    final int index = slidingXYPlotAdapter.getSeriePosition(seriesIndex);
                    if (logger.isDebugEnabled()) {
                        logger.debug("chartMouseClicked: serie={}, target index={}", seriesIndex, index);
                    }
                    final String targetName = slidingXYPlotAdapter.getTargetName(index);
                    if (targetName != null && !ObjectUtils.areEquals(targetName, selectedTargetName)) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("chartMouseClicked: selectedTargetName={}", targetName);
                        }
                        final ObservationManager om = ObservationManager.getInstance();
                        om.fireTargetSelectionChanged(om.getTarget(targetName));
                    }
                }
            }
        }

        @Override
        public void chartMouseMoved(final ChartMouseEvent event) {
        }
    });
    this.add(this.chartPanel, BorderLayout.CENTER);
    this.scroller = new JScrollBar(JScrollBar.VERTICAL, 0, 0, 0, 0);
    this.scroller.setName("scroller");
    this.scroller.getModel().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent ce) {
            final DefaultBoundedRangeModel model = (DefaultBoundedRangeModel) ce.getSource();
            // update position and repaint the plot:
            slidingXYPlotAdapter.setPosition(model.getValue());
            // update current target from updated position:
            setCurrentTargetName(slidingXYPlotAdapter.getCurrentTargetName());
        }
    });
    // update mouse wheel handler:
    updateMouseWheelHandler(false);
    // Use a panel to define custom margin arround the scroll bar:
    this.scrollerPanel = new JPanel(new BorderLayout());
    this.scrollerPanel.add(this.scroller);
    this.scrollerPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 0));
    this.scrollerPanel.setBackground(Color.WHITE);
    this.add(this.scrollerPanel, BorderLayout.EAST);
    final JPanel panelOptions = new JPanel(new FlowLayout(FlowLayout.CENTER, 6, 2));
    panelOptions.add(new JLabel("Time:"));
    this.jComboTimeRef = new JComboBox(AsproConstants.TIME_CHOICES);
    this.jComboTimeRef.setName("jComboTimeRef");
    this.jComboTimeRef.setSelectedItem(this.myPreferences.getPreference(Preferences.TIME_REFERENCE));
    this.jComboTimeRef.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            refreshPlot();
        }
    });
    panelOptions.add(this.jComboTimeRef);
    this.jCheckBoxNightOnly = new JCheckBox("Night only");
    this.jCheckBoxNightOnly.setName("jCheckBoxNightOnly");
    this.jCheckBoxNightOnly.setSelected(myPreferences.getPreferenceAsBoolean(Preferences.ONLY_NIGHT));
    this.jCheckBoxNightOnly.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (getChartData() != null && jCheckBoxNightOnly.isEnabled()) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    // Update date axis = zoom on night bounds:
                    if (nightLower != 0d && nightUpper != 0d) {
                        updateDateAxisBounds(nightLower, nightUpper);
                    }
                } else {
                    // full range:
                    final ObservabilityData obsData = getChartData().getFirstObsData();
                    updateDateAxisBounds(obsData.getDateMin().getTime(), obsData.getDateMax().getTime());
                }
            }
        }
    });
    panelOptions.add(this.jCheckBoxNightOnly);
    this.jCheckBoxBaseLineLimits = new JCheckBox("Baseline limits");
    this.jCheckBoxBaseLineLimits.setName("jCheckBoxBaseLineLimits");
    this.jCheckBoxBaseLineLimits.setSelected(DEFAULT_DO_BASELINE_LIMITS);
    this.jCheckBoxBaseLineLimits.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            final boolean doBaseLineLimits = e.getStateChange() == ItemEvent.SELECTED;
            // disable the automatic refresh :
            final boolean prevAutoRefresh = setAutoRefresh(false);
            try {
                if (doBaseLineLimits) {
                    // force LST to compute correctly base line limits :
                    jComboTimeRef.setSelectedItem(TimeRef.LST.getDisplayName());
                    jCheckBoxDetailedOutput.setSelected(false);
                } else {
                    // restore user preference :
                    jComboTimeRef.setSelectedItem(myPreferences.getPreference(Preferences.TIME_REFERENCE));
                }
                jComboTimeRef.setEnabled(!doBaseLineLimits);
                jCheckBoxDetailedOutput.setEnabled(!doBaseLineLimits);
            } finally {
                // restore the automatic refresh :
                setAutoRefresh(prevAutoRefresh);
            }
            refreshPlot();
        }
    });
    panelOptions.add(this.jCheckBoxBaseLineLimits);
    this.jCheckBoxDetailedOutput = new JCheckBox("Details");
    this.jCheckBoxDetailedOutput.setName("jCheckBoxDetailedOutput");
    this.jCheckBoxDetailedOutput.setSelected(DEFAULT_DO_DETAILED_OUTPUT);
    this.jCheckBoxDetailedOutput.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            refreshPlot();
        }
    });
    panelOptions.add(this.jCheckBoxDetailedOutput);
    this.jCheckBoxListFilters = new CheckBoxList(FILTERS) {

        /**
         * default serial UID for Serializable interface
         */
        private static final long serialVersionUID = 1;

        /**
         * This method is called as the cursor moves within the list
         */
        @Override
        public String getToolTipText(final MouseEvent evt) {
            // Get item index :
            final int index = locationToIndex(evt.getPoint());
            if (index != -1) {
                // Get filter:
                final ObservabilityFilter filter = (ObservabilityFilter) getModel().getElementAt(index);
                if (filter != null) {
                    // Return the tool tip text :
                    return filter.getTooltip();
                }
            }
            return getToolTipText();
        }
    };
    this.jCheckBoxListFilters.setName("jCheckBoxListFilters");
    // note: only 1 is ugly on macOS X
    this.jCheckBoxListFilters.setVisibleRowCount(2);
    this.jCheckBoxListFilters.getCheckBoxListSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            if (!e.getValueIsAdjusting() && getChartData() != null) {
                updatePlot(getChartData());
            }
        }
    });
    panelOptions.add(createSeparator());
    panelOptions.add(new JLabel("Filters:"));
    panelOptions.add(new JScrollPane(this.jCheckBoxListFilters));
    this.jLabelGroups = new JLabel("Groups:");
    panelOptions.add(this.jLabelGroups);
    this.checkBoxListGroups = createCheckBoxList();
    this.checkBoxListGroups.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    this.checkBoxListGroups.setToolTipText("groups whose target belongs to");
    // note: only 1 is ugly on macOS X
    this.checkBoxListGroups.setVisibleRowCount(2);
    this.checkBoxListGroups.setCellRenderer(TargetGroupRenderer.INSTANCE);
    this.checkBoxListGroups.getCheckBoxListSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            if (!e.getValueIsAdjusting() && getChartData() != null) {
                updatePlot(getChartData());
            }
        }
    });
    this.jScrollPaneGroups = new JScrollPane(this.checkBoxListGroups);
    panelOptions.add(jScrollPaneGroups);
    this.jCheckBoxShowRelated = new JCheckBox("<html>Show<br>related</html>");
    this.jCheckBoxShowRelated.setName("jCheckBoxShowRelated");
    this.jCheckBoxShowRelated.setToolTipText("If enabled, selected target and its calibrators are always shown (not filtered)");
    this.jCheckBoxShowRelated.setSelected(DEFAULT_DO_SHOW_RELATED);
    this.jCheckBoxShowRelated.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            // refresh the plot:
            updatePlot(getChartData());
        }
    });
    panelOptions.add(this.jCheckBoxShowRelated);
    this.jCheckBoxScrollView = new JCheckBox("Scroll view");
    this.jCheckBoxScrollView.setName("jCheckBoxScrollView");
    this.jCheckBoxScrollView.setToolTipText("<html>If enabled, only few targets are displayed and the plot is scrollable (mousewheel supported)" + "<br>but <b>the exported PDF always contains all targets</b> (multiple page if necessary)" + "<br>If disabled, all targets are displayed and the plot can be zoomed in / out (mouse)" + "<br>but <b>the exported PDF document contains targets as displayed (single page only)</b></html>");
    this.jCheckBoxScrollView.setSelected(DEFAULT_DO_SCROLL_VIEW);
    this.jCheckBoxScrollView.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            // update scrollbar state and repaint the plot:
            updateSliderProperties(false);
        }
    });
    panelOptions.add(createSeparator());
    panelOptions.add(this.jCheckBoxScrollView);
    this.add(panelOptions, BorderLayout.PAGE_END);
    // register this instance as a Preference Observer :
    this.myPreferences.addObserver(this);
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) FlowLayout(java.awt.FlowLayout) ObservabilityData(fr.jmmc.aspro.model.observability.ObservabilityData) StarObservabilityData(fr.jmmc.aspro.model.observability.StarObservabilityData) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ObservationManager(fr.jmmc.aspro.model.ObservationManager) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) DefaultBoundedRangeModel(javax.swing.DefaultBoundedRangeModel) JScrollBar(javax.swing.JScrollBar) XYItemEntity(org.jfree.chart.entity.XYItemEntity) BorderLayout(java.awt.BorderLayout) ObservabilityFilter(fr.jmmc.aspro.gui.util.ObservabilityFilter) ChangeListener(javax.swing.event.ChangeListener) ClickableXYAnnotationEntity(fr.jmmc.aspro.gui.chart.ClickableXYAnnotationEntity) XYAnnotationEntity(org.jfree.chart.entity.XYAnnotationEntity) JScrollPane(javax.swing.JScrollPane) ClickableXYAnnotationEntity(fr.jmmc.aspro.gui.chart.ClickableXYAnnotationEntity) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) MouseEvent(java.awt.event.MouseEvent) SlidingXYPlotAdapter(fr.jmmc.aspro.gui.chart.SlidingXYPlotAdapter) JComboBox(javax.swing.JComboBox) BoundedDateAxis(fr.jmmc.oiexplorer.core.gui.chart.BoundedDateAxis) JLabel(javax.swing.JLabel) ChartMouseListener(org.jfree.chart.ChartMouseListener) ListSelectionListener(javax.swing.event.ListSelectionListener) JCheckBox(javax.swing.JCheckBox) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) ObservationCollectionObsData(fr.jmmc.aspro.model.ObservationCollectionObsData) CheckBoxList(com.jidesoft.swing.CheckBoxList) ItemListener(java.awt.event.ItemListener) ChartEntity(org.jfree.chart.entity.ChartEntity) Observations(fr.jmmc.aspro.model.rawobs.Observations)

Aggregations

BoundedDateAxis (fr.jmmc.oiexplorer.core.gui.chart.BoundedDateAxis)3 CheckBoxList (com.jidesoft.swing.CheckBoxList)1 ClickableXYAnnotationEntity (fr.jmmc.aspro.gui.chart.ClickableXYAnnotationEntity)1 SlidingXYPlotAdapter (fr.jmmc.aspro.gui.chart.SlidingXYPlotAdapter)1 ObservabilityFilter (fr.jmmc.aspro.gui.util.ObservabilityFilter)1 ObservationCollectionObsData (fr.jmmc.aspro.model.ObservationCollectionObsData)1 ObservationManager (fr.jmmc.aspro.model.ObservationManager)1 ObservabilityData (fr.jmmc.aspro.model.observability.ObservabilityData)1 StarObservabilityData (fr.jmmc.aspro.model.observability.StarObservabilityData)1 Observations (fr.jmmc.aspro.model.rawobs.Observations)1 BorderLayout (java.awt.BorderLayout)1 FlowLayout (java.awt.FlowLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 MouseEvent (java.awt.event.MouseEvent)1 DefaultBoundedRangeModel (javax.swing.DefaultBoundedRangeModel)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1