Demo: show simple dialog for "File > New"

(used to test previous commit)
This commit is contained in:
Karl Tauber
2020-09-17 13:26:45 +02:00
parent ef4c467b20
commit 81d46ba8ee
4 changed files with 654 additions and 2 deletions

View File

@@ -105,6 +105,11 @@ class DemoFrame
FlatUIDefaultsInspector.show();
}
private void newActionPerformed() {
NewDialog newDialog = new NewDialog( this );
newDialog.setVisible( true );
}
private void openActionPerformed() {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog( this );
@@ -361,7 +366,7 @@ class DemoFrame
newMenuItem.setText("New");
newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
newMenuItem.setMnemonic('N');
newMenuItem.addActionListener(e -> menuItemActionPerformed(e));
newMenuItem.addActionListener(e -> newActionPerformed());
fileMenu.add(newMenuItem);
//---- openMenuItem ----

View File

@@ -131,7 +131,7 @@ new FormModel {
"text": "New"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 78, 4226, false )
"mnemonic": 78
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) )
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "newActionPerformed", false ) )
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "openMenuItem"

View File

@@ -0,0 +1,393 @@
/*
* Copyright 2020 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.demo;
import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.*;
import net.miginfocom.swing.*;
/**
* @author Karl Tauber
*/
class NewDialog
extends JDialog
{
NewDialog( Window owner ) {
super( owner );
initComponents();
// hide menubar, which is here for testing
menuBar1.setVisible( false );
getRootPane().setDefaultButton( okButton );
// register ESC key to close frame
((JComponent)getContentPane()).registerKeyboardAction(
e -> dispose(),
KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0, false ),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
}
private void okActionPerformed() {
dispose();
}
private void cancelActionPerformed() {
dispose();
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
dialogPane = new JPanel();
contentPanel = new JPanel();
label1 = new JLabel();
textField1 = new JTextField();
label3 = new JLabel();
comboBox2 = new JComboBox<>();
label2 = new JLabel();
comboBox1 = new JComboBox<>();
buttonBar = new JPanel();
okButton = new JButton();
cancelButton = new JButton();
menuBar1 = new JMenuBar();
menu1 = new JMenu();
menuItem8 = new JMenuItem();
menuItem7 = new JMenuItem();
menuItem6 = new JMenuItem();
menuItem5 = new JMenuItem();
menuItem4 = new JMenuItem();
menuItem3 = new JMenuItem();
menuItem2 = new JMenuItem();
menuItem1 = new JMenuItem();
menu2 = new JMenu();
menuItem18 = new JMenuItem();
menuItem17 = new JMenuItem();
menuItem16 = new JMenuItem();
menuItem15 = new JMenuItem();
menuItem14 = new JMenuItem();
menuItem13 = new JMenuItem();
menuItem12 = new JMenuItem();
menuItem11 = new JMenuItem();
menuItem10 = new JMenuItem();
menuItem9 = new JMenuItem();
menu3 = new JMenu();
menuItem25 = new JMenuItem();
menuItem26 = new JMenuItem();
menuItem24 = new JMenuItem();
menuItem23 = new JMenuItem();
menuItem22 = new JMenuItem();
menuItem21 = new JMenuItem();
menuItem20 = new JMenuItem();
menuItem19 = new JMenuItem();
popupMenu1 = new JPopupMenu();
cutMenuItem = new JMenuItem();
copyMenuItem = new JMenuItem();
pasteMenuItem = new JMenuItem();
//======== this ========
setTitle("New");
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setModal(true);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
//======== dialogPane ========
{
dialogPane.setLayout(new BorderLayout());
//======== contentPanel ========
{
contentPanel.setLayout(new MigLayout(
"insets dialog,hidemode 3",
// columns
"[fill]" +
"[grow,fill]",
// rows
"[]" +
"[]" +
"[]"));
//---- label1 ----
label1.setText("Name:");
contentPanel.add(label1, "cell 0 0");
//---- textField1 ----
textField1.setComponentPopupMenu(popupMenu1);
contentPanel.add(textField1, "cell 1 0");
//---- label3 ----
label3.setText("Package:");
contentPanel.add(label3, "cell 0 1");
//---- comboBox2 ----
comboBox2.setEditable(true);
comboBox2.setModel(new DefaultComboBoxModel<>(new String[] {
"com.myapp",
"com.myapp.core",
"com.myapp.ui",
"com.myapp.util",
"com.myapp.extras",
"com.myapp.components",
"com.myapp.dialogs",
"com.myapp.windows"
}));
contentPanel.add(comboBox2, "cell 1 1");
//---- label2 ----
label2.setText("Type:");
contentPanel.add(label2, "cell 0 2");
//---- comboBox1 ----
comboBox1.setModel(new DefaultComboBoxModel<>(new String[] {
"Class",
"Interface",
"Package",
"Annotation",
"Enum",
"Record",
"Java Project",
"Project",
"Folder",
"File"
}));
contentPanel.add(comboBox1, "cell 1 2");
}
dialogPane.add(contentPanel, BorderLayout.CENTER);
//======== buttonBar ========
{
buttonBar.setLayout(new MigLayout(
"insets dialog,alignx right",
// columns
"[button,fill]" +
"[button,fill]",
// rows
null));
//---- okButton ----
okButton.setText("OK");
okButton.addActionListener(e -> okActionPerformed());
buttonBar.add(okButton, "cell 0 0");
//---- cancelButton ----
cancelButton.setText("Cancel");
cancelButton.addActionListener(e -> cancelActionPerformed());
buttonBar.add(cancelButton, "cell 1 0");
}
dialogPane.add(buttonBar, BorderLayout.SOUTH);
//======== menuBar1 ========
{
//======== menu1 ========
{
menu1.setText("text");
//---- menuItem8 ----
menuItem8.setText("text");
menu1.add(menuItem8);
//---- menuItem7 ----
menuItem7.setText("text");
menu1.add(menuItem7);
//---- menuItem6 ----
menuItem6.setText("text");
menu1.add(menuItem6);
//---- menuItem5 ----
menuItem5.setText("text");
menu1.add(menuItem5);
//---- menuItem4 ----
menuItem4.setText("text");
menu1.add(menuItem4);
//---- menuItem3 ----
menuItem3.setText("text");
menu1.add(menuItem3);
//---- menuItem2 ----
menuItem2.setText("text");
menu1.add(menuItem2);
//---- menuItem1 ----
menuItem1.setText("text");
menu1.add(menuItem1);
}
menuBar1.add(menu1);
//======== menu2 ========
{
menu2.setText("text");
//---- menuItem18 ----
menuItem18.setText("text");
menu2.add(menuItem18);
//---- menuItem17 ----
menuItem17.setText("text");
menu2.add(menuItem17);
//---- menuItem16 ----
menuItem16.setText("text");
menu2.add(menuItem16);
//---- menuItem15 ----
menuItem15.setText("text");
menu2.add(menuItem15);
//---- menuItem14 ----
menuItem14.setText("text");
menu2.add(menuItem14);
//---- menuItem13 ----
menuItem13.setText("text");
menu2.add(menuItem13);
//---- menuItem12 ----
menuItem12.setText("text");
menu2.add(menuItem12);
//---- menuItem11 ----
menuItem11.setText("text");
menu2.add(menuItem11);
//---- menuItem10 ----
menuItem10.setText("text");
menu2.add(menuItem10);
//---- menuItem9 ----
menuItem9.setText("text");
menu2.add(menuItem9);
}
menuBar1.add(menu2);
//======== menu3 ========
{
menu3.setText("text");
//---- menuItem25 ----
menuItem25.setText("text");
menu3.add(menuItem25);
//---- menuItem26 ----
menuItem26.setText("text");
menu3.add(menuItem26);
//---- menuItem24 ----
menuItem24.setText("text");
menu3.add(menuItem24);
//---- menuItem23 ----
menuItem23.setText("text");
menu3.add(menuItem23);
//---- menuItem22 ----
menuItem22.setText("text");
menu3.add(menuItem22);
//---- menuItem21 ----
menuItem21.setText("text");
menu3.add(menuItem21);
//---- menuItem20 ----
menuItem20.setText("text");
menu3.add(menuItem20);
//---- menuItem19 ----
menuItem19.setText("text");
menu3.add(menuItem19);
}
menuBar1.add(menu3);
}
dialogPane.add(menuBar1, BorderLayout.NORTH);
}
contentPane.add(dialogPane, BorderLayout.CENTER);
pack();
setLocationRelativeTo(getOwner());
//======== popupMenu1 ========
{
//---- cutMenuItem ----
cutMenuItem.setText("Cut");
cutMenuItem.setMnemonic('C');
popupMenu1.add(cutMenuItem);
//---- copyMenuItem ----
copyMenuItem.setText("Copy");
copyMenuItem.setMnemonic('O');
popupMenu1.add(copyMenuItem);
//---- pasteMenuItem ----
pasteMenuItem.setText("Paste");
pasteMenuItem.setMnemonic('P');
popupMenu1.add(pasteMenuItem);
}
// JFormDesigner - End of component initialization //GEN-END:initComponents
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
private JPanel dialogPane;
private JPanel contentPanel;
private JLabel label1;
private JTextField textField1;
private JLabel label3;
private JComboBox<String> comboBox2;
private JLabel label2;
private JComboBox<String> comboBox1;
private JPanel buttonBar;
private JButton okButton;
private JButton cancelButton;
private JMenuBar menuBar1;
private JMenu menu1;
private JMenuItem menuItem8;
private JMenuItem menuItem7;
private JMenuItem menuItem6;
private JMenuItem menuItem5;
private JMenuItem menuItem4;
private JMenuItem menuItem3;
private JMenuItem menuItem2;
private JMenuItem menuItem1;
private JMenu menu2;
private JMenuItem menuItem18;
private JMenuItem menuItem17;
private JMenuItem menuItem16;
private JMenuItem menuItem15;
private JMenuItem menuItem14;
private JMenuItem menuItem13;
private JMenuItem menuItem12;
private JMenuItem menuItem11;
private JMenuItem menuItem10;
private JMenuItem menuItem9;
private JMenu menu3;
private JMenuItem menuItem25;
private JMenuItem menuItem26;
private JMenuItem menuItem24;
private JMenuItem menuItem23;
private JMenuItem menuItem22;
private JMenuItem menuItem21;
private JMenuItem menuItem20;
private JMenuItem menuItem19;
private JPopupMenu popupMenu1;
private JMenuItem cutMenuItem;
private JMenuItem copyMenuItem;
private JMenuItem pasteMenuItem;
// JFormDesigner - End of variables declaration //GEN-END:variables
}

View File

@@ -0,0 +1,254 @@
JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8"
new FormModel {
contentType: "form/swing"
root: new FormRoot {
add( new FormWindow( "javax.swing.JDialog", new FormLayoutManager( class java.awt.BorderLayout ) ) {
name: "this"
"title": "New"
"defaultCloseOperation": 2
"modal": true
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
name: "dialogPane"
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets dialog,hidemode 3"
"$columnConstraints": "[fill][grow,fill]"
"$rowConstraints": "[][][]"
} ) {
name: "contentPanel"
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label1"
"text": "Name:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 0"
} )
add( new FormComponent( "javax.swing.JTextField" ) {
name: "textField1"
"componentPopupMenu": new FormReference( "popupMenu1" )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 0"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label3"
"text": "Package:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 1"
} )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "comboBox2"
"editable": true
"model": new javax.swing.DefaultComboBoxModel {
selectedItem: "com.myapp"
addElement( "com.myapp" )
addElement( "com.myapp.core" )
addElement( "com.myapp.ui" )
addElement( "com.myapp.util" )
addElement( "com.myapp.extras" )
addElement( "com.myapp.components" )
addElement( "com.myapp.dialogs" )
addElement( "com.myapp.windows" )
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 1"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label2"
"text": "Type:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 2"
} )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "comboBox1"
"model": new javax.swing.DefaultComboBoxModel {
selectedItem: "Class"
addElement( "Class" )
addElement( "Interface" )
addElement( "Package" )
addElement( "Annotation" )
addElement( "Enum" )
addElement( "Record" )
addElement( "Java Project" )
addElement( "Project" )
addElement( "Folder" )
addElement( "File" )
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2"
} )
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "Center"
} )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets dialog,alignx right"
"$columnConstraints": "[button,fill][button,fill]"
"$rowSpecs": "[fill]"
} ) {
name: "buttonBar"
add( new FormComponent( "javax.swing.JButton" ) {
name: "okButton"
"text": "OK"
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "okActionPerformed", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 0"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "cancelButton"
"text": "Cancel"
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "cancelActionPerformed", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 0"
} )
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "South"
} )
add( new FormContainer( "javax.swing.JMenuBar", new FormLayoutManager( class javax.swing.JMenuBar ) ) {
name: "menuBar1"
add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) {
name: "menu1"
"text": "text"
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem8"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem7"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem6"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem5"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem4"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem3"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem2"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem1"
"text": "text"
} )
} )
add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) {
name: "menu2"
"text": "text"
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem18"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem17"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem16"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem15"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem14"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem13"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem12"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem11"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem10"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem9"
"text": "text"
} )
} )
add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) {
name: "menu3"
"text": "text"
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem25"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem26"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem24"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem23"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem22"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem21"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem20"
"text": "text"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "menuItem19"
"text": "text"
} )
} )
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "North"
} )
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "Center"
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 330, 210 )
} )
add( new FormContainer( "javax.swing.JPopupMenu", new FormLayoutManager( class javax.swing.JPopupMenu ) ) {
name: "popupMenu1"
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "cutMenuItem"
"text": "Cut"
"mnemonic": 67
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "copyMenuItem"
"text": "Copy"
"mnemonic": 79
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "pasteMenuItem"
"text": "Paste"
"mnemonic": 80
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 220 )
"size": new java.awt.Dimension( 91, 87 )
} )
}
}