1 /* 2 Part of the Papilio Loader 3 4 Copyright (c) 2010-11 GadgetFactory LLC 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License version 2 8 as published by the Free Software Foundation. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software Foundation, 17 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19 20 package net.gadgetfactory.papilio.loader; 21 22 import java.awt.BorderLayout; 23 import java.awt.Dimension; 24 import javax.swing.JPanel; 25 import javax.swing.BorderFactory; 26 import javax.swing.JScrollPane; 27 import javax.swing.JTextArea; 28 import javax.swing.border.Border; 29 import javax.swing.border.TitledBorder; 30 31 public class OutputPanel extends JPanel 32 { 33 final int OUTPUT_ROWS = 5; 34 final int OUTPUT_COLUMNS = 70; 35 36 private JTextArea txtOutput = new JTextArea(OUTPUT_ROWS, OUTPUT_COLUMNS); 37 getOutputTextArea()38 public JTextArea getOutputTextArea() { 39 return txtOutput; 40 } 41 OutputPanel(int width, int height, int topMargin, int rightMargin, int bottomMargin, int leftMargin)42 public OutputPanel(int width, int height, 43 int topMargin, int rightMargin, int bottomMargin, int leftMargin) { 44 45 // Create margin and Titled border, containing title at top, around this panel. 46 Border bdrMargin = BorderFactory.createEmptyBorder(topMargin, leftMargin, bottomMargin, rightMargin); 47 this.setBorder(BorderFactory.createTitledBorder( 48 bdrMargin, "Information", TitledBorder.LEFT, TitledBorder.ABOVE_TOP)); 49 50 /* ------------------------------------------------------------------------------------ 51 * Scenario: You need to display a component in as much space as it can get. 52 * If it is the only component in its container, use GridLayout or BorderLayout. 53 * ------------------------------------------------------------------------------------ */ 54 // Each JPanel object is initialized to use a FlowLayout, unless you specify it differently. 55 this.setLayout(new BorderLayout()); 56 57 // txtOutput.setText("This is a non-editable word-wrapped JTextArea. " + 58 // "A text area is a \"plain\" text component, " + 59 // "which means that although it can display text " + 60 // "in any font, all of the text is in the same font.\n\n" + 61 // "Whatever output generated by loader console executable " + 62 // "will be captured and displayed herein."); 63 txtOutput.setText(""); 64 txtOutput.setEditable(false); 65 txtOutput.setLineWrap(true); 66 67 /* ------------------------------------------------------------------------------------ 68 * As per the BorderLayout, if the window is enlarged, the center area 69 * gets as much of the available space as possible. The other areas expand only 70 * as much as necessary to fill all available space. 71 * ------------------------------------------------------------------------------------ */ 72 /* Output text area displays the output produced by running console programs and 73 hence as such, we need to make the Output text area - and hence this JPanel - 74 as large as possible. 75 Since Output text area is space-hungry, put it in CENTER. 76 */ 77 this.add(new JScrollPane(txtOutput), BorderLayout.CENTER); 78 79 this.setPreferredSize(new Dimension(width, height)); 80 // this.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); 81 } 82 83 } 84