001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.codegen.gui.editor;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Component;
023: import java.awt.Container;
024: import java.awt.Dimension;
025: import java.awt.Font;
026:
027: import javax.swing.Box;
028: import javax.swing.ImageIcon;
029: import javax.swing.JButton;
030: import javax.swing.JPanel;
031:
032: import com.jeta.forms.components.label.JETALabel;
033: import com.jeta.open.gui.framework.JETAPanel;
034: import com.jeta.open.i18n.I18N;
035: import com.jgoodies.forms.layout.CellConstraints;
036: import com.jgoodies.forms.layout.FormLayout;
037:
038: public class SourceView extends JETAPanel {
039: JETALabel m_codegen_label = new JETALabel();
040: JButton m_options_btn = new JButton();
041:
042: /**
043: * Default constructor
044: */
045: public SourceView(Component editor) {
046: initializePanel(editor);
047: }
048:
049: /**
050: * Adds fill components to empty cells in the first row and first column of
051: * the grid. This ensures that the grid spacing will be the same as shown in
052: * the designer.
053: *
054: * @param cols
055: * an array of column indices in the first row where fill
056: * components should be added.
057: * @param rows
058: * an array of row indices in the first column where fill
059: * components should be added.
060: */
061: void addFillComponents(Container panel, int[] cols, int[] rows) {
062: Dimension filler = new Dimension(10, 10);
063:
064: boolean filled_cell_11 = false;
065: CellConstraints cc = new CellConstraints();
066: if (cols.length > 0 && rows.length > 0) {
067: if (cols[0] == 1 && rows[0] == 1) {
068: /** add a rigid area */
069: panel.add(Box.createRigidArea(filler), cc.xy(1, 1));
070: filled_cell_11 = true;
071: }
072: }
073:
074: for (int index = 0; index < cols.length; index++) {
075: if (cols[index] == 1 && filled_cell_11) {
076: continue;
077: }
078: panel.add(Box.createRigidArea(filler), cc
079: .xy(cols[index], 1));
080: }
081:
082: for (int index = 0; index < rows.length; index++) {
083: if (rows[index] == 1 && filled_cell_11) {
084: continue;
085: }
086: panel.add(Box.createRigidArea(filler), cc
087: .xy(1, rows[index]));
088: }
089:
090: }
091:
092: /**
093: * Helper method to load an image file from the CLASSPATH
094: *
095: * @param imageName
096: * the package and name of the file to load relative to the
097: * CLASSPATH
098: * @return an ImageIcon instance with the specified image file
099: * @throws IllegalArgumentException
100: * if the image resource cannot be loaded.
101: */
102: public ImageIcon loadImage(String imageName) {
103: try {
104: ClassLoader classloader = getClass().getClassLoader();
105: java.net.URL url = classloader.getResource(imageName);
106: if (url != null) {
107: ImageIcon icon = new ImageIcon(url);
108: return icon;
109: }
110: } catch (Exception e) {
111: e.printStackTrace();
112: }
113: throw new IllegalArgumentException("Unable to load image: "
114: + imageName);
115: }
116:
117: public JPanel createPanel(Component editor) {
118: JPanel jpanel1 = new JPanel();
119: FormLayout formlayout1 = new FormLayout(
120: "FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE",
121: "CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE");
122: CellConstraints cc = new CellConstraints();
123: jpanel1.setLayout(formlayout1);
124:
125: jpanel1.add(createPanel1(), cc.xy(2, 2));
126:
127: jpanel1.add(editor, cc.xy(2, 3));
128:
129: addFillComponents(jpanel1, new int[] { 1, 2, 3 }, new int[] {
130: 1, 2, 3, 4 });
131: return jpanel1;
132: }
133:
134: public JPanel createPanel1() {
135: JPanel jpanel1 = new JPanel();
136: jpanel1.setOpaque(false);
137: FormLayout formlayout1 = new FormLayout(
138: "FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE",
139: "CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
140: CellConstraints cc = new CellConstraints();
141: jpanel1.setLayout(formlayout1);
142:
143: m_codegen_label.setFont(new Font("Dialog", Font.BOLD, 12));
144: m_codegen_label.setAntiAliased(true);
145: m_codegen_label.setName("codegen.label");
146: m_codegen_label.setText("Code Generation");
147: jpanel1.add(m_codegen_label, cc.xy(1, 1));
148:
149: m_options_btn.setText(I18N.getLocalizedMessage("Options..."));
150: m_options_btn.setName("options.btn");
151: jpanel1.add(m_options_btn, cc.xy(3, 1));
152:
153: addFillComponents(jpanel1, new int[] { 2 }, new int[0]);
154: return jpanel1;
155: }
156:
157: /**
158: * Initializer
159: */
160: protected void initializePanel(Component editor) {
161: setLayout(new BorderLayout());
162: add(createPanel(editor), BorderLayout.CENTER);
163: }
164:
165: }
|