/****************************************************************************** * * * Copyright 2016 Subterranean Security * * * * 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.subterranean_security.crimson.viewer.ui.screen.generator; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; public class CreateDialog extends JDialog { private static final long serialVersionUID = 1L; private final JPanel contentPanel = new JPanel(); private JTextField textField; private JButton okButton; public static CreateDialog global;// to prevent the crazy user from opening // multiple dialogs public CreateDialog() { setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setResizable(false); setBounds(100, 100, 248, 148); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(null); JLabel lblName = new JLabel("Name"); lblName.setHorizontalAlignment(SwingConstants.CENTER); lblName.setBounds(12, 16, 214, 17); contentPanel.add(lblName); textField = new JTextField(); textField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { okButton.setEnabled(!textField.getText().isEmpty()); } }); textField.setBounds(40, 41, 160, 21); contentPanel.add(textField); textField.setColumns(10); { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { okButton = new JButton("Save"); okButton.setEnabled(false); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } } } }