001: /*
002: * BlobColumnPanel.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.renderer;
013:
014: import java.awt.Color;
015: import java.awt.Dimension;
016: import java.awt.Font;
017: import java.awt.GridBagConstraints;
018: import java.awt.GridBagLayout;
019: import java.awt.event.ActionListener;
020: import javax.swing.JLabel;
021: import javax.swing.JPanel;
022: import javax.swing.SwingConstants;
023: import workbench.gui.WbSwingUtilities;
024: import workbench.gui.components.FlatButton;
025: import workbench.resource.ResourceMgr;
026:
027: /**
028: * Renderer for BLOB datatype...
029: * @author support@sql-workbench.net
030: */
031: public class BlobColumnPanel extends JPanel {
032: private static final int BUTTON_WIDTH = 16;
033: private FlatButton openButton = new FlatButton("...");
034: private JLabel label = new JLabel();
035:
036: public BlobColumnPanel() {
037: super ();
038: setLayout(new GridBagLayout());
039: Dimension d = new Dimension(BUTTON_WIDTH, BUTTON_WIDTH);
040: openButton.setBasicUI();
041: openButton.setFlatLook();
042: openButton.setBorder(WbSwingUtilities.FLAT_BUTTON_BORDER);
043: openButton.setMaximumSize(d);
044: openButton.setPreferredSize(d);
045: openButton.setMinimumSize(d);
046: openButton.setEnabled(true);
047: openButton.setFocusable(false);
048: label.setHorizontalTextPosition(SwingConstants.LEFT);
049: label.setVerticalTextPosition(SwingConstants.TOP);
050: GridBagConstraints c = new GridBagConstraints();
051: c.gridx = 0;
052: c.gridy = 0;
053: c.weightx = 1;
054: c.weighty = 1;
055: c.fill = GridBagConstraints.NONE;
056: c.anchor = GridBagConstraints.NORTHWEST;
057: add(label, c);
058:
059: c.gridx = 2;
060: c.fill = GridBagConstraints.NONE;
061: c.weightx = 0;
062: add(openButton, c);
063:
064: openButton.setVisible(true);
065: this .setToolTipText(ResourceMgr.getDescription(
066: "LblShowBlobInfo", true));
067: }
068:
069: public int getButtonWidth() {
070: if (openButton != null && openButton.isVisible())
071: return BUTTON_WIDTH;
072: else
073: return 0;
074: }
075:
076: public void setValue(Object value) {
077: if (value == null) {
078: this .label.setText("");
079: } else {
080: this .label.setText("(BLOB)");
081: }
082: }
083:
084: public void addActionListener(ActionListener l) {
085: if (openButton != null)
086: openButton.addActionListener(l);
087: }
088:
089: public void removeActionListener(ActionListener l) {
090: if (openButton != null)
091: openButton.removeActionListener(l);
092: }
093:
094: public void setFont(Font f) {
095: super .setFont(f);
096: if (label != null)
097: label.setFont(f);
098: }
099:
100: public String getLabel() {
101: return label.getText();
102: }
103:
104: public void setBackground(Color c) {
105: super .setBackground(c);
106: if (label != null)
107: label.setBackground(c);
108: }
109:
110: public void setForeground(Color c) {
111: super.setForeground(c);
112: if (label != null)
113: label.setForeground(c);
114: }
115:
116: }
|