/* * 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; import javax.swing.DefaultListModel; public class WindowsDialog extends javax.swing.JDialog { private final MainFrame frame; private final DefaultListModel model; /** * Creates new form WindowsDialog */ public WindowsDialog(MainFrame frame, boolean modal) { super(frame, modal); this.frame=frame; model=new DefaultListModel(); initComponents(); // if(frame.fileTab.getTabCount() >0) { for(int i=0; i<MainFrame.FILE_TAB_INDEX; i++) { model.addElement(frame.fileTab.getToolTipTextAt(i)); // } } if(model.isEmpty()) { this.activateButton.setEnabled(false); } } /** * 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() { jScrollPane1 = new javax.swing.JScrollPane(); fileList = new javax.swing.JList(); activateButton = new javax.swing.JButton(); closeButton = new javax.swing.JButton(); exitButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Windows"); setResizable(false); fileList.setModel(model); fileList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); jScrollPane1.setViewportView(fileList); activateButton.setText("Activate"); activateButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { activateButtonActionPerformed(evt); } }); closeButton.setText("Close"); closeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { closeButtonActionPerformed(evt); } }); exitButton.setText("Exit"); exitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitButtonActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(activateButton, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(closeButton, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(exitButton, javax.swing.GroupLayout.Alignment.TRAILING)) .addContainerGap()) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {activateButton, closeButton, exitButton}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(activateButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(closeButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(exitButton)) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)) .addContainerGap()) ); layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {activateButton, closeButton, exitButton}); pack(); }// </editor-fold>//GEN-END:initComponents private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed dispose(); }//GEN-LAST:event_exitButtonActionPerformed private void activateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_activateButtonActionPerformed Object selectedValue = this.fileList.getSelectedValue(); if(selectedValue != null) { String file = this.fileList.getSelectedValue().toString(); if(frame.fileTab.getTabCount() >=0) { for(int i=0; i<MainFrame.FILE_TAB_INDEX; i++) { if(file.equals(frame.fileTab.getToolTipTextAt(i))) { frame.fileTab.setSelectedIndex(i); //MainFrame.FILE_TAB_INDEX=(i); } } } } }//GEN-LAST:event_activateButtonActionPerformed private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed Object selectedValue = this.fileList.getSelectedValue(); if(!model.isEmpty()) { if(selectedValue != null) { String file = this.fileList.getSelectedValue().toString(); if(frame.fileTab.getTabCount() >=0) { for(int i=0; i<MainFrame.FILE_TAB_INDEX; i++) { if(file.equals(frame.fileTab.getToolTipTextAt(i))) { frame.askSave(i); model.remove(i); } } } } }else{ dispose(); } }//GEN-LAST:event_closeButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton activateButton; private javax.swing.JButton closeButton; private javax.swing.JButton exitButton; private javax.swing.JList fileList; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables }