001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.ui.swing.drawingarea;
043:
044: import java.awt.event.KeyEvent;
045: import java.awt.Font;
046: import java.awt.Frame;
047: import java.awt.event.ActionEvent;
048: import javax.swing.JComponent;
049: import javax.swing.KeyStroke;
050: import javax.swing.AbstractAction;
051: import javax.swing.Action;
052: import org.netbeans.modules.uml.common.ETSystem;
053: import com.tomsawyer.editor.TSEGraph;
054: import com.tomsawyer.editor.TSEGraphWindow;
055: import com.tomsawyer.editor.service.layout.jlayout.TSELayoutPropertiesDialog;
056: import com.tomsawyer.editor.service.layout.properties.TSETabComponent;
057: import com.tomsawyer.service.client.TSServiceProxy;
058: import com.tomsawyer.editor.service.TSEAllOptionsServiceInputData;
059: import com.tomsawyer.editor.TSEResourceBundleWrapper;
060: import com.tomsawyer.editor.service.layout.jlayout.AccessiblityUtils;
061:
062: /**
063: * @author KevinM
064: *
065: */
066: public class ETLayoutPropertiesDialog extends TSELayoutPropertiesDialog
067: implements IETSecondaryWindow {
068: private boolean hasBeenVisible = false;
069: private static TSEResourceBundleWrapper tsResBundle = TSEResourceBundleWrapper
070: .getSystemLabelBundle();
071:
072: //public ETLayoutPropertiesDialog(Frame arg0, String arg1, TSEGraphWindow arg2, TSLayoutServer arg3)
073: public ETLayoutPropertiesDialog(Frame arg0, String arg1,
074: TSEGraphWindow arg2, TSServiceProxy arg3,
075: TSEAllOptionsServiceInputData inputData) {
076: super (arg0, arg1, arg2, arg3, inputData);
077: if (arg3 == null) {
078: ETSystem.out
079: .println("null layout Server passed to the layout properties dialog.");
080: }
081: }
082:
083: //public ETLayoutPropertiesDialog(Frame arg0, String arg1, TSEGraphWindow arg2, TSLayoutServer arg3, Class arg4)
084: public ETLayoutPropertiesDialog(Frame arg0, String arg1,
085: TSEGraphWindow arg2, TSServiceProxy arg3,
086: TSEAllOptionsServiceInputData inputData, Class arg4) {
087: super (arg0, arg1, arg2, arg3, inputData, arg4);
088: }
089:
090: //public ETLayoutPropertiesDialog(Frame arg0, String arg1, TSEGraphWindow arg2, TSLayoutServer arg3, int arg4)
091: public ETLayoutPropertiesDialog(Frame arg0, String arg1,
092: TSEGraphWindow arg2, TSServiceProxy arg3,
093: TSEAllOptionsServiceInputData inputData, int arg4) {
094: super (arg0, arg1, arg2, arg3, inputData, arg4);
095: }
096:
097: /*
098: //public ETLayoutPropertiesDialog(Frame arg0, String arg1, TSEGraphWindow arg2, TSLayoutServer arg3, Class arg4, int arg5)
099: public ETLayoutPropertiesDialog(Frame arg0, String arg1, TSEGraphWindow arg2, TSServiceProxy arg3, TSEAllOptionsServiceInputData inputData, Class arg4, int arg5)
100: {
101: super(arg0, arg1, arg2, arg3, inputData, arg4, arg5);
102: }
103: */
104:
105: protected void init() {
106: super .init();
107: setA11yFeatures();
108: }
109:
110: /* (non-Javadoc)
111: * @see com.tomsawyer.editor.layout.TSELayoutPropertiesDialog#onLayout()
112: */
113: public void onLayout() {
114: IDrawingAreaControl drawingArea = getDrawingArea();
115: if (drawingArea != null) {
116: // Copy the info into the layout server.
117: setLayoutStyleFromTab();
118: onApply();
119:
120: // Use the DrawingArea Layout command to dispatch the layout command.
121: drawingArea.setLayoutStyle(drawingArea.getLayoutStyle());
122: } else {
123: // No drawing area use the super class.
124: super .onLayout();
125: }
126: }
127:
128: /*
129: * Returns the Currently showing tab.
130: */
131: public TSETabComponent getActiveTab() {
132: TSETabComponent[] tabs = this .getTabs();
133: for (int i = 0; i < this .getNumberOfTabs(); i++) {
134: TSETabComponent pTab = tabs[i];
135: if (pTab != null && pTab.isShowing()) {
136: return pTab;
137: }
138: }
139: return null;
140: }
141:
142: /*
143: * Returns the Layout Style of the currently showing tab as a string.
144: */
145: public int getActiveLayoutStyle() {
146: //String layoutStyle = null;
147: int layoutStyle = -1;
148:
149: TSETabComponent pActiveTab = getActiveTab();
150: if (pActiveTab != null)
151: layoutStyle = pActiveTab.getLayoutStyle();
152:
153: //if (layoutStyle == null || layoutStyle.length() == 0)
154: if (layoutStyle == -1) {
155: // Keep the current layout style.
156: //layoutStyle = getGraphWindow().getGraph().getLayoutStyle();
157: }
158: return layoutStyle;
159: }
160:
161: /*
162: * Sets the graph windows active graph's layout style equal to the current tab style..
163: */
164: protected void setLayoutStyleFromTab() {
165: //getGraphWindow().getGraph().setLayoutStyle(getActiveLayoutStyle());
166:
167: //set this thru serviceInputDataObject... as layoutoptions cannot be set on node/edge/graph itself in TS6.0
168: }
169:
170: /*
171: * Returns the DrawingArea Control
172: */
173: protected IDrawingAreaControl getDrawingArea() {
174: ADGraphWindow graphWindow = getGraphWindow() instanceof ADGraphWindow ? (ADGraphWindow) getGraphWindow()
175: : null;
176: return graphWindow != null ? graphWindow.getDrawingArea()
177: : null;
178: }
179:
180: /*
181: * (non-Javadoc)
182: * @see java.awt.Component#setVisible(boolean)
183: */
184: public void setVisible(boolean bShow) {
185: super .setVisible(bShow);
186: if (hasBeenVisible == false && bShow) {
187: // There is a bug the bottom the layout props dlg is grey the first time its shown.
188: super .setVisible(false);
189: super .setVisible(true);
190: hasBeenVisible = true;
191: }
192: }
193:
194: public void setA11yFeatures() {
195: // Set mnemonics
196: okButton.setMnemonic(AccessiblityUtils.getMnemonic("OK"));
197: cancelButton.setMnemonic(AccessiblityUtils
198: .getMnemonic("Cancel"));
199: applyButton.setMnemonic(AccessiblityUtils.getMnemonic("Apply"));
200: layoutButton.setMnemonic(AccessiblityUtils
201: .getMnemonic("Layout"));
202: resetButton.setMnemonic(AccessiblityUtils.getMnemonic("Reset"));
203: defaultsButton.setMnemonic(AccessiblityUtils
204: .getMnemonic("Defaults"));
205:
206: // set accessibility name and descritpion
207: AccessiblityUtils.setAccessibleProperties(okButton, null, "OK");
208: AccessiblityUtils.setAccessibleProperties(cancelButton, null,
209: "Cancel");
210: AccessiblityUtils.setAccessibleProperties(applyButton, null,
211: "Apply");
212: AccessiblityUtils.setAccessibleProperties(layoutButton, null,
213: "Layout");
214: AccessiblityUtils.setAccessibleProperties(resetButton, null,
215: "Reset");
216: AccessiblityUtils.setAccessibleProperties(defaultsButton, null,
217: "Defaults");
218:
219: // set accessible description for the dialog itself
220: this .getAccessibleContext().setAccessibleDescription(
221: this .getTitle());
222: tabbedPane.getAccessibleContext().setAccessibleDescription("");
223:
224: // set the font of tabbed to whatever font used for the tabbed panel
225: TSETabComponent selTab = (TSETabComponent) tabbedPane
226: .getSelectedComponent();
227: Font defaultFont = selTab.getFont();
228: if (defaultFont != null) {
229: System.out.println("ETLayout: one of the tab's font="
230: + defaultFont);
231: tabbedPane.setFont(defaultFont);
232: }
233:
234: // set OK button the default button
235: this .getRootPane().setDefaultButton(this .okButton);
236:
237: //Map hte ESC key to the action of closing the dailog.
238: Action escapeAction = new AbstractAction() {
239: public void actionPerformed(ActionEvent e) {
240: dispose();
241: }
242: };
243: getRootPane().getInputMap(
244: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
245: .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
246: "ESCAPE");
247: getRootPane().getActionMap().put("ESCAPE", escapeAction);
248:
249: }
250:
251: // protected TSETabComponent createAppropriateTab(String tabName)
252: // {
253: // ETSystem.out.println("Creating Layout properties Tab " + tabName);
254: // if (tabName.endsWith("TSESymmetricTab"))
255: // {
256: // try
257: // {
258: // return new ADSymmetricTab(getGraph(), inputData, this);
259: // }
260: // catch (RuntimeException e)
261: // {
262: // return null;
263: // }
264: // }
265: // else if (tabName.endsWith("TSECircularTab"))
266: // {
267: // // We don't want to show this guy, until Pure Java 6.5.
268: // return null;
269: // }
270: // else if (tabName.endsWith("TSEDisconnectedTab"))
271: // {
272: // try
273: // {
274: // return new ADDisconnectedTab(getGraph(), inputData, this);
275: // }
276: // catch (RuntimeException e)
277: // {
278: // return null;
279: // }
280: // }
281: // else if (tabName.endsWith("TSEGeneralTab"))
282: // {
283: // try
284: // {
285: // return new ADGeneralTab(getGraph(), inputData, this);
286: // }
287: // catch (RuntimeException e)
288: // {
289: // return null;
290: // }
291: // }
292: // else if (tabName.endsWith("TSEHierarchicalTab"))
293: // {
294: // try
295: // {
296: // return new ADHierarchicalTab(getGraph(), inputData, this);
297: // }
298: // catch (RuntimeException e)
299: // {
300: // return null;
301: // }
302: // }
303: // else if (tabName.endsWith("TSEOrthogonalTab"))
304: // {
305: // try
306: // {
307: // return new ADOrthogonalTab(getGraph(), inputData, this);
308: // }
309: // catch (RuntimeException e)
310: // {
311: // return null;
312: // }
313: // }
314: // /* no tree in 6.0
315: // else if (tabName.endsWith("TSETreeTab"))
316: // {
317: // try
318: // {
319: // return new ADTreeTab(getGraph(), inputData, this);
320: // }
321: // catch (RuntimeException e)
322: // {
323: // return null;
324: // }
325: // }
326: // */
327: //
328: // return super.createAppropriateTab(tabName);
329: // }
330:
331: /* (non-Javadoc)
332: * @see com.tomsawyer.editor.layout.TSELayoutPropertiesDialog#getGraph()
333: */
334: public TSEGraph getGraph() {
335: TSEGraph theGraph = super .getGraph();
336: if (theGraph == null && getDrawingArea() != null) {
337: TSEGraphWindow window = getDrawingArea().getGraphWindow();
338: if (window != null) {
339: theGraph = window.getGraph();
340: }
341: }
342: return theGraph;
343: }
344:
345: /* (non-Javadoc)
346: * @see java.awt.Component#show()
347: */
348: @SuppressWarnings("deprecation")
349: // TODO: change to setVisible(boolean)?
350: public void show() {
351: super .show();
352:
353: // Hide the help button.
354: hideHelpButton();
355: }
356:
357: /*
358: * Hides the help button if its visible.
359: */
360: protected void hideHelpButton() {/* jyothi
361: // Hide the help button until we have help.
362: if (helpButton != null && helpButton.isVisible())
363: {
364: helpButton.setVisible(false);
365: }
366: */
367: }
368:
369: //jyothi
370: public void setGraphWindow(TSEGraphWindow graphWindow) {
371: // written to remove compilation error.. need to do more work..
372: }
373:
374: // The following methods are provided by TomSawyer as a workaround
375: // to fix the issue of not being able to localize the tab names
376: /**
377: * This method creates the tab object of the specified tab name.
378: * If such a class does not exist, this method returns null.
379: */
380: protected TSETabComponent createAppropriateTab(String tabName) {
381: TSETabComponent tabComponent = null;
382:
383: if (tabName.equals(tsResBundle.getStringSafely("General"))) { // NOI18N
384: tabComponent = new com.tomsawyer.editor.service.layout.jlayout.TSEGeneralTabExt(
385: this .getGraph(), this .inputData, this );
386:
387: } else if (tabName.equals(tsResBundle
388: .getStringSafely("Disconnected"))) { // NOI18N
389: tabComponent = new com.tomsawyer.editor.service.layout.jlayout.TSEDisconnectedTabExt(
390: this .getGraph(), this .inputData, this );
391:
392: } else if (tabName.equals(tsResBundle
393: .getStringSafely("Hierarchical"))) { // NOI18N
394: tabComponent = new com.tomsawyer.editor.service.layout.jlayout.TSEHierarchicalTabExt(
395: this .getGraph(), this .inputData, this );
396:
397: } else if (tabName.equals(tsResBundle
398: .getStringSafely("Orthogonal"))) { // NOI18N
399: tabComponent = new com.tomsawyer.editor.service.layout.jlayout.TSEOrthogonalTabExt(
400: this .getGraph(), this .inputData, this );
401:
402: } else if (tabName.equals(tsResBundle
403: .getStringSafely("Symmetric"))) { // NOI18N
404: tabComponent = new com.tomsawyer.editor.service.layout.jlayout.TSESymmetricTabExt(
405: this .getGraph(), this .inputData, this );
406:
407: } else if (tabName.equals(tsResBundle
408: .getStringSafely("Routing"))) { // NOI18N
409: tabComponent = new com.tomsawyer.editor.service.layout.jlayout.TSERoutingTabExt(
410: this .getGraph(), this .inputData, this );
411: }
412:
413: return tabComponent;
414:
415: }
416:
417: /**
418: * This method returns the names of the tabs.
419: */
420: protected String[] getTabNames() {
421: return internationalizedTabNames;
422: }
423:
424: static String[] internationalizedTabNames = {
425: tsResBundle.getStringSafely("General"), // NOI18N
426: tsResBundle.getStringSafely("Disconnected"), // NOI18N
427: tsResBundle.getStringSafely("Hierarchical"), // NOI18N
428: tsResBundle.getStringSafely("Orthogonal"), // NOI18N
429: tsResBundle.getStringSafely("Symmetric"), // NOI18N
430: tsResBundle.getStringSafely("Routing") // NOI18N
431: };
432:
433: }
|