001/* 002 * Copyright (c) 2010-2012 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2012-05-09 11:05:40 -0700 (Wed, 09 May 2012) $' 007 * '$Revision: 29823 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.kepler.plotting; 031 032import java.awt.BorderLayout; 033import java.awt.Component; 034import java.awt.Dimension; 035import java.awt.FlowLayout; 036import java.awt.event.ActionEvent; 037 038import javax.swing.BorderFactory; 039import javax.swing.Box; 040import javax.swing.BoxLayout; 041import javax.swing.JButton; 042import javax.swing.JFrame; 043import javax.swing.JPanel; 044import javax.swing.JScrollPane; 045import javax.swing.border.Border; 046import javax.swing.border.EtchedBorder; 047 048import org.kepler.gui.PlotsEditorPanel; 049 050import ptolemy.vergil.toolbox.FigureAction; 051 052/** 053 * Created by IntelliJ IDEA. 054 * User: sean 055 * Date: Jul 6, 2010 056 * Time: 5:06:05 PM 057 */ 058 059public class PlotEditor extends JPanel { 060 061 public PlotEditor(PlotsEditorPanel plotsEditorPanel, Plot plot) { 062 this.setEditorPanel(plotsEditorPanel); 063 this.setPlot(plot); 064 initialize(); 065 } 066 067 public PlotEditor() { 068 initialize(); 069 } 070 071 private void initialize() { 072 073 Border loweredEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); 074 this.setBorder(loweredEtchedBorder); 075 076 this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); 077 deleteButton = new JButton("Delete"); 078 deleteButton.setAlignmentX(Component.CENTER_ALIGNMENT); 079 final PlotEditor me = this; 080 deleteButton.setAction(new FigureAction("delete") { 081 @Override 082 public void actionPerformed(ActionEvent e) { 083 JPanel panel = me.getPlot().getPanel(); 084 panel.getParent().remove(panel); 085 JButton clearButton = me.getPlot().getClearButton(); 086 clearButton.getParent().remove(clearButton); 087 me.getEditorPanel().removePlot(me); 088 me.getEditorPanel().fixGraphics(); 089 } 090 }); 091 JPanel deleteButtonflowPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0)); 092 deleteButtonflowPanel.add(deleteButton); 093 this.add(deleteButtonflowPanel); 094 JPanel graphLabelsflowPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); 095 096 graphLabelsPanel = new GraphLabelsPanel(this); 097 graphLabelsflowPanel.add(graphLabelsPanel); 098 this.add(graphLabelsflowPanel); 099 table = new DataTable(this); 100 JScrollPane scrollPane = new JScrollPane(table); 101 102 this.add(scrollPane); 103 this.add(Box.createRigidArea(new Dimension(0,20))); 104 this.setMaximumSize(PlottingConstants.MAX_SIZE); 105 } 106 107 public static void main(String[] args) { 108 JFrame frame = new JFrame(); 109 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 110 frame.getContentPane().setLayout(new BorderLayout()); 111 frame.getContentPane().add(new PlotsEditorPanel(null, "title")); 112// frame.getContentPane().add(new PlotEditor()); 113 frame.pack(); 114 frame.setVisible(true); 115 } 116 117 public void setEditorPanel(PlotsEditorPanel panel) { 118 this.editorPanel = panel; 119 } 120 121 public PlotsEditorPanel getEditorPanel() { 122 return editorPanel; 123 } 124 125 public void setActive(boolean active) { 126 this.active = active; 127 _setActive(active); 128 } 129 130 private void _setActive(boolean active) { 131 if (active) { 132 133 } 134 else { 135// this.setBackground(Color.BLUE); 136 tbp.setActive(false); 137 deleteButton.setEnabled(false); 138 graphLabelsPanel.setActive(false); 139 table.setActive(false); 140 } 141 } 142 143 public boolean isActive() { 144 return active; 145 } 146 147 public void setPlot(Plot plot) { 148 this.plot = plot; 149 } 150 151 public Plot getPlot() { 152 return plot; 153 } 154 155 public DataTable getTable() { 156 return table; 157 } 158 159 private PlotsEditorPanel editorPanel; 160 private boolean active = true; 161 162 private JButton deleteButton; 163 private GraphLabelsPanel graphLabelsPanel; 164 private DataTable table; 165 private TableButtonPanel tbp; 166 private Plot plot; 167}