using list renderer

This commit is contained in:
Greg DiCristofaro 2020-03-18 11:02:53 -04:00
parent 87b6398cfc
commit 906fc50a08
2 changed files with 4 additions and 72 deletions

View File

@ -24,6 +24,7 @@ import java.awt.Cursor;
import java.awt.HeadlessException;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -31,9 +32,11 @@ import java.util.logging.Level;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
@ -64,7 +67,7 @@ public class EamDbSettingsDialog extends JDialog {
/**
* This class handles displaying and rendering drop down menu for database choices in central repo.
*/
private class DbChoiceRenderer extends TypedBasicComboBoxRenderer<CentralRepoDbChoice> {
private class DbChoiceRenderer extends JLabel implements ListCellRenderer<CentralRepoDbChoice>, Serializable {
private static final long serialVersionUID = 1L;
public Component getListCellRendererComponent(

View File

@ -1,71 +0,0 @@
/*
* Central Repository
*
* Copyright 2015-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.centralrepository.optionspanel;
import java.awt.Dimension;
import java.io.Serializable;
import javax.swing.JLabel;
import javax.swing.ListCellRenderer;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
/**
* This class implements the same behavior as the BasicComboBoxRenderer while
* providing type safety.
* @param <E> The object type that will be used in the combo box.
*/
public abstract class TypedBasicComboBoxRenderer<E> extends JLabel
implements ListCellRenderer<E>, Serializable {
protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
private final static Border SAFE_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1);
/**
* The main constructor for this class.
*/
public TypedBasicComboBoxRenderer() {
super();
setOpaque(true);
setBorder(getNoFocusBorder());
}
private static Border getNoFocusBorder() {
if (System.getSecurityManager() != null) {
return SAFE_NO_FOCUS_BORDER;
} else {
return noFocusBorder;
}
}
@Override
public Dimension getPreferredSize() {
Dimension size;
if ((this.getText() == null) || (this.getText().equals( "" ))) {
setText( " " );
size = super.getPreferredSize();
setText( "" );
}
else {
size = super.getPreferredSize();
}
return size;
}
}