OSDN Git Service

replace anonymouse classes with local classes and avoid synthetic-access
authorargius <argius.net@gmail.com>
Sat, 29 Nov 2014 02:43:00 +0000 (11:43 +0900)
committerargius <argius.net@gmail.com>
Sat, 29 Nov 2014 02:43:00 +0000 (11:43 +0900)
in order to reduce nameless class files (with refactoring)

src/net/argius/stew/ui/window/ConnectorMapEditDialog.java
src/net/argius/stew/ui/window/ConsoleTextArea.java
src/net/argius/stew/ui/window/DatabaseInfoTree.java
src/net/argius/stew/ui/window/ResultSetTable.java
src/net/argius/stew/ui/window/ResultSetTableModel.java
src/net/argius/stew/ui/window/TextSearchPanel.java
src/net/argius/stew/ui/window/WindowLauncher.java
src/net/argius/stew/ui/window/WindowOutputProcessor.java

index 518aa76..a95b23b 100644 (file)
@@ -5,15 +5,12 @@ import static javax.swing.JOptionPane.*;
 import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
 import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
 import static net.argius.stew.ui.window.ConnectorMapEditDialog.ActionKey.*;
-
 import java.awt.*;
 import java.awt.event.*;
 import java.io.*;
 import java.util.*;
-
 import javax.swing.*;
 import javax.swing.event.*;
-
 import net.argius.stew.*;
 
 final class ConnectorMapEditDialog extends JDialog implements ChangeListener, AnyActionListener {
@@ -80,11 +77,12 @@ final class ConnectorMapEditDialog extends JDialog implements ChangeListener, An
     }
 
     private final class IdListMouseListener extends MouseAdapter {
+        IdListMouseListener() {
+        } // empty
         @Override
         public void mouseClicked(MouseEvent e) {
             if (e.getClickCount() % 2 == 0) {
-                ConnectorEntry entry = (ConnectorEntry)idList.getSelectedValue();
-                openConnectorEditDialog(entry.getConnector());
+                openConnectorEditDialog();
             }
         }
     }
@@ -192,6 +190,11 @@ final class ConnectorMapEditDialog extends JDialog implements ChangeListener, An
         return button;
     }
 
+    void openConnectorEditDialog() {
+        ConnectorEntry entry = (ConnectorEntry)idList.getSelectedValue();
+        openConnectorEditDialog(entry.getConnector());
+    }
+
     private void openConnectorEditDialog(Connector connector) {
         ConnectorEditDialog dialog = new ConnectorEditDialog(this, connector);
         dialog.addChangeListener(this);
index 0472d87..781ce03 100644 (file)
@@ -281,6 +281,8 @@ final class ConsoleTextArea extends JTextArea implements AnyActionListener, Text
     }
 
     private final class TextSearchKeyListener extends KeyAdapter {
+        TextSearchKeyListener() {
+        } // empty
         @Override
         public void keyTyped(KeyEvent e) {
             removeKeyListener(this);
index 267b194..578f0b3 100644 (file)
@@ -41,14 +41,15 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
         toggleShowColumnNumber
     }
 
-    private static final Logger log = Logger.getLogger(DatabaseInfoTree.class);
+    static final Logger log = Logger.getLogger(DatabaseInfoTree.class);
+
     private static final ResourceManager res = ResourceManager.getInstance(DatabaseInfoTree.class);
 
     private static final String TABLE_TYPE_TABLE = "TABLE";
     private static final String TABLE_TYPE_VIEW = "VIEW";
     private static final String TABLE_TYPE_INDEX = "INDEX";
     private static final String TABLE_TYPE_SEQUENCE = "SEQUENCE";
-    private static final List<String> DEFAULT_TABLE_TYPES = //
+    static final List<String> DEFAULT_TABLE_TYPES = //
     Arrays.asList(TABLE_TYPE_TABLE, TABLE_TYPE_VIEW, TABLE_TYPE_INDEX, TABLE_TYPE_SEQUENCE);
 
     static volatile boolean showColumnNumber;
@@ -462,7 +463,7 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
         expandNode(connectorNode, dbmeta);
         createdStatusSet.add(connectorNode);
         // events
-        addTreeWillExpandListener(new TreeWillExpandListener() {
+        class TreeWillExpandListenerImpl implements TreeWillExpandListener {
             @Override
             public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
                 TreePath path = event.getPath();
@@ -484,7 +485,8 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
             public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
                 // ignore
             }
-        });
+        }
+        addTreeWillExpandListener(new TreeWillExpandListenerImpl());
         this.dbmeta = dbmeta;
         // showing
         model.reload();
@@ -578,37 +580,21 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
             return;
         }
         final DefaultTreeModel model = (DefaultTreeModel)getModel();
-        final InfoNode tmpNode = new InfoNode(res.get("i.paren-in-processing")) {
-            @Override
-            protected List<InfoNode> createChildren(DatabaseMetaData dbmeta) throws SQLException {
-                return Collections.emptyList();
-            }
-            @Override
-            public boolean isLeaf() {
-                return true;
-            }
-        };
-        invokeLater(new Runnable() {
-            @Override
-            public void run() {
-                model.insertNodeInto(tmpNode, parent, 0);
-            }
-        });
+        final DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(res.get("i.paren-in-processing"));
         // asynchronous
-        DaemonThreadFactory.execute(new Runnable() {
+        class NodeExpansionTask implements Runnable {
             @Override
             public void run() {
+                class Task1 implements Runnable {
+                    @Override
+                    public void run() {
+                        model.insertNodeInto(tmpNode, parent, 0);
+                    }
+                }
+                invokeLater(new Task1());
+                final List<InfoNode> children;
                 try {
-                    final List<InfoNode> children = new ArrayList<InfoNode>(parent.createChildren(dbmeta));
-                    invokeLater(new Runnable() {
-                        @Override
-                        public void run() {
-                            for (InfoNode child : children) {
-                                model.insertNodeInto(child, parent, parent.getChildCount());
-                            }
-                            model.removeNodeFromParent(tmpNode);
-                        }
-                    });
+                    children = new ArrayList<InfoNode>(parent.createChildren(dbmeta));
                 } catch (SQLException ex) {
                     try {
                         if (dbmeta.getConnection().isClosed())
@@ -618,8 +604,19 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
                     }
                     throw new RuntimeException(ex);
                 }
+                class Task2 implements Runnable {
+                    @Override
+                    public void run() {
+                        for (InfoNode child : children) {
+                            model.insertNodeInto(child, parent, parent.getChildCount());
+                        }
+                        model.removeNodeFromParent(tmpNode);
+                    }
+                }
+                invokeLater(new Task2());
             }
-        });
+        }
+        DaemonThreadFactory.execute(new NodeExpansionTask());
     }
 
     /**
@@ -671,9 +668,7 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
                                                       int row,
                                                       boolean hasFocus) {
             super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
-            if (value instanceof InfoNode) {
-                setIcon(Utilities.getImageIcon(((InfoNode)value).getIconName()));
-            }
+            setIcon((value instanceof InfoNode) ? Utilities.getImageIcon(((InfoNode)value).getIconName()) : null);
             if (value instanceof ColumnNode) {
                 if (showColumnNumber) {
                     TreePath path = tree.getPathForRow(row);
@@ -901,11 +896,7 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea
             ResultSet rs = dbmeta.getColumns(catalog, schema, name, null);
             try {
                 while (rs.next()) {
-                    a.add(new ColumnNode(rs.getString(4),
-                                         rs.getString(6),
-                                         rs.getInt(7),
-                                         rs.getString(18),
-                                         this));
+                    a.add(new ColumnNode(rs.getString(4), rs.getString(6), rs.getInt(7), rs.getString(18), this));
                 }
             } finally {
                 rs.close();
index cdb9915..43e629a 100644 (file)
@@ -7,7 +7,6 @@ import static java.awt.event.MouseEvent.MOUSE_PRESSED;
 import static javax.swing.KeyStroke.getKeyStroke;
 import static net.argius.stew.ui.window.AnyActionKey.*;
 import static net.argius.stew.ui.window.ResultSetTable.ActionKey.*;
-
 import java.awt.*;
 import java.awt.event.*;
 import java.beans.*;
@@ -15,12 +14,10 @@ import java.io.*;
 import java.sql.*;
 import java.util.*;
 import java.util.List;
-
 import javax.swing.*;
 import javax.swing.event.*;
 import javax.swing.table.*;
 import javax.swing.text.*;
-
 import net.argius.stew.*;
 import net.argius.stew.io.*;
 import net.argius.stew.text.*;
@@ -108,25 +105,25 @@ final class ResultSetTable extends JTable implements AnyActionListener, TextSear
     }
 
     private final class RowHeaderMouseInputListener extends MouseInputAdapter {
-    
+
         @SuppressWarnings("hiding")
         private final RowHeader rowHeader;
         private int dragStartRow;
-    
+
         RowHeaderMouseInputListener(RowHeader rowHeader) {
             this.rowHeader = rowHeader;
         }
-    
+
         @Override
         public void mousePressed(MouseEvent e) {
             changeSelection(e);
         }
-    
+
         @Override
         public void mouseDragged(MouseEvent e) {
             changeSelection(e);
         }
-    
+
         private void changeSelection(MouseEvent e) {
             Point p = new Point(e.getX(), e.getY());
             if (SwingUtilities.isLeftMouseButton(e)) {
@@ -175,9 +172,9 @@ final class ResultSetTable extends JTable implements AnyActionListener, TextSear
     }
 
     private final class ColumnHeaderMouseInputListener extends MouseInputAdapter {
-    
+
         private int dragStartColumn;
-    
+
         ColumnHeaderMouseInputListener() {
         } // empty
 
@@ -189,14 +186,14 @@ final class ResultSetTable extends JTable implements AnyActionListener, TextSear
             }
             mousePositionForColumnHeader.setLocation(e.getPoint());
         }
-    
+
         @Override
         public void mouseDragged(MouseEvent e) {
             if (SwingUtilities.isLeftMouseButton(e)) {
                 changeSelection(e);
             }
         }
-    
+
         private void changeSelection(MouseEvent e) {
             final Point p = e.getPoint();
             int id = e.getID();
@@ -307,7 +304,7 @@ final class ResultSetTable extends JTable implements AnyActionListener, TextSear
             } else {
                 for (final int i : getSelectedColumns()) {
                     a.add(m.getColumnName(i));
-                }   
+                }
             }
             ClipboardHelper.setString(TextUtilities.join(TAB, a));
         } else if (ev.isAnyOf(findColumnName)) {
@@ -450,12 +447,13 @@ final class ResultSetTable extends JTable implements AnyActionListener, TextSear
                 final JTextComponent text = (JTextComponent)c;
                 AnyAction aa = new AnyAction(text);
                 aa.setUndoAction();
-                c.addFocusListener(new FocusAdapter() {
+                class EditCanceledOnCellFocusLost extends FocusAdapter {
                     @Override
                     public void focusLost(FocusEvent e) {
                         editingCanceled(new ChangeEvent(e.getSource()));
                     }
-                });
+                }
+                c.addFocusListener(new EditCanceledOnCellFocusLost());
             }
         }
     }
@@ -664,7 +662,7 @@ final class ResultSetTable extends JTable implements AnyActionListener, TextSear
             }
             table.changeSelection(ri, ci, false, extend);
         }
-        
+
     }
 
     private static final class NullValueRenderer extends DefaultTableCellRenderer {
index b320de2..a1a92c8 100644 (file)
@@ -4,16 +4,13 @@ import static java.awt.EventQueue.invokeLater;
 import static java.sql.Types.*;
 import static java.util.Collections.nCopies;
 import static net.argius.stew.text.TextUtilities.join;
-
 import java.math.*;
 import java.sql.*;
 import java.util.*;
 import java.util.Map.Entry;
 import java.util.concurrent.*;
 import java.util.regex.*;
-
 import javax.swing.table.*;
-
 import net.argius.stew.*;
 
 /**
@@ -22,7 +19,7 @@ import net.argius.stew.*;
  */
 final class ResultSetTableModel extends DefaultTableModel {
 
-    private static final Logger log = Logger.getLogger(ResultSetTableModel.class);
+    static final Logger log = Logger.getLogger(ResultSetTableModel.class);
 
     private static final long serialVersionUID = -8861356207097438822L;
     private static final String PTN1 = "\\s*SELECT\\s.+?\\sFROM\\s+([^\\s]+).*";
@@ -230,20 +227,20 @@ final class ResultSetTableModel extends DefaultTableModel {
     }
 
     private static final class RowComparator implements Comparator<List<Object>> {
-    
+
         private final int f;
         private final int columnIndex;
-    
+
         RowComparator(int f, int columnIndex) {
             this.f = f;
             this.columnIndex = columnIndex;
         }
-    
+
         @Override
         public int compare(List<Object> row1, List<Object> row2) {
             return c(row1, row2) * f;
         }
-    
+
         private int c(List<Object> row1, List<Object> row2) {
             if (row1 == null || row2 == null) {
                 return row1 == null ? row2 == null ? 0 : -1 : 1;
@@ -274,7 +271,7 @@ final class ResultSetTableModel extends DefaultTableModel {
     }
 
     /**
-     * Checks whether this table is linkable. 
+     * Checks whether this table is linkable.
      * @return
      */
     boolean isLinkable() {
@@ -365,9 +362,10 @@ final class ResultSetTableModel extends DefaultTableModel {
         }
         final CountDownLatch latch = new CountDownLatch(1);
         final List<SQLException> errors = new ArrayList<SQLException>();
+        final Connection conn = this.conn;
+        final int[] types = this.types;
         // asynchronous execution
-        DaemonThreadFactory.execute(new Runnable() {
-            @SuppressWarnings("synthetic-access")
+        class SqlTask implements Runnable {
             @Override
             public void run() {
                 try {
@@ -410,7 +408,8 @@ final class ResultSetTableModel extends DefaultTableModel {
                 }
                 latch.countDown();
             }
-        });
+        }
+        DaemonThreadFactory.execute(new SqlTask());
         try {
             // waits for a task to stop
             latch.await(3L, TimeUnit.SECONDS);
@@ -418,7 +417,7 @@ final class ResultSetTableModel extends DefaultTableModel {
             throw new RuntimeException(ex);
         }
         if (latch.getCount() != 0) {
-            DaemonThreadFactory.execute(new Runnable() {
+            class SqlTaskErrorHandler implements Runnable {
                 @Override
                 public void run() {
                     try {
@@ -427,15 +426,17 @@ final class ResultSetTableModel extends DefaultTableModel {
                         log.warn(ex);
                     }
                     if (!errors.isEmpty()) {
-                        invokeLater(new Runnable() {
+                        class ErrorNotifier implements Runnable {
                             @Override
                             public void run() {
                                 WindowOutputProcessor.showErrorDialog(null, errors.get(0));
                             }
-                        });
+                        }
+                        invokeLater(new ErrorNotifier());
                     }
                 }
-            });
+            }
+            DaemonThreadFactory.execute(new SqlTaskErrorHandler());
         } else if (!errors.isEmpty()) {
             if (log.isDebugEnabled()) {
                 for (final Exception ex : errors) {
index 5e23d96..fb8cf65 100644 (file)
@@ -6,14 +6,11 @@ import static javax.swing.JOptionPane.WARNING_MESSAGE;
 import static javax.swing.JOptionPane.showMessageDialog;
 import static javax.swing.KeyStroke.getKeyStroke;
 import static net.argius.stew.ui.window.TextSearchPanel.ActionKey.*;
-
 import java.awt.*;
 import java.awt.event.*;
 import java.util.*;
 import java.util.List;
-
 import javax.swing.*;
-
 import net.argius.stew.*;
 import net.argius.stew.ui.window.TextSearch.Matcher;
 
@@ -70,7 +67,7 @@ final class TextSearchPanel extends JPanel implements AnyActionListener {
         add(ignoreCaseCheck);
         // [Setup Focus Policy]
         final FocusTraversalPolicy parentPolicy = frame.getFocusTraversalPolicy();
-        frame.setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {
+        class LayoutFocusTraversalPolicyImpl extends LayoutFocusTraversalPolicy {
             @Override
             public Component getComponentAfter(Container focusCycleRoot, Component component) {
                 if (component == ignoreCaseCheck) {
@@ -85,7 +82,8 @@ final class TextSearchPanel extends JPanel implements AnyActionListener {
                 }
                 return parentPolicy.getComponentBefore(focusCycleRoot, component);
             }
-        });
+        }
+        frame.setFocusTraversalPolicy(new LayoutFocusTraversalPolicyImpl());
         // [Events]
         // text field
         ContextMenu.createForText(text);
index 851919f..5fc94c1 100644 (file)
@@ -29,12 +29,14 @@ import net.argius.stew.ui.*;
  */
 public final class WindowLauncher implements
                                  Launcher,
+                                 FocusListener,
                                  AnyActionListener,
                                  Runnable,
                                  UncaughtExceptionHandler {
 
+    static final ResourceManager res = ResourceManager.getInstance(WindowLauncher.class);
     private static final Logger log = Logger.getLogger(WindowLauncher.class);
-    private static final ResourceManager res = ResourceManager.getInstance(WindowLauncher.class);
+
     private static final List<WindowLauncher> instances = Collections.synchronizedList(new ArrayList<WindowLauncher>());
 
     private final WindowOutputProcessor op;
@@ -105,13 +107,7 @@ public final class WindowLauncher implements
         textSearchMap.put(textArea, textArea);
         for (Entry<JComponent, TextSearch> entry : textSearchMap.entrySet()) {
             final JComponent c = entry.getKey();
-            c.addFocusListener(new FocusAdapter() {
-                @Override
-                public void focusGained(FocusEvent e) {
-                    focused = c;
-                    textSearchPanel.setCurrentTarget(textSearchMap.get(c));
-                }
-            });
+            c.addFocusListener(this);
             textSearchPanel.addTarget(entry.getValue());
         }
         // status bar
@@ -201,6 +197,18 @@ public final class WindowLauncher implements
     }
 
     @Override
+    public void focusGained(FocusEvent e) {
+        JComponent c = (JComponent)e.getSource();
+        focused = c;
+        textSearchPanel.setCurrentTarget(textSearchMap.get(c));
+    }
+
+    @Override
+    public void focusLost(FocusEvent e) {
+        // ignore
+    }
+
+    @Override
     public void anyActionPerformed(AnyActionEvent ev) {
         log.atEnter("anyActionPerformed", ev);
         ev.validate();
@@ -763,35 +771,36 @@ public final class WindowLauncher implements
             final JLabel statusBar = this.statusBar;
             final OutputProcessor opref = env.getOutputProcessor();
             final AnyAction invoker = new AnyAction(this);
-            try {
-                doPreProcess();
-                executorService.execute(new Runnable() {
-                    @Override
-                    public void run() {
-                        Connection conn = env.getCurrentConnection();
-                        long time = System.currentTimeMillis();
-                        if (!Command.invoke(env, cmd)) {
-                            exit();
-                        }
-                        if (infoTree.isEnabled()) {
-                            try {
-                                if (env.getCurrentConnection() != conn) {
-                                    infoTree.clear();
-                                    if (env.getCurrentConnection() != null) {
-                                        infoTree.refreshRoot(env);
-                                    }
+            final class CommandTask implements Runnable {
+                @Override
+                public void run() {
+                    Connection conn = env.getCurrentConnection();
+                    long time = System.currentTimeMillis();
+                    if (!Command.invoke(env, cmd)) {
+                        exit();
+                    }
+                    if (infoTree.isEnabled()) {
+                        try {
+                            if (env.getCurrentConnection() != conn) {
+                                infoTree.clear();
+                                if (env.getCurrentConnection() != null) {
+                                    infoTree.refreshRoot(env);
                                 }
-                            } catch (Throwable th) {
-                                handleError(th);
                             }
-                        }
-                        if (env.getOutputProcessor() == opref) {
-                            time = System.currentTimeMillis() - time;
-                            statusBar.setText(res.get("i.statusbar-message", time / 1000f, cmd));
-                            invoker.doLater("doPostProcess");
+                        } catch (Throwable th) {
+                            handleError(th);
                         }
                     }
-                });
+                    if (env.getOutputProcessor() == opref) {
+                        time = System.currentTimeMillis() - time;
+                        statusBar.setText(res.get("i.statusbar-message", time / 1000f, cmd));
+                        invoker.doLater("doPostProcess");
+                    }
+                }
+            }
+            try {
+                doPreProcess();
+                executorService.execute(new CommandTask());
             } catch (Exception ex) {
                 throw new RuntimeException(ex);
             } finally {
@@ -832,6 +841,8 @@ public final class WindowLauncher implements
     }
 
     private static final class WakeupTimerTask extends TimerTask {
+        WakeupTimerTask() {
+        } // empty
         private final AnyAction aa = new AnyAction(this);
         @Override
         public void run() {
index 0cf54c8..c97b0a6 100644 (file)
@@ -5,17 +5,14 @@ import static net.argius.stew.Bootstrap.getPropertyAsInt;
 import static net.argius.stew.ui.window.AnyActionKey.*;
 import static net.argius.stew.ui.window.Utilities.getImageIcon;
 import static net.argius.stew.ui.window.Utilities.sleep;
-
 import java.awt.*;
 import java.awt.event.*;
 import java.io.*;
 import java.sql.*;
 import java.util.*;
 import java.util.List;
-
 import javax.swing.*;
 import javax.swing.table.*;
-
 import net.argius.stew.*;
 import net.argius.stew.io.*;
 import net.argius.stew.ui.*;
@@ -252,14 +249,10 @@ final class WindowOutputProcessor extends JFrame implements OutputProcessor, Any
         aa.doLater("removeComponent", p);
     }
 
-    private void requestFocusToTextAreaInWindow() {
+    void requestFocusToTextAreaInWindow() {
         textArea.requestFocusInWindow();
     }
 
-    private void moveWindow(int incX, int incY) {
-        setLocation(getX() + incX, getY() + incY);
-    }
-
     final class PostProcessAction extends JPanel {
         int sign = -1;
         byte[] alpha;
@@ -272,7 +265,7 @@ final class WindowOutputProcessor extends JFrame implements OutputProcessor, Any
         }
         void shakeWindow(int range) {
             sign *= -1;
-            moveWindow(range * sign, 0);
+            setLocation(getX() + range * sign, getY() + 0);
         }
         void showComponent(JComponent c) {
             requestFocusToTextAreaInWindow();