/* * ------------------------------------------------------------------------- * $Id: PortfolioPie.java,v 1.4 2004/05/26 18:54:55 estewart Exp $ * ------------------------------------------------------------------------- * Copyright (c) 1999 Visual Numerics Inc. All Rights Reserved. * * This software is confidential information which is proprietary to * and a trade secret of Visual Numerics, Inc. Use, duplication or * disclosure is subject to the terms of an appropriate license * agreement. * * VISUAL NUMERICS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. VISUAL * NUMERICS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR * ITS DERIVATIVES. *-------------------------------------------------------------------------- */ package com.imsl.demo.risk; import com.imsl.chart.*; /** * * @author brophy * @created February 1, 2002 */ public class PortfolioPie extends javax.swing.JDialog { static private final String COLORS[] = {"red", "green", "yellow", "blue", "gray"}; private JPanelChart jPanelChart; private Pie pie; /** Creates new form PortfolioPie */ public PortfolioPie(java.awt.Frame parent) { super(parent, false); initComponents(); setLocation(200, 0); jPanelChart = new JPanelChart(); jPanelChart.setPreferredSize(new java.awt.Dimension(225,225)); getContentPane().add(jPanelChart); } void update(String tickers[], double values[]) { if (pie != null) pie.remove(); Chart chart = jPanelChart.getChart(); chart.setComponent(this); int n = 0; for (int k = 0; k < tickers.length; k++) { if (values[k] > 0.0) n++; } double x[] = new double[n]; n = 0; for (int k = 0; k < tickers.length; k++) { if (values[k] > 0.0) x[n++] = values[k]; } n = 0; pie = new Pie(chart, x); pie.setExplode(0.2); pie.setLabelType(Pie.LABEL_TYPE_TITLE); for (int k = 0; k < tickers.length; k++) { if (values[k] > 0.0) { PieSlice s = pie.getPieSlice(n); s.setTitle(tickers[k]); s.setFillColor(COLORS[n]); n++; } } repaint(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents setTitle("Portfolio"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(evt); } }); pack(); }//GEN-END:initComponents /** Closes the dialog */ private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog setVisible(false); dispose(); }//GEN-LAST:event_closeDialog // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables }