001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * LogPane.java
028: *
029: * Created on 22 agosto 2005, 15.02
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.logpane;
034:
035: import it.businesslogic.ireport.util.LanguageChangedListener;
036: import java.awt.Component;
037: import java.util.*;
038: import it.businesslogic.ireport.util.LanguageChangedEvent;
039: import it.businesslogic.ireport.util.I18n;
040:
041: /**
042: *
043: * @author Administrator
044: */
045: public class LogPane extends javax.swing.JPanel implements
046: java.awt.event.ActionListener {
047:
048: private LogTextArea mainLogTextArea;
049: private ProblemsPanel problemsPanel;
050: private Vector logsComponents = new Vector();
051: private LogTextArea pointedLogTextArea = null;
052: private Properties properties;
053:
054: /** Creates new form LogPane */
055: public LogPane() {
056: initComponents();
057: mainLogTextArea = new LogTextArea(I18n.getString(
058: "logPane.mainConsole", "Main console"));
059: mainLogTextArea.setLogPane(this );
060: mainLogTextArea.addActionListener(this );
061: problemsPanel = new ProblemsPanel();
062:
063: jTabbedPaneLogs
064: .add(mainLogTextArea.getTitle(), mainLogTextArea);
065: jTabbedPaneLogs.add(problemsPanel.getName(), problemsPanel);
066:
067: add(jTabbedPaneLogs, java.awt.BorderLayout.CENTER);
068:
069: //updateLogTabs();
070: I18n
071: .addOnLanguageChangedListener(new LanguageChangedListener() {
072: public void languageChanged(LanguageChangedEvent evt) {
073: applyI18n();
074: }
075: });
076: applyI18n();
077: }
078:
079: protected void updateLogTabs() {
080: for (int i = 2; i < jTabbedPaneLogs.getComponentCount(); ++i) {
081: jTabbedPaneLogs.remove(i);
082: }
083:
084: if (logsComponents.size() > 0) {
085:
086: for (int i = 0; i < logsComponents.size(); ++i) {
087: jTabbedPaneLogs.add(((LogTextArea) logsComponents
088: .elementAt(i)).getTitle(),
089: (LogTextArea) logsComponents.elementAt(i));
090: }
091: }
092:
093: /*
094: if (getComponentCount()==0)
095: {
096: remove(mainLogTextArea);
097:
098: }
099: }
100: else
101: {
102: if (getComponentCount()==0 || getComponent(0) == jTabbedPaneLogs)
103: {
104: if (getComponentCount() > 0) remove(jTabbedPaneLogs);
105: add(mainLogTextArea, java.awt.BorderLayout.CENTER);
106: }
107: }
108: */
109:
110: this .updateUI();
111: }
112:
113: /** This method is called from within the constructor to
114: * initialize the form.
115: * WARNING: Do NOT modify this code. The content of this method is
116: * always regenerated by the Form Editor.
117: */
118: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
119: private void initComponents() {
120: jPopupMenuLog = new javax.swing.JPopupMenu();
121: jMenuItemClearLog = new javax.swing.JMenuItem();
122: jMenuItemCloseLog = new javax.swing.JMenuItem();
123: jMenuItemKeepLog = new javax.swing.JMenuItem();
124: jTabbedPaneLogs = new javax.swing.JTabbedPane();
125:
126: jMenuItemClearLog.setText("Clear log");
127: jMenuItemClearLog
128: .addActionListener(new java.awt.event.ActionListener() {
129: public void actionPerformed(
130: java.awt.event.ActionEvent evt) {
131: jMenuItemClearLogActionPerformed(evt);
132: }
133: });
134:
135: jPopupMenuLog.add(jMenuItemClearLog);
136:
137: jMenuItemCloseLog.setText("Close log");
138: jMenuItemCloseLog
139: .addActionListener(new java.awt.event.ActionListener() {
140: public void actionPerformed(
141: java.awt.event.ActionEvent evt) {
142: jMenuItemCloseLogActionPerformed(evt);
143: }
144: });
145:
146: jPopupMenuLog.add(jMenuItemCloseLog);
147:
148: jMenuItemKeepLog.setText("Keep log");
149: jMenuItemKeepLog
150: .addActionListener(new java.awt.event.ActionListener() {
151: public void actionPerformed(
152: java.awt.event.ActionEvent evt) {
153: jMenuItemKeepLogActionPerformed(evt);
154: }
155: });
156:
157: jPopupMenuLog.add(jMenuItemKeepLog);
158:
159: setLayout(new java.awt.BorderLayout());
160:
161: jTabbedPaneLogs
162: .addMouseListener(new java.awt.event.MouseAdapter() {
163: public void mouseClicked(
164: java.awt.event.MouseEvent evt) {
165: jTabbedPaneLogsMouseClicked(evt);
166: }
167: });
168:
169: add(jTabbedPaneLogs, java.awt.BorderLayout.CENTER);
170:
171: }// </editor-fold>//GEN-END:initComponents
172:
173: private void jMenuItemKeepLogActionPerformed(
174: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemKeepLogActionPerformed
175: this .pointedLogTextArea.setRemovable(false);
176: }//GEN-LAST:event_jMenuItemKeepLogActionPerformed
177:
178: private void jMenuItemCloseLogActionPerformed(
179: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCloseLogActionPerformed
180: if (this .pointedLogTextArea != null
181: && this .pointedLogTextArea != getMainLogTextArea()) {
182: this .removeLog(pointedLogTextArea);
183: }
184: }//GEN-LAST:event_jMenuItemCloseLogActionPerformed
185:
186: private void jTabbedPaneLogsMouseClicked(
187: java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPaneLogsMouseClicked
188:
189: if (evt.getButton() == evt.BUTTON3 && evt.getClickCount() == 1) {
190:
191: if (jTabbedPaneLogs.getSelectedComponent() instanceof LogTextArea) {
192: this .jPopupMenuLog.show(this , evt.getPoint().x, evt
193: .getPoint().y);
194: this .pointedLogTextArea = (LogTextArea) jTabbedPaneLogs
195: .getSelectedComponent();
196: } else {
197: this .pointedLogTextArea = null;
198: }
199: }
200: }//GEN-LAST:event_jTabbedPaneLogsMouseClicked
201:
202: private void jMenuItemClearLogActionPerformed(
203: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemClearLogActionPerformed
204:
205: if (this .pointedLogTextArea != null) {
206: this .pointedLogTextArea.clearConsole();
207: }
208: }//GEN-LAST:event_jMenuItemClearLogActionPerformed
209:
210: public LogTextArea createNewLog() {
211: LogTextArea lta = new LogTextArea(I18n.getString("logPane.log",
212: "Log"));
213: lta.setLogPane(this );
214: lta.addActionListener(this );
215: logsComponents.addElement(lta);
216: for (int i = 0; i < logsComponents.size(); ++i) {
217: Object component = logsComponents.elementAt(i);
218: if (!(component instanceof LogTextArea))
219: continue;
220:
221: if (((LogTextArea) component).isRemovable()) {
222: logsComponents.removeElementAt(i);
223: i--;
224: }
225: }
226: updateLogTabs();
227: return lta;
228: }
229:
230: /*
231: public void removeLog(int logIndex)
232: {
233: logsComponents.removeElementAt(logIndex);
234: updateLogTabs();
235: }
236: */
237:
238: public void removeLog(LogTextArea logTextArea) {
239: if (logTextArea.isRemovable()) {
240: logsComponents.removeElement(logTextArea);
241: updateLogTabs();
242: }
243: }
244:
245: public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
246:
247: if (actionEvent.getSource() == null)
248: return;
249: for (int i = 2; i < jTabbedPaneLogs.getComponentCount(); ++i) {
250: LogTextArea lta = (LogTextArea) jTabbedPaneLogs
251: .getComponent(i);
252: if (lta == actionEvent.getSource()) {
253: jTabbedPaneLogs.setTitleAt(i, lta.getTitle());
254: break;
255: }
256: }
257: }
258:
259: public LogTextArea getMainLogTextArea() {
260: return mainLogTextArea;
261: }
262:
263: public void setMainLogTextArea(LogTextArea mainLogTextArea) {
264: this .mainLogTextArea = mainLogTextArea;
265: }
266:
267: public void setActiveLog(LogTextArea c) {
268: try {
269: jTabbedPaneLogs.setSelectedComponent(c);
270: } catch (Exception ex) {
271: }
272: }
273:
274: public void setActiveLogComponent(Component c) {
275: try {
276: jTabbedPaneLogs.setSelectedComponent(c);
277: } catch (Exception ex) {
278: }
279: }
280:
281: // Variables declaration - do not modify//GEN-BEGIN:variables
282: private javax.swing.JMenuItem jMenuItemClearLog;
283: private javax.swing.JMenuItem jMenuItemCloseLog;
284: private javax.swing.JMenuItem jMenuItemKeepLog;
285: private javax.swing.JPopupMenu jPopupMenuLog;
286: private javax.swing.JTabbedPane jTabbedPaneLogs;
287:
288: // End of variables declaration//GEN-END:variables
289:
290: //Added by Felix Firgau for I18n on Feb 10th 2006
291: public void applyI18n() {
292: // Start autogenerated code ----------------------
293: jMenuItemCloseLog.setText(I18n.getString(
294: "logPane.menuItemCloseLog", "Close log"));
295: jMenuItemKeepLog.setText(I18n.getString(
296: "logPane.menuItemKeepLog", "Keep log"));
297: // End autogenerated code ----------------------
298: jMenuItemClearLog.setText(it.businesslogic.ireport.util.I18n
299: .getString("clearLog", "Clear log"));
300:
301: }
302:
303: public void languageChanged(LanguageChangedEvent evt) {
304: this .applyI18n();
305: }//End
306:
307: public ProblemsPanel getProblemsPanel() {
308: return problemsPanel;
309: }
310:
311: public void setProblemsPanel(ProblemsPanel problemsPanel) {
312: this.problemsPanel = problemsPanel;
313: }
314: }
|