Source Code Cross Referenced for CategorySensitiveComposedEditor.java in  » Content-Management-System » contelligent » de » finix » contelligent » client » gui » category » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » contelligent » de.finix.contelligent.client.gui.category 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2006 C:1 Financial Services GmbH
003:         *
004:         * This software is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License Version 2.1, as published by the Free Software Foundation.
007:         *
008:         * This software is distributed in the hope that it will be useful,
009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011:         * Lesser General Public License for more details.
012:         *
013:         * You should have received a copy of the GNU Lesser General Public
014:         * License along with this library; if not, write to the Free Software
015:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016:         */
017:
018:        package de.finix.contelligent.client.gui.category;
019:
020:        import java.awt.BorderLayout;
021:        import java.awt.Color;
022:        import java.awt.Dimension;
023:        import java.awt.LayoutManager;
024:        import java.awt.Rectangle;
025:        import java.awt.event.ActionEvent;
026:        import java.awt.event.ActionListener;
027:        import java.awt.event.ComponentAdapter;
028:        import java.awt.event.ComponentEvent;
029:        import java.util.ArrayList;
030:        import java.util.HashMap;
031:        import java.util.Iterator;
032:        import java.util.List;
033:        import java.util.Map;
034:        import java.util.logging.Level;
035:        import java.util.logging.Logger;
036:
037:        import javax.swing.AbstractAction;
038:        import javax.swing.Action;
039:        import javax.swing.JButton;
040:        import javax.swing.JComponent;
041:        import javax.swing.JPanel;
042:        import javax.swing.JScrollPane;
043:        import javax.swing.JSlider;
044:        import javax.swing.JTabbedPane;
045:        import javax.swing.Scrollable;
046:        import javax.swing.event.ChangeEvent;
047:        import javax.swing.event.ChangeListener;
048:
049:        import de.finix.contelligent.client.base.Description;
050:        import de.finix.contelligent.client.base.category.ContelligentCategory;
051:        import de.finix.contelligent.client.base.category.ContelligentCategoryManager;
052:        import de.finix.contelligent.client.base.resource.ContelligentResource;
053:        import de.finix.contelligent.client.event.ContelligentEvent;
054:        import de.finix.contelligent.client.gui.AbstractComponentEditor;
055:        import de.finix.contelligent.client.gui.ComponentEditor;
056:        import de.finix.contelligent.client.gui.ComponentRenderer;
057:        import de.finix.contelligent.client.gui.ContelligentAction;
058:        import de.finix.contelligent.client.gui.GUI;
059:        import de.finix.contelligent.client.gui.UnsupportedGUIException;
060:        import de.finix.contelligent.client.i18n.Resources;
061:        import de.finix.contelligent.client.util.ExceptionDialog;
062:        import de.finix.contelligent.client.util.TableLayout;
063:        import de.finix.contelligent.client.wizard.CategorySensitiveWizard;
064:        import de.finix.contelligent.client.wizard.Wizard;
065:
066:        public class CategorySensitiveComposedEditor extends
067:                AbstractComponentEditor {
068:
069:            private static Logger logger = Logger
070:                    .getLogger(CategorySensitiveComposedEditor.class.getName());
071:
072:            public final static int DISPLAY_MODE_FLAT = 0;
073:
074:            public final static int DISPLAY_MODE_TABBED = 1;
075:
076:            public final static int DISPLAY_MODE_MATRIX = 2;
077:
078:            public final static int DISPLAY_MODE_COMBO = 3;
079:
080:            // MATRIX properties
081:            private final static int MINIMUM_COLUMN_WIDTH = 25;
082:
083:            private final static int MAXIMUM_COLUMN_WIDTH = 1600;
084:
085:            private final static int MINIMUM_ROW_HEIGHT = 25;
086:
087:            private final static int MAXIMUM_ROW_HEIGHT = 1200;
088:
089:            private final static int VERTICAL = 0;
090:
091:            private final static int HORIZONTAL = 1;
092:
093:            private final static int COLUMN_WIDTH = 250;
094:
095:            private final static int ROW_HEIGHT = 250;
096:
097:            private int orientation = HORIZONTAL;
098:
099:            private int displayMode = DISPLAY_MODE_MATRIX;
100:
101:            private Map<String, GUI2PaneMapping> guiMap;
102:
103:            private Class guiClass;
104:
105:            private Map categoryCombinations;
106:
107:            private List<ContelligentCategory> sensitiveCategories;
108:
109:            private List<ComponentRenderer> editors;
110:
111:            private Action[] editActions = new Action[] {
112:                    new SelectTabbedLayoutAction(),
113:                    // new SelectFlatLayoutAction(),
114:                    new SelectMatrixLayoutAction(),
115:                    new SelectSensitiveCategoriesAction() };
116:
117:            private Action[] renderActions = new Action[] {
118:                    new SelectTabbedLayoutAction(),
119:                    // new SelectFlatLayoutAction(),
120:                    new SelectMatrixLayoutAction() };
121:
122:            private boolean layoutPrepared = false;
123:
124:            public void setDisplayMode(int displayMode) {
125:                this .displayMode = displayMode;
126:            }
127:
128:            public void setOrientation(int orientation) {
129:                this .orientation = orientation;
130:            }
131:
132:            public void setGUIClass(Class guiClass) {
133:                this .guiClass = guiClass;
134:            }
135:
136:            public void init() {
137:                update();
138:            }
139:
140:            public void update() {
141:                prepareLayout();
142:                editors = new ArrayList<ComponentRenderer>();
143:                for (Iterator it = guiMap.values().iterator(); it.hasNext();) {
144:                    GUI2PaneMapping mapping = (GUI2PaneMapping) it.next();
145:                    GUI gui = mapping.getGui();
146:                    JPanel pane = mapping.getPane();
147:                    try {
148:                        ComponentRenderer renderer;
149:                        if (isEditable()) {
150:                            renderer = gui.getEditor(GUI.DEFAULT);
151:                            editors.add(renderer);
152:                        } else {
153:                            renderer = gui.getRenderer(GUI.DEFAULT);
154:                        }
155:                        pane.removeAll();
156:                        pane.add((java.awt.Component) renderer,
157:                                BorderLayout.CENTER);
158:                    } catch (UnsupportedGUIException uge) {
159:                        logger.log(Level.SEVERE,
160:                                "Could not find gui for resource", uge);
161:                    }
162:                }
163:                revalidate();
164:                repaint();
165:            }
166:
167:            public void setEditable(boolean editable) {
168:                super .setEditable(editable);
169:                update();
170:            }
171:
172:            public void commit() {
173:                Iterator i = editors.iterator();
174:                while (i.hasNext()) {
175:                    ComponentEditor editor = (ComponentEditor) i.next();
176:                    editor.commit();
177:                }
178:            }
179:
180:            public void rollback() {
181:                Iterator i = editors.iterator();
182:                while (i.hasNext()) {
183:                    ComponentEditor editor = (ComponentEditor) i.next();
184:                    editor.rollback();
185:                }
186:                layoutPrepared = false;
187:                categoryCombinations = null;
188:                prepareLayout();
189:                update();
190:            }
191:
192:            public void updateComponent() {
193:            }
194:
195:            protected void componentChanged(ContelligentEvent event) {
196:            }
197:
198:            protected void childComponentAdded(ContelligentEvent event) {
199:            }
200:
201:            protected void childComponentRemoved(ContelligentEvent event) {
202:            }
203:
204:            protected void childComponentChanged(ContelligentEvent event) {
205:            }
206:
207:            protected void descendentComponentChanged(ContelligentEvent event) {
208:            }
209:
210:            public Action[] getActions() {
211:                if (isEditable()) {
212:                    return editActions;
213:                }
214:                return renderActions;
215:            }
216:
217:            private void prepareLayout() {
218:                if (!layoutPrepared) {
219:                    removeAll();
220:                    layoutPrepared = true;
221:                    GUI gui = createGUIInstance();
222:                    sensitiveCategories = gui.getSensitiveCategories();
223:                    if (sensitiveCategories.size() == 0) {
224:                        guiMap = new HashMap<String, GUI2PaneMapping>();
225:                        JPanel panel = new JPanel(new BorderLayout());
226:                        panel.setOpaque(false);
227:                        add(panel, BorderLayout.CENTER);
228:                        GUI2PaneMapping mapping = new GUI2PaneMapping(gui,
229:                                panel);
230:                        guiMap.put("", mapping);
231:                        return;
232:                    }
233:                    if (categoryCombinations == null) {
234:                        categoryCombinations = ContelligentCategoryManager
235:                                .getSensitveCategoryCombinations(sensitiveCategories);
236:                        guiMap = createGUIs(categoryCombinations);
237:                    }
238:                    switch (displayMode) {
239:                    case DISPLAY_MODE_FLAT: {
240:                        JTabbedPane composedPane = new JTabbedPane();
241:                        composedPane.setBorder(null);
242:                        for (Iterator it = guiMap.entrySet().iterator(); it
243:                                .hasNext();) {
244:                            Map.Entry entry = (Map.Entry) it.next();
245:                            String identifier = (String) entry.getKey();
246:                            JPanel panel = new JPanel(new BorderLayout());
247:                            panel.setOpaque(false);
248:                            composedPane.addTab(identifier, panel);
249:                            GUI2PaneMapping mapping = (GUI2PaneMapping) entry
250:                                    .getValue();
251:                            mapping.setPane(panel);
252:                        }
253:                        add(composedPane, BorderLayout.CENTER);
254:                        break;
255:                    }
256:                    case DISPLAY_MODE_TABBED: {
257:                        JTabbedPane composedPane = new JTabbedPane();
258:                        composedPane.setBorder(null);
259:                        addCategoryValuesAsTabs(composedPane,
260:                                new HashMap<String, String>(),
261:                                sensitiveCategories, sensitiveCategories,
262:                                DISPLAY_MODE_TABBED);
263:                        add(composedPane, BorderLayout.CENTER);
264:                        break;
265:                    }
266:                    case DISPLAY_MODE_MATRIX: {
267:                        JComponent composedPane;
268:                        if (sensitiveCategories.size() == 1) {
269:                            ContelligentCategory category = (ContelligentCategory) sensitiveCategories
270:                                    .get(0);
271:                            if (orientation == HORIZONTAL) {
272:                                composedPane = createMatrix(
273:                                        new HashMap<String, String>(),
274:                                        category, null);
275:                            } else {
276:                                composedPane = createMatrix(
277:                                        new HashMap<String, String>(), null,
278:                                        category);
279:                            }
280:                        } else if (sensitiveCategories.size() == 2) {
281:                            ContelligentCategory verticalCategory = (ContelligentCategory) sensitiveCategories
282:                                    .get(0);
283:                            ContelligentCategory horizontalCategory = (ContelligentCategory) sensitiveCategories
284:                                    .get(1);
285:                            if (orientation == HORIZONTAL) {
286:                                composedPane = createMatrix(
287:                                        new HashMap<String, String>(),
288:                                        horizontalCategory, verticalCategory);
289:                            } else {
290:                                composedPane = createMatrix(
291:                                        new HashMap<String, String>(),
292:                                        verticalCategory, horizontalCategory);
293:                            }
294:                        } else {
295:                            composedPane = new JTabbedPane();
296:                            composedPane.setBorder(null);
297:                            addCategoryValuesAsTabs(composedPane,
298:                                    new HashMap<String, String>(),
299:                                    sensitiveCategories, sensitiveCategories,
300:                                    DISPLAY_MODE_MATRIX);
301:                            add(composedPane, BorderLayout.CENTER);
302:                        }
303:                        add(composedPane, BorderLayout.CENTER);
304:                        break;
305:                    }
306:                    }
307:                }
308:            }
309:
310:            private void addCategoryValuesAsTabs(JComponent component,
311:                    Map<String, String> prefixCategoryMap,
312:                    List<ContelligentCategory> sensitiveCategories,
313:                    List<ContelligentCategory> globalCategories, int displayMode) {
314:                if (sensitiveCategories.size() == 0
315:                        && displayMode == DISPLAY_MODE_TABBED) {
316:                    String identifier = ContelligentCategoryManager
317:                            .createUniqueCategoryIdentifier(globalCategories,
318:                                    prefixCategoryMap);
319:                    GUI2PaneMapping mapping = (GUI2PaneMapping) guiMap
320:                            .get(identifier);
321:                    mapping.setPane((JPanel) component);
322:                } else {
323:                    ContelligentCategory category = (ContelligentCategory) sensitiveCategories
324:                            .get(0);
325:                    List<ContelligentCategory> newSensitiveCategories = new ArrayList<ContelligentCategory>(
326:                            sensitiveCategories);
327:                    newSensitiveCategories.remove(category);
328:                    String name = category.getName();
329:                    String[] values = category.getSupportedValues();
330:                    for (int j = 0; j < values.length; j++) {
331:                        String categoryValue = values[j];
332:                        prefixCategoryMap.put(name, categoryValue);
333:                        JComponent pane;
334:                        if (newSensitiveCategories.size() == 0
335:                                && displayMode == DISPLAY_MODE_TABBED) {
336:                            pane = new JPanel(new BorderLayout());
337:                            pane.setOpaque(false);
338:                        } else if (newSensitiveCategories.size() == 2
339:                                && displayMode == DISPLAY_MODE_MATRIX) {
340:                            ContelligentCategory horizontalCategory = (ContelligentCategory) newSensitiveCategories
341:                                    .get(0);
342:                            ContelligentCategory verticalCategory = (ContelligentCategory) newSensitiveCategories
343:                                    .get(1);
344:                            if (orientation == HORIZONTAL) {
345:                                pane = createMatrix(prefixCategoryMap,
346:                                        horizontalCategory, verticalCategory);
347:                            } else {
348:                                pane = createMatrix(prefixCategoryMap,
349:                                        verticalCategory, horizontalCategory);
350:                            }
351:                        } else {
352:                            pane = new JTabbedPane();
353:                            pane.setBorder(null);
354:                        }
355:                        ((JTabbedPane) component).addTab(categoryValue, pane);
356:                        if (newSensitiveCategories.size() > 2
357:                                || displayMode == DISPLAY_MODE_TABBED) {
358:                            addCategoryValuesAsTabs(pane, prefixCategoryMap,
359:                                    newSensitiveCategories, globalCategories,
360:                                    displayMode);
361:                        }
362:                    }
363:                }
364:            }
365:
366:            private JComponent createMatrix(Map<String, String> categoryMap,
367:                    ContelligentCategory horizontalCategory,
368:                    ContelligentCategory verticalCategory) {
369:                String[] supportedHorizontalValues = null;
370:                double[] cols;
371:                if (horizontalCategory == null) {
372:                    cols = new double[1];
373:                    cols[0] = TableLayout.FILL;
374:                } else {
375:                    supportedHorizontalValues = horizontalCategory
376:                            .getSupportedValues();
377:                    cols = new double[supportedHorizontalValues.length];
378:                    for (int i = 0; i < supportedHorizontalValues.length; i++) {
379:                        cols[i] = TableLayout.FILL;
380:                    }
381:                }
382:                String[] supportedVerticalValues = null;
383:                double[] rows;
384:                if (verticalCategory == null) {
385:                    rows = new double[1];
386:                    rows[0] = TableLayout.FILL;
387:                } else {
388:                    supportedVerticalValues = verticalCategory
389:                            .getSupportedValues();
390:                    rows = new double[supportedVerticalValues.length];
391:                    for (int i = 0; i < supportedVerticalValues.length; i++) {
392:                        rows[i] = TableLayout.FILL;
393:                    }
394:                }
395:                final TableLayout resizableLayout = new TableLayout(
396:                        new double[][] { cols, rows });
397:                final MatrixPanel matrixPane = new MatrixPanel(resizableLayout,
398:                        cols[0] == -1, rows[0] == -1);
399:                matrixPane.setOpaque(true);
400:                matrixPane.setBackground(Color.white);
401:                final JScrollPane matrixScroller = new JScrollPane(matrixPane);
402:                matrixScroller.setOpaque(true);
403:                matrixScroller.setBackground(Color.white);
404:                JPanel resizePane = new JPanel(new TableLayout(new double[][] {
405:                        { 25, TableLayout.FILL }, { 25, TableLayout.FILL } }));
406:                resizePane.setOpaque(false);
407:                JButton switchOrientation = new JButton(Resources.flipAxisIcon);
408:                switchOrientation.addActionListener(new ActionListener() {
409:                    public void actionPerformed(ActionEvent e) {
410:                        if (orientation == HORIZONTAL) {
411:                            orientation = VERTICAL;
412:                        } else {
413:                            orientation = HORIZONTAL;
414:                        }
415:                        layoutPrepared = false;
416:                        update();
417:                    }
418:                });
419:                resizePane.add(switchOrientation, "0,0");
420:                if (horizontalCategory != null) {
421:                    ContelligentCategory cat = ContelligentCategoryManager
422:                            .getInstance().getCategoryByName(
423:                                    horizontalCategory.getName());
424:                    Description description = cat.getDescription(Resources
425:                            .getLocale());
426:                    String columnLabel = "";
427:                    if (description != null) {
428:                        columnLabel = description.getTitle();
429:                    }
430:
431:                    final MatrixScrollerLabel columnView = new MatrixScrollerLabel(
432:                            columnLabel, supportedHorizontalValues,
433:                            MatrixScrollerLabel.HORIZONTAL, cols[0]);
434:                    matrixScroller.setColumnHeaderView(columnView);
435:                    if (supportedHorizontalValues.length > 1) {
436:                        final JSlider columnWidth = new JSlider(
437:                                JSlider.HORIZONTAL, MINIMUM_COLUMN_WIDTH,
438:                                MAXIMUM_COLUMN_WIDTH, COLUMN_WIDTH);
439:                        columnView.addComponentListener(new ComponentAdapter() {
440:                            public void componentResized(ComponentEvent e) {
441:                                columnWidth.setValue((int) columnView
442:                                        .getSingleWidth());
443:                                columnWidth.revalidate();
444:                                columnWidth.repaint();
445:                            }
446:                        });
447:                        columnWidth.getModel().setValueIsAdjusting(true);
448:                        columnWidth.addChangeListener(new ChangeListener() {
449:                            public void stateChanged(ChangeEvent e) {
450:                                JSlider source = (JSlider) e.getSource();
451:                                if (!source.getValueIsAdjusting()) {
452:                                    int adjustedColumnWidth = source.getValue();
453:                                    for (int i = 0; i < resizableLayout
454:                                            .getColumn().length; i++) {
455:                                        resizableLayout.setColumn(i,
456:                                                adjustedColumnWidth);
457:                                    }
458:                                    columnView
459:                                            .setUnitWidth(adjustedColumnWidth);
460:                                    columnView.setTrackHorizontal(false);
461:                                    columnView.revalidate();
462:                                    columnView.repaint();
463:                                    matrixPane.setTrackHorizontal(false);
464:                                    matrixPane.revalidate();
465:                                    matrixPane.repaint();
466:                                    matrixScroller.revalidate();
467:                                    matrixScroller.repaint();
468:                                }
469:                            }
470:                        });
471:                        resizePane.add(columnWidth, "1,0");
472:                    }
473:                }
474:
475:                if (verticalCategory != null) {
476:                    ContelligentCategory cat = ContelligentCategoryManager
477:                            .getInstance().getCategoryByName(
478:                                    verticalCategory.getName());
479:                    Description description = cat.getDescription(Resources
480:                            .getLocale());
481:                    String rowLabel = "";
482:                    if (description != null) {
483:                        rowLabel = description.getTitle();
484:                    }
485:                    final MatrixScrollerLabel rowView = new MatrixScrollerLabel(
486:                            rowLabel, supportedVerticalValues,
487:                            MatrixScrollerLabel.VERTICAL, rows[0]);
488:                    matrixScroller.setRowHeaderView(rowView);
489:                    if (supportedVerticalValues.length > 1) {
490:                        final JSlider rowHeight = new JSlider(JSlider.VERTICAL,
491:                                MINIMUM_ROW_HEIGHT, MAXIMUM_ROW_HEIGHT,
492:                                ROW_HEIGHT);
493:                        rowView.addComponentListener(new ComponentAdapter() {
494:                            public void componentResized(ComponentEvent e) {
495:                                rowHeight.setValue((int) rowView
496:                                        .getSingleWidth());
497:                                rowHeight.revalidate();
498:                                rowHeight.repaint();
499:                            }
500:                        });
501:                        rowHeight.setInverted(true);
502:                        rowHeight.getModel().setValueIsAdjusting(true);
503:                        rowHeight.addChangeListener(new ChangeListener() {
504:                            public void stateChanged(ChangeEvent e) {
505:                                JSlider source = (JSlider) e.getSource();
506:                                if (!source.getValueIsAdjusting()) {
507:                                    int adjustedRowHeight = source.getValue();
508:                                    for (int i = 0; i < resizableLayout
509:                                            .getRow().length; i++) {
510:                                        resizableLayout.setRow(i,
511:                                                adjustedRowHeight);
512:                                    }
513:                                    rowView.setUnitWidth(adjustedRowHeight);
514:                                    rowView.setTrackHorizontal(false);
515:                                    rowView.revalidate();
516:                                    rowView.repaint();
517:                                    matrixPane.setTrackVertical(false);
518:                                    matrixPane.revalidate();
519:                                    matrixPane.repaint();
520:                                    matrixScroller.revalidate();
521:                                    matrixScroller.repaint();
522:                                }
523:                            }
524:                        });
525:                        resizePane.add(rowHeight, "0,1");
526:                    }
527:                }
528:                if (verticalCategory != null) {
529:                    for (int row = 0; row < supportedVerticalValues.length; row++) {
530:                        String verticalValue = supportedVerticalValues[row];
531:                        categoryMap.put(verticalCategory.getName(),
532:                                verticalValue);
533:                        if (horizontalCategory != null) {
534:                            for (int column = 0; column < supportedHorizontalValues.length; column++) {
535:                                String horizontalValue = supportedHorizontalValues[column];
536:                                categoryMap.put(horizontalCategory.getName(),
537:                                        horizontalValue);
538:                                matrixPane.add(createMatrixPanel(categoryMap),
539:                                        column + "," + row);
540:                            }
541:                        } else {
542:                            matrixPane.add(createMatrixPanel(categoryMap), 0
543:                                    + "," + row);
544:                        }
545:                    }
546:                } else {
547:                    for (int column = 0; column < supportedHorizontalValues.length; column++) {
548:                        String horizontalValue = supportedHorizontalValues[column];
549:                        categoryMap.put(horizontalCategory.getName(),
550:                                horizontalValue);
551:                        matrixPane.add(createMatrixPanel(categoryMap), column
552:                                + "," + 0);
553:                    }
554:                }
555:                if (horizontalCategory == null) {
556:                    resizePane.add(matrixScroller, "1,0,1,1");
557:                } else if (verticalCategory == null) {
558:                    resizePane.add(matrixScroller, "0,1,1,1");
559:                } else {
560:                    resizePane.add(matrixScroller, "1,1");
561:                }
562:                return resizePane;
563:            }
564:
565:            private JPanel createMatrixPanel(Map categoryMap) {
566:                String identifier = ContelligentCategoryManager
567:                        .createUniqueCategoryIdentifier(sensitiveCategories,
568:                                categoryMap);
569:                JPanel panel = new JPanel(new BorderLayout());
570:                panel.setOpaque(false);
571:                GUI2PaneMapping mapping = (GUI2PaneMapping) guiMap
572:                        .get(identifier);
573:                mapping.setPane(panel);
574:                return panel;
575:            }
576:
577:            private GUI createGUIInstance() {
578:                try {
579:                    GUI gui = (GUI) guiClass.newInstance();
580:                    gui.setComponent(getComponent());
581:                    gui.setView(getView());
582:                    gui.setResourceMode(getGUI().getResourceMode());
583:                    logger.log(Level.FINE,
584:                            "Sensitive configuration to inner gui: "
585:                                    + getGUI().getConfiguration());
586:                    gui.setConfiguration(getGUI().getConfiguration());
587:                    gui.init();
588:                    return gui;
589:                } catch (IllegalAccessException iae) {
590:                    logger.log(Level.SEVERE, "GUI [" + guiClass.getName()
591:                            + "] not found!", iae);
592:                    ExceptionDialog.show(iae);
593:                } catch (InstantiationException ie) {
594:                    logger.log(Level.SEVERE, "GUI [" + guiClass.getName()
595:                            + "] not found!", ie);
596:                    ExceptionDialog.show(ie);
597:                }
598:                return null;
599:            }
600:
601:            private Map<String, GUI2PaneMapping> createGUIs(Map combinations) {
602:                Map<String, GUI2PaneMapping> guiMap = new HashMap<String, GUI2PaneMapping>();
603:                for (Iterator it = combinations.entrySet().iterator(); it
604:                        .hasNext();) {
605:                    Map.Entry entry = (Map.Entry) it.next();
606:                    String identifier = (String) entry.getKey();
607:                    Map categoryMap = (Map) entry.getValue();
608:                    GUI gui = createGUIInstance();
609:                    if (gui != null) {
610:                        gui.setResourceCategoryMap(categoryMap);
611:                        guiMap.put(identifier, new GUI2PaneMapping(gui, null));
612:                    }
613:                }
614:                return guiMap;
615:            }
616:
617:            public List getEditors() {
618:                return editors;
619:            }
620:
621:            private static class GUI2PaneMapping {
622:                private GUI gui;
623:
624:                private JPanel pane;
625:
626:                public GUI2PaneMapping(GUI gui, JPanel pane) {
627:                    this .gui = gui;
628:                    this .pane = pane;
629:                }
630:
631:                public GUI getGui() {
632:                    return gui;
633:                }
634:
635:                public void setPane(JPanel pane) {
636:                    this .pane = pane;
637:                }
638:
639:                public JPanel getPane() {
640:                    return pane;
641:                }
642:            }
643:
644:            public class SelectTabbedLayoutAction extends AbstractAction
645:                    implements  ContelligentAction {
646:                public SelectTabbedLayoutAction() {
647:                    super ("select_tabbed_layout_action",
648:                            Resources.selectTabbedLayoutIcon);
649:                    putValue(TYPE, PUSH_ACTION);
650:                    putValue(ACTION_TYPE, VIEW_ACTION);
651:                    putValue(ACTION_GROUP, VIEW_CATEGORIES_GROUP);
652:                    putValue(ACTION_POS, VIEW_CATEGORIES_TABBED);
653:                    putValue(MENU_TARGET, MENU);
654:                    putValue(BUTTON_TARGET, TOOLBAR);
655:                    putValue(POPUP_TARGET, NO_POPUP);
656:                }
657:
658:                public void actionPerformed(ActionEvent e) {
659:                    setDisplayMode(DISPLAY_MODE_TABBED);
660:                    layoutPrepared = false;
661:                    prepareLayout();
662:                    update();
663:                }
664:            }
665:
666:            public class SelectFlatLayoutAction extends AbstractAction
667:                    implements  ContelligentAction {
668:                public SelectFlatLayoutAction() {
669:                    super ("select_flat_layout_action",
670:                            Resources.selectFlatLayoutIcon);
671:                    putValue(TYPE, PUSH_ACTION);
672:                    putValue(ACTION_TYPE, VIEW_ACTION);
673:                    putValue(MENU_TARGET, MENU);
674:                    putValue(BUTTON_TARGET, TOOLBAR);
675:                    putValue(POPUP_TARGET, NO_POPUP);
676:                }
677:
678:                public void actionPerformed(ActionEvent e) {
679:                    setDisplayMode(DISPLAY_MODE_FLAT);
680:                    layoutPrepared = false;
681:                    prepareLayout();
682:                    update();
683:                }
684:            }
685:
686:            public class SelectMatrixLayoutAction extends AbstractAction
687:                    implements  ContelligentAction {
688:                public SelectMatrixLayoutAction() {
689:                    super ("select_matrix_layout_action",
690:                            Resources.selectMatrixLayoutIcon);
691:                    putValue(TYPE, PUSH_ACTION);
692:                    putValue(ACTION_TYPE, VIEW_ACTION);
693:                    putValue(ACTION_GROUP, VIEW_CATEGORIES_GROUP);
694:                    putValue(ACTION_POS, VIEW_CATEGORIES_MATRIX);
695:                    putValue(MENU_TARGET, MENU);
696:                    putValue(BUTTON_TARGET, TOOLBAR);
697:                    putValue(POPUP_TARGET, NO_POPUP);
698:                }
699:
700:                public void actionPerformed(ActionEvent e) {
701:                    setDisplayMode(DISPLAY_MODE_MATRIX);
702:                    layoutPrepared = false;
703:                    prepareLayout();
704:                    update();
705:                }
706:            }
707:
708:            public class SelectSensitiveCategoriesAction extends AbstractAction
709:                    implements  ContelligentAction {
710:                public SelectSensitiveCategoriesAction() {
711:                    super ("select_sensitive_categories_action",
712:                            Resources.editCategoriesIcon);
713:                    putValue(TYPE, PUSH_ACTION);
714:                    putValue(ACTION_TYPE, EDIT_ACTION);
715:                    putValue(ACTION_GROUP, EDIT_CATEGORIES_GROUP);
716:                    putValue(ACTION_POS, EDIT_CATEGORIES_DEFINE);
717:                    putValue(MENU_TARGET, MENU);
718:                    putValue(BUTTON_TARGET, TOOLBAR);
719:                    putValue(POPUP_TARGET, NO_POPUP);
720:                }
721:
722:                public void actionPerformed(ActionEvent e) {
723:                    GUI gui = createGUIInstance();
724:                    CategorySensitiveWizard wizard = new CategorySensitiveWizard(
725:                            gui.getSensitiveCategories(), gui.getResourceMode());
726:                    int result = wizard.startWizard(Wizard.FIRST_STEP);
727:                    if (result != CategorySensitiveWizard.CANCEL_OPTION) {
728:                        List categories = wizard.getCategories();
729:                        gui.setCategories(categories);
730:                        gui.getComponent().setModified(true);
731:                        layoutPrepared = false;
732:                        categoryCombinations = null;
733:                        prepareLayout();
734:                        update();
735:                    }
736:                }
737:            }
738:
739:            static class MatrixPanel extends JPanel implements  Scrollable {
740:                private boolean trackHorizontal, trackVertical;
741:
742:                public MatrixPanel(LayoutManager layoutManager,
743:                        boolean trackHorizontal, boolean trackVertical) {
744:                    super (layoutManager);
745:                    this .trackHorizontal = trackHorizontal;
746:                    this .trackVertical = trackVertical;
747:                }
748:
749:                public Dimension getPreferredScrollableViewportSize() {
750:                    return getPreferredSize();
751:                }
752:
753:                public boolean getScrollableTracksViewportHeight() {
754:                    return trackVertical;
755:                }
756:
757:                public boolean getScrollableTracksViewportWidth() {
758:                    return trackHorizontal;
759:                }
760:
761:                public void setTrackHorizontal(boolean trackHorizontal) {
762:                    this .trackHorizontal = trackHorizontal;
763:                }
764:
765:                public void setTrackVertical(boolean trackVertical) {
766:                    this .trackVertical = trackVertical;
767:                }
768:
769:                public int getScrollableBlockIncrement(Rectangle visibleRect,
770:                        int orientation, int direction) {
771:                    return 10;
772:                }
773:
774:                public int getScrollableUnitIncrement(Rectangle visibleRect,
775:                        int orientation, int direction) {
776:                    return 10;
777:                }
778:            }
779:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.