下面列出了javax.swing.JList#setVisibleRowCount ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initComponents() {
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
listModel = new DefaultListModel();
list = new JList(listModel);
list.getAccessibleContext().setAccessibleName(Bundle.ProfilingPointsDisplayer_ListAccessName());
list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
list.setVisibleRowCount(6);
list.setCellRenderer(org.netbeans.modules.profiler.ppoints.Utils.getPresenterListRenderer());
JScrollPane listScroll = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
listScroll.setPreferredSize(new Dimension(405, listScroll.getPreferredSize().height));
add(listScroll, BorderLayout.CENTER);
}
public void init() {
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
tableIcon = FormUtils.getIcon(tableIcon, DEFAULT_TABLE_ICON);
for (PanelHolder p : panels)
p.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
list = new JList(new ListListModel(panels));
list.setBorder(BorderFactory.createEmptyBorder(5, 5 , 5, 5));
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setVisibleRowCount(-1);
list.addListSelectionListener(this);
list.setCellRenderer(renderer);
list.setSelectedIndex(0);
if (cellHeight != 0)
list.setFixedCellHeight(cellHeight);
JScrollPane scroll = new JScrollPane(list);
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scroll, editorPanel);
split.setResizeWeight(0);
split.setDividerLocation(150);
add(split);
}
public void create(PropertiesPanel panel) {
JPanel buttons = new JPanel();
JPanel p = new JPanel();
JList l = new JList(model);
l.setVisibleRowCount(visibleRowCount);
JScrollPane sp = new JScrollPane(l);
buttons.setLayout(new BorderLayout());
buttons.add(BorderLayout.NORTH, access.newAddButton(l));
buttons.add(BorderLayout.SOUTH, access.newRemoveButton(l));
p.setLayout(new BorderLayout());
p.add(BorderLayout.CENTER, sp);
p.add(BorderLayout.EAST, buttons);
p.setBorder(new TitledBorder(label));
panel.valuecmps.put(key, l);
panel.container.add(p, Awt.constraints(true, GridBagConstraints.HORIZONTAL));
}
public void init() {
tableIcon = FormUtils.getIcon(tableIcon, DEFAULT_TABLE_ICON);
for (TableEditor<?> editor : editors)
editor.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));
list = new JList(editors);
list.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setVisibleRowCount(-1);
JScrollPane scroll = new JScrollPane(list);
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scroll, editorPanel);
getContentPane().add(split);
list.addListSelectionListener(this);
list.setCellRenderer(new ListCellRenderer());
list.setSelectedIndex(0);
setSize(800, 600);
}
@Override
public void actionPerformed (ActionEvent e)
{
// Create a dialog with a JList of possible additions
// That is all languages, minus those already desired
List<String> additionals = new ArrayList<String>(
Arrays.asList(OcrCompanion.ALL_LANGUAGES));
additionals.removeAll(desired);
JList<String> list = new JList(
additionals.toArray(new String[additionals.size()]));
JScrollPane scrollPane = new JScrollPane(list);
list.setLayoutOrientation(JList.VERTICAL_WRAP);
list.setVisibleRowCount(10);
// Let the user select additional languages
int opt = JOptionPane.showConfirmDialog(
Installer.getFrame(),
scrollPane,
"OCR languages selection",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
List<String> toAdd = list.getSelectedValuesList();
logger.debug("Opt: {} Selection: {}", opt, toAdd);
// Save the selection, only if OK
if (opt == JOptionPane.OK_OPTION) {
logger.info("Additional languages: {}", toAdd);
desired.addAll(toAdd);
// This may impact the "installed" status of the companion
companion.checkInstalled();
banner.defineLayout(null);
companion.updateView();
}
}
protected void initPanel()
{
setLayout(new BorderLayout());
final JList dataSourceList = new JList(dialogModel.getConnections());
dataSourceList.setCellRenderer(new DataSourceDefinitionListCellRenderer());
dataSourceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
dataSourceList.addListSelectionListener(new DataSourceDefinitionListSelectionListener(dataSourceList));
dataSourceList.setVisibleRowCount(10);
final SelectionConnectionUpdateHandler theSelectedConnectionAction = new SelectionConnectionUpdateHandler(
dataSourceList);
dialogModel.addPropertyChangeListener(theSelectedConnectionAction);
final EditDataSourceAction editDataSourceAction = new EditDataSourceAction(dataSourceList);
dialogModel.addPropertyChangeListener(editDataSourceAction);
final RemoveDataSourceAction removeDataSourceAction = new RemoveDataSourceAction(dataSourceList);
dialogModel.addPropertyChangeListener(removeDataSourceAction);
final JPanel connectionButtonPanel = new JPanel();
connectionButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
if (isSecurityConfigurationAvailable())
{
connectionButtonPanel.add(new JButton(createEditSecurityAction()));
connectionButtonPanel.add(Box.createHorizontalStrut(40));
}
connectionButtonPanel.add(new BorderlessButton(editDataSourceAction));
connectionButtonPanel.add(new BorderlessButton(new AddDataSourceAction(dataSourceList)));
connectionButtonPanel.add(new BorderlessButton(removeDataSourceAction));
final JPanel connectionButtonPanelWrapper = new JPanel(new BorderLayout());
connectionButtonPanelWrapper.add(new JLabel(bundleSupport.getString("ConnectionPanel.Connections")), BorderLayout.CENTER);
connectionButtonPanelWrapper.add(connectionButtonPanel, BorderLayout.EAST);
add(BorderLayout.NORTH, connectionButtonPanelWrapper);
add(BorderLayout.CENTER, new JScrollPane(dataSourceList));
}
private void initUI() {
categoriesModel = new CategoriesListModel();
categoriesSelection = new CategoriesSelectionModel();
scrollIncrement = new JCheckBox("XXX").getPreferredSize().height; // NOI18N
JList<ProfilerOptionsPanel> categoriesList = new JList<ProfilerOptionsPanel>(categoriesModel) {
public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize();
dim.width = Math.max(dim.width + 20, 140);
return dim;
}
};
categoriesList.setVisibleRowCount(0);
categoriesList.setSelectionModel(categoriesSelection);
categoriesList.setCellRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
String panelName = " " + ((ProfilerOptionsPanel)value).getDisplayName() + " "; // NOI18N
return super.getListCellRendererComponent(list, panelName, index, isSelected, cellHasFocus);
}
});
JScrollPane categoriesScroll = new JScrollPane(categoriesList);
JLabel categoriesLabel = new JLabel();
categoriesLabel.setHorizontalAlignment(JLabel.LEADING);
Mnemonics.setLocalizedText(categoriesLabel, Bundle.ProfilerOptionsContainer_Categories());
categoriesLabel.setLabelFor(categoriesList);
int labelOffset = 6;
JPanel categoriesPanel = new JPanel(new BorderLayout(0, labelOffset));
categoriesPanel.add(categoriesLabel, BorderLayout.NORTH);
categoriesPanel.add(categoriesScroll, BorderLayout.CENTER);
content = new JPanel(new BorderLayout());
content.setBorder(BorderFactory.createEmptyBorder(categoriesLabel.getPreferredSize().height + labelOffset, 11, 0, 0));
content.setMinimumSize(new Dimension(0, 0));
content.setPreferredSize(new Dimension(0, 0));
setLayout(new BorderLayout());
add(categoriesPanel, BorderLayout.WEST);
add(content, BorderLayout.CENTER);
}
void setColumns(String[] names, String[] selected) {
displayedNames = new String[names.length];
realNames.clear();
for (int i=0; i<names.length; i++) {
String s = TeXParser.removeSubscripting(names[i]);
// add white space for better look
displayedNames[i] = " "+s+" "; //$NON-NLS-1$ //$NON-NLS-2$
realNames.put(displayedNames[i], names[i]);
if (selected!=null) {
for (int j=0; j<selected.length; j++) {
if (selected[j]!=null && selected[j].equals(names[i])) {
selected[j] = displayedNames[i];
}
}
}
}
prevPatterns.clear();
for(String name : names) {
prevPatterns.put(name, getFormatPattern(name));
}
// create column list and add to scroller
columnList = new JList(displayedNames);
columnList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
columnList.setVisibleRowCount(-1);
columnList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
showNumberFormatAndSample(columnList.getSelectedIndices());
}
});
columnScroller.setViewportView(columnList);
pack();
int[] indices = null;
if (selected!=null) {
// select requested names
indices = new int[selected.length];
for (int j=0; j<indices.length; j++) {
inner:
for (int i = 0; i< displayedNames.length; i++) {
if (displayedNames[i].equals(selected[j])) {
indices[j] = i;
break inner;
}
}
}
columnList.setSelectedIndices(indices);
}
else
showNumberFormatAndSample(indices);
}
/** This method creates the GUI components and paces them into the layout*/
protected void initGuiComponents(){
this.getContentPane().setLayout(new BoxLayout(this.getContentPane(),
BoxLayout.Y_AXIS));
// Create source label
sourceLabel = new JLabel("Source");
sourceLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
// Create source list
sourceList = new JList(sourceListModel);
sourceList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
sourceList.setVisibleRowCount(10);
sourceList.setAlignmentX(Component.LEFT_ALIGNMENT);
// Create target label
targetLabel = new JLabel("Target");
targetLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
// Create the target list
targetList = new JList(targetListModel);
targetList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
targetList.setVisibleRowCount(10);
targetList.setAlignmentX(Component.LEFT_ALIGNMENT);
targetList.setPreferredSize(sourceList.getPreferredSize());
// Create Add >> button
addButton = new JButton(">>>");
// Create Remove << button
removeButton = new JButton("<<<");
// Create ok button
okButton = new JButton("Ok");
// Create cancel button
cancelButton = new JButton("Cancel");
///////////////////////////////////////
// Arange components
//////////////////////////////////////
// Create the main box
Box componentsBox = Box.createVerticalBox();
componentsBox.add(Box.createRigidArea(new Dimension(0,5)));
Box firstLevelBox = Box.createHorizontalBox();
firstLevelBox.add(Box.createRigidArea(new Dimension(10,0)));
// Add the Source list
Box currentBox = Box.createVerticalBox();
currentBox.add(sourceLabel);
currentBox.add(new JScrollPane(sourceList));
// Add the current box to the firstLevelBox
firstLevelBox.add(currentBox);
firstLevelBox.add(Box.createRigidArea(new Dimension(10,0)));
// Add the add and remove buttons
currentBox = Box.createVerticalBox();
currentBox.add(addButton);
currentBox.add(Box.createRigidArea(new Dimension(0,10)));
currentBox.add(removeButton);
// Add the remove buttons to the firstLevelBox
firstLevelBox.add(currentBox);
firstLevelBox.add(Box.createRigidArea(new Dimension(10,0)));
// Add the target list
currentBox = Box.createVerticalBox();
currentBox.add(targetLabel);
currentBox.add(new JScrollPane(targetList));
// Add target list to the firstLevelBox
firstLevelBox.add(currentBox);
firstLevelBox.add(Box.createRigidArea(new Dimension(20,0)));
// Add ok and cancel buttons to the currentBox
currentBox = Box.createHorizontalBox();
currentBox.add(Box.createHorizontalGlue());
currentBox.add(okButton);
currentBox.add(Box.createRigidArea(new Dimension(25,0)));
currentBox.add(cancelButton);
currentBox.add(Box.createHorizontalGlue());
// Add all components to the components box
componentsBox.add(firstLevelBox);
componentsBox.add(Box.createRigidArea(new Dimension(0,10)));
componentsBox.add(currentBox);
componentsBox.add(Box.createRigidArea(new Dimension(0,5)));
// Add the components box to the dialog
this.getContentPane().add(componentsBox);
this.pack();
}
private JPanel analysisChain() {
JPanel panel = new JPanel(new GridBagLayout());
panel.setOpaque(false);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(5, 5, 5, 5);
c.gridx = 0;
c.gridy = 0;
c.weightx = 0.1;
c.weighty = 0.5;
panel.add(new JLabel(MessageUtils.getLocalizedMessage("analysis.dialog.chain.label.charfilters")), c);
String[] charFilters = analyzer.getCharFilterFactories().stream().map(f -> CharFilterFactory.findSPIName(f.getClass())).toArray(String[]::new);
JList<String> charFilterList = new JList<>(charFilters);
charFilterList.setVisibleRowCount(charFilters.length == 0 ? 1 : Math.min(charFilters.length, 5));
c.gridx = 1;
c.gridy = 0;
c.weightx = 0.5;
c.weighty = 0.5;
panel.add(new JScrollPane(charFilterList), c);
c.gridx = 0;
c.gridy = 1;
c.weightx = 0.1;
c.weighty = 0.1;
panel.add(new JLabel(MessageUtils.getLocalizedMessage("analysis.dialog.chain.label.tokenizer")), c);
String tokenizer = TokenizerFactory.findSPIName(analyzer.getTokenizerFactory().getClass());
JTextField tokenizerTF = new JTextField(tokenizer);
tokenizerTF.setColumns(30);
tokenizerTF.setEditable(false);
tokenizerTF.setPreferredSize(new Dimension(300, 25));
tokenizerTF.setBorder(BorderFactory.createLineBorder(Color.gray));
c.gridx = 1;
c.gridy = 1;
c.weightx = 0.5;
c.weighty = 0.1;
panel.add(tokenizerTF, c);
c.gridx = 0;
c.gridy = 2;
c.weightx = 0.1;
c.weighty = 0.5;
panel.add(new JLabel(MessageUtils.getLocalizedMessage("analysis.dialog.chain.label.tokenfilters")), c);
String[] tokenFilters = analyzer.getTokenFilterFactories().stream().map(f -> TokenFilterFactory.findSPIName(f.getClass())).toArray(String[]::new);
JList<String> tokenFilterList = new JList<>(tokenFilters);
tokenFilterList.setVisibleRowCount(tokenFilters.length == 0 ? 1 : Math.min(tokenFilters.length, 5));
tokenFilterList.setMinimumSize(new Dimension(300, 25));
c.gridx = 1;
c.gridy = 2;
c.weightx = 0.5;
c.weighty = 0.5;
panel.add(new JScrollPane(tokenFilterList), c);
return panel;
}
/**
* ListDemo Constructor.
*
* @param swingset the swingset
*/
public ListDemo(SwingSet2 swingset) {
super(swingset, "ListDemo"
, "toolbar/JList.gif");
loadImages();
//modified by jb2011
JLabel description = N9ComponentFactory.createLabel_style2(getString("ListDemo.description"));
getDemoPanel().add(description, BorderLayout.NORTH);
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.X_AXIS));
centerPanel.add(Box.createRigidArea(HGAP10));
getDemoPanel().add(centerPanel, BorderLayout.CENTER);
JPanel listPanel = new JPanel();
listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.Y_AXIS));
listPanel.add(Box.createRigidArea(VGAP10));
centerPanel.add(listPanel);
centerPanel.add(Box.createRigidArea(HGAP30));
// Create the list
list = new JList();
//* 由jb2011注释掉,以便测试Ui里的通用renderer
// list.setCellRenderer(new CompanyLogoListCellRenderer());
listModel = new GeneratedListModel(this);
list.setModel(listModel);
// Set the preferred row count. This affects the preferredSize
// of the JList when it's in a scrollpane.
list.setVisibleRowCount(22);
// Add list to a scrollpane
JScrollPane scrollPane = new JScrollPane(list);
listPanel.add(scrollPane);
listPanel.add(Box.createRigidArea(VGAP10));
// Add the control panel (holds the prefix/suffix list and prefix/suffix checkboxes)
centerPanel.add(createControlPanel());
// create prefixes and suffixes
addPrefix("Tera", true);
addPrefix("Micro", false);
addPrefix("Southern", false);
addPrefix("Net", true);
addPrefix("YoYo", true);
addPrefix("Northern", false);
addPrefix("Tele", false);
addPrefix("Eastern", false);
addPrefix("Neo", false);
addPrefix("Digi", false);
addPrefix("National", false);
addPrefix("Compu", true);
addPrefix("Meta", true);
addPrefix("Info", false);
addPrefix("Western", false);
addPrefix("Data", false);
addPrefix("Atlantic", false);
addPrefix("Advanced", false);
addPrefix("Euro", false);
addPrefix("Pacific", false);
addPrefix("Mobile", false);
addPrefix("In", false);
addPrefix("Computa", false);
addPrefix("Digital", false);
addPrefix("Analog", false);
addSuffix("Tech", true);
addSuffix("Soft", true);
addSuffix("Telecom", true);
addSuffix("Solutions", false);
addSuffix("Works", true);
addSuffix("Dyne", false);
addSuffix("Services", false);
addSuffix("Vers", false);
addSuffix("Devices", false);
addSuffix("Software", false);
addSuffix("Serv", false);
addSuffix("Systems", true);
addSuffix("Dynamics", true);
addSuffix("Net", false);
addSuffix("Sys", false);
addSuffix("Computing", false);
addSuffix("Scape", false);
addSuffix("Com", false);
addSuffix("Ware", false);
addSuffix("Widgets", false);
addSuffix("Media", false);
addSuffix("Computer", false);
addSuffix("Hardware", false);
addSuffix("Gizmos", false);
addSuffix("Concepts", false);
}
private JComponent buildList() {
Application[] elements = new Application[] {
new Application("Address Book", "x-office-address-book.png"),
new Application("Calendar", "x-office-calendar.png"),
new Application("Presentation", "x-office-presentation.png"),
new Application("Spreadsheet", "x-office-spreadsheet.png"),
};
list = new JList(elements);
list.setCellRenderer(new ApplicationListCellRenderer());
list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
list.setVisibleRowCount(2);
list.setBorder(BorderFactory.createEtchedBorder());
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int index = list.getSelectedIndex();
Rectangle bounds = list.getCellBounds(index, index);
Point location = new Point(bounds.x, bounds.y);
location = SwingUtilities.convertPoint(list, location, glassPane);
location.y -= 13;
bounds.setLocation(location);
glassPane.showSpring(bounds,
((Application) list.getSelectedValue()).icon.getImage());
}
}
});
JPanel panel = new JPanel(new GridBagLayout());
panel.add(new JLabel("Launcher"),
new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
GridBagConstraints.LINE_START, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
panel.add(list, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
panel.add(new JLabel("Double-click an icon to launch the program"),
new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0,
GridBagConstraints.LINE_START, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
return panel;
}
private void init(Font font) {
setLayout(new GridBagLayout());
Insets ins = new Insets(2, 2, 2, 2);
fontList = new JList(FONTS);
fontList.setVisibleRowCount(10);
fontList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
add(new JScrollPane(fontList), new GridBagConstraints(0, 0, 1, 1, 2, 2,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
ins, 0, 0));
sizeList = new JList(SIZES);
((JLabel)sizeList.getCellRenderer()).setHorizontalAlignment(JLabel.RIGHT);
sizeList.setVisibleRowCount(10);
sizeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
add(new JScrollPane(sizeList), new GridBagConstraints(1, 0, 1, 1, 1, 2,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
ins, 0, 0));
boldCheckBox = new JCheckBox("Bold");
add(boldCheckBox, new GridBagConstraints(0, 1, 2, 1, 1, 0,
GridBagConstraints.WEST, GridBagConstraints.NONE,
ins, 0, 0));
italicCheckBox = new JCheckBox("Italic");
add(italicCheckBox, new GridBagConstraints(0, 2, 2, 1, 1, 0,
GridBagConstraints.WEST, GridBagConstraints.NONE,
ins, 0, 0));
previewLabel = new JLabel("");
previewLabel.setHorizontalAlignment(JLabel.CENTER);
previewLabel.setVerticalAlignment(JLabel.CENTER);
add(new JScrollPane(previewLabel), new GridBagConstraints(0, 3, 2, 1, 1, 1,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
ins, 0, 0));
setFont(font == null ? previewLabel.getFont() : font);
fontList.addListSelectionListener(selectionUpdater);
sizeList.addListSelectionListener(selectionUpdater);
boldCheckBox.addChangeListener(selectionUpdater);
italicCheckBox.addChangeListener(selectionUpdater);
}
private DialogData requestDialogData(final Product product) {
boolean ortorectifiable = isOrtorectifiable(product);
String[] demNames = DEMFactory.getDEMNameList();
// sort the list
final List<String> sortedDEMNames = Arrays.asList(demNames);
java.util.Collections.sort(sortedDEMNames);
demNames = sortedDEMNames.toArray(new String[sortedDEMNames.size()]);
final DialogData dialogData = new DialogData("SRTM 3sec (Auto Download)", ResamplingFactory.BILINEAR_INTERPOLATION_NAME, ortorectifiable);
PropertySet propertySet = PropertyContainer.createObjectBacked(dialogData);
configureDemNameProperty(propertySet, "demName", demNames, "SRTM 3sec (Auto Download)");
configureDemNameProperty(propertySet, "resamplingMethod", ResamplingFactory.resamplingNames,
ResamplingFactory.BILINEAR_INTERPOLATION_NAME);
configureBandNameProperty(propertySet, "elevationBandName", product);
configureBandNameProperty(propertySet, "latitudeBandName", product);
configureBandNameProperty(propertySet, "longitudeBandName", product);
final BindingContext ctx = new BindingContext(propertySet);
JList demList = new JList();
demList.setVisibleRowCount(10);
ctx.bind("demName", new SingleSelectionListComponentAdapter(demList));
JTextField elevationBandNameField = new JTextField();
elevationBandNameField.setColumns(10);
ctx.bind("elevationBandName", elevationBandNameField);
JCheckBox outputDemCorrectedBandsChecker = new JCheckBox("Output DEM-corrected bands");
ctx.bind("outputDemCorrectedBands", outputDemCorrectedBandsChecker);
JLabel latitudeBandNameLabel = new JLabel("Latitude band name:");
JTextField latitudeBandNameField = new JTextField();
latitudeBandNameField.setEnabled(ortorectifiable);
ctx.bind("latitudeBandName", latitudeBandNameField).addComponent(latitudeBandNameLabel);
ctx.bindEnabledState("latitudeBandName", true, "outputGeoCodingBands", true);
JLabel longitudeBandNameLabel = new JLabel("Longitude band name:");
JTextField longitudeBandNameField = new JTextField();
longitudeBandNameField.setEnabled(ortorectifiable);
ctx.bind("longitudeBandName", longitudeBandNameField).addComponent(longitudeBandNameLabel);
ctx.bindEnabledState("longitudeBandName", true, "outputGeoCodingBands", true);
TableLayout tableLayout = new TableLayout(2);
tableLayout.setTableAnchor(TableLayout.Anchor.WEST);
tableLayout.setTableFill(TableLayout.Fill.HORIZONTAL);
tableLayout.setTablePadding(4, 4);
tableLayout.setCellColspan(0, 0, 2);
tableLayout.setCellColspan(1, 0, 2);
/* tableLayout.setCellColspan(3, 0, 2);
tableLayout.setCellWeightX(0, 0, 1.0);
tableLayout.setRowWeightX(1, 1.0);
tableLayout.setCellWeightX(2, 1, 1.0);
tableLayout.setCellWeightX(4, 1, 1.0);
tableLayout.setCellWeightX(5, 1, 1.0);
tableLayout.setCellPadding(4, 0, new Insets(0, 24, 0, 4));
tableLayout.setCellPadding(5, 0, new Insets(0, 24, 0, 4)); */
JPanel parameterPanel = new JPanel(tableLayout);
/*row 0*/
parameterPanel.add(new JLabel("Digital elevation model (DEM):"));
parameterPanel.add(new JScrollPane(demList));
/*row 1*/
parameterPanel.add(new JLabel("Resampling method:"));
final JComboBox resamplingCombo = new JComboBox(DEMFactory.getDEMResamplingMethods());
parameterPanel.add(resamplingCombo);
ctx.bind("resamplingMethod", resamplingCombo);
parameterPanel.add(new JLabel("Elevation band name:"));
parameterPanel.add(elevationBandNameField);
if (ortorectifiable) {
/*row 2*/
parameterPanel.add(outputDemCorrectedBandsChecker);
/*row 3*/
parameterPanel.add(latitudeBandNameLabel);
parameterPanel.add(latitudeBandNameField);
/*row 4*/
parameterPanel.add(longitudeBandNameLabel);
parameterPanel.add(longitudeBandNameField);
outputDemCorrectedBandsChecker.setSelected(ortorectifiable);
outputDemCorrectedBandsChecker.setEnabled(ortorectifiable);
}
final ModalDialog dialog = new ModalDialog(SnapApp.getDefault().getMainFrame(), DIALOG_TITLE, ModalDialog.ID_OK_CANCEL, HELP_ID);
dialog.setContent(parameterPanel);
if (dialog.show() == ModalDialog.ID_OK) {
return dialogData;
}
return null;
}
private void setupList(@SuppressWarnings("rawtypes") JList list) {
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
list.setLayoutOrientation(JList.VERTICAL);
list.setVisibleRowCount(-1);
}
/**
* Constructs a <code>JList</code> with an empty model.
*/
public ListParameterComponent( final ListParameter listParameter, final ParameterUpdateContext updateContext,
final ParameterContext parameterContext ) {
this.listParameter = listParameter;
this.updateContext = updateContext;
this.parameterContext = parameterContext;
this.selectionCache = new ArrayList<Integer>();
list = new JList();
list.setCellRenderer( new FixedTheJDKListCellRenderer() );
if ( listParameter.isAllowMultiSelection() ) {
list.addListSelectionListener( new MultiValueListParameterHandler( listParameter.getName() ) );
list.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
} else {
list.addListSelectionListener( new SingleValueListParameterHandler( listParameter.getName() ) );
list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
}
final String layout =
listParameter.getParameterAttribute( ParameterAttributeNames.Core.NAMESPACE,
ParameterAttributeNames.Core.LAYOUT, parameterContext );
if ( "horizontal".equals( layout ) ) { //$NON-NLS-1$
list.setLayoutOrientation( JList.HORIZONTAL_WRAP );
list.setVisibleRowCount( 1 );
list.setPreferredSize( new Dimension( (int) list.getMinimumSize().getWidth(), 25 ) );
} else {
final String visibleItemsText =
listParameter.getParameterAttribute( ParameterAttributeNames.Core.NAMESPACE,
ParameterAttributeNames.Core.VISIBLE_ITEMS, parameterContext );
final int visibleItems = ParserUtil.parseInt( visibleItemsText, 0 );
if ( visibleItems > 0 ) {
list.setVisibleRowCount( visibleItems );
}
}
setViewportView( list );
getViewport().setMinimumSize( list.getPreferredScrollableViewportSize() );
setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );
changeListener = new ListUpdateHandler();
updateContext.addChangeListener( changeListener );
}
@SuppressWarnings( "unchecked" )
private void init() {
globalTemplateAction = new GlobalTemplateAction( this, dialogModel );
queryTemplateAction = new QueryTemplateAction( this, dialogModel );
queryNameList = new JList( dialogModel.getQueries() );
queryNameList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
queryNameList.setVisibleRowCount( 5 );
queryNameList.setCellRenderer( new QueryListCellRenderer() );
queryNameList.addListSelectionListener( new QuerySelectedHandler( dialogModel, queryNameList ) );
queryNameTextField = new JTextField();
queryNameTextField.setColumns( 35 );
queryNameTextField.setEnabled( dialogModel.isQuerySelected() );
queryNameTextField.getDocument().addDocumentListener( new QueryNameUpdateHandler() );
globalScriptTextArea = new RSyntaxTextArea();
globalScriptTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_NONE );
globalScriptTextArea.getDocument().addDocumentListener( new GlobalScriptUpdateHandler() );
globalLanguageField =
new SmartComboBox( new DefaultComboBoxModel( DataFactoryEditorSupport.getScriptEngineLanguages() ) );
globalLanguageField.setRenderer( new QueryLanguageListCellRenderer() );
globalLanguageField.addActionListener( new UpdateGlobalScriptLanguageHandler() );
queryScriptTextArea = new RSyntaxTextArea();
queryScriptTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_NONE );
queryScriptTextArea.getDocument().addDocumentListener( new QueryScriptUpdateHandler() );
queryLanguageField =
new SmartComboBox( new DefaultComboBoxModel( DataFactoryEditorSupport.getScriptEngineLanguages() ) );
queryLanguageListCellRenderer = new QueryLanguageListCellRenderer();
queryLanguageField.setRenderer( queryLanguageListCellRenderer );
queryLanguageField.addActionListener( new UpdateQueryScriptLanguageHandler() );
dialogModel.addQueryDialogModelListener( new DialogModelChangesDispatcher() );
initialize();
createComponents();
}
private void init( final DesignTimeContext context ) {
if ( context == null ) {
throw new NullPointerException();
}
this.context = context;
setModal( true );
setTitle( Messages.getString( "PmdDataSourceEditor.Title" ) );
maxPreviewRowsSpinner = new JSpinner( new SpinnerNumberModel( 10000, 1, Integer.MAX_VALUE, 1 ) );
previewAction = new PreviewAction();
globalTemplateAction = new GlobalTemplateAction();
queryTemplateAction = new QueryTemplateAction();
filenameField = new JTextField( null, 0 );
filenameField.setColumns( 30 );
filenameField.getDocument().addDocumentListener( new FilenameDocumentListener() );
queryNameList = new JList();
queryNameList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
queryNameList.setVisibleRowCount( 5 );
queryNameList.addListSelectionListener( new QueryNameListSelectionListener() );
queryNameList.setCellRenderer( new QueryNameListCellRenderer() );
queryAddButton = new BorderlessButton( new AddQueryAction() );
queryRemoveButton = new BorderlessButton( new RemoveQueryAction() );
queryNameTextField = new JTextField( null, 0 );
queryNameTextField.setColumns( 35 );
queryNameTextField.getDocument().addDocumentListener( new QueryNameTextFieldDocumentListener() );
domainIdTextField = new JTextField( null, 0 );
domainIdTextField.setColumns( 35 );
domainIdTextField.getDocument().addDocumentListener( new DomainTextFieldDocumentListener() );
queryTextArea = new RSyntaxTextArea();
queryTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_XML );
queryTextArea.setWrapStyleWord( true );
queryTextArea.setLineWrap( true );
queryTextArea.setRows( 5 );
queryTextArea.getDocument().addDocumentListener( new QueryDocumentListener() );
queryDesignerButton = new JButton( new QueryDesignerAction() );
queryDesignerButton.setEnabled( false );
queryDesignerButton.setBorder( new EmptyBorder( 0, 0, 0, 0 ) );
globalScriptTextArea = new RSyntaxTextArea();
globalScriptTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_NONE );
globalLanguageField = new SmartComboBox( new DefaultComboBoxModel( getScriptEngineLanguages() ) );
globalLanguageField.setRenderer( new QueryLanguageListCellRenderer() );
globalLanguageField.addActionListener( new UpdateScriptLanguageHandler() );
queryScriptTextArea = new RSyntaxTextArea();
queryScriptTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_NONE );
queryScriptTextArea.getDocument().addDocumentListener( new QueryScriptDocumentListener() );
queryLanguageListCellRenderer = new QueryLanguageListCellRenderer();
queryLanguageField = new SmartComboBox( new DefaultComboBoxModel( getScriptEngineLanguages() ) );
queryLanguageField.setRenderer( queryLanguageListCellRenderer );
queryLanguageField.addActionListener( new UpdateScriptLanguageHandler() );
super.init();
}
/**
* Creates the panel which holds the main content of the dialog
*/
private void initDialog( final DesignTimeContext designTimeContext ) {
this.designTimeContext = designTimeContext;
setTitle( Messages.getString( "JdbcDataSourceDialog.Title" ) );
setModal( true );
globalTemplateAction = new GlobalTemplateAction();
queryTemplateAction = new QueryTemplateAction();
dialogModel = new NamedDataSourceDialogModel();
dialogModel.addPropertyChangeListener( new ConfirmValidationHandler() );
connectionComponent = new JdbcConnectionPanel( dialogModel, designTimeContext );
maxPreviewRowsSpinner = new JSpinner( new SpinnerNumberModel( 10000, 1, Integer.MAX_VALUE, 1 ) );
final QueryNameTextFieldDocumentListener updateHandler = new QueryNameTextFieldDocumentListener();
dialogModel.getQueries().addListDataListener( updateHandler );
queryNameList = new JList( dialogModel.getQueries() );
queryNameList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
queryNameList.setVisibleRowCount( 5 );
queryNameList.addListSelectionListener( new QuerySelectedHandler() );
queryNameTextField = new JTextField();
queryNameTextField.setColumns( 35 );
queryNameTextField.setEnabled( dialogModel.isQuerySelected() );
queryNameTextField.getDocument().addDocumentListener( updateHandler );
queryTextArea = new RSyntaxTextArea();
queryTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_SQL );
queryTextArea.setEnabled( dialogModel.isQuerySelected() );
queryTextArea.getDocument().addDocumentListener( new QueryDocumentListener() );
globalScriptTextArea = new RSyntaxTextArea();
globalScriptTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_NONE );
globalLanguageField = new SmartComboBox<ScriptEngineFactory>( new DefaultComboBoxModel( DataFactoryEditorSupport.getScriptEngineLanguages() ) );
globalLanguageField.setRenderer( new QueryLanguageListCellRenderer() );
globalLanguageField.addActionListener( new UpdateScriptLanguageHandler() );
queryScriptTextArea = new RSyntaxTextArea();
queryScriptTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_NONE );
queryScriptTextArea.getDocument().addDocumentListener( new QueryScriptDocumentListener() );
queryLanguageListCellRenderer = new QueryLanguageListCellRenderer();
queryLanguageField = new SmartComboBox<ScriptEngineFactory>( new DefaultComboBoxModel( DataFactoryEditorSupport.getScriptEngineLanguages() ) );
queryLanguageField.setRenderer( queryLanguageListCellRenderer );
queryLanguageField.addActionListener( new UpdateScriptLanguageHandler() );
super.init();
}
/**
* Instantiates a new list selector.
*
* @param listData the list data
*/
public ListSelector(Object[] listData) {
for (int i = 0; i < listData.length; i++)
listModel.addElement(listData[i]);
setLayout(new BorderLayout(4, 4));
list = new JList(listModel);
list.setFixedCellWidth(200);
list.setVisibleRowCount(3);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
Border etchedBorder = BorderFactory.createEtchedBorder();
list.setBorder(etchedBorder);
JScrollPane scrollPane = new JScrollPane(list, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
add(scrollPane, BorderLayout.CENTER);
JPanel controlPanel = new JPanel();
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(2, 2, 2, 2);
controlPanel.setLayout(gbl);
addField = new JTextField(6);
addField.addActionListener(this);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.NORTHEAST;
controlPanel.add(addField, gbc);
gbc.gridx = 1;
gbc.anchor = GridBagConstraints.NORTHWEST;
addButton = new SmallButton("Add");
addButton.addActionListener(this);
controlPanel.add(addButton, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.anchor = GridBagConstraints.WEST;
JPanel movePanel = new JPanel();
movePanel.setLayout(new GridLayout(1, 2, 4, 4));
moveUpButton = new ImageButton(Images.UP);
moveUpButton.addActionListener(this);
movePanel.add(moveUpButton);
moveDownButton = new ImageButton(Images.DOWN);
moveDownButton.addActionListener(this);
movePanel.add(moveDownButton);
controlPanel.add(movePanel, gbc);
gbc.gridx = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.anchor = GridBagConstraints.WEST;
removeButton = new SmallButton("Remove");
removeButton.addActionListener(this);
controlPanel.add(removeButton, gbc);
add(controlPanel, BorderLayout.EAST);
}