1 package com.calipso.reportgenerator.userinterface; 2 3 import com.calipso.reportgenerator.common.InfoException; 4 5 import javax.swing.*; 6 import java.awt.*; 7 import java.awt.datatransfer.StringSelection ; 8 import java.awt.dnd.*; 9 import java.util.Vector ; 10 import java.util.Iterator ; 11 import java.util.Set ; 12 import com.calipso.reportgenerator.common.IReportManager; 13 import com.calipso.reportgenerator.common.ShowExceptionMessageDialog; 14 15 18 public class DragSourcePanel extends JPanel implements DragGestureListener, DragSourceListener { 19 20 private JLabel label; 21 private JButton button; 22 private DimensionColumnValue framColVal; 23 private Vector colVecJCeck; 24 private PivotTable pivote; 25 private String location; 26 private IReportManager reportManager; 27 private int reportHandle; 28 29 33 public JLabel getLabel() { 34 return label; 35 } 36 37 41 public JButton getButton() { 42 return button; 43 } 44 45 49 public DragSourcePanel(String name, PivotTable pivote, String description, String location, IReportManager reportManager,int reportHandle) { 50 this.pivote = pivote; 51 this.location = location; 52 this.reportManager = reportManager; 53 this.reportHandle = reportHandle; 54 label = new JLabel(description + " "); 55 label.setBackground(Color.BLACK); 56 label.setForeground(Color.WHITE); 57 Font font = new Font("Arial", Font.BOLD, 10); 58 label.setFont(font); 59 setName(name); 60 setLayout(new BorderLayout()); 61 button = new JButton(" "); 62 button.setPreferredSize(new Dimension(10, 10)); 63 add(button, BorderLayout.EAST); 64 button.addActionListener(new java.awt.event.ActionListener () { 65 public void actionPerformed(java.awt.event.ActionEvent evt) { 66 try { 67 jButton1ActionPerformed(); 68 } 69 catch (Exception e) { 70 ShowExceptionMessageDialog.initExceptionDialogMessage(com.calipso.reportgenerator.common.LanguageTraslator.traslate("89"),e); 71 } 72 } 73 }); 74 add(label, BorderLayout.CENTER); 75 DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this); 76 } 77 78 82 public DimensionColumnValue getFramColVal() { 83 return framColVal; 84 } 85 86 90 private void jButton1ActionPerformed() throws InfoException { 91 Set set = getReportManager().getDimensionValues(getReportHandle(),getName()); 92 int maxWidthLabel = Math.max((int) (getPreferredSize().getWidth()), getMaxWidthLabel(storeCheckButtonLabel(set))); 93 this.framColVal = new DimensionColumnValue(maxWidthLabel, getLocationOnScreen(), pivote, colVecJCeck, location, getName()); 94 95 } 96 97 102 private int getMaxWidthLabel(Vector vector) { 103 Font font = new Font("Arial", Font.BOLD, 10); 104 int width = 0; 105 int max = -1; 106 JTextField aux = null; 107 for (int index = 0; index < vector.size(); index++) { 108 Object vec[] = (Object []) vector.get(index); 109 String str = (vec[0]).toString(); 110 width = getFontMetrics(font).stringWidth(str); 111 if (width > max) { 112 aux = new JTextField(str.trim()); 113 max = (int) aux.getPreferredSize().getWidth() + str.length(); 114 } 115 } 116 return max; 117 } 118 119 123 private Vector storeCheckButtonLabel(Set set) { 124 ColumnProperties properties = pivote.getTableProperties().getRowColumn(getName()); 125 Set unchecked = properties.getExcludeValue(); 126 colVecJCeck = new Vector (); 127 Iterator iterator = set.iterator(); 128 while (iterator.hasNext()) { 129 Object value = iterator.next(); 130 Object [] btnArray = new Object [2]; 131 btnArray[0] = value; 132 btnArray[1] = new Boolean (unchecked == null || !unchecked.contains(value)); 133 colVecJCeck.add(btnArray); 134 } 135 return colVecJCeck; 136 } 137 138 public String getLocationOfComponent() { 139 return location; 140 } 141 142 146 public void dragGestureRecognized(DragGestureEvent dge) { 147 dge.startDrag(DragSource.DefaultCopyNoDrop, new StringSelection (this.getName()), this); 148 } 149 150 154 public void dragEnter(DragSourceDragEvent dsde) { 155 dsde.getDragSourceContext().setCursor(DragSource.DefaultCopyDrop); 156 } 157 158 162 public void dragOver(DragSourceDragEvent dsde) { 163 } 164 165 169 public void dropActionChanged(DragSourceDragEvent dsde) { 170 } 171 172 176 public void dragExit(DragSourceEvent dse) { 177 dse.getDragSourceContext().setCursor(DragSource.DefaultCopyNoDrop); 178 } 179 180 184 public void dragDropEnd(DragSourceDropEvent dsde) { 185 } 186 187 public IReportManager getReportManager() { 188 return reportManager; 189 } 190 191 public int getReportHandle() { 192 return reportHandle; 193 } 194 } 195 | Popular Tags |