From ba6512c255973594c455a58100d521f564ac4c1d Mon Sep 17 00:00:00 2001 From: pompert <sdos@astron.nl> Date: Thu, 1 Jun 2006 14:36:14 +0000 Subject: [PATCH] BugID: 701 Additions: -PlotSlotListener class to help the Slot containers listen for mouse events originating from plots or slots. -PlotSlotViewFrame class is a beta dialog that enables the user to view a slot in a separate window. Mods: -Various bugfixes and improvements to make slots more functional, speedy and robust. --- .../lofar/sas/otb/util/plotter/PlotSlot.java | 73 ++++++++-- .../otb/util/plotter/PlotSlotListener.java | 44 ++++++ .../sas/otb/util/plotter/PlotSlotManager.java | 102 ++++++++------ .../otb/util/plotter/PlotSlotViewFrame.java | 52 ++++++++ .../sas/otb/util/plotter/PlotSlotsPanel.java | 126 ++++++++++++------ .../sas/otbcomponents/ParmDBPlotPanel.form | 35 ++--- .../sas/otbcomponents/ParmDBPlotPanel.java | 83 ++++++------ 7 files changed, 356 insertions(+), 159 deletions(-) create mode 100644 SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotListener.java create mode 100644 SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotViewFrame.java diff --git a/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlot.java b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlot.java index 1163e1442ef..af0d57d3ac4 100644 --- a/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlot.java +++ b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlot.java @@ -26,11 +26,14 @@ package nl.astron.lofar.sas.otb.util.plotter; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; -import java.awt.Font; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.LinkedList; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; +import javax.swing.SwingUtilities; import nl.astron.lofar.java.gui.plotter.PlotConstants; import nl.astron.lofar.java.gui.plotter.PlotPanel; import nl.astron.lofar.java.gui.plotter.exceptions.PlotterException; @@ -48,6 +51,8 @@ public class PlotSlot extends JPanel{ private String slotLabel; private boolean hasLegend; private JLabel rightClickFacade; + private LinkedList<PlotSlotListener> listenerList = null; + private MouseAdapter plotMouseListener; /** Creates a new instance of PlotSlot */ public PlotSlot() { @@ -55,6 +60,11 @@ public class PlotSlot extends JPanel{ itsPlot = null; hasLegend = false; setBackground(Color.WHITE); + plotMouseListener = new MouseAdapter(){ + public void mouseReleased(MouseEvent evt){ + fireContextMenuEvent(evt); + } + }; setBorder(javax.swing.BorderFactory.createEtchedBorder()); setSize(new Dimension(320,240)); setPreferredSize(new Dimension(320,240)); @@ -71,6 +81,7 @@ public class PlotSlot extends JPanel{ public PlotSlot(String label) { this(); setLabel(label); + rightClickFacade.setText(" "+label); } public void setLabel(String label){ @@ -85,13 +96,13 @@ public class PlotSlot extends JPanel{ return itsPlot; } public void setPlot(PlotPanel aPlot){ - removeAll(); - itsPlot = aPlot; - addOptionLabel(); - add(itsPlot,BorderLayout.CENTER); - if(containsLegend()){ - addLegend(); - } + removeAll(); + itsPlot = aPlot; + addOptionLabel(); + add(itsPlot,BorderLayout.CENTER); + if(containsLegend()){ + addLegend(); + } } public void addPlot(Object constraints){ @@ -103,7 +114,6 @@ public class PlotSlot extends JPanel{ } itsPlot.createPlot(PlotConstants.PLOT_XYLINE,true,constraints); add(itsPlot,BorderLayout.CENTER); - } catch (PlotterException ex) { JTextArea error = new JTextArea(ex.getMessage()); error.setColumns(50); @@ -120,7 +130,7 @@ public class PlotSlot extends JPanel{ itsPlot.modifyPlot(constraints); add(itsPlot,BorderLayout.CENTER); if(containsLegend()){ - addLegend(); + addLegend(); } } catch (PlotterException ex) { @@ -151,6 +161,8 @@ public class PlotSlot extends JPanel{ northPanel.setBackground(Color.LIGHT_GRAY); rightClickFacade.setForeground(Color.WHITE); northPanel.add(rightClickFacade,BorderLayout.CENTER); + northPanel.addMouseListener(plotMouseListener); + add(northPanel,BorderLayout.NORTH); } @@ -176,7 +188,7 @@ public class PlotSlot extends JPanel{ public void removeLegend(){ if(containsLegend() && itsPlot != null && itsPlot.getPlot()!= null){ removeAll(); - if(containsPlot()) addOptionLabel(); + addOptionLabel(); add(itsPlot,BorderLayout.CENTER); hasLegend = false; } @@ -226,4 +238,43 @@ public class PlotSlot extends JPanel{ return !containsPlot(); } + + /** + * Registers ActionListener to receive events. + * + * @param listener The listener to register. + */ + public void addSlotListener(PlotSlotListener listener) { + + if (listenerList == null ) { + listenerList = new LinkedList<PlotSlotListener>(); + } + listenerList.add(listener); + } + + /** + * Removes ActionListener from the list of listeners. + * + * @param listener The listener to remove. + */ + public void removeSlotListener(PlotSlotListener listener) { + + listenerList.remove(listener); + } + + /** + * Notifies all registered listeners about the event. + * + * @param event The event to be fired + */ + private void fireContextMenuEvent(MouseEvent evt) { + if (listenerList != null) { + if(SwingUtilities.isRightMouseButton(evt)){ + for(PlotSlotListener listener : listenerList){ + ((PlotSlotListener)listener).slotContextMenuTriggered(this,evt); + } + } + } + } + } diff --git a/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotListener.java b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotListener.java new file mode 100644 index 00000000000..673e6d94e89 --- /dev/null +++ b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotListener.java @@ -0,0 +1,44 @@ +/* + * PlotSlotListener.java + * + * Copyright (C) 2002-2007 + * ASTRON (Netherlands Foundation for Research in Astronomy) + * P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +package nl.astron.lofar.sas.otb.util.plotter; + +import java.awt.event.MouseEvent; + +/** + * @version $Id$ + * @created June 1, 2006, 11:12 AM + * @author pompert + */ +public class PlotSlotListener{ + + /** + * Creates a new instance of PlotSlotListener + */ + public PlotSlotListener() { + } + + public void slotContextMenuTriggered(PlotSlot aSlot,MouseEvent evt){ + + } +} diff --git a/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotManager.java b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotManager.java index 020fe90cfd6..88ea083778b 100644 --- a/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotManager.java +++ b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotManager.java @@ -39,6 +39,9 @@ import javax.swing.SwingUtilities; */ public class PlotSlotManager{ + public static final String REFRESH_FULL = "REFRESHFULL"; + public static final String REFRESH_SINGLE = "REFRESHSINGLE"; + private LinkedList<PlotSlot> itsPlotSlots; private PlotSlot selectedSlot; @@ -52,38 +55,41 @@ public class PlotSlotManager{ return itsPlotSlots.size(); } public void setAmountOfSlots(int amount, boolean force) throws IllegalArgumentException{ - if(itsPlotSlots.size() < amount){ - int difference = amount - itsPlotSlots.size(); - int oldAmount = itsPlotSlots.size(); - for(int i = 1; i <= difference; i++){ - PlotSlot aNewSlot = new PlotSlot(); - aNewSlot.setLabel(""+(oldAmount+i)); - itsPlotSlots.add(aNewSlot); - } - }else if (itsPlotSlots.size() > amount){ - int difference = itsPlotSlots.size() - amount; - boolean plotInTheWay = false; - int plotsInTheWay = 0; - for(int i = 1; i <= difference; i++){ - PlotSlot checkPlot = getSlot(amount+i); - if(!checkPlot.isEmpty()){ - plotInTheWay = true; - plotsInTheWay++; + if(amount > 0){ + if(itsPlotSlots.size() < amount){ + int difference = amount - itsPlotSlots.size(); + int oldAmount = itsPlotSlots.size(); + for(int i = 1; i <= difference; i++){ + PlotSlot aNewSlot = new PlotSlot(); + aNewSlot.setLabel(""+(oldAmount+i)); + itsPlotSlots.add(aNewSlot); } - } - if(plotInTheWay && !force){ - String exceptionString = "There is/are "+plotsInTheWay+" plot(s) present in the "; - exceptionString+= "last "+difference+" slots.\n\nPlease clear or move "; - exceptionString+= "these plots manually by pressing cancel,\nor let "; - exceptionString+= "the application delete them by pressing Clear Slots."; - throw new IllegalArgumentException(exceptionString); - }else{ + this.fireSlotsUpdated(-1); + }else if (itsPlotSlots.size() > amount){ + int difference = itsPlotSlots.size() - amount; + boolean plotInTheWay = false; + int plotsInTheWay = 0; for(int i = 1; i <= difference; i++){ - itsPlotSlots.removeLast(); + PlotSlot checkPlot = getSlot(amount+i); + if(!checkPlot.isEmpty()){ + plotInTheWay = true; + plotsInTheWay++; + } + } + if(plotInTheWay && !force){ + String exceptionString = "There is/are "+plotsInTheWay+" plot(s) present in the "; + exceptionString+= "last "+difference+" slots.\n\nPlease clear or move "; + exceptionString+= "these plots manually by pressing cancel,\nor let "; + exceptionString+= "the application delete them by pressing Clear Slots."; + throw new IllegalArgumentException(exceptionString); + }else{ + for(int i = 1; i <= difference; i++){ + itsPlotSlots.removeLast(); + } + this.fireSlotsUpdated(-1); } } } - this.fireSlotsUpdated(amount); } public LinkedList<PlotSlot> getSlots(){ return itsPlotSlots; @@ -141,7 +147,15 @@ public class PlotSlotManager{ public void createPlotInSlot(int index, Object constraints){ getSlot(index).addPlot(constraints); - this.fireSlotsUpdated(index); + int currentPlots = 0; + for(PlotSlot slot : itsPlotSlots){ + if(slot.containsPlot()) currentPlots++; + } + if(currentPlots > 1){ + fireSlotsUpdated(index); + }else{ + fireSlotsUpdated(-1); + } } public void createLegendInSlot(int index){ getSlot(index).addLegend(); @@ -159,6 +173,7 @@ public class PlotSlotManager{ public void modifyPlotInSlot(int index, Object constraints){ getSlot(index).modifyPlot(constraints); + this.fireSlotsUpdated(index); } public void movePlot(int indexFromSlot, int indexToSlot){ @@ -169,10 +184,12 @@ public class PlotSlotManager{ } getSlot(indexFromSlot).clearSlot(); this.fireSlotsUpdated(indexFromSlot); + this.fireSlotsUpdated(indexToSlot); } public void clearSlot(int index){ getSlot(index).clearSlot(); + this.fireSlotsUpdated(index); } public boolean isSlotAvailable(int index){ @@ -183,43 +200,48 @@ public class PlotSlotManager{ * Utility field used by event firing mechanism. */ private javax.swing.event.EventListenerList listenerList = null; - + /** * Registers ActionListener to receive events. * * @param listener The listener to register. */ public void addActionListener(java.awt.event.ActionListener listener) { - + if (listenerList == null ) { listenerList = new javax.swing.event.EventListenerList(); } - listenerList.add (java.awt.event.ActionListener.class, listener); + listenerList.add(java.awt.event.ActionListener.class, listener); } - + /** * Removes ActionListener from the list of listeners. * * @param listener The listener to remove. */ public void removeActionListener(java.awt.event.ActionListener listener) { - - listenerList.remove (java.awt.event.ActionListener.class, listener); + + listenerList.remove(java.awt.event.ActionListener.class, listener); } - + /** * Notifies all registered listeners about the event. - * + * * @param event The event to be fired */ private void fireSlotsUpdated(int id) { - + if (listenerList == null) return; - Object[] listeners = listenerList.getListenerList (); - ActionEvent action = new ActionEvent(this,id,"REFRESH"); + Object[] listeners = listenerList.getListenerList(); + ActionEvent action = null; + if(id == -1){ + action = new ActionEvent(this,id,this.REFRESH_FULL); + }else{ + action = new ActionEvent(this,id,this.REFRESH_SINGLE); + } for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i]==java.awt.event.ActionListener.class) { - ((java.awt.event.ActionListener)listeners[i+1]).actionPerformed (action); + ((java.awt.event.ActionListener)listeners[i+1]).actionPerformed(action); } } } diff --git a/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotViewFrame.java b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotViewFrame.java new file mode 100644 index 00000000000..cba1c3e8105 --- /dev/null +++ b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotViewFrame.java @@ -0,0 +1,52 @@ +/* + * PlotSlotViewFrame.java + * + * Copyright (C) 2002-2007 + * ASTRON (Netherlands Foundation for Research in Astronomy) + * P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +package nl.astron.lofar.sas.otb.util.plotter; + +import java.awt.BorderLayout; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.JDialog; + +/** + * @version $Id$ + * @created June 1, 2006, 2:56 PM + * @author pompert + */ +public class PlotSlotViewFrame extends JDialog{ + + int plotIndex; + + /** Creates a new instance of PlotSlotViewFrame */ + public PlotSlotViewFrame(PlotSlotManager parent, int index, String title) { + super(); + plotIndex = index; + this.getContentPane().setLayout(new BorderLayout()); + setTitle(title); + PlotSlot viewSlot = parent.getSlot(index); + this.getContentPane().add(viewSlot,BorderLayout.CENTER); + this.setSize(640,480); + this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE); + } + +} diff --git a/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotsPanel.java b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotsPanel.java index 5619a0bf210..5ffca1d9049 100644 --- a/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotsPanel.java +++ b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otb/util/plotter/PlotSlotsPanel.java @@ -30,10 +30,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import javax.swing.JComponent; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; -import javax.swing.SwingUtilities; import org.apache.log4j.Logger; /** @@ -47,7 +45,7 @@ public class PlotSlotsPanel extends javax.swing.JPanel { static String name = "PlotSlotsPanel"; private PlotSlotManager itsSlotManager; private PlotSlot selectedSlot; - + /** Creates new form BeanForm */ public PlotSlotsPanel() { initComponents(); @@ -55,14 +53,17 @@ public class PlotSlotsPanel extends javax.swing.JPanel { itsSlotManager = new PlotSlotManager(numberOfSlots); itsSlotManager.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ - if(evt.getActionCommand().equals("REFRESH")){ - rearrangeSlotGrid(); + if(evt.getActionCommand().equals(PlotSlotManager.REFRESH_FULL)){ + rearrangeSlotGrid(); + } + if(evt.getActionCommand().equals(PlotSlotManager.REFRESH_SINGLE)){ + int slotId = evt.getID(); + itsSlotManager.getSlot(slotId).validate(); } - } + } }); - rearrangeSlotGrid(); } - + /** adds a button to the BeanForm */ public void addPlotToSlot(int index,Object constraints) throws IllegalArgumentException{ if(itsSlotManager.isSlotAvailable(index)){ @@ -80,7 +81,7 @@ public class PlotSlotsPanel extends javax.swing.JPanel { public void setAmountOfSlots(int amount, boolean force) throws IllegalArgumentException{ itsSlotManager.setAmountOfSlots(amount,force); } - + public boolean isSlotAvailable(int index){ return itsSlotManager.isSlotAvailable(index); } @@ -94,10 +95,10 @@ public class PlotSlotsPanel extends javax.swing.JPanel { double squareRoot = Math.sqrt(Double.parseDouble(""+itsSlotManager.getAmountOfSlots())); int columnsAndRows = Integer.parseInt(""+(int)squareRoot); GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = columnsAndRows; - gridBagConstraints.gridheight = columnsAndRows; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0); + gridBagConstraints.gridwidth = columnsAndRows; + gridBagConstraints.gridheight = columnsAndRows; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0); GridBagLayout layout = new GridBagLayout(); layout.setConstraints(slotsPanel,gridBagConstraints); //320,240 both! @@ -118,12 +119,12 @@ public class PlotSlotsPanel extends javax.swing.JPanel { gridBagConstraints.weighty = 1.0; gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER; PlotSlot newSlot = itsSlotManager.getSlot(i); - newSlot.addMouseListener(new SlotMouseAdapter()); + newSlot.addSlotListener(new SlotMouseAdapter()); newSlot.setSize(new Dimension(getWidth()/columnsAndRows,getHeight()/columnsAndRows)); // newSlot.setMinimumSize(new Dimension(getWidth()/columnsAndRows,getHeight()/columnsAndRows)); newSlot.setPreferredSize(new Dimension(getWidth()/columnsAndRows,getHeight()/columnsAndRows)); - slotsPanel.add(newSlot,gridBagConstraints); + slotsPanel.add(newSlot,gridBagConstraints); x++; if (x == columnsAndRows){ y++; @@ -132,7 +133,7 @@ public class PlotSlotsPanel extends javax.swing.JPanel { } slotsPanel.validate(); //slotsPanel.repaint(); - } + } /** This method is called from within the constructor to * initialize the form. @@ -152,75 +153,98 @@ public class PlotSlotsPanel extends javax.swing.JPanel { add(slotsPanel, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents - // Variables declaration - do not modify//GEN-BEGIN:variables + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel slotsPanel; // End of variables declaration//GEN-END:variables - + /** * Utility field used by event firing mechanism. */ private javax.swing.event.EventListenerList listenerList = null; - + /** * Registers ActionListener to receive events. * * @param listener The listener to register. */ public void addActionListener(java.awt.event.ActionListener listener) { - + if (listenerList == null ) { listenerList = new javax.swing.event.EventListenerList(); } - listenerList.add (java.awt.event.ActionListener.class, listener); + listenerList.add(java.awt.event.ActionListener.class, listener); } - + /** * Removes ActionListener from the list of listeners. * * @param listener The listener to remove. */ public void removeActionListener(java.awt.event.ActionListener listener) { - - listenerList.remove (java.awt.event.ActionListener.class, listener); + + listenerList.remove(java.awt.event.ActionListener.class, listener); } - + /** * Notifies all registered listeners about the event. - * + * * @param event The event to be fired */ private void fireActionListenerActionPerformed(java.awt.event.ActionEvent event) { - + if (listenerList == null) return; - Object[] listeners = listenerList.getListenerList (); + Object[] listeners = listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i]==java.awt.event.ActionListener.class) { - ((java.awt.event.ActionListener)listeners[i+1]).actionPerformed (event); + ((java.awt.event.ActionListener)listeners[i+1]).actionPerformed(event); } } } - + /** * This inner class provides the plotter with the functionality of moving slots etc * */ - class SlotMouseAdapter extends MouseAdapter{ - public void mouseReleased(MouseEvent e){ + class SlotMouseAdapter extends PlotSlotListener{ + public void slotContextMenuTriggered(PlotSlot aSlot, MouseEvent e){ Object source = e.getSource(); - if(source instanceof PlotSlot){ - selectedSlot = (PlotSlot)source; - if(SwingUtilities.isRightMouseButton(e) && selectedSlot.containsPlot()){ + if(aSlot instanceof PlotSlot){ + selectedSlot = aSlot; + if(selectedSlot.containsPlot()){ JPopupMenu aPopupMenu = new JPopupMenu(); + + if(selectedSlot.containsLegend()){ + JMenuItem aMenuItem=new JMenuItem("Hide Legend"); + aMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + selectedSlot.removeLegend(); + selectedSlot.validate(); + + } + }); + aPopupMenu.add(aMenuItem); + }else{ + JMenuItem aMenuItem=new JMenuItem("Show Legend"); + aMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + selectedSlot.addLegend(); + selectedSlot.validate(); + } + }); + aPopupMenu.add(aMenuItem); + } + + int[] availableSlots = itsSlotManager.getAvailableSlotIndexes(); if(availableSlots.length > 0){ - JMenuItem aMenuItem=new JMenuItem("Move to ..."); - + aPopupMenu.addSeparator(); + JMenuItem aMenuItem=new JMenuItem("Move to slot ..."); + aMenuItem.addMouseListener(new MouseAdapter(){ public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseReleased(MouseEvent e){ - System.out.println("hiero entered"); JPopupMenu moveSlotPopupMenu = new JPopupMenu(); int[] availableSlots = itsSlotManager.getAvailableSlotIndexes(); for(int i = 0; i < availableSlots.length; i++){ @@ -228,6 +252,7 @@ public class PlotSlotsPanel extends javax.swing.JPanel { subItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { itsSlotManager.movePlot(Integer.parseInt(selectedSlot.getLabel()),Integer.parseInt(evt.getActionCommand().substring(5))); + repaint(); } }); moveSlotPopupMenu.add(subItem); @@ -239,9 +264,30 @@ public class PlotSlotsPanel extends javax.swing.JPanel { aPopupMenu.add(aMenuItem); - aPopupMenu.setOpaque(true); - aPopupMenu.show(selectedSlot, e.getX(), e.getY()); + } + aPopupMenu.addSeparator(); + JMenuItem aMenuItem=new JMenuItem("Show in separate window (BETA)"); + aMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + PlotSlotViewFrame dialog = new PlotSlotViewFrame(itsSlotManager,Integer.parseInt(selectedSlot.getLabel()),"Viewer for Plot "+selectedSlot.getLabel()); + dialog.setVisible(true); + + } + }); + aPopupMenu.add(aMenuItem); + aPopupMenu.addSeparator(); + JMenuItem aMenuItem2=new JMenuItem("Clear Slot"); + aMenuItem2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + itsSlotManager.clearSlot(Integer.parseInt(selectedSlot.getLabel())); + selectedSlot.repaint(); + } + }); + aPopupMenu.add(aMenuItem2); + + aPopupMenu.setOpaque(true); + aPopupMenu.show(selectedSlot, e.getX(), e.getY()); } } } diff --git a/SAS/OTB/OTB/src/nl/astron/lofar/sas/otbcomponents/ParmDBPlotPanel.form b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otbcomponents/ParmDBPlotPanel.form index 2c06a226366..6070909e72c 100644 --- a/SAS/OTB/OTB/src/nl/astron/lofar/sas/otbcomponents/ParmDBPlotPanel.form +++ b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otbcomponents/ParmDBPlotPanel.form @@ -73,7 +73,7 @@ </Properties> <Constraints> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription"> - <GridBagConstraints gridX="0" gridY="1" gridWidth="2" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="2" insetsLeft="2" insetsBottom="2" insetsRight="2" anchor="10" weightX="0.0" weightY="0.0"/> + <GridBagConstraints gridX="0" gridY="1" gridWidth="3" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="2" insetsLeft="2" insetsBottom="2" insetsRight="2" anchor="10" weightX="0.0" weightY="0.0"/> </Constraint> </Constraints> @@ -91,34 +91,19 @@ </Component> </SubComponents> </Container> - <Container class="javax.swing.JScrollPane" name="helpPane"> - <AuxValues> - <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> - </AuxValues> + <Component class="javax.swing.JButton" name="bHelp"> + <Properties> + <Property name="text" type="java.lang.String" value="Help"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bHelpActionPerformed"/> + </Events> <Constraints> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription"> - <GridBagConstraints gridX="0" gridY="2" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="2" insetsLeft="2" insetsBottom="2" insetsRight="2" anchor="18" weightX="0.0" weightY="0.0"/> + <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="0" ipadX="10" ipadY="0" insetsTop="2" insetsLeft="2" insetsBottom="0" insetsRight="20" anchor="13" weightX="0.0" weightY="0.0"/> </Constraint> </Constraints> - - <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> - <SubComponents> - <Component class="javax.swing.JTextArea" name="tHelp"> - <Properties> - <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> - <Color blue="ee" green="ee" id="Viewport.background" palette="3" red="ee" type="palette"/> - </Property> - <Property name="columns" type="int" value="20"/> - <Property name="editable" type="boolean" value="false"/> - <Property name="rows" type="int" value="5"/> - <Property name="text" type="java.lang.String" value="To zoom: Click and hold the left mouse button and select a rectangle.
To reset the zoom: Press CTRL-LeftMouseButton to reset the zoom.
To change colors/etc: Double-Click on a line in the legend.
To change plot/axis labels and tics/etc: Click on an axis or title and press the right mouse button."/> - <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> - <Dimension value="[565, 75]"/> - </Property> - </Properties> - </Component> - </SubComponents> - </Container> + </Component> </SubComponents> </Container> </SubComponents> diff --git a/SAS/OTB/OTB/src/nl/astron/lofar/sas/otbcomponents/ParmDBPlotPanel.java b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otbcomponents/ParmDBPlotPanel.java index 1fdae99d23e..94cd63baa80 100644 --- a/SAS/OTB/OTB/src/nl/astron/lofar/sas/otbcomponents/ParmDBPlotPanel.java +++ b/SAS/OTB/OTB/src/nl/astron/lofar/sas/otbcomponents/ParmDBPlotPanel.java @@ -42,13 +42,15 @@ public class ParmDBPlotPanel extends javax.swing.JPanel implements IViewPanel{ itsMainFrame = aMainFrame; itsParamName = paramName; successfulNumberOfSlots=4; + initPanel(paramName); } /** Creates new form BeanForm */ public ParmDBPlotPanel() { initComponents(); - + successfulNumberOfSlots=4; + validate(); } public void setMainFrame(MainFrame aMainFrame) { @@ -195,6 +197,7 @@ public class ParmDBPlotPanel extends javax.swing.JPanel implements IViewPanel{ return name; } public void setContent(Object anObject) { + jParmDBnode node = (jParmDBnode)anObject; itsParamName = node.nodeID(); logger.trace("ParmDB name selected : "+itsParamName); @@ -206,8 +209,6 @@ public class ParmDBPlotPanel extends javax.swing.JPanel implements IViewPanel{ slotsPane.getViewport().setPreferredSize(new Dimension(640,480)); itsSlotsPanel.setMinimumSize(new Dimension(640,480)); itsSlotsPanel.setPreferredSize(new Dimension(panelWidth-440,panelHeight-340)); - //itsSlotsPanel.repaint(); - //initPanel(itsParamName); } private void saveInput() { @@ -247,8 +248,7 @@ public class ParmDBPlotPanel extends javax.swing.JPanel implements IViewPanel{ cSlotsAmount = new javax.swing.JComboBox(); slotsPane = new javax.swing.JScrollPane(); itsSlotsPanel = new nl.astron.lofar.sas.otb.util.plotter.PlotSlotsPanel(); - helpPane = new javax.swing.JScrollPane(); - tHelp = new javax.swing.JTextArea(); + bHelp = new javax.swing.JButton(); setLayout(new java.awt.BorderLayout()); @@ -285,80 +285,77 @@ public class ParmDBPlotPanel extends javax.swing.JPanel implements IViewPanel{ gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; - gridBagConstraints.gridwidth = 2; + gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); contentPanel.add(slotsPane, gridBagConstraints); - tHelp.setBackground(javax.swing.UIManager.getDefaults().getColor("Viewport.background")); - tHelp.setColumns(20); - tHelp.setEditable(false); - tHelp.setRows(5); - tHelp.setText("To zoom: Click and hold the left mouse button and select a rectangle.\nTo reset the zoom: Press CTRL-LeftMouseButton to reset the zoom.\nTo change colors/etc: Double-Click on a line in the legend.\nTo change plot/axis labels and tics/etc: Click on an axis or title and press the right mouse button."); - tHelp.setMinimumSize(new java.awt.Dimension(565, 75)); - helpPane.setViewportView(tHelp); + bHelp.setText("Help"); + bHelp.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + bHelpActionPerformed(evt); + } + }); gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 2; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); - contentPanel.add(helpPane, gridBagConstraints); + gridBagConstraints.ipadx = 10; + gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 0, 20); + contentPanel.add(bHelp, gridBagConstraints); add(contentPanel, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents + + private void bHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bHelpActionPerformed + String message = "Slots:\nRight-click on the light-gray header of a slot"; + message+=" to see what you can do with the plot in it.\n\nPlots:\n"; + message+="To zoom: Click and hold the left mouse button and select a rectangle."; + message+="\nTo reset the zoom: Press CTRL-LeftMouseButton to reset the zoom."; + message+="\nTo change colors/etc: Double-Click on a line in the legend.\n"; + message+="To change plot/axis labels and tics/etc: Click on an axis or title"; + message+=" and press the right mouse button."; + + JOptionPane.showMessageDialog(null,message, "Help",JOptionPane.INFORMATION_MESSAGE); + + }//GEN-LAST:event_bHelpActionPerformed private void cSlotsAmountItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cSlotsAmountItemStateChanged - int wannaHaveSlots = Integer.parseInt(evt.getItem().toString()); - - System.out.println("current slots: "+ successfulNumberOfSlots); - System.out.println("want to have slots: "+ wannaHaveSlots); - if(wannaHaveSlots != successfulNumberOfSlots){ + int wannaHaveSlots = Integer.parseInt(evt.getItemSelectable().getSelectedObjects()[0].toString()); + if (wannaHaveSlots != successfulNumberOfSlots){ try { + wannaHaveSlots = Integer.parseInt(evt.getItem().toString()); itsSlotsPanel.setAmountOfSlots(wannaHaveSlots,false); + successfulNumberOfSlots = itsSlotsPanel.getAmountOfSlots(); } catch (NumberFormatException ex) { //TODO log! ex.printStackTrace(); } catch (IllegalArgumentException ex) { //TODO log! - //ex.printStackTrace(); String[] buttons = {"Clear Slots","Cancel"}; int choice = JOptionPane.showOptionDialog(this,ex.getMessage(), "Plots detected in to be deleted slots", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,buttons,buttons[0]); if(choice == 0){ - itsSlotsPanel.setAmountOfSlots(wannaHaveSlots,true); + itsSlotsPanel.setAmountOfSlots(Integer.parseInt(evt.getItem().toString()),true); + successfulNumberOfSlots = itsSlotsPanel.getAmountOfSlots(); }else{ - double squareRoot = Math.sqrt(Double.parseDouble(""+itsSlotsPanel.getAmountOfSlots())); - System.out.println("cancelling : slots was "+ itsSlotsPanel.getAmountOfSlots()); + double squareRoot = Math.sqrt(Double.parseDouble(""+successfulNumberOfSlots)); int wishedIndex = (Integer.parseInt(""+(int)squareRoot))-1; - cSlotsAmount.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "4", "9", "16", "25" })); - System.out.println("cancelling : setting combobox to index "+ wishedIndex +" / value "+squareRoot); - cSlotsAmount.addItemListener(new java.awt.event.ItemListener() { - public void itemStateChanged(java.awt.event.ItemEvent evt) { - cSlotsAmountItemStateChanged(evt); - } - }); - System.out.println("cancelling : slots will be "+ itsSlotsPanel.getAmountOfSlots()); - - cSlotsAmount.setSelectedItem(new String(""+itsSlotsPanel.getAmountOfSlots())); - } + cSlotsAmount.setSelectedItem(new String(""+successfulNumberOfSlots)); + } } + } - successfulNumberOfSlots = itsSlotsPanel.getAmountOfSlots(); }//GEN-LAST:event_cSlotsAmountItemStateChanged // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton bHelp; private javax.swing.JComboBox cSlotsAmount; private javax.swing.JPanel contentPanel; - private javax.swing.JScrollPane helpPane; private nl.astron.lofar.sas.otb.util.plotter.PlotSlotsPanel itsSlotsPanel; private javax.swing.JLabel lSlotsAmount; private javax.swing.JScrollPane slotsPane; - private javax.swing.JTextArea tHelp; // End of variables declaration//GEN-END:variables /** -- GitLab