/* * EuroCarbDB, a framework for carbohydrate bioinformatics * * Copyright (c) 2006-2009, Eurocarb project, or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * A copy of this license accompanies this distribution in the file LICENSE.txt. * * 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 Lesser General Public License * for more details. * * Last commit: $Rev: 1210 $ by $Author: glycoslave $ on $Date:: 2009-06-12 #$ */ package org.eurocarbdb.application.glycanbuilder; import javax.swing.*; /** Dialog to set the range of a repeating block @author Alessio Ceroni (a.ceroni@imperial.ac.uk) */ public class RepetitionPropertiesDialog extends EscapeDialog implements java.awt.event.ActionListener, java.awt.event.ItemListener { // data members private Residue current; private GlycanDocument theDoc; /** Create a new dialog @param parent the parent frame @param _current the residue representing the end of the repeat block @param _theDoc the document containing the residue and its structure. The document will be notified of the change in the properties of the residue */ public RepetitionPropertiesDialog(java.awt.Frame parent, Residue _current, GlycanDocument _theDoc) { super(parent, true); // set data current = _current; theDoc = _theDoc; // init values initComponents(); fillComponents(); setTraversal(); setActions(); enableItems(); // set location setLocationRelativeTo(parent); } private void fillComponents() { field_min_rep.setText("" + current.getMinRepetitions()); field_max_rep.setText("" + current.getMaxRepetitions()); } private void setTraversal() { CustomFocusTraversalPolicy tp = new CustomFocusTraversalPolicy(); tp.addComponent(field_min_rep); tp.addComponent(field_max_rep); tp.addComponent(button_ok); tp.addComponent(button_cancel); this.setFocusTraversalPolicy(tp); getRootPane().setDefaultButton(button_ok); } private void setActions() { button_ok.addActionListener(this); button_cancel.addActionListener(this); } private void enableItems() { } private void retrieveData() { String min_rep = field_min_rep.getText(); String max_rep = field_max_rep.getText(); current.setMinRepetitions(min_rep); current.setMaxRepetitions(max_rep); theDoc.fireDocumentChanged(); } public void actionPerformed(java.awt.event.ActionEvent e) { String action = e.getActionCommand(); if (action == "OK") { retrieveData(); closeDialog(); } else if (action == "Cancel"){ closeDialog(); } } public void itemStateChanged(java.awt.event.ItemEvent e) { enableItems(); } /** 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. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); field_min_rep = new javax.swing.JTextField(); field_max_rep = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jSeparator1 = new javax.swing.JSeparator(); button_ok = new javax.swing.JButton(); button_cancel = new javax.swing.JButton(); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(); } }); jLabel1.setText("Min repetitions"); field_min_rep.setText("jTextField1"); field_max_rep.setText("jTextField1"); jLabel2.setText("Max repetitions"); button_ok.setText("OK"); button_cancel.setText("Cancel"); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this.getContentPane()); this.getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(12, 12, 12) .add(button_ok) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(button_cancel)) .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel1) .add(jLabel2)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(field_max_rep, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE) .add(field_min_rep, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)))) .addContainerGap()) ); layout.linkSize(new java.awt.Component[] {button_cancel, button_ok}, org.jdesktop.layout.GroupLayout.HORIZONTAL); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel1) .add(field_min_rep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel2) .add(field_max_rep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(button_ok) .add(button_cancel)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents /** Closes the dialog */ private void closeDialog() {//GEN-FIRST:event_closeDialog setVisible(false); dispose(); }//GEN-LAST:event_closeDialog // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton button_cancel; private javax.swing.JButton button_ok; private javax.swing.JTextField field_max_rep; private javax.swing.JTextField field_min_rep; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JSeparator jSeparator1; // End of variables declaration//GEN-END:variables }