/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* JPnlItemFlow.java
*
* Created on 17/07/2010, 17:11:41
*/
package systole.view.tabs.segments;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JToolTip;
import javax.swing.border.Border;
import org.jdesktop.application.Action;
import org.jdesktop.swingx.border.DropShadowBorder;
import org.jfree.chart.ChartPanel;
/**
*
* @author jmj
*/
public abstract class JPnlItem extends javax.swing.JPanel {
private Integer segmentIndex;
protected Border selectedBorder;
protected Border defaultBorder;
protected Color selectedColor = new Color(192, 192, 192);
protected boolean clicked = false;
/** Creates new form JPnlItemFlow
* @param segmentNumber
* @param pnl
* @param hint
*/
public JPnlItem(Integer segmentNumber, ChartPanel pnl, String hint) {
initComponents();
this.segmentIndex = segmentNumber;
this.jLblSegment.setText("Segmento " + (this.segmentIndex + 1));
this.jPnlCenter.add(pnl, BorderLayout.CENTER);
this.jPnlCenter.revalidate();
pnl.setComponentPopupMenu(jPopupMenuRemove);
this.setComponentPopupMenu(jPopupMenuRemove);
this.jPnlCenter.setComponentPopupMenu(jPopupMenuRemove);
DropShadowBorder selectBorder = new DropShadowBorder();
selectBorder.setShowLeftShadow(true);
selectBorder.setShowTopShadow(true);
this.selectedBorder = selectBorder;
this.defaultBorder = this.getBorder();
pnl.addMouseListener(new MouseListenerChart(this));
this.setToolTipText(hint);
this.jPnlCenter.setToolTipText(hint);
pnl.setToolTipText(hint);
}
protected void setVisibleCorrelation(boolean value) {
this.jMenuItemCorrelation.setVisible(value);
}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPopupMenuRemove = new javax.swing.JPopupMenu();
jMenuItemRemove = new javax.swing.JMenuItem();
jMenuItemCorrelation = new javax.swing.JMenuItem();
jPnlTop = new javax.swing.JPanel();
jLblSegment = new javax.swing.JLabel();
jPnlBottom = new javax.swing.JPanel();
jPnlRigth = new javax.swing.JPanel();
jPnlLeft = new javax.swing.JPanel();
jPnlCenter = new javax.swing.JPanel();
jPopupMenuRemove.setName("jPopupMenuRemove"); // NOI18N
javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(systole.view.SystoleApp.class).getContext().getActionMap(JPnlItem.class, this);
jMenuItemRemove.setAction(actionMap.get("removeSegment")); // NOI18N
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(systole.view.SystoleApp.class).getContext().getResourceMap(JPnlItem.class);
jMenuItemRemove.setIcon(resourceMap.getIcon("jMenuItemRemove.icon")); // NOI18N
jMenuItemRemove.setText(resourceMap.getString("jMenuItemRemove.text")); // NOI18N
jMenuItemRemove.setName("jMenuItemRemove"); // NOI18N
jPopupMenuRemove.add(jMenuItemRemove);
jMenuItemCorrelation.setAction(actionMap.get("applyCorrelation")); // NOI18N
jMenuItemCorrelation.setIcon(resourceMap.getIcon("jMenuItemCorrelation.icon")); // NOI18N
jMenuItemCorrelation.setText(resourceMap.getString("jMenuItemCorrelation.text")); // NOI18N
jMenuItemCorrelation.setToolTipText(resourceMap.getString("jMenuItemCorrelation.toolTipText")); // NOI18N
jMenuItemCorrelation.setName("jMenuItemCorrelation"); // NOI18N
jPopupMenuRemove.add(jMenuItemCorrelation);
setBorder(new javax.swing.border.LineBorder(resourceMap.getColor("Form.border.lineColor"), 2, true)); // NOI18N
setName("Form"); // NOI18N
setLayout(new java.awt.BorderLayout());
jPnlTop.setName("jPnlTop"); // NOI18N
jPnlTop.setPreferredSize(new java.awt.Dimension(220, 15));
jPnlTop.setLayout(new java.awt.BorderLayout());
jLblSegment.setFont(jLblSegment.getFont().deriveFont(jLblSegment.getFont().getSize()-1f));
jLblSegment.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLblSegment.setText(resourceMap.getString("jLblSegment.text")); // NOI18N
jLblSegment.setName("jLblSegment"); // NOI18N
jPnlTop.add(jLblSegment, java.awt.BorderLayout.CENTER);
add(jPnlTop, java.awt.BorderLayout.NORTH);
jPnlBottom.setName("jPnlBottom"); // NOI18N
jPnlBottom.setPreferredSize(new java.awt.Dimension(220, 8));
javax.swing.GroupLayout jPnlBottomLayout = new javax.swing.GroupLayout(jPnlBottom);
jPnlBottom.setLayout(jPnlBottomLayout);
jPnlBottomLayout.setHorizontalGroup(
jPnlBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 396, Short.MAX_VALUE)
);
jPnlBottomLayout.setVerticalGroup(
jPnlBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 8, Short.MAX_VALUE)
);
add(jPnlBottom, java.awt.BorderLayout.SOUTH);
jPnlRigth.setName("jPnlRigth"); // NOI18N
jPnlRigth.setPreferredSize(new java.awt.Dimension(8, 152));
javax.swing.GroupLayout jPnlRigthLayout = new javax.swing.GroupLayout(jPnlRigth);
jPnlRigth.setLayout(jPnlRigthLayout);
jPnlRigthLayout.setHorizontalGroup(
jPnlRigthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 8, Short.MAX_VALUE)
);
jPnlRigthLayout.setVerticalGroup(
jPnlRigthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 273, Short.MAX_VALUE)
);
add(jPnlRigth, java.awt.BorderLayout.LINE_END);
jPnlLeft.setName("jPnlLeft"); // NOI18N
jPnlLeft.setPreferredSize(new java.awt.Dimension(8, 152));
javax.swing.GroupLayout jPnlLeftLayout = new javax.swing.GroupLayout(jPnlLeft);
jPnlLeft.setLayout(jPnlLeftLayout);
jPnlLeftLayout.setHorizontalGroup(
jPnlLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 8, Short.MAX_VALUE)
);
jPnlLeftLayout.setVerticalGroup(
jPnlLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 273, Short.MAX_VALUE)
);
add(jPnlLeft, java.awt.BorderLayout.LINE_START);
jPnlCenter.setName("jPnlCenter"); // NOI18N
jPnlCenter.setLayout(new java.awt.BorderLayout());
add(jPnlCenter, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLblSegment;
private javax.swing.JMenuItem jMenuItemCorrelation;
private javax.swing.JMenuItem jMenuItemRemove;
private javax.swing.JPanel jPnlBottom;
private javax.swing.JPanel jPnlCenter;
private javax.swing.JPanel jPnlLeft;
private javax.swing.JPanel jPnlRigth;
private javax.swing.JPanel jPnlTop;
private javax.swing.JPopupMenu jPopupMenuRemove;
// End of variables declaration//GEN-END:variables
@Action
public void removeSegment() {
}
/**
* @return the segmentIndex
*/
public Integer getSegmentIndex() {
return segmentIndex;
}
@Override
protected void processMouseEvent(MouseEvent e) {
if ((e.getClickCount() == 1) && (e.getButton() == MouseEvent.BUTTON1)) {
this.click();
}
}
/**
*
*/
public abstract void click();
/**
*
*/
public void unclick() {
if (this.isClicked()) {
this.setBorder(this.defaultBorder);
this.revalidate();
this.setClicked(false);
}
}
/**
* @return the clicked
*/
public boolean isClicked() {
return clicked;
}
/**
* @param clicked the clicked to set
*/
public void setClicked(boolean clicked) {
this.clicked = clicked;
}
/**
*
*/
public abstract void select();
@Action
public void applyCorrelation() {
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final JPnlItem other = (JPnlItem) obj;
if (this.segmentIndex != other.segmentIndex && (this.segmentIndex == null || !this.segmentIndex.equals(other.segmentIndex))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 13 * hash + (this.segmentIndex != null ? this.segmentIndex.hashCode() : 0);
hash = 13 * hash + (this.jLblSegment != null ? this.jLblSegment.hashCode() : 0);
return hash;
}
/**
* @return the jPnlBottom
*/
public javax.swing.JPanel getJPnlBottom() {
return jPnlBottom;
}
/**
* @return the jPnlLeft
*/
public javax.swing.JPanel getJPnlLeft() {
return jPnlLeft;
}
/**
* @return the jPnlRigth
*/
public javax.swing.JPanel getJPnlRigth() {
return jPnlRigth;
}
/**
* @return the jPnlTop
*/
public javax.swing.JPanel getJPnlTop() {
return jPnlTop;
}
private class MouseListenerChart implements MouseListener {
private JPnlItem parent;
public MouseListenerChart(JPnlItem parent) {
this.parent = parent;
}
public void mouseClicked(MouseEvent e) {
if ((e.getClickCount() == 1) && (e.getButton() == MouseEvent.BUTTON1)) {
this.parent.click();
}
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
}
}