001: package com.calipso.reportgenerator.userinterface.dinamicchart;
002:
003: import javax.swing.*;
004: import java.awt.event.ActionListener;
005: import java.awt.event.ActionEvent;
006: import java.awt.datatransfer.StringSelection;
007: import java.awt.dnd.*;
008: import java.awt.*;
009: import java.util.Set;
010: import java.util.HashSet;
011:
012: /**
013: *
014: * User: soliveri
015: * Date: Jul 23, 2003
016: * Time: 4:48:03 PM
017: *
018: */
019:
020: public class SourceDimension extends JPanel implements
021: DragGestureListener, DragSourceListener, ActionListener {
022:
023: private String name;
024: private DragSource dragSource;
025: private JLabel lbDimesionValues;
026: private JButton btDimesionValues;
027: private DimensionValues dimensionValues;
028: private int originalWidth;
029:
030: public SourceDimension(String name, String text,
031: HashSet excludedValues, Set notExcludedValues) {
032: this .name = name;
033: dimensionValues = new DimensionValues(this , excludedValues,
034: notExcludedValues);
035: setLayout(new BorderLayout());
036: lbDimesionValues = new JLabel(text + " ");
037: lbDimesionValues.setFont(new Font("Arial", Font.BOLD, 10));
038: btDimesionValues = new JButton();
039: btDimesionValues.addActionListener(this );
040: btDimesionValues.setPreferredSize(new Dimension(10, 10));
041: setSize(new Dimension(lbDimesionValues.getPreferredSize().width
042: + 20 + btDimesionValues.getSize().width, 15));
043: setPreferredSize(new Dimension((lbDimesionValues
044: .getPreferredSize().width)
045: + 20 + btDimesionValues.getSize().width, 15));
046: setMinimumSize(new Dimension((lbDimesionValues
047: .getPreferredSize().width)
048: + 20 + btDimesionValues.getSize().width, 15));
049: setMaximumSize(new Dimension((lbDimesionValues
050: .getPreferredSize().width)
051: + 20 + btDimesionValues.getSize().width, 15));
052: originalWidth = (lbDimesionValues.getPreferredSize().width)
053: + 20 + btDimesionValues.getSize().width;
054: add(lbDimesionValues, BorderLayout.CENTER);
055: add(btDimesionValues, BorderLayout.EAST);
056: setBorder(BorderFactory.createRaisedBevelBorder());
057: dragSource = DragSource.getDefaultDragSource();
058: dragSource.createDefaultDragGestureRecognizer(this ,
059: DnDConstants.ACTION_MOVE, this );
060: }
061:
062: public String getName() {
063: return name;
064: }
065:
066: public void dragGestureRecognized(DragGestureEvent dge) {
067: dge.startDrag(DragSource.DefaultCopyNoDrop,
068: new StringSelection(getName()), this );
069: }
070:
071: public void dragEnter(DragSourceDragEvent dsde) {
072: dsde.getDragSourceContext().setCursor(
073: DragSource.DefaultCopyDrop);
074: }
075:
076: public void dragOver(DragSourceDragEvent dsde) {
077: }
078:
079: public void dropActionChanged(DragSourceDragEvent dsde) {
080: }
081:
082: public void dragExit(DragSourceEvent dse) {
083: dse.getDragSourceContext()
084: .setCursor(DragSource.DefaultCopyDrop);
085: }
086:
087: public void dragDropEnd(DragSourceDropEvent dsde) {
088: }
089:
090: public void actionPerformed(ActionEvent e) {
091: if (e.getSource() == btDimesionValues) {
092: dimensionValues.setLocation(getLocationOnScreen().x,
093: getLocationOnScreen().y + 15);
094: dimensionValues.setSize(100, dimensionValues
095: .getPreferredSize().height);
096: dimensionValues.setVisible(true);
097: }
098: }
099:
100: public HashSet getExcludedValues() {
101: return dimensionValues.getExcludedDimensionsValues();
102: }
103:
104: public int getOriginalWidth() {
105: return originalWidth;
106: }
107: }
|