use of javax.swing.DefaultListSelectionModel in project pcgen by PCGen.
the class AbilityChooserTab method createState.
//
// private final class AbilityTransferHandler extends TransferHandler
// {
//
// private CharacterFacade character;
//
// public AbilityTransferHandler(CharacterFacade character)
// {
// this.character = character;
// }
//
// private final DataFlavor abilityFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType +
// ";class=" +
// AbilityFacade.class.getName(),
// null);
//
// @Override
// public int getSourceActions(JComponent c)
// {
// if (selectedAbility != null)
// {
// if (selectedTreeViewPanel.isAncestorOf(c))
// {
// return MOVE;
// }
// if (selectedAbility.isMult())
// {
// return COPY;
// }
// if (!character.hasAbility(selectedCatagory, selectedAbility))
// {
// return MOVE;
// }
// }
// return NONE;
// }
//
// @Override
// protected Transferable createTransferable(JComponent c)
// {
// final AbilityFacade transferAbility = selectedAbility;
// return new Transferable()
// {
//
// public DataFlavor[] getTransferDataFlavors()
// {
// return new DataFlavor[]
// {
// abilityFlavor
// };
// }
//
// public boolean isDataFlavorSupported(DataFlavor flavor)
// {
// return abilityFlavor == flavor;
// }
//
// public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
// {
// if (!isDataFlavorSupported(flavor))
// {
// throw new UnsupportedFlavorException(flavor);
// }
// return transferAbility;
// }
//
// };
// }
//
// @Override
// public boolean canImport(JComponent comp, DataFlavor[] transferFlavors)
// {
// return transferFlavors[0] == abilityFlavor;
// }
//
// @Override
// public boolean importData(JComponent comp, Transferable t)
// {
// if (selectedTreeViewPanel.isAncestorOf(comp))
// {
// try
// {
// AbilityFacade ability = (AbilityFacade) t.getTransferData(abilityFlavor);
// // TODO: add some extra logic
// character.addAbility(selectedCatagory, ability);
// return true;
// }
// catch (UnsupportedFlavorException ex)
// {
// Logger.getLogger(AbilityChooserTab.class.getName()).log(Level.SEVERE,
// null,
// ex);
// }
// catch (IOException ex)
// {
// Logger.getLogger(AbilityChooserTab.class.getName()).log(Level.SEVERE,
// null,
// ex);
// }
// return false;
// }
// return true;
// }
//
// @Override
// protected void exportDone(JComponent source, Transferable data,
// int action)
// {
// if (action == COPY)
// {
// return;
// }
// }
//
// }
public Hashtable<Object, Object> createState(CharacterFacade character, ListFacade<AbilityCategoryFacade> categories, ListFacade<AbilityCategoryFacade> fullCategoryList, String title) {
Hashtable<Object, Object> state = new Hashtable<>();
CategoryTableModel categoryTableModel = new CategoryTableModel(character, fullCategoryList, categoryBar, categoryTable);
state.put(CategoryTableModel.class, categoryTableModel);
ListSelectionModel listModel = new DefaultListSelectionModel();
listModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
state.put(ListSelectionModel.class, listModel);
state.put(AbilityTreeTableModel.class, new AbilityTreeTableModel(character, categories));
state.put(AvailableAbilityTreeViewModel.class, new AvailableAbilityTreeViewModel(character, fullCategoryList, listModel, title));
//state.put(AbilityTransferHandler.class, new AbilityTransferHandler(character));
state.put(InfoHandler.class, new InfoHandler(character, categories));
state.put(TreeRendererHandler.class, new TreeRendererHandler(character));
state.put(AddAction.class, new AddAction(character));
state.put(RemoveAction.class, new RemoveAction(character));
state.put(AbilityFilterHandler.class, new AbilityFilterHandler(character));
state.put(CategoryFilterHandler.class, new CategoryFilterHandler(categoryTableModel));
return state;
}
use of javax.swing.DefaultListSelectionModel in project pcgen by PCGen.
the class AbilityChooserTab method storeState.
@Override
public void storeState(Hashtable<Object, Object> state) {
((InfoHandler) state.get(InfoHandler.class)).uninstall();
((AvailableAbilityTreeViewModel) state.get(AvailableAbilityTreeViewModel.class)).uninstall();
categoryTable.setSelectionModel(new DefaultListSelectionModel());
((CategoryTableModel) state.get(CategoryTableModel.class)).uninstall();
((AddAction) state.get(AddAction.class)).uninstall();
((RemoveAction) state.get(RemoveAction.class)).uninstall();
((TreeRendererHandler) state.get(TreeRendererHandler.class)).uninstall();
}
use of javax.swing.DefaultListSelectionModel in project ACS by ACS-Community.
the class AlarmTable method initGUI.
/**
* Init the GUI
*/
private void initGUI() {
setShowHorizontalLines(true);
// Build and set the selection model
selectionModel = new DefaultListSelectionModel();
selectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
setSelectionModel(selectionModel);
this.setOpaque(false);
sorter = new TableRowSorter<AlarmTableModel>(model);
this.setRowSorter(sorter);
sorter.setMaxSortKeys(2);
sorter.setSortsOnUpdates(true);
// Initially sort by timestamp
List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
sortKeys.add(new RowSorter.SortKey(AlarmTableColumn.PRIORITY.ordinal(), SortOrder.ASCENDING));
sortKeys.add(new RowSorter.SortKey(AlarmTableColumn.TIME.ordinal(), SortOrder.DESCENDING));
sorter.setSortKeys(sortKeys);
// Remove all the columns not visible at startup
TableColumnModel colModel = getColumnModel();
columns = new TableColumn[colModel.getColumnCount()];
for (int t = 0; t < columns.length; t++) {
columns[t] = colModel.getColumn(t);
columns[t].setIdentifier(AlarmTableColumn.values()[t]);
if (columns[t].getIdentifier() == AlarmTableColumn.ICON || columns[t].getIdentifier() == AlarmTableColumn.IS_CHILD || columns[t].getIdentifier() == AlarmTableColumn.IS_PARENT) {
columns[t].setWidth(20);
columns[t].setResizable(false);
columns[t].setPreferredWidth(20);
columns[t].setMaxWidth(20);
columns[t].setMinWidth(20);
} else if (columns[t].getIdentifier() == AlarmTableColumn.PRIORITY) {
BufferedImage bImg = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
Graphics2D g2D = bImg.createGraphics();
FontMetrics fm = g2D.getFontMetrics();
int sz = fm.stringWidth(PriorityLabel.VERY_HIGH.description);
columns[t].setPreferredWidth(sz + 6);
columns[t].setMaxWidth(sz + 8);
}
}
for (AlarmTableColumn col : AlarmTableColumn.values()) {
if (!col.visibleAtStartup) {
colModel.removeColumn(columns[col.ordinal()]);
}
}
buildPopupMenu();
addMouseListener(mouseAdapter);
getTableHeader().addMouseListener(new AlarmHeaderMouseAdapter());
// Set the tooltip
ToolTipManager ttm = ToolTipManager.sharedInstance();
ttm.setDismissDelay(Integer.MAX_VALUE);
ttm.setLightWeightPopupEnabled(true);
}
use of javax.swing.DefaultListSelectionModel in project ACS by ACS-Community.
the class LogEntryTable method initialize.
/**
* Setup the table
*
* @param shortDateFormat The format to show the date (if <code>true</code> is short, otherwise complete)
* @param logTypeformat The way to show the log type (if <code>true</code> the description is shown)
*/
private void initialize(boolean shortDateFormat, boolean logTypeformat) {
createDefaultColumnsFromModel();
setShowHorizontalLines(false);
TableColumnModel tcm = getColumnModel();
// Setup the first col
TableColumn tc;
// Setup the first col
tc = tcm.getColumn(0);
tc.setCellRenderer(new InfoRenderer());
tc.setWidth(18);
tc.setMaxWidth(18);
tc.setResizable(false);
tc = tcm.getColumn(LogField.ENTRYTYPE.ordinal() + 1);
logTypeRenderer = new EntryTypeRenderer(logTypeformat);
tc.setCellRenderer(logTypeRenderer);
tc = tcm.getColumn(LogField.TIMESTAMP.ordinal() + 1);
dateRenderer = new DateRenderer(shortDateFormat);
tc.setCellRenderer(dateRenderer);
int n = tcm.getColumnCount();
columnsList = new TableColumn[n];
visibleColumns = new boolean[n];
for (int i = 0; i < n; i++) {
columnsList[i] = tcm.getColumn(i);
visibleColumns[i] = true;
if (i == LogField.LOGMESSAGE.ordinal() + 1) {
columnsList[i].setPreferredWidth(250);
}
}
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
sizeColumnsToFit(JTable.AUTO_RESIZE_OFF);
// Hide some columns (default at startup)
hideColumn(LogField.LINE.ordinal() + 1);
hideColumn(LogField.ROUTINE.ordinal() + 1);
hideColumn(LogField.HOST.ordinal() + 1);
hideColumn(LogField.PROCESS.ordinal() + 1);
hideColumn(LogField.CONTEXT.ordinal() + 1);
hideColumn(LogField.THREAD.ordinal() + 1);
hideColumn(LogField.LOGID.ordinal() + 1);
hideColumn(LogField.PRIORITY.ordinal() + 1);
hideColumn(LogField.URI.ordinal() + 1);
hideColumn(LogField.STACKID.ordinal() + 1);
hideColumn(LogField.FILE.ordinal() + 1);
hideColumn(LogField.STACKLEVEL.ordinal() + 1);
hideColumn(LogField.AUDIENCE.ordinal() + 1);
hideColumn(LogField.ARRAY.ordinal() + 1);
hideColumn(LogField.ANTENNA.ordinal() + 1);
// Build and set the selection model
selectionModel = new DefaultListSelectionModel();
selectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
setSelectionModel(selectionModel);
addMouseListener(new TableMouseAdapter());
}
use of javax.swing.DefaultListSelectionModel in project adempiere by adempiere.
the class MiniTable method doAction.
/**
* Performs the action.
* @param e
* @param actionName determines which action to perform
* @param dy the number of rows over which to perform the action.
*/
private void doAction(ActionEvent e, String actionName, int dy) {
int leadRow = 0;
MiniTable table = (MiniTable) e.getSource();
if (table.getRowCount() <= 0 || table.getColumnCount() <= 0) {
// bail - don't try to move selection on an empty table
return;
}
ListSelectionModel rsm = table.getSelectionModel();
int index = rsm.getLeadSelectionIndex();
int compare = table.getRowCount();
if (table.getShowTotals())
compare = compare - 1;
index = index < compare ? index : -1;
if (dy != 0) {
if (// Up
dy < 0) {
// Check limit at the top
leadRow = Math.min(Math.max(index + dy, 0), index);
} else if (// Down
dy > 0) {
// Check the limit at the bottom
leadRow = Math.min(Math.max(index + dy, 0), compare - 1);
}
if (actionName.equals("SelectRowUp") || actionName.equals("SelectRowDown")) {
rsm.clearSelection();
rsm.addSelectionInterval(leadRow, leadRow);
matchCheckWithSelectedRows();
} else if (actionName.equals("AddRowUp") || actionName.equals("AddRowDown")) {
// Determine if the focused row is selected
// Test the first row
Object data = table.getValueAt(index, table.convertColumnIndexToView(getKeyColumnIndex()));
if (data instanceof IDColumn) {
rsm.addSelectionInterval(index, leadRow);
setRowChecked(index, true);
setRowChecked(leadRow, true);
}
} else if (actionName.equals("AddRowUpExtend") || actionName.equals("AddRowDownExtend")) {
table.changeSelection(index, 0, false, true);
table.changeSelection(leadRow, 0, false, true);
matchCheckWithSelectedRows();
} else if (actionName.equals("ChangeLeadUp") || actionName.equals("ChangeLeadDown")) {
// Determine if the focused row is selected
if (isRowChecked(index)) {
// Select the original row
rsm.addSelectionInterval(index, index);
} else if (!isRowChecked(index) && table.isRowSelected(index)) {
rsm.removeSelectionInterval(index, index);
}
((DefaultListSelectionModel) rsm).moveLeadSelectionIndex(leadRow);
}
}
Rectangle cellRect = table.getCellRect(leadRow, 0, false);
if (cellRect != null) {
table.scrollRectToVisible(cellRect);
}
}
Aggregations