Search in sources :

Example 1 with DefaultListSelectionModel

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;
}
Also used : CategoryTableModel(pcgen.gui2.tabs.ability.CategoryTableModel) AbilityTreeTableModel(pcgen.gui2.tabs.ability.AbilityTreeTableModel) Hashtable(java.util.Hashtable) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ListSelectionModel(javax.swing.ListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel)

Example 2 with DefaultListSelectionModel

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();
}
Also used : CategoryTableModel(pcgen.gui2.tabs.ability.CategoryTableModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel)

Example 3 with DefaultListSelectionModel

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);
}
Also used : UndocAlarmTableModel(alma.acsplugins.alarmsystem.gui.undocumented.table.UndocAlarmTableModel) RowSorter(javax.swing.RowSorter) TableRowSorter(javax.swing.table.TableRowSorter) ToolTipManager(javax.swing.ToolTipManager) ArrayList(java.util.ArrayList) TableColumnModel(javax.swing.table.TableColumnModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) FontMetrics(java.awt.FontMetrics) AlarmTableColumn(alma.acsplugins.alarmsystem.gui.table.AlarmTableModel.AlarmTableColumn)

Example 4 with DefaultListSelectionModel

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());
}
Also used : InfoRenderer(alma.acs.logging.table.renderer.InfoRenderer) TableColumnModel(javax.swing.table.TableColumnModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) DateRenderer(alma.acs.logging.table.renderer.DateRenderer) EntryTypeRenderer(alma.acs.logging.table.renderer.EntryTypeRenderer) TableColumn(javax.swing.table.TableColumn)

Example 5 with DefaultListSelectionModel

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);
    }
}
Also used : Rectangle(java.awt.Rectangle) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ListSelectionModel(javax.swing.ListSelectionModel)

Aggregations

DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)10 ListSelectionModel (javax.swing.ListSelectionModel)4 ArrayList (java.util.ArrayList)2 TableColumnModel (javax.swing.table.TableColumnModel)2 CategoryTableModel (pcgen.gui2.tabs.ability.CategoryTableModel)2 DateRenderer (alma.acs.logging.table.renderer.DateRenderer)1 EntryTypeRenderer (alma.acs.logging.table.renderer.EntryTypeRenderer)1 InfoRenderer (alma.acs.logging.table.renderer.InfoRenderer)1 AlarmTableColumn (alma.acsplugins.alarmsystem.gui.table.AlarmTableModel.AlarmTableColumn)1 UndocAlarmTableModel (alma.acsplugins.alarmsystem.gui.undocumented.table.UndocAlarmTableModel)1 FontMetrics (java.awt.FontMetrics)1 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 BufferedImage (java.awt.image.BufferedImage)1 BitSet (java.util.BitSet)1 Hashtable (java.util.Hashtable)1 DefaultListModel (javax.swing.DefaultListModel)1 RowSorter (javax.swing.RowSorter)1 ToolTipManager (javax.swing.ToolTipManager)1