001: /*
002: * Copyright 2005 Paul Hinds
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.tp23.antinstaller.renderer.swing;
017:
018: import java.awt.Dimension;
019: import java.awt.Font;
020:
021: import javax.swing.JLabel;
022: import javax.swing.JPanel;
023: import javax.swing.text.JTextComponent;
024:
025: import org.tp23.antinstaller.input.CommentOutput;
026: import org.tp23.antinstaller.input.OutputField;
027: import org.tp23.gui.GBCF;
028:
029: public class CommentOutputRenderer extends SwingOutputFieldRenderer {
030:
031: protected AILabel fieldLabel = new AILabel();
032: // hack callback, should move this to superclass
033: protected JTextComponent explanatoryTextField;
034:
035: private static Font boldCommentFont;
036: private static Font titleCommentFont;
037: static {
038: boldCommentFont = new JLabel().getFont();// reusing the variable
039: try {
040: boldCommentFont = new Font(boldCommentFont.getFamily(),
041: Font.BOLD, boldCommentFont.getSize());
042: titleCommentFont = new Font(boldCommentFont.getFamily(),
043: Font.BOLD, 16);
044: } catch (Exception ex) {
045: // lets not fail due to font errors
046: }
047: }
048:
049: public CommentOutputRenderer() {
050: }
051:
052: public void initComponent(JPanel parent) {
053: try {
054: jbInit();
055: } catch (Exception e) {
056: e.printStackTrace();
057: }
058: }
059:
060: public void setOutputField(OutputField outputField) {
061: this .outputField = (CommentOutput) outputField;// trap ClassCast bugs early
062: }
063:
064: public void updateInputField() {
065: }
066:
067: // hack callback, should move this to superclass
068: public JTextComponent getExplanatoryTextField() {
069: return explanatoryTextField;
070: }
071:
072: // hack callback, should move this to superclass
073: public void setExplanatoryTextField(
074: JTextComponent explanatoryTextField) {
075: this .explanatoryTextField = explanatoryTextField;
076: }
077:
078: /**
079: * Since comments may now include expanded properties this should be called when the
080: * field is rendered. For no ONLY comment fields have property values expanded
081: */
082: public void updateDefaultValue() {
083: fieldLabel.setText(outputField.getDisplayText());
084: if (explanatoryTextField != null) {
085: explanatoryTextField.setText(outputField
086: .getExplanatoryText());
087: }
088: }
089:
090: private void jbInit() throws Exception {
091:
092: // FindBugs - cast is performed here to avoid overriding protected superclass field
093: CommentOutput cOutputField = (CommentOutput) outputField;
094:
095: fieldLabel.setText(cOutputField.getDisplayText());
096:
097: if (OutputField.isTrue(cOutputField.getBold())) {
098: fieldLabel.setFont(boldCommentFont);
099: }
100: if (OutputField.isTrue(cOutputField.getTitle())) {
101: fieldLabel.setFont(titleCommentFont);
102: }
103: }
104:
105: public int addSelf(JPanel content, GBCF cf, int row,
106: boolean overflow) {
107: content.add(fieldLabel, cf.getSpan(row));
108: if (overflow) {
109: fieldLabel.setOverflow(SizeConstants.OVERFLOW_TOTAL_SIZE);
110: } else {
111: fieldLabel.setOverflow(new Dimension(
112: SizeConstants.FIELD_WIDTH
113: + SizeConstants.LABEL_WIDTH,
114: SizeConstants.FIELD_HEIGHT));
115: }
116: return ++row;
117: }
118:
119: /**
120: * renderError
121: */
122: public void renderError() {
123: }
124: }
|