KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > dinamicchart > SourceDimension


1 package com.calipso.reportgenerator.userinterface.dinamicchart;
2
3 import javax.swing.*;
4 import java.awt.event.ActionListener JavaDoc;
5 import java.awt.event.ActionEvent JavaDoc;
6 import java.awt.datatransfer.StringSelection JavaDoc;
7 import java.awt.dnd.*;
8 import java.awt.*;
9 import java.util.Set JavaDoc;
10 import java.util.HashSet JavaDoc;
11
12 /**
13  *
14  * User: soliveri
15  * Date: Jul 23, 2003
16  * Time: 4:48:03 PM
17  *
18  */

19
20 public class SourceDimension extends JPanel implements DragGestureListener, DragSourceListener, ActionListener JavaDoc {
21
22   private String JavaDoc name;
23   private DragSource dragSource;
24   private JLabel lbDimesionValues;
25   private JButton btDimesionValues;
26   private DimensionValues dimensionValues;
27   private int originalWidth;
28
29   public SourceDimension(String JavaDoc name, String JavaDoc text, HashSet JavaDoc excludedValues, Set JavaDoc notExcludedValues) {
30     this.name = name;
31     dimensionValues = new DimensionValues(this, excludedValues, notExcludedValues);
32     setLayout(new BorderLayout());
33     lbDimesionValues = new JLabel(text + " ");
34     lbDimesionValues.setFont(new Font("Arial", Font.BOLD, 10));
35     btDimesionValues = new JButton();
36     btDimesionValues.addActionListener(this);
37     btDimesionValues.setPreferredSize(new Dimension(10, 10));
38     setSize(new Dimension(lbDimesionValues.getPreferredSize().width + 20 + btDimesionValues.getSize().width, 15));
39     setPreferredSize(new Dimension((lbDimesionValues.getPreferredSize().width) + 20 + btDimesionValues.getSize().width, 15));
40     setMinimumSize(new Dimension((lbDimesionValues.getPreferredSize().width) + 20 + btDimesionValues.getSize().width, 15));
41     setMaximumSize(new Dimension((lbDimesionValues.getPreferredSize().width) + 20 + btDimesionValues.getSize().width, 15));
42     originalWidth = (lbDimesionValues.getPreferredSize().width) + 20 + btDimesionValues.getSize().width;
43     add(lbDimesionValues, BorderLayout.CENTER);
44     add(btDimesionValues, BorderLayout.EAST);
45     setBorder(BorderFactory.createRaisedBevelBorder());
46     dragSource = DragSource.getDefaultDragSource();
47     dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this);
48   }
49
50   public String JavaDoc getName() {
51     return name;
52   }
53
54   public void dragGestureRecognized(DragGestureEvent dge) {
55     dge.startDrag(DragSource.DefaultCopyNoDrop, new StringSelection JavaDoc(getName()), this);
56   }
57
58   public void dragEnter(DragSourceDragEvent dsde) {
59     dsde.getDragSourceContext().setCursor(DragSource.DefaultCopyDrop);
60   }
61
62   public void dragOver(DragSourceDragEvent dsde) {
63   }
64
65   public void dropActionChanged(DragSourceDragEvent dsde) {
66   }
67
68   public void dragExit(DragSourceEvent dse) {
69     dse.getDragSourceContext().setCursor(DragSource.DefaultCopyDrop);
70   }
71
72   public void dragDropEnd(DragSourceDropEvent dsde) {
73   }
74
75   public void actionPerformed(ActionEvent JavaDoc e) {
76     if(e.getSource() == btDimesionValues) {
77       dimensionValues.setLocation(getLocationOnScreen().x, getLocationOnScreen().y + 15);
78       dimensionValues.setSize(100, dimensionValues.getPreferredSize().height);
79       dimensionValues.setVisible(true);
80     }
81   }
82
83   public HashSet JavaDoc getExcludedValues() {
84     return dimensionValues.getExcludedDimensionsValues();
85   }
86
87   public int getOriginalWidth() {
88     return originalWidth;
89   }
90 }
91
Popular Tags