[Nextobjects-devel] nextobjects/nextobjects/src/org/devaki/nextobjects/ui/workspace/models/objects L
Status: Alpha
Brought to you by:
eflorent
|
From: <efl...@us...> - 2003-06-08 09:46:34
|
Update of /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/ui/workspace/models/objects
In directory sc8-pr-cvs1:/tmp/cvs-serv1772
Added Files:
LabelEdit.java
Log Message:
Added Files:
LabelEdit.java
--- NEW FILE: LabelEdit.java ---
/*
nextobjects Copyright (C) 2001-2005 Laurent Thevenet,Emmanuel Florent
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 2 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, write to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.devaki.nextobjects.ui.workspace.models.objects;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import org.devaki.nextobjects.NextObjects;
import org.devaki.nextobjects.ui.components.CustomButton;
import org.devaki.nextobjects.ui.components.CustomTextArea;
import org.devaki.nextobjects.ui.components.CustomTextField;
import org.devaki.nextobjects.workspace.models.objects.Label;
/**
* Edit a note on the models
* @author eflorent
*/
public class LabelEdit extends JDialog
{
/**
* the label
*/
private Label myLabel;
/**
* the ok button
*/
private CustomButton jButtonOK = new CustomButton("OK", "", true, false);
/**
* the cancel button
*/
private CustomButton jButtonCancel =
new CustomButton("Cancel", "", true, false);
/**
* the main jpanel
*/
private JPanel jPanelGeneral = new JPanel(new GridBagLayout());
/**
* jlabel name
*/
private JLabel jLabelName = new JLabel("Name");
/**
* jlabel description
*/
private JLabel jLabelDescription = new JLabel("Description");
/**
* jtextfield name
*/
private CustomTextField jTextFieldName =
new CustomTextField("", "Name of the association in the schema", true);
/**
* jtextarea description
*/
private CustomTextArea jTextAreaDescription =
new CustomTextArea("", "Description of the association", true, true);
/**
* the tablbed pane
*/
private JTabbedPane jTabbedPane = new JTabbedPane(SwingConstants.TOP);
/**
* the unique panel
*/
private JPanel jPanelNotes = new JPanel(new GridBagLayout());
/**
* Create a new 'LabelEdit' object
*/
public LabelEdit()
{
super(NextObjects.getReference());
this.jLabelDescription.setBorder(null);
this.jLabelName.setBorder(null);
/** Initialization **/
// Define the size of the window
this.setSize(new Dimension(475, 500));
// Center the window
this.setLocationRelativeTo(null);
// Specify that the window is modal
this.setModal(true);
// Specify that the window is not resizable
this.setResizable(false);
// Define what to do when closing this window using the cross button
this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
/** Components properties **/
// PANELS
// Set a GridBagLayout for the content panel
this.getContentPane().setLayout(new GridBagLayout());
// Create titled borders for some panels
/** Listeners **/
// FOCUS
this.jTextFieldName.addFocusListener(new FocusAdapter()
{
// Select the content of 'jTextFieldName' when it gained focus
public void focusGained(FocusEvent e)
{
jTextFieldName.selectAll();
}
});
this.jButtonOK.addActionListener(new ActionListener()
{
// When calling 'jButtonOK', save data and close the window
public void actionPerformed(ActionEvent e)
{
closingWindow(true);
}
});
this.jButtonCancel.addActionListener(new ActionListener()
{
// When calling 'jButtonCancel', close the dialog without saving
public void actionPerformed(ActionEvent e)
{
closingWindow(false);
}
});
// 'jPanelNotes'
this.jPanelNotes.add(
this.jLabelName,
new GridBagConstraints(
0,
0,
1,
1,
0.0,
0.0,
GridBagConstraints.NORTH,
GridBagConstraints.BOTH,
new Insets(5, 5, 5, 5),
0,
0));
this.jPanelNotes.add(
this.jTextFieldName,
new GridBagConstraints(
1,
0,
1,
1,
0.0,
0.0,
GridBagConstraints.NORTH,
GridBagConstraints.BOTH,
new Insets(5, 5, 5, 5),
0,
0));
// 'jPanelNotes'
this.jPanelNotes.add(
new JScrollPane(this.jTextAreaDescription),
new GridBagConstraints(
0,
1,
2,
2,
1.0,
1.0,
GridBagConstraints.CENTER,
GridBagConstraints.BOTH,
new Insets(5, 5, 5, 5),
0,
0));
this.jTabbedPane.add(this.jPanelNotes, "Notes");
// Content Panel
this.getContentPane().add(
this.jTabbedPane,
new GridBagConstraints(
0,
0,
2,
1,
1.0,
1.0,
GridBagConstraints.CENTER,
GridBagConstraints.BOTH,
new Insets(5, 5, 0, 5),
0,
0));
this.getContentPane().add(
this.jButtonOK,
new GridBagConstraints(
0,
1,
1,
1,
1.0,
0.0,
GridBagConstraints.EAST,
GridBagConstraints.NONE,
new Insets(5, 5, 5, 5),
0,
0));
this.getContentPane().add(
this.jButtonCancel,
new GridBagConstraints(
1,
1,
1,
1,
0.0,
0.0,
GridBagConstraints.CENTER,
GridBagConstraints.NONE,
new Insets(5, 0, 5, 5),
0,
0));
} // End of 'AssociationEdit()'
/**
* What to do before closing the window
* @param isOK can save
*/
private void closingWindow(boolean isOK)
{
// Save data if this method follows an action on 'jButtonOK'
if (isOK)
{
this.saveData();
}
// Dispose window (unallocate resources) - show() must be call to set the
// window visible again
this.dispose();
}
/**
* Enable or disable the 'OK' button depending on the length of
* 'jTextFieldName' and 'jTextFieldCode'
*/
private void enablingOKButton()
{
if ((this.jTextFieldName.getText().length() != 0)
&& (this.jTextAreaDescription.getText().length() != 0))
{
// Both text fields length are different from zero, so enable 'jButtonOK'
this.jButtonOK.setEnabled(true);
}
// One or both text fields length are equal to zero, so diable 'jButtonOK'
else
{
this.jButtonOK.setEnabled(false);
}
}
/**
* Initialize window components with the data of the object given as
* parameter of the constructor
* @param pLabel the context label
*/
public void setData(Label pLabel)
{
// Define title of the window
this.setTitle(
new StringBuffer()
.append("Properties of '")
.append(pLabel.getName())
.append("' - devaki-nextobjects")
.toString());
// Initialize the local reference of the edited object
this.myLabel = pLabel;
this.jTextFieldName.setText(pLabel.getName());
this.jTextAreaDescription.setText(pLabel.getDescription());
// Set 'General', the active tab when opening the dialog box
this.jTabbedPane.setSelectedIndex(0);
// Set 'jButtonOK' as the default button
this.getRootPane().setDefaultButton(this.jButtonOK);
// Make the window visible
this.show();
}
/**
* Save the informations into the edited object
*/
private void saveData()
{
this.myLabel.setName(this.jTextFieldName.getText());
this.myLabel.setDescription(this.jTextAreaDescription.getText());
}
}
|