InternalFrame: basic implementation (issues #39 and #11)

This commit is contained in:
Karl Tauber
2020-01-27 15:23:03 +01:00
parent 7e61d6a850
commit df4f51eff3
18 changed files with 612 additions and 38 deletions

View File

@@ -7,6 +7,7 @@ package com.formdev.flatlaf.testing;
import java.awt.*;
import java.beans.PropertyVetoException;
import javax.swing.*;
import com.formdev.flatlaf.icons.FlatFileViewFloppyDriveIcon;
import com.formdev.flatlaf.util.UIScale;
import net.miginfocom.swing.*;
@@ -49,10 +50,25 @@ public class FlatInternalFrameTest
maximizableCheckBox.isSelected(),
iconifiableCheckBox.isSelected() );
JPanel panel = new JPanel();
panel.setBackground( new Color( (int) (Math.random() * 0xffffff) ) );
if( iconCheckBox.isSelected() )
internalFrame.setFrameIcon( new FlatFileViewFloppyDriveIcon() );
JPanel panel = new JPanel() {
private final Color color = new Color( (int) (Math.random() * 0xffffff) | 0x20000000, true );
@Override
protected void paintComponent( Graphics g ) {
super.paintComponent( g );
g.setColor( color );
g.fillRect( 20, 20, getWidth() - 40, getHeight() - 40 );
}
};
internalFrame.setContentPane( panel );
if( !palette.getComponentOrientation().isLeftToRight() )
internalFrame.setComponentOrientation( ComponentOrientation.RIGHT_TO_LEFT );
internalFrame.setBounds( frameX + UIScale.scale( GAP ) * (frameCount % 10),
frameY + UIScale.scale( GAP ) * (frameCount % 10), UIScale.scale( 200 ), UIScale.scale( 200 ) );
desktopPane.add( internalFrame, JLayeredPane.DEFAULT_LAYER );
@@ -76,6 +92,7 @@ public class FlatInternalFrameTest
closableCheckBox = new JCheckBox();
iconifiableCheckBox = new JCheckBox();
maximizableCheckBox = new JCheckBox();
iconCheckBox = new JCheckBox();
titleLabel = new JLabel();
titleField = new JTextField();
createFrameButton = new JButton();
@@ -107,6 +124,7 @@ public class FlatInternalFrameTest
// rows
"[fill]0" +
"[]0" +
"[]0" +
"[]unrel" +
"[]unrel"));
@@ -130,18 +148,22 @@ public class FlatInternalFrameTest
maximizableCheckBox.setSelected(true);
paletteContentPane.add(maximizableCheckBox, "cell 1 1,alignx left,growx 0");
//---- iconCheckBox ----
iconCheckBox.setText("Frame icon");
paletteContentPane.add(iconCheckBox, "cell 0 2");
//---- titleLabel ----
titleLabel.setText("Frame title:");
paletteContentPane.add(titleLabel, "cell 0 2");
paletteContentPane.add(titleField, "cell 1 2");
paletteContentPane.add(titleLabel, "cell 0 3");
paletteContentPane.add(titleField, "cell 1 3");
//---- createFrameButton ----
createFrameButton.setText("Create Frame");
createFrameButton.addActionListener(e -> createInternalFrame());
paletteContentPane.add(createFrameButton, "cell 1 3,alignx right,growx 0");
paletteContentPane.add(createFrameButton, "cell 1 4,alignx right,growx 0");
}
desktopPane.add(palette, JLayeredPane.PALETTE_LAYER);
palette.setBounds(15, 25, 220, 160);
palette.setBounds(15, 25, 220, 185);
}
add(desktopPane, "cell 0 0,width 600,height 600");
// JFormDesigner - End of component initialization //GEN-END:initComponents
@@ -157,6 +179,7 @@ public class FlatInternalFrameTest
private JCheckBox closableCheckBox;
private JCheckBox iconifiableCheckBox;
private JCheckBox maximizableCheckBox;
private JCheckBox iconCheckBox;
private JLabel titleLabel;
private JTextField titleField;
private JButton createFrameButton;

View File

@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.0.0.194" Java: "11.0.2" encoding: "UTF-8"
JFDML JFormDesigner: "7.0.0.0.194" Java: "13.0.1" encoding: "UTF-8"
new FormModel {
contentType: "form/swing"
@@ -14,7 +14,7 @@ new FormModel {
add( new FormContainer( "javax.swing.JInternalFrame", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "hidemode 3"
"$columnConstraints": "[fill][fill]"
"$rowConstraints": "[fill]0[]0[]unrel[]unrel"
"$rowConstraints": "[fill]0[]0[]0[]unrel[]unrel"
} ) {
name: "palette"
"visible": true
@@ -50,29 +50,35 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "iconCheckBox"
"text": "Frame icon"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 2"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "titleLabel"
"text": "Frame title:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 2"
"value": "cell 0 3"
} )
add( new FormComponent( "javax.swing.JTextField" ) {
name: "titleField"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2"
"value": "cell 1 3"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "createFrameButton"
"text": "Create Frame"
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "createInternalFrame", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 3,alignx right,growx 0"
"value": "cell 1 4,alignx right,growx 0"
} )
}, new FormLayoutConstraints( null ) {
"x": 15
"y": 25
"width": 220
"height": 160
"height": 185
"layer": 100
} )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {

View File

@@ -403,8 +403,8 @@ public class FlatTestFrame
private void updateComponentsRecur( Container container, BiConsumer<Component, String> action ) {
for( Component c : container.getComponents() ) {
if( c instanceof JPanel ) {
updateComponentsRecur( (JPanel) c, action );
if( c instanceof JPanel || c instanceof JDesktopPane ) {
updateComponentsRecur( (Container) c, action );
continue;
}