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.ModelUserObject;
036:
037: /* Base class for model selections dialogs */
038:
039: public class BaseModelSelectDialog extends BasePropertiesDialog {
040: public static Dimension HGAP10 = new Dimension(10, 1);
041:
042: protected ArrayList mPanels = new ArrayList();
043: protected ArrayList mModels = 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 BaseModelSelectDialog(String pCaption, JFrame pFrame,
052: ArrayList pModels) {
053: super (pCaption, true, new Dimension(300, 310));
054:
055: mModels = pModels;
056:
057: mClient.setLayout(new BorderLayout());
058: mClient.setBorder(new EmptyBorder(3, 3, 0, 3));
059:
060: mList.setBorder(null);
061: mList.setBackground(SystemColor.window);
062: mList.setLayout(new BoxLayout(mList, BoxLayout.Y_AXIS));
063: mList.add(Box.createRigidArea(HGAP10));
064:
065: for (int i = 0; i < pModels.size(); i++)
066: createCheckBox((ModelUserObject) pModels.get(i));
067:
068: mClient.add(new JScrollPane(mList), BorderLayout.CENTER);
069: mClient.add(mToolBar, BorderLayout.SOUTH);
070:
071: mToolBar.setBorder(null);
072: mToolBar.add(Application.createButton(mCheckAllAction));
073: mToolBar.add(Application.createButton(mUnCheckAllAction));
074: }
075:
076: public void ok() {
077: for (int i = 0; i < mPanels.size(); i++) {
078: PanelItem lItem = (PanelItem) mPanels.get(i);
079: if (!lItem.getCheckBox().isSelected())
080: mModels.remove(lItem.mModel);
081: }
082: super .ok();
083: }
084:
085: // create and add cheack box
086: protected void createCheckBox(ModelUserObject pModel) {
087: PanelItem lItem = new PanelItem(pModel);
088: mList.add(lItem.getCheckBox());
089: mPanels.add(lItem);
090: }
091:
092: // check all items
093: protected void checkAll(boolean pCheck) {
094: for (int i = 0; i < mPanels.size(); i++) {
095: PanelItem lItem = (PanelItem) mPanels.get(i);
096: lItem.getCheckBox().setSelected(pCheck);
097: }
098: }
099:
100: /* Auxilary classes */
101:
102: public class PanelItem {
103: private ModelUserObject mModel = null;
104: private JCheckBox mCheckBox = null;
105:
106: public PanelItem(ModelUserObject pModel) {
107: mModel = pModel;
108: if (mModel != null)
109: mCheckBox = new JCheckBox(mModel.getModelName());
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 ModelUserObject getPanel() {
120: return mModel;
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: }
|