Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Clavis.Windows; import Clavis.KeyQuest; import com.sun.glass.events.KeyEvent; import java.awt.Color; import java.awt.Component; import java.awt.Desktop; import java.awt.Dimension; import java.awt.Event; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; import java.util.prefs.Preferences; import javax.imageio.ImageIO; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JDialog; import javax.swing.JTable; import javax.swing.KeyStroke; import javax.swing.ListSelectionModel; import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.font.PDFont; import org.apache.pdfbox.pdmodel.font.PDType1Font; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.util.CellUtil; import org.apache.poi.xssf.usermodel.XSSFPrintSetup; /** * * @author toze */ public class WShedule extends JDialog { private final static long serialVersionUID = 1L; private final javax.swing.JDialog componentepai; private java.awt.Color painelcor; private final Keys.Material mat; private final Preferences prefs; private final String url; private final Langs.Locale lingua; private TimeDate.Date inicio; private TimeDate.Date fim; private java.util.List<Keys.Request> lista; private MouseAdapter mouseaction; private String[][] valores; int andamento = 0; String estado = ""; /** * Creates new form NewJPanel */ /** * Creates new form NewJPanel * * @param comp * @param cor * @param mat * @param url * @param lingua */ public WShedule(javax.swing.JDialog comp, java.awt.Color cor, Keys.Material mat, String url, Langs.Locale lingua) { componentepai = comp; painelcor = cor; this.mat = mat; this.url = url; prefs = Preferences.userNodeForPackage(this.getClass()); this.lingua = lingua; inicio = new TimeDate.Date(); fim = new TimeDate.Date(); lista = new java.util.ArrayList<>(); estado = ""; } /** * 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() { jPanelInicial = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new org.jdesktop.swingx.JXTable(); ; jButtonSair = new javax.swing.JButton(); jXDatePickerInicio = new org.jdesktop.swingx.JXDatePicker(); jXDatePickerFim = new org.jdesktop.swingx.JXDatePicker(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jButtonImprimir = new javax.swing.JButton(); jComboBoxEstado = new javax.swing.JComboBox<>(); jLabel3 = new javax.swing.JLabel(); jButtonExportar = new javax.swing.JButton(); setMinimumSize(new java.awt.Dimension(900, 600)); setSize(new java.awt.Dimension(900, 600)); jPanelInicial.setBorder(javax.swing.BorderFactory.createCompoundBorder( javax.swing.BorderFactory.createLineBorder(painelcor, 4), javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)))); jPanelInicial.setMinimumSize(new java.awt.Dimension(900, 500)); jPanelInicial.setPreferredSize(new java.awt.Dimension(900, 500)); org.jdesktop.swingx.border.DropShadowBorder dropShadowBorder1 = new org.jdesktop.swingx.border.DropShadowBorder(); dropShadowBorder1.setCornerSize(6); dropShadowBorder1.setShadowSize(3); dropShadowBorder1.setShowLeftShadow(true); jScrollPane1.setBorder(javax.swing.BorderFactory.createCompoundBorder(dropShadowBorder1, javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)))); jTable1.setBorder(null); if (mat.getTypeOfMaterial().getMaterialTypeID() == 1) { jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { lingua.translate("Utilizador"), lingua.translate("Horrio"), lingua.translate("Data"), lingua.translate("Atividade"), lingua.translate("Disciplina") })); jTable1.getColumnModel().getColumn(0).setPreferredWidth(250); jTable1.getColumnModel().getColumn(1).setMinWidth(90); jTable1.getColumnModel().getColumn(2).setMinWidth(90); jTable1.getColumnModel().getColumn(3).setMinWidth(150); jTable1.getColumnModel().getColumn(4).setMinWidth(150); } else { jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { lingua.translate("Utilizador"), lingua.translate("Data inicial"), lingua.translate("Data final"), lingua.translate("Atividade") })); jTable1.getColumnModel().getColumn(0).setPreferredWidth(250); jTable1.getColumnModel().getColumn(1).setMinWidth(90); jTable1.getColumnModel().getColumn(2).setMinWidth(90); jTable1.getColumnModel().getColumn(3).setMinWidth(150); } jScrollPane1.setViewportView(jTable1); Border border = BorderFactory.createEmptyBorder(5, 5, 0, 0); UIManager.put("Table.focusCellHighlightBorder", border); jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(javax.swing.JLabel.CENTER); renderer.setFocusable(false); javax.swing.JLabel lo = new javax.swing.JLabel(); lo.setBackground(new Color(100, 100, 100)); lo.setOpaque(true); jScrollPane1.setCorner(javax.swing.JScrollPane.UPPER_TRAILING_CORNER, lo); jTable1.setRowHeight(30); jTable1.setEditable(false); jTable1.setSelectionBackground(Color.DARK_GRAY); jTable1.getColumnModel().getColumn(1).setCellRenderer(renderer); jTable1.getColumnModel().getColumn(2).setCellRenderer(renderer); jTable1.getColumnModel().getColumn(3).setCellRenderer(renderer); if (mat.getTypeOfMaterial().getMaterialTypeID() == 1) { jTable1.getColumnModel().getColumn(4).setCellRenderer(renderer); } DefaultTableCellRenderer headerRenderer = new DefaultTableCellRenderer() { private static final long serialVersionUID = 2L; @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setFont(new Font("Cantarell", Font.PLAIN, 14)); this.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 0, new Color(1, 1, 1))); return this; } }; DefaultTableCellRenderer headerRenderer2 = new DefaultTableCellRenderer() { private static final long serialVersionUID = 3L; @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setFont(new Font("Cantarell", Font.PLAIN, 14)); this.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(1, 1, 1)), BorderFactory.createEmptyBorder(0, 20, 0, 0))); this.setBackground(new Color(100, 100, 100)); setForeground(Color.WHITE); setPreferredSize(new Dimension(100, 40)); return this; } }; headerRenderer.setBackground(new Color(100, 100, 100)); headerRenderer.setForeground(Color.WHITE); headerRenderer.setPreferredSize(new Dimension(100, 40)); headerRenderer.setHorizontalAlignment(javax.swing.JLabel.CENTER); for (int i = 0; i < jTable1.getColumnCount(); i++) { if (i == 0) { headerRenderer2.setHorizontalAlignment(javax.swing.JLabel.LEFT); jTable1.getColumnModel().getColumn(i).setHeaderRenderer(headerRenderer2); } else { jTable1.getColumnModel().getColumn(i).setHeaderRenderer(headerRenderer); } } jButtonSair.setBackground(new java.awt.Color(1, 1, 1)); jButtonSair.setToolTipText(""); jButtonSair.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); jButtonSair.setFocusPainted(false); jButtonSair.setMaximumSize(new java.awt.Dimension(90, 40)); jButtonSair.setMinimumSize(new java.awt.Dimension(90, 40)); jButtonSair.setPreferredSize(new java.awt.Dimension(90, 40)); jButtonSair.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonSairActionPerformed(evt); } }); jXDatePickerInicio.setBackground(new java.awt.Color(254, 254, 254)); org.jdesktop.swingx.border.DropShadowBorder dropShadowBorder2 = new org.jdesktop.swingx.border.DropShadowBorder(); dropShadowBorder2.setCornerSize(6); dropShadowBorder2.setShadowSize(3); dropShadowBorder2.setShowLeftShadow(true); jXDatePickerInicio.setBorder(javax.swing.BorderFactory.createCompoundBorder(dropShadowBorder2, javax.swing.BorderFactory.createMatteBorder(0, 1, 1, 1, new java.awt.Color(0, 0, 0)))); jXDatePickerInicio.setFont(new java.awt.Font("Cantarell", 0, 12)); // NOI18N jXDatePickerInicio.setMaximumSize(new java.awt.Dimension(1155551, 26)); jXDatePickerInicio.setMinimumSize(new java.awt.Dimension(66, 26)); jXDatePickerInicio.setPreferredSize(new java.awt.Dimension(131, 26)); jXDatePickerInicio.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jXDatePickerInicioActionPerformed(evt); } }); jXDatePickerFim.setBackground(new java.awt.Color(254, 254, 254)); org.jdesktop.swingx.border.DropShadowBorder dropShadowBorder3 = new org.jdesktop.swingx.border.DropShadowBorder(); dropShadowBorder3.setCornerSize(6); dropShadowBorder3.setShadowSize(3); dropShadowBorder3.setShowLeftShadow(true); jXDatePickerFim.setBorder(javax.swing.BorderFactory.createCompoundBorder(dropShadowBorder3, javax.swing.BorderFactory.createMatteBorder(0, 1, 1, 1, new java.awt.Color(0, 0, 0)))); jXDatePickerFim.setFont(new java.awt.Font("Cantarell", 0, 12)); // NOI18N jXDatePickerFim.setMaximumSize(new java.awt.Dimension(1155551, 26)); jXDatePickerFim.setMinimumSize(new java.awt.Dimension(66, 26)); jXDatePickerFim.setPreferredSize(new java.awt.Dimension(121, 26)); jLabel1.setBackground(new java.awt.Color(100, 100, 100)); jLabel1.setFont(new java.awt.Font("Cantarell", 0, 12)); // NOI18N jLabel1.setForeground(new java.awt.Color(254, 254, 254)); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("Incio"); jLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP); jLabel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); jLabel1.setMaximumSize(new java.awt.Dimension(3343446, 96)); jLabel1.setMinimumSize(new java.awt.Dimension(36, 26)); jLabel1.setOpaque(true); jLabel1.setPreferredSize(new java.awt.Dimension(100, 20)); jLabel2.setBackground(new java.awt.Color(100, 100, 100)); jLabel2.setFont(new java.awt.Font("Cantarell", 0, 12)); // NOI18N jLabel2.setForeground(new java.awt.Color(254, 254, 254)); jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel2.setText("Fim"); jLabel2.setVerticalAlignment(javax.swing.SwingConstants.TOP); jLabel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); jLabel2.setMaximumSize(new java.awt.Dimension(355557, 96)); jLabel2.setMinimumSize(new java.awt.Dimension(37, 26)); jLabel2.setOpaque(true); jLabel2.setPreferredSize(new java.awt.Dimension(100, 20)); jButtonImprimir.setBackground(new java.awt.Color(51, 102, 153)); jButtonImprimir.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); jButtonImprimir.setFocusPainted(false); jButtonImprimir.setMaximumSize(new java.awt.Dimension(5345, 40)); jButtonImprimir.setPreferredSize(new java.awt.Dimension(90, 40)); jButtonImprimir.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonImprimirActionPerformed(evt); } }); jComboBoxEstado.setBackground(new java.awt.Color(213, 213, 213)); jComboBoxEstado.setBorder(null); jComboBoxEstado.setFocusable(false); jComboBoxEstado.setMinimumSize(new java.awt.Dimension(35, 22)); jComboBoxEstado.setPreferredSize(new java.awt.Dimension(125, 28)); jComboBoxEstado.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBoxEstadoActionPerformed(evt); } }); jLabel3.setBackground(new java.awt.Color(100, 100, 100)); jLabel3.setFont(new java.awt.Font("Cantarell", 0, 12)); // NOI18N jLabel3.setForeground(new java.awt.Color(254, 254, 254)); jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel3.setText("Estado"); jLabel3.setVerticalAlignment(javax.swing.SwingConstants.TOP); jLabel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); jLabel3.setMaximumSize(new java.awt.Dimension(355557, 96)); jLabel3.setMinimumSize(new java.awt.Dimension(37, 26)); jLabel3.setOpaque(true); jLabel3.setPreferredSize(new java.awt.Dimension(100, 20)); jButtonExportar.setBackground(new java.awt.Color(51, 102, 153)); jButtonExportar.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); jButtonExportar.setFocusPainted(false); jButtonExportar.setMaximumSize(new java.awt.Dimension(5345, 40)); jButtonExportar.setPreferredSize(new java.awt.Dimension(90, 40)); jButtonExportar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonExportarActionPerformed(evt); } }); javax.swing.GroupLayout jPanelInicialLayout = new javax.swing.GroupLayout(jPanelInicial); jPanelInicial.setLayout(jPanelInicialLayout); jPanelInicialLayout.setHorizontalGroup(jPanelInicialLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelInicialLayout.createSequentialGroup().addGap(42, 42, 42) .addGroup(jPanelInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelInicialLayout.createSequentialGroup().addComponent(jScrollPane1) .addGap(42, 42, 42)) .addGroup(jPanelInicialLayout.createSequentialGroup().addGap(29, 29, 29) .addComponent(jButtonSair, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButtonExportar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(71, 71, 71)))) .addGroup(jPanelInicialLayout.createSequentialGroup().addGap(71, 71, 71) .addGroup(jPanelInicialLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jXDatePickerInicio, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanelInicialLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE) .addComponent(jXDatePickerFim, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 201, Short.MAX_VALUE) .addGroup(jPanelInicialLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jComboBoxEstado, 0, 241, Short.MAX_VALUE)) .addGap(71, 71, 71))); jPanelInicialLayout .setVerticalGroup(jPanelInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelInicialLayout.createSequentialGroup().addGap(16, 16, 16) .addGroup(jPanelInicialLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(0, 0, 0) .addGroup(jPanelInicialLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jXDatePickerInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jXDatePickerFim, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBoxEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanelInicialLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButtonSair, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButtonExportar, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(16, 16, 16))); try { if (Clavis.KeyQuest.class.getResource("Images/exit26x24.png") != null) { BufferedImage im = ImageIO.read(Clavis.KeyQuest.class.getResourceAsStream("Images/exit26x24.png")); ImageIcon imic = new ImageIcon(im); if (imic != null) { jButtonSair.setIcon(imic); } } } catch (IOException eo) { } jButtonSair.setToolTipText(lingua.translate("Voltar")); javax.swing.JPanel pan2 = new javax.swing.JPanel(null); String compoe = lingua.translate("Hoje dia") + ": " + new TimeDate.Date().toString(); javax.swing.JLabel fil2 = new javax.swing.JLabel(compoe); fil2.setBounds(0, 0, 300, 26); fil2.setHorizontalAlignment(SwingConstants.CENTER); pan2.setPreferredSize(new Dimension(300, 30)); pan2.setBounds(0, 0, 300, 30); pan2.add(fil2); jXDatePickerInicio.setLinkPanel(pan2); jXDatePickerInicio.setLocale(lingua.systemlocale); jXDatePickerInicio.getEditor().setSelectionColor(Color.DARK_GRAY); jXDatePickerInicio.getEditor().setBorder(BorderFactory.createEmptyBorder()); jXDatePickerInicio.getEditor().setHorizontalAlignment(SwingConstants.CENTER); javax.swing.JButton bbt2 = (javax.swing.JButton) jXDatePickerInicio.getComponent(1); bbt2.setBackground(Color.WHITE); jXDatePickerInicio.addActionListener(actionJXDatePicker()); jXDatePickerInicio.setFormats("dd/MM/yyyy"); javax.swing.JPanel pan = new javax.swing.JPanel(null); String compoe0 = lingua.translate("Hoje dia") + ": " + new TimeDate.Date().toString(); javax.swing.JLabel fil = new javax.swing.JLabel(compoe); fil.setBounds(0, 0, 300, 26); fil.setHorizontalAlignment(SwingConstants.CENTER); pan.setPreferredSize(new Dimension(300, 30)); pan.setBounds(0, 0, 300, 30); pan.add(fil); jXDatePickerFim.setLinkPanel(pan); Component[] t = jXDatePickerFim.getLinkPanel().getComponents(); jXDatePickerFim.setLocale(lingua.systemlocale); jXDatePickerFim.getEditor().setSelectionColor(Color.DARK_GRAY); jXDatePickerFim.getEditor().setBorder(BorderFactory.createEmptyBorder()); jXDatePickerFim.getEditor().setHorizontalAlignment(SwingConstants.CENTER); javax.swing.JButton bbt = (javax.swing.JButton) jXDatePickerFim.getComponent(1); bbt.setBackground(Color.WHITE); jXDatePickerFim.addActionListener(actionJXDatePicker()); jXDatePickerFim.setFormats("dd/MM/yyyy"); jLabel1.setText(lingua.translate("Incio")); jLabel2.setText(lingua.translate("Fim")); try { if (Clavis.KeyQuest.class.getResource("Images/print.png") != null) { BufferedImage im = ImageIO.read(Clavis.KeyQuest.class.getResourceAsStream("Images/print.png")); ImageIcon imic = new ImageIcon(im); if (imic != null) { jButtonImprimir.setIcon(imic); } } } catch (IOException eo) { } jButtonImprimir.setToolTipText(lingua.translate("Imprimir")); jComboBoxEstado.setModel(new javax.swing.DefaultComboBoxModel<>( new String[] { lingua.translate("todos"), lingua.translate("terminado"), lingua.translate("no realizado"), lingua.translate("por realizar") })); Clavis.KeyQuest.addVisualComboBox(jComboBoxEstado); ((javax.swing.JLabel) jComboBoxEstado.getRenderer()).setHorizontalAlignment(javax.swing.JLabel.CENTER); jLabel3.setText(lingua.translate("Estado")); try { if (Clavis.KeyQuest.class.getResource("Images/exportar.png") != null) { BufferedImage im = ImageIO.read(Clavis.KeyQuest.class.getResourceAsStream("Images/exportar.png")); ImageIcon imic = new ImageIcon(im); if (imic != null) { jButtonExportar.setIcon(imic); } } } catch (IOException eo) { } jButtonExportar.setToolTipText(lingua.translate("Exportar para excel")); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(jPanelInicial, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(0, 0, 0))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanelInicial, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)); }// </editor-fold>//GEN-END:initComponents private void jButtonSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSairActionPerformed prefs.putInt("largura", this.getWidth()); prefs.putInt("altura", this.getHeight()); prefs.putInt("x", getX()); prefs.putInt("y", getY()); this.close(); }//GEN-LAST:event_jButtonSairActionPerformed private void jComboBoxEstadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxEstadoActionPerformed int val = jComboBoxEstado.getSelectedIndex(); prefs.putInt("comboboxvalue", val); this.refreshTable(val); }//GEN-LAST:event_jComboBoxEstadoActionPerformed private void jXDatePickerInicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXDatePickerInicioActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jXDatePickerInicioActionPerformed private void jButtonImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonImprimirActionPerformed if ((valores != null) && (valores.length > 0)) { File file = new File("doc.pdf"); createPDFDocument("doc.pdf", valores); FileIOAux.PrintAux print = new FileIOAux.PrintAux(file, lingua, null); print.print(); file.delete(); } else { Components.MessagePane mensagem = new Components.MessagePane(null, Components.MessagePane.INFORMACAO, painelcor, lingua.translate("Erro de impresso"), 400, 200, lingua.translate("No existem valores para imprimir") + ".", new String[] { lingua.translate("Voltar") }); mensagem.showMessage(); } }//GEN-LAST:event_jButtonImprimirActionPerformed private void jButtonExportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExportarActionPerformed if ((valores != null) && (valores.length > 0)) { this.createXLSDocument("doc.xls", valores); } else { Components.MessagePane mensagem = new Components.MessagePane(this, Components.MessagePane.INFORMACAO, painelcor, lingua.translate("Erro de exportao"), 400, 200, lingua.translate("No existem valores para exportar") + ".", new String[] { lingua.translate("Voltar") }); mensagem.showMessage(); } }//GEN-LAST:event_jButtonExportarActionPerformed public void createPDFDocument(String nome, String[][] valores) { PDDocument doc = new PDDocument(); try { String titulo = lingua.translate("Registo de emprstimos / requisies do recurso") + ": " + lingua.translate(mat.getTypeOfMaterialName()) + " " + lingua.translate(mat.getDescription()); String subtitulo = lingua.translate("Desde") + ": " + inicio.toString() + " " + lingua.translate("at") + ": " + fim.toString(); String subsubtitulo = lingua.translate("Estado") + ": " + lingua.translate(estado); drawTable(doc, valores, titulo, subtitulo, subsubtitulo); doc.save(nome); doc.close(); } catch (IOException ex) { Logger.getLogger(WShedule.class.getName()).log(Level.SEVERE, null, ex); } } /** * @see * http://fahdshariff.blogspot.pt/2010/10/creating-tables-with-pdfbox.html */ private static void drawTable(PDDocument doc, String[][] content, String titulo, String subtitulo, String subsubtitulo) throws IOException { float y = 680f; float margin = 60f; final int rows = content.length; final int cols = content[0].length; final float rowHeight = 20f; int maximolinhas = (int) (y / (rowHeight + 2)); float tableHeight; int paginas = 0; int linhas; if (rows < maximolinhas) { linhas = rows; paginas++; } else { linhas = maximolinhas; int auxiliar = 0; while (auxiliar < rows) { paginas++; auxiliar += maximolinhas; } } final float cellMargin = 5f; float tamanhotexto = 12f; float tamanhotexto2 = 8f; float dimensao = 0f; float dimensao2 = 0f; PDFont font = PDType1Font.TIMES_ROMAN; for (String[] content1 : content) { dimensao = font.getStringWidth(content1[0]) / 1000 * tamanhotexto2; if (dimensao > 222.0f) { String nome = content1[0]; String[] texto = nome.split(" "); nome = nome.replace(texto[0], ""); nome = nome.replace(texto[texto.length - 1], ""); int i = 1; while (dimensao > 222.0f) { if (texto[i].length() > 2) { nome = nome.replace(texto[i], texto[i].charAt(0) + "."); } else { nome = nome.replace(texto[i], ""); } dimensao = font.getStringWidth(texto[0] + nome + texto[texto.length - 1]) / 1000 * tamanhotexto2; i++; } content1[0] = texto[0] + nome + texto[texto.length - 1]; } dimensao2 = font.getStringWidth(content1[3]) / 1000 * tamanhotexto2 + 10; if (dimensao2 > 180.0f) { String nome = content1[3]; String[] texto = nome.split(" "); nome = nome.replace(texto[0], ""); nome = nome.replace(texto[texto.length - 1], ""); int i = 1; while (dimensao2 > 180.0f) { if (texto[i].length() > 2) { nome = nome.replace(texto[i], texto[i].charAt(0) + "."); } else { nome = nome.replace(texto[i], ""); } dimensao2 = font.getStringWidth(texto[0] + nome + texto[texto.length - 1]) / 1000 * tamanhotexto2; i++; } content1[3] = texto[0] + nome + texto[texto.length - 1]; } } int passagem = 0; int passagemdepagina = 0; float tableWidth; if (dimensao < 100) { dimensao = 100; } if (dimensao2 < 100) { dimensao2 = 100; } float firstcolWidth = dimensao + 10 * cellMargin; float lastcolWidth = dimensao2 + 10 * cellMargin; float colWidth; PDPageContentStream contentStream = null; while (passagem < paginas) { PDPage page = new PDPage(); doc.addPage(page); try { contentStream = new PDPageContentStream(doc, page); } catch (IOException ex) { Logger.getLogger(WShedule.class.getName()).log(Level.SEVERE, null, ex); } if (contentStream != null) { contentStream.setFont(font, tamanhotexto); tableWidth = page.getMediaBox().getWidth() - (2 * margin); colWidth = (tableWidth - firstcolWidth - lastcolWidth) / (float) (cols - 2); if (passagem == 0) { contentStream.beginText(); float posicao = margin + (tableWidth / 2) - ((font.getStringWidth(titulo) / 1000 * tamanhotexto) / 2); contentStream.newLineAtOffset(posicao, page.getMediaBox().getHeight() - 40); contentStream.showText(titulo); contentStream.endText(); contentStream.beginText(); posicao = margin + (tableWidth / 2) - ((font.getStringWidth(subtitulo) / 1000 * tamanhotexto) / 2); contentStream.newLineAtOffset(posicao, page.getMediaBox().getHeight() - 60); contentStream.showText(subtitulo); contentStream.endText(); contentStream.beginText(); posicao = margin + (tableWidth / 2) - ((font.getStringWidth(subsubtitulo) / 1000 * tamanhotexto) / 2); contentStream.newLineAtOffset(posicao, page.getMediaBox().getHeight() - 80); contentStream.showText(subsubtitulo); contentStream.endText(); } if (passagem == 1) { y += 40; } float nexty = y; contentStream.setFont(font, tamanhotexto2); for (int i = 0; i <= linhas; i++) { if (i < linhas) { if ((i % 2) == 0) { contentStream.setNonStrokingColor(200, 200, 200); contentStream.addRect(margin, nexty - rowHeight, tableWidth, rowHeight); contentStream.fill(); } } contentStream.setNonStrokingColor(0, 0, 0); contentStream.moveTo(margin, nexty); contentStream.lineTo(margin + tableWidth, nexty); contentStream.stroke(); nexty -= rowHeight; } //draw the columns float nextx = margin; for (int i = 0; i <= cols; i++) { contentStream.moveTo(nextx, y); if (linhas < maximolinhas) { tableHeight = rowHeight * linhas; } else { tableHeight = rowHeight * maximolinhas; } contentStream.lineTo(nextx, y - tableHeight); contentStream.stroke(); switch (i) { case 0: nextx += firstcolWidth; break; case 3: nextx += lastcolWidth; break; default: nextx += colWidth; break; } } float textx = margin; float texty = y - 15; float ttexto; boolean primeira = true; for (int i = 0; i < linhas; i++) { for (int j = 0; j < content[i + passagemdepagina].length; j++) { String text = content[i + passagemdepagina][j]; ttexto = font.getStringWidth(text) / 1000 * tamanhotexto2; if (j == 0) { ttexto = textx + ((firstcolWidth / 2) - (ttexto / 2)); } else if (j < 3) { ttexto = textx + ((colWidth / 2) - (ttexto / 2)); } else { ttexto = textx + ((lastcolWidth / 2) - (ttexto / 2)); } contentStream.beginText(); contentStream.newLineAtOffset(ttexto, texty); contentStream.showText(text); contentStream.endText(); if (j == 0) { textx += firstcolWidth; } else { textx += colWidth; } } texty -= rowHeight; textx = margin; } contentStream.beginText(); contentStream.newLineAtOffset((tableWidth / 2) + margin, 40); contentStream.showText("" + (passagem + 1)); contentStream.endText(); contentStream.close(); } passagem++; maximolinhas = (int) (y / (rowHeight + 1)); linhas = rows - (maximolinhas * passagem); if (linhas > maximolinhas) { linhas = maximolinhas; } passagemdepagina = maximolinhas * passagem; } } public void createXLSDocument(String nome, String[][] valores) { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(nome); HSSFRow row; HSSFCell cell; for (int i = 0; i < valores.length; i++) { row = sheet.createRow(i); for (int j = 0; j < valores[i].length; j++) { cell = row.createCell(j); cell.setCellValue(valores[i][j]); if (valores[i][j] != null) { sheet.setColumnWidth(j, 255 * valores[i][j].length() + 4); CellUtil.setAlignment(cell, wb, CellStyle.ALIGN_CENTER); } } } wb.setPrintArea(0, 0, valores[0].length, 0, valores.length); sheet.getPrintSetup().setPaperSize(XSSFPrintSetup.A4_PAPERSIZE); FileOutputStream out; String sfile = new File("").getAbsolutePath() + System.getProperty("file.separator") + nome; File file = new File(sfile); if (!file.exists()) { try { file.createNewFile(); } catch (IOException ex) { Logger.getLogger(WShedule.class.getName()).log(Level.SEVERE, null, ex); } } if (file.canWrite()) { try { out = new FileOutputStream(file); } catch (FileNotFoundException ex) { Logger.getLogger(WShedule.class.getName()).log(Level.SEVERE, null, ex); out = null; } if (out != null) { try { wb.write(out); out.close(); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(file); } else { Components.MessagePane mensagem = new Components.MessagePane(this, Components.MessagePane.INFORMACAO, painelcor, lingua.translate("Nota"), 400, 200, lingua.translate("O documento \"doc.xls\" foi criado na pasta raiz do programa") + ".", new String[] { lingua.translate("Voltar") }); mensagem.showMessage(); } } catch (IOException ex) { Logger.getLogger(WShedule.class.getName()).log(Level.SEVERE, null, ex); } } } } public boolean isFileOpen(File file) { boolean cond; try { org.apache.commons.io.FileUtils.touch(file); cond = true; } catch (IOException e) { cond = false; } return cond; } /** * @return the painelcor */ public java.awt.Color getPainelcor() { return painelcor; } public void appear() { int largura = prefs.getInt("largura", (int) this.getPreferredSize().getWidth()); int altura = prefs.getInt("altura", (int) this.getPreferredSize().getHeight()); int x = prefs.getInt("x", this.getX()); int y = prefs.getInt("y", this.getY()); this.setBounds(x, y, largura, altura); this.setVisible(true); this.setLocationRelativeTo(this.componentepai); } public void close() { prefs.putInt("largura", getWidth()); prefs.putInt("altura", getHeight()); prefs.putInt("x", getX()); prefs.putInt("y", getY()); this.setVisible(false); File fil = new File("doc.pdf"); if (fil.exists()) { fil.delete(); } this.dispose(); } public synchronized void create() { initComponents(); this.setModal(true); this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { close(); } }); this.setTitle(lingua.translate("Registos de emprstimo para o recurso") + ": " + lingua.translate(mat.getTypeOfMaterialName()).toLowerCase() + " " + lingua.translate(mat.getDescription())); KeyQuest.addtoPropertyListener(jPanelInicial, true); String dat = new TimeDate.Date().toString(); String[] auxiliar = prefs.get("datainicio", dat).split("/"); if (auxiliar[0].length() > 1) { if (auxiliar[0].charAt(0) == '0') { auxiliar[0] = auxiliar[0].replaceFirst("0", ""); } } if (auxiliar[1].length() > 1) { if (auxiliar[1].charAt(0) == '0') { auxiliar[1] = auxiliar[1].replaceFirst("0", ""); } } if (auxiliar[2].length() > 1) { if (auxiliar[2].charAt(0) == '0') { auxiliar[2] = auxiliar[2].replaceFirst("0", ""); } } inicio = new TimeDate.Date(Integer.valueOf(auxiliar[0]), Integer.valueOf(auxiliar[1]), Integer.valueOf(auxiliar[2])); auxiliar = prefs.get("datafim", dat).split("/"); if (auxiliar[0].length() > 1) { if (auxiliar[0].charAt(0) == '0') { auxiliar[0] = auxiliar[0].replaceFirst("0", ""); } } if (auxiliar[1].length() > 1) { if (auxiliar[1].charAt(0) == '0') { auxiliar[1] = auxiliar[1].replaceFirst("0", ""); } } if (auxiliar[2].length() > 1) { if (auxiliar[2].charAt(0) == '0') { auxiliar[2] = auxiliar[2].replaceFirst("0", ""); } } fim = new TimeDate.Date(Integer.valueOf(auxiliar[0]), Integer.valueOf(auxiliar[1]), Integer.valueOf(auxiliar[2])); SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy"); Date date; try { date = sdf.parse(fim.toString()); } catch (ParseException ex) { date = new Date(); } jXDatePickerFim.setDate(date); try { date = sdf.parse(inicio.toString()); } catch (ParseException ex) { date = new Date(); } jXDatePickerInicio.setDate(date); andamento = 0; if (DataBase.DataBase.testConnection(url)) { DataBase.DataBase db = new DataBase.DataBase(url); java.util.List<Keys.Request> requisicoes = Clavis.RequestList .simplifyRequests(db.getRequestsByMaterialByDateInterval(mat, inicio, fim)); db.close(); estado = lingua.translate("Todos"); DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel(); if (requisicoes.size() > 0) { valores = new String[requisicoes.size()][4]; lista = new java.util.ArrayList<>(); requisicoes.stream().map((req) -> { if (mat.getMaterialTypeID() == 1) { valores[andamento][0] = req.getPerson().getName(); valores[andamento][1] = req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0); valores[andamento][2] = req.getBeginDate().toString(); String[] multipla = req.getActivity().split(":::"); if (multipla.length > 1) { Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua); pop.create(); jTable1.addMouseListener(new MouseAdapter() { int x = andamento; int y = 3; @Override public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { int row = jTable1.rowAtPoint(e.getPoint()); int col = jTable1.columnAtPoint(e.getPoint()); if ((row == x) && (col == y)) { pop.show(e.getComponent(), e.getX(), e.getY()); } } } @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (pop.isShowing()) { pop.setVisible(false); } } } }); valores[andamento][3] = lingua.translate(multipla[0]) + ""; } else { valores[andamento][3] = lingua.translate(req.getActivity()); } if (valores[andamento][3].equals("")) { valores[andamento][3] = lingua.translate("Sem descrio"); } Object[] ob = { req.getPerson().getName(), req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0), req.getBeginDate().toString(), valores[andamento][3], req.getSubject().getName() }; modelo.addRow(ob); } else { valores[andamento][0] = req.getPerson().getName(); valores[andamento][1] = req.getBeginDate().toString(); valores[andamento][2] = req.getEndDate().toString(); String[] multipla = req.getActivity().split(":::"); if (multipla.length > 1) { Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua); pop.create(); jTable1.addMouseListener(new MouseAdapter() { int x = andamento; int y = 3; @Override public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { int row = jTable1.rowAtPoint(e.getPoint()); int col = jTable1.columnAtPoint(e.getPoint()); if ((row == x) && (col == y)) { pop.show(e.getComponent(), e.getX(), e.getY()); } } } @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (pop.isShowing()) { pop.setVisible(false); } } } }); valores[andamento][3] = multipla[0]; } else { valores[andamento][3] = lingua.translate(req.getActivity()); } if (valores[andamento][3].equals("")) { valores[andamento][3] = lingua.translate("Sem descrio"); } Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(), req.getEndDate().toString(), valores[andamento][3] }; modelo.addRow(ob); } return req; }).map((req) -> { lista.add(req); return req; }).forEach((_item) -> { andamento++; }); } } jComboBoxEstado.setSelectedIndex(prefs.getInt("comboboxvalue", 0)); String[] opcoes = { lingua.translate("Ver detalhes da requisio"), lingua.translate("Ver requisices com a mesma data"), lingua.translate("Ver requisices com o mesmo estado") }; ActionListener[] eventos = new ActionListener[opcoes.length]; eventos[0] = (ActionEvent r) -> { Border border = BorderFactory.createCompoundBorder( BorderFactory.createCompoundBorder(new org.jdesktop.swingx.border.DropShadowBorder(Color.BLACK, 3, 0.5f, 6, false, false, true, true), BorderFactory.createLineBorder(Color.BLACK, 1)), BorderFactory.createEmptyBorder(0, 10, 0, 10)); int val = jTable1.getSelectedRow(); Keys.Request req = lista.get(val); javax.swing.JPanel pan = new javax.swing.JPanel(null); pan.setPreferredSize(new Dimension(500, 300)); pan.setBounds(0, 20, 500, 400); pan.setBackground(Components.MessagePane.BACKGROUND_COLOR); javax.swing.JLabel lrecurso1 = new javax.swing.JLabel(lingua.translate("Recurso") + ": "); lrecurso1.setBounds(10, 20, 120, 26); lrecurso1.setFocusable(true); lrecurso1.setHorizontalAlignment(javax.swing.JLabel.LEFT); pan.add(lrecurso1); javax.swing.JLabel lrecurso11 = new javax.swing.JLabel( lingua.translate(req.getMaterial().getTypeOfMaterialName()) + " " + lingua.translate(req.getMaterial().getDescription())); lrecurso11.setBounds(140, 20, 330, 26); lrecurso11.setBorder(border); pan.add(lrecurso11); javax.swing.JLabel lrecurso2 = new javax.swing.JLabel(lingua.translate("Utilizador") + ": "); lrecurso2.setBounds(10, 50, 120, 26); lrecurso2.setFocusable(true); lrecurso2.setHorizontalAlignment(javax.swing.JLabel.LEFT); pan.add(lrecurso2); javax.swing.JLabel lrecurso22 = new javax.swing.JLabel(req.getPerson().getName()); lrecurso22.setBounds(140, 50, 330, 26); lrecurso22.setBorder(border); pan.add(lrecurso22); javax.swing.JLabel lrecurso3 = new javax.swing.JLabel(lingua.translate("Data inicial") + ": "); lrecurso3.setBounds(10, 80, 120, 26); lrecurso3.setFocusable(true); lrecurso3.setHorizontalAlignment(javax.swing.JLabel.LEFT); pan.add(lrecurso3); javax.swing.JLabel lrecurso33 = new javax.swing.JLabel( req.getBeginDate().toStringWithMonthWord(lingua)); lrecurso33.setBounds(140, 80, 330, 26); lrecurso33.setBorder(border); pan.add(lrecurso33); javax.swing.JLabel lrecurso4 = new javax.swing.JLabel(lingua.translate("Data final") + ": "); lrecurso4.setBounds(10, 110, 120, 26); lrecurso4.setFocusable(true); lrecurso4.setHorizontalAlignment(javax.swing.JLabel.LEFT); pan.add(lrecurso4); javax.swing.JLabel lrecurso44 = new javax.swing.JLabel(req.getEndDate().toStringWithMonthWord(lingua)); lrecurso44.setBounds(140, 110, 330, 26); lrecurso44.setBorder(border); pan.add(lrecurso44); javax.swing.JLabel lrecurso5 = new javax.swing.JLabel(lingua.translate("Atividade") + ": "); lrecurso5.setBounds(10, 140, 120, 26); lrecurso5.setFocusable(true); lrecurso5.setHorizontalAlignment(javax.swing.JLabel.LEFT); pan.add(lrecurso5); javax.swing.JLabel lrecurso55; if (req.getActivity().equals("")) { lrecurso55 = new javax.swing.JLabel(lingua.translate("Sem descrio")); } else { String[] saux = req.getActivity().split(":::"); String atividade; boolean situacao = false; if (saux.length > 1) { situacao = true; atividade = saux[0]; } else { atividade = req.getActivity(); } if (req.getSubject().getId() > 0) { lrecurso55 = new javax.swing.JLabel( lingua.translate(atividade) + ": " + req.getSubject().getName()); } else { lrecurso55 = new javax.swing.JLabel(lingua.translate(atividade)); } if (situacao) { Components.PopUpMenu pop = new Components.PopUpMenu(saux, lingua); pop.create(); lrecurso55.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { pop.show(e.getComponent(), e.getX(), e.getY()); } @Override public void mouseExited(MouseEvent e) { pop.setVisible(false); } }); } } lrecurso55.setBounds(140, 140, 330, 26); lrecurso55.setBorder(border); pan.add(lrecurso55); int distancia = 170; if (req.getBeginDate().isBigger(req.getEndDate()) == 0) { javax.swing.JLabel lrecurso6 = new javax.swing.JLabel(lingua.translate("Horrio") + ": "); lrecurso6.setBounds(10, distancia, 120, 26); lrecurso6.setFocusable(true); lrecurso6.setHorizontalAlignment(javax.swing.JLabel.LEFT); pan.add(lrecurso6); javax.swing.JLabel lrecurso66 = new javax.swing.JLabel( req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0)); lrecurso66.setBounds(140, distancia, 330, 26); lrecurso66.setBorder(border); pan.add(lrecurso66); distancia = 200; } if (req.getBeginDate().isBigger(req.getEndDate()) == 0) { javax.swing.JLabel lrecurso7 = new javax.swing.JLabel(lingua.translate("Dia da semana") + ": "); lrecurso7.setBounds(10, distancia, 120, 26); lrecurso7.setFocusable(true); lrecurso7.setHorizontalAlignment(javax.swing.JLabel.LEFT); pan.add(lrecurso7); javax.swing.JLabel lrecurso77 = new javax.swing.JLabel( lingua.translate(req.getWeekDay().perDayName())); lrecurso77.setBounds(140, distancia, 330, 26); lrecurso77.setBorder(border); pan.add(lrecurso77); if (distancia == 200) { distancia = 230; } else { distancia = 200; } } if (req.isTerminated() || req.isActive()) { javax.swing.JLabel lrecurso8 = new javax.swing.JLabel(lingua.translate("Levantamento") + ": "); lrecurso8.setBounds(10, distancia, 120, 26); lrecurso8.setFocusable(true); lrecurso8.setHorizontalAlignment(javax.swing.JLabel.LEFT); pan.add(lrecurso8); javax.swing.JLabel lrecurso88; if ((req.getLiftDate() != null) && (req.getLiftTime() != null)) { lrecurso88 = new javax.swing.JLabel(req.getLiftDate().toString() + " " + lingua.translate("s") + " " + req.getLiftTime().toString(0)); } else { lrecurso88 = new javax.swing.JLabel(lingua.translate("sem dados para apresentar")); } lrecurso88.setBounds(140, distancia, 330, 26); lrecurso88.setBorder(border); pan.add(lrecurso88); switch (distancia) { case 200: distancia = 230; break; case 230: distancia = 260; break; default: distancia = 200; break; } } if (req.isTerminated()) { javax.swing.JLabel lrecurso9 = new javax.swing.JLabel(lingua.translate("Entrega") + ": "); lrecurso9.setBounds(10, distancia, 120, 26); lrecurso9.setFocusable(true); lrecurso9.setHorizontalAlignment(javax.swing.JLabel.LEFT); pan.add(lrecurso9); javax.swing.JLabel lrecurso99; if ((req.getDeliveryDate() != null) && (req.getDeliveryTime() != null)) { lrecurso99 = new javax.swing.JLabel(req.getDeliveryDate().toString() + " " + lingua.translate("s") + " " + req.getDeliveryTime().toString(0)); } else { lrecurso99 = new javax.swing.JLabel(lingua.translate("sem dados para apresentar")); } lrecurso99.setBounds(140, distancia, 330, 26); lrecurso99.setBorder(border); pan.add(lrecurso99); switch (distancia) { case 200: distancia = 230; break; case 230: distancia = 260; break; case 260: distancia = 290; break; default: distancia = 200; break; } } Components.MessagePane mensagem = new Components.MessagePane(this, Components.MessagePane.INFORMACAO, Clavis.KeyQuest.getSystemColor(), lingua.translate(""), 500, 400, pan, "", new String[] { lingua.translate("Voltar") }); mensagem.showMessage(); }; eventos[1] = (ActionEvent r) -> { String val = jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 2).toString(); SimpleDateFormat sdf_auxiliar = new SimpleDateFormat("dd/MM/yyyy"); Date data_auxiliar; try { data_auxiliar = sdf_auxiliar.parse(val); Calendar cal = Calendar.getInstance(); cal.setTime(data_auxiliar); int dia = cal.get(Calendar.DAY_OF_MONTH); int mes = cal.get(Calendar.MONTH) + 1; int ano = cal.get(Calendar.YEAR); inicio = new TimeDate.Date(dia, mes, ano); fim = new TimeDate.Date(dia, mes, ano); } catch (ParseException ex) { data_auxiliar = new Date(); } jXDatePickerFim.setDate(data_auxiliar); jXDatePickerInicio.setDate(data_auxiliar); refreshTable(jComboBoxEstado.getSelectedIndex()); }; eventos[2] = (ActionEvent r) -> { String val = jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 3).toString(); for (int i = 0; i < jComboBoxEstado.getItemCount(); i++) { if (jComboBoxEstado.getItemAt(i).equals(val)) { jComboBoxEstado.setSelectedIndex(i); } } }; KeyStroke[] strokes = new KeyStroke[opcoes.length]; strokes[0] = KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK); strokes[1] = KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK); strokes[2] = KeyStroke.getKeyStroke(KeyEvent.VK_E, Event.CTRL_MASK); Components.PopUpMenu pop = new Components.PopUpMenu(opcoes, eventos, strokes); pop.create(); mouseaction = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { java.awt.Point ponto = new java.awt.Point(e.getX(), e.getY()); if (jTable1.rowAtPoint(ponto) > -1) { jTable1.setRowSelectionInterval(jTable1.rowAtPoint(ponto), jTable1.rowAtPoint(new java.awt.Point(e.getX(), e.getY()))); } } @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { if (jTable1.getSelectedRow() >= 0) { java.awt.Point ponto = new java.awt.Point(e.getX(), e.getY()); if (jTable1.rowAtPoint(ponto) > -1) { pop.show(e.getComponent(), e.getX(), e.getY()); } } } } }; jTable1.addMouseListener(mouseaction); } public synchronized void refreshTable(int val) { DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel(); if (modelo.getRowCount() > 0) { int tam = modelo.getRowCount(); for (int h = 0; h < tam; h++) { modelo.removeRow(0); } } java.util.List<Keys.Request> requisicoes = new java.util.ArrayList<>(); if (DataBase.DataBase.testConnection(url)) { DataBase.DataBase db = new DataBase.DataBase(url); requisicoes = Clavis.RequestList .simplifyRequests(db.getRequestsByMaterialByDateInterval(mat, inicio, fim)); db.close(); } lista = new java.util.ArrayList<>(); andamento = 0; switch (val) { case 0: estado = lingua.translate("Todos"); for (Keys.Request req : requisicoes) { String[] multipla = req.getActivity().split(":::"); String saux; if (multipla.length > 1) { saux = multipla[0]; Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua); pop.create(); jTable1.addMouseListener(new MouseAdapter() { int x = andamento; int y = 3; @Override public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { int row = jTable1.rowAtPoint(e.getPoint()); int col = jTable1.columnAtPoint(e.getPoint()); if ((row == x) && (col == y)) { pop.show(e.getComponent(), e.getX(), e.getY()); } } } @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (pop.isShowing()) { pop.setVisible(false); } } } }); } else { saux = req.getActivity(); } if (saux.equals("")) { saux = lingua.translate("Sem descrio"); } if (mat.getMaterialTypeID() == 1) { Object[] ob = { req.getPerson().getName(), req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0), req.getBeginDate().toString(), saux, req.getSubject().getName() }; modelo.addRow(ob); } else { Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(), req.getEndDate().toString(), saux }; modelo.addRow(ob); } lista.add(req); andamento++; } break; case 1: estado = lingua.translate("terminado"); for (Keys.Request req : requisicoes) { if (req.isTerminated()) { String[] multipla = req.getActivity().split(":::"); String saux; if (multipla.length > 1) { saux = multipla[0]; Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua); pop.create(); jTable1.addMouseListener(new MouseAdapter() { int x = andamento; int y = 3; @Override public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { int row = jTable1.rowAtPoint(e.getPoint()); int col = jTable1.columnAtPoint(e.getPoint()); if ((row == x) && (col == y)) { pop.show(e.getComponent(), e.getX(), e.getY()); } } } @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (pop.isShowing()) { pop.setVisible(false); } } } }); } else { saux = req.getActivity(); } if (saux.equals("")) { saux = lingua.translate("Sem descrio"); } if (mat.getMaterialTypeID() == 1) { Object[] ob = { req.getPerson().getName(), req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0), req.getBeginDate().toString(), saux, req.getSubject().getName() }; modelo.addRow(ob); } else { Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(), req.getEndDate().toString(), saux }; modelo.addRow(ob); } lista.add(req); andamento++; } } break; case 2: estado = lingua.translate("no realizado"); for (Keys.Request req : requisicoes) { if ((!req.isActive()) && ((req.getEndDate().isBigger(new TimeDate.Date()) > 0) || ((req.getEndDate().isBigger(new TimeDate.Date()) == 0) && (req.getTimeEnd().compareTime(new TimeDate.Time()) > 0)))) { String[] multipla = req.getActivity().split(":::"); String saux; if (multipla.length > 1) { saux = multipla[0]; Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua); pop.create(); jTable1.addMouseListener(new MouseAdapter() { int x = andamento; int y = 3; @Override public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { int row = jTable1.rowAtPoint(e.getPoint()); int col = jTable1.columnAtPoint(e.getPoint()); if ((row == x) && (col == y)) { pop.show(e.getComponent(), e.getX(), e.getY()); } } } @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (pop.isShowing()) { pop.setVisible(false); } } } }); } else { saux = req.getActivity(); } if (saux.equals("")) { saux = lingua.translate("Sem descrio"); } if (mat.getMaterialTypeID() == 1) { Object[] ob = { req.getPerson().getName(), req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0), req.getBeginDate().toString(), saux, req.getSubject().getName() }; modelo.addRow(ob); } else { Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(), req.getEndDate().toString(), saux }; modelo.addRow(ob); } lista.add(req); andamento++; } } break; case 3: estado = lingua.translate("por realizar"); for (Keys.Request req : requisicoes) { if ((!req.isActive()) && (!req.isTerminated()) && ((req.getEndDate().isBigger(new TimeDate.Date()) < 0) || ((req.getEndDate().isBigger(new TimeDate.Date()) == 0) && (req.getTimeEnd().compareTime(new TimeDate.Time()) < 0)))) { String[] multipla = req.getActivity().split(":::"); String saux; if (multipla.length > 1) { saux = multipla[0]; Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua); pop.create(); jTable1.addMouseListener(new MouseAdapter() { int x = andamento; int y = 3; @Override public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { int row = jTable1.rowAtPoint(e.getPoint()); int col = jTable1.columnAtPoint(e.getPoint()); if ((row == x) && (col == y)) { pop.show(e.getComponent(), e.getX(), e.getY()); } } } @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (pop.isShowing()) { pop.setVisible(false); } } } }); } else { saux = req.getActivity(); } if (saux.equals("")) { saux = lingua.translate("Sem descrio"); } if (mat.getMaterialTypeID() == 1) { Object[] ob = { req.getPerson().getName(), req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0), req.getBeginDate().toString(), saux, req.getSubject().getName() }; modelo.addRow(ob); } else { Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(), req.getEndDate().toString(), saux }; modelo.addRow(ob); } lista.add(req); andamento++; } } break; } valores = new String[lista.size()][4]; for (int i = 0; i < lista.size(); i++) { String[] multipla = lista.get(i).getActivity().split(":::"); String saux = multipla[0]; if (saux.equals("")) { saux = lingua.translate("Sem descrio"); } if (mat.getMaterialTypeID() == 1) { valores[i][0] = lista.get(i).getPerson().getName(); valores[i][1] = lista.get(i).getTimeBegin().toString(0) + " - " + lista.get(i).getTimeEnd().toString(0); valores[i][2] = lista.get(i).getBeginDate().toString(); valores[i][3] = saux + " - " + lista.get(i).getSubject().getName(); } else { valores[i][0] = lista.get(i).getPerson().getName(); valores[i][1] = lista.get(i).getBeginDate().toString(); valores[i][2] = lista.get(i).getEndDate().toString(); valores[i][3] = saux; } } } public ActionListener actionJXDatePicker() { ActionListener l = (ActionEvent e) -> { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); String date = sdf.format(jXDatePickerFim.getDate()); String[] aux = date.split("/"); fim = new TimeDate.Date(Integer.valueOf(aux[0]), Integer.valueOf(aux[1]), Integer.valueOf(aux[2])); date = sdf.format(jXDatePickerInicio.getDate()); aux = date.split("/"); inicio = new TimeDate.Date(Integer.valueOf(aux[0]), Integer.valueOf(aux[1]), Integer.valueOf(aux[2])); if (fim.isBigger(inicio) > 0) { inicio = fim; jXDatePickerInicio.setDate(jXDatePickerFim.getDate()); } prefs.put("datafim", fim.toString()); prefs.put("datainicio", inicio.toString()); this.refreshTable(jComboBoxEstado.getSelectedIndex()); }; return l; } /** * @param painelcor the painelcor to set */ public void setPainelcor(java.awt.Color painelcor) { this.painelcor = painelcor; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtonExportar; private javax.swing.JButton jButtonImprimir; private javax.swing.JButton jButtonSair; private javax.swing.JComboBox<String> jComboBoxEstado; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPanel jPanelInicial; private javax.swing.JScrollPane jScrollPane1; /* private javax.swing.JTable jTable1; */ private org.jdesktop.swingx.JXTable jTable1; private org.jdesktop.swingx.JXDatePicker jXDatePickerFim; private org.jdesktop.swingx.JXDatePicker jXDatePickerInicio; // End of variables declaration//GEN-END:variables /** * @return the componentepai */ public javax.swing.JDialog getParentWindow() { return componentepai; } /** * @return the mat */ public Keys.Material getMaterial() { return mat; } /** * @return the prefs */ public Preferences getPreferences() { return prefs; } /** * @return the url */ public String getUrl() { return url; } /** * @return the inicio */ public TimeDate.Date getBeginning() { return inicio; } /** * @param inicio the inicio to set */ public void setBeginning(TimeDate.Date inicio) { this.inicio = inicio; } /** * @return the fim */ public TimeDate.Date getEnd() { return fim; } /** * @param fim the fim to set */ public void setEnd(TimeDate.Date fim) { this.fim = fim; } /** * @return the lista */ public java.util.List<Keys.Request> getList() { return lista; } /** * @param lista the lista to set */ public void setList(java.util.List<Keys.Request> lista) { this.lista = lista; } }