/* * Copyright (C) 2013 Vinu K.N * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.domainmath.gui.packages.image; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class ImgInfoPanel extends JPanel { JTable table; private final ImgInfoDataFileTableModel model; private final String directory; private final ImageToolFrame frame; public ImgInfoPanel(String directory,ImageToolFrame frame) { // super(new GridLayout(1, 0)); super(new BorderLayout()); this.frame=frame; table = new JTable(); this.directory = directory; model = new ImgInfoDataFileTableModel(directory); model.init(); table.setModel(model); // table.setAutoCreateColumnsFromModel(true); // table.setAutoCreateRowSorter(true); table.getTableHeader().setReorderingAllowed(false); //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(20); JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true); add(scrollPane,BorderLayout.CENTER); } public ImgInfoDataFileTableModel getModel() { return model; } public void reload() { frame.generateProperties(); new DataTask().execute(); } private class DataTask extends SwingWorker<Void, Void> { @Override protected Void doInBackground() { int delay = 1000; //milliseconds ActionListener taskPerformer = new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { model.refresh(); model.fireTableStructureChanged(); model.fireTableDataChanged(); table.repaint(); } }; javax.swing.Timer t= new javax.swing.Timer(delay, taskPerformer); t.setRepeats(false); t.start(); return null; } @Override protected void done() { try { int delay = 1000; //milliseconds ActionListener taskPerformer = new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { model.refresh(); model.fireTableStructureChanged(); model.fireTableDataChanged(); table.repaint(); } }; javax.swing.Timer t= new javax.swing.Timer(delay, taskPerformer); t.setRepeats(false); t.start(); } catch (Exception ignore) { } } } }