chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1204622 - in /chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench: CreateDocumentDialog.java CreateFolderDialog.java swing/InfoPanel.java
Date Mon, 21 Nov 2011 18:04:03 GMT
Author: fmui
Date: Mon Nov 21 18:04:02 2011
New Revision: 1204622

URL: http://svn.apache.org/viewvc?rev=1204622&view=rev
Log:
Workbench: cosmetic changes

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateDocumentDialog.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateFolderDialog.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/swing/InfoPanel.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateDocumentDialog.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateDocumentDialog.java?rev=1204622&r1=1204621&r2=1204622&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateDocumentDialog.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateDocumentDialog.java
Mon Nov 21 18:04:02 2011
@@ -19,6 +19,7 @@
 package org.apache.chemistry.opencmis.workbench;
 
 import java.awt.BorderLayout;
+import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.Frame;
 import java.awt.event.ActionEvent;
@@ -182,6 +183,8 @@ public class CreateDocumentDialog extend
                 String filename = filenameField.getText();
 
                 try {
+                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
                     if (filename.length() > 0) {
                         // create a document from a file
                         ObjectId objectId = getClientModel().createDocument(name, type, filename,
@@ -217,6 +220,8 @@ public class CreateDocumentDialog extend
                 } catch (Exception e) {
                     ClientHelper.showError(null, e);
                 } finally {
+                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+
                     try {
                         getClientModel().reloadFolder();
                     } catch (Exception e) {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateFolderDialog.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateFolderDialog.java?rev=1204622&r1=1204621&r2=1204622&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateFolderDialog.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateFolderDialog.java
Mon Nov 21 18:04:02 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.chemistry.opencmis.workbench;
 
+import java.awt.Cursor;
 import java.awt.Frame;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -59,13 +60,22 @@ public class CreateFolderDialog extends 
                 String type = ((ObjectTypeItem) typeBox.getSelectedItem()).getObjectType().getId();
 
                 try {
+                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
                     getClientModel().createFolder(name, type);
-                    getClientModel().reloadFolder();
 
                     thisDialog.setVisible(false);
                     thisDialog.dispose();
                 } catch (Exception e) {
                     ClientHelper.showError(null, e);
+                } finally {
+                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+
+                    try {
+                        getClientModel().reloadFolder();
+                    } catch (Exception e) {
+                        ClientHelper.showError(null, e);
+                    }
                 }
             }
         });

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/swing/InfoPanel.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/swing/InfoPanel.java?rev=1204622&r1=1204621&r2=1204622&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/swing/InfoPanel.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/swing/InfoPanel.java
Mon Nov 21 18:04:02 2011
@@ -23,9 +23,18 @@ import java.awt.Cursor;
 import java.awt.Desktop;
 import java.awt.FlowLayout;
 import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.net.URI;
@@ -35,12 +44,12 @@ import javax.swing.BorderFactory;
 import javax.swing.BoxLayout;
 import javax.swing.JComponent;
 import javax.swing.JLabel;
+import javax.swing.JMenuItem;
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 import javax.swing.JTextField;
 import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
 
 import org.apache.chemistry.opencmis.workbench.ClientHelper;
 import org.apache.chemistry.opencmis.workbench.model.ClientModel;
@@ -86,7 +95,10 @@ public abstract class InfoPanel extends 
     }
 
     protected JTextField addLine(final String label, final boolean bold) {
-        JTextField textField = new JTextField();
+        return addLine(label, bold, new JTextField());
+    }
+
+    protected JTextField addLine(final String label, final boolean bold, JTextField textField)
{
         textField.setEditable(false);
         textField.setBorder(BorderFactory.createEmptyBorder());
         if (bold) {
@@ -113,127 +125,11 @@ public abstract class InfoPanel extends 
     }
 
     protected JTextField addId(final String label) {
-        final JTextField textField = addLine(label, false);
-
-        textField.getDocument().addDocumentListener(new DocumentListener() {
-            @Override
-            public void removeUpdate(DocumentEvent e) {
-
-            }
-
-            @Override
-            public void insertUpdate(DocumentEvent e) {
-                String id = textField.getText();
-                if (id.length() > 0 && !id.startsWith("(")) {
-                    textField.setForeground(ClientHelper.LINK_COLOR);
-                    textField.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
-                } else {
-                    textField.setForeground(UIManager.getColor("textForeground"));
-                    textField.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
-                }
-            }
-
-            @Override
-            public void changedUpdate(DocumentEvent e) {
-            }
-        });
-
-        textField.addMouseListener(new MouseListener() {
-            @Override
-            public void mouseReleased(MouseEvent e) {
-            }
-
-            @Override
-            public void mousePressed(MouseEvent e) {
-            }
-
-            @Override
-            public void mouseExited(MouseEvent e) {
-            }
-
-            @Override
-            public void mouseEntered(MouseEvent e) {
-            }
-
-            @Override
-            public void mouseClicked(MouseEvent e) {
-                if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 1)
{
-                    String id = textField.getText();
-                    if (id.length() > 0 && !id.startsWith("(")) {
-                        try {
-                            getClientModel().loadObject(id);
-                        } catch (Exception ex) {
-                            ClientHelper.showError(InfoPanel.this, ex);
-                        }
-                    }
-                }
-            }
-        });
-
-        return textField;
+        return addLine(label, false, new IdTextField());
     }
 
     protected JTextField addLink(final String label) {
-        final JTextField textField = addLine(label, false);
-
-        if (Desktop.isDesktopSupported()) {
-            textField.getDocument().addDocumentListener(new DocumentListener() {
-                @Override
-                public void removeUpdate(DocumentEvent e) {
-
-                }
-
-                @Override
-                public void insertUpdate(DocumentEvent e) {
-                    String uri = textField.getText().toLowerCase();
-                    if (uri.startsWith("http://") || uri.startsWith("https://")) {
-                        textField.setForeground(Color.BLUE);
-                        textField.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
-                    } else {
-                        textField.setForeground(UIManager.getColor("textForeground"));
-                        textField.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
-                    }
-                }
-
-                @Override
-                public void changedUpdate(DocumentEvent e) {
-                }
-            });
-
-            textField.addMouseListener(new MouseListener() {
-                @Override
-                public void mouseReleased(MouseEvent e) {
-                }
-
-                @Override
-                public void mousePressed(MouseEvent e) {
-                }
-
-                @Override
-                public void mouseExited(MouseEvent e) {
-                }
-
-                @Override
-                public void mouseEntered(MouseEvent e) {
-                }
-
-                @Override
-                public void mouseClicked(MouseEvent e) {
-                    if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount()
== 1) {
-                        String uri = textField.getText().toLowerCase();
-                        if (uri.startsWith("http://") || uri.startsWith("https://")) {
-                            try {
-                                Desktop.getDesktop().browse(new URI(textField.getText()));
-                            } catch (Exception ex) {
-                                ClientHelper.showError(InfoPanel.this, ex);
-                            }
-                        }
-                    }
-                }
-            });
-        }
-
-        return textField;
+        return addLine(label, false, new UrlTextField());
     }
 
     protected YesNoLabel addYesNoLabel(String label) {
@@ -305,4 +201,179 @@ public abstract class InfoPanel extends 
             }
         }
     }
+
+    private abstract class ClickableTextField extends JTextField {
+        private static final long serialVersionUID = 1L;
+
+        private String link;
+        private final JPopupMenu popup;
+
+        public ClickableTextField() {
+            popup = new JPopupMenu();
+            final JMenuItem menuItem = new JMenuItem("Copy to clipboard");
+            popup.add(menuItem);
+
+            menuItem.addActionListener(new ActionListener() {
+                public void actionPerformed(ActionEvent e) {
+                    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+                    Transferable transferable = new StringSelection(link);
+                    clipboard.setContents(transferable, null);
+                }
+            });
+
+            addMouseListener(new MouseListener() {
+
+                @Override
+                public void mouseExited(MouseEvent e) {
+                }
+
+                @Override
+                public void mouseEntered(MouseEvent e) {
+                }
+
+                @Override
+                public void mouseClicked(MouseEvent e) {
+                    if (link != null) {
+                        if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount()
== 1) {
+                            try {
+                                linkAction(link);
+                            } catch (Exception ex) {
+                                ClientHelper.showError(InfoPanel.this, ex);
+                            }
+                        }
+                    }
+                }
+
+                @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());
+                    }
+                }
+            });
+        }
+
+        public abstract boolean isLink(String link);
+
+        public abstract Color getLinkColor(String link);
+
+        public abstract void linkAction(String link);
+
+        @Override
+        public void setText(String text) {
+            if (!isLink(text)) {
+                setForeground(UIManager.getColor("textForeground"));
+                setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+                popup.setEnabled(false);
+                link = null;
+            } else {
+                setForeground(getLinkColor(text));
+                setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+                popup.setEnabled(true);
+                link = text;
+            }
+
+            super.setText(text);
+        }
+
+        @Override
+        public void validate() {
+        }
+
+        @Override
+        public void revalidate() {
+        }
+
+        @Override
+        public void repaint(long tm, int x, int y, int width, int height) {
+        }
+
+        @Override
+        public void repaint(Rectangle r) {
+        }
+
+        @Override
+        public void paintComponent(Graphics g) {
+            super.paintComponent(g);
+
+            if (link != null) {
+                FontMetrics fm = getFontMetrics(getFont());
+
+                int y1 = fm.getHeight() - 2;
+                int x2 = fm.stringWidth(link);
+                g.setColor(getLinkColor(link));
+                g.drawLine(0, y1, x2, y1);
+            }
+        }
+    }
+
+    private class IdTextField extends ClickableTextField {
+        private static final long serialVersionUID = 1L;
+
+        public IdTextField() {
+            super();
+        }
+
+        @Override
+        public boolean isLink(String link) {
+            return link != null && link.length() > 0 && !link.startsWith("(");
+        }
+
+        @Override
+        public Color getLinkColor(String link) {
+            return ClientHelper.LINK_COLOR;
+        }
+
+        @Override
+        public void linkAction(String link) {
+            try {
+                getClientModel().loadObject(link);
+            } catch (Exception ex) {
+                ClientHelper.showError(InfoPanel.this, ex);
+            }
+        }
+    }
+
+    private class UrlTextField extends ClickableTextField {
+        private static final long serialVersionUID = 1L;
+
+        public UrlTextField() {
+            super();
+        }
+
+        @Override
+        public boolean isLink(String link) {
+            if (link == null || link.length() == 0) {
+                return false;
+            }
+
+            String lower = link.toLowerCase();
+            return lower.startsWith("http://") || lower.startsWith("https://");
+        }
+
+        @Override
+        public Color getLinkColor(String link) {
+            return Color.BLUE;
+        }
+
+        @Override
+        public void linkAction(String link) {
+            if (Desktop.isDesktopSupported()) {
+                try {
+                    Desktop.getDesktop().browse(new URI(link));
+                } catch (Exception ex) {
+                    ClientHelper.showError(InfoPanel.this, ex);
+                }
+            }
+        }
+    }
 }



Mime
View raw message