package main;
import java.awt.Component;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import org.apache.log4j.Logger;
import constants.StringConstants;
import helper.FocusTraversalOnArray;
public class ExecutorConfiguradorAlertasEstoque extends JFrame {
private final static Logger log = Logger
.getLogger(ExecutorConfiguradorAlertasEstoque.class);
private static final long serialVersionUID = 8225254197047480128L;
/**
* Launch the application.
*/
public static void main(final String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
final ExecutorConfiguradorAlertasEstoque frame = new ExecutorConfiguradorAlertasEstoque();
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
} catch (final Exception e) {
e.printStackTrace();
}
}
});
}
private JButton botaoAdicionarEmail = null;
private JButton botaoAdicionarReferencia = null;
private JButton botaoBuscar = null;
private JButton botaoDesativar = null;
private JButton botaoExcluirEmail = null;
private JButton botaoExcluirReferencia = null;
private JButton botaoNovo = null;
private JButton botaoSalvar = null;
private JCheckBox checkBoxAtivo = null;
private JComboBox comboAlertas = null;
private JComboBox comboLoja = null;
private JLabel labelEmail = null;
private JLabel labelIdLoja = null;
private JLabel labelLoja = null;
private JLabel labelMargem = null;
private JLabel labelNome = null;
private JLabel labelReferencia = null;
private JPanel painelAlertas = null;
private JPanel painelBusca = null;
private JPanel painelConteudo = null;
private JScrollPane painelScrollTabelaAlerta = null;
private JScrollPane painelScrollTabelaEmail = null;
private JTable tabelaEmail = null;
private JTable tabelaReferencia = null;
private JTextField textoEmail = null;
private JTextField textoIdLoja = null;
private JTextField textoMargem = null;
private JTextField textoNomeAlerta = null;
private JTextField textoReferencia = null;
/**
* Create the frame.
*/
private ExecutorConfiguradorAlertasEstoque() {
super();
UIManager.put(StringConstants.GLOBAL_ACAO_DEFAULT_BOTOES, Boolean.TRUE);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (final ClassNotFoundException e) {
ExecutorConfiguradorAlertasEstoque.log
.error(StringConstants.GLOBAL_FALHA_LAYOUT_WINDOWS);
} catch (final InstantiationException e) {
ExecutorConfiguradorAlertasEstoque.log
.error(StringConstants.GLOBAL_FALHA_LAYOUT_WINDOWS);
} catch (final IllegalAccessException e) {
ExecutorConfiguradorAlertasEstoque.log
.error(StringConstants.GLOBAL_FALHA_LAYOUT_WINDOWS);
} catch (final UnsupportedLookAndFeelException e) {
ExecutorConfiguradorAlertasEstoque.log
.error(StringConstants.GLOBAL_FALHA_LAYOUT_WINDOWS);
}
this.initialize();
}
private JButton getBotaoAdicionarEmail() {
if (this.botaoAdicionarEmail == null) {
this.botaoAdicionarEmail = new JButton(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_ADICIONAR);
this.botaoAdicionarEmail.setBounds(400, 160, 78, 20);
}
return this.botaoAdicionarEmail;
}
private JButton getBotaoAdicionarReferencia() {
if (this.botaoAdicionarReferencia == null) {
this.botaoAdicionarReferencia = new JButton(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_ADICIONAR);
this.botaoAdicionarReferencia.setBounds(400, 63, 78, 20);
}
return this.botaoAdicionarReferencia;
}
private JButton getBotaoBuscar() {
if (this.botaoBuscar == null) {
this.botaoBuscar = new JButton(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_BUSCAR);
this.botaoBuscar
.setIcon(new ImageIcon(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_CAMINHO_ICONE_BOTAO_BUSCAR));
this.botaoBuscar.setBounds(142, 15, 86, 22);
}
return this.botaoBuscar;
}
private JButton getBotaoDesativar() {
if (this.botaoDesativar == null) {
this.botaoDesativar = new JButton(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_DESATIVAR);
this.botaoDesativar.setBounds(74, 259, 80, 20);
}
return this.botaoDesativar;
}
private JButton getBotaoExcluirEmail() {
if (this.botaoExcluirEmail == null) {
this.botaoExcluirEmail = new JButton(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_EXCLUIR);
this.botaoExcluirEmail.setBounds(480, 160, 65, 20);
}
return this.botaoExcluirEmail;
}
private JButton getBotaoExcluirReferencia() {
if (this.botaoExcluirReferencia == null) {
this.botaoExcluirReferencia = new JButton(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_EXCLUIR);
this.botaoExcluirReferencia.setBounds(480, 63, 65, 20);
}
return this.botaoExcluirReferencia;
}
private JButton getBotaoNovo() {
if (this.botaoNovo == null) {
this.botaoNovo = new JButton(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_NOVO);
this.botaoNovo.setBounds(536, 57, 59, 23);
}
return this.botaoNovo;
}
private JButton getBotaoSalvar() {
if (this.botaoSalvar == null) {
this.botaoSalvar = new JButton(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_SALVAR);
this.botaoSalvar.setBounds(8, 259, 64, 20);
}
return this.botaoSalvar;
}
private JCheckBox getCheckBoxAtivo() {
if (this.checkBoxAtivo == null) {
this.checkBoxAtivo = new JCheckBox(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_CHECKBOX_ATIVO);
this.checkBoxAtivo.setBounds(318, 39, 50, 20);
}
return this.checkBoxAtivo;
}
private JComboBox getComboAlertas() {
if (this.comboAlertas == null) {
this.comboAlertas = new JComboBox();
this.comboAlertas.setMaximumRowCount(4);
this.comboAlertas.setBounds(233, 15, 202, 22);
}
return this.comboAlertas;
}
private JComboBox getComboLoja() {
if (this.comboLoja == null) {
this.comboLoja = new JComboBox();
this.comboLoja.setMaximumRowCount(4);
this.comboLoja.setBounds(66, 15, 150, 22);
}
return this.comboLoja;
}
private JLabel getLabelEmail() {
if (this.labelEmail == null) {
this.labelEmail = new JLabel(StringConstants.GLOBAL_EMAIL);
this.labelEmail.setBounds(8, 160, 46, 20);
}
return this.labelEmail;
}
private JLabel getLabelIdLoja() {
if (this.labelIdLoja == null) {
this.labelIdLoja = new JLabel(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_ID_LOJA);
this.labelIdLoja.setBounds(8, 16, 46, 20);
}
return this.labelIdLoja;
}
private JLabel getLabelLoja() {
if (this.labelLoja == null) {
this.labelLoja = new JLabel(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_LOJA);
this.labelLoja.setBounds(8, 16, 24, 20);
}
return this.labelLoja;
}
private JLabel getLabelMargem() {
if (this.labelMargem == null) {
this.labelMargem = new JLabel(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_MARGEM);
this.labelMargem.setBounds(200, 64, 46, 20);
}
return this.labelMargem;
}
private JLabel getLabelNome() {
if (this.labelNome == null) {
this.labelNome = new JLabel(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_NOME);
this.labelNome.setBounds(8, 40, 32, 20);
}
return this.labelNome;
}
private JLabel getLabelReferencia() {
if (this.labelReferencia == null) {
this.labelReferencia = new JLabel(StringConstants.GLOBAL_REFERENCIA);
this.labelReferencia.setBounds(8, 64, 58, 20);
}
return this.labelReferencia;
}
private JPanel getPainelAlertas() {
if (this.painelAlertas == null) {
this.painelAlertas = new JPanel();
this.painelAlertas.setBounds(0, 83, 595, 284);
this.painelAlertas
.setBorder(new TitledBorder(
null,
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LEGEND_FIELDSET_ALERTA,
TitledBorder.LEADING, TitledBorder.TOP, null, null));
this.painelAlertas.setLayout(null);
this.painelAlertas.add(this.getLabelLoja());
this.painelAlertas.add(this.getComboLoja());
this.painelAlertas.add(this.getLabelNome());
this.painelAlertas.add(this.getTextoNomeAlerta());
this.painelAlertas.add(this.getCheckBoxAtivo());
this.painelAlertas.add(this.getLabelReferencia());
this.painelAlertas.add(this.getTextoReferencia());
this.painelAlertas.add(this.getLabelMargem());
this.painelAlertas.add(this.getTextoMargem());
this.painelAlertas.add(this.getBotaoAdicionarReferencia());
this.painelAlertas.add(this.getBotaoExcluirReferencia());
this.painelAlertas.add(this.getPainelScrollTabelaAlerta());
this.painelAlertas.add(this.getLabelEmail());
this.painelAlertas.add(this.getTextoEmail());
this.painelAlertas.add(this.getBotaoAdicionarEmail());
this.painelAlertas.add(this.getBotaoExcluirEmail());
this.painelAlertas.add(this.getPainelScrollTabelaEmail());
this.painelAlertas.add(this.getBotaoSalvar());
this.painelAlertas.add(this.getBotaoDesativar());
}
return this.painelAlertas;
}
private JPanel getPainelBusca() {
if (this.painelBusca == null) {
this.painelBusca = new JPanel();
this.painelBusca.setBounds(0, 0, 595, 54);
this.painelBusca
.setBorder(new TitledBorder(
null,
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LEGEND_FIELDSET_BUSCA,
TitledBorder.LEADING, TitledBorder.TOP, null, null));
this.painelBusca.setLayout(null);
// Adicionando componente ao painel.
this.painelBusca.add(this.getLabelIdLoja());
// Adicionando componente ao painel.
this.painelBusca.add(this.getTextoIdLoja());
// Adicionando componente ao painel.
this.painelBusca.add(this.getBotaoBuscar());
// Adicionando componente ao painel.
this.painelBusca.add(this.getComboAlertas());
}
return this.painelBusca;
}
private JPanel getPainelConteudo() {
if (this.painelConteudo == null) {
this.painelConteudo = new JPanel();
this.painelConteudo.setLayout(null);
// Adicionando componente ao painel.
this.painelConteudo.add(this.getPainelBusca());
// Adicionando componente ao painel.
this.painelConteudo.add(this.getPainelAlertas());
this.painelConteudo.add(this.getBotaoNovo());
this.painelConteudo
.setFocusTraversalPolicy(new FocusTraversalOnArray(
new Component[] { this.getTextoIdLoja(),
this.getBotaoBuscar(),
this.getComboAlertas() }));
}
return this.painelConteudo;
}
private JScrollPane getPainelScrollTabelaAlerta() {
if (this.painelScrollTabelaAlerta == null) {
final JTable tabelaReferenciaVar = this.getTabelaReferencia();
this.painelScrollTabelaAlerta = new JScrollPane(tabelaReferenciaVar);
this.painelScrollTabelaAlerta
.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
this.painelScrollTabelaAlerta.setBounds(8, 87, 582, 71);
this.painelScrollTabelaAlerta.setPreferredSize(tabelaReferenciaVar
.getPreferredSize());
}
return this.painelScrollTabelaAlerta;
}
private JScrollPane getPainelScrollTabelaEmail() {
if (this.painelScrollTabelaEmail == null) {
this.painelScrollTabelaEmail = new JScrollPane(
this.getTabelaEmail());
this.painelScrollTabelaEmail
.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
this.painelScrollTabelaEmail.setBounds(8, 182, 582, 71);
}
return this.painelScrollTabelaEmail;
}
private JTable getTabelaEmail() {
if (this.tabelaEmail == null) {
this.tabelaEmail = new JTable();
this.tabelaEmail.setEnabled(false);
this.tabelaEmail.setModel(new DefaultTableModel(new Object[][] {
{ null, null }, { null, null }, { null, null }, },
new String[] { StringConstants.GLOBAL_ESPACO,
StringConstants.GLOBAL_EMAIL }) {
/**
*
*/
private static final long serialVersionUID = 1031830474249153406L;
boolean[] columnEditables = new boolean[] { false, false };
Class<?>[] columnTypes = new Class[] { Boolean.class,
String.class };
@Override
public Class<?> getColumnClass(final int columnIndex) {
return this.columnTypes[columnIndex];
}
@Override
public boolean isCellEditable(
@SuppressWarnings("unused") final int row,
final int column) {
return this.columnEditables[column];
}
});
final TableColumnModel colunas = this.tabelaEmail.getColumnModel();
final TableColumn coluna = colunas.getColumn(0);
coluna.setResizable(false);
coluna.setPreferredWidth(15);
final TableColumn colunaEmail = colunas.getColumn(1);
colunaEmail.setResizable(false);
colunaEmail.setPreferredWidth(567);
}
return this.tabelaEmail;
}
private JTable getTabelaReferencia() {
if (this.tabelaReferencia == null) {
this.tabelaReferencia = new JTable();
this.tabelaReferencia.setEnabled(false);
this.tabelaReferencia
.setModel(new DefaultTableModel(
new Object[][] { { null, null, null, null },
{ null, null, null, null },
{ null, null, null, null }, },
new String[] {
StringConstants.GLOBAL_ESPACO,
StringConstants.GLOBAL_REFERENCIA,
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_CABECALHO_TABELA_REFERENCIA_COLUNA_DESCRICAO,
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_CABECALHO_TABELA_REFERENCIA_COLUNA_MARGEM_SEGURANCA }) {
/**
*
*/
private static final long serialVersionUID = 8037678798262562338L;
boolean[] columnEditables = new boolean[] { false,
false, false, false };
Class<?>[] columnTypes = new Class[] { Boolean.class,
Integer.class, String.class, Integer.class };
@Override
public Class<?> getColumnClass(final int columnIndex) {
return this.columnTypes[columnIndex];
}
@Override
public boolean isCellEditable(
@SuppressWarnings("unused") final int row,
final int column) {
return this.columnEditables[column];
}
});
final TableColumnModel colunas = this.tabelaReferencia
.getColumnModel();
final TableColumn coluna = colunas.getColumn(0);
coluna.setResizable(false);
coluna.setPreferredWidth(15);
final TableColumn colunaReferencia = colunas.getColumn(1);
colunaReferencia.setResizable(false);
colunaReferencia.setPreferredWidth(60);
final TableColumn colunaDescricao = colunas.getColumn(2);
colunaDescricao.setResizable(false);
colunaDescricao.setPreferredWidth(400);
final TableColumn colunaMargem = colunas.getColumn(3);
colunaMargem.setResizable(false);
colunaMargem.setPreferredWidth(107);
}
return this.tabelaReferencia;
}
private JTextField getTextoEmail() {
if (this.textoEmail == null) {
this.textoEmail = new JTextField();
this.textoEmail.setBounds(63, 160, 250, 20);
this.textoEmail.setColumns(10);
}
return this.textoEmail;
}
private JTextField getTextoIdLoja() {
if (this.textoIdLoja == null) {
this.textoIdLoja = new JTextField();
this.textoIdLoja.setBounds(48, 15, 86, 22);
this.textoIdLoja.setColumns(10);
}
return this.textoIdLoja;
}
private JTextField getTextoMargem() {
if (this.textoMargem == null) {
this.textoMargem = new JTextField();
this.textoMargem.setBounds(248, 63, 86, 20);
this.textoMargem.setColumns(10);
}
return this.textoMargem;
}
private JTextField getTextoNomeAlerta() {
if (this.textoNomeAlerta == null) {
this.textoNomeAlerta = new JTextField();
this.textoNomeAlerta.setBounds(66, 39, 250, 22);
this.textoNomeAlerta.setColumns(30);
}
return this.textoNomeAlerta;
}
private JTextField getTextoReferencia() {
if (this.textoReferencia == null) {
this.textoReferencia = new JTextField();
this.textoReferencia.setBounds(66, 63, 100, 20);
this.textoReferencia.setColumns(10);
}
return this.textoReferencia;
}
/**
*
*/
private void initialize() {
this.setBounds(100, 100, 600, 390);
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
this.setIconImage(Toolkit
.getDefaultToolkit()
.getImage(
StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_CAMINHO_ICONE_TELA));
this.setContentPane(this.getPainelConteudo());
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setTitle(StringConstants.GLOBAL_TITULO_SISTEMA);
this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(
@SuppressWarnings("unused") final WindowEvent e) {
if (JOptionPane.showOptionDialog(
ExecutorConfiguradorAlertasEstoque.this,
StringConstants.GLOBAL_DESEJA_REALMENTE_SAIR,
StringConstants.GLOBAL_TITULO_SISTEMA,
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null) == JOptionPane.YES_OPTION) {
ExecutorConfiguradorAlertasEstoque.this.dispose();
}
}
});
}
}
Lembrando que esta tela do sistema ainda está toda crua, sem funcionalidade alguma...
Gostaria de que se possível olhassem o código e apontassem melhorias.
Já estou estudando o framework ObjectTableModel para usar aqui ao invés de DefaultTableModel.
Me falaram também que no projeto Towel existe um gerenciador de eventos que é algo que muito me interessa. Acho muito "feio" ficar em cada objeto Component implementando ActionListeners, FocusListeners, KeyListeners e etc.
Em anexo segue o ícone do botão buscar, não posso botar a logomarca da empresa, mas isso não é problema, é só substituir a imagem que eu uso por outra no teste de vocês.
