`
txf2004
  • 浏览: 7040451 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Creating a New Window Group

阅读更多

In the IDE, when you're involved in GUI editing, several helper windows open together with the Design mode of the editor. For example, when you open a TopComponent in Design mode, the Palette and the Properties window open too. However, if you had previously opened the TopComponent in Design mode and closed the Palette, the Palette isn't opened when next you open the TopComponent. Basically, the helper windows (i.e., in this case, the Palette and Properties window) are only open if you had them open previously, on the assumption that their previous open/closed state are the ones you would like to maintain.

If you had to code that for all your windows, it would be something like this in pseudo code:

if (TopComponentA is opened) {
if (HelperTopComponentB was open previously and is now closed) {
HelperTopComponentB must open again
}
if (HelperTopComponentC was open previously and is now closed) {
HelperTopComponentC must open again
}
}

That would be a lot of cumbersome work, since the above is only for the opening of the TopComponent; there'd have to be something similar for closing the TopComponent. Wouldn't it be cool if I could create a group of components and then simply do this:

group.open();

And, then, later, when I close a TopComponent, I would simply call this:

group.close();

Then, all the opened and closed helper windows would be saved in whatever state they're in, automatically, without me having to think about it. Now, that would be cool. Hmmm... I think I should create an issue in Issuezilla for this. Okay, let's do that. Oops. Wait. Section 2.3 of the "New Window System API Changes" is titled "Window Groups". That's, in fact, exactly what I was looking for... So, three cheers for Interface TopComponentGroup .

So, if you go to config/Windows2Local in your user directory, you should see (after closing the IDE at least once) the following:

In the previous two blog entries, I wrote about the "Modes" folder above. The first blog entry was about creating a new mode. The second was about two modes sharing the 'editor' area of the IDE (or of another application based on the NetBeans Platform). This time, let's look at the "Groups" folder. If you open the "Groups" folder, one of the subfolders is called "debugger". It contains files for 9 TopComponents, which are all opened at the same time when a debug process begins and closed at the same time when it ends.

Let's create our own group, add two TopComponents, and then open the TopComponents simultaneously.

  1. Create a new module project, with org.netbeans.modules.windowgroupsample as the code name base.
  2. Use the Window Component wizard twice, to create two TopComponents. In the first page of the wizard, choose "editor" for the first and "output" for the second (or anything else, it really doesn't matter). Make sure that you don't select the checkbox, so that the TopComponent won't be shown at start up. Let's say the first is called "OneTopComponent" and the second "TwoTopComponent" (which means you should type "One" and "Two" as the prefix in the wizard) and we'll put them both in the main package.
  3. Now we're going to create the window group. Right-click the top package, create a new XML document called "MyGroupWsgrp.xml", within a new subpackage called "groups". Add a subpackage to the new group and call that subpackage "MyGroup". Inside of it, create two XML documents, one called "OneTopComponentWstcgrp.xml" and the other "TwoTopComponentWstcgrp.xml". You should now see this in the Projects window:

  4. Next, put this in "MyGroupWsgrp.xml":
    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE group PUBLIC
    "-//NetBeans//DTD Group Properties 2.0//EN"
    "http://www.netbeans.org/dtds/group-properties2_0.dtd">

    <group version="2.0">
    <module name="org.netbeans.modules.windowgroupsample" spec="1.0" />
    <name unique="MyGroup" />
    <state opened="false" />
    </group>

    Note: The value of the state element above specifies that the group will be closed, by default, when the application starts up.

  5. In "OneTopComponentWstcgrp.xml", change the content to this:
    <?xml version="1.0" encoding="UTF-8" ?>

    <!DOCTYPE tc-group PUBLIC
    "-//NetBeans//DTD Top Component in Group Properties 2.0//EN"
    "http://www.netbeans.org/dtds/tc-group2_0.dtd">

    <tc-group version="2.0">
    <module name="org.netbeans.modules.windowgroupsample" spec="1.0"/>
    <tc-id id="OneTopComponent" />
    <open-close-behavior open="true" close="true" />
    </tc-group>

    Note 1: The value of the tc-id element must match the value of the PREFERRED_ID String that was generated in your TopComponent, when you finished the Window Component wizard. Have a look, and notice that the two match.

    Note 2: The values of the open-close-behavior element are the flags that indicate what will happen when group.open() and group.close() are called. For example, if the open attribute is set to "true", then by default the TopComponent will open when the group opens.

    Similar to the above, change the content of "TwoTopComponentWstcgrp.xml" to this:

    <?xml version="1.0" encoding="UTF-8" ?>

    <!DOCTYPE tc-group PUBLIC
    "-//NetBeans//DTD Top Component in Group Properties 2.0//EN"
    "http://www.netbeans.org/dtds/tc-group2_0.dtd">

    <tc-group version="2.0">
    <module name="org.netbeans.modules.windowgroupsample" spec="1.0"/>
    <tc-id id="TwoTopComponent" />
    <open-close-behavior open="true" close="true" />
    </tc-group>
  6. Now we will register our new group in the XML Layer. Open the XML Layer and notice the Windows2 section at the end (all generated when you created your two TopComponents). Add the highlighted section below, to register our new group:
    <folder name="Windows2">
    <folder name="Components">
    <file name="OneTopComponent.settings" url="OneTopComponentSettings.xml"/>
    <file name="TwoTopComponent.settings" url="TwoTopComponentSettings.xml"/>
    </folder>
    <folder name="Modes">
    <folder name="editor">
    <file name="OneTopComponent.wstcref" url="OneTopComponentWstcref.xml"/>
    </folder>
    <folder name="output">
    <file name="TwoTopComponent.wstcref" url="TwoTopComponentWstcref.xml"/>
    </folder>
    </folder>
    <folder name="Groups">
    <file name="MyGroup.wsgrp" url="groups/MyGroupWsgrp.xml"/>
    <folder name="MyGroup">
    <file name="OneTopComponent.wstcgrp" url="groups/MyGroup/OneTopComponentWstcgrp.xml"/>
    <file name="TwoTopComponent.wstcgrp" url="groups/MyGroup/TwoTopComponentWstcgrp.xml"/>
    </folder>
    </folder>

    </folder>
  7. Save everything. Don't install the module yet, let's first refresh all our window positions to their defaults (just in case you've moved things around and things go wrong later, best to have everything at their defaults so that we can analyze the situation better). Close the IDE. Go to the user directory and delete the Windows2Local folder in the user directory's config folder.
  8. Start the IDE again. Install the module in the IDE. Close the IDE. Go back to the Windows2Local folder and, when you open the Groups folder, you should now see your new group definition file as well as a folder, containing a file for each of the two TopComponents that belongs to the group (according to your registration entries in the XML Layer):

  9. Now start the IDE again. Use the New Action wizard twice. The first time, create "ShowMyGroupAction" and stick this in the performAction() event:
    TopComponentGroup group = WindowManager.getDefault().findTopComponentGroup("MyGroup");
    if (group == null) {
    return;
    }
    group.open();

    Put the cursor on the first line above and, when the lightbulb appears, let the IDE generate import statements for these packages:

    import org.openide.windows.TopComponentGroup;
    import org.openide.windows.WindowManager;

    The second time you use the New Action wizard, create "HideMyGroupAction" and stick the following into the performAction() event:

    TopComponentGroup group = WindowManager.getDefault().findTopComponentGroup("MyGroup");
    if (group == null) {
    return;
    }
    group.close();

    Again let the IDE generate import statements for the two required packages.

  10. Install the module again. Now you can use the menu items to show and hide both TopComponents simultaneously. There's a lot of variations that apply here. If you close one of them after opening both, it will not be opened next time you use the menu item for showing both. And that's only one example of the way the Window System API now does all the thinking for you.

本文转自 Geertjan 的博客,原文地址:http://blogs.sun.com/geertjan/entry/creating_a_window_group

分享到:
评论

相关推荐

    BCGControlBarPro.v12.00

    Please note that our Application Wizards were updated and now, when you're creating a new, Ribbon-based application, you can choose "Backstage view" option (see screenshot) and initial backstage view ...

    UE(官方下载)

    However, what happens when you're moving to a new system and you want to port your settings and customizations over along with UltraEdit? Add a webpage to your toolbar Use UltraEdit's powerful user ...

    Bloodshed Dev-C++

    * When creating a DLL, the created static lib respects now the project-defined output directory Version 4.9.8.0 * Changed position of compiler/linker parameters in Project Options. * Improved help ...

    Visual C++ 编程资源大全(英文源码 控件)

    08.zip Drop down a popdown window instead of a dropdown list from a combobox 在ComboBox中用Drop down方式代替dropdown list方式(32KB)&lt;END&gt;&lt;br&gt;9,09.zip Change listbox width of combo boxes 在...

    gerrit-3.0.3.war

    Issue 11644: Fix setting project description when creating a project by REST API and setting plugin configs at the same time. Issue 11374: Fix handling of plugin capabilities on modification of child...

    DevExpress VCL 13.1.4(v2013vol1.4) 源码-例子-帮助-part2

    Q525613 - Creating a node in a tree list with an unallocated Handle does not specify the node's AbsoluteIndex property value Q520603 - cxDBTreeList - The "List index out of bounds" exception occurs ...

    DevExpress VCL 13.1.4(v2013vol1.4) 源码-例子-帮助-part1

    Q525613 - Creating a node in a tree list with an unallocated Handle does not specify the node's AbsoluteIndex property value Q520603 - cxDBTreeList - The "List index out of bounds" exception occurs ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    creating undo-group. - FIX The current scale ignores in TFlexBox.GetRefreshRect and TFlexEllipse.GetRefreshRect methods for pen width calculation. - FIX The method TFlexText.GetRefreshRect don't ...

    Sortable前端框架

    // Called when creating a clone of element onClone: function (/**Event*/evt) { var origEl = evt.item; var cloneEl = evt.clone; } }); ``` --- #### `group` option To drag elements from one list...

    Git-2.21.0-64-bit.zip

    * "git fetch" that grabs from a group of remotes learned to run the auto-gc only once at the very end. * A handful of Windows build patches have been upstreamed. * The code to read state files ...

    unigui0.83.5.820

    - 0000437: AV when creating inherited forms when no projectgroup is available - 0000413: Maximized ExtWindow can't return to normal size - 0000697: UniPanel: Caption Alignment - 0000696: UniPanel: ...

    VB编程资源大全(英文源码 网络)

    it switches tray icons on different states & displays the number of new messages (as msn messenger display messages) and plays a WAV file&lt;END&gt;&lt;br&gt;52 , urlhist.zip This sample demonstrates how to ...

    RxLib控件包内含RxGIF,全部源码及DEMO

    has a button to bring up calendar in popup window (combo-box alike) or in a dialog. TQBEQuery enables Delphi applications to use Paradox-style Query-by-example (QBE) statements to query tables, and ...

    Ubuntu The Complete Reference

    - **User and Group Management**: Techniques for managing users and groups, including creating new accounts and modifying group memberships. - **File System Management**: Discussion of managing the ...

    EurekaLog_7.5.0.0_Enterprise

    18)..Fixed: Possible "Unit XYZ was compiled with a different version of ABC" when using packages 19)..Fixed: FastMM shared MM compatibility 20)..Fixed: Minor bugs in stack tracing (which usually ...

Global site tag (gtag.js) - Google Analytics