Add pane-splitting.

git-svn-id: file:///home/svn/framework3/trunk@13714 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Matt Weeks 2011-09-11 00:21:01 +00:00
parent 94d77fbb4f
commit 35a6f26654
11 changed files with 133 additions and 36 deletions

Binary file not shown.

View File

@ -30,7 +30,8 @@ includes=**
jar.compress=false
javac.classpath=\
${libs.swing-app-framework.classpath}:\
${file.reference.msgpack-0.5.1-devel.jar}
${file.reference.msgpack-0.5.1-devel.jar}:\
${libs.absolutelayout.classpath}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false

View File

@ -1,6 +1,8 @@
package msfgui;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.Point;
import java.awt.Window;
@ -21,6 +23,7 @@ import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JWindow;
import javax.swing.event.ChangeEvent;
@ -36,6 +39,7 @@ public class DraggableTabbedPane extends JTabbedPane{
private static Set panes = new HashSet();
private boolean dragging = false;
private int draggedTabIndex = 0;
private Container paneParent;
private Map focusListeners = new HashMap();
private static FocusListener lastFocusListener = null;
private static JWindow window;
@ -115,11 +119,35 @@ public class DraggableTabbedPane extends JTabbedPane{
destinationPane.focusListeners.put(comp, focusListeners.get(comp));
//If we got rid of the last tab, close this window, unless it's the main window
JFrame rent = (JFrame)getTopLevelAncestor();
if(getTabCount() < 1 && rent != MsfguiApp.mainFrame.getFrame()){
rent.setVisible(false);
rent.dispose();
panes.remove(DraggableTabbedPane.this);
if(getTabCount() < 1 && paneParent != MsfguiApp.mainFrame.getFrame()){
panes.remove(this);
//If parent is a frame, just close it
if(paneParent instanceof JFrame){
paneParent.setVisible(false);
((JFrame)paneParent).dispose();
//If it's a split pane, replace with other side
}else if(paneParent instanceof JSplitPane){
JSplitPane split = (JSplitPane)paneParent;
Component replacement;
if (split.getRightComponent() == this)
replacement = split.getLeftComponent();
else if (((JSplitPane)paneParent).getLeftComponent() == this)
replacement = split.getRightComponent();
else
throw new MsfException("Not either side of split? This should never happen");
Container parent = split.getParent();
parent.remove(split);
parent.add(replacement);
//If the other side is a DraggableTabbedPane, update its parent
for(Container c = parent; c != null; c=c.getParent()){
if((c instanceof JSplitPane || c instanceof JFrame)
&& replacement instanceof DraggableTabbedPane){
((DraggableTabbedPane)replacement).paneParent = c;
break;
}
}
((Window)((javax.swing.JComponent)replacement).getTopLevelAncestor()).pack();
}
}
}
@ -174,9 +202,11 @@ public class DraggableTabbedPane extends JTabbedPane{
}
/**
* Default constructor of DraggableTabbedPane.
* Constructs a new DraggableTabbedPane with a parent
* @param parent
*/
public DraggableTabbedPane() {
public DraggableTabbedPane(Container parent) {
paneParent = parent;
//Set up right-click menu
final JPopupMenu tabPopupMenu = new JPopupMenu();
JMenuItem closeTabItem = new JMenuItem("Close this tab");
@ -191,6 +221,36 @@ public class DraggableTabbedPane extends JTabbedPane{
}
});
tabPopupMenu.add(closeTabItem);
JMenuItem newWinItem = new JMenuItem("Move to new window");
newWinItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int indx = getSelectedIndex();
if(indx == -1)
return;
moveTabToNewFrame(indx,0,0);
}
});
tabPopupMenu.add(newWinItem);
JMenuItem splitVerticalItem = new JMenuItem("Split vertically");
splitVerticalItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int indx = getSelectedIndex();
if(indx == -1)
return;
addSplit(indx,JSplitPane.VERTICAL_SPLIT);
}
});
tabPopupMenu.add(splitVerticalItem);
JMenuItem splitHorizontalItem = new JMenuItem("Split horizontally");
splitHorizontalItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int indx = getSelectedIndex();
if(indx == -1)
return;
addSplit(indx,JSplitPane.HORIZONTAL_SPLIT);
}
});
tabPopupMenu.add(splitHorizontalItem);
addMouseListener( new PopupMouseListener() {
public void showPopup(MouseEvent e) {
tabPopupMenu.show(DraggableTabbedPane.this, e.getX(), e.getY() );
@ -244,19 +304,20 @@ public class DraggableTabbedPane extends JTabbedPane{
for(Object tabo : panes){
DraggableTabbedPane pane = (DraggableTabbedPane)tabo;
try{
Point ptabo = (pane).getLocationOnScreen();
Point ptabo = pane.getLocationOnScreen();
int x = e.getXOnScreen() - ptabo.x;
int y = e.getYOnScreen() - ptabo.y;
int tabNumber = pane.getUI().tabForCoordinate(pane, x, y);
//If it's not on one of the tabs, but it's still in the tab bar, make a new tab
if (tabNumber < 0 && pane.getBounds().contains(x, y))
int paneW = pane.getWidth();
int paneH = pane.getHeight();
if (tabNumber < 0 && x > 0 && y > 0 && x <= paneW && y <= paneH)
tabNumber = pane.getTabCount() - 1;
//We found it!
if (tabNumber >= 0) {
moveTabTo(draggedTabIndex, pane, tabNumber);
MsfguiApp.getPropertiesNode().put("tabWindowPreference", "tab"); //guess we like tabs
return;
}
}catch(java.awt.IllegalComponentStateException icse){
@ -269,16 +330,48 @@ public class DraggableTabbedPane extends JTabbedPane{
panes.add(this);
}
/**
* Splits the current tabbed pane, adding indx to the new split
* @param indx
*/
private void addSplit(int indx, int orientation) {
//Make split pane
JSplitPane split = new javax.swing.JSplitPane();
split.setOrientation(orientation);
split.setLeftComponent(DraggableTabbedPane.this);
//make new tabbedpane
final DraggableTabbedPane tabs = new DraggableTabbedPane(split);
moveTabTo(indx, tabs, 0);
split.setRightComponent(tabs);
if (paneParent instanceof JFrame) {
Dimension size = paneParent.getSize();
((JFrame) paneParent).getContentPane().removeAll();
((JFrame) paneParent).getContentPane().setLayout(new java.awt.GridLayout());
((JFrame) paneParent).getContentPane().add(split);
((JFrame) paneParent).pack();
paneParent.setSize(size);
} else if (paneParent instanceof JSplitPane) {
JSplitPane splitParent = (JSplitPane) paneParent;
if (splitParent.getRightComponent() == null) {
splitParent.setRightComponent(split);
} else if (splitParent.getLeftComponent() == null) {
splitParent.setLeftComponent(split);
}
splitParent.setDividerLocation(0.5);
}
split.setDividerLocation(0.5);
paneParent = split;
}
/**
* Creates a new frame, and places the given tab in it
*/
private MsfFrame moveTabToNewFrame(int tabNumber, int x, int y) throws HeadlessException {
MsfguiApp.getPropertiesNode().put("tabWindowPreference", "window"); //guess we like new windows
final MsfFrame newFrame = new MsfFrame("Msfgui");
newFrame.setSize(DraggableTabbedPane.this.getSize());
newFrame.setLocation(x, y);
//Make tabs to go in the frame
final DraggableTabbedPane tabs = new DraggableTabbedPane();
final DraggableTabbedPane tabs = new DraggableTabbedPane(newFrame);
moveTabTo(tabNumber, tabs, 0);
newFrame.add(tabs);
newFrame.setVisible(true);

View File

@ -39,7 +39,7 @@
<Property name="name" type="java.lang.String" value="tabbedPane" noResource="true"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new DraggableTabbedPane()"/>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new DraggableTabbedPane(this)"/>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="1"/>
</AuxValues>

View File

@ -244,7 +244,7 @@ public class InteractWindow extends MsfFrame implements ClipboardOwner {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
tabbedPane = new DraggableTabbedPane();
tabbedPane = new DraggableTabbedPane(this);
outputScrollPane = new javax.swing.JScrollPane();
outputArea = new javax.swing.JTextArea();
promptLabel = new javax.swing.JLabel();
@ -308,16 +308,16 @@ public class InteractWindow extends MsfFrame implements ClipboardOwner {
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(promptLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(inputField, javax.swing.GroupLayout.DEFAULT_SIZE, 506, Short.MAX_VALUE)
.addComponent(inputField, javax.swing.GroupLayout.DEFAULT_SIZE, 505, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(submitButton)
.addContainerGap())
.addComponent(outputScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 623, Short.MAX_VALUE)
.addComponent(outputScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 619, Short.MAX_VALUE)
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
.addComponent(outputScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE)
.addComponent(outputScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(promptLabel)

View File

@ -28,7 +28,7 @@
<Property name="name" type="java.lang.String" value="tabbedPane" noResource="true"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new DraggableTabbedPane()"/>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new DraggableTabbedPane(getFrame())"/>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="1"/>
</AuxValues>
@ -874,6 +874,9 @@
<Property name="action" type="javax.swing.Action" editor="org.netbeans.modules.swingapp.ActionEditor">
<action class="msfgui.MainFrame" id="showAboutBox" methodName="showAboutBox"/>
</Property>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="F1"/>
</Property>
<Property name="name" type="java.lang.String" value="aboutMenuItem" noResource="true"/>
</Properties>
<AuxValues>

View File

@ -469,7 +469,7 @@ nameloop: for (int i = 0; i < names.length; i++) {
private void initComponents() {
mainPanel = new javax.swing.JPanel();
tabbedPane = new DraggableTabbedPane();
tabbedPane = new DraggableTabbedPane(getFrame());
jobsPane = new javax.swing.JScrollPane();
jobsList = new javax.swing.JList();
sessionsPane = new javax.swing.JScrollPane();

View File

@ -37,7 +37,7 @@
<Property name="name" type="java.lang.String" value="tabbedPane" noResource="true"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new DraggableTabbedPane()"/>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new DraggableTabbedPane(this)"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
@ -60,13 +60,13 @@
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="jScrollPane1" alignment="0" pref="893" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="0" pref="889" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="upButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="pwdLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="addressField" pref="728" max="32767" attributes="0"/>
<Component id="addressField" pref="725" max="32767" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="goButton" min="-2" max="-2" attributes="0"/>
</Group>
@ -99,7 +99,7 @@
<Component id="goButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="433" max="32767" attributes="0"/>
<Component id="jScrollPane1" pref="427" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="refreshButton" alignment="3" min="-2" max="-2" attributes="0"/>

View File

@ -289,7 +289,7 @@ public class MeterpFileBrowser extends MsfFrame {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
tabbedPane = new DraggableTabbedPane();
tabbedPane = new DraggableTabbedPane(this);
mainPanel = new javax.swing.JPanel();
upButton = new javax.swing.JButton();
pwdLabel = new javax.swing.JLabel();
@ -406,13 +406,13 @@ public class MeterpFileBrowser extends MsfFrame {
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 893, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 889, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
.addComponent(upButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pwdLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(addressField, javax.swing.GroupLayout.DEFAULT_SIZE, 728, Short.MAX_VALUE)
.addComponent(addressField, javax.swing.GroupLayout.DEFAULT_SIZE, 725, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(goButton))
.addGroup(mainPanelLayout.createSequentialGroup()
@ -439,7 +439,7 @@ public class MeterpFileBrowser extends MsfFrame {
.addComponent(addressField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(goButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(refreshButton)

View File

@ -37,7 +37,7 @@
<Property name="name" type="java.lang.String" value="tabbedPane" noResource="true"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new DraggableTabbedPane()"/>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new DraggableTabbedPane(this)"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
@ -60,10 +60,10 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="1" pref="590" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="1" pref="586" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="refreshButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="418" max="32767" attributes="0"/>
<EmptySpace pref="416" max="32767" attributes="0"/>
<Component id="killButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="migrateButton" min="-2" max="-2" attributes="0"/>
@ -77,7 +77,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="358" max="32767" attributes="0"/>
<Component id="jScrollPane1" pref="352" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="refreshButton" alignment="3" min="-2" max="-2" attributes="0"/>

View File

@ -139,7 +139,7 @@ public class ProcessList extends MsfFrame {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
tabbedPane = new DraggableTabbedPane();
tabbedPane = new DraggableTabbedPane(this);
mainPanel = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
processTable = new javax.swing.JTable();
@ -206,10 +206,10 @@ public class ProcessList extends MsfFrame {
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 590, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE)
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(refreshButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 418, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 416, Short.MAX_VALUE)
.addComponent(killButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(migrateButton)))
@ -219,7 +219,7 @@ public class ProcessList extends MsfFrame {
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(refreshButton)