Logo Search packages:      
Sourcecode: wims version File versions

synchronized void ptolemy::plot::PlotBox::setButtons ( boolean  visible  )  [inline]

If the argument is true, make a fill button visible at the upper right. This button auto-scales the plot. NOTE: The button may infringe on the title space, if the title is long. In an application, it is preferable to provide a menu with the fill command. This way, when printing the plot, the printed plot will not have a spurious button. Thus, this method should be used only by applets, which normally do not have menus. This method should only be called from within the event dispatch thread, since it interacts with swing.

Reimplemented in ptolemy::plot::PlotLive.

Definition at line 1221 of file PlotBox.java.

Referenced by init().

                                                         {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        if (_printButton == null) {
            // Load the image by using the absolute path to the gif.
            URL img = null;
            try {
                // FindBugs: Usage of GetResource may be unsafe if
                // class is extended
                img = FileUtilities.nameToURL(
                        "$CLASSPATH/ptolemy/plot/img/print.gif", null, null);
            } catch (IOException ex) {
                ex.printStackTrace();
            }

            if (img != null) {
                ImageIcon printIcon = new ImageIcon(img);
                _printButton = new JButton(printIcon);
                _printButton.setBorderPainted(false);
            } else {
                // Backup in case something goes wrong with the
                // class loader.
                _printButton = new JButton("P");
            }

            // FIXME: If we failed to get an image, then the letter "P"
            // Is not likely to fit into a 20x20 button.
            _printButton.setPreferredSize(new Dimension(20, 20));
            _printButton.setToolTipText("Print the plot.");
            _printButton.addActionListener(new ButtonListener());
            add(_printButton);
        }

        _printButton.setVisible(visible);

        if (_resetButton == null) {
            // Load the image by using the absolute path to the gif.
            URL img = null;
            try {
                // FindBugs: Usage of GetResource may be unsafe if
                // class is extended
                img = FileUtilities.nameToURL(
                        "$CLASSPATH/ptolemy/plot/img/reset.gif", null, null);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            if (img != null) {
                ImageIcon resetIcon = new ImageIcon(img);
                _resetButton = new JButton(resetIcon);
                _resetButton.setBorderPainted(false);
            } else {
                // Backup in case something goes wrong with the
                // class loader.
                _resetButton = new JButton("R");
            }

            // FIXME: If we failed to get an image, then the letter "R"
            // Is not likely to fit into a 20x20 button.
            _resetButton.setPreferredSize(new Dimension(20, 20));
            _resetButton
                    .setToolTipText("Reset X and Y ranges to their original values");
            _resetButton.addActionListener(new ButtonListener());
            add(_resetButton);
        }

        _resetButton.setVisible(visible);

        if (_formatButton == null) {
            // Load the image by using the absolute path to the gif.
            URL img = null;
            try {
                // FindBugs: Usage of GetResource may be unsafe if
                // class is extended
                img = FileUtilities.nameToURL(
                        "$CLASSPATH/ptolemy/plot/img/format.gif", null, null);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            if (img != null) {
                ImageIcon formatIcon = new ImageIcon(img);
                _formatButton = new JButton(formatIcon);
                _formatButton.setBorderPainted(false);
            } else {
                // Backup in case something goes wrong with the
                // class loader.
                _formatButton = new JButton("S");
            }

            // FIXME: If we failed to get an image, then the letter "S"
            // Is not likely to fit into a 20x20 button.
            _formatButton.setPreferredSize(new Dimension(20, 20));
            _formatButton.setToolTipText("Set the plot format");
            _formatButton.addActionListener(new ButtonListener());
            add(_formatButton);
        }

        _formatButton.setVisible(visible);

        if (_fillButton == null) {
            // Load the image by using the absolute path to the gif.
            URL img = null;
            try {
                // FindBugs: Usage of GetResource may be unsafe if
                // class is extended
                img = FileUtilities.nameToURL(
                        "$CLASSPATH/ptolemy/plot/img/fill.gif", null, null);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            if (img != null) {
                ImageIcon fillIcon = new ImageIcon(img);
                _fillButton = new JButton(fillIcon);
                _fillButton.setBorderPainted(false);
            } else {
                // Backup in case something goes wrong with the
                // class loader.
                _fillButton = new JButton("F");
            }

            // FIXME: If we failed to get an image, then the letter "F"
            // Is not likely to fit into a 20x20 button.
            _fillButton.setPreferredSize(new Dimension(20, 20));
            _fillButton.setToolTipText("Rescale the plot to fit the data");
            _fillButton.addActionListener(new ButtonListener());
            add(_fillButton);
        }

        _fillButton.setVisible(visible);

        // Request the focus so that key events are heard.
        // NOTE: no longer needed?
        // requestFocus();
    }


Generated by  Doxygen 1.6.0   Back to index