diff --git a/src/de/mpg/molgen/buczek/portifix/Gui.form b/src/de/mpg/molgen/buczek/portifix/Gui.form index 5abf62c..9ee0a8b 100644 --- a/src/de/mpg/molgen/buczek/portifix/Gui.form +++ b/src/de/mpg/molgen/buczek/portifix/Gui.form @@ -3,6 +3,7 @@
+ diff --git a/src/de/mpg/molgen/buczek/portifix/Gui.java b/src/de/mpg/molgen/buczek/portifix/Gui.java index b59a4ee..d719c36 100644 --- a/src/de/mpg/molgen/buczek/portifix/Gui.java +++ b/src/de/mpg/molgen/buczek/portifix/Gui.java @@ -7,10 +7,15 @@ import java.awt.Component; import java.awt.Container; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -19,7 +24,10 @@ import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.AbstractAction; +import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; +import javax.swing.TransferHandler; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.table.DefaultTableCellRenderer; @@ -80,17 +88,16 @@ private String singleColumnValueOfArray(String s[]) { private String singleColumnValueOfSelection(int col) { return singleColumnValueOfArray(columnValuesOfSelection(col)); } - + private static void setTreeEnabled(Component component, boolean enabled) { - component.setEnabled(enabled); - if (component instanceof Container) { - Container container = (Container)component; - for (Component child : container.getComponents()) { - setTreeEnabled(child,enabled); - } - } + component.setEnabled(enabled); + if (component instanceof Container) { + Container container = (Container) component; + for (Component child : container.getComponents()) { + setTreeEnabled(child, enabled); + } + } } - private void updateForm() { @@ -100,7 +107,7 @@ private void updateForm() { } else { String[] name = new String[selected.length]; for (int i = 0; i < name.length; i++) { - int mi=jTable1.convertRowIndexToModel(selected[i]); + int mi = jTable1.convertRowIndexToModel(selected[i]); name[i] = tableModel.getValueAt(mi, 1) + " " + tableModel.getValueAt(mi, 0); } jLabel_name.setText(singleColumnValueOfArray(name)); @@ -113,6 +120,7 @@ private void updateForm() { private void startEdit() { jTable1.setEnabled(false); + setTreeEnabled(jTable1, false); jButton_refresh.setEnabled(false); jButton_saveall.setEnabled(true); jButton_savethis.setEnabled(true); @@ -121,6 +129,7 @@ private void startEdit() { private void stopEdit() { jTable1.setEnabled(true); + setTreeEnabled(jTable1, true); jButton_refresh.setEnabled(true); jButton_saveall.setEnabled(false); jButton_savethis.setEnabled(false); @@ -169,6 +178,8 @@ public void run() { tableModel = new TableModel(); initComponents(); + jTable1.addMouseListener(popupListener); + Properties p = new Properties(); p.setProperty("text.today", "today"); p.setProperty("text.month", "month"); @@ -208,7 +219,8 @@ public void focusGained(FocusEvent e) { } @Override - public void focusLost(FocusEvent e) { } + public void focusLost(FocusEvent e) { + } }); jButton_cancel.addActionListener(new ActionListener() { @@ -233,6 +245,17 @@ public void actionPerformed(ActionEvent e) { }); getRootPane().setDefaultButton(jButton_saveall); + + // Action copy=jTable1.getActionMap().get("copy"); + popupMenu.add(new AbstractAction("copy") { + + @Override + public void actionPerformed(ActionEvent e) { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + jTable1.getTransferHandler().exportToClipboard(jTable1, clipboard, TransferHandler.COPY); + } + }); + updateForm(); } @@ -264,6 +287,7 @@ private void initComponents() { jTable1 = new javax.swing.JTable(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("Portifix"); jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); @@ -414,6 +438,7 @@ private void jButton_saveallActionPerformed(java.awt.event.ActionEvent evt) {//G /** * @param args the command line arguments + * @throws java.sql.SQLException */ public static void main(String args[]) throws SQLException { @@ -430,19 +455,16 @@ public static void main(String args[]) throws SQLException { break; } } - } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } // + + // /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { + @Override public void run() { new Gui().setVisible(true); } @@ -468,4 +490,28 @@ public void run() { private javax.swing.JTable jTable1; private javax.swing.JTextField jTextField_datum; // End of variables declaration//GEN-END:variables + + private final JPopupMenu popupMenu = new JPopupMenu(); + + private final MouseListener popupListener = new MouseAdapter() { + + @Override + public void mousePressed(MouseEvent e) { + maybeShowPopup(e); + } + + @Override + public void mouseReleased(MouseEvent e) { + maybeShowPopup(e); + } + + private void maybeShowPopup(MouseEvent e) { + Component c = e.getComponent(); + if (e.isPopupTrigger() && c.isEnabled()) { + popupMenu.show(c, e.getX(), e.getY()); + } + } + + }; + } diff --git a/src/de/mpg/molgen/buczek/portifix/PopupListener.java b/src/de/mpg/molgen/buczek/portifix/PopupListener.java new file mode 100644 index 0000000..71e6b87 --- /dev/null +++ b/src/de/mpg/molgen/buczek/portifix/PopupListener.java @@ -0,0 +1,40 @@ +/* + * 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 de.mpg.molgen.buczek.portifix; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JPopupMenu; + +/** + * + * @author buczek + */ +public class PopupListener extends MouseAdapter { + + JPopupMenu popup; + + public PopupListener(JPopupMenu popup) { + this.popup = popup; + } + + @Override + public void mousePressed(MouseEvent e) { + maybeShowPopup(e); + } + + @Override + public void mouseReleased(MouseEvent e) { + maybeShowPopup(e); + } + + private void maybeShowPopup(MouseEvent e) { + if (e.isPopupTrigger()) { + popup.show(e.getComponent(), e.getX(), e.getY()); + } + } + +}