[..]
public class Uc4toolboxView extends FrameView {
public Uc4toolboxView(SingleFrameApplication app) {
super(app);
initComponents();
initOwnComponents();
// aktuelle Einstellungen laden und in der GUI setzen
setPreferences();
// Beim Beenden Programms alle Änderungen zurückschreiben
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
try {
storePreferences();
} catch(BackingStoreException ex) {
ex.printStackTrace();
}
}
}));
// status bar initialization - message timeout, idle icon and busy animation, etc
resourceMap = getResourceMap();
int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
messageTimer = new Timer(messageTimeout, new ActionListener() {
public void actionPerformed(ActionEvent e) {
statusMessageLabel.setText("");
}
});
messageTimer.setRepeats(false);
int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
for (int i = 0; i < busyIcons.length; i++) {
busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
}
busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
public void actionPerformed(ActionEvent e) {
busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
}
});
idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
statusAnimationLabel.setIcon(idleIcon);
// connecting action tasks to status bar via TaskMonitor
TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if ("started".equals(propertyName)) {
if (!busyIconTimer.isRunning()) {
statusAnimationLabel.setIcon(busyIcons[0]);
busyIconIndex = 0;
busyIconTimer.start();
}
} else if ("done".equals(propertyName)) {
busyIconTimer.stop();
statusAnimationLabel.setIcon(idleIcon);
} else if ("message".equals(propertyName)) {
String text = (String)(evt.getNewValue());
statusMessageLabel.setText((text == null) ? "" : text);
messageTimer.restart();
} else if ("progress".equals(propertyName)) {
int value = (Integer)(evt.getNewValue());
}
}
});
}
void storePreferences() throws BackingStoreException {
// Ermitteln des zuständigen Knotens
Preferences prefs = Preferences.userNodeForPackage(getClass());
// Speichern der Fenster-Position
prefs.put("export-path", exportpath);
prefs.put("utilities-path", utilitiespath);
prefs.put("util-ini-path", utilinipath);
// Zur Sicherheit alles zurückschreiben
prefs.flush();
}
void setPreferences() {
// Ermitteln des zuständigen Knotens
Preferences prefs;
prefs = Preferences.userNodeForPackage(getClass());
// Setzen der Pfade
exportpath = prefs.get("export-path", "");
utilitiespath = prefs.get("utilities-path", "");
utilinipath = prefs.get("util-ini-path", "");
}
@Action
public void showAboutBox() {
if (aboutBox == null) {
JFrame mainFrame = Uc4toolboxApp.getApplication().getMainFrame();
aboutBox = new Uc4toolboxAboutBox(mainFrame);
aboutBox.setLocationRelativeTo(mainFrame);
}
Uc4toolboxApp.getApplication().show(aboutBox);
}
/** 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">
private void initComponents() {
mainPanel = new javax.swing.JPanel();
jDesktopPane1 = new javax.swing.JDesktopPane();
menuBar = new javax.swing.JMenuBar();
javax.swing.JMenu MenuDatei = new javax.swing.JMenu();
MenuDateiCreate = new javax.swing.JMenuItem();
MenuDateiOpen = new javax.swing.JMenuItem();
MenuDateiClose = new javax.swing.JMenuItem();
MenuDateiCloseAll = new javax.swing.JMenuItem();
jSeparator3 = new javax.swing.JSeparator();
MenuDateiPrint = new javax.swing.JMenuItem();
MenuDateiTransport = new javax.swing.JMenuItem();
MenuDateiExport = new javax.swing.JMenu();
MenuDateiExportCSV = new javax.swing.JMenuItem();
MenuDateiExportHTML = new javax.swing.JMenuItem();
MenuDateiExportPDF = new javax.swing.JMenuItem();
jSeparator2 = new javax.swing.JSeparator();
MenuDateiEinstellungen = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JSeparator();
javax.swing.JMenuItem MenuDateiBeenden = new javax.swing.JMenuItem();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
javax.swing.JMenu helpMenu = new javax.swing.JMenu();
HelpMenuHelp = new javax.swing.JMenuItem();
javax.swing.JMenuItem HelpMenuAbout = new javax.swing.JMenuItem();
statusPanel = new javax.swing.JPanel();
javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
statusMessageLabel = new javax.swing.JLabel();
statusAnimationLabel = new javax.swing.JLabel();
mainPanel.setName("mainPanel"); // NOI18N
jDesktopPane1.setName("jDesktopPane1"); // NOI18N
org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jDesktopPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jDesktopPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 568, Short.MAX_VALUE)
);
menuBar.setName("menuBar"); // NOI18N
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(uc4toolbox.Uc4toolboxApp.class).getContext().getResourceMap(Uc4toolboxView.class);
MenuDatei.setText(resourceMap.getString("MenuDatei.text")); // NOI18N
MenuDatei.setName("MenuDatei"); // NOI18N
MenuDateiCreate.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
MenuDateiCreate.setText(resourceMap.getString("MenuDateiCreate.text")); // NOI18N
MenuDateiCreate.setName("MenuDateiCreate"); // NOI18N
MenuDatei.add(MenuDateiCreate);
javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(uc4toolbox.Uc4toolboxApp.class).getContext().getActionMap(Uc4toolboxView.class, this);
MenuDateiOpen.setAction(actionMap.get("openTk")); // NOI18N
MenuDateiOpen.setText(resourceMap.getString("MenuDateiOpen.text")); // NOI18N
MenuDateiOpen.setName("MenuDateiOpen"); // NOI18N
MenuDatei.add(MenuDateiOpen);
MenuDateiClose.setAction(actionMap.get("closeTk")); // NOI18N
MenuDateiClose.setText(resourceMap.getString("MenuDateiClose.text")); // NOI18N
MenuDateiClose.setName("MenuDateiClose"); // NOI18N
MenuDatei.add(MenuDateiClose);
MenuDateiCloseAll.setAction(actionMap.get("closeTkAll")); // NOI18N
MenuDateiCloseAll.setText(resourceMap.getString("MenuDateiCloseAll.text")); // NOI18N
MenuDateiCloseAll.setName("MenuDateiCloseAll"); // NOI18N
MenuDatei.add(MenuDateiCloseAll);
jSeparator3.setName("jSeparator3"); // NOI18N
MenuDatei.add(jSeparator3);
MenuDateiPrint.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
MenuDateiPrint.setText(resourceMap.getString("MenuDateiPrint.text")); // NOI18N
MenuDateiPrint.setEnabled(false);
MenuDateiPrint.setName("MenuDateiPrint"); // NOI18N
MenuDatei.add(MenuDateiPrint);
MenuDateiTransport.setAction(actionMap.get("transportBox")); // NOI18N
MenuDateiTransport.setText(resourceMap.getString("MenuDateiTransport.text")); // NOI18N
MenuDateiTransport.setName("MenuDateiTransport"); // NOI18N
MenuDatei.add(MenuDateiTransport);
MenuDateiExport.setText(resourceMap.getString("MenuDateiExport.text")); // NOI18N
MenuDateiExport.setEnabled(false);
MenuDateiExport.setName("MenuDateiExport"); // NOI18N
MenuDateiExportCSV.setText(resourceMap.getString("MenuDateiExportCSV.text")); // NOI18N
MenuDateiExportCSV.setEnabled(false);
MenuDateiExportCSV.setName("MenuDateiExportCSV"); // NOI18N
MenuDateiExport.add(MenuDateiExportCSV);
MenuDateiExportHTML.setText(resourceMap.getString("MenuDateiExportHTML.text")); // NOI18N
MenuDateiExportHTML.setEnabled(false);
MenuDateiExportHTML.setName("MenuDateiExportHTML"); // NOI18N
MenuDateiExport.add(MenuDateiExportHTML);
MenuDateiExportPDF.setText(resourceMap.getString("MenuDateiExportPDF.text")); // NOI18N
MenuDateiExportPDF.setEnabled(false);
MenuDateiExportPDF.setName("MenuDateiExportPDF"); // NOI18N
MenuDateiExport.add(MenuDateiExportPDF);
MenuDatei.add(MenuDateiExport);
jSeparator2.setName("jSeparator2"); // NOI18N
MenuDatei.add(jSeparator2);
MenuDateiEinstellungen.setAction(actionMap.get("showOptions")); // NOI18N
MenuDateiEinstellungen.setText(resourceMap.getString("MenuDateiEinstellungen.text")); // NOI18N
MenuDateiEinstellungen.setName("MenuDateiEinstellungen"); // NOI18N
MenuDatei.add(MenuDateiEinstellungen);
jSeparator1.setName("jSeparator1"); // NOI18N
MenuDatei.add(jSeparator1);
MenuDateiBeenden.setAction(actionMap.get("quit")); // NOI18N
MenuDateiBeenden.setText(resourceMap.getString("MenuDateiBeenden.text")); // NOI18N
MenuDateiBeenden.setName("MenuDateiBeenden"); // NOI18N
MenuDatei.add(MenuDateiBeenden);
menuBar.add(MenuDatei);
jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
jMenu1.setName("jMenu1"); // NOI18N
jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
jMenuItem1.setEnabled(false);
jMenuItem1.setName("jMenuItem1"); // NOI18N
jMenu1.add(jMenuItem1);
jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
jMenuItem2.setEnabled(false);
jMenuItem2.setName("jMenuItem2"); // NOI18N
jMenu1.add(jMenuItem2);
menuBar.add(jMenu1);
helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
helpMenu.setName("helpMenu"); // NOI18N
HelpMenuHelp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
HelpMenuHelp.setText(resourceMap.getString("HelpMenuHelp.text")); // NOI18N
HelpMenuHelp.setName("HelpMenuHelp"); // NOI18N
helpMenu.add(HelpMenuHelp);
HelpMenuAbout.setAction(actionMap.get("showAboutBox")); // NOI18N
HelpMenuAbout.setText(resourceMap.getString("HelpMenuAbout.text")); // NOI18N
HelpMenuAbout.setName("HelpMenuAbout"); // NOI18N
helpMenu.add(HelpMenuAbout);
menuBar.add(helpMenu);
statusPanel.setName("statusPanel"); // NOI18N
statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
statusMessageLabel.setName("statusMessageLabel"); // NOI18N
statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
org.jdesktop.layout.GroupLayout statusPanelLayout = new org.jdesktop.layout.GroupLayout(statusPanel);
statusPanel.setLayout(statusPanelLayout);
statusPanelLayout.setHorizontalGroup(
statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)
.add(statusPanelLayout.createSequentialGroup()
.addContainerGap()
.add(statusMessageLabel)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 780, Short.MAX_VALUE)
.add(statusAnimationLabel)
.addContainerGap())
);
statusPanelLayout.setVerticalGroup(
statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(statusPanelLayout.createSequentialGroup()
.add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(statusMessageLabel)
.add(statusAnimationLabel))
.add(3, 3, 3))
);
setComponent(mainPanel);
setMenuBar(menuBar);
setStatusBar(statusPanel);
}// </editor-fold>
private void initOwnComponents() {
tkBoxScrollPane = new javax.swing.JScrollPane();
tkBoxScrollPane.setName("jScrollPane1"); // NOI18N
Object[][] initO = new Object [][] {{null,null,null,null}};
String[] initS = new String [] {"Nr.", "Objekt", "Typ", "Beschreibung"};
tkTable.setModel(new DefaultTableModelImpl(initO,initS));
tkTable.setName("jTable1"); // NOI18N
tkBoxScrollPane.setViewportView(tkTable);
tkTable.getColumnModel().getColumn(0).setMinWidth(40);
tkTable.getColumnModel().getColumn(0).setPreferredWidth(40);
tkTable.getColumnModel().getColumn(0).setMaxWidth(100);
tkTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N
tkTable.getColumnModel().getColumn(1).setMinWidth(250);
tkTable.getColumnModel().getColumn(1).setPreferredWidth(300);
tkTable.getColumnModel().getColumn(1).setMaxWidth(1000);
tkTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title1")); // NOI18N
tkTable.getColumnModel().getColumn(2).setMinWidth(40);
tkTable.getColumnModel().getColumn(2).setPreferredWidth(40);
tkTable.getColumnModel().getColumn(2).setMaxWidth(60);
tkTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable1.columnModel.title2")); // NOI18N
tkTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTable1.columnModel.title3")); // NOI18N
}
@Action
public void showOptions() {
if (optionsBox == null) {
JFrame mainFrame = Uc4toolboxApp.getApplication().getMainFrame();
optionsBox = new Uc4toolboxOptions(mainFrame);
optionsBox.setLocation(200,200);
}
Uc4toolboxApp.getApplication().show(optionsBox);
}
@Action
public void openTk() {
//Menu ein-/ausschalten
MenuDateiClose.setEnabled(true);
MenuDateiCloseAll.setEnabled(true);
MenuDateiTransport.setEnabled(true);
MenuDateiExport.setEnabled(true);
MenuDateiExportCSV.setEnabled(true);
MenuDateiPrint.setEnabled(true);
//ggf. Vector leeren
if (csv.size() > 0) csv.removeAllElements();
//FileDialog:
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(mainPanel);
if(returnVal == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile().getName();
path = chooser.getSelectedFile().getPath();
transportkoffer = path.replace('\\', '/');
}
try
{
//Tabellenstruktur holen...
DefaultTableModel model = (DefaultTableModel)tkTable.getModel();
//Tabelle muss noch gelöscht werden
if (model.getRowCount()>0)
{
for (int co=model.getRowCount()-1; co >= 0; co--)
{
model.removeRow(co);
}
}
//Datei lesen
BufferedReader br = new BufferedReader(new FileReader(transportkoffer));
//in br ist alles was wir brauchen, jetzt muss geschnibbelt werden!
//Jede Zeile durchlaufen
counter = 0;
counterges = 0;
while ((input = br.readLine()) != null)
{
counterges++;
if (counterges == 2)
{
builddate = input.trim();
pos1 = input.length();
pos1 = pos1-17;
builddate = input.substring(pos1);
builddate = builddate.trim();
}
//Wenn Tabelleninhalt (z.b. TOH) gefunden, verarbeitung beginnen
if (input.equals("TOH"))
{
while(!input.equals("R"))
{
input = br.readLine();
if (input.startsWith("F002"))
{
field2 = input.substring(5);
}
if (input.startsWith("F003"))
{
field1 = input.substring(5);
}
if (input.startsWith("F005"))
{
field3 = input.substring(5);
}
}
if (field1.length() <= 0)
{
++counter;
//Gesammelte Daten in die Tabelle schmeissen:
model.addRow(new Object[]
{
counter,field1,field2,field3
});
String tempString = field1+";"+field2+";"+field3;
csv.addElement(tempString);
}
}
}
}
catch (Exception g)
{
System.err.println("File input error: "+g);
}
tkBoxtitle = "Transportkoffer "+file;
tkBoxinfo = ""+counter+" Objekte Export-Datum: "+builddate;
tkBoxFrame = new javax.swing.JInternalFrame();
resourceMap = org.jdesktop.application.Application.getInstance(uc4toolbox.Uc4toolboxApp.class).getContext().getResourceMap(Uc4toolboxView.class);
frameCount = frameCount+1;
tkBoxFrame.setName("tkBoxFrame"+frameCount);
tkBoxFrame.setClosable(true);
tkBoxFrame.setIconifiable(true);
tkBoxFrame.setMaximizable(true);
tkBoxFrame.setResizable(true);
tkBoxFrame.setVisible(true);
tkBoxFrame.setTitle(tkBoxtitle);
org.jdesktop.layout.GroupLayout tkBoxFrameLayout = new org.jdesktop.layout.GroupLayout(tkBoxFrame.getContentPane());
tkBoxFrame.getContentPane().setLayout(tkBoxFrameLayout);
tkBoxFrameLayout.setHorizontalGroup(
tkBoxFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(tkBoxScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)
);
tkBoxFrameLayout.setVerticalGroup(
tkBoxFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(tkBoxFrameLayout.createSequentialGroup()
.add(tkBoxScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
.addContainerGap())
);
framePos = framePos + 10;
tkBoxFrame.setBounds((70+framePos), (70+framePos), 380, 330);
jDesktopPane1.add(tkBoxFrame, javax.swing.JLayeredPane.DEFAULT_LAYER);
try {
tkBoxFrame.setSelected(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(Uc4toolboxView.class.getName()).log(Level.SEVERE, null, ex);
}
tkBoxFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
tkBoxFrame.addInternalFrameListener(tkBoxFrameCloseHandler);
}
@Action
public void closeTk() {
jDesktopPane1.getSelectedFrame().dispose();
if (jDesktopPane1.getAllFrames().length <= 0) {
MenuDateiClose.setEnabled(false);
MenuDateiCloseAll.setEnabled(false);
MenuDateiTransport.setEnabled(false);
MenuDateiExport.setEnabled(false);
MenuDateiExportCSV.setEnabled(false);
MenuDateiPrint.setEnabled(false);
}
}
@Action
public void closeTkAll() {
jDesktopPane1.removeAll();
jDesktopPane1.repaint();
MenuDateiClose.setEnabled(false);
MenuDateiCloseAll.setEnabled(false);
MenuDateiTransport.setEnabled(false);
MenuDateiExport.setEnabled(false);
MenuDateiExportCSV.setEnabled(false);
MenuDateiPrint.setEnabled(false);
}
@Action
public void transportBox() {
if (transportBox == null) {
JFrame mainFrame = Uc4toolboxApp.getApplication().getMainFrame();
transportBox = new Uc4toolboxTransport(mainFrame);
transportBox.setLocation(200,200);
}
Uc4toolboxApp.getApplication().show(transportBox);
}
// Variables declaration - do not modify
[..]
private class DefaultTableModelImpl extends DefaultTableModel {
public DefaultTableModelImpl(Object[][] data, Object[] columnNames) {
super(data, columnNames);
}
boolean[] canEdit = new boolean[]{false, false, false, false};
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
}
}