package view;
import view.interfaces.IEditorView;
import java.util.ArrayList;
import view.states.arvores.AbstractEditorViewState;
import presenter.EditorPresenter;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPopupMenu;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import org.jdesktop.swingx.JXButton;
import org.jdesktop.swingx.JXTable;
import util.Substance;
import view.helpers.NumberColumnFormat;
public final class EditorView extends javax.swing.JInternalFrame implements IEditorView {
/**
*
*/
private EditorPresenter presenter;
/**
*
*/
private AbstractEditorViewState state;
/**
*
*/
private AbstractEditorViewState prevState;
/**
*
*/
private NumberColumnFormat numberCF2;
/**
*
*/
public static void setLookAndFeel(String pLaF) {
try {
UIManager.setLookAndFeel(pLaF);
} catch (Exception e) {
System.err.println(e);
}
}
/**
*
*/
public EditorView() {
setLookAndFeel(Substance.getAparencia(20));
initComponents();
presenter = new EditorPresenter(this);
numberCF2 = new NumberColumnFormat("#0.000000", "#0.000000");
}
@Override
public final void setState(final AbstractEditorViewState newState) {
if (state != null && !state.equals(prevState)) {
this.prevState = this.state;
}
this.state = newState;
this.state.habilitar();
}
@Override
public final void revertToPreviousState() {
if (this.prevState != null) {
this.state = this.prevState;
this.state.habilitar();
}
}
@Override
public final AbstractEditorViewState getViewState() {
return state;
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
popupMenu = new javax.swing.JPopupMenu();
jPanel1 = new javax.swing.JPanel();
pnlBotoes = new org.jdesktop.swingx.JXPanel();
btnSalvar = new org.jdesktop.swingx.JXButton();
btnNovaArvore = new javax.swing.JButton();
btnRemoverArvore = new org.jdesktop.swingx.JXButton();
btnImportar = new org.jdesktop.swingx.JXButton();
btnCancelar = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
grdDados = new org.jdesktop.swingx.JXTable();
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setMaximizable(true);
setResizable(true);
btnSalvar.setText("Salvar");
btnNovaArvore.setText("Nova árvore");
btnRemoverArvore.setText("Remover árvore");
btnImportar.setText("Importar");
btnCancelar.setText("Cancelar");
javax.swing.GroupLayout pnlBotoesLayout = new javax.swing.GroupLayout(pnlBotoes);
pnlBotoes.setLayout(pnlBotoesLayout);
pnlBotoesLayout.setHorizontalGroup(
pnlBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBotoesLayout.createSequentialGroup()
.addContainerGap(294, Short.MAX_VALUE)
.addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancelar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnNovaArvore, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(11, 11, 11)
.addComponent(btnRemoverArvore, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnImportar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pnlBotoesLayout.setVerticalGroup(
pnlBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBotoesLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(pnlBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnRemoverArvore, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnNovaArvore)
.addComponent(btnImportar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnCancelar)
.addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
grdDados.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{},
{},
{},
{}
},
new String [] {
}
));
jScrollPane1.setViewportView(grdDados);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pnlBotoes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 772, Short.MAX_VALUE))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(67, 67, 67)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(pnlBotoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(11, 11, 11))
);
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.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
@Override
public final JXTable getGrid() {
return grdDados;
}
@Override
public final JPopupMenu getPopupMenu() {
return popupMenu;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancelar;
private org.jdesktop.swingx.JXButton btnImportar;
private javax.swing.JButton btnNovaArvore;
private org.jdesktop.swingx.JXButton btnRemoverArvore;
private org.jdesktop.swingx.JXButton btnSalvar;
private org.jdesktop.swingx.JXTable grdDados;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private org.jdesktop.swingx.JXPanel pnlBotoes;
private javax.swing.JPopupMenu popupMenu;
// End of variables declaration//GEN-END:variables
@Override
public final JButton getBtnNovaArvore() {
return btnNovaArvore;
}
@Override
public final JXButton getBtnRemoverArvore() {
return btnRemoverArvore;
}
@Override
public final JXButton getBtnSalvar() {
return btnSalvar;
}
@Override
public final JButton getBtnCancelar() {
return btnCancelar;
}
@Override
public boolean getErrors() {
return numberCF2.hasErrors();
}
@Override
public final JXButton getBtnImportar() {
return btnImportar;
}
@Override
public final EditorPresenter getPresenter() {
return presenter;
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new EditorView().setVisible(true);
}
});
}
@Override
public void formatCells() {
for (int i = 1; i < grdDados.getColumnModel().getColumnCount(); i++) {
grdDados.getColumnModel().getColumn(i).setCellEditor(numberCF2.getEditor());
grdDados.getColumnModel().getColumn(i).setCellRenderer(numberCF2.getRenderer());
}
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
centerRenderer.setHorizontalAlignment(JLabel.CENTER);
grdDados.getColumnModel().getColumn(0).setCellRenderer(centerRenderer);
int columnWidth = 50;
grdDados.getColumnModel().getColumn(0).setPreferredWidth(columnWidth);
grdDados.getColumnModel().getColumn(0).setMaxWidth(columnWidth);
grdDados.getColumnModel().getColumn(0).setMinWidth(columnWidth);
grdDados.repaint();
}
@Override
public void setColumnFormat(String name) {
grdDados.getColumn(name).setCellEditor(numberCF2.getEditor());
grdDados.getColumn(name).setCellRenderer(numberCF2.getRenderer());
}
@Override
public ArrayList<Long> getArvoresSelecionadas() {
final ArrayList<Long> arvoresSelecionadas = new ArrayList<Long>();
int[] selecionadas = grdDados.getSelectedRows();
for (int i = 0; i < grdDados.getSelectedRowCount(); i++) {
arvoresSelecionadas.add((Long) grdDados.getValueAt(selecionadas[i], 0));
}
return arvoresSelecionadas;
}
}