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.util.*;
018: import java.awt.BorderLayout;
019: import java.awt.Dimension;
020:
021: import javax.swing.JCheckBox;
022: import javax.swing.JComboBox;
023: import javax.swing.JFrame;
024: import javax.swing.JPanel;
025: import javax.swing.JSpinner;
026: import javax.swing.JTabbedPane;
027: import javax.swing.SpinnerNumberModel;
028:
029: import com.metaboss.applications.designstudio.Application;
030: import com.metaboss.applications.designstudio.BasePropertiesDialog;
031: import com.metaboss.applications.designstudio.components.Rule;
032: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
033:
034: /* Application Options dialog */
035:
036: public class OptionsDialog extends BasePropertiesDialog {
037: private JTabbedPane mTabControl = new JTabbedPane();
038: private JPanel mPropertiesPanel = new JPanel();
039: private JPanel mDiagramPanel = new JPanel();
040: //properties
041: private JCheckBox mAutoValidateCheckBox = new JCheckBox();
042: private JCheckBox mValidateOnSaveCheckBox = new JCheckBox();
043: //private JComboBox mTabRegimeField = new JComboBox();
044: //diagram
045: private JSpinner mGridSizeField = new JSpinner(
046: new SpinnerNumberModel(1, 1, 100, 1));
047: private JComboBox mGridMesureBox = new JComboBox();
048: private JCheckBox mShowGridCheckBox = new JCheckBox();
049: private JCheckBox mUseGridCheckBox = new JCheckBox();
050: private JCheckBox mPortsVisibleCheckBox = new JCheckBox();
051: private JCheckBox mShowToolTipsCheckBox = new JCheckBox();
052: private JCheckBox mShowRulerCheckBox = new JCheckBox();
053: private JCheckBox mShowEdgesLabelsCheckBox = new JCheckBox();
054: private JCheckBox mShowEdgesCardinalityCheckBox = new JCheckBox();
055: private JCheckBox mShowEdgesEndsCheckBox = new JCheckBox();
056:
057: public OptionsDialog(JFrame pFrame) throws Exception {
058: super ("Options", true, new Dimension(470, 370));
059:
060: mClient.setLayout(new BorderLayout());
061: mButtonBar.setBorder(null);
062:
063: mPropertiesPanel.setLayout(mClientGridBagLayout);
064: mDiagramPanel.setLayout(mClientGridBagLayout);
065:
066: mCaptionLabel.setText("Metaboss Development Studio Options");
067:
068: // properties
069: addCheckBox(mPropertiesPanel, "- automatically validate model",
070: mAutoValidateCheckBox, 1, false);
071: addCheckBox(mPropertiesPanel,
072: "- validate models before saving",
073: mValidateOnSaveCheckBox, 2, false);
074: //addComboBox(mPropertiesPanel, "Close Buttons Regime: ", mTabRegimeField, 3);
075: // diagram
076: addSpinner(mDiagramPanel, "Grid Size: ", mGridSizeField, 1, 33,
077: false);
078: addShortComboBox(mDiagramPanel, "Grid Measurment: ",
079: mGridMesureBox, 2, 40, false);
080: addCheckBox(mDiagramPanel, "- show grid", mShowGridCheckBox, 3,
081: false);
082: addCheckBox(mDiagramPanel, "- use grid", mUseGridCheckBox, 4,
083: false);
084: addCheckBox(mDiagramPanel, "- ports visible",
085: mPortsVisibleCheckBox, 5, false);
086: addCheckBox(mDiagramPanel, "- show tooltips",
087: mShowToolTipsCheckBox, 6, false);
088: addCheckBox(mDiagramPanel, "- show ruler", mShowRulerCheckBox,
089: 7, false);
090: addCheckBox(mDiagramPanel, "- show edges captions",
091: mShowEdgesLabelsCheckBox, 8, false);
092: addCheckBox(mDiagramPanel, "- show edges cardinality",
093: mShowEdgesCardinalityCheckBox, 9, false);
094: addCheckBox(mDiagramPanel, "- show edges ends names",
095: mShowEdgesEndsCheckBox, 10, false);
096:
097: mTabControl.addTab("Properties", mPropertiesPanel);
098: mTabControl.addTab("Diagram", mDiagramPanel);
099: mTabControl.setBorder(null);
100: mTabControl.setFont(Application.DEFAULT_FONT);
101: mClient.add(mTabControl);
102:
103: //fillBoxWithTabPanelRegimes(mTabRegimeField);
104: fillBoxWithRulerModes(mGridMesureBox);
105:
106: loadProperties();
107: setVisible(true);
108: }
109:
110: public void loadProperties() {
111: mAutoValidateCheckBox
112: .setSelected(Application.properties.mAutoValidateModel);
113: mValidateOnSaveCheckBox
114: .setSelected(Application.properties.mValidateModelOnSave);
115: //mTabRegimeField.setSelectedIndex(findRegimeItemIndex(Application.properties.mCloseButtonRegime));
116:
117: mGridSizeField.setValue(new Integer(
118: Application.properties.mGridSize));
119: //mGridSizeField.setText(new Integer(Application.properties.mGridSize).toString());
120: mGridMesureBox
121: .setSelectedIndex(findRuleModeIndex(Application.properties.mRulerMode));
122: mShowGridCheckBox.setSelected(Application.properties.mShowGrid);
123: mUseGridCheckBox.setSelected(Application.properties.mUseGrid);
124: mPortsVisibleCheckBox
125: .setSelected(Application.properties.mPortsVisible);
126: mShowToolTipsCheckBox
127: .setSelected(Application.properties.mShowToolTip);
128: mShowRulerCheckBox
129: .setSelected(Application.properties.mShowRuler);
130: mShowEdgesLabelsCheckBox
131: .setSelected(Application.properties.mShowEdgesLabels);
132: mShowEdgesCardinalityCheckBox
133: .setSelected(Application.properties.mShowEdgesCardinality);
134: mShowEdgesEndsCheckBox
135: .setSelected(Application.properties.mShowEdgesEndsNames);
136: }
137:
138: // save service module proeprties
139: public void saveProperties(ModelElement pObject) throws Exception {
140: Application.properties.mAutoValidateModel = mAutoValidateCheckBox
141: .isSelected();
142: Application.properties.mValidateModelOnSave = mValidateOnSaveCheckBox
143: .isSelected();
144: //Application.properties.mCloseButtonRegime = ((TabPanelRegimeItem)mTabRegimeField.getSelectedItem()).mRegime;
145:
146: Application.properties.mGridSize = ((Integer) mGridSizeField
147: .getValue()).intValue();
148: Application.properties.mRulerMode = ((RulerModeItem) mGridMesureBox
149: .getSelectedItem()).mMode;
150: Application.properties.mShowGrid = mShowGridCheckBox
151: .isSelected();
152: Application.properties.mUseGrid = mUseGridCheckBox.isSelected();
153: Application.properties.mPortsVisible = mPortsVisibleCheckBox
154: .isSelected();
155: Application.properties.mShowToolTip = mShowToolTipsCheckBox
156: .isSelected();
157: Application.properties.mShowRuler = mShowRulerCheckBox
158: .isSelected();
159: Application.properties.mShowEdgesLabels = mShowEdgesLabelsCheckBox
160: .isSelected();
161: Application.properties.mShowEdgesCardinality = mShowEdgesCardinalityCheckBox
162: .isSelected();
163: Application.properties.mShowEdgesEndsNames = mShowEdgesEndsCheckBox
164: .isSelected();
165:
166: Application.fireOptionsChanged(false);
167: }
168:
169: public void ok() {
170: if (checkProperties()) {
171: setVisible(false);
172: try {
173: saveProperties(null);
174: } catch (Exception e) {
175: e.printStackTrace();
176: }
177: mModalResult = MR_OK;
178: }
179: }
180:
181: // check fields data
182: public boolean checkProperties() {
183: boolean lResult = true;
184: /*try
185: {
186: Integer.parseInt(mGridSizeField.getText());
187: }
188: catch(Exception e)
189: {
190: Application.showError(e.getMessage());
191: lResult = false;
192: }*/
193: return lResult;
194: }
195:
196: // check Metaboss directory changed
197: private boolean checkChanged(String pOldDir, String pNewDir) {
198: boolean lResult = (pOldDir == null && pNewDir != null)
199: || (pOldDir != null && pNewDir == null)
200: || (!pOldDir.equals(pNewDir));
201: return lResult;
202: }
203:
204: //fill combobox with tabpanel regimes
205: private void fillBoxWithRulerModes(JComboBox pBox) {
206: pBox.removeAllItems();
207: pBox.addItem(new RulerModeItem(Rule.RM_INCH));
208: pBox.addItem(new RulerModeItem(Rule.RM_METRIC));
209: pBox.addItem(new RulerModeItem(Rule.RM_PIXEL));
210: }
211:
212: // find rule mode index
213: private int findRuleModeIndex(int pMode) {
214: for (int i = 0; i < mGridMesureBox.getItemCount(); i++) {
215: RulerModeItem lItem = (RulerModeItem) mGridMesureBox
216: .getItemAt(i);
217: if (lItem.mMode == pMode)
218: return i;
219: }
220: return -1;
221: }
222:
223: //fill combobox with tabpanel regimes
224: /*private void fillBoxWithTabPanelRegimes(JComboBox pBox)
225: {
226: pBox.removeAllItems();
227: pBox.addItem(new TabPanelRegimeItem(TabPanel.CB_INVISIBLE));
228: pBox.addItem(new TabPanelRegimeItem(TabPanel.CB_VISIBLE));
229: pBox.addItem(new TabPanelRegimeItem(TabPanel.CB_FLOATING));
230: pBox.addItem(new TabPanelRegimeItem(TabPanel.CB_ONEFORALL));
231: }*/
232:
233: // find message type index
234: /*private int findRegimeItemIndex(int pRegime)
235: {
236: for (int i=0; i<mTabRegimeField.getItemCount(); i++)
237: {
238: TabPanelRegimeItem lItem = (TabPanelRegimeItem)mTabRegimeField.getItemAt(i);
239: if (lItem.mRegime==pRegime) return i;
240: }
241: return -1;
242: }*/
243:
244: /* TabPanel regimes combobox item class */
245:
246: /*public class TabPanelRegimeItem
247: {
248: public int mRegime = TabPanel.CB_VISIBLE;
249:
250: public TabPanelRegimeItem(int pRegime)
251: {
252: mRegime = pRegime;
253: }
254:
255: public String toString()
256: {
257: return TabPanel.regimeToString(mRegime);
258: }
259: }*/
260:
261: /* Ruler Mode combobox item class */
262:
263: public class RulerModeItem {
264: public int mMode = Rule.RM_PIXEL;
265:
266: public RulerModeItem(int pMode) {
267: mMode = pMode;
268: }
269:
270: public String toString() {
271: return Rule.modeToStr(mMode);
272: }
273: }
274: }
|