01: /*
02: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
07: *
08: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
09: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
10: * the license for the specific language governing your rights and limitations.
11: *
12: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
13: */
14: package org.pentaho.reportdesigner.crm.report.properties.editors;
15:
16: import org.jetbrains.annotations.NotNull;
17: import org.jetbrains.annotations.Nullable;
18:
19: import javax.swing.*;
20: import java.awt.*;
21:
22: /**
23: * User: Martin
24: * Date: 24.10.2005
25: * Time: 09:23:33
26: */
27: public abstract class CellEditorJLabelWithEllipsis<T> extends JPanel {
28:
29: @NotNull
30: protected JLabel label;
31: @NotNull
32: protected JButton ellipsisButton;
33: @Nullable
34: protected T uncommittedValue;
35: @Nullable
36: protected T origValue;
37:
38: public CellEditorJLabelWithEllipsis() {
39: setLayout(new BorderLayout());
40:
41: setOpaque(false);
42:
43: label = new JLabel();
44: label.setOpaque(false);
45: ellipsisButton = new JButton("...");
46: ellipsisButton.setDefaultCapable(false);
47: ellipsisButton.setMargin(new Insets(0, 0, 0, 0));
48:
49: add(label, BorderLayout.CENTER);
50: add(ellipsisButton, BorderLayout.EAST);
51: }
52:
53: @NotNull
54: public JLabel getLabel() {
55: return label;
56: }
57:
58: @NotNull
59: public JButton getEllipsisButton() {
60: return ellipsisButton;
61: }
62:
63: public void setValue(@Nullable
64: T value, boolean commit) {
65: label.setText(convertToText(value));
66: uncommittedValue = value;
67:
68: if (commit) {
69: origValue = value;
70: }
71: }
72:
73: @Nullable
74: public T getValue() {
75: if (uncommittedValue != null) {
76: return uncommittedValue;
77: }
78:
79: return origValue;
80: }
81:
82: @Nullable
83: public abstract String convertToText(@Nullable
84: T obj);
85: }
|