/* * Copyright (C) 2014 Vinu K.N * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.domainmath.gui.dialog; import java.awt.Image; import java.awt.Toolkit; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; /** * * @author Vinu K.N */ public class InputDialog extends javax.swing.JDialog { /** * Creates new form ExceptionDialog */ private String secondTitle; private String input; public InputDialog(JComponent parent, boolean modal,String secondTitle,String text) { initComponents(); this.label.setText(secondTitle); setLocationRelativeTo(parent); setModal(modal); setIconImage(icon); } public InputDialog(JComponent parent, boolean modal) { initComponents(); this.label.setText(secondTitle); setLocationRelativeTo(parent); setModal(modal); setIconImage(icon); } public InputDialog(JFrame parent,boolean modal) { super(parent,modal); initComponents(); setLocationRelativeTo(parent); setModal(modal); setIconImage(icon); } public InputDialog(JComponent parent) { initComponents(); this.label.setText(secondTitle); setLocationRelativeTo(parent); setModal(true); setIconImage(icon); } public InputDialog(JFrame parent) { super(parent,true); initComponents(); setLocationRelativeTo(parent); setModal(true); setIconImage(icon); } public InputDialog(boolean modal) { initComponents(); setLocationRelativeTo(null); setModal(modal); setIconImage(icon); } public void addButton(JButton b){ this.buttonPanel.add(b); this.buttonPanel.revalidate(); } public String getSecondTitle() { return secondTitle; } public void setSecondTitle(String secondTitle) { this.secondTitle = secondTitle; this.label.setText(secondTitle); } public String getInput() { return input; } public void setInput(String input) { this.input = input; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); label = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jTextField1 = new javax.swing.JTextField(); buttonPanel = new javax.swing.JPanel(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("DomainMath IDE"); jPanel1.setBackground(new java.awt.Color(255, 155, 0)); label.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N label.setForeground(new java.awt.Color(255, 255, 255)); label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/domainmath/gui/dialogs/resources/appbar.edit.png"))); // NOI18N label.setText("Delete Test.m?"); label.setToolTipText(""); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(label, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); jPanel2.setBackground(new java.awt.Color(255, 255, 255)); jTextField1.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N jTextField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField1ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 402, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(42, 42, 42)) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(42, 42, 42) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(111, Short.MAX_VALUE)) ); buttonPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 10, 5, 10)); buttonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT)); jButton1.setText("OK"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); buttonPanel.add(jButton1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(0, 0, 0) .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed String text = this.jTextField1.getText(); if(!text.equals("")) { setInput(text); dispose(); } }//GEN-LAST:event_jButton1ActionPerformed private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed String text = this.jTextField1.getText(); if(!text.equals("")) { setInput(text); dispose(); } }//GEN-LAST:event_jTextField1ActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { } /* Create and display the dialog */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { InputDialog dialog = new InputDialog(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); } }); } public java.net.URL imgURL = getClass().getResource("/org/domainmath/gui/dialogs/resources/DomainMath.png"); public Image icon = Toolkit.getDefaultToolkit().getImage(imgURL); // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel buttonPanel; private javax.swing.JButton jButton1; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JTextField jTextField1; private javax.swing.JLabel label; // End of variables declaration//GEN-END:variables }