Source Code Cross Referenced for XSurveyComponentBig.java in  » XML-UI » xui32 » com » xoetrope » carousel » survey » 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 » XML UI » xui32 » com.xoetrope.carousel.survey 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package com.xoetrope.carousel.survey;
0002:
0003:        import com.xoetrope.survey.Question;
0004:        import com.xoetrope.survey.QuestionGroup;
0005:        import java.awt.Color;
0006:        import java.awt.Component;
0007:        import java.awt.Dimension;
0008:        import java.awt.Font;
0009:        import java.awt.Graphics;
0010:        import java.awt.Graphics2D;
0011:        import java.awt.Image;
0012:        import java.awt.Point;
0013:        import java.awt.Polygon;
0014:        import java.awt.Rectangle;
0015:        import java.awt.RenderingHints;
0016:        import java.awt.Shape;
0017:        import java.awt.Toolkit;
0018:        import java.awt.event.ActionEvent;
0019:        import java.awt.event.ActionListener;
0020:        import java.awt.event.MouseAdapter;
0021:        import java.awt.event.MouseEvent;
0022:        import java.awt.event.MouseListener;
0023:        import java.awt.event.MouseMotionListener;
0024:        import java.awt.geom.Rectangle2D;
0025:        import java.net.URL;
0026:        import java.util.Enumeration;
0027:        import java.util.Observable;
0028:        import java.util.Observer;
0029:        import java.util.Vector;
0030:        import javax.swing.BorderFactory;
0031:        import javax.swing.ImageIcon;
0032:        import javax.swing.JButton;
0033:        import javax.swing.JComponent;
0034:        import javax.swing.JLabel;
0035:        import javax.swing.JLayeredPane;
0036:        import javax.swing.JMenuItem;
0037:        import javax.swing.JPanel;
0038:        import javax.swing.JPopupMenu;
0039:        import javax.swing.JScrollBar;
0040:        import javax.swing.JScrollPane;
0041:        import javax.swing.ScrollPaneConstants;
0042:        import javax.swing.SwingUtilities;
0043:        import javax.swing.event.ChangeEvent;
0044:        import javax.swing.event.ChangeListener;
0045:        import javax.swing.plaf.basic.BasicArrowButton;
0046:        import net.xoetrope.editor.project.pages.components.EditorComponentAdapter;
0047:        import net.xoetrope.xui.XProject;
0048:        import net.xoetrope.xui.XProjectManager;
0049:        import net.xoetrope.xui.data.XModel;
0050:        import javax.swing.JComponent;
0051:
0052:        /**
0053:         * A super class for QuestionGroupView and RuleView, handles collapsing/expannding, dragging,
0054:         * srcolling content, etc...
0055:         *
0056:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
0057:         * the GNU Public License (GPL), please see license.txt for more details. If
0058:         * you make commercial use of this software you must purchase a commercial
0059:         * license from Xoetrope.</p>
0060:         * <p> $Revision: 1.5 $</p>
0061:         */
0062:        public abstract class XSurveyComponentBig extends JComponent implements 
0063:                MouseListener, MouseMotionListener {
0064:            public static Color BACKGROUND_COLOR = Color.BLUE;
0065:            public static Color BORDER_COLOR = Color.BLACK;
0066:            public static Color SELECTED_COLOR = new Color(240, 240, 0);
0067:            public static int WIDTH = 200;
0068:            public static int HEIGHT = 216;
0069:            public static int LEFT_GAP = 10;
0070:            public static int RIGHT_GAP = 10;
0071:            public static int TOP_GAP = 10;
0072:            public static int BOTTOM_GAP = 30;
0073:            public static int HEADER_GAP = 30;
0074:            public static int HEADER_HEIGHT = 50;
0075:            public static int COMPONENT_HEIGHT = 20;
0076:            public static int COMPONENT_GAP = 5;
0077:            public static double ARROW_BUTTON_Y = 0.2;
0078:            public static Color ARROW_BUTTON_BACKGROUND = new Color(39, 147,
0079:                    173);
0080:            public static Color ARROW_BUTTON_BORDER = Color.BLACK;
0081:            public static int ARROW_BUTTON_WIDTH = 40;
0082:            public static int ARROW_BUTTON_HEIGHT = 20;
0083:            public static int ARROW_BUTTON_GAP = 3;
0084:            public static int HEADERFIELD_WIDTH = 180;
0085:            public static int HEADERFIELD_HEIGHT = 30;
0086:            public static int HEADERFIELD_GAP = 5;
0087:            public static int HEADERID_WIDTH = 30;
0088:            public static int HEADERTARGET_WIDTH = 30;
0089:            public static int HEADERFIELD_ARC = 10;
0090:            public static int HEADER_TEXT_GAP = 3;
0091:            public static Color HEADERFIELD_BACKGROUND = Color.GREEN;
0092:            public static Color HEADERFIELD_BORDER = Color.BLACK;
0093:            public static int HEADER_FONT_STYLE = 0;
0094:            public static int HEADER_FONT_SIZE = 12;
0095:            public static String HEADER_FONT_NAME = "Dialog";
0096:            public static Color HEADER_FONT_COLOR = Color.BLACK;
0097:
0098:            protected Color backgroundColor;
0099:            protected Color borderColor;
0100:            protected int width, height;
0101:            protected int leftGap, rightGap, topGap, bottomGap;
0102:            protected int headerHeight, headerGap;
0103:            protected int componentHeight, componentGap;
0104:            protected Shape shape;
0105:            protected XRulesEditorPane editorPane;
0106:            protected int posX, posY;
0107:            protected int headerFontStyle, headerFontSize;
0108:            protected String headerFontName;
0109:            protected Color headerFontColor;
0110:            protected Font headerFont;
0111:            protected XArrowButton arrowButtonUp;
0112:            protected XArrowButton arrowButtonDown;
0113:            protected Color arrowButtonBackground;
0114:            protected Color arrowButtonBorder;
0115:            protected int arrowButtonWidth;
0116:            protected int arrowButtonHeight;
0117:            protected double arrowButtonY;
0118:            protected int arrowButtonGap;
0119:            protected XHeaderField headerField;
0120:            protected int headerFieldWidth;
0121:            protected int headerFieldHeight;
0122:            protected int headerFieldGap;
0123:            protected int headerIdWidth;
0124:            protected int headerTargetWidth;
0125:            protected int headerFieldArc;
0126:            protected int headerTextGap;
0127:            protected Color headerFieldBackground;
0128:            protected Color headerFieldBorder;
0129:            protected int startComp;
0130:            protected boolean needsRefresh;
0131:            protected MouseEvent firstMouseEvent;
0132:            protected boolean isDragged;
0133:            protected Vector components = null;
0134:            protected XSurvey survey;
0135:            protected JPopupMenu popupMenu;
0136:            protected XSurveyEditorFrame editorFrame;
0137:            protected boolean isSelected;
0138:            protected Color selectedColor;
0139:            protected boolean expanded;
0140:            protected Observer selectionObserver;
0141:
0142:            protected static double getScale() {
0143:                return XRulesEditorPane.SCALE;
0144:            }
0145:
0146:            public XSurveyComponentBig(XRulesEditorPane ep) {
0147:                super ();
0148:
0149:                editorPane = ep;
0150:                editorPane.add(this , JLayeredPane.PALETTE_LAYER);
0151:                selectionObserver = ep.getSelectionObserver();
0152:                setLayout(null);
0153:                initVariables();
0154:                setSize();
0155:                createArrowButtons();
0156:                refreshArrowButtons();
0157:                createHeaderField();
0158:                refreshHeaderField();
0159:                addMouseListener(this );
0160:                addMouseMotionListener(this );
0161:                addMouseListener(editorPane.getChangesSaver());
0162:                createPopupMenu();
0163:            }
0164:
0165:            protected abstract void createShape();
0166:
0167:            protected abstract void createComponents();
0168:
0169:            public abstract String getHeaderId();
0170:
0171:            public abstract String getHeaderName();
0172:
0173:            public abstract String getHeaderTarget();
0174:
0175:            protected abstract void createPopupMenu();
0176:
0177:            public boolean isSelected() {
0178:                return isSelected;
0179:            }
0180:
0181:            public void isSelected(boolean state) {
0182:                if (isSelected == state)
0183:                    return;
0184:                isSelected = state;
0185:                if (isSelected)
0186:                    selectionObserver.update(null, this );
0187:            }
0188:
0189:            public void selectXComponents(boolean state) {
0190:                Enumeration enumComponents = components.elements();
0191:                while (enumComponents.hasMoreElements()) {
0192:                    XSurveyComponentSmall component = (XSurveyComponentSmall) enumComponents
0193:                            .nextElement();
0194:                    component.isSelected(state);
0195:                    component.repaint();
0196:                }
0197:            }
0198:
0199:            public Vector getXComponents() {
0200:                return components;
0201:            }
0202:
0203:            public void remove() {
0204:                while (components.size() > 0) {
0205:                    XSurveyComponentSmall component = (XSurveyComponentSmall) components
0206:                            .get(0);
0207:                    component.remove();
0208:                }
0209:                editorPane.remove(arrowButtonUp);
0210:                editorPane.remove(arrowButtonDown);
0211:                editorPane.remove(headerField);
0212:                editorPane.remove(this );
0213:            }
0214:
0215:            public void refresh() {
0216:                setSize();
0217:                setLocation();
0218:                revalidate();
0219:                if (expanded && isVisible()) {
0220:                    refreshComponents();
0221:                    refreshArrowButtons();
0222:                }
0223:                refreshHeaderField();
0224:                repaint();
0225:            }
0226:
0227:            public void setVisible(boolean state) {
0228:                super .setVisible(state);
0229:                Enumeration enumComponents = components.elements();
0230:                while (enumComponents.hasMoreElements()) {
0231:                    XSurveyComponentSmall component = (XSurveyComponentSmall) enumComponents
0232:                            .nextElement();
0233:                    component.setVisible(expanded && state);
0234:                    if (expanded && state) {
0235:                        component.refresh();
0236:                        component.moveToFront();
0237:                    }
0238:                    ;
0239:                }
0240:
0241:                if (headerField != null)
0242:                    headerField.setVisible(state);
0243:
0244:                if (expanded) {
0245:                    arrowButtonUp.setVisible(state);
0246:                    arrowButtonDown.setVisible(state);
0247:                    if (state)
0248:                        refreshComponents();
0249:                }
0250:            }
0251:
0252:            public void repaint() {
0253:                super .repaint();
0254:                if (headerField != null)
0255:                    headerField.repaint();
0256:
0257:                if (components != null) {
0258:                    Enumeration enumComponents = components.elements();
0259:                    while (enumComponents.hasMoreElements()) {
0260:                        XSurveyComponentSmall component = (XSurveyComponentSmall) enumComponents
0261:                                .nextElement();
0262:                        component.repaint();
0263:                    }
0264:                }
0265:            }
0266:
0267:            protected void createArrowButtons() {
0268:                double ys = getArrowButtonY();
0269:                Color bg = getArrowButtonBackground();
0270:                Color br = getArrowButtonBorder();
0271:
0272:                int w = getArrowButtonWidth();
0273:                int h = getArrowButtonHeight();
0274:                arrowButtonUp = new XArrowButton(w, h, ys, bg, br,
0275:                        XArrowButton.UP);
0276:                arrowButtonDown = new XArrowButton(w, h, ys, bg, br,
0277:                        XArrowButton.DOWN);
0278:                editorPane.add(arrowButtonUp, JLayeredPane.PALETTE_LAYER);
0279:                editorPane.add(arrowButtonDown, JLayeredPane.PALETTE_LAYER);
0280:
0281:                arrowButtonUp.addMouseListener(new MouseAdapter() {
0282:                    public void mousePressed(MouseEvent e) {
0283:                        scroll(-1);
0284:                        moveToFront();
0285:                    }
0286:                });
0287:                arrowButtonDown.addMouseListener(new MouseAdapter() {
0288:                    public void mousePressed(MouseEvent e) {
0289:                        scroll(1);
0290:                        moveToFront();
0291:                    }
0292:                });
0293:            }
0294:
0295:            protected void createHeaderField() {
0296:                headerField = new XHeaderField(this , editorPane);
0297:            }
0298:
0299:            public XHeaderField getHeaderField() {
0300:                return headerField;
0301:            }
0302:
0303:            protected void initVariables() {
0304:                expanded = true;
0305:                XProject project = XProjectManager.getCurrentProject();
0306:                survey = (XSurvey) project.getObject("Survey");
0307:                editorFrame = (XSurveyEditorFrame) project
0308:                        .getObject("EditorFrame");
0309:                popupMenu = null;
0310:                shape = null;
0311:                components = new Vector();
0312:                needsRefresh = true;
0313:                posX = 0;
0314:                posY = 0;
0315:                width = WIDTH;
0316:                height = HEIGHT;
0317:                leftGap = LEFT_GAP;
0318:                rightGap = RIGHT_GAP;
0319:                topGap = TOP_GAP;
0320:                bottomGap = BOTTOM_GAP;
0321:                headerGap = HEADER_GAP;
0322:                headerHeight = HEADER_HEIGHT;
0323:                componentHeight = COMPONENT_HEIGHT;
0324:                componentGap = COMPONENT_GAP;
0325:                backgroundColor = BACKGROUND_COLOR;
0326:                borderColor = BORDER_COLOR;
0327:                headerFontName = HEADER_FONT_NAME;
0328:                headerFontSize = HEADER_FONT_SIZE;
0329:                headerFontStyle = HEADER_FONT_STYLE;
0330:                headerFontColor = HEADER_FONT_COLOR;
0331:                startComp = 0;
0332:                firstMouseEvent = null;
0333:                isDragged = false;
0334:                arrowButtonBackground = ARROW_BUTTON_BACKGROUND;
0335:                arrowButtonBorder = ARROW_BUTTON_BORDER;
0336:                arrowButtonWidth = ARROW_BUTTON_WIDTH;
0337:                arrowButtonHeight = ARROW_BUTTON_HEIGHT;
0338:                arrowButtonY = ARROW_BUTTON_Y;
0339:                arrowButtonGap = ARROW_BUTTON_GAP;
0340:                headerFieldWidth = HEADERFIELD_WIDTH;
0341:                headerFieldHeight = HEADERFIELD_HEIGHT;
0342:                headerFieldGap = HEADERFIELD_GAP;
0343:                headerIdWidth = HEADERID_WIDTH;
0344:                headerTargetWidth = HEADERTARGET_WIDTH;
0345:                headerFieldBackground = HEADERFIELD_BACKGROUND;
0346:                headerFieldBorder = HEADERFIELD_BORDER;
0347:                headerFieldArc = HEADERFIELD_ARC;
0348:                headerTextGap = HEADER_TEXT_GAP;
0349:                selectedColor = SELECTED_COLOR;
0350:            }
0351:
0352:            public void setExpanded(boolean state) {
0353:                if (expanded ^ state) {
0354:                    expanded = state;
0355:                    if (state)
0356:                        expand();
0357:                    else
0358:                        collapse();
0359:                }
0360:            }
0361:
0362:            protected void expand() {
0363:                setSize();
0364:                arrowButtonUp.setVisible(true);
0365:                arrowButtonDown.setVisible(true);
0366:                refreshComponents();
0367:                moveToFront();
0368:            }
0369:
0370:            protected void collapse() {
0371:                setSize();
0372:                arrowButtonUp.setVisible(false);
0373:                arrowButtonDown.setVisible(false);
0374:                Enumeration enumComponents = components.elements();
0375:                while (enumComponents.hasMoreElements()) {
0376:                    XSurveyComponentSmall component = (XSurveyComponentSmall) enumComponents
0377:                            .nextElement();
0378:                    component.setVisible(false);
0379:                }
0380:            }
0381:
0382:            public boolean isExpanded() {
0383:                return expanded;
0384:            }
0385:
0386:            public void needsRefresh(boolean state) {
0387:                needsRefresh = state;
0388:            }
0389:
0390:            public boolean needsRefresh() {
0391:                return needsRefresh;
0392:            }
0393:
0394:            public boolean contains(int x, int y) {
0395:                return (shape != null && shape.contains(x, y));
0396:            }
0397:
0398:            protected void setSize() {
0399:                Dimension size = new Dimension(getWidth(), getHeight());
0400:                setSize(size);
0401:                setMinimumSize(size);
0402:                setPreferredSize(size);
0403:                createShape();
0404:            }
0405:
0406:            protected void setLocation() {
0407:                int x = getPosX();
0408:                int y = getPosY();
0409:                super .setLocation(x, y);
0410:            }
0411:
0412:            protected void refreshComponents() {
0413:                int compHeight = getComponentHeight();
0414:                int compGap = getComponentGap();
0415:                int numComps = getNumVisComponents();
0416:
0417:                int y = getLocation().y;
0418:                y += getTopGap() + getHeaderHeight() + getHeaderGap();
0419:                y -= startComp * (compGap + compHeight);
0420:                int x = getLocation().x + getLeftGap();
0421:
0422:                for (int i = 0; i < components.size(); i++) {
0423:                    XSurveyComponentSmall component = (XSurveyComponentSmall) components
0424:                            .get(i);
0425:                    if (!component.isDragged())
0426:                        component.setLocation(x, y);
0427:                    component.setWidth(getContentWidth());
0428:                    component.setSize();
0429:                    boolean visible = component.isDragged() || i >= startComp
0430:                            && i < startComp + numComps;
0431:                    component.setVisible(visible);
0432:                    y += compHeight + compGap;
0433:                    if (visible) {
0434:                        component.refresh();
0435:                        component.revalidate();
0436:                        component.repaint();
0437:                    }
0438:                }
0439:                refreshArrowButtonsState();
0440:                needsRefresh(false);
0441:            }
0442:
0443:            protected boolean hasComponentsUp() {
0444:                return (startComp > 0);
0445:            }
0446:
0447:            protected boolean hasComponentsDown() {
0448:                return (startComp + getNumVisComponents() < components.size());
0449:            }
0450:
0451:            protected void refreshArrowButtonsState() {
0452:                arrowButtonUp.setEnabled(hasComponentsUp());
0453:                arrowButtonDown.setEnabled(hasComponentsDown());
0454:                arrowButtonUp.repaint();
0455:                arrowButtonDown.repaint();
0456:            }
0457:
0458:            protected void scrollToBottom() {
0459:                startComp = components.size() - getNumVisComponents();
0460:                startComp = Math.max(startComp, 0);
0461:            }
0462:
0463:            protected void scroll(int units) {
0464:                startComp += units;
0465:                if (startComp < 0)
0466:                    startComp = 0;
0467:                if (startComp > components.size() - getNumVisComponents())
0468:                    startComp = components.size() - getNumVisComponents();
0469:                refreshComponents();
0470:            }
0471:
0472:            protected void refreshArrowButtons() {
0473:                int aw, ah, x, y;
0474:                int w = getWidth();
0475:
0476:                arrowButtonUp.setSize();
0477:                aw = arrowButtonUp.getWidth();
0478:                ah = arrowButtonUp.getHeight();
0479:                x = getLocation().x + (w - aw) / 2;
0480:                y = getLocation().y + getTopGap();
0481:                y += getHeaderHeight() + getHeaderGap();
0482:                y -= getArrowButtonGap() + ah;
0483:                arrowButtonUp.setLocation(x, y);
0484:
0485:                arrowButtonDown.setSize();
0486:                aw = arrowButtonDown.getWidth();
0487:                ah = arrowButtonDown.getHeight();
0488:                x = getLocation().x + (w - aw) / 2;
0489:                y = getLocation().y + getHeight();
0490:                y -= getBottomGap() - getArrowButtonGap();
0491:                arrowButtonDown.setLocation(x, y);
0492:
0493:            }
0494:
0495:            protected void refreshHeaderField() {
0496:                int hw, hh, x, y;
0497:                int w = getWidth();
0498:
0499:                headerField.setSize();
0500:                hw = getHeaderFieldWidth();
0501:                hh = getHeaderFieldHeight();
0502:                x = getLocation().x + (w - hw) / 2;
0503:                y = getLocation().y + getTopGap();
0504:                headerField.setLocation(x, y);
0505:            }
0506:
0507:            public void moveToFront() {
0508:                editorPane.moveToFront(this );
0509:
0510:                // components
0511:                Enumeration enumComponents = components.elements();
0512:                while (enumComponents.hasMoreElements()) {
0513:                    XSurveyComponentSmall component = (XSurveyComponentSmall) enumComponents
0514:                            .nextElement();
0515:                    if (component.isVisible())
0516:                        component.moveToFront();
0517:                }
0518:
0519:                //arrow buttons
0520:                editorPane.moveToFront(arrowButtonUp);
0521:                editorPane.moveToFront(arrowButtonDown);
0522:
0523:                //header
0524:                editorPane.moveToFront(headerField);
0525:                headerField.repaint();
0526:            }
0527:
0528:            protected void paintShape(Graphics2D g) {
0529:                g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
0530:                        RenderingHints.VALUE_ANTIALIAS_ON);
0531:                g.setColor(backgroundColor);
0532:                g.fill(shape);
0533:                g.setColor(borderColor);
0534:                g.draw(shape);
0535:            }
0536:
0537:            protected void paintArrows(Graphics2D g) {
0538:            }
0539:
0540:            public void paint(Graphics g) {
0541:                Graphics2D g2d = (Graphics2D) g;
0542:                if (needsRefresh())
0543:                    refreshComponents();
0544:            }
0545:
0546:            public void setLocation(int x, int y) {
0547:                setPosX(x);
0548:                setPosY(y);
0549:
0550:                int dx = x - getLocation().x;
0551:                int dy = y - getLocation().y;
0552:                super .setLocation(x, y);
0553:
0554:                //components
0555:                Enumeration enumComponents = components.elements();
0556:                while (enumComponents.hasMoreElements()) {
0557:                    XSurveyComponentSmall component = (XSurveyComponentSmall) enumComponents
0558:                            .nextElement();
0559:                    x = component.getLocation().x + dx;
0560:                    y = component.getLocation().y + dy;
0561:                    component.setLocation(x, y);
0562:                }
0563:
0564:                //arrow buttons
0565:                x = arrowButtonUp.getLocation().x + dx;
0566:                y = arrowButtonUp.getLocation().y + dy;
0567:                arrowButtonUp.setLocation(x, y);
0568:                x = arrowButtonDown.getLocation().x + dx;
0569:                y = arrowButtonDown.getLocation().y + dy;
0570:                arrowButtonDown.setLocation(x, y);
0571:
0572:                //header
0573:                x = headerField.getLocation().x + dx;
0574:                y = headerField.getLocation().y + dy;
0575:                headerField.setLocation(x, y);
0576:            }
0577:
0578:            public int getComponentIdx(XSurveyComponentSmall component) {
0579:                int idx = -1;
0580:                for (int i = 0; i < components.size() && idx == -1; i++) {
0581:                    XSurveyComponentSmall c = (XSurveyComponentSmall) components
0582:                            .get(i);
0583:                    if (c.equals(component))
0584:                        idx = i;
0585:                }
0586:                return idx;
0587:            }
0588:
0589:            public void removeComponents() {
0590:                while (components.size() > 0) {
0591:                    XSurveyComponentSmall component = (XSurveyComponentSmall) components
0592:                            .get(0);
0593:                    component.remove();
0594:                }
0595:            }
0596:
0597:            public boolean removeComponent(XSurveyComponentSmall c) {
0598:                boolean b = components.remove(c);
0599:                return b;
0600:            }
0601:
0602:            public void insertComponent(XSurveyComponentSmall component,
0603:                    int position) {
0604:                components.add(position, component);
0605:                refreshComponents();
0606:            }
0607:
0608:            public boolean insertComponent(XSurveyComponentSmall component) {
0609:                int qx = component.getLocation().x;
0610:                int qy = component.getLocation().y;
0611:                int qw = component.getSize().width;
0612:                int qh = component.getSize().height;
0613:                int gx = getLocation().x;
0614:                int gy = getLocation().y;
0615:                int gw = getSize().width;
0616:                int gh = getSize().height;
0617:                int leftGap = getLeftGap();
0618:                int rightGap = getRightGap();
0619:                int top = getTopGap() + getHeaderHeight();
0620:
0621:                if (qx + qw / 2 < gx + leftGap
0622:                        || qx + qw / 2 > gx + gw - rightGap)
0623:                    return false;
0624:                if (qy + qh / 2 < gy + top || qy + qh / 2 > gy + gh)
0625:                    return false;
0626:
0627:                int qcx = qx + qw / 2;
0628:                int qcy = qy + qh / 2;
0629:                int idx = -1, cy = -1, pcy = -1;
0630:                for (int i = 0; i < components.size(); i++) {
0631:                    XSurveyComponentSmall qv = (XSurveyComponentSmall) components
0632:                            .get(i);
0633:                    cy = qv.getLocation().y + qv.getSize().height / 2;
0634:                    if (qcy < cy && (pcy == -1 || qcy > pcy))
0635:                        idx = i;
0636:                    pcy = cy;
0637:                }
0638:
0639:                components.add((idx >= 0 ? idx : components.size()), component);
0640:                refreshComponents();
0641:                return true;
0642:            }
0643:
0644:            public boolean moveComponentView(XSurveyComponentSmall component) {
0645:                int compIdx = -1;
0646:                for (int i = 0; i < components.size() && compIdx == -1; i++) {
0647:                    XSurveyComponentSmall qv = (XSurveyComponentSmall) components
0648:                            .get(i);
0649:                    if (qv.equals(component))
0650:                        compIdx = i;
0651:                }
0652:                if (compIdx == -1)
0653:                    return false;
0654:
0655:                int leftGap = getLeftGap();
0656:                int rightGap = getRightGap();
0657:                int bootomGap = getBottomGap();
0658:                int top = getTopGap() + getHeaderHeight();
0659:                int qx = component.getLocation().x;
0660:                int qy = component.getLocation().y;
0661:                int qw = component.getSize().width;
0662:                int qh = component.getSize().height;
0663:                int gx = getLocation().x;
0664:                int gy = getLocation().y;
0665:                int gw = getSize().width;
0666:                int gh = getSize().height;
0667:
0668:                if (qx + qw / 2 < gx + leftGap
0669:                        || qx + qw / 2 > gx + gw - rightGap) {
0670:                    components.remove(component);
0671:                    refreshComponents();
0672:                    return false;
0673:                }
0674:                if (qy + qh / 2 < gy + top || qy + qh / 2 > gy + gh) {
0675:                    components.remove(component);
0676:                    refreshComponents();
0677:                    return false;
0678:                }
0679:
0680:                int y1 = 0, y2 = 0;
0681:                if (compIdx > 0) {
0682:                    XSurveyComponentSmall qv = (XSurveyComponentSmall) components
0683:                            .get(compIdx - 1);
0684:                    y1 = qv.getLocation().y + qv.getSize().height / 2;
0685:                } else
0686:                    y1 = component.getLocation().y;
0687:
0688:                if (compIdx < components.size() - 1) {
0689:                    XSurveyComponentSmall qv = (XSurveyComponentSmall) components
0690:                            .get(compIdx + 1);
0691:                    y2 = qv.getLocation().y + qv.getSize().height / 2;
0692:                } else
0693:                    y2 = component.getLocation().y + component.getSize().height;
0694:
0695:                if (component.getLocation().y < y1) {
0696:                    components.remove(component);
0697:                    components.add(compIdx - 1, component);
0698:                } else if (component.getLocation().y
0699:                        + component.getSize().height > y2) {
0700:                    components.remove(component);
0701:                    components.add(compIdx + 1, component);
0702:                }
0703:
0704:                refreshComponents();
0705:                return true;
0706:            }
0707:
0708:            protected void refreshView() {
0709:                refreshComponents();
0710:                moveToFront();
0711:                repaint();
0712:            }
0713:
0714:            public void mouseClicked(MouseEvent e) {
0715:            }
0716:
0717:            protected void showPopupMenu(Point p) {
0718:                if (popupMenu != null)
0719:                    popupMenu.show(this , p.x, p.y);
0720:            }
0721:
0722:            public void mousePressed(MouseEvent e) {
0723:                editorPane.selectAllComponents(false);
0724:                isSelected(true);
0725:                repaint();
0726:
0727:                firstMouseEvent = e;
0728:                moveToFront();
0729:                repaint();
0730:                if (e.getButton() == MouseEvent.BUTTON3)
0731:                    showPopupMenu(e.getPoint());
0732:            }
0733:
0734:            protected void startDragging(MouseEvent e) {
0735:            }
0736:
0737:            protected void endDragging(MouseEvent e) {
0738:            }
0739:
0740:            public void mouseReleased(MouseEvent e) {
0741:                if (!isDragged)
0742:                    return;
0743:
0744:                isDragged = false;
0745:                firstMouseEvent = null;
0746:                endDragging(e);
0747:            }
0748:
0749:            public void mouseEntered(MouseEvent e) {
0750:            }
0751:
0752:            public void mouseExited(MouseEvent e) {
0753:            }
0754:
0755:            public void mouseDragged(MouseEvent e) {
0756:                if (firstMouseEvent == null)
0757:                    return;
0758:
0759:                if (!isDragged) {
0760:                    isDragged = true;
0761:                    startDragging(e);
0762:                }
0763:
0764:                int dx = (int) (e.getX() - firstMouseEvent.getX());
0765:                int dy = (int) (e.getY() - firstMouseEvent.getY());
0766:                dx = (int) (dx / editorPane.getGridGap())
0767:                        * editorPane.getGridGap();
0768:                dy = (int) (dy / editorPane.getGridGap())
0769:                        * editorPane.getGridGap();
0770:
0771:                int x = getLocation().x + dx;
0772:                int y = getLocation().y + dy;
0773:                setLocation(x, y);
0774:            }
0775:
0776:            public void mouseMoved(MouseEvent e) {
0777:            }
0778:
0779:            public int getPosX() {
0780:                return (int) (getScale() * posX);
0781:            }
0782:
0783:            public void setPosX(int px) {
0784:                posX = (int) ((double) px / getScale());
0785:            }
0786:
0787:            public int getPosY() {
0788:                return (int) (getScale() * posY);
0789:            }
0790:
0791:            public void setPosY(int py) {
0792:                posY = (int) ((double) py / getScale());
0793:            }
0794:
0795:            public int getWidth() {
0796:                return (int) (getScale() * width);
0797:            }
0798:
0799:            public void setWidth(int w) {
0800:                width = (int) ((double) w / getScale());
0801:            }
0802:
0803:            public int getHeight() {
0804:                int h = (expanded ? height : topGap + headerHeight + topGap);
0805:                return (int) (getScale() * h);
0806:            }
0807:
0808:            public void setHeight(int h) {
0809:                height = (int) ((double) h / getScale());
0810:            }
0811:
0812:            public int getLeftGap() {
0813:                return (int) (getScale() * leftGap);
0814:            }
0815:
0816:            public void setLeftGap(int lg) {
0817:                leftGap = (int) ((double) lg / getScale());
0818:            }
0819:
0820:            public int getRightGap() {
0821:                return (int) (getScale() * rightGap);
0822:            }
0823:
0824:            public void setRightGap(int rg) {
0825:                rightGap = (int) ((double) rg / getScale());
0826:            }
0827:
0828:            public int getTopGap() {
0829:                return (int) (getScale() * topGap);
0830:            }
0831:
0832:            public void setTopGap(int tg) {
0833:                topGap = (int) ((double) tg / getScale());
0834:            }
0835:
0836:            public int getBottomGap() {
0837:                return (int) (getScale() * bottomGap);
0838:            }
0839:
0840:            public void setBottomGap(int bg) {
0841:                bottomGap = (int) ((double) bg / getScale());
0842:            }
0843:
0844:            public int getContentWidth() {
0845:                return (int) (getScale() * (width - leftGap - rightGap));
0846:            }
0847:
0848:            public int getAbsContentWidth() {
0849:                return (width - leftGap - rightGap);
0850:            }
0851:
0852:            public int getHeaderHeight() {
0853:                return (int) (getScale() * headerHeight);
0854:            }
0855:
0856:            public void setHeaderHeight(int hh) {
0857:                headerHeight = (int) ((double) hh / getScale());
0858:            }
0859:
0860:            public int getHeaderGap() {
0861:                return (int) (getScale() * headerGap);
0862:            }
0863:
0864:            public void setHeaderGap(int hg) {
0865:                headerGap = (int) ((double) hg / getScale());
0866:            }
0867:
0868:            public int getContentHeight() {
0869:                return (int) (getScale() * (height - topGap - headerHeight
0870:                        - headerGap - bottomGap));
0871:            }
0872:
0873:            public int getComponentGap() {
0874:                return (int) (getScale() * componentGap);
0875:            }
0876:
0877:            public void setComponentGap(int cg) {
0878:                componentGap = (int) ((double) cg / getScale());
0879:            }
0880:
0881:            public int getComponentHeight() {
0882:                return (int) (getScale() * componentHeight);
0883:            }
0884:
0885:            public void setComponentHeight(int ch) {
0886:                componentHeight = (int) ((double) ch / getScale());
0887:            }
0888:
0889:            public int getScrollUnitIncrement() {
0890:                return getComponentHeight() + getComponentGap();
0891:            }
0892:
0893:            public Color getBackgroundColor() {
0894:                return backgroundColor;
0895:            }
0896:
0897:            public void setBackgroundColor(Color bc) {
0898:                backgroundColor = bc;
0899:            }
0900:
0901:            public Color getBorderColor() {
0902:                return borderColor;
0903:            }
0904:
0905:            public void setBorderColor(Color bc) {
0906:                borderColor = bc;
0907:            }
0908:
0909:            public int getHeaderFontStyle() {
0910:                return headerFontStyle;
0911:            }
0912:
0913:            public void setHeaderFontStyle(int hfs) {
0914:                headerFontStyle = hfs;
0915:            }
0916:
0917:            public int getHeaderFontSize() {
0918:                return (int) (getScale() * headerFontSize);
0919:            }
0920:
0921:            public void setHeaderFontSize(int hfs) {
0922:                headerFontSize = (int) ((double) hfs / getScale());
0923:            }
0924:
0925:            public String getHeaderFontName() {
0926:                return headerFontName;
0927:            }
0928:
0929:            public void setHeaderFontName(String hfn) {
0930:                headerFontName = hfn;
0931:            }
0932:
0933:            public Color getHeaderFontColor() {
0934:                return headerFontColor;
0935:            }
0936:
0937:            public void setHeaderFontColor(Color hfc) {
0938:                headerFontColor = hfc;
0939:            }
0940:
0941:            public Font getHeaderFont() {
0942:                return new Font(getHeaderFontName(), getHeaderFontStyle(),
0943:                        getHeaderFontSize());
0944:            }
0945:
0946:            public void setStartComp(int sc) {
0947:                startComp = sc;
0948:            }
0949:
0950:            public int getStartComp() {
0951:                return startComp;
0952:            }
0953:
0954:            public Color getArrowButtonBackground() {
0955:                return arrowButtonBackground;
0956:            }
0957:
0958:            public void setArrowButtonBackground(Color c) {
0959:                arrowButtonBackground = c;
0960:            }
0961:
0962:            public Color getArrowButtonBorder() {
0963:                return arrowButtonBorder;
0964:            }
0965:
0966:            public void setArrowButtonBorder(Color c) {
0967:                arrowButtonBorder = c;
0968:            }
0969:
0970:            public int getArrowButtonWidth() {
0971:                return (int) (getScale() * arrowButtonWidth);
0972:            }
0973:
0974:            public void setArrowButtonWidth(int aw) {
0975:                arrowButtonWidth = (int) ((double) aw / getScale());
0976:            }
0977:
0978:            public int getArrowButtonHeight() {
0979:                return (int) (getScale() * arrowButtonHeight);
0980:            }
0981:
0982:            public void setArrowButtonHeight(int ah) {
0983:                arrowButtonHeight = (int) ((double) ah / getScale());
0984:            }
0985:
0986:            public double getArrowButtonY() {
0987:                return arrowButtonY;
0988:            }
0989:
0990:            public void setArrowButtonY(double ay) {
0991:                arrowButtonY = ay;
0992:            }
0993:
0994:            public int getArrowButtonGap() {
0995:                return (int) (getScale() * arrowButtonGap);
0996:            }
0997:
0998:            public void setArrowButtonGap(int bg) {
0999:                arrowButtonGap = (int) ((double) bg / getScale());
1000:            }
1001:
1002:            public int getNumVisComponents() {
1003:                return (int) ((double) getContentHeight() / (getComponentGap() + getComponentHeight()));
1004:            }
1005:
1006:            public int getHeaderFieldWidth() {
1007:                return (int) (getScale() * headerFieldWidth);
1008:            }
1009:
1010:            public void setHeaderFieldWidth(int hfw) {
1011:                headerFieldWidth = (int) ((double) hfw / getScale());
1012:            }
1013:
1014:            public int getHeaderFieldHeight() {
1015:                return (int) (getScale() * headerFieldHeight);
1016:            }
1017:
1018:            public void setHeaderFieldHeight(int hfh) {
1019:                headerFieldHeight = (int) ((double) hfh / getScale());
1020:            }
1021:
1022:            public int getHeaderFieldGap() {
1023:                return (int) (getScale() * headerFieldGap);
1024:            }
1025:
1026:            public void setHeaderFieldGap(int hfg) {
1027:                headerFieldGap = (int) ((double) hfg / getScale());
1028:            }
1029:
1030:            public int getHeaderIdWidth() {
1031:                return (int) (getScale() * headerIdWidth);
1032:            }
1033:
1034:            public void setHeaderIdWidth(int hiw) {
1035:                headerIdWidth = (int) ((double) hiw / getScale());
1036:            }
1037:
1038:            public int getHeaderTargetWidth() {
1039:                return (int) (getScale() * headerTargetWidth);
1040:            }
1041:
1042:            public void setHeaderTargetWidth(int htf) {
1043:                headerTargetWidth = (int) ((double) htf / getScale());
1044:            }
1045:
1046:            public int getHeaderNameWidth() {
1047:                int headerNameWidth = headerFieldWidth - 2 * headerFieldGap
1048:                        - headerIdWidth - headerTargetWidth;
1049:                return (int) (getScale() * headerNameWidth);
1050:            }
1051:
1052:            public int getHeaderFieldArc() {
1053:                return (int) (getScale() * headerFieldArc);
1054:            }
1055:
1056:            public void setHeaderFieldArc(int hfa) {
1057:                headerFieldArc = (int) ((double) hfa / getScale());
1058:            }
1059:
1060:            public int getHeaderTextGap() {
1061:                return (int) (getScale() * headerTextGap);
1062:            }
1063:
1064:            public void setHeaderTextGap(int htg) {
1065:                headerTextGap = (int) ((double) htg / getScale());
1066:            }
1067:
1068:            public Color getHeaderBackground() {
1069:                return (isSelected ? selectedColor : headerFieldBackground);
1070:            }
1071:
1072:            public void setHeaderFieldBackground(Color hfb) {
1073:                headerFieldBackground = hfb;
1074:            }
1075:
1076:            public Color getHeaderFieldBorder() {
1077:                return headerFieldBorder;
1078:            }
1079:
1080:            public void setHeaderFieldBorder(Color hfb) {
1081:                headerFieldBorder = hfb;
1082:            }
1083:
1084:            public Color getSelectedColor() {
1085:                return selectedColor;
1086:            }
1087:
1088:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.