1 | /*
|
---|
2 | * Copyright 2005 Paul Hinds
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 | package org.tp23.antinstaller.renderer.swing;
|
---|
17 |
|
---|
18 | import java.awt.Dimension;
|
---|
19 | import java.awt.Font;
|
---|
20 | import java.awt.Color;
|
---|
21 |
|
---|
22 | import javax.swing.JTextArea;
|
---|
23 | import javax.swing.JLabel;
|
---|
24 | import javax.swing.JPanel;
|
---|
25 | import javax.swing.text.JTextComponent;
|
---|
26 |
|
---|
27 | import org.tp23.antinstaller.input.CommentOutput;
|
---|
28 | import org.tp23.antinstaller.input.OutputField;
|
---|
29 | import org.tp23.gui.GBCF;
|
---|
30 |
|
---|
31 | public class CommentOutputRenderer
|
---|
32 | extends SwingOutputFieldRenderer {
|
---|
33 |
|
---|
34 | protected JTextArea fieldLabel = new JTextArea();
|
---|
35 | //protected AILabel fieldLabel = new AILabel();
|
---|
36 | // hack callback, should move this to superclass
|
---|
37 | protected JTextComponent explanatoryTextField;
|
---|
38 |
|
---|
39 | private static Font boldCommentFont;
|
---|
40 | private static Font titleCommentFont;
|
---|
41 | static{
|
---|
42 | boldCommentFont = new JLabel().getFont();// reusing the variable
|
---|
43 | try {
|
---|
44 | boldCommentFont = new Font(boldCommentFont.getFamily(), Font.BOLD, boldCommentFont.getSize());
|
---|
45 | titleCommentFont = new Font(boldCommentFont.getFamily(), Font.BOLD, 16);
|
---|
46 | }
|
---|
47 | catch (Exception ex) {
|
---|
48 | // lets not fail due to font errors
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public CommentOutputRenderer() {
|
---|
53 | }
|
---|
54 |
|
---|
55 | public void initComponent(JPanel parent){
|
---|
56 | fieldLabel.setLineWrap(true);
|
---|
57 | fieldLabel.setWrapStyleWord(true);
|
---|
58 | fieldLabel.setEditable(false);
|
---|
59 | fieldLabel.setBackground( parent.getBackground() );
|
---|
60 | try {
|
---|
61 | jbInit();
|
---|
62 | }
|
---|
63 | catch(Exception e) {
|
---|
64 | e.printStackTrace();
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | public void setOutputField(OutputField outputField) {
|
---|
69 | this.outputField = (CommentOutput)outputField;// trap ClassCast bugs early
|
---|
70 | }
|
---|
71 | public void updateInputField(){
|
---|
72 | }
|
---|
73 |
|
---|
74 | // hack callback, should move this to superclass
|
---|
75 | public JTextComponent getExplanatoryTextField() {
|
---|
76 | return explanatoryTextField;
|
---|
77 | }
|
---|
78 | // hack callback, should move this to superclass
|
---|
79 | public void setExplanatoryTextField(JTextComponent explanatoryTextField) {
|
---|
80 | this.explanatoryTextField = explanatoryTextField;
|
---|
81 | }
|
---|
82 | /**
|
---|
83 | * Since comments may now include expanded properties this should be called when the
|
---|
84 | * field is rendered. For no ONLY comment fields have property values expanded
|
---|
85 | */
|
---|
86 | public void updateDefaultValue(){
|
---|
87 | fieldLabel.setText(outputField.getDisplayText());
|
---|
88 | if(explanatoryTextField != null) {
|
---|
89 | explanatoryTextField.setText(outputField.getExplanatoryText());
|
---|
90 | }
|
---|
91 | }
|
---|
92 | private void jbInit() throws Exception {
|
---|
93 |
|
---|
94 | // FindBugs - cast is performed here to avoid overriding protected superclass field
|
---|
95 | CommentOutput cOutputField = (CommentOutput)outputField;
|
---|
96 |
|
---|
97 | fieldLabel.setText(cOutputField.getDisplayText());
|
---|
98 |
|
---|
99 | if( OutputField.isTrue(cOutputField.getBold()) ){
|
---|
100 | fieldLabel.setFont(boldCommentFont);
|
---|
101 | }
|
---|
102 | if( OutputField.isTrue(cOutputField.getTitle()) ){
|
---|
103 | fieldLabel.setFont(titleCommentFont);
|
---|
104 | }
|
---|
105 | }
|
---|
106 | public int addSelf(JPanel content, GBCF cf, int row, boolean overflow) {
|
---|
107 |
|
---|
108 | //JPanel np = new JPanel();
|
---|
109 | //np.setLayout( new FlowLayout() );
|
---|
110 | //np.add( fieldLabel );
|
---|
111 |
|
---|
112 | content.add(fieldLabel);
|
---|
113 |
|
---|
114 | JPanel p = new JPanel();
|
---|
115 | p.setMinimumSize( new Dimension(0,1) );
|
---|
116 | content.add(p);
|
---|
117 |
|
---|
118 | //content.add(fieldLabel);
|
---|
119 | /*
|
---|
120 | if(overflow){
|
---|
121 | fieldLabel.setOverflow(SizeConstants.OVERFLOW_TOTAL_SIZE);
|
---|
122 | } else {
|
---|
123 | fieldLabel.setOverflow(new Dimension(SizeConstants.FIELD_WIDTH + SizeConstants.LABEL_WIDTH, SizeConstants.FIELD_HEIGHT));
|
---|
124 | }
|
---|
125 | */
|
---|
126 | return ++row;
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * renderError
|
---|
132 | */
|
---|
133 | public void renderError() {
|
---|
134 | }
|
---|
135 | }
|
---|