Limitar Atalho somente no Frame em foco

3 respostas
programaçãojava
C

Ola galera, eu sou novo no forum então me desculpem se estou fazendo algo de errado, estou com um pequeno problema em um ERP que trabalho, estou colocando a função em alguma tela de atalho de teclado, mas quando abro outra tela do sistema e clico a tecla de atalho a ação continha acontecendo na tela de traz, gostaria da ajuda de vcs para ver oque posso fazer para limitar a ação somente quando o frame estiver com focus nele

o metodo que estou utilizando é o seguinte
esta dentro do meu metodo initComponents();

KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {

public boolean dispatchKeyEvent(KeyEvent e) {

			if (e.getID() == KeyEvent.KEY_PRESSED) {

				if (e.getKeyCode() == KeyEvent.VK_F2) {
					tabPanel.setSelectedIndex(0);
					setTabComponentFocus();
				} else if (e.getKeyCode() == KeyEvent.VK_F3) {
					tabPanel.setSelectedIndex(1);
					setTabComponentFocus();
				}

			}

			return false;
		}
	});

desde ja agradeço a atenção de todos

3 Respostas

D

Para, especificamente, um jframe, não sei se tem, mas dá uma olhada aqui que tem um exemplo de como fazer para que, quando a janela tenha foco, você consiga fazer algo parecido.

S

Brother coloca o código dessa sua classe pra ter uma ideia melhor do que vc fez, é um chute, mas acredito que você está adicionando o listener no JFrame e não no Jpanel então ele acaba respondendo…

Na minha opinião vc tem duas saídas ou implementa no JPanel (vai funcionar somente se tiver focused) ou adiciona um FocusListener pra verificar o isActive() e o isFocused() do JFrame. É meio difícil te dar um exemplo sem saber a fundo seu caso, mas o caminho é esse.

Edit - Só complementando… O JFrame não possui por padrão um setFocused() ou requestFocus() porque a ideia dele é ser uma representação da tela somente, adicionar código desse tipo nele soa quase como uma gambiarra (em casos comuns), JFrame tem normalmente dentro dele um Jpanel e nele sim temos esse tipo de listener, e no seu caso cairia como uma luva sem mudar nada no seu código pra fazer isso.

C
package br.com.grampac.gui.cadastro.tarefa;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.util.Calendar;

import javax.swing.Action;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

import br.com.grampac.core.Main;
import br.com.grampac.domain.User;
import br.com.grampac.domain.tarefa.Comentario;
import br.com.grampac.domain.tarefa.Departamento;
import br.com.grampac.domain.tarefa.PeriodicidadeTarefa;
import br.com.grampac.domain.tarefa.StatusTarefa;
import br.com.grampac.domain.tarefa.Tarefa;
import br.com.grampac.domain.tarefa.TarefaProcedimento;
import br.com.grampac.domain.tarefa.TipoProcedimento;
import br.com.grampac.domain.tarefa.TipoTarefa;
import br.com.grampac.gui.components.LookupField;
import br.com.grampac.gui.tools.GUITools;
import br.com.grampac.presenter.TarefaPresenter;
import br.com.grampac.view.ViewMode;
import br.com.insidecode.commons.Dates;
import br.com.insidecode.gui.components.CalendarField;
import br.com.insidecode.gui.components.CharacterCase;
import br.com.insidecode.gui.components.EnterCheckBox;
import br.com.insidecode.gui.components.EnterComboBox;
import br.com.insidecode.gui.components.EnterRadioButton;
import br.com.insidecode.gui.components.NumericField;
import br.com.insidecode.gui.components.StringField;
import br.com.insidecode.gui.components.TextAreaField;

public class TarefaFormPanel extends JPanel {

	private static final long serialVersionUID = -7900582045545674804L;

	private JLabel idLabel = new JLabel("ID:");
	private JLabel descricaoLabel = new JLabel("Descrição:");
	private JLabel usuarioLabel = new JLabel("Executor:");
	private JLabel dataInicioLabel = new JLabel("Data inicial:");
	private JLabel dataFimLabel = new JLabel("Data final:");
	private JLabel tipoLabel = new JLabel("Tipo:");
	private JLabel periodoLabel = new JLabel("Período:");
	private JLabel statusLabel = new JLabel("Status:");
	private JLabel dataConclusaoLabel = new JLabel("Data de conclusão:");
	private JLabel dataCriacaoLabel = new JLabel("Data de criação:");
	private JLabel diaSemanaLabel = new JLabel("Dia da semana:");
	private JLabel representantesLabel = new JLabel("F3-Anexos");

	private NumericField idField;
	private TextAreaField descricaoField;
	private LookupField<User> usuarioLookupField;
	private CalendarField dataInicioField;

	private CalendarField dataFimField;
	private CalendarField dataConclusaoField;
	private CalendarField dataCriacaoField;

	private EnterComboBox tipoCombo;
	private EnterComboBox periodoCombo;
	private EnterComboBox statusCombo;
	private EnterComboBox diaSemanaCombo;

	private EnterCheckBox gerarAutoCheck;

	private ComentarioPanel comentarioPanel;
	private TarefaAnexoPanel anexosPanel;
	private JTabbedPane tabPanel;

	private JButton saveButton = new JButton("Salvar");

	private JButton cancelButton = new JButton("Cancelar");
	private JButton closeButton = new JButton("Fechar");
	private JButton commentButton = new JButton("Comentar");
	private JButton remindButton = new JButton("Lembrar");
	// Criando Componentes do Procedimentos
	private EnterRadioButton tarefaOption = new EnterRadioButton("Tarefa", true);
	private EnterRadioButton procedimentoOption = new EnterRadioButton("Procedimento", false);
	private ButtonGroup tpGroup = new ButtonGroup();
	private EnterComboBox tipoProcedimentoCombo;
	private EnterComboBox departamentoCombo;
	private JLabel assuntoLabel = new JLabel("Assunto:");
	private StringField assuntoField;
	private StringField clienteField;

	private Tarefa tarefa;

	private TarefaPanel view;

	private TarefaPresenter presenter;

	Calendar data = Calendar.getInstance();

	public TarefaFormPanel(TarefaPanel view) {
		super(new BorderLayout());

		this.view = view;

		initComponents();

		buildPanel();
	}

	private void initComponents() {

		assuntoField = new StringField(8000, CharacterCase.UPPER_CASE);
		assuntoField.setEditable(false);
		assuntoField.setVisible(false);
		
		clienteField = new StringField(8000, CharacterCase.UPPER_CASE);
		clienteField.setEditable(false);
		clienteField.setVisible(false);

		assuntoLabel.setText("         ");

		tpGroup = new ButtonGroup();
		tpGroup.add(tarefaOption);
		tpGroup.add(procedimentoOption);

		idField = new NumericField(3, "##0");
		idField.setHorizontalAlignment(JTextField.RIGHT);
		idField.setEditable(false);

		descricaoField = new TextAreaField(5, 50, 8000, CharacterCase.UPPER_CASE);

		usuarioLookupField = new LookupField<User>(3, 50);
		usuarioLookupField.setIdPropertyName("id");
		usuarioLookupField.setDescriptionPropertyName("name");

		dataInicioField = new CalendarField();
		dataInicioField.setValue(Calendar.getInstance());

		dataFimField = new CalendarField();
		dataFimField.setValue(Calendar.getInstance());

		tipoCombo = new EnterComboBox(new DefaultComboBoxModel(TipoTarefa.values()));
		tipoCombo.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				if (tipoCombo.getSelectedItem() == TipoTarefa.AVULSA) {
					periodoCombo.setEnabled(false);
					periodoCombo.setSelectedIndex(0);
					gerarAutoCheck.setSelected(false);
					gerarAutoCheck.setVisible(false);
					gerarAutoCheck.setEnabled(false);
				} else {
					periodoCombo.setEnabled(true);
					gerarAutoCheck.setSelected(true);
					gerarAutoCheck.setVisible(true);
					gerarAutoCheck.setEnabled(true);
				}
			}
		});

		DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(PeriodicidadeTarefa.values());
		comboBoxModel.insertElementAt(null, 0);
		periodoCombo = new EnterComboBox(comboBoxModel);
		periodoCombo.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				if (periodoCombo.getSelectedItem() == PeriodicidadeTarefa.SEMANAL) {
					diaSemanaCombo.setEnabled(true);
					diaSemanaCombo.setVisible(true);
					diaSemanaLabel.setVisible(true);
					diaSemanaCombo.setSelectedIndex(0);
				} else {
					diaSemanaCombo.setEnabled(false);
					diaSemanaCombo.setVisible(false);
					diaSemanaLabel.setVisible(false);
					diaSemanaCombo.setSelectedIndex(-1);
				}
			}
		});

		gerarAutoCheck = new EnterCheckBox("Gerar automaticamente", false);
		gerarAutoCheck.setEnabled(false);
		gerarAutoCheck.setVisible(false);

		statusCombo = new EnterComboBox(new DefaultComboBoxModel(StatusTarefa.values()));
		statusCombo.setEnabled(false);
		statusCombo.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				if (statusCombo.getSelectedItem() == StatusTarefa.CONCLUIDA) {
					dataConclusaoField.setValue(Calendar.getInstance());
				} else
					dataConclusaoField.setValue(null);
			}
		});

		dataConclusaoField = new CalendarField();
		dataConclusaoField.setEditable(false);

		dataCriacaoField = new CalendarField();
		dataCriacaoField.setValue(Calendar.getInstance());
		dataCriacaoField.setEditable(false);

		diaSemanaCombo = new EnterComboBox(new DefaultComboBoxModel(
				new String[] { null, "Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado" }));
		diaSemanaCombo.addItemListener(new ItemListener() {

			@Override
			public void itemStateChanged(ItemEvent e) {
				if (diaSemanaCombo.getSelectedIndex() != 0 && diaSemanaCombo.isVisible() && diaSemanaCombo.hasFocus()) {
					data = Calendar.getInstance();

					if (diaSemanaCombo.getSelectedIndex() < data.get(Calendar.DAY_OF_WEEK)) {
						dataInicioField.setValue(Dates.addDays(
								7 - (data.get(Calendar.DAY_OF_WEEK) - diaSemanaCombo.getSelectedIndex()), data));
						dataFimField.setValue(Dates.addDays(
								7 - (data.get(Calendar.DAY_OF_WEEK) - diaSemanaCombo.getSelectedIndex()), data));
					} else {
						dataInicioField.setValue(Dates
								.addDays((diaSemanaCombo.getSelectedIndex() - data.get(Calendar.DAY_OF_WEEK)), data));
						dataFimField.setValue(Dates
								.addDays((diaSemanaCombo.getSelectedIndex() - data.get(Calendar.DAY_OF_WEEK)), data));
					}
				}
			}
		});
		DefaultComboBoxModel defaultComboBoxModel = new DefaultComboBoxModel(TipoProcedimento.values());
		DefaultComboBoxModel comboBoxModel2 = defaultComboBoxModel;
		comboBoxModel2.insertElementAt(null, 0);
		tipoProcedimentoCombo = new EnterComboBox(comboBoxModel2);
		tipoProcedimentoCombo.setSelectedIndex(1);

		DefaultComboBoxModel comboboxmodel3 = new DefaultComboBoxModel(Departamento.values());
		comboboxmodel3.insertElementAt(null, 0);
		departamentoCombo = new EnterComboBox(comboboxmodel3);
		departamentoCombo.setSelectedIndex(0);

		procedimentoOption.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				tarefaOuProcedimento();
			}
		});

		tarefaOption.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				tarefaOuProcedimento();
			}
		});

		comentarioPanel = new ComentarioPanel();
		anexosPanel = new TarefaAnexoPanel(view.getPresenter());
		anexosPanel.setForeground(Color.red);
		tabPanel = buildTabPanel();
		saveButton.setActionCommand("save");
		cancelButton.setActionCommand("cancel");
		closeButton.setActionCommand("close");
		commentButton.setActionCommand("comment");
		remindButton.setActionCommand("remind");

		tabPanel.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent arg0) {
				setTabComponentFocus();
			}
		});

		KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {

			public boolean dispatchKeyEvent(KeyEvent e) {

				if (e.getID() == KeyEvent.KEY_PRESSED) {

					if (e.getKeyCode() == KeyEvent.VK_F2) {
						tabPanel.setSelectedIndex(0);
						setTabComponentFocus();
					} else if (e.getKeyCode() == KeyEvent.VK_F3) {
						tabPanel.setSelectedIndex(1);
						setTabComponentFocus();
					}

				}

				return false;
			}
		});

	}

	private void updatePermissions() {

	}

	private void setTabComponentFocus() {
		if (tabPanel.getSelectedIndex() == 0) {
			requestFocus();
		} else if (tabPanel.getSelectedIndex() == 1) {
			anexosPanel.requestFocus();
		}
	}

	private void buildPanel() {
		add(buildFormPanel(), BorderLayout.CENTER);
		add(buildButtonPanel(), BorderLayout.SOUTH);
	}

	private Component buildFormPanel() {
		FormLayout layout = new FormLayout(
				// 1 		2 		3	 4 		5 		6 	7 		8 		9 	10 11 12 13
				"p:grow, r:pref, 2dlu, 50dlu, 5dlu, 20dlu, 5dlu, r:pref, 50dlu, 5dlu, pref, 50dlu, 6dlu, 236dlu, 1dlu:grow", // columns
				// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
				"p:grow, pref, 2dlu, pref, 5dlu, pref, 5dlu, pref, 1dlu, pref, 1dlu, pref, 8dlu, pref, 20dlu, p:grow"); // rows

		PanelBuilder builder = new PanelBuilder(layout);// , new
														// FormDebugPanel());

		builder.setDefaultDialogBorder();

		// Fill the table with labels and components.
		CellConstraints cc = new CellConstraints();

		int row = 1;
		builder.addSeparator("Tarefa / Procedimento", cc.xyw(14, row, 2));

		row += 1;
		builder.add(idLabel, cc.xy(2, row));
		builder.add(idField, cc.xyw(4, row, 1));
		builder.add(buildOpcoesTP(), cc.xyw(14, row, 2));

		row += 2;
		builder.add(assuntoLabel, cc.xy(2, row));
		builder.add(assuntoField, cc.xyw(4, row, 11));

		row += 2;
		builder.add(descricaoLabel, cc.xy(2, row));
		builder.add(new JScrollPane(descricaoField), cc.xyw(4, row, 11));

		row += 2;
		builder.add(usuarioLabel, cc.xy(2, row));
		builder.add(usuarioLookupField, cc.xyw(4, row, 7));

		row += 2;
		builder.add(dataInicioLabel, cc.xy(2, row));
		builder.add(dataInicioField, cc.xy(4, row));

		builder.add(dataFimLabel, cc.xy(8, row));
		builder.add(dataFimField, cc.xy(9, row));
		
		builder.add(clienteField, cc.xy(11, row));

		row += 2;
		builder.add(tipoLabel, cc.xy(2, row));
		builder.add(tipoCombo, cc.xyw(4, row, 3));
		builder.add(tipoProcedimentoCombo, cc.xyw(4, row, 3));

		builder.add(periodoLabel, cc.xy(8, row));
		builder.add(periodoCombo, cc.xy(9, row));

		builder.add(diaSemanaLabel, cc.xy(11, row));
		builder.add(diaSemanaCombo, cc.xy(12, row));

		builder.add(gerarAutoCheck, cc.xyw(14, row, 2));

		row += 2;
		builder.add(statusLabel, cc.xy(2, row));
		builder.add(statusCombo, cc.xyw(4, row, 3));
		builder.add(departamentoCombo, cc.xyw(4, row, 3));

		builder.add(dataConclusaoLabel, cc.xy(8, row));
		builder.add(dataConclusaoField, cc.xy(9, row));

		builder.add(dataCriacaoLabel, cc.xy(11, row));
		builder.add(dataCriacaoField, cc.xy(12, row));

		row += 2;
		builder.add(tabPanel, cc.xyw(1, row, 14));

		return builder.getPanel();
	}

	public LookupField<User> getUsuarioLookupField() {
		return usuarioLookupField;
	}

	public ComentarioPanel getComentarioPanel() {
		return comentarioPanel;
	}

	private JPanel buildButtonPanel() {
		JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));

		panel.add(remindButton);
		panel.add(commentButton);
		panel.add(saveButton);
		panel.add(cancelButton);
		panel.add(closeButton);

		return panel;
	}

	private JTabbedPane buildTabPanel() {
		JTabbedPane panel = new JTabbedPane();

		// panel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
		panel.add("F2-Comentários", comentarioPanel);
		panel.add("F3-Anexos", anexosPanel);

		return panel;
	}

	public void addActionListener(ActionListener listener) {

		saveButton.addActionListener(listener);
		cancelButton.addActionListener(listener);
		closeButton.addActionListener(listener);
		commentButton.addActionListener(listener);
		remindButton.addActionListener(listener);
		comentarioPanel.addActionListener(listener);
	}

	public void clear() {
		idField.clear();
		descricaoField.clear();
		usuarioLookupField.clear();
		dataInicioField.clear();
		dataFimField.clear();
		dataInicioField.setValue(Calendar.getInstance());
		dataFimField.setValue(Calendar.getInstance());
		tipoCombo.setSelectedIndex(0);
		periodoCombo.setSelectedIndex(-1);
		diaSemanaCombo.setSelectedIndex(-1);
		statusCombo.setSelectedIndex(0);
		dataConclusaoField.clear();
		gerarAutoCheck.setSelected(false);
		anexosPanel.clear();
		tabPanel.setSelectedIndex(0);
		representantesLabel.setForeground(Color.black);
		tabPanel.setTabComponentAt(1, representantesLabel);
		procedimentoOption.setSelected(false);
		assuntoField.clear();
		clienteField.clear();
		departamentoCombo.setSelectedIndex(0);
		tipoProcedimentoCombo.setSelectedIndex(0);

	}

	public void lock() {
		idField.setEditable(false);
		descricaoField.setEditable(false);
		usuarioLookupField.setEnabled(false);
		dataInicioField.setEditable(false);
		dataFimField.setEditable(false);
		tipoCombo.setEnabled(false);
		periodoCombo.setEnabled(false);
		diaSemanaCombo.setEnabled(false);
		gerarAutoCheck.setEnabled(false);
		statusCombo.setEnabled(false);
		dataConclusaoField.setEditable(false);

		saveButton.setVisible(true);
		cancelButton.setText("F8 -Cancelar");
		commentButton.setVisible(false);
		remindButton.setVisible(false);

		if (view.getMode() == ViewMode.SHOW) {

			commentButton.setVisible(true);
			remindButton.setVisible(true);
			saveButton.setVisible(false);
			cancelButton.setText("Voltar");
			tarefaOption.setEnabled(false);
			procedimentoOption.setEnabled(false);
		}

		anexosPanel.disableFields();
	}

	public void unlockCriador() {
		idField.setEditable(false);
		descricaoField.setEditable(true);
		usuarioLookupField.setEnabled(true);
		dataInicioField.setEditable(true);
		dataFimField.setEditable(true);
		tipoCombo.setEnabled(true);
		statusCombo.setEnabled(true);
		commentButton.setVisible(true);
		remindButton.setVisible(true);
		saveButton.setVisible(true);
		cancelButton.setText("Cancelar");

		if (view.getMode() == ViewMode.NEW) {
			commentButton.setVisible(false);
			remindButton.setVisible(false);
			tarefaOption.setEnabled(true);
			tarefaOption.isSelected();
			procedimentoOption.setEnabled(true);

		}
		if (view.getMode() == ViewMode.EDIT) {
			tarefaOption.setEnabled(false);
			procedimentoOption.setEnabled(false);
		}

		anexosPanel.enableFields();
	}

	public void unlock() {
		idField.setEditable(false);
		descricaoField.setEditable(false);
		usuarioLookupField.setEnabled(false);
		dataInicioField.setEditable(false);
		dataFimField.setEditable(false);
		tipoCombo.setEnabled(false);
		periodoCombo.setEnabled(false);
		diaSemanaCombo.setEnabled(false);
		gerarAutoCheck.setEnabled(false);
		statusCombo.setEnabled(true);
		commentButton.setVisible(true);
		remindButton.setVisible(true);
		saveButton.setVisible(true);
		cancelButton.setText("Cancelar");

		if (view.getMode() == ViewMode.NEW) {
			commentButton.setVisible(false);

		}

		anexosPanel.enableFields();
	}

	private Container buildOpcoesTP() {
		FormLayout layout = new FormLayout(
				// 1 2 3
				"pref, 2dlu, pref, 2dlu, pref", // columns
				"pref"); // rows

		PanelBuilder builder = new PanelBuilder(layout);
		CellConstraints cc = new CellConstraints();

		int row = 1;

		builder.add(tarefaOption, cc.xy(1, row));
		builder.add(procedimentoOption, cc.xy(5, row));

		return builder.getPanel();
	}

	public Tarefa getBean() {
		tarefa.setId(idField.getIntegerValue());
		tarefa.setDescricao(descricaoField.getValue());
		tarefa.setUsuario(usuarioLookupField.getValue());
		tarefa.setDataInicial(dataInicioField.getCalendar());
		tarefa.setDataFinal(dataFimField.getCalendar());
		tarefa.setTipo((TipoTarefa) tipoCombo.getSelectedItem());
		tarefa.setPeriodicidade((PeriodicidadeTarefa) periodoCombo.getSelectedItem());
		tarefa.setDiaSemana(diaSemanaCombo.getSelectedIndex());
		tarefa.setGerarAuto(gerarAutoCheck.isSelected());
		tarefa.setStatus((StatusTarefa) statusCombo.getSelectedItem());
		tarefa.setDataConclusao(dataConclusaoField.getCalendar());
		tarefa.setDataCriacao(dataCriacaoField.getCalendar());
		tarefa.setAnexos(anexosPanel.getAnexos());
		tarefa.setAssunto(assuntoField.getValue());
		tarefa.setCliente(clienteField.getValue());
		tarefa.setTipoProcedimento((TipoProcedimento) tipoProcedimentoCombo.getSelectedItem());
		tarefa.setDepartamento((Departamento) departamentoCombo.getSelectedItem());
		tarefa.setTarefaProcedimento(
		tarefaOption.isSelected() ? TarefaProcedimento.TAREFA : TarefaProcedimento.PROCEDIMENTO);

		return tarefa;
	}

	public void setBean(Tarefa bean) {
		this.tarefa = bean;

		clear();

		idField.setValue(tarefa.getId());
		descricaoField.setValue(tarefa.getDescricao());
		assuntoField.setValue(tarefa.getAssunto());
		clienteField.setValue(tarefa.getCliente());
		usuarioLookupField.setValue(tarefa.getUsuario());
		dataInicioField.setValue(tarefa.getDataInicial());
		dataFimField.setValue(tarefa.getDataFinal());
		tipoCombo.setSelectedItem(tarefa.getTipo());
		periodoCombo.setSelectedItem(tarefa.getPeriodicidade());
		diaSemanaCombo.setSelectedIndex(tarefa.getDiaSemana());
		gerarAutoCheck.setSelected(tarefa.isGerarAuto());
		statusCombo.setSelectedItem(tarefa.getStatus());
		dataConclusaoField.setValue(tarefa.getDataConclusao());
		dataCriacaoField.setValue(tarefa.getDataCriacao());
		tipoProcedimentoCombo.setSelectedItem(tarefa.getTarefaProcedimento());
		departamentoCombo.setSelectedItem(tarefa.getDepartamento());
		tipoProcedimentoCombo.setSelectedItem(tarefa.getTipoProcedimento());
		comentarioPanel.setBean(tarefa);
		tarefaOption.setSelected(tarefa.getTarefaProcedimento() == TarefaProcedimento.TAREFA);
		procedimentoOption.setSelected(tarefa.getTarefaProcedimento() == TarefaProcedimento.PROCEDIMENTO);
		tarefaOuProcedimento();

		int qtde = anexosPanel.setBean(tarefa);

		if (qtde > 0) {
			JLabel representantesLabel = new JLabel("F3-Anexos(" + qtde + ")");
			representantesLabel.setForeground(Color.red);
			tabPanel.setTabComponentAt(1, GUITools.boldFont(representantesLabel));
		}
	}

	public Departamento getDepartamento() {
		return (Departamento) departamentoCombo.getSelectedItem();
	}

	public EnterComboBox getDepartamentoCombo() {
		return departamentoCombo;
	}

	public void setDepartamentoCombo(EnterComboBox departamentoCombo) {
		this.departamentoCombo = departamentoCombo;
	}

	public void setdepartamentoCombo(EnterComboBox departamentoCombo) {
		this.departamentoCombo = departamentoCombo;
	}

	@Override
	public void requestFocus() {
		if (descricaoField.isEditable()) {
			descricaoField.requestFocus();
		}
	}

	public static void main(String[] args) {
		Main.loadLookAndFeel();

		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.add(new TarefaFormPanel(null));
		frame.pack();
		frame.setVisible(true);

	}

	public void tarefaOuProcedimento() {

		if (tarefaOption.isSelected()) {

			tipoCombo.setVisible(true);
			statusCombo.setSelectedIndex(0);
			tipoProcedimentoCombo.setVisible(false);
			statusLabel.setText("Status:");
			statusCombo.setVisible(true);
			departamentoCombo.setVisible(false);
			periodoCombo.setVisible(true);
			periodoLabel.setVisible(true);
			assuntoLabel.setText("  ");
			assuntoField.setVisible(false);
			clienteField.setVisible(false);
			dataInicioField.setVisible(true);
			dataInicioLabel.setText("Data Inicial:");
			dataFimField.setVisible(true);
			dataFimLabel.setText("Data Final:");
			dataConclusaoLabel.setText("Data da Conclusão:");
			dataConclusaoField.setVisible(true);

			if (periodoCombo.getSelectedItem() == PeriodicidadeTarefa.SEMANAL) {
				diaSemanaCombo.setEnabled(true);
				diaSemanaCombo.setVisible(true);
				diaSemanaLabel.setVisible(true);
				diaSemanaCombo.setSelectedIndex(0);
			} else {
				diaSemanaCombo.setEnabled(false);
				diaSemanaCombo.setVisible(false);
				diaSemanaLabel.setVisible(false);
				diaSemanaCombo.setSelectedIndex(-1);
			}
		} else {

			statusCombo.setSelectedIndex(3);
			tipoCombo.setVisible(false);
			tipoProcedimentoCombo.setVisible(true);
			tipoProcedimentoCombo.setSelectedIndex(0);
			statusLabel.setText("Depto:");
			statusCombo.setVisible(false);
			departamentoCombo.setVisible(true);
			assuntoField.setVisible(true);
			clienteField.setVisible(false);
			assuntoField.requestFocus(true);
			assuntoField.setEditable(true);
			periodoCombo.setVisible(false);
			periodoLabel.setVisible(false);
			dataInicioField.setVisible(false);
			dataInicioLabel.setText("      ");
			dataFimField.setVisible(false);
			dataFimLabel.setText("      ");
			dataConclusaoLabel.setText("      ");
			dataConclusaoField.setVisible(false);
			assuntoLabel.setText("Assunto:");
			diaSemanaLabel.setVisible(false);
			diaSemanaCombo.setVisible(false);
			gerarAutoCheck.setVisible(false);

		}
	}

}
Criado 15 de fevereiro de 2018
Ultima resposta 17 de fev. de 2018
Respostas 3
Participantes 3