001: //THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: //CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: //BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: //OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: //LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: //EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: //POSSIBILITY OF SUCH DAMAGE.
013: //
014: //Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.auxilarydialogs;
016:
017: import java.awt.BorderLayout;
018: import java.awt.Dimension;
019: import java.awt.SystemColor;
020: import java.awt.event.ActionEvent;
021: import java.util.ArrayList;
022:
023: import javax.swing.Box;
024: import javax.swing.BoxLayout;
025: import javax.swing.JCheckBox;
026: import javax.swing.JFrame;
027: import javax.swing.JPanel;
028: import javax.swing.JScrollPane;
029: import javax.swing.JToolBar;
030: import javax.swing.border.EmptyBorder;
031:
032: import com.metaboss.applications.designstudio.Application;
033: import com.metaboss.applications.designstudio.BaseAction;
034: import com.metaboss.applications.designstudio.BasePropertiesDialog;
035: import com.metaboss.applications.designstudio.userobjects.DiagramUserObject;
036:
037: /* Select Diagram dialog class */
038:
039: public class DiagramSelectDialog extends BasePropertiesDialog {
040: public static Dimension HGAP10 = new Dimension(10, 1);
041:
042: protected ArrayList mPanels = new ArrayList();
043: protected ArrayList mDiagrams = null;
044: // ui
045: protected JToolBar mToolBar = new JToolBar();
046: protected JPanel mList = new JPanel();
047: // actions
048: protected CheckAllAction mCheckAllAction = new CheckAllAction();
049: protected UnCheckAllAction mUnCheckAllAction = new UnCheckAllAction();
050:
051: public DiagramSelectDialog(JFrame pFrame, ArrayList pDiagrams) {
052: super ("Select Diagram", true, new Dimension(300, 310));
053:
054: mDiagrams = pDiagrams;
055:
056: mClient.setLayout(new BorderLayout());
057: mClient.setBorder(new EmptyBorder(3, 3, 0, 3));
058:
059: mList.setBorder(null);
060: mList.setBackground(SystemColor.window);
061: mList.setLayout(new BoxLayout(mList, BoxLayout.Y_AXIS));
062: mList.add(Box.createRigidArea(HGAP10));
063:
064: for (int i = 0; i < pDiagrams.size(); i++)
065: createCheckBox((DiagramUserObject) pDiagrams.get(i));
066:
067: mClient.add(new JScrollPane(mList), BorderLayout.CENTER);
068: mClient.add(mToolBar, BorderLayout.SOUTH);
069:
070: mToolBar.setBorder(null);
071: mToolBar.add(Application.createButton(mCheckAllAction));
072: mToolBar.add(Application.createButton(mUnCheckAllAction));
073: }
074:
075: public void ok() {
076: for (int i = 0; i < mPanels.size(); i++) {
077: PanelItem lItem = (PanelItem) mPanels.get(i);
078: if (!lItem.getCheckBox().isSelected())
079: mDiagrams.remove(lItem.mDiagram);
080: }
081: super .ok();
082: }
083:
084: // create and add cheack box
085: protected void createCheckBox(DiagramUserObject pModel) {
086: PanelItem lItem = new PanelItem(pModel);
087: mList.add(lItem.getCheckBox());
088: mPanels.add(lItem);
089: }
090:
091: // check all items
092: protected void checkAll(boolean pCheck) {
093: for (int i = 0; i < mPanels.size(); i++) {
094: PanelItem lItem = (PanelItem) mPanels.get(i);
095: lItem.getCheckBox().setSelected(pCheck);
096: }
097: }
098:
099: /* Auxilary classes */
100:
101: public class PanelItem {
102: private DiagramUserObject mDiagram = null;
103: private JCheckBox mCheckBox = null;
104:
105: public PanelItem(DiagramUserObject pDiagram) {
106: mDiagram = pDiagram;
107: if (mDiagram != null && mDiagram.getDiagram() != null)
108: mCheckBox = new JCheckBox(mDiagram.getDiagram()
109: .getName());
110: else
111: mCheckBox = new JCheckBox("test");
112: mCheckBox.setBackground(SystemColor.window);
113: }
114:
115: public JCheckBox getCheckBox() {
116: return mCheckBox;
117: }
118:
119: public DiagramUserObject getPanel() {
120: return mDiagram;
121: }
122: }
123:
124: /* Actions */
125:
126: public class CheckAllAction extends BaseAction {
127: public CheckAllAction() {
128: super ("Check All", Application.CHECK_ICON);
129: }
130:
131: public void actionPerformed(ActionEvent arg0) {
132: checkAll(true);
133: }
134: }
135:
136: public class UnCheckAllAction extends BaseAction {
137: public UnCheckAllAction() {
138: super ("Uncheck All", Application.UNCHECK_ICON);
139: }
140:
141: public void actionPerformed(ActionEvent arg0) {
142: checkAll(false);
143: }
144: }
145: }
|