📄 doubleinfo.java
字号:
/**
* DuMP3 version morpheus_0.2.9 - a duplicate/similar file finder in Java<BR>
* Copyright 2005 Alexander Grässer<BR>
* All Rights Reserved, http://dump3.sourceforge.net/<BR>
* <BR>
* This file is part of DuMP3.<BR>
* <BR>
* DuMP3 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 2 of the License, or (at your option) any later version.<BR>
* <BR>
* DuMP3 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.<BR>
* <BR>
* You should have received a copy of the GNU General Public License along with DuMP3; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
* Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.za.grasser.duplicate.gui.info;
import java.util.Map;
import net.za.grasser.duplicate.file.FingerprintFile;
import net.za.grasser.duplicate.gui.StringSorter;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableColumn;
/**
* This class ...
*
* @author <a href="http://sourceforge.net/sendmessage.php?touser=733840">pyropunk at sourceforge dot net</a>
* @version $Revision: 1.6 $
*/
public class DoubleInfo extends Composite {
/**
* <code>tableViewerLeft</code> DoubleInfo -
*/
TableViewer tableViewerLeft;
/**
* <code>tableViewerRight</code> DoubleInfo -
*/
TableViewer tableViewerRight;
/**
* <code>fire</code> DoubleInfo -
*/
boolean fire = true;
/**
* Constructor
*
* @param pArg0
* @param pArg1
*/
public DoubleInfo(final Composite pArg0, final int pArg1) {
super(pArg0, pArg1);
getTableViewerLeft();
getTableViewerRight();
}
/**
* This method will display the fingerprint files additional info in two lists.
*
* @param left - can be null
* @param right - can be null
*/
public void display(final FingerprintFile left, final FingerprintFile right) {
if (left == null) {
tableViewerLeft.setInput(null);
} else {
tableViewerLeft.setInput(left.getInfo());
}
if (right == null) {
tableViewerRight.setInput(null);
} else {
tableViewerRight.setInput(right.getInfo());
}
tableViewerLeft.refresh();
tableViewerRight.refresh();
}
/**
* @return TableViewer - Returns the tableViewerLeft.
*/
public TableViewer getTableViewerLeft() {
if (tableViewerLeft == null) {
tableViewerLeft = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
final FormData tableViewerLeftLData = new FormData();
tableViewerLeftLData.width = 67;
tableViewerLeftLData.height = 63;
tableViewerLeftLData.left = new FormAttachment(0, 1000, 0);
tableViewerLeftLData.right = new FormAttachment(500, 1000, -14);
tableViewerLeftLData.top = new FormAttachment(0, 1000, 0);
tableViewerLeftLData.bottom = new FormAttachment(1000, 1000, 0);
tableViewerLeft.getControl().setLayoutData(tableViewerLeftLData);
tableViewerLeft.getTable().setHeaderVisible(true);
final TableColumn column1 = new TableColumn(tableViewerLeft.getTable(), SWT.LEFT);
column1.setText("Property");
column1.setWidth(100);
final TableColumn column2 = new TableColumn(tableViewerLeft.getTable(), SWT.RIGHT);
column2.setText("Value");
column2.setWidth(120);
tableViewerLeft.setContentProvider(new MapTableContentProvider());
tableViewerLeft.setLabelProvider(new PropertyLabelProvider());
tableViewerLeft.setSorter(new StringSorter());
tableViewerLeft.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(final SelectionChangedEvent evt) {
if (fire) {
tableViewerLeftSelectionChanged(evt);
}
}
});
}
return tableViewerLeft;
}
/**
* This method synchronizes the right selection with the left
*
* @param pEvt
*/
@SuppressWarnings("unchecked")
protected void tableViewerLeftSelectionChanged(final SelectionChangedEvent pEvt) {
final IStructuredSelection selection = (IStructuredSelection)pEvt.getSelection();
if (selection.isEmpty()) {
return;
}
final Map.Entry<String, String> sel = (Map.Entry<String, String>)selection.getFirstElement();
final String sKey = sel.getKey();
final Map<String, String> m = (Map<String, String>)tableViewerRight.getInput();
boolean found = false;
for (final Map.Entry<String, String> lEntry : m.entrySet()) {
if (sKey.equals(lEntry.getKey())) {
found = true;
fire = false;
tableViewerRight.setSelection(new StructuredSelection(lEntry));
fire = true;
break;
}
}
if (!found) {
tableViewerRight.setSelection(null);
}
}
/**
* This method synchronizes the left selection with the right
*
* @param pEvt
*/
@SuppressWarnings("unchecked")
protected void tableViewerRightSelectionChanged(final SelectionChangedEvent pEvt) {
final IStructuredSelection selection = (IStructuredSelection)pEvt.getSelection();
if (selection.isEmpty()) {
return;
}
final Map.Entry<String, String> sel = (Map.Entry<String, String>)selection.getFirstElement();
final String sKey = sel.getKey();
final Map<String, String> m = (Map<String, String>)tableViewerLeft.getInput();
boolean found = false;
for (final Map.Entry<String, String> lEntry : m.entrySet()) {
if (sKey.equals(lEntry.getKey())) {
found = true;
fire = false;
tableViewerLeft.setSelection(new StructuredSelection(lEntry));
fire = true;
break;
}
}
if (!found) {
tableViewerLeft.setSelection(null);
}
}
/**
* @return TableViewer - Returns the tableViewerRight.
*/
public TableViewer getTableViewerRight() {
if (tableViewerRight == null) {
tableViewerRight = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
final FormData tableViewerRightLData = new FormData();
tableViewerRightLData.width = 67;
tableViewerRightLData.height = 63;
tableViewerRightLData.left = new FormAttachment(500, 1000, 14);
tableViewerRightLData.right = new FormAttachment(1000, 1000, 0);
tableViewerRightLData.top = new FormAttachment(0, 1000, 0);
tableViewerRightLData.bottom = new FormAttachment(1000, 1000, 0);
tableViewerRight.getControl().setLayoutData(tableViewerRightLData);
tableViewerRight.getTable().setHeaderVisible(true);
final TableColumn column1 = new TableColumn(tableViewerRight.getTable(), SWT.LEFT);
column1.setText("Property");
column1.setWidth(100);
final TableColumn column2 = new TableColumn(tableViewerRight.getTable(), SWT.RIGHT);
column2.setText("Value");
column2.setWidth(120);
tableViewerRight.setContentProvider(new MapTableContentProvider());
tableViewerRight.setLabelProvider(new PropertyLabelProvider());
tableViewerRight.setSorter(new StringSorter());
tableViewerRight.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(final SelectionChangedEvent evt) {
if (fire) {
tableViewerRightSelectionChanged(evt);
}
}
});
}
return tableViewerRight;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -