< prev index next >
src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java
Print this page
rev 1580 : 6727661: Code improvement and warnings removing from the swing/plaf packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: alexp
Contributed-by: Florian Brunner <fbrunnerlist@gmx.ch>
@@ -1256,11 +1256,11 @@
g.fillRect(rect.x, rect.y, rect.width, rect.height);
}
}
private Rectangle getDropLineRect(JTree.DropLocation loc) {
- Rectangle rect = null;
+ Rectangle rect;
TreePath path = loc.getPath();
int index = loc.getChildIndex();
boolean ltr = leftToRight;
Insets insets = tree.getInsets();
@@ -2131,11 +2131,11 @@
Component focusedComponent = SwingUtilities2.
compositeRequestFocus(editingComponent);
boolean selectAll = true;
- if(event != null && event instanceof MouseEvent) {
+ if(event != null) {
/* Find the component that will get forwarded all the
mouse events until mouseReleased. */
Point componentPoint = SwingUtilities.convertPoint
(tree, new Point(event.getX(), event.getY()),
editingComponent);
@@ -3128,11 +3128,11 @@
} // End of class BasicTreeUI.MouseInputHandler
private static final TransferHandler defaultTransferHandler = new TreeTransferHandler();
- static class TreeTransferHandler extends TransferHandler implements UIResource, Comparator {
+ static class TreeTransferHandler extends TransferHandler implements UIResource, Comparator<TreePath> {
private JTree tree;
/**
* Create a Transferable to use as the source for a data transfer.
@@ -3159,13 +3159,11 @@
TreeModel model = tree.getModel();
TreePath lastPath = null;
TreePath[] displayPaths = getDisplayOrderPaths(paths);
- for (int i = 0; i < displayPaths.length; i++) {
- TreePath path = displayPaths[i];
-
+ for (TreePath path : displayPaths) {
Object node = path.getLastPathComponent();
boolean leaf = model.isLeaf(node);
String label = getDisplayString(path, true, leaf);
plainBuf.append(label + "\n");
@@ -3182,13 +3180,13 @@
}
return null;
}
- public int compare(Object o1, Object o2) {
- int row1 = tree.getRowForPath((TreePath)o1);
- int row2 = tree.getRowForPath((TreePath)o2);
+ public int compare(TreePath o1, TreePath o2) {
+ int row1 = tree.getRowForPath(o1);
+ int row2 = tree.getRowForPath(o2);
return row1 - row2;
}
String getDisplayString(TreePath path, boolean selected, boolean leaf) {
int row = tree.getRowForPath(path);
@@ -3203,19 +3201,19 @@
* HTML requires display order. This method resorts the paths
* to be in the display order.
*/
TreePath[] getDisplayOrderPaths(TreePath[] paths) {
// sort the paths to display order rather than selection order
- ArrayList selOrder = new ArrayList();
- for (int i = 0; i < paths.length; i++) {
- selOrder.add(paths[i]);
+ ArrayList<TreePath> selOrder = new ArrayList<TreePath>();
+ for (TreePath path : paths) {
+ selOrder.add(path);
}
Collections.sort(selOrder, this);
int n = selOrder.size();
TreePath[] displayPaths = new TreePath[n];
for (int i = 0; i < n; i++) {
- displayPaths[i] = (TreePath) selOrder.get(i);
+ displayPaths[i] = selOrder.get(i);
}
return displayPaths;
}
public int getSourceActions(JComponent c) {
@@ -3324,14 +3322,11 @@
*/
private boolean isNavigationKey(KeyEvent event) {
InputMap inputMap = tree.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
KeyStroke key = KeyStroke.getKeyStrokeForEvent(event);
- if (inputMap != null && inputMap.get(key) != null) {
- return true;
- }
- return false;
+ return inputMap != null && inputMap.get(key) != null;
}
//
// PropertyChangeListener
< prev index next >