Demo: menu and toolbar added

This commit is contained in:
Karl Tauber
2019-09-07 19:09:23 +02:00
parent 2c7fee97f3
commit 0c16914c28
14 changed files with 467 additions and 0 deletions

View File

@@ -17,6 +17,7 @@
package com.formdev.flatlaf.demo;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import net.miginfocom.swing.*;
@@ -36,12 +37,48 @@ class DemoFrame
tabbedPane.setSelectedIndex( tabIndex );
}
private void exitActionPerformed() {
dispose();
}
private void aboutActionPerformed() {
JOptionPane.showMessageDialog( this, "FlatLaf Demo", "About", JOptionPane.PLAIN_MESSAGE );
}
private void selectedTabChanged() {
FlatLafDemo.prefs.putInt( FlatLafDemo.KEY_TAB, tabbedPane.getSelectedIndex() );
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
JMenuBar menuBar1 = new JMenuBar();
JMenu fileMenu = new JMenu();
JMenuItem newMenuItem = new JMenuItem();
JMenuItem openMenuItem = new JMenuItem();
JMenuItem closeMenuItem = new JMenuItem();
JMenuItem exitMenuItem = new JMenuItem();
JMenu editMenu = new JMenu();
JMenuItem undoMenuItem = new JMenuItem();
JMenuItem redoMenuItem = new JMenuItem();
JMenuItem cutMenuItem = new JMenuItem();
JMenuItem copyMenuItem = new JMenuItem();
JMenuItem pasteMenuItem = new JMenuItem();
JMenuItem deleteMenuItem = new JMenuItem();
JMenu viewMenu = new JMenu();
JCheckBoxMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem();
JRadioButtonMenuItem radioButtonMenuItem1 = new JRadioButtonMenuItem();
JRadioButtonMenuItem radioButtonMenuItem2 = new JRadioButtonMenuItem();
JRadioButtonMenuItem radioButtonMenuItem3 = new JRadioButtonMenuItem();
JMenu helpMenu = new JMenu();
JMenuItem aboutMenuItem = new JMenuItem();
JToolBar toolBar1 = new JToolBar();
JButton backButton = new JButton();
JButton forwardButton = new JButton();
JButton cutButton = new JButton();
JButton copyButton = new JButton();
JButton pasteButton = new JButton();
JButton refreshButton = new JButton();
JToggleButton showToggleButton = new JToggleButton();
JPanel contentPanel = new JPanel();
tabbedPane = new JTabbedPane();
BasicComponentsPanel basicComponentsPanel = new BasicComponentsPanel();
@@ -57,6 +94,132 @@ class DemoFrame
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
//======== menuBar1 ========
{
//======== fileMenu ========
{
fileMenu.setText("File");
//---- newMenuItem ----
newMenuItem.setText("New");
newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
fileMenu.add(newMenuItem);
//---- openMenuItem ----
openMenuItem.setText("Open");
openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
fileMenu.add(openMenuItem);
fileMenu.addSeparator();
//---- closeMenuItem ----
closeMenuItem.setText("Close");
closeMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
fileMenu.add(closeMenuItem);
fileMenu.addSeparator();
//---- exitMenuItem ----
exitMenuItem.setText("Exit");
exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
exitMenuItem.addActionListener(e -> exitActionPerformed());
fileMenu.add(exitMenuItem);
}
menuBar1.add(fileMenu);
//======== editMenu ========
{
editMenu.setText("Edit");
//---- undoMenuItem ----
undoMenuItem.setText("Undo");
undoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
editMenu.add(undoMenuItem);
//---- redoMenuItem ----
redoMenuItem.setText("Redo");
redoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
editMenu.add(redoMenuItem);
editMenu.addSeparator();
//---- cutMenuItem ----
cutMenuItem.setText("Cut");
cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
editMenu.add(cutMenuItem);
//---- copyMenuItem ----
copyMenuItem.setText("Copy");
copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
editMenu.add(copyMenuItem);
//---- pasteMenuItem ----
pasteMenuItem.setText("Paste");
pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
editMenu.add(pasteMenuItem);
editMenu.addSeparator();
//---- deleteMenuItem ----
deleteMenuItem.setText("Delete");
deleteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
editMenu.add(deleteMenuItem);
}
menuBar1.add(editMenu);
//======== viewMenu ========
{
viewMenu.setText("View");
//---- checkBoxMenuItem1 ----
checkBoxMenuItem1.setText("Show Toolbar");
checkBoxMenuItem1.setSelected(true);
viewMenu.add(checkBoxMenuItem1);
viewMenu.addSeparator();
//---- radioButtonMenuItem1 ----
radioButtonMenuItem1.setText("Details");
radioButtonMenuItem1.setSelected(true);
viewMenu.add(radioButtonMenuItem1);
//---- radioButtonMenuItem2 ----
radioButtonMenuItem2.setText("Small Icons");
viewMenu.add(radioButtonMenuItem2);
//---- radioButtonMenuItem3 ----
radioButtonMenuItem3.setText("Large Icons");
viewMenu.add(radioButtonMenuItem3);
}
menuBar1.add(viewMenu);
//======== helpMenu ========
{
helpMenu.setText("Help");
//---- aboutMenuItem ----
aboutMenuItem.setText("About");
aboutMenuItem.addActionListener(e -> aboutActionPerformed());
helpMenu.add(aboutMenuItem);
}
menuBar1.add(helpMenu);
}
setJMenuBar(menuBar1);
//======== toolBar1 ========
{
toolBar1.add(backButton);
toolBar1.add(forwardButton);
toolBar1.addSeparator();
toolBar1.add(cutButton);
toolBar1.add(copyButton);
toolBar1.add(pasteButton);
toolBar1.addSeparator();
toolBar1.add(refreshButton);
toolBar1.addSeparator();
//---- showToggleButton ----
showToggleButton.setSelected(true);
toolBar1.add(showToggleButton);
}
contentPane.add(toolBar1, BorderLayout.NORTH);
//======== contentPanel ========
{
contentPanel.setLayout(new MigLayout(
@@ -80,7 +243,28 @@ class DemoFrame
contentPanel.add(controlBar, "cell 0 1");
}
contentPane.add(contentPanel, BorderLayout.CENTER);
//---- buttonGroup1 ----
ButtonGroup buttonGroup1 = new ButtonGroup();
buttonGroup1.add(radioButtonMenuItem1);
buttonGroup1.add(radioButtonMenuItem2);
buttonGroup1.add(radioButtonMenuItem3);
// JFormDesigner - End of component initialization //GEN-END:initComponents
undoMenuItem.setIcon( new ScaledSVGIcon( "icons/undo.svg" ) );
redoMenuItem.setIcon( new ScaledSVGIcon( "icons/redo.svg" ) );
cutMenuItem.setIcon( new ScaledSVGIcon( "icons/menu-cut.svg" ) );
copyMenuItem.setIcon( new ScaledSVGIcon( "icons/copy.svg" ) );
pasteMenuItem.setIcon( new ScaledSVGIcon( "icons/menu-paste.svg" ) );
backButton.setIcon( new ScaledSVGIcon( "icons/back.svg" ) );
forwardButton.setIcon( new ScaledSVGIcon( "icons/forward.svg" ) );
cutButton.setIcon( new ScaledSVGIcon( "icons/menu-cut.svg" ) );
copyButton.setIcon( new ScaledSVGIcon( "icons/copy.svg" ) );
pasteButton.setIcon( new ScaledSVGIcon( "icons/menu-paste.svg" ) );
refreshButton.setIcon( new ScaledSVGIcon( "icons/refresh.svg" ) );
showToggleButton.setIcon( new ScaledSVGIcon( "icons/show.svg" ) );
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables

View File

@@ -12,6 +12,42 @@ new FormModel {
"defaultCloseOperation": 2
"$locationPolicy": 2
"$sizePolicy": 2
add( new FormContainer( "javax.swing.JToolBar", new FormLayoutManager( class javax.swing.JToolBar ) ) {
name: "toolBar1"
add( new FormComponent( "javax.swing.JButton" ) {
name: "backButton"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "forwardButton"
} )
add( new FormComponent( "javax.swing.JToolBar$Separator" ) {
name: "separator5"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "cutButton"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "copyButton"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "pasteButton"
} )
add( new FormComponent( "javax.swing.JToolBar$Separator" ) {
name: "separator6"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "refreshButton"
} )
add( new FormComponent( "javax.swing.JToolBar$Separator" ) {
name: "separator7"
} )
add( new FormComponent( "javax.swing.JToggleButton" ) {
name: "showToggleButton"
"selected": true
} )
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "North"
} )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets dialog,hidemode 3"
"$columnConstraints": "[grow,fill]"
@@ -63,9 +99,125 @@ new FormModel {
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "Center"
} )
menuBar: 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: "fileMenu"
"text": "File"
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "newMenuItem"
"text": "New"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 78, 4226, false )
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "openMenuItem"
"text": "Open"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 79, 4226, false )
} )
add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) {
name: "separator2"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "closeMenuItem"
"text": "Close"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 87, 4226, false )
} )
add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) {
name: "separator1"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "exitMenuItem"
"text": "Exit"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 81, 4226, false )
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "exitActionPerformed", false ) )
} )
} )
add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) {
name: "editMenu"
"text": "Edit"
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "undoMenuItem"
"text": "Undo"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 90, 4226, false )
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "redoMenuItem"
"text": "Redo"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 89, 4226, false )
} )
add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) {
name: "separator4"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "cutMenuItem"
"text": "Cut"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 88, 4226, false )
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "copyMenuItem"
"text": "Copy"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 67, 4226, false )
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "pasteMenuItem"
"text": "Paste"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 86, 4226, false )
} )
add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) {
name: "separator3"
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "deleteMenuItem"
"text": "Delete"
"accelerator": static javax.swing.KeyStroke getKeyStroke( 127, 0, false )
} )
} )
add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) {
name: "viewMenu"
"text": "View"
add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) {
name: "checkBoxMenuItem1"
"text": "Show Toolbar"
"selected": true
} )
add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) {
name: "separator8"
} )
add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) {
name: "radioButtonMenuItem1"
"text": "Details"
"selected": true
"$buttonGroup": new FormReference( "buttonGroup1" )
} )
add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) {
name: "radioButtonMenuItem2"
"text": "Small Icons"
"$buttonGroup": new FormReference( "buttonGroup1" )
} )
add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) {
name: "radioButtonMenuItem3"
"text": "Large Icons"
"$buttonGroup": new FormReference( "buttonGroup1" )
} )
} )
add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) {
name: "helpMenu"
"text": "Help"
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "aboutMenuItem"
"text": "About"
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "aboutActionPerformed", false ) )
} )
} )
}
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 800, 710 )
} )
add( new FormNonVisual( "javax.swing.ButtonGroup" ) {
name: "buttonGroup1"
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 720 )
} )
}
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright 2019 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
*
* http://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.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.net.URISyntaxException;
import javax.swing.ImageIcon;
import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.UIScale;
import com.kitfox.svg.app.beans.SVGIcon;
/**
* @author Karl Tauber
*/
public class ScaledSVGIcon
extends ImageIcon
{
private final SVGIcon svgIcon;
public ScaledSVGIcon( String name ) {
svgIcon = new SVGIcon();
svgIcon.setAntiAlias( true );
try {
svgIcon.setSvgURI( getClass().getResource( name ).toURI() );
} catch( URISyntaxException ex ) {
ex.printStackTrace();
}
}
@Override
public int getIconWidth() {
return UIScale.scale( svgIcon.getIconWidth() );
}
@Override
public int getIconHeight() {
return UIScale.scale( svgIcon.getIconHeight() );
}
@Override
public void paintIcon( Component c, Graphics g, int x, int y ) {
Graphics2D g2 = (Graphics2D) g.create();
try {
FlatUIUtils.setRenderingHints( g2 );
g2.translate( x, y );
UIScale.scaleGraphics( g2 );
svgIcon.paintIcon( c, g2, 0, 0 );
} finally {
g2.dispose();
}
}
@Override
public Image getImage() {
BufferedImage image = new BufferedImage( getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB );
Graphics2D g = image.createGraphics();
try {
paintIcon( null, g, 0, 0 );
} finally {
g.dispose();
}
return image;
}
}