1 56 57 package org.objectstyle.cayenne.dataview.dvmodeler; 58 59 import java.awt.BorderLayout ; 60 import java.awt.Color ; 61 import java.awt.GradientPaint ; 62 import java.awt.Graphics ; 63 import java.awt.Graphics2D ; 64 import java.awt.Paint ; 65 66 import javax.swing.Icon ; 67 import javax.swing.JComponent ; 68 import javax.swing.JLabel ; 69 import javax.swing.JPanel ; 70 import javax.swing.UIManager ; 71 72 import com.jgoodies.forms.factories.Borders; 73 import com.jgoodies.looks.plastic.PlasticXPLookAndFeel; 74 75 80 81 public class JTile extends JPanel { 82 private TitleBar titleBar = new TitleBar(); 83 private JComponent contentPane; 84 private String captionText; 85 private Icon captionIcon; 86 87 public JTile() { 88 this(null, null, null); 89 } 90 91 public JTile(JComponent contentPane, String caption) { 92 this(contentPane, caption, null); 93 } 94 95 public JTile(String caption) { 96 this(null, caption, null); 97 } 98 99 public JTile(JComponent contentPane) { 100 this(contentPane, null, null); 101 } 102 103 public JTile(JComponent contentPane, String caption, Icon icon) { 104 init(); 105 setContentPane(contentPane); 106 setCaption(caption); 107 setIcon(icon); 108 } 109 110 public void setContentPane(JComponent contentPane) { 111 this.contentPane = contentPane; 112 this.add(contentPane, BorderLayout.CENTER); 113 } 114 115 public JComponent getContentPane() { 116 return contentPane; 117 } 118 119 public void setCaption(String text) { 120 this.captionText = text; 121 titleBar.setCaption(text); 122 } 123 124 public String getCaption() { 125 return captionText; 126 } 127 128 public void setIcon(Icon icon) { 129 this.captionIcon = icon; 130 titleBar.setIcon(icon); 131 } 132 133 public Icon getIcon() { 134 return captionIcon; 135 } 136 137 private void init() { 138 this.setBorder(CustomBorderFactory.TILE_BORDER); 139 this.setLayout(new BorderLayout ()); 140 this.add(titleBar, BorderLayout.NORTH); 141 } 142 143 private class TitleBar extends JPanel { 144 private Color leftColor; 145 private JLabel caption = new JLabel (" "); 146 private JLabel captionIcon = new JLabel (EmptyIcon.DEFAULT_ICON); 147 148 private TitleBar() { 149 leftColor = PlasticXPLookAndFeel.getSimpleInternalFrameBackground(); 150 caption.setOpaque(false); 151 caption.setForeground(PlasticXPLookAndFeel.getSimpleInternalFrameForeground()); 152 caption.setBorder(Borders.DLU2_BORDER); 153 captionIcon.setOpaque(false); 154 captionIcon.setBorder(Borders.DLU2_BORDER); 155 setLayout(new BorderLayout (0, 0)); 156 add(caption, BorderLayout.CENTER); 157 add(captionIcon, BorderLayout.WEST); 158 } 159 160 private void setCaption(String text) { 161 caption.setText((text != null && text.length() > 0 ? text : " ")); 162 } 163 164 private void setIcon(Icon icon) { 165 captionIcon.setIcon((icon != null ? icon : EmptyIcon.DEFAULT_ICON)); 166 } 167 168 public void paintComponent(Graphics g) { 169 super.paintComponent(g); 170 Graphics2D g2d = (Graphics2D )g; 171 Paint oldPaint = g2d.getPaint(); 172 int width = getWidth(); 173 int height = getHeight(); 174 Color highlight = UIManager.getColor("controlLtHighlight"); 175 Color shadow = UIManager.getColor("controlShadow"); 176 177 g.setColor(highlight); 178 g.drawLine(0, 0, width, 0); 179 g.drawLine(0, 0, 0, height); 180 g.setColor(shadow); 181 g.drawLine(0, height-1, width, height-1); 182 GradientPaint paint = new GradientPaint ( 183 1, height/2, leftColor, width, height/2, getBackground(), false); 184 g2d.setPaint(paint); 185 g2d.fillRect(1, 1, width-1, height-2); 186 187 g2d.setPaint(oldPaint); 188 } 189 } 190 } 191 | Popular Tags |