1 32 33 package it.businesslogic.ireport.gui.box; 34 import it.businesslogic.ireport.*; 35 import java.awt.*; 36 40 public class SampleBoxPanel extends javax.swing.JPanel { 41 42 private Box box; 43 44 45 public SampleBoxPanel() { 46 initComponents(); 47 this.setBackground(Color.WHITE); 48 setBox(new Box()); 49 } 50 51 public Box getBox() { 52 return box; 53 } 54 55 public void setBox(Box box) { 56 this.box = box; 57 this.invalidate(); 58 this.repaint(); 59 } 60 61 public void refresh() { 62 this.invalidate(); 63 this.repaint(); 64 } 65 66 public void paint(Graphics g2) 67 { 68 Graphics2D g = (Graphics2D)g2; 69 g.clearRect(0,0,this.getWidth(),this.getHeight()); 70 g.setColor( Color.LIGHT_GRAY); 71 Stroke oldStroke = g.getStroke(); 72 Color oldColor = g.getColor(); 73 74 g.fillRect(10, 10, this.getWidth()-20, this.getHeight()-20); 75 76 if (!getBox().getLeftBorder().equals("None")) 77 { 78 Stroke stroke = ReportElement.getPenStroke( getBox().getLeftBorder(), 1.0); 79 g.setStroke(stroke); 80 g.setColor(getBox().getLeftBorderColor()); 81 g.drawLine(10, 10, 10, this.getHeight()-10); 82 } 83 84 if (!getBox().getRightBorder().equals("None")) 85 { 86 Stroke stroke = ReportElement.getPenStroke( getBox().getRightBorder(), 1.0); 87 g.setStroke(stroke); 88 g.setColor(getBox().getRightBorderColor()); 89 g.drawLine(this.getWidth()-10, 10, this.getWidth()-10, this.getHeight()-10); 90 } 91 92 if (!getBox().getTopBorder().equals("None")) 93 { 94 Stroke stroke = ReportElement.getPenStroke( getBox().getTopBorder(), 1.0); 95 g.setStroke(stroke); 96 g.setColor(getBox().getTopBorderColor()); 97 g.drawLine(10, 10, this.getWidth()-10, 10); 98 } 99 100 if (!getBox().getBottomBorder().equals("None")) 101 { 102 Stroke stroke = ReportElement.getPenStroke( getBox().getBottomBorder(), 1.0); 103 g.setStroke(stroke); 104 g.setColor(getBox().getBottomBorderColor()); 105 g.drawLine(10, this.getHeight()-10, this.getWidth()-10, this.getHeight()-10); 106 } 107 108 g.setColor(oldColor); 109 g.setStroke(oldStroke); 110 } 111 112 113 118 private void initComponents() { 120 setLayout(new java.awt.BorderLayout ()); 121 122 } 124 125 128 } 129 | Popular Tags |