/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ import java.util.*; import java.text.*; import java.io.*; import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import org.opensolaris.chime.*; import org.opensolaris.chime.swingx.event.MenuSupplier; import org.opensolaris.dtracex.*; import org.opensolaris.os.dtrace.*; import java.util.logging.*; public class TestChime { public static void main(String[] args) { Logger logger = Logger.getLogger(AggregationDisplay.class.getName()); logger.setLevel(Level.OFF); if (args.length != 1) { System.err.println("usage: java TestChime "); System.exit(1); } System.setProperty("CHIME_HOME", "/opt/OSOL0chime"); File file = new File(args[0]); if (!file.canRead()) { System.err.println("Cannot read " + file.getPath()); System.exit(1); } JFrame f = new JFrame("Title"); final JPanel p = new JPanel(new BorderLayout()); DisplayDescription d = AggregationDisplay.getDescriptionFromFile(file); try { AggregationDisplay.prepareDescription(d); } catch (Exception e) { e.printStackTrace(); } Command c = AggregationDisplay.createCommand(d); final AggregationDisplay display = new AggregationDisplay(c, d); p.add(display.getDisplay(), BorderLayout.CENTER); AbstractDisplay.startDisplay(display); final JButton pauseButton = new JButton("Pause"); pauseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { display.setPaused(!display.isPaused()); pauseButton.setText(display.isPaused() ? "Resume" : "Pause"); } }); final JButton intervalButton = new JButton("Set Interval ..."); intervalButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object input = JOptionPane.showInputDialog(p, "Enter the desired interval in seconds", "Set Interval", JOptionPane.QUESTION_MESSAGE, null, // icon null, // selectionValues [] Double.toString((double)display.getIntervalMillis() / 1000.d)); if (input instanceof String) { double d = Double.parseDouble((String)input); display.setIntervalMillis((long)(d * 1000.d)); } } }); JPanel buttonPanel = new JPanel(); buttonPanel.add(intervalButton); buttonPanel.add(pauseButton); p.add(buttonPanel, BorderLayout.SOUTH); if (display.getDisplay() instanceof JComponent) { JComponent jc = (JComponent)display.getDisplay(); MenuSupplier.add(jc, display); } f.setContentPane(p); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { AbstractDisplay.startShutdown(display); } }); f.setSize(400, 400); f.setVisible(true); } }