Java 类javax.swing.ListModel 实例源码
项目:incubator-netbeans
文件:TableUISupport.java
@Override
public int getNextMatch(String prefix, int startIndex, Bias bias) {
ListModel model = getModel();
if (!(model instanceof TableModel)) {
return super.getNextMatch(prefix, startIndex, bias);
}
TableModel tablesModel = (TableModel)model;
int max = tablesModel.getSize();
int increment = (bias == Bias.Forward) ? 1 : -1;
int index = startIndex;
prefix = prefix.toUpperCase();
do {
Table table = tablesModel.getElementAt(index);
String tableName = table.getName().toUpperCase();
if (tableName.startsWith(prefix)) {
return index;
}
index = (index + increment + max) % max;
} while (index != startIndex);
return -1;
}
项目:incubator-netbeans
文件:CategoryPanelFormatters.java
@Override
public boolean isChanged() {
ListModel formattersModel = formattersList.getModel();
VariablesFormatter[] formatters = new VariablesFormatter[formattersModel.getSize()];
for (int i = 0; i < formatters.length; i++) {
formatters[i] = (VariablesFormatter) formattersModel.getElementAt(i);
}
VariablesFormatter[] saved = VariablesFormatter.loadFormatters();
if(saved == null) {
return false;
}
if(saved.length != formatters.length) {
return true;
}
for (int i = 0; i < saved.length; i++) {
VariablesFormatter savedFormatter = saved[i];
VariablesFormatter currentFormatter = (VariablesFormatter) formattersModel.getElementAt(i);
if(!areVariablesFormattersEqual(savedFormatter, currentFormatter)) {
return true;
}
}
return false;
}
项目:incubator-netbeans
文件:FixVersionConflictPanel.java
FixDescription getResult() {
FixDescription res = new FixDescription();
res.isSet = addSetCheck.isSelected();
res.version2Set = res.isSet ? (ArtifactVersion) versionList.getSelectedValue() : null;
res.isExclude = excludeCheck.isSelected();
if (res.isExclude) {
res.exclusionTargets = new HashSet<Artifact>();
res.conflictParents = new HashSet<MavenDependencyNode>();
ListModel lm = excludesList.getModel();
for (int i = 0; i < lm.getSize(); i++) {
ExclTargetEntry entry = (ExclTargetEntry) lm.getElementAt(i);
if (entry.isSelected) {
res.exclusionTargets.add(entry.artif);
res.conflictParents.addAll(eTargets.getConflictParents(entry.artif));
}
}
}
return res;
}
项目:FreeCol
文件:UnitType.java
@Override
public int getMaximumIndex(Colony colony, JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD) {
ListModel<BuildableType> buildQueue = buildQueueList.getModel();
final int buildQueueLastPos = buildQueue.getSize();
boolean canBuild = false;
if (colony.canBuild(this)) {
canBuild = true;
}
// does not depend on anything, nothing depends on it
// can be built at any time
if (canBuild) return buildQueueLastPos;
// check for building in queue that allows builting this unit
for (int index = 0; index < buildQueue.getSize(); index++) {
BuildableType toBuild = buildQueue.getElementAt(index);
if (toBuild == this) continue;
if (toBuild.hasAbility(Ability.BUILD, this)) {
return buildQueueLastPos;
}
}
return UNABLE_TO_BUILD;
}
项目:incubator-netbeans
文件:TaskPanel.java
private void reloadField (JComponent component, IssueField field) {
String newValue;
newValue = task.getFieldValue(field);
boolean fieldDirty = unsavedFields.contains(field.getKey());
if (!fieldDirty) {
if (component instanceof JComboBox) {
throw new UnsupportedOperationException();
} else if (component instanceof JTextComponent) {
((JTextComponent) component).setText(newValue);
} else if (component instanceof JList) {
JList list = (JList) component;
list.clearSelection();
ListModel model = list.getModel();
for (String value : task.getFieldValues(field)) {
for (int i = 0; i < model.getSize(); i++) {
if (value.equals(model.getElementAt(i))) {
list.addSelectionInterval(i, i);
}
}
}
} else if (component instanceof JCheckBox) {
((JCheckBox) component).setSelected("1".equals(newValue));
}
}
}
项目:incubator-netbeans
文件:GenerateCodeOperator.java
/**
* Opens requested code generation dialog
* @param type Displayname of menu item
* @param editor Operator of editor window where should be menu opened
* @return true is item is found, false elsewhere
*/
public static boolean openDialog(String type, EditorOperator editor) {
new EventTool().waitNoEvent(1000);
editor.pushKey(KeyEvent.VK_INSERT, KeyEvent.ALT_DOWN_MASK);
JDialogOperator jdo = new JDialogOperator();
new EventTool().waitNoEvent(1000);
JListOperator list = new JListOperator(jdo);
ListModel lm = list.getModel();
for (int i = 0; i < lm.getSize(); i++) {
CodeGenerator cg = (CodeGenerator) lm.getElementAt(i);
if(cg.getDisplayName().equals(type)) {
list.setSelectedIndex(i);
jdo.pushKey(KeyEvent.VK_ENTER);
new EventTool().waitNoEvent(1000);
return true;
}
}
return false;
}
项目:incubator-netbeans
文件:GenerateCodeOperator.java
/**
* Compares list of items provided in the Insert Code dialog with the list of expected items
* @param editor Operator of editor window where should Insert Code should be caled
* @param items Expected items
* @return true if both list are the same, false otherwise
*/
public static boolean containsItems(EditorOperator editor, String ... items) {
Set<String> actItems = new HashSet<String>();
List<String> expItems = Arrays.asList(items);
editor.pushKey(KeyEvent.VK_INSERT, KeyEvent.ALT_DOWN_MASK);
JDialogOperator jdo = new JDialogOperator();
JListOperator list = new JListOperator(jdo);
ListModel lm = list.getModel();
for (int i = 0; i < lm.getSize(); i++) {
CodeGenerator cg = (CodeGenerator) lm.getElementAt(i);
actItems.add(cg.getDisplayName());
if(!expItems.contains(cg.getDisplayName())) return false;
}
for (String string : expItems) {
if(!actItems.contains(string)) return false;
}
return true;
}
项目:incubator-netbeans
文件:TableUISupport.java
@Override
public int getNextMatch(String prefix, int startIndex, Bias bias) {
ListModel model = getModel();
if (!(model instanceof TableModel)) {
return super.getNextMatch(prefix, startIndex, bias);
}
TableModel tablesModel = (TableModel)model;
int max = tablesModel.getSize();
int increment = (bias == Bias.Forward) ? 1 : -1;
int index = startIndex;
prefix = prefix.toUpperCase();
do {
Table table = tablesModel.getElementAt(index);
String tableName = table.getName().toUpperCase();
if (tableName.startsWith(prefix)) {
return index;
}
index = (index + increment + max) % max;
} while (index != startIndex);
return -1;
}
项目:incubator-netbeans
文件:GoToPanelImpl.java
/** Sets the model.
* Threading: Requires EDT.
* @param the model to set
* @param finished true for final update
* @return true if model has changed
*/
@Override
public boolean setModel(
@NonNull final ListModel model,
final boolean finished) {
assert SwingUtilities.isEventDispatchThread();
matchesList.setModel(model);
if (model.getSize() > 0 || getText() == null || getText().trim().length() == 0 ) {
matchesList.setSelectedIndex(0);
setListPanelContent(null,false);
if ( time != -1 ) {
GoToSymbolAction.LOGGER.log(
Level.FINE,
"Real search time {0} ms.", //NOI18N
(System.currentTimeMillis() - time));
time = -1;
}
return true;
} else if (finished) {
setListPanelContent(NbBundle.getMessage(GoToPanelImpl.class, "TXT_NoSymbolsFound") ,false );
return false;
} else {
return false;
}
}
项目:incubator-netbeans
文件:FileSearchPanel.java
void setModel(
@NonNull final ListModel model,
final boolean done) {
// XXX measure time here
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
LOG.log(
Level.FINE,
"Reset selected items"); //NOI18N
selectedItems = null;
resultList.setModel(model);
if (done) {
setListPanelContent(null,false);
}
}
});
}
项目:incubator-netbeans
文件:GoToPanel.java
/** Sets the model from different therad
*/
boolean setModel( final ListModel model) {
assert SwingUtilities.isEventDispatchThread();
matchesList.setModel(model);
if (model.getSize() > 0 || getText() == null || getText().trim().length() == 0 ) {
matchesList.setSelectedIndex(0);
setListPanelContent(null,false);
if ( time != -1 ) {
GoToTypeAction.LOGGER.fine("Real search time " + (System.currentTimeMillis() - time) + " ms.");
time = -1;
}
return true;
} else {
setListPanelContent( NbBundle.getMessage(GoToPanel.class, "TXT_NoTypesFound") ,false ); // NOI18N
return false;
}
}
项目:scorekeeperfrontend
文件:EntryPanel.java
protected void setPaidDriverInfo()
{
paidwarning.setOpaque(false);
paidwarning.setText("");
if (selectedDriver == null)
return;
ListModel<DecoratedCar> m = cars.getModel();
if (m.getSize() > 0) {
for (int ii = 0; ii < m.getSize(); ii++) {
DecoratedCar c = (DecoratedCar)m.getElementAt(ii);
if (!c.isInRunOrder() && c.hasPaid()) return;
}
}
paidwarning.setText("No cars paid and not in runorder");
paidwarning.setOpaque(true);
}
项目:incubator-netbeans
文件:QuickSearchPopup.java
void invoke() {
int selection = jList1.getSelectedIndex();
ListModel model = jList1.getModel();
Object item = model.getElementAt(selection);
if(item == null) {
return;
}
if(item instanceof PopupItem.IssueItem) {
IssueImpl issue = ((PopupItem.IssueItem) item).getIssue();
if (issue != null) {
comboBar.setIssue(issue);
clearModel();
}
} else {
PopupItem pitem = (PopupItem) item;
pitem.invoke();
}
}
项目:FreeCol
文件:BuildingType.java
@Override
public int getMinimumIndex(Colony colony, JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD) {
ListModel<BuildableType> buildQueue = buildQueueList.getModel();
BuildingType upgradesFrom = this.getUpgradesFrom();
if (upgradesFrom == null) return 0;
Building building = colony.getBuilding(this);
BuildingType buildingType = (building == null) ? null
: building.getType();
if (buildingType == upgradesFrom) return 0;
for (int index = 0; index < buildQueue.getSize(); index++) {
if (upgradesFrom.equals(buildQueue.getElementAt(index))) {
return index + 1;
}
}
return UNABLE_TO_BUILD;
}
项目:jmt
文件:ScrollBivariatePanel.java
public ScrollBivariatePanel(JWatBivariateStatsTable table) {
tab = table;
setViewportView(tab);
ListModel lm = new AbstractListModel() {
private static final long serialVersionUID = 1L;
String headers[] = ((JWatBivariateStatsTableModel) tab.getModel()).getNames();
public int getSize() {
return headers.length;
}
public Object getElementAt(int index) {
return headers[index];
}
};
JList rowHeader = new JList(lm);
rowHeader.setBackground(getBackground());
rowHeader.setFixedCellWidth(100);
rowHeader.setFixedCellHeight(tab.getRowHeight());
rowHeader.setCellRenderer(new RowHeaderRenderer(tab));
setRowHeaderView(rowHeader);
}
项目:jmt
文件:ScrollBivariatePanel.java
public void setNames() {
ListModel lm = new AbstractListModel() {
private static final long serialVersionUID = 1L;
String headers[] = ((JWatBivariateStatsTableModel) tab.getModel()).getNames();
public int getSize() {
return headers.length;
}
public Object getElementAt(int index) {
return headers[index];
}
};
JList rowHeader = new JList(lm);
rowHeader.setBackground(getBackground());
rowHeader.setFixedCellWidth(100);
rowHeader.setFixedCellHeight(tab.getRowHeight());
rowHeader.setCellRenderer(new RowHeaderRenderer(tab));
setRowHeaderView(rowHeader);
}
项目:LogisticApp
文件:FracionalPanelBuilder.java
private void updateListTrechos(RotaVO rota) throws CadastroException {
DefaultListModel<RotaVO> model = new DefaultListModel<RotaVO>();
ListModel<RotaVO> currentModel = this.listTrechos.getModel();
// as rotas precisam ser sequenciais
// logo se a origem da nova rota não for igual ao destino da última,
// lançar exceção
if (currentModel.getSize() > 0) {
RotaVO last = currentModel.getElementAt(currentModel.getSize() - 1);
if (!last.getDescricaoDestino().equals(rota.getDescricaoOrigem()))
throw new CadastroException("Trecho inválido. A próxima rota precisa possuir "
+ last.getDescricaoDestino() + " como origem.");
}
for (int i = 0; i < currentModel.getSize(); i++) {
RotaVO trecho = currentModel.getElementAt(i);
model.addElement(trecho);
}
model.addElement(rota);
this.listTrechos.setModel(model);
}
项目:QN-ACTR-Release
文件:ScrollBivariatePanel.java
public void setNames() {
ListModel lm = new AbstractListModel() {
/**
*
*/
private static final long serialVersionUID = 1L;
String headers[] = ((JWatBivariateStatsTableModel) tab.getModel()).getNames();
public int getSize() {
return headers.length;
}
public Object getElementAt(int index) {
return headers[index];
}
};
JList rowHeader = new JList(lm);
rowHeader.setBackground(getBackground());
rowHeader.setFixedCellWidth(100);
rowHeader.setFixedCellHeight(tab.getRowHeight());
rowHeader.setCellRenderer(new RowHeaderRenderer(tab));
setRowHeaderView(rowHeader);
}
项目:KernelHive
文件:NodePropertiesDialog.java
private void fillSourceFilesList(final List<IKernelFile> sourceFiles) {
final ListModel model = new SourceFilesListModel(sourceFiles);
list.setModel(model);
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
e.consume();
final IKernelFile file = (IKernelFile) list
.getSelectedValue();
frame.getController().openTab(file.getFile());
}
}
});
}
项目:Equella
文件:CombinedListModel.java
/**
* Converts a full index of a list item to the relevant model number. This
* is required for <code>AttachmentListCellRenderer</code> to display the
* correct icon.
*
* @see AttachmentListCellRenderer
* @param index of list item
* @return index of model used for index parameter
*/
public int getModelIndex(int index)
{
for( int i = 0; i < models.size(); i++ )
{
ListModel model = models.get(i);
if( model.getSize() <= index )
{
index -= model.getSize();
}
else
{
return i;
}
}
return -1;
}
项目:Equella
文件:CombinedListModel.java
@Override
public Object getElementAt(int index)
{
for( int i = 0; i < models.size(); i++ )
{
ListModel model = models.get(i);
if( model.getSize() <= index )
{
index -= model.getSize();
}
else
{
return model.getElementAt(index);
}
}
return null;
}
项目:ramus
文件:TableRowHeader.java
private void updatePrefferedWidth(int firstRow, int lastRow) {
final ListModel model = getModel();
final int l = model.getSize() - 1;
if (lastRow > l)
lastRow = l;
if (firstRow < 0)
firstRow = 0;
int m = this.m;
for (int i = firstRow; i <= lastRow; i++) {
final Object obj = model.getElementAt(i);
if (obj == null)
continue;
final Component c = renderer.getListCellRendererComponent(this,
obj, i, true, true);
final int t = c.getPreferredSize().width + 2;
if (t > m)
m = t;
}
if (m != getFixedCellWidth()) {
setFixedCellWidth(m);
revalidate();
}
}
项目:ramus
文件:TableRowHeader.java
private void updatePrefferedWidth(int firstRow, int lastRow) {
final ListModel model = getModel();
final int l = model.getSize() - 1;
if (lastRow > l)
lastRow = l;
if (firstRow < 0)
firstRow = 0;
int m = this.m;
for (int i = firstRow; i <= lastRow; i++) {
final Object obj = model.getElementAt(i);
if (obj == null)
continue;
final Component c = renderer.getListCellRendererComponent(this,
obj, i, true, true);
final int t = c.getPreferredSize().width + 2;
if (t > m)
m = t;
}
if (m != getFixedCellWidth()) {
setFixedCellWidth(m);
revalidate();
}
}
项目:freecol
文件:BuildingType.java
@Override
public int getMinimumIndex(Colony colony, JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD) {
ListModel<BuildableType> buildQueue = buildQueueList.getModel();
BuildingType upgradesFrom = this.getUpgradesFrom();
if (upgradesFrom == null) return 0;
Building building = colony.getBuilding(this);
BuildingType buildingType = (building == null) ? null
: building.getType();
if (buildingType == upgradesFrom) return 0;
for (int index = 0; index < buildQueue.getSize(); index++) {
if (upgradesFrom.equals(buildQueue.getElementAt(index))) {
return index + 1;
}
}
return UNABLE_TO_BUILD;
}
项目:freecol
文件:UnitType.java
@Override
public int getMaximumIndex(Colony colony, JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD) {
ListModel<BuildableType> buildQueue = buildQueueList.getModel();
final int buildQueueLastPos = buildQueue.getSize();
boolean canBuild = false;
if (colony.canBuild(this)) {
canBuild = true;
}
// does not depend on anything, nothing depends on it
// can be built at any time
if (canBuild) return buildQueueLastPos;
// check for building in queue that allows builting this unit
for (int index = 0; index < buildQueue.getSize(); index++) {
BuildableType toBuild = buildQueue.getElementAt(index);
if (toBuild == this) continue;
if (toBuild.hasAbility(Ability.BUILD, this)) {
return buildQueueLastPos;
}
}
return UNABLE_TO_BUILD;
}
项目:pdfjumbler
文件:JDragDropList.java
@Override
public void setModel(ListModel<T> model) {
if (model instanceof StandardListModel) {
super.setModel(model);
} else {
throw new IllegalArgumentException("Unsupported model type.");
}
}
项目:incubator-netbeans
文件:SpellcheckerOptionsPanel.java
private ListModel getInstalledDictionariesModel() {
DefaultListModel dlm = new DefaultListModel();
for (Locale l : DictionaryProviderImpl.getInstalledDictionariesLocales()) {
dlm.addElement(l);
}
return dlm;
}
项目:incubator-netbeans
文件:CategoryPanelFormatters.java
private Set<String> getFormatterNames() {
Set<String> formatterNames = new HashSet<String>();
ListModel formattersModel = formattersList.getModel();
int n = formattersModel.getSize();
for (int i = 0; i < n; i++) {
VariablesFormatter vf = (VariablesFormatter) formattersModel.getElementAt(i);
formatterNames.add(vf.getName());
}
return formatterNames;
}
项目:incubator-netbeans
文件:CategoryPanelFormatters.java
@Override
public void store() {
/*if (selectedVariablesFormatter != null) {
storeSelectedFormatter(selectedVariablesFormatter);
}*/
Properties p = Properties.getDefault().getProperties("debugger.options.JPDA");
ListModel formattersModel = formattersList.getModel();
VariablesFormatter[] formatters = new VariablesFormatter[formattersModel.getSize()];
for (int i = 0; i < formatters.length; i++) {
VariablesFormatter vf = (VariablesFormatter) formattersModel.getElementAt(i);
formatters[i] = vf;
}
p.setArray("VariableFormatters", formatters);
}
项目:FreeCol
文件:BuildQueuePanel.java
private List<BuildableType> getBuildableTypes(JList<? extends BuildableType> list) {
List<BuildableType> result = new ArrayList<>();
if (list == null) return result;
ListModel<? extends BuildableType> model = list.getModel();
for (int index = 0; index < model.getSize(); index++) {
result.add(model.getElementAt(index));
}
return result;
}
项目:incubator-netbeans
文件:ManageGroupsPanel.java
private boolean isReady() {
ListModel model = groupList.getModel ();
if(model.getSize() != Group.allGroups().size() + 1 ) {
return false;
}
return true;
}
项目:incubator-netbeans
文件:FileListPanel.java
private ListModel getFileListModel(){
DefaultListModel ret = new DefaultListModel();
for (String file: origFiles){
ret.addElement(file);
}
return ret;
}
项目:incubator-netbeans
文件:FileListPanel.java
public List<String> getFiles(){
Vector<String> files = new Vector<String>();
ListModel lm = this.listFiles.getModel();
int numFiles = lm.getSize();
if (numFiles > 0){
for (int i=0; i < numFiles; i++){
files.add((String) lm.getElementAt(i));
}
}
return files;
}
项目:incubator-netbeans
文件:DeclarationPopup.java
private ListModel createListModel() {
DefaultListModel dlm = new DefaultListModel();
for (AlternativeLocation el: declarations) {
dlm.addElement(el);
}
return dlm;
}
项目:incubator-netbeans
文件:IsOverriddenPopup.java
private ListModel createListModel() {
DefaultListModel dlm = new DefaultListModel();
for (OverrideDescription el: declarations) {
dlm.addElement(el);
}
return dlm;
}
项目:incubator-netbeans
文件:GenerateCodeOperator.java
/**
* Check if Insertcode popup contains requested item
* @param editor Operator of editor window where should Insert Code should be caled
* @param items Expected items
* @return true if all requested item are pressent, to exact match use {@link #containsItems(org.netbeans.jellytools.EditorOperator, java.lang.String[]) containsItems}
*/
public static boolean checkItems(EditorOperator editor, String ... items) {
Set<String> expItems = new HashSet<String>(Arrays.asList(items));
editor.pushKey(KeyEvent.VK_INSERT, KeyEvent.ALT_DOWN_MASK);
JDialogOperator jdo = new JDialogOperator();
JListOperator list = new JListOperator(jdo);
ListModel lm = list.getModel();
for (int i = 0; i < lm.getSize(); i++) {
CodeGenerator cg = (CodeGenerator) lm.getElementAt(i);
expItems.remove(cg.getDisplayName());
}
if(!expItems.isEmpty()) return false;
return true;
}
项目:incubator-netbeans
文件:MethodCandidateChooser.java
private ListModel createListModel() {
DefaultListModel dlm = new DefaultListModel();
for (Candidate cand: toShow) {
dlm.addElement(cand);
}
return dlm;
}
项目:incubator-netbeans
文件:ClasspathCustomEditorOperator.java
/** returns complete class path from editor
* @return String[] class paths */
public String[] getClasspathValue() {
ArrayList<String> data=new ArrayList<String>();
ListModel model=lstClasspath().getModel();
for (int i=0; i<model.getSize(); i++) {
data.add(model.getElementAt(i).toString());
}
return (String[])data.toArray(new String[data.size()]);
}
项目:incubator-netbeans
文件:StringArrayCustomEditorOperator.java
/** getter for array of Strings
* @return String[] array of strings from custom editor */
public String[] getStringArrayValue() {
ListModel lm=lstItemList().getModel();
String value[]=new String[lm.getSize()];
for (int i=0; i<lm.getSize(); i++) {
value[i]=lm.getElementAt(i).toString();
}
return value;
}
项目:incubator-netbeans
文件:IsOverriddenPopup.java
private ListModel createListModel() {
DefaultListModel dlm = new DefaultListModel();
for (ElementDescription el: declarations) {
dlm.addElement(el);
}
return dlm;
}