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: * JBoxButton.java
028: *
029: * Created on May 17, 2006, 3:06 PM
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.box;
034:
035: import it.businesslogic.ireport.Box;
036: import java.awt.Point;
037: import javax.swing.SwingUtilities;
038: import it.businesslogic.ireport.util.I18n;
039:
040: /**
041: *
042: * @author gtoffoli
043: */
044: public class JBoxButton extends javax.swing.JPanel {
045:
046: private Box lastBox = null;
047: private JBoxButtonPopup popup;
048: private boolean popupOpened = false;
049:
050: /** Creates new form JBoxButton */
051: public JBoxButton() {
052: initComponents();
053: popup = new JBoxButtonPopup(this , jPanel1);
054: popup.setInvoker(this );
055: popup.setVisible(false);
056: applyI18n();
057: }
058:
059: /** This method is called from within the constructor to
060: * initialize the form.
061: * WARNING: Do NOT modify this code. The content of this method is
062: * always regenerated by the Form Editor.
063: */
064: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
065: private void initComponents() {
066: java.awt.GridBagConstraints gridBagConstraints;
067:
068: jPanel1 = new javax.swing.JPanel();
069: jButton2 = new javax.swing.JButton();
070: jButton3 = new javax.swing.JButton();
071: jButton4 = new javax.swing.JButton();
072: jButton5 = new javax.swing.JButton();
073: jButton6 = new javax.swing.JButton();
074: jButton7 = new javax.swing.JButton();
075: jButton8 = new javax.swing.JButton();
076: jButton9 = new javax.swing.JButton();
077: jButton1 = new javax.swing.JButton();
078:
079: jPanel1.setLayout(new java.awt.GridBagLayout());
080:
081: jPanel1.setMinimumSize(new java.awt.Dimension(100, 52));
082: jPanel1.setPreferredSize(new java.awt.Dimension(100, 52));
083: jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
084: public void mousePressed(java.awt.event.MouseEvent evt) {
085: jPanel1MousePressed(evt);
086: }
087: });
088:
089: jButton2
090: .setIcon(new javax.swing.ImageIcon(
091: getClass()
092: .getResource(
093: "/it/businesslogic/ireport/icons/toolbars/box_1.png")));
094: jButton2.setBorderPainted(false);
095: jButton2.setFocusPainted(false);
096: jButton2.setFocusable(false);
097: jButton2.setMargin(new java.awt.Insets(2, 2, 2, 2));
098: jButton2.setOpaque(false);
099: jButton2.setRequestFocusEnabled(false);
100: jButton2.addActionListener(new java.awt.event.ActionListener() {
101: public void actionPerformed(java.awt.event.ActionEvent evt) {
102: jButton2ActionPerformed(evt);
103: }
104: });
105:
106: gridBagConstraints = new java.awt.GridBagConstraints();
107: gridBagConstraints.gridy = 1;
108: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
109: gridBagConstraints.weightx = 1.0;
110: gridBagConstraints.weighty = 1.0;
111: gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
112: jPanel1.add(jButton2, gridBagConstraints);
113:
114: jButton3
115: .setIcon(new javax.swing.ImageIcon(
116: getClass()
117: .getResource(
118: "/it/businesslogic/ireport/icons/toolbars/box_2.png")));
119: jButton3.setBorderPainted(false);
120: jButton3.setFocusPainted(false);
121: jButton3.setFocusable(false);
122: jButton3.setMargin(new java.awt.Insets(2, 2, 2, 2));
123: jButton3.setOpaque(false);
124: jButton3.setRequestFocusEnabled(false);
125: jButton3.addActionListener(new java.awt.event.ActionListener() {
126: public void actionPerformed(java.awt.event.ActionEvent evt) {
127: jButton3ActionPerformed(evt);
128: }
129: });
130:
131: gridBagConstraints = new java.awt.GridBagConstraints();
132: gridBagConstraints.gridy = 1;
133: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
134: gridBagConstraints.weightx = 1.0;
135: gridBagConstraints.weighty = 1.0;
136: gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
137: jPanel1.add(jButton3, gridBagConstraints);
138:
139: jButton4
140: .setIcon(new javax.swing.ImageIcon(
141: getClass()
142: .getResource(
143: "/it/businesslogic/ireport/icons/toolbars/box_4.png")));
144: jButton4.setBorderPainted(false);
145: jButton4.setFocusPainted(false);
146: jButton4.setFocusable(false);
147: jButton4.setMargin(new java.awt.Insets(2, 2, 2, 2));
148: jButton4.setOpaque(false);
149: jButton4.setRequestFocusEnabled(false);
150: jButton4.addActionListener(new java.awt.event.ActionListener() {
151: public void actionPerformed(java.awt.event.ActionEvent evt) {
152: jButton4ActionPerformed(evt);
153: }
154: });
155:
156: gridBagConstraints = new java.awt.GridBagConstraints();
157: gridBagConstraints.gridy = 1;
158: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
159: gridBagConstraints.weightx = 1.0;
160: gridBagConstraints.weighty = 1.0;
161: gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
162: jPanel1.add(jButton4, gridBagConstraints);
163:
164: jButton5
165: .setIcon(new javax.swing.ImageIcon(
166: getClass()
167: .getResource(
168: "/it/businesslogic/ireport/icons/toolbars/box_7.png")));
169: jButton5.setBorderPainted(false);
170: jButton5.setFocusPainted(false);
171: jButton5.setFocusable(false);
172: jButton5.setMargin(new java.awt.Insets(2, 2, 2, 2));
173: jButton5.setOpaque(false);
174: jButton5.setRequestFocusEnabled(false);
175: jButton5.addActionListener(new java.awt.event.ActionListener() {
176: public void actionPerformed(java.awt.event.ActionEvent evt) {
177: jButton5ActionPerformed(evt);
178: }
179: });
180:
181: gridBagConstraints = new java.awt.GridBagConstraints();
182: gridBagConstraints.gridy = 1;
183: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
184: gridBagConstraints.weightx = 1.0;
185: gridBagConstraints.weighty = 1.0;
186: gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
187: jPanel1.add(jButton5, gridBagConstraints);
188:
189: jButton6
190: .setIcon(new javax.swing.ImageIcon(
191: getClass()
192: .getResource(
193: "/it/businesslogic/ireport/icons/toolbars/box_5.png")));
194: jButton6.setBorderPainted(false);
195: jButton6.setFocusPainted(false);
196: jButton6.setFocusable(false);
197: jButton6.setMargin(new java.awt.Insets(2, 2, 2, 2));
198: jButton6.setOpaque(false);
199: jButton6.setRequestFocusEnabled(false);
200: jButton6.addActionListener(new java.awt.event.ActionListener() {
201: public void actionPerformed(java.awt.event.ActionEvent evt) {
202: jButton6ActionPerformed(evt);
203: }
204: });
205:
206: gridBagConstraints = new java.awt.GridBagConstraints();
207: gridBagConstraints.gridy = 2;
208: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
209: gridBagConstraints.weightx = 1.0;
210: gridBagConstraints.weighty = 1.0;
211: gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
212: jPanel1.add(jButton6, gridBagConstraints);
213:
214: jButton7
215: .setIcon(new javax.swing.ImageIcon(
216: getClass()
217: .getResource(
218: "/it/businesslogic/ireport/icons/toolbars/box_3.png")));
219: jButton7.setBorderPainted(false);
220: jButton7.setFocusPainted(false);
221: jButton7.setFocusable(false);
222: jButton7.setMargin(new java.awt.Insets(2, 2, 2, 2));
223: jButton7.setOpaque(false);
224: jButton7.setRequestFocusEnabled(false);
225: jButton7.addActionListener(new java.awt.event.ActionListener() {
226: public void actionPerformed(java.awt.event.ActionEvent evt) {
227: jButton7ActionPerformed(evt);
228: }
229: });
230:
231: gridBagConstraints = new java.awt.GridBagConstraints();
232: gridBagConstraints.gridy = 2;
233: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
234: gridBagConstraints.weightx = 1.0;
235: gridBagConstraints.weighty = 1.0;
236: gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
237: jPanel1.add(jButton7, gridBagConstraints);
238:
239: jButton8
240: .setIcon(new javax.swing.ImageIcon(
241: getClass()
242: .getResource(
243: "/it/businesslogic/ireport/icons/toolbars/box_6.png")));
244: jButton8.setBorderPainted(false);
245: jButton8.setFocusPainted(false);
246: jButton8.setFocusable(false);
247: jButton8.setMargin(new java.awt.Insets(2, 2, 2, 2));
248: jButton8.setOpaque(false);
249: jButton8.setRequestFocusEnabled(false);
250: jButton8.addActionListener(new java.awt.event.ActionListener() {
251: public void actionPerformed(java.awt.event.ActionEvent evt) {
252: jButton8ActionPerformed(evt);
253: }
254: });
255:
256: gridBagConstraints = new java.awt.GridBagConstraints();
257: gridBagConstraints.gridy = 2;
258: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
259: gridBagConstraints.weightx = 1.0;
260: gridBagConstraints.weighty = 1.0;
261: gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
262: jPanel1.add(jButton8, gridBagConstraints);
263:
264: jButton9
265: .setIcon(new javax.swing.ImageIcon(
266: getClass()
267: .getResource(
268: "/it/businesslogic/ireport/icons/toolbars/box_8.png")));
269: jButton9.setBorderPainted(false);
270: jButton9.setFocusPainted(false);
271: jButton9.setFocusable(false);
272: jButton9.setMargin(new java.awt.Insets(2, 2, 2, 2));
273: jButton9.setOpaque(false);
274: jButton9.setRequestFocusEnabled(false);
275: jButton9.addActionListener(new java.awt.event.ActionListener() {
276: public void actionPerformed(java.awt.event.ActionEvent evt) {
277: jButton9ActionPerformed(evt);
278: }
279: });
280:
281: gridBagConstraints = new java.awt.GridBagConstraints();
282: gridBagConstraints.gridy = 2;
283: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
284: gridBagConstraints.weightx = 1.0;
285: gridBagConstraints.weighty = 1.0;
286: gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
287: jPanel1.add(jButton9, gridBagConstraints);
288:
289: setLayout(new java.awt.BorderLayout());
290:
291: jButton1
292: .setIcon(new javax.swing.ImageIcon(
293: getClass()
294: .getResource(
295: "/it/businesslogic/ireport/icons/toolbars/box.png")));
296: jButton1.setMaximumSize(new java.awt.Dimension(32, 25));
297: jButton1.setMinimumSize(new java.awt.Dimension(32, 25));
298: jButton1.setPreferredSize(new java.awt.Dimension(32, 25));
299: jButton1.addActionListener(new java.awt.event.ActionListener() {
300: public void actionPerformed(java.awt.event.ActionEvent evt) {
301: jButton1ActionPerformed(evt);
302: }
303: });
304: jButton1.addFocusListener(new java.awt.event.FocusAdapter() {
305: public void focusLost(java.awt.event.FocusEvent evt) {
306: jButton1FocusLost(evt);
307: }
308: });
309: jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
310: public void mouseClicked(java.awt.event.MouseEvent evt) {
311: jButton1MouseClicked(evt);
312: }
313: });
314:
315: add(jButton1, java.awt.BorderLayout.CENTER);
316:
317: }// </editor-fold>//GEN-END:initComponents
318:
319: private void jButton1FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jButton1FocusLost
320:
321: //hidePopup();
322:
323: }//GEN-LAST:event_jButton1FocusLost
324:
325: private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
326: //System.out.println("jButton1MouseClicked");
327: //if (!jPanel1.contains(evt.getPoint() )) hidePopup();
328: }//GEN-LAST:event_jButton1MouseClicked
329:
330: private void jPanel1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MousePressed
331: //System.out.println("jPanel1MousePressed");
332: //if (!jPanel1.contains(evt.getPoint() )) hidePopup();
333: }//GEN-LAST:event_jPanel1MousePressed
334:
335: private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
336: selectedBox(8);
337: }//GEN-LAST:event_jButton9ActionPerformed
338:
339: private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
340: selectedBox(7);
341: }//GEN-LAST:event_jButton8ActionPerformed
342:
343: private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
344: selectedBox(6);
345: }//GEN-LAST:event_jButton7ActionPerformed
346:
347: private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
348: selectedBox(5);
349: }//GEN-LAST:event_jButton6ActionPerformed
350:
351: private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
352: selectedBox(4);
353: }//GEN-LAST:event_jButton5ActionPerformed
354:
355: private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
356: selectedBox(3);
357: }//GEN-LAST:event_jButton4ActionPerformed
358:
359: private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
360: selectedBox(2);
361: }//GEN-LAST:event_jButton3ActionPerformed
362:
363: private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
364: selectedBox(1);
365: }//GEN-LAST:event_jButton2ActionPerformed
366:
367: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
368:
369: if (popup.isVisible()) {
370: hidePopup();
371: } else {
372: showPopup();
373: }
374: }//GEN-LAST:event_jButton1ActionPerformed
375:
376: public void showPopup() {
377: popup.show();
378: }
379:
380: public void hidePopup() {
381: popup.setVisible(false);
382: }
383:
384: // Variables declaration - do not modify//GEN-BEGIN:variables
385: private javax.swing.JButton jButton1;
386: private javax.swing.JButton jButton2;
387: private javax.swing.JButton jButton3;
388: private javax.swing.JButton jButton4;
389: private javax.swing.JButton jButton5;
390: private javax.swing.JButton jButton6;
391: private javax.swing.JButton jButton7;
392: private javax.swing.JButton jButton8;
393: private javax.swing.JButton jButton9;
394: private javax.swing.JPanel jPanel1;
395:
396: // End of variables declaration//GEN-END:variables
397:
398: public void setLastBox(Box b) {
399: this .lastBox = b;
400: }
401:
402: public Box getLastBox() {
403: return this .lastBox;
404: }
405:
406: /**
407: * Utility field used by event firing mechanism.
408: */
409: private javax.swing.event.EventListenerList listenerList = null;
410:
411: /**
412: * Registers ActionListener to receive events.
413: * @param listener The listener to register.
414: */
415: public synchronized void addActionListener(
416: java.awt.event.ActionListener listener) {
417:
418: if (listenerList == null) {
419: listenerList = new javax.swing.event.EventListenerList();
420: }
421: listenerList.add(java.awt.event.ActionListener.class, listener);
422: }
423:
424: /**
425: * Removes ActionListener from the list of listeners.
426: * @param listener The listener to remove.
427: */
428: public synchronized void removeActionListener(
429: java.awt.event.ActionListener listener) {
430:
431: listenerList.remove(java.awt.event.ActionListener.class,
432: listener);
433: }
434:
435: /**
436: * Notifies all registered listeners about the event.
437: *
438: * @param event The event to be fired
439: */
440: public void fireActionListenerActionPerformed(
441: java.awt.event.ActionEvent event) {
442:
443: if (listenerList == null)
444: return;
445: Object[] listeners = listenerList.getListenerList();
446: for (int i = listeners.length - 2; i >= 0; i -= 2) {
447: if (listeners[i] == java.awt.event.ActionListener.class) {
448: ((java.awt.event.ActionListener) listeners[i + 1])
449: .actionPerformed(event);
450: }
451: }
452: }
453:
454: /*
455: * Fire an event if box > 0...
456: *
457: * __1__
458: * | |
459: * 4 2
460: * |__3__|
461: *
462: * 1 2 3 4
463: * Box 1: 0,0,0,0
464: * Box 2: 1,0,0,0 ---
465: * Box 3: 0,0,1,0 ___
466: * Box 4: 1,0,1,0 ===
467: * Box 5: 0,0,0,1 |
468: * Box 6: 0,1,0,0 |
469: * Box 7: 0,1,0,1 | |
470: * Box 8: 1,1,1,1 |=|
471: *
472: */
473: public void selectedBox(int b) {
474: Box box = new Box();
475: if (b == 2 || b == 4 || b == 8) {
476: box.setTopBorder("1Point");
477: //box.setTopBorderColor(Color.BLACK);
478: }
479:
480: if (b == 6 || b == 7 || b == 8) {
481: box.setRightBorder("1Point");
482: //box.setRightBorderColor(Color.BLACK);
483: }
484:
485: if (b == 3 || b == 4 || b == 8) {
486: box.setBottomBorder("1Point");
487: //box.setBottomBorderColor(Color.BLACK);
488: }
489:
490: if (b == 5 || b == 7 || b == 8) {
491: box.setLeftBorder("1Point");
492: //box.setBottomBorderColor(Color.BLACK);
493: }
494:
495: setLastBox(box);
496: fireActionListenerActionPerformed(new java.awt.event.ActionEvent(
497: this , b, ""));
498:
499: hidePopup();
500: }
501:
502: public void setEnabled(boolean b) {
503: jButton1.setEnabled(b);
504: super .setEnabled(b);
505: }
506:
507: public void applyI18n() {
508: // Start autogenerated code ----------------------
509: // End autogenerated code ----------------------
510: }
511: }
|