Example usage for org.jfree.chart ChartPanel setDomainZoomable

List of usage examples for org.jfree.chart ChartPanel setDomainZoomable

Introduction

In this page you can find the example usage for org.jfree.chart ChartPanel setDomainZoomable.

Prototype

public void setDomainZoomable(boolean flag) 

Source Link

Document

Sets the flag that controls whether or not zooming is enabled for the domain axis.

Usage

From source file:loci.slim.ui.DecayGraph.java

/**
 * Initialize the graph and returns the containing JFrame.
 *
 * @return frame/*from  w  ww.  j  a va 2 s  . co  m*/
 */
@Override
public JFrame init(final JFrame frame, final int bins, final double timeInc,
        final ICursorListener cursorListener) {
    final boolean create = false;
    if (null == _frame || !_frame.isVisible() || _bins != bins || _timeInc != timeInc) {
        // save incoming parameters
        _bins = bins;
        _timeInc = timeInc;
        _maxValue = timeInc * bins;
        _cursorListener = cursorListener;

        if (null != _frame) {
            // delete existing frame
            _frame.setVisible(false);
            _frame.dispose();
        }

        // create the combined chart
        final JFreeChart chart = createCombinedChart(bins, timeInc);
        final ChartPanel panel = new ChartPanel(chart, true, true, true, false, true);
        panel.setDomainZoomable(false);
        panel.setRangeZoomable(false);
        panel.setPreferredSize(SIZE);

        // add start/stop vertical bar handling
        _dataStart = _transStop = null;
        final JXLayer<JComponent> layer = new JXLayer<JComponent>(panel);
        _startStopDraggingUI = new StartStopDraggingUI<JComponent>(panel, _decaySubPlot, this, _maxValue);
        layer.setUI(_startStopDraggingUI);

        // create a frame for the chart
        _frame = new JFrame();
        final Container container = _frame.getContentPane();
        container.setLayout(new BorderLayout());
        container.add(layer, BorderLayout.CENTER);

        final JPanel miscPane = new JPanel();
        miscPane.setLayout(new FlowLayout());
        final JLabel label1 = new JLabel(CHI_SQUARE);
        miscPane.add(label1);
        _chiSqTextField = new JTextField(7);
        _chiSqTextField.setEditable(false);
        miscPane.add(_chiSqTextField);
        final JLabel label2 = new JLabel(PHOTON_COUNT);
        miscPane.add(label2);
        _photonTextField = new JTextField(7);
        _photonTextField.setEditable(false);
        miscPane.add(_photonTextField);
        _logCheckBox = new JCheckBox(LOGARITHMIC);
        _logCheckBox.setSelected(_logarithmic);
        _logCheckBox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                _logarithmic = _logCheckBox.isSelected();
                NumberAxis photonAxis;
                if (_logarithmic) {
                    photonAxis = new LogarithmicAxis(PHOTON_AXIS_LABEL);
                } else {
                    photonAxis = new NumberAxis(PHOTON_AXIS_LABEL);
                }
                _decaySubPlot.setRangeAxis(photonAxis);
            }
        });
        miscPane.add(_logCheckBox);
        container.add(miscPane, BorderLayout.SOUTH);

        // IJ.log("size from prefs " + getSizeFromPreferences());
        // _frame.setSize(getSizeFromPreferences());
        // _frame.setMaximumSize(MAX_SIZE); // doesn't work; bug in Java
        _frame.pack();
        _frame.setLocationRelativeTo(frame);
        _frame.setVisible(true);
        _frame.addComponentListener(new ComponentListener() {

            @Override
            public void componentHidden(final ComponentEvent e) {

            }

            @Override
            public void componentMoved(final ComponentEvent e) {

            }

            @Override
            public void componentResized(final ComponentEvent e) {
                // constrain maximum size
                boolean resize = false;
                final Dimension size = _frame.getSize();
                // IJ.log("COMPONENT RESIZED incoming size " + size);
                if (size.width > MAX_SIZE.width) {
                    size.width = MAX_SIZE.width;
                    resize = true;
                }
                if (size.height > MAX_SIZE.height) {
                    size.height = MAX_SIZE.height;
                    resize = true;
                }
                if (size.width < MIN_SIZE.width) {
                    size.width = MIN_SIZE.width;
                    resize = true;
                }
                if (size.height < MIN_SIZE.height) {
                    size.height = MIN_SIZE.height;
                    resize = true;
                }
                if (resize) {
                    _frame.setSize(size);
                }
                // IJ.log("save resized " + resize + " size " + size);
                saveSizeInPreferences(size);
            }

            @Override
            public void componentShown(final ComponentEvent e) {

            }
        });
        _frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(final WindowEvent e) {
                _cursorListener.hideCursor();
            }
        });
        _frame.setSize(getSizeFromPreferences());
    }
    return _frame;
}

From source file:iad_zad3.gui.MainWindow.java

private void showKMeansChart() {
    jPanelChart.removeAll();/*from   w w w .ja  v a  2s .  c om*/
    ChartPanel chartPanel = new ChartPanel(
            Charts.getKmeansChart(clusteringAlgorithm.getData(), clusteringAlgorithm.getCentroids()));
    chartPanel.setPreferredSize(new Dimension(600, 600));
    chartPanel.setDomainZoomable(true);
    jPanelChart.setLayout(new java.awt.BorderLayout());
    jPanelChart.add(chartPanel, BorderLayout.CENTER);
    jPanelChart.validate();
}

From source file:windows.sensorWindow.java

/**
 * window constructor for chart window// w ww. j a va 2s.  c  o  m
 * 
 * @param title
 *            title for the new window
 */
public sensorWindow(final String title) {

    super(title);

    System.out.println("create sensorWindow");

    // font customizing
    // -------------------------------------------------------
    /*
     * Font font1 = null; try { font1 = Font.createFont(Font.TRUETYPE_FONT,
     * new File("U:/workspace/SWTtest/fonts/roboto/Roboto-Black.ttf")); }
     * catch (FontFormatException | IOException e1) { e1.printStackTrace();
     * } StandardChartTheme chartTheme = new
     * StandardChartTheme("robotTheme");
     * chartTheme.setExtraLargeFont(font1.deriveFont(24f));
     * chartTheme.setLargeFont(font1.deriveFont(16f));
     * chartTheme.setRegularFont(font1.deriveFont(12f));
     * chartTheme.setSmallFont(font1.deriveFont(10f));
     * ChartFactory.setChartTheme(chartTheme);
     */
    Font font1 = new Font("Tahoma", Font.BOLD, 16);
    Font font2 = new Font("Tahoma", Font.PLAIN, 12);
    Font font3 = new Font("Tahoma", Font.BOLD, 16);
    customFonts.put("axisLabelFont", font1);
    customFonts.put("axisValueFont", font2);
    customFonts.put("titleFont", font3);
    // -------------------------------------------------------------------------

    this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    plot = new CombinedDomainXYPlot(new DateAxis("Time"));

    for (int i = 0; i < connectionData.presentedBrickList.size(); i++) {
        Brick tmpBrick = connectionData.presentedBrickList.get(i);
        addPlot(tmpBrick);
    }

    final JFreeChart chart = new JFreeChart("", plot);
    // chart.setBorderPaint(Color.black);
    // chart.setBorderVisible(true);
    // chart.setBackgroundPaint(Color.white);
    chart.removeLegend();

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    // plot.setRenderer(renderer2);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(chartRangeSec * 1000); // chart range seconds
    axis.setLabelFont(customFonts.get("axisLabelFont"));
    axis.setTickLabelFont(customFonts.get("axisValueFont"));

    //final JPanel content = new JPanel(new BorderLayout());
    content = new JPanel(new BorderLayout());
    JScrollPane scrollPane = new JScrollPane();
    JViewport viewport = scrollPane.getViewport();
    viewport.setView(content);

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel, BorderLayout.NORTH);
    // content.add(getScrollBar(xAxe), BorderLayout.SOUTH);

    // disable zoom
    chartPanel.setRangeZoomable(false);
    chartPanel.setDomainZoomable(false);

    // mouse selection
    chartPanel.addMouseListener(new MouseMarker(chartPanel));

    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    // chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    // setContentPane(content);

    // ===================================================
    // buttons
    buttonPanel = new JPanel(new FlowLayout());

    for (int i = 0; i < connectionData.presentedBrickList.size(); i++) {
        for (int i2 = 0; i2 < 2; i2++) {
            Brick tmpBrick = connectionData.presentedBrickList.get(i);
            JButton button = new JButton(tmpBrick.uid + " start");
            button.setActionCommand(buttonComAddBtn + tmpBrick.uid + i + "(" + i2 + ")");
            button.addActionListener(this);
            tmplButtons.put(tmpBrick.uid, button);
            // if ((tmpBrick.ctrlTmpl[0]) || (tmpBrick.ctrlTmpl[1]))
            // {
            // buttonPanel.add(button);
            // }
            changeTmplCntrl(tmpBrick, i2);
        }
    }
    content.add(buttonPanel, BorderLayout.SOUTH);
    // ===================================================

    // ===================================================
    // scroll bar
    final JPanel sliderPanel = new JPanel(new FlowLayout());

    slider = new JSlider(1, sliderValuesNumber);
    slider.setValue(sliderValuesNumber);
    slider.setEnabled(false);
    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            if (sliderData.sliderActive == true) {
                int sliderValue = slider.getValue();
                if (sliderValue == sliderValuesNumber)
                    sliderUpdate = true;
                else
                    sliderUpdate = false;
                /*
                System.out.println("slider : " + sliderValue);
                System.out.println("Millis first: "
                      + sliderData.getMilliseconds(
                   sliderValue - sliderValuesNumber)
                   .toString());
                System.out.println("Millis last : "
                      + sliderData.getMilliseconds(sliderValue)
                   .toString());
                */
                DateRange range = new DateRange(
                        sliderData.getMilliseconds(sliderValue - sliderValuesNumber).getFirstMillisecond(),
                        sliderData.getMilliseconds(sliderValue).getFirstMillisecond());
                plot.getDomainAxis().setRange(range);
            }
        }
    });
    sliderPanel.add(slider);
    // chartPanel.add(slider);
    /*
     * final Panel chartPanel2 = new Panel(); chartPanel2.add(slider);
     * content.add(chartPanel2, BorderLayout.SOUTH);
     */
    content.add(sliderPanel, BorderLayout.CENTER);
    // ===================================================

    // ===================================================
    // scrolling
    /*
     * String[] data = {"one", "two", "three", "four", "five", "six",
     * "seven", "eight", "nine", "ten"}; JList list = new JList(data);
     * 
     * // give the list some scrollbars. // the horizontal (bottom)
     * scrollbar will only appear // when the screen is too wide. The
     * vertical // scrollbar is always present, but disabled if the // list
     * is small. JScrollPane jsp = new JScrollPane(list,
     * JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
     * JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
     * 
     * // add the JScrollPane (not the list) to the window.
     * getContentPane().add(jsp, BorderLayout.CENTER);
     */
    // ==================================================

    setContentPane(content);

    this.addComponentListener(new java.awt.event.ComponentAdapter() {
        public void componentResized(java.awt.event.ComponentEvent e) {
            chartPanel.setMaximumDrawWidth((int) e.getComponent().getSize().getWidth());
            chartPanel.setMaximumDrawHeight((int) e.getComponent().getSize().getHeight());
            //chartPanel.setPreferredSize(e.getComponent().getPreferredSize());
            //chartPanel.setSize(e.getComponent().getSize());
            //chartPanel.setLocation(0,0); 
        }
    });

    // start auto update plot
    autoUpdatePlot();

    this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.out.println("close sensor window");
            functions.windowController.closeSensorWindow();
        }

    });
}

From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java

/**
  * Draw a chart in a panel.  Good for precursors and daughters
  * @param parentPanel//  w w  w  .  ja  va  2  s . c om
  * @param dataset
  * @param domainMin
  * @param domainMax
  * @param supplier
  * @param wg
  */

protected void createChartInPanel(JPanel parentPanel, XYSeriesCollection dataset, Double domainMin,
        Double domainMax, DrawingSupplier supplier, whichGraph wg) {
    if (precursorChromatogramEmpty(transitionOnPlot) && wg == whichGraph.Precursor) {
        precursorContainerContainerPanel.setVisible(false);
        if (this.getWidth() >= 100 && this.getHeight() >= 100)
            this.setPreferredSize(new Dimension(this.getWidth(), this.getHeight()));
        pack();
        return;
    }
    switch (wg) {
    case Precursor:
        clearPreviousChartJunk(oldPrecursorChart);
        oldPrecursorChart = null;
        break;
    case Daughter:
        clearPreviousChartJunk(oldProductChart);
        oldProductChart = null;
        break;
    }

    JFreeChart chart = ChartFactory.createXYLineChart(null, "seconds", null, dataset, PlotOrientation.VERTICAL,
            true, false, false);

    chart.setBackgroundPaint(new Color(220, 220, 220));
    XYPlot xyp = (XYPlot) (chart.getPlot());
    xyp.setBackgroundPaint(Color.WHITE);
    xyp.setDomainGridlinesVisible(true);
    xyp.setRangeGridlinesVisible(true);
    xyp.setDomainGridlinePaint(Color.LIGHT_GRAY);
    xyp.setRangeGridlinePaint(Color.LIGHT_GRAY);
    if (supplier != null) {
        xyp.setDrawingSupplier(supplier);
    } else {
        xyp.setDrawingSupplier(Utils.plainDrawingSupplier(Color.LIGHT_GRAY));
    }
    xyp.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE);

    CenterZoomNumberAxis axisDomain = new CenterZoomNumberAxis("seconds");
    axisDomain.setAutoRangeIncludesZero(false);
    axisDomain.setRange(Math.max(0.0, domainMin), domainMax);
    axisDomain.addChangeListener(new domainAxisZoomCoordinator(axisDomain));

    xyp.clearAnnotations();
    xyp.setDomainAxis(axisDomain);
    xyp.getDomainAxis().setAutoRange(false);
    xyp.getRangeAxis().setAutoRange(false);
    XYLineAndShapeRenderer xylsr = (XYLineAndShapeRenderer) xyp.getRenderer();
    xylsr.setLegendLine(Utils.legendThing(16, 6));

    xylsr.setShapesFilled(true);
    xylsr.setBaseShapesFilled(true);
    PanelWithChart panelWithChart = new PanelWithChart(chart);
    ChartPanel cp = panelWithChart.getChartPanel();
    cp.removeMouseListener(cp);
    cp.removeMouseMotionListener(cp);
    if (peaksTable != null) {
        MRMerMouseListener mml = new MRMerMouseListener(cp, (PeaksTableModel) peaksTable.getModel());
        cp.addMouseListener(mml);
        cp.addMouseMotionListener(mml);
    }
    cp.setPreferredSize(new Dimension(parentPanel.getWidth(), parentPanel.getHeight() - 10));
    cp.setDomainZoomable(true);
    cp.setRangeZoomable(false);
    cp.setPopupMenu(null);
    parentPanel.removeAll();
    parentPanel.add(panelWithChart);

    switch (wg) {
    case Precursor:
        createChartInPanelPrecursorTasksOnly(xyp);
        oldPrecursorChart = xyp;
        break;
    case Daughter:
        createChartInPanelDaughterTasksOnly(xyp);
        oldProductChart = xyp;
        break;
    }
    parentPanel.updateUI();
    listTransition.requestFocus();
}