Java tutorial
/** * Copyright 2013-2015 TIKAL-TECHNOLOGY * *Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package org.nekorp.workflow.desktop.view; import java.io.File; import java.io.IOException; import javax.swing.JFileChooser; import javax.swing.filechooser.FileNameExtensionFilter; import org.nekorp.workflow.desktop.control.ProgramacionServicioWizard; import org.nekorp.workflow.desktop.view.binding.Bindable; import org.nekorp.workflow.desktop.view.binding.BindingManager; import org.nekorp.workflow.desktop.view.model.importar.ProgramacionMetadata; import org.nekorp.workflow.desktop.view.model.validacion.ValidacionGeneralProgramacion; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * @author Nekorp */ @Component("formatoProgramacionView") public class FormatoProgramacionView extends ApplicationView { private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger .getLogger(FormatoProgramacionView.class); @Autowired private javax.swing.JFrame mainFrame; @Autowired private ProgramacionServicioWizard application; @Autowired private ValidacionGeneralProgramacion validacionGeneralProgramacion; @Autowired private BindingManager<Bindable> bindingManager; @Autowired private ProgramacionMetadata programacionMetadata; /** * Creates new form FormatoProgramacionView */ public FormatoProgramacionView() { } @Override public void iniciaVista() { initComponents(); bindComponents(); } @Override public void setEditableStatus(boolean value) { //no hacer nada. } @Override public ViewValidIndicator getValidInidicator() { return validacionGeneralProgramacion; } private void bindComponents() { //bindings con el servicio bindingManager.registerBind(programacionMetadata, "detalles", (Bindable) this.info); } /** * 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. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); importar = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); info = new org.nekorp.workflow.desktop.view.binding.SimpleBindableJTextArea(); setBackground(new java.awt.Color(255, 255, 255)); jLabel1.setText("formato de programacin:"); importar.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N importar.setText("Importar"); importar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { importarActionPerformed(evt); } }); jLabel2.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N jLabel2.setText(" "); jScrollPane1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); info.setEditable(false); info.setColumns(20); info.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N info.setRows(8); jScrollPane1.setViewportView(info); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addComponent(importar).addGap(0, 0, Short.MAX_VALUE)) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 490, Short.MAX_VALUE)) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1).addComponent(jLabel2)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(importar) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); }// </editor-fold>//GEN-END:initComponents private void importarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importarActionPerformed try { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Hojas de clculo", "xlsx"); chooser.setFileFilter(filter); String homePath = System.getProperty("user.home"); File f = new File(new File(homePath).getCanonicalPath()); chooser.setSelectedFile(f); int returnVal = chooser.showOpenDialog(this.mainFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); this.application.importarArchivo(chooser.getSelectedFile()); this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); } } catch (IOException ex) { FormatoProgramacionView.LOGGER.error(ex); } }//GEN-LAST:event_importarActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton importar; private javax.swing.JTextArea info; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables }