use of javax.swing.ListSelectionModel in project tetrad by cmu-phil.
the class LoadHpcGraphJsonAction method buildHpcJsonChooserComponent.
private JComponent buildHpcJsonChooserComponent(final TetradDesktop desktop) {
final HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
// Get ComputingAccount from DB
final DefaultListModel<HpcAccount> listModel = new DefaultListModel<HpcAccount>();
for (HpcAccount account : hpcAccountManager.getHpcAccounts()) {
listModel.addElement(account);
}
// JSplitPane
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
// Left pane -> JList (parent pane)
JPanel leftPanel = new JPanel(new BorderLayout());
// Right pane -> ComputingAccountResultList
final JPanel jsonResultListPanel = new JPanel(new BorderLayout());
int minWidth = 800;
int minHeight = 600;
int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
int frameWidth = screenWidth * 3 / 4;
int frameHeight = screenHeight * 3 / 4;
final int paneWidth = minWidth > frameWidth ? minWidth : frameWidth;
final int paneHeight = minHeight > frameHeight ? minHeight : frameHeight;
// JTable
final Vector<String> columnNames = new Vector<>();
columnNames.addElement("Name");
columnNames.addElement("Created");
columnNames.addElement("Last Modified");
columnNames.addElement("Size");
Vector<Vector<String>> rowData = new Vector<>();
final DefaultTableModel tableModel = new LoadHpcGraphJsonTableModel(rowData, columnNames);
final JTable jsonResultTable = new JTable(tableModel);
jsonResultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// Resize table's column width
jsonResultTable.getColumnModel().getColumn(0).setPreferredWidth(paneWidth * 2 / 5);
jsonResultTable.getColumnModel().getColumn(1).setPreferredWidth(paneWidth * 2 / 15);
jsonResultTable.getColumnModel().getColumn(2).setPreferredWidth(paneWidth * 2 / 15);
jsonResultTable.getColumnModel().getColumn(3).setPreferredWidth(paneWidth * 2 / 15);
ListSelectionModel selectionModel = jsonResultTable.getSelectionModel();
selectionModel.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
int row = jsonResultTable.getSelectedRow();
if (row >= 0) {
DefaultTableModel model = (DefaultTableModel) jsonResultTable.getModel();
jsonFileName = (String) model.getValueAt(row, 0);
}
}
});
final JScrollPane scrollTablePane = new JScrollPane(jsonResultTable);
jsonResultListPanel.add(scrollTablePane, BorderLayout.CENTER);
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(jsonResultListPanel);
// Center Panel
final JList<HpcAccount> accountList = new JList<>(listModel);
accountList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
accountList.setLayoutOrientation(JList.VERTICAL);
accountList.setSelectedIndex(-1);
accountList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting())
return;
int selectedIndex = ((JList<?>) e.getSource()).getSelectedIndex();
// Show or remove the json list
if (selectedIndex > -1) {
jsonFileName = null;
hpcAccount = listModel.get(selectedIndex);
TableColumnModel columnModel = jsonResultTable.getColumnModel();
List<Integer> columnWidthList = new ArrayList<>();
for (int i = 0; i < columnModel.getColumnCount(); i++) {
int width = columnModel.getColumn(i).getPreferredWidth();
columnWidthList.add(width);
}
jsonResultTable.clearSelection();
try {
HpcAccountService hpcAccountService = hpcJobManager.getHpcAccountService(hpcAccount);
ResultService resultService = hpcAccountService.getResultService();
Set<ResultFile> results = resultService.listAlgorithmResultFiles(HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
Vector<Vector<String>> jsonFiles = new Vector<>();
for (ResultFile resultFile : results) {
if (resultFile.getName().endsWith(".json")) {
Vector<String> rowData = new Vector<>();
rowData.addElement(resultFile.getName());
rowData.addElement(FilePrint.fileTimestamp(resultFile.getCreationTime().getTime()));
rowData.addElement(FilePrint.fileTimestamp(resultFile.getLastModifiedTime().getTime()));
rowData.addElement(FilePrint.humanReadableSize(resultFile.getFileSize(), false));
jsonFiles.add(rowData);
}
}
tableModel.setDataVector(jsonFiles, columnNames);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// Resize table's column width
for (int i = 0; i < columnModel.getColumnCount(); i++) {
jsonResultTable.getColumnModel().getColumn(i).setPreferredWidth(columnWidthList.get(i).intValue());
}
}
}
});
// Left Panel
JScrollPane accountListScroller = new JScrollPane(accountList);
leftPanel.add(accountListScroller, BorderLayout.CENTER);
splitPane.setDividerLocation(paneWidth / 5);
accountListScroller.setPreferredSize(new Dimension(paneWidth / 5, paneHeight));
jsonResultListPanel.setPreferredSize(new Dimension(paneWidth * 4 / 5, paneHeight));
return splitPane;
}
use of javax.swing.ListSelectionModel in project clusterMaker2 by RBVI.
the class ResultPanelPCA method initComponents.
private void initComponents() {
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setAutoCreateRowSorter(true);
table.setDefaultRenderer(StringBuffer.class, new ResultsPanel.JTextAreaRenderer(defaultRowHeight));
// gives a little vertical room between clusters
table.setIntercellSpacing(new Dimension(0, 4));
// removes an outline that appears when the user clicks on the images
table.setFocusable(false);
// Ask to be notified of selection changes.
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(this);
JScrollPane tableScrollPane = new JScrollPane(table);
// System.out.println("CBP: after creating JScrollPane");
tableScrollPane.getViewport().setBackground(Color.WHITE);
add(tableScrollPane, BorderLayout.CENTER);
// System.out.println("CBP: after adding JScrollPane");
}
use of javax.swing.ListSelectionModel in project GDSC-SMLM by aherbert.
the class ImageJ3DResultsViewer method run.
@Override
public void run(String arg) {
// For testing
// if (true || Utils.isExtraOptions())
// {
// new ImageJ3DResultsViewerDemo().run(arg);
// return;
// }
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
if (ImageJ3DViewerUtils.JAVA_3D_VERSION == null) {
IJ.error(TITLE, "Java 3D is not available");
return;
}
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "There are no fitting results in memory");
return;
}
final ImageJ3DResultsViewerSettings.Builder settings = SettingsManager.readImageJ3DResultsViewerSettings(0).toBuilder();
addToSelection.set(settings.getAddToSelection());
// Get a list of the window titles available. Allow the user to select
// an existing window or a new one.
final String title = TITLE;
final List<Image3DUniverse> univList = new LocalList<>();
final List<String> titleList = new LocalList<>();
titleList.add("New window");
buildWindowList(title, univList, titleList);
final String[] titles = titleList.toArray(new String[0]);
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Select a dataset to display");
ResultsManager.addInput(gd, settings.getInputOption(), InputSource.MEMORY);
// The behaviour is to allow the settings to store if the user prefers a new window
// or to reuse an existing window. If 'new window' then a new window should always
// be selected. Otherwise open in the same window as last time. If there was no last
// window then the settings will carried over from the last ImageJ session.
final String window = (settings.getNewWindow()) ? "" : lastWindow.get();
gd.addChoice("Window", titles, window);
gd.addSlider("Transparancy", 0, 0.9, settings.getTransparency(), new OptionListener<Double>() {
@Override
public boolean collectOptions(Double value) {
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog("Transparancy options", null);
egd.addCheckbox("Support_dynamic_transparency", settings.getSupportDynamicTransparency());
egd.addCheckbox("Enable_dynamic_transparency", settings.getEnableDynamicTransparency());
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
settings.setSupportDynamicTransparency(egd.getNextBoolean());
settings.setEnableDynamicTransparency(egd.getNextBoolean());
return true;
}
});
gd.addChoice("Colour", LutHelper.getLutNames(), settings.getLut());
gd.addChoice("Rendering", RENDERING, settings.getRendering(), new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer value) {
settings.setRendering(value);
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog("Drawing mode options", null);
final int rendering = settings.getRendering();
if (rendering != 0) {
return false;
}
egd.addNumericField("Pixel_size", settings.getPixelSize(), 2, 6, "px");
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
settings.setPixelSize(egd.getNextNumber());
return true;
}
});
gd.addCheckbox("Shaded", settings.getShaded());
gd.addChoice("Size_mode", SIZE_MODE, settings.getSizeMode(), new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer value) {
settings.setSizeMode(value);
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog("Size mode options", null);
final SizeMode mode = SizeMode.forNumber(settings.getSizeMode());
if (mode == SizeMode.FIXED_SIZE) {
egd.addNumericField("Size", settings.getSize(), 2, 6, "nm");
} else {
// Other modes do not require options
return false;
}
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
settings.setSize(egd.getNextNumber());
return true;
}
});
gd.addChoice("Sort_mode", SORT_MODE, settings.getSortMode(), new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer value) {
settings.setSortMode(value);
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog("Sort mode options", null);
final SortMode mode = SortMode.forNumber(settings.getSortMode());
if (mode == SortMode.NONE) {
return false;
}
egd.addMessage(TextUtils.wrap("Note: The sort mode is used to correctly render transparent objects. " + "For non-transparent objects faster rendering is achieved with a reverse " + "sort to put close objects at the front.", 80));
egd.addMessage(TextUtils.wrap(mode.getDetails(), 80));
egd.addMessage("Define the direction of the view");
egd.addNumericField("Direction_x", settings.getSortDirectionX(), 3, 10, "");
egd.addNumericField("Direction_y", settings.getSortDirectionY(), 3, 10, "");
egd.addNumericField("Direction_z", settings.getSortDirectionZ(), 3, 10, "");
if (mode == SortMode.PERSPECTIVE) {
egd.addMessage("Define the view eye position");
egd.addNumericField("Eye_x", settings.getSortEyeX(), 3, 10, "nm");
egd.addNumericField("Eye_y", settings.getSortEyeY(), 3, 10, "nm");
egd.addNumericField("Eye_z", settings.getSortEyeZ(), 3, 10, "nm");
}
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
settings.setSortDirectionX(egd.getNextNumber());
settings.setSortDirectionY(egd.getNextNumber());
settings.setSortDirectionZ(egd.getNextNumber());
if (mode == SortMode.PERSPECTIVE) {
settings.setSortEyeX(egd.getNextNumber());
settings.setSortEyeY(egd.getNextNumber());
settings.setSortEyeZ(egd.getNextNumber());
}
return true;
}
});
gd.addChoice("Transparency_mode", TRANSPARENCY_MODE, settings.getTransparencyMode(), new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer value) {
settings.setTransparencyMode(value);
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog("Transparency mode options", null);
final TransparencyMode mode = TransparencyMode.forNumber(settings.getTransparencyMode());
if (mode == TransparencyMode.NONE) {
return false;
}
egd.addSlider("Min_transparancy", 0, 0.95, settings.getMinTransparency());
egd.addSlider("Max_transparancy", 0, 0.95, settings.getMaxTransparency());
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
settings.setMinTransparency(egd.getNextNumber());
settings.setMaxTransparency(egd.getNextNumber());
return true;
}
});
addColourMode(settings, gd);
gd.addMessage("2D options");
gd.addChoice("Depth_mode", DEPTH_MODE, settings.getDepthMode(), new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer value) {
settings.setDepthMode(value);
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog("Depth mode options", null);
final DepthMode mode = DepthMode.forNumber(settings.getDepthMode());
if (mode == DepthMode.NONE) {
return false;
}
egd.addNumericField("Depth_range", settings.getDepthRange(), 2, 6, "nm");
if (mode == DepthMode.DITHER) {
egd.addNumericField("Dither_seed", settings.getDitherSeed(), 0);
}
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
settings.setDepthRange(egd.getNextNumber());
if (mode == DepthMode.DITHER) {
settings.setDitherSeed((int) egd.getNextNumber());
}
return true;
}
});
addHelp(gd);
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
final String name = ResultsManager.getInputSource(gd);
final int windowChoice = gd.getNextChoiceIndex();
lastWindow.set(titles[windowChoice]);
settings.setInputOption(name);
settings.setTransparency(gd.getNextNumber());
settings.setLut(gd.getNextChoiceIndex());
settings.setRendering(gd.getNextChoiceIndex());
settings.setShaded(gd.getNextBoolean());
settings.setSizeMode(gd.getNextChoiceIndex());
settings.setSortMode(gd.getNextChoiceIndex());
settings.setTransparencyMode(gd.getNextChoiceIndex());
settings.setColourMode(gd.getNextChoiceIndex());
settings.setDepthMode(gd.getNextChoiceIndex());
gd.collectOptions();
if (windowChoice == 0) {
// Store if the user chose a new window when they had a choice of an existing window
if (titleList.size() > 1) {
settings.setNewWindow(true);
// Otherwise they had no choice so leave the preferences as they are.
}
} else {
// This was not a new window
settings.setNewWindow(false);
}
SettingsManager.writeSettings(settings);
MemoryPeakResults results = ResultsManager.loadInputResults(name, false, null, null);
if (MemoryPeakResults.isEmpty(results)) {
IJ.error(TITLE, "No results could be loaded");
return;
}
// Determine if the drawing mode is supported and compute the point size
final Point3f[] sphereSize = createSphereSize(results, settings);
if (sphereSize == null) {
return;
}
// Cache the table settings
resultsTableSettings.set(settings.getResultsTableSettings());
// Create a 3D viewer.
if (windowChoice == 0) {
univ = createImage3DUniverse(title, titleList);
} else {
// Ignore the new window
univ = univList.get(windowChoice - 1);
}
lastWindow.set(univ.getWindow().getTitle());
results = results.copy();
// Commence a digest
final Future<PeakResultsDigest> futureDigest = PeakResultsDigest.digestLater(executorService, results.toArray());
final LocalList<Point3f> points = getPoints(results, settings);
final ResultsMetaData data = new ResultsMetaData(settings.build(), results, points, sphereSize);
sort(data);
final float[] alpha = createAlpha(results, settings, sphereSize);
final float transparency = getTransparency(settings);
final Color3f[] colors = createColour(results, settings);
ContentNode contentNode;
// Build to support true transparency (depends on settings).
// Currently this is not supported for PointArrays as they require colouring
// in the coordinate data.
IJ.showStatus("Creating 3D geometry ...");
if (settings.getSupportDynamicTransparency()) {
final ItemGeometryGroup pointGroup = createItemGroup(settings, sphereSize, points, alpha, transparency, colors);
if (pointGroup == null) {
IJ.showStatus("");
return;
}
if (settings.getEnableDynamicTransparency()) {
final long total = points.size() + getTotalTransparentObjects(univ, name);
activateDynamicTransparency(univ, total, settings.getEnableDynamicTransparency());
} else {
activateDynamicTransparency(univ, 0, settings.getEnableDynamicTransparency());
}
contentNode = new ItemGroupNode(pointGroup);
} else {
final ItemMesh mesh = createItemMesh(settings, points, sphereSize, transparency, alpha);
if (mesh == null) {
IJ.showStatus("");
return;
}
setColour(mesh, colors);
contentNode = new CustomMeshNode(mesh);
}
IJ.showStatus("Creating 3D content ...");
// Use custom content to support adding new switchable nodes
final CustomContent content = new CustomContent(name, !settings.getSupportDynamicTransparency());
final CustomContentInstant contentInstant = (CustomContentInstant) content.getCurrent();
contentInstant.setTransparency((float) settings.getTransparency());
contentInstant.setShaded(settings.getShaded());
contentInstant.showCoordinateSystem(UniverseSettings.showLocalCoordinateSystemsByDefault);
contentInstant.display(contentNode);
createHighlightColour(settings.getHighlightColour());
content.setUserData(data);
// Prevent relative rotation
content.setLocked(true);
// Set up the click selection node
data.createClickSelectionNode(contentInstant);
// Set up the results selection model
data.digest = PeakResultsDigest.waitForDigest(futureDigest, -1);
if (data.digest == null) {
IJ.error(TITLE, "Failed to identify repeat results set");
IJ.showStatus("");
return;
}
Triple<PeakResultTableModel, ListSelectionModel, PeakResultTableModelFrame> triplet = resultsTables.get(data.digest);
if (triplet == null) {
triplet = Triple.of(new PeakResultTableModel(results, false, // Note the settings do not matter until the table is set live
resultsTableSettings.get()), new DefaultListSelectionModel(), null);
triplet.getLeft().setCheckDuplicates(true);
resultsTables.put(data.digest, triplet);
}
// Preserve orientation on the content
final boolean auto = univ.getAutoAdjustView();
final Content oldContent = univ.getContent(name);
if (oldContent == null) {
univ.setAutoAdjustView(true);
} else {
univ.removeContent(name);
univ.setAutoAdjustView(false);
}
IJ.showStatus("Drawing 3D content ... ");
final StopWatch sw = StopWatch.createStarted();
final Future<Content> future = univ.addContentLater(content);
Content added = null;
for (; ; ) {
try {
// Wait for 1 second
for (int i = 0; i < 20; i++) {
Thread.sleep(50);
if (future.isDone()) {
// Only get the result when finished, so avoiding a blocking wait
added = future.get();
break;
}
}
if (added != null) {
break;
}
final long seconds = sw.getTime(TimeUnit.SECONDS);
if (seconds % 20 == 0) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE, null);
egd.addMessage("Current wait time is " + sw.toString());
egd.setOKLabel("Wait");
egd.showDialog();
if (egd.wasCanceled()) {
future.cancel(true);
break;
}
}
IJ.showStatus("Drawing 3D content ... " + seconds);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
} catch (final ExecutionException ex) {
break;
}
}
univ.setAutoAdjustView(auto);
// Initialise the selection model
if (added != null) {
data.addSelectionModel(triplet);
}
IJ.showStatus("");
}
use of javax.swing.ListSelectionModel in project GDSC-SMLM by aherbert.
the class PeakResultTableModelFrameDemo method main.
/**
* Launch the application.
*
* @param args the arguments
*/
public static void main(String[] args) {
final SplitMix r = SplitMix.new64(System.currentTimeMillis());
final int n = 20;
final ListSelectionModel selectionModel = new DefaultListSelectionModel();
EventQueue.invokeLater((Runnable) () -> {
try {
final PeakResultStoreList store = new ArrayPeakResultStore(10);
for (int i = n; i-- > 0; ) {
store.add(new PeakResult(r.nextInt(), r.nextInt(), r.nextInt(), r.nextFloat(), r.nextDouble(), r.nextFloat(), r.nextFloat(), PeakResult.createParams(r.nextFloat(), r.nextFloat(), r.nextFloat(), r.nextFloat(), r.nextFloat()), null));
}
final CalibrationWriter cw = new CalibrationWriter();
cw.setNmPerPixel(100);
cw.setCountPerPhoton(10);
cw.setDistanceUnit(DistanceUnit.PIXEL);
cw.setIntensityUnit(IntensityUnit.COUNT);
final ResultsTableSettings.Builder tableSettings = ResultsTableSettings.newBuilder();
tableSettings.setDistanceUnit(DistanceUnit.NM);
tableSettings.setIntensityUnit(IntensityUnit.PHOTON);
tableSettings.setShowFittingData(true);
tableSettings.setShowNoiseData(true);
tableSettings.setShowPrecision(true);
tableSettings.setRoundingPrecision(4);
final PeakResultTableModel model = new PeakResultTableModel(store, cw.getCalibration(), null, tableSettings.build());
final PeakResultTableModelFrame d = new PeakResultTableModelFrame(model, null, selectionModel);
d.setTitle("D");
d.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
d.setVisible(true);
// Selecting in one list activates the other list
final PeakResultTableModelFrame d2 = new PeakResultTableModelFrame(model, null, selectionModel);
d2.setTitle("D2");
// Since we have the same selection model we need the same row sorter,
// otherwise the selection is scrambled by sorting.
// The alternative would be to get the source for the selection event (the table)
// and get the row sorter to do the mapping.
// However this breaks deletion of data as the row sorter double processes the deletion.
// Basically only one table can use the same selection model when sorting is desired.
// d2.table.setRowSorter(d.table.getRowSorter())
d2.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
d2.setVisible(true);
} catch (final Exception ex) {
ex.printStackTrace();
}
});
}
use of javax.swing.ListSelectionModel in project sldeditor by robward-scisys.
the class InlineFeaturePanel method createUI.
/**
* Creates the UI.
*
* @param noOfRows the no of rows
*/
private void createUI(int noOfRows) {
setLayout(new BorderLayout());
int xPos = 0;
int width = BasePanel.FIELD_PANEL_WIDTH - xPos - 20;
int height = BasePanel.WIDGET_HEIGHT * (noOfRows - 1);
this.setBounds(0, 0, width, height);
// CRS dropdown
JPanel topPanel = new JPanel();
topPanel.add(createCRSList("CRS", xPos, topPanel));
add(topPanel, BorderLayout.NORTH);
// Feature table panel
featureTable = new JTable(model);
featureTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
featureTable.setColumnSelectionAllowed(true);
featureTable.setAutoscrolls(true);
featureTable.getTableHeader().setReorderingAllowed(false);
featureTable.setBounds(xPos, 0, BasePanel.FIELD_PANEL_WIDTH, getRowY(noOfRows - 2));
model.setTable(featureTable, crsComboBox);
ListSelectionModel selectionModel = featureTable.getSelectionModel();
selectionModel.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
removeFeatureButton.setEnabled(true);
}
}
});
JScrollPane scrollPanel = new JScrollPane(featureTable);
scrollPanel.setBounds(xPos, 0, BasePanel.FIELD_PANEL_WIDTH, getRowY(noOfRows - 2));
JPanel tablePanel = new JPanel();
tablePanel.add(scrollPanel);
add(tablePanel, BorderLayout.CENTER);
// Buttons
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new FlowLayout());
// Feature panel
JPanel addFeaturePanel = new JPanel();
addFeaturePanel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(FieldConfigBase.class, "InlineFeature.features")));
JButton addButton = new JButton(Localisation.getString(FieldConfigBase.class, "InlineFeature.addfeature"));
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addButtonPressed();
}
});
addFeaturePanel.add(addButton);
removeFeatureButton = new JButton(Localisation.getString(FieldConfigBase.class, "InlineFeature.removefeature"));
removeFeatureButton.setEnabled(false);
removeFeatureButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
removeFeatureButtonPressed();
}
});
addFeaturePanel.add(removeFeatureButton);
bottomPanel.add(addFeaturePanel);
// Attribute panel
JPanel attributePanel = new JPanel();
attributePanel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(FieldConfigBase.class, "InlineFeature.attributes")));
JButton addColumnButton = new JButton(Localisation.getString(FieldConfigBase.class, "InlineFeature.addattribute"));
addColumnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
model.addNewColumn();
}
});
attributePanel.add(addColumnButton);
JButton removeColumnButton = new JButton(Localisation.getString(FieldConfigBase.class, "InlineFeature.removeattribute"));
ArrowIcon arrow = new ArrowIcon(SwingConstants.SOUTH, true);
removeColumnButton.setIcon(arrow);
removeColumnButton.setHorizontalTextPosition(AbstractButton.LEFT);
removeColumnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
removeColumnButton(removeColumnButton, e);
}
});
attributePanel.add(removeColumnButton);
bottomPanel.add(attributePanel);
add(bottomPanel, BorderLayout.SOUTH);
//
// Set up the column header editing
//
columnHeader = featureTable.getTableHeader();
columnHeader.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
if (event.getClickCount() == 2) {
int columnIndex = columnHeader.columnAtPoint(event.getPoint());
editColumnAt(columnIndex);
}
}
});
columnTextField = new JTextField();
columnTextField.setBorder(null);
columnTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
renameColumn();
}
});
renamePopup = new JPopupMenu();
renamePopup.setBorder(new MatteBorder(0, 1, 1, 1, Color.DARK_GRAY));
renamePopup.add(columnTextField);
}
Aggregations