bugged
stringlengths
6
599k
fixed
stringlengths
10
599k
__index_level_0__
int64
0
1.13M
public Object action (SaxDocumentHandler handler, AttributeList attrs) { // create new object appropriately Field newfield = new Field(); newfield.setXMLAttributes(attrs); // set XML attributes from passed list // grab the field axis and add the field FieldAxis fieldAxis = CurrentArray.getFieldAxis(); fieldAxis.addField(newfield); String fieldId = newfield.getFieldId(); String fieldIdRef = newfield.getFieldIdRef(); // add this object to the lookup table, if it has an ID if (fieldId != null) { // a warning check, just in case if (FieldObj.containsKey(fieldId)) Log.warnln("More than one field node with fieldId=\""+fieldId+"\", using latest node." ); // add this into the list of field objects FieldObj.put(fieldId, newfield); } // If there is a reference object, clone it to get // the new field if (fieldIdRef != null) { if (FieldObj.containsKey(fieldIdRef)) { BaseObject refFieldObj = (BaseObject) FieldObj.get(fieldIdRef); try { newfield = (Field) refFieldObj.clone(); } catch (java.lang.CloneNotSupportedException e) { Log.errorln("Weird error, cannot clone field object. Aborting read."); System.exit(-1); } // override attrs with those in passed list newfield.setXMLAttributes(attrs); newfield.setFieldId(null); // shouldnt have fieldId from the refObj } else { Log.warnln("Error: Reader got an field with FieldIdRef=\""+fieldIdRef+"\" but no previous field has that id! Ignoring add field request."); return (Object) null; } } // add this object to all open field groups Iterator iter = CurrentFieldGroupList.iterator(); while (iter.hasNext()) { FieldGroup nextFieldGroupObj = (FieldGroup) iter.next(); newfield.addToGroup(nextFieldGroupObj); } CurrentDatatypeObject = newfield; LastFieldObject = newfield; return newfield; }
public Object action (SaxDocumentHandler handler, AttributeList attrs) { // create new object appropriately Field newfield = new Field(); newfield.setXMLAttributes(attrs); // set XML attributes from passed list // grab the field axis and add the field FieldAxis fieldAxis = CurrentArray.getFieldAxis(); fieldAxis.addField(newfield); String fieldId = newfield.getFieldId(); String fieldIdRef = newfield.getFieldIdRef(); // add this object to the lookup table, if it has an ID if (fieldId != null) { // a warning check, just in case if (FieldObj.containsKey(fieldId)) Log.warnln("More than one field node with fieldId=\""+fieldId+"\", using latest node." ); // add this into the list of field objects FieldObj.put(fieldId, newfield); } // If there is a reference object, clone it to get // the new field if (fieldIdRef != null) { if (FieldObj.containsKey(fieldIdRef)) { BaseObject refFieldObj = (BaseObject) FieldObj.get(fieldIdRef); try { newfield = (Field) refFieldObj.clone(); } catch (java.lang.CloneNotSupportedException e) { Log.errorln("Weird error, cannot clone field object. Aborting read."); System.exit(-1); } // override attrs with those in passed list newfield.setXMLAttributes(attrs); newfield.setFieldId(findUniqueIdName(FieldObj, newfield.getFieldId())); FieldObj.put(newfield.getFieldId(), newfield); // shouldnt have fieldId from the refObj } else { Log.warnln("Error: Reader got an field with FieldIdRef=\""+fieldIdRef+"\" but no previous field has that id! Ignoring add field request."); return (Object) null; } } // add this object to all open field groups Iterator iter = CurrentFieldGroupList.iterator(); while (iter.hasNext()) { FieldGroup nextFieldGroupObj = (FieldGroup) iter.next(); newfield.addToGroup(nextFieldGroupObj); } CurrentDatatypeObject = newfield; LastFieldObject = newfield; return newfield; }
1,812
public Object action (SaxDocumentHandler handler, AttributeList attrs) { String parentNodeName = getParentNodeName(); // create new object appropriately Note newnote = new Note(); newnote.setXMLAttributes(attrs); // set XML attributes from passed list String noteId = newnote.getNoteId(); String noteIdRef = newnote.getNoteIdRef(); // add this object to the lookup table, if it has an ID if (noteId != null) { // a warning check, just in case if (NoteObj.containsKey(noteId)) Log.warnln("More than one note node with noteId=\""+noteId+"\", using latest node." ); // add this into the list of note objects NoteObj.put(noteId, newnote); } // If there is a reference object, clone it to get // the new axis if (noteIdRef != null) { if (NoteObj.containsKey(noteIdRef)) { BaseObject refNoteObj = (BaseObject) NoteObj.get(noteIdRef); try { newnote = (Note) refNoteObj.clone(); } catch (java.lang.CloneNotSupportedException e) { Log.errorln("Weird error, cannot clone note object. Aborting read."); System.exit(-1); } // override attrs with those in passed list newnote.setXMLAttributes(attrs); newnote.setNoteId(null); // note shouldnt have noteId from the parent } else { Log.warnln("Error: Reader got a note with NoteIdRef=\""+noteIdRef+"\" but no previous note has that id! Ignoring add note request."); return (Object) null; } } // add this object to parent object if( parentNodeName.equals(XDFNodeName.NOTES) ) { // only NOTES objects appear in arrays, so we can // just add to the current array CurrentArray.addNote(newnote); } else if ( parentNodeName.equals(XDFNodeName.FIELD) ) { LastFieldObject.addNote(newnote); } else if ( parentNodeName.equals(XDFNodeName.PARAMETER) ) { LastParameterObject.addNote(newnote); } else { Log.warnln( "Unknown parent node: "+parentNodeName+" for note. Ignoring."); } LastNoteObject = newnote; return newnote; }
public Object action (SaxDocumentHandler handler, AttributeList attrs) { String parentNodeName = getParentNodeName(); // create new object appropriately Note newnote = new Note(); newnote.setXMLAttributes(attrs); // set XML attributes from passed list String noteId = newnote.getNoteId(); String noteIdRef = newnote.getNoteIdRef(); // add this object to the lookup table, if it has an ID if (noteId != null) { // a warning check, just in case if (NoteObj.containsKey(noteId)) Log.warnln("More than one note node with noteId=\""+noteId+"\", using latest node." ); // add this into the list of note objects NoteObj.put(noteId, newnote); } // If there is a reference object, clone it to get // the new axis if (noteIdRef != null) { if (NoteObj.containsKey(noteIdRef)) { BaseObject refNoteObj = (BaseObject) NoteObj.get(noteIdRef); try { newnote = (Note) refNoteObj.clone(); } catch (java.lang.CloneNotSupportedException e) { Log.errorln("Weird error, cannot clone note object. Aborting read."); System.exit(-1); } // override attrs with those in passed list newnote.setXMLAttributes(attrs); newnote.setNoteId(findUniqueIdName(NoteObj, newnote.getNoteId())); NoteObj.put(newnote.getNoteId(), newnote); // note shouldnt have noteId from the parent } else { Log.warnln("Error: Reader got a note with NoteIdRef=\""+noteIdRef+"\" but no previous note has that id! Ignoring add note request."); return (Object) null; } } // add this object to parent object if( parentNodeName.equals(XDFNodeName.NOTES) ) { // only NOTES objects appear in arrays, so we can // just add to the current array CurrentArray.addNote(newnote); } else if ( parentNodeName.equals(XDFNodeName.FIELD) ) { LastFieldObject.addNote(newnote); } else if ( parentNodeName.equals(XDFNodeName.PARAMETER) ) { LastParameterObject.addNote(newnote); } else { Log.warnln( "Unknown parent node: "+parentNodeName+" for note. Ignoring."); } LastNoteObject = newnote; return newnote; }
1,813
public Object action (SaxDocumentHandler handler, AttributeList attrs) { // if this is still defined, we havent init'd an // XMLDataIOStyle object for this array yet, do it now. if ( !(DataIOStyleAttribs.isEmpty()) ) { FormattedXMLDataIOStyle readObj = new FormattedXMLDataIOStyle (CurrentArray, DataIOStyleAttribs); // readObj.setXMLAttributes(DataIOStyleAttribs); CurrentArray.setXMLDataIOStyle(readObj); DataIOStyleAttribs = new Hashtable(); // clear table CurrentFormatObjectList.add(readObj); } // okey, now that that is taken care off, we will go // get the current format (read) object, and add the readCell // command to it. Object formatObj = (Object) CurrentFormatObjectList.get(CurrentFormatObjectList.size()-1); ReadCellFormattedIOCmd readCellObj = new ReadCellFormattedIOCmd(); readCellObj.setXMLAttributes(attrs); if (formatObj instanceof FormattedXMLDataIOStyle) { return ((FormattedXMLDataIOStyle) formatObj).addFormatCommand(readCellObj); } else if ( formatObj instanceof RepeatFormattedIOCmd ) { return ((RepeatFormattedIOCmd) formatObj).addFormatCommand(readCellObj); } else { Log.warnln("Warning: cant add ReadCellFormattedIOCmd object to parent, ignoring request "); } return (Object) null; }
public Object action (SaxDocumentHandler handler, AttributeList attrs) { // if this is still defined, we havent init'd an // XMLDataIOStyle object for this array yet, do it now. if ( !(DataIOStyleAttribs.isEmpty()) ) { FormattedXMLDataIOStyle readObj = new FormattedXMLDataIOStyle (CurrentArray, DataIOStyleAttribs); String readId = readObj.getReadId(); String readIdRef = readObj.getReadIdRef(); if (readId != null) { if (ReadObj.containsKey(readId)) Log.warnln("More than one read node with readId=\""+readId+"\", using latest node." ); ReadObj.put(readId, readObj); } if (readIdRef != null) { if (ReadObj.containsKey(readIdRef)) { BaseObject refReadObj = (BaseObject) ReadObj.get(readIdRef); try { readObj = (FormattedXMLDataIOStyle) refReadObj.clone(); } catch (java.lang.CloneNotSupportedException e) { Log.errorln("Weird error, cannot clone FormattedXMLDataIOStyle (read node) object. Aborting read."); System.exit(-1); } readObj.hashtableInitXDFAttributes(DataIOStyleAttribs); readObj.setReadId(findUniqueIdName(ReadObj, readObj.getReadId())); ReadObj.put(readObj.getReadId(), readObj); } else { Log.warnln("Error: Reader got a read node with ReadIdRef=\""+readIdRef+"\" but no previous read node has that id! Ignoring add request."); return (Object) null; } } // readObj.setXMLAttributes(DataIOStyleAttribs); CurrentArray.setXMLDataIOStyle(readObj); DataIOStyleAttribs = new Hashtable(); // clear table CurrentFormatObjectList.add(readObj); } // okey, now that that is taken care off, we will go // get the current format (read) object, and add the readCell // command to it. Object formatObj = (Object) CurrentFormatObjectList.get(CurrentFormatObjectList.size()-1); ReadCellFormattedIOCmd readCellObj = new ReadCellFormattedIOCmd(); readCellObj.setXMLAttributes(attrs); if (formatObj instanceof FormattedXMLDataIOStyle) { return ((FormattedXMLDataIOStyle) formatObj).addFormatCommand(readCellObj); } else if ( formatObj instanceof RepeatFormattedIOCmd ) { return ((RepeatFormattedIOCmd) formatObj).addFormatCommand(readCellObj); } else { Log.warnln("Warning: cant add ReadCellFormattedIOCmd object to parent, ignoring request "); } return (Object) null; }
1,814
private void addDataToCurrentArray ( Locator dataLocator, String thisString, DataFormat CurrentDataFormat ) {AxisInterface FastAxis = (AxisInterface) CurrentArray.getAxisList().get(0);AxisInterface SlowAxis = (AxisInterface) CurrentArray.getAxisList().get(1); // Note that we dont treat binary data at all try { Log.errorln("setData:["+thisString+"]["+dataLocator.getAxisLocation(FastAxis)+","+dataLocator.getAxisLocation(SlowAxis)+"]"); if ( CurrentDataFormat instanceof StringDataFormat) { CurrentArray.setData(dataLocator, thisString); } else if ( CurrentDataFormat instanceof FixedDataFormat) { Double number = new Double (thisString); CurrentArray.setData(dataLocator, number.doubleValue()); } else if ( CurrentDataFormat instanceof IntegerDataFormat) { Integer number = new Integer (thisString); CurrentArray.setData(dataLocator, number.intValue()); } else if ( CurrentDataFormat instanceof ExponentialDataFormat) { // hurm.. this is a stop-gap. Exponential format needs to be // preserved better than this. -b.t. Double number = new Double (thisString); CurrentArray.setData(dataLocator, number.doubleValue()); } else { Log.warnln("The dataFormat:"+CurrentDataFormat.toString()+" is not allowed in tagged data."); Log.warnln("Unable to setData:["+thisString+"], ignoring request"); } } catch (SetDataException e) { // bizarre error. Cant add data (out of memory??) :P Log.errorln("Unable to setData:["+thisString+"], ignoring request"); Log.printStackTrace(e); } }
private void addDataToCurrentArray ( Locator dataLocator, String thisString, DataFormat CurrentDataFormat ) {AxisInterface FastAxis = (AxisInterface) CurrentArray.getAxisList().get(0);AxisInterface SlowAxis = (AxisInterface) CurrentArray.getAxisList().get(1); // Note that we dont treat binary data at all try { Log.errorln("setData:["+thisString+"]["+dataLocator.getAxisLocation(FastAxis)+","+dataLocator.getAxisLocation(SlowAxis)+"]"); if ( CurrentDataFormat instanceof StringDataFormat) { CurrentArray.setData(dataLocator, thisString); } else if ( CurrentDataFormat instanceof FixedDataFormat) { Double number = new Double (thisString); CurrentArray.setData(dataLocator, number.doubleValue()); } else if ( CurrentDataFormat instanceof IntegerDataFormat) { Integer number = new Integer (thisString); CurrentArray.setData(dataLocator, number.intValue()); } else if ( CurrentDataFormat instanceof ExponentialDataFormat) { // hurm.. this is a stop-gap. Exponential format needs to be // preserved better than this. -b.t. Double number = new Double (thisString); CurrentArray.setData(dataLocator, number.doubleValue()); } else { Log.warnln("The dataFormat:"+CurrentDataFormat.toString()+" is not allowed in tagged data."); Log.warnln("Unable to setData:["+thisString+"], ignoring request"); } } catch (SetDataException e) { // bizarre error. Cant add data (out of memory??) :P Log.errorln("Unable to setData:["+thisString+"], ignoring request"); Log.printStackTrace(e); } }
1,815
private void addDataToCurrentArray ( Locator dataLocator, String thisString, DataFormat CurrentDataFormat ) {AxisInterface FastAxis = (AxisInterface) CurrentArray.getAxisList().get(0);AxisInterface SlowAxis = (AxisInterface) CurrentArray.getAxisList().get(1); // Note that we dont treat binary data at all try { Log.errorln("setData:["+thisString+"]["+dataLocator.getAxisLocation(FastAxis)+","+dataLocator.getAxisLocation(SlowAxis)+"]"); if ( CurrentDataFormat instanceof StringDataFormat) { CurrentArray.setData(dataLocator, thisString); } else if ( CurrentDataFormat instanceof FixedDataFormat) { Double number = new Double (thisString); CurrentArray.setData(dataLocator, number.doubleValue()); } else if ( CurrentDataFormat instanceof IntegerDataFormat) { Integer number = new Integer (thisString); CurrentArray.setData(dataLocator, number.intValue()); } else if ( CurrentDataFormat instanceof ExponentialDataFormat) { // hurm.. this is a stop-gap. Exponential format needs to be // preserved better than this. -b.t. Double number = new Double (thisString); CurrentArray.setData(dataLocator, number.doubleValue()); } else { Log.warnln("The dataFormat:"+CurrentDataFormat.toString()+" is not allowed in tagged data."); Log.warnln("Unable to setData:["+thisString+"], ignoring request"); } } catch (SetDataException e) { // bizarre error. Cant add data (out of memory??) :P Log.errorln("Unable to setData:["+thisString+"], ignoring request"); Log.printStackTrace(e); } }
private void addDataToCurrentArray ( Locator dataLocator, String thisString, DataFormat CurrentDataFormat ) {AxisInterface FastAxis = (AxisInterface) CurrentArray.getAxisList().get(0);AxisInterface SlowAxis = (AxisInterface) CurrentArray.getAxisList().get(1); // Note that we dont treat binary data at all try { if ( CurrentDataFormat instanceof StringDataFormat) { CurrentArray.setData(dataLocator, thisString); } else if ( CurrentDataFormat instanceof FixedDataFormat) { Double number = new Double (thisString); CurrentArray.setData(dataLocator, number.doubleValue()); } else if ( CurrentDataFormat instanceof IntegerDataFormat) { Integer number = new Integer (thisString); CurrentArray.setData(dataLocator, number.intValue()); } else if ( CurrentDataFormat instanceof ExponentialDataFormat) { // hurm.. this is a stop-gap. Exponential format needs to be // preserved better than this. -b.t. Double number = new Double (thisString); CurrentArray.setData(dataLocator, number.doubleValue()); } else { Log.warnln("The dataFormat:"+CurrentDataFormat.toString()+" is not allowed in tagged data."); Log.warnln("Unable to setData:["+thisString+"], ignoring request"); } } catch (SetDataException e) { // bizarre error. Cant add data (out of memory??) :P Log.errorln("Unable to setData:["+thisString+"], ignoring request"); Log.printStackTrace(e); } }
1,816
private ArrayList formattedSplitStringIntoStringObjects ( String data , FormattedXMLDataIOStyle readObj ) { ArrayList stringObjList = new ArrayList(); List commandList = readObj.getCommands(); DataFormat dataFormat[] = CurrentArray.getDataFormatList(); int dataPosition = 0; int dataLength = data.length(); int currentDataFormat = 0; int nrofDataFormat = dataFormat.length; Log.debugln("in formattedSplitString, data :["+data+"]"); // the extraction loop // whip thru the data string, either ignoring or accepting // characters in the string as directed by the formatCmdList while (dataPosition < dataLength) { Iterator formatIter = commandList.iterator(); while (formatIter.hasNext()) { FormattedIOCmd thisCommand = (FormattedIOCmd) formatIter.next(); if (thisCommand instanceof ReadCellFormattedIOCmd) // ReadCell ==> read some data { DataFormat formatObj = dataFormat[currentDataFormat]; int endDataPosition = dataPosition + formatObj.numOfBytes(); // add in our object String thisData = data.substring(dataPosition,endDataPosition); // remove leading whitespace from what will be non-string data. if (Character.isWhitespace(thisData.charAt(0)) && !(formatObj instanceof StringDataFormat)) thisData = trimLeadingWhitespace(thisData); Log.debugln("Got Data:["+thisData+"] ("+dataPosition+","+endDataPosition+")"); stringObjList.add(thisData); dataPosition = endDataPosition; // advance our pointer to the current DataFormat if (nrofDataFormat > 1) if (currentDataFormat == (nrofDataFormat - 1)) currentDataFormat = 0; else currentDataFormat++; } else if (thisCommand instanceof SkipCharFormattedIOCmd) // SkipChar ==> just adv. dataPointer { dataPosition += ((SkipCharFormattedIOCmd) thisCommand).getCount().intValue(); } else { Log.errorln("Unknown FormattedIOCmd, aborting formatted read."); // needed check ? break; } } } return stringObjList; }
private ArrayList formattedSplitStringIntoStringObjects ( String data , FormattedXMLDataIOStyle readObj ) { ArrayList stringObjList = new ArrayList(); List commandList = readObj.getCommands(); DataFormat dataFormat[] = CurrentArray.getDataFormatList(); int dataPosition = 0; int dataLength = data.length(); int currentDataFormat = 0; int nrofDataFormat = dataFormat.length; Log.debugln("in formattedSplitString, data :["+data+"]"); // the extraction loop // whip thru the data string, either ignoring or accepting // characters in the string as directed by the formatCmdList while (dataPosition < dataLength) { Iterator formatIter = commandList.iterator(); while (formatIter.hasNext()) { FormattedIOCmd thisCommand = (FormattedIOCmd) formatIter.next(); if (thisCommand instanceof ReadCellFormattedIOCmd) // ReadCell ==> read some data { DataFormat formatObj = dataFormat[currentDataFormat]; int endDataPosition = dataPosition + formatObj.numOfBytes(); // add in our object String thisData = data.substring(dataPosition,endDataPosition); // remove leading whitespace from what will be non-string data. if (Character.isWhitespace(thisData.charAt(0)) && !(formatObj instanceof StringDataFormat)) thisData = trimLeadingWhitespace(thisData); Log.debugln("Got Formatted DataCell:["+thisData+"]"); stringObjList.add(thisData); dataPosition = endDataPosition; // advance our pointer to the current DataFormat if (nrofDataFormat > 1) if (currentDataFormat == (nrofDataFormat - 1)) currentDataFormat = 0; else currentDataFormat++; } else if (thisCommand instanceof SkipCharFormattedIOCmd) // SkipChar ==> just adv. dataPointer { dataPosition += ((SkipCharFormattedIOCmd) thisCommand).getCount().intValue(); } else { Log.errorln("Unknown FormattedIOCmd, aborting formatted read."); // needed check ? break; } } } return stringObjList; }
1,817
public void remove(Component component) { super.remove(component); }
public void remove(Component component) { int index = indexOfComponent(component); if (index == -1) { Component[] cs = getComponents(); for (int i = 0; i< cs.length; i++) if (cs[i] == component) super.remove(i); } else removeTabAt(index); }
1,818
public void setModel(SingleSelectionModel model) { if (model != this.model) { SingleSelectionModel oldModel = this.model; this.model.removeChangeListener(changeListener); this.model = model; this.model.addChangeListener(changeListener); firePropertyChange("model", oldModel, this.model); } }
public void setModel(SingleSelectionModel m) { if (model != this.model) { SingleSelectionModel oldModel = this.model; this.model.removeChangeListener(changeListener); this.model = model; this.model.addChangeListener(changeListener); firePropertyChange("model", oldModel, this.model); } }
1,819
public void setModel(SingleSelectionModel model) { if (model != this.model) { SingleSelectionModel oldModel = this.model; this.model.removeChangeListener(changeListener); this.model = model; this.model.addChangeListener(changeListener); firePropertyChange("model", oldModel, this.model); } }
public void setModel(SingleSelectionModel model) { if (m != model) { SingleSelectionModel oldModel = this.model; this.model.removeChangeListener(changeListener); this.model = model; this.model.addChangeListener(changeListener); firePropertyChange("model", oldModel, this.model); } }
1,820
public void setModel(SingleSelectionModel model) { if (model != this.model) { SingleSelectionModel oldModel = this.model; this.model.removeChangeListener(changeListener); this.model = model; this.model.addChangeListener(changeListener); firePropertyChange("model", oldModel, this.model); } }
public void setModel(SingleSelectionModel model) { if (model != this.model) { SingleSelectionModel oldModel = this.model; this.model.removeChangeListener(changeListener); this.model = model; this.model.addChangeListener(changeListener); firePropertyChange("model", oldModel, this.model); } }
1,821
protected void decodeLineStyle(Object lineStyleFlag) throws NotImplementedException { // FIXME: not implemented }
protected void decodeLineStyle(Object lineStyleFlag) { // FIXME: not implemented }
1,822
protected void paintHorizontalSeparators(Graphics g, JComponent c) throws NotImplementedException { // FIXME: not implemented }
protected void paintHorizontalSeparators(Graphics g, JComponent c) { // FIXME: not implemented }
1,827
protected void initKeys(Keys keys) { keys.setKey(1, new Key(KeyEvent.VK_ESCAPE)); keys.setKey(2, new Key('1', KeyEvent.VK_1, '!', KeyEvent.VK_EXCLAMATION_MARK)); keys.setKey(3, new Key('2', KeyEvent.VK_2, '@', KeyEvent.VK_AT)); keys.setKey(4, new Key('3', KeyEvent.VK_3, '#', KeyEvent.VK_NUMBER_SIGN, '', KeyEvent.VK_3)); keys.setKey(5, new Key('4', KeyEvent.VK_4, '$', KeyEvent.VK_DOLLAR)); keys.setKey(6, new Key('5', '%', KeyEvent.VK_5)); keys.setKey(7, new Key('6', '^', KeyEvent.VK_6)); keys.setKey(8, new Key('7', '&', KeyEvent.VK_7)); keys.setKey(9, new Key('8', KeyEvent.VK_8, '*', KeyEvent.VK_MULTIPLY)); keys.setKey(10, new Key('9', KeyEvent.VK_9, '(', KeyEvent.VK_LEFT_PARENTHESIS)); keys.setKey(11, new Key('0', KeyEvent.VK_0, ')', KeyEvent.VK_RIGHT_PARENTHESIS)); keys.setKey(12, new Key('[', KeyEvent.VK_OPEN_BRACKET, '{', KeyEvent.VK_BRACELEFT)); keys.setKey(13, new Key(']', KeyEvent.VK_CLOSE_BRACKET, '}', KeyEvent.VK_BRACERIGHT)); keys.setKey(14, new Key('\b', KeyEvent.VK_BACK_SPACE)); keys.setKey(15, new Key('\t', KeyEvent.VK_TAB)); keys.setKey(16, new Key('\'',KeyEvent.VK_QUOTE, '\"', KeyEvent.VK_QUOTEDBL)); keys.setKey(17, new Key(',',KeyEvent.VK_COMMA, '<', KeyEvent.VK_LESS)); keys.setKey(18, new Key('.',KeyEvent.VK_PERIOD, '>', KeyEvent.VK_GREATER)); keys.setKey(19, new Key('p', 'P', KeyEvent.VK_P)); keys.setKey(20, new Key('y', 'Y', KeyEvent.VK_Y)); keys.setKey(21, new Key('f', 'F', KeyEvent.VK_F)); keys.setKey(22, new Key('g', 'G', KeyEvent.VK_G)); keys.setKey(23, new Key('c', 'C', KeyEvent.VK_C)); keys.setKey(24, new Key('r', 'R', KeyEvent.VK_R)); keys.setKey(25, new Key('l', 'L', KeyEvent.VK_L)); keys.setKey(26, new Key('/', '?',KeyEvent.VK_SLASH)); keys.setKey(27, new Key('=', KeyEvent.VK_EQUALS, '+', KeyEvent.VK_PLUS)); keys.setKey(28, new Key('\n', KeyEvent.VK_ENTER)); keys.setKey(29, new Key((char) 0, KeyEvent.VK_CONTROL)); keys.setKey(30, new Key('a', 'A', KeyEvent.VK_A)); keys.setKey(31, new Key('o', 'O', KeyEvent.VK_O)); keys.setKey(32, new Key('e', 'E', KeyEvent.VK_E)); keys.setKey(33, new Key('u', 'U', KeyEvent.VK_U)); keys.setKey(34, new Key('i', 'I', KeyEvent.VK_I)); keys.setKey(35, new Key('d', 'D', KeyEvent.VK_D)); keys.setKey(36, new Key('h', 'H', KeyEvent.VK_H)); keys.setKey(37, new Key('t', 'T', KeyEvent.VK_T)); keys.setKey(38, new Key('n', 'N', KeyEvent.VK_N)); keys.setKey(39, new Key('s', 'S',KeyEvent.VK_S));//KeyEvent.VK_SEMICOLON, ':', KeyEvent.VK_COLON)); keys.setKey(40, new Key("-".charAt(0), KeyEvent.VK_MINUS, '_', KeyEvent.VK_UNDERSCORE)); keys.setKey(41, new Key('`', '~', KeyEvent.VK_BACK_QUOTE)); keys.setKey(43, new Key('\\', '|', KeyEvent.VK_BACK_SLASH)); keys.setKey(44, new Key(';', KeyEvent.VK_SEMICOLON,':', KeyEvent.VK_COLON)); keys.setKey(45, new Key('q', 'Q', KeyEvent.VK_Q)); keys.setKey(46, new Key('j', 'J', KeyEvent.VK_J)); keys.setKey(47, new Key('k', 'K', KeyEvent.VK_K)); keys.setKey(48, new Key('x', 'X', KeyEvent.VK_X)); keys.setKey(49, new Key('b', 'B', KeyEvent.VK_B)); keys.setKey(50, new Key('m', 'M', KeyEvent.VK_M)); keys.setKey(51, new Key('w', 'M',KeyEvent.VK_M));//KeyEvent.VK_COMMA, '<', KeyEvent.VK_LESS)); keys.setKey(52, new Key('v', 'V',KeyEvent.VK_V));//KeyEvent.VK_PERIOD, '>', KeyEvent.VK_GREATER)); keys.setKey(53, new Key('z', 'Z', KeyEvent.VK_Z)); keys.setKey(55, new Key('*', KeyEvent.VK_MULTIPLY)); keys.setKey(57, new Key(' ', KeyEvent.VK_SPACE)); keys.setKey(71, new Key('7', KeyEvent.VK_NUMPAD7)); keys.setKey(72, new Key('8', KeyEvent.VK_NUMPAD8)); keys.setKey(73, new Key('9', KeyEvent.VK_NUMPAD9)); keys.setKey(74, new Key('-', KeyEvent.VK_SUBTRACT)); keys.setKey(75, new Key('4', KeyEvent.VK_NUMPAD4)); keys.setKey(76, new Key('5', KeyEvent.VK_NUMPAD5)); keys.setKey(77, new Key('6', KeyEvent.VK_NUMPAD6)); keys.setKey(78, new Key('+', KeyEvent.VK_ADD)); keys.setKey(79, new Key('1', KeyEvent.VK_NUMPAD1)); keys.setKey(80, new Key('2', KeyEvent.VK_NUMPAD2)); keys.setKey(81, new Key('3', KeyEvent.VK_NUMPAD3)); keys.setKey(82, new Key('0', KeyEvent.VK_NUMPAD0)); keys.setKey(83, new Key('.', KeyEvent.VK_DECIMAL)); keys.setKey(86, new Key('/', KeyEvent.VK_SLASH)); keys.setKey(42, new Key(KeyEvent.VK_SHIFT)); keys.setKey(54, new Key(KeyEvent.VK_SHIFT)); keys.setKey(56, new Key(KeyEvent.VK_ALT)); keys.setKey(58, new Key(KeyEvent.VK_CAPS_LOCK)); keys.setKey(59, new Key(KeyEvent.VK_F1)); keys.setKey(60, new Key(KeyEvent.VK_F2)); keys.setKey(61, new Key(KeyEvent.VK_F3)); keys.setKey(62, new Key(KeyEvent.VK_F4)); keys.setKey(63, new Key(KeyEvent.VK_F5)); keys.setKey(64, new Key(KeyEvent.VK_F6)); keys.setKey(65, new Key(KeyEvent.VK_F7)); keys.setKey(66, new Key(KeyEvent.VK_F8)); keys.setKey(67, new Key(KeyEvent.VK_F9)); keys.setKey(68, new Key(KeyEvent.VK_F10)); keys.setKey(69, new Key(KeyEvent.VK_NUM_LOCK)); keys.setKey(70, new Key(KeyEvent.VK_SCROLL_LOCK)); keys.setKey(87, new Key(KeyEvent.VK_F11)); keys.setKey(88, new Key(KeyEvent.VK_F12)); keys.setKey(96, new Key(KeyEvent.VK_INSERT)); keys.setKey(97, new Key(KeyEvent.VK_HOME)); keys.setKey(98, new Key(KeyEvent.VK_PAGE_UP)); keys.setKey(99, new Key(KeyEvent.VK_DIVIDE)); keys.setKey(100, new Key(KeyEvent.VK_PRINTSCREEN)); keys.setKey(101, new Key(KeyEvent.VK_DELETE)); keys.setKey(102, new Key(KeyEvent.VK_END)); keys.setKey(103, new Key(KeyEvent.VK_PAGE_DOWN)); keys.setKey(104, new Key(KeyEvent.VK_UP)); keys.setKey(105, new Key(KeyEvent.VK_SEPARATOR)); keys.setKey(110, new Key(KeyEvent.VK_ESCAPE)); keys.setKey(111, new Key(KeyEvent.VK_FINAL)); keys.setKey(112, new Key(KeyEvent.VK_CONTROL)); keys.setKey(113, new Key(KeyEvent.VK_LEFT)); keys.setKey(114, new Key(KeyEvent.VK_DOWN)); keys.setKey(115, new Key(KeyEvent.VK_RIGHT)); keys.setKey(116, new Key(KeyEvent.VK_PAUSE)); }
protected void initKeys(Keys keys) { keys.setKey(1, new Key(KeyEvent.VK_ESCAPE)); keys.setKey(2, new Key('1', KeyEvent.VK_1, '!', KeyEvent.VK_EXCLAMATION_MARK)); keys.setKey(3, new Key('2', KeyEvent.VK_2, '@', KeyEvent.VK_AT)); keys.setKey(4, new Key('3', KeyEvent.VK_3, '#', KeyEvent.VK_NUMBER_SIGN, '', KeyEvent.VK_3)); keys.setKey(5, new Key('4', KeyEvent.VK_4, '$', KeyEvent.VK_DOLLAR)); keys.setKey(6, new Key('5', '%', KeyEvent.VK_5)); keys.setKey(7, new Key('6', '^', KeyEvent.VK_6)); keys.setKey(8, new Key('7', '&', KeyEvent.VK_7)); keys.setKey(9, new Key('8', KeyEvent.VK_8, '*', KeyEvent.VK_MULTIPLY)); keys.setKey(10, new Key('9', KeyEvent.VK_9, '(', KeyEvent.VK_LEFT_PARENTHESIS)); keys.setKey(11, new Key('0', KeyEvent.VK_0, ')', KeyEvent.VK_RIGHT_PARENTHESIS)); keys.setKey(12, new Key('[', KeyEvent.VK_OPEN_BRACKET, '{', KeyEvent.VK_BRACELEFT)); keys.setKey(13, new Key(']', KeyEvent.VK_CLOSE_BRACKET, '}', KeyEvent.VK_BRACERIGHT)); keys.setKey(14, new Key('\b', KeyEvent.VK_BACK_SPACE)); keys.setKey(15, new Key('\t', KeyEvent.VK_TAB)); keys.setKey(16, new Key('\'',KeyEvent.VK_QUOTE, '\"', KeyEvent.VK_QUOTEDBL)); keys.setKey(17, new Key(',',KeyEvent.VK_COMMA, '<', KeyEvent.VK_LESS)); keys.setKey(18, new Key('.',KeyEvent.VK_PERIOD, '>', KeyEvent.VK_GREATER)); keys.setKey(19, new Key('p', 'P', KeyEvent.VK_P)); keys.setKey(20, new Key('y', 'Y', KeyEvent.VK_Y)); keys.setKey(21, new Key('f', 'F', KeyEvent.VK_F)); keys.setKey(22, new Key('g', 'G', KeyEvent.VK_G)); keys.setKey(23, new Key('c', 'C', KeyEvent.VK_C)); keys.setKey(24, new Key('r', 'R', KeyEvent.VK_R)); keys.setKey(25, new Key('l', 'L', KeyEvent.VK_L)); keys.setKey(26, new Key('/', '?',KeyEvent.VK_SLASH)); keys.setKey(27, new Key('=', KeyEvent.VK_EQUALS, '+', KeyEvent.VK_PLUS)); keys.setKey(28, new Key('\n', KeyEvent.VK_ENTER)); keys.setKey(29, new Key((char) 0, KeyEvent.VK_CONTROL)); keys.setKey(30, new Key('a', 'A', KeyEvent.VK_A)); keys.setKey(31, new Key('o', 'O', KeyEvent.VK_O)); keys.setKey(32, new Key('e', 'E', KeyEvent.VK_E)); keys.setKey(33, new Key('u', 'U', KeyEvent.VK_U)); keys.setKey(34, new Key('i', 'I', KeyEvent.VK_I)); keys.setKey(35, new Key('d', 'D', KeyEvent.VK_D)); keys.setKey(36, new Key('h', 'H', KeyEvent.VK_H)); keys.setKey(37, new Key('t', 'T', KeyEvent.VK_T)); keys.setKey(38, new Key('n', 'N', KeyEvent.VK_N)); keys.setKey(39, new Key('s', 'S',KeyEvent.VK_S));//KeyEvent.VK_SEMICOLON, ':', KeyEvent.VK_COLON)); keys.setKey(40, new Key("-".charAt(0), KeyEvent.VK_MINUS, '_', KeyEvent.VK_UNDERSCORE)); keys.setKey(41, new Key('`', '~', KeyEvent.VK_BACK_QUOTE)); keys.setKey(43, new Key('\\', '|', KeyEvent.VK_BACK_SLASH)); keys.setKey(44, new Key(';', KeyEvent.VK_SEMICOLON,':', KeyEvent.VK_COLON)); keys.setKey(45, new Key('q', 'Q', KeyEvent.VK_Q)); keys.setKey(46, new Key('j', 'J', KeyEvent.VK_J)); keys.setKey(47, new Key('k', 'K', KeyEvent.VK_K)); keys.setKey(48, new Key('x', 'X', KeyEvent.VK_X)); keys.setKey(49, new Key('b', 'B', KeyEvent.VK_B)); keys.setKey(50, new Key('m', 'M', KeyEvent.VK_M)); keys.setKey(51, new Key('w', 'W',KeyEvent.VK_M));//KeyEvent.VK_COMMA, '<', KeyEvent.VK_LESS)); keys.setKey(52, new Key('v', 'V',KeyEvent.VK_V));//KeyEvent.VK_PERIOD, '>', KeyEvent.VK_GREATER)); keys.setKey(53, new Key('z', 'Z', KeyEvent.VK_Z)); keys.setKey(55, new Key('*', KeyEvent.VK_MULTIPLY)); keys.setKey(57, new Key(' ', KeyEvent.VK_SPACE)); keys.setKey(71, new Key('7', KeyEvent.VK_NUMPAD7)); keys.setKey(72, new Key('8', KeyEvent.VK_NUMPAD8)); keys.setKey(73, new Key('9', KeyEvent.VK_NUMPAD9)); keys.setKey(74, new Key('-', KeyEvent.VK_SUBTRACT)); keys.setKey(75, new Key('4', KeyEvent.VK_NUMPAD4)); keys.setKey(76, new Key('5', KeyEvent.VK_NUMPAD5)); keys.setKey(77, new Key('6', KeyEvent.VK_NUMPAD6)); keys.setKey(78, new Key('+', KeyEvent.VK_ADD)); keys.setKey(79, new Key('1', KeyEvent.VK_NUMPAD1)); keys.setKey(80, new Key('2', KeyEvent.VK_NUMPAD2)); keys.setKey(81, new Key('3', KeyEvent.VK_NUMPAD3)); keys.setKey(82, new Key('0', KeyEvent.VK_NUMPAD0)); keys.setKey(83, new Key('.', KeyEvent.VK_DECIMAL)); keys.setKey(86, new Key('/', KeyEvent.VK_SLASH)); keys.setKey(42, new Key(KeyEvent.VK_SHIFT)); keys.setKey(54, new Key(KeyEvent.VK_SHIFT)); keys.setKey(56, new Key(KeyEvent.VK_ALT)); keys.setKey(58, new Key(KeyEvent.VK_CAPS_LOCK)); keys.setKey(59, new Key(KeyEvent.VK_F1)); keys.setKey(60, new Key(KeyEvent.VK_F2)); keys.setKey(61, new Key(KeyEvent.VK_F3)); keys.setKey(62, new Key(KeyEvent.VK_F4)); keys.setKey(63, new Key(KeyEvent.VK_F5)); keys.setKey(64, new Key(KeyEvent.VK_F6)); keys.setKey(65, new Key(KeyEvent.VK_F7)); keys.setKey(66, new Key(KeyEvent.VK_F8)); keys.setKey(67, new Key(KeyEvent.VK_F9)); keys.setKey(68, new Key(KeyEvent.VK_F10)); keys.setKey(69, new Key(KeyEvent.VK_NUM_LOCK)); keys.setKey(70, new Key(KeyEvent.VK_SCROLL_LOCK)); keys.setKey(87, new Key(KeyEvent.VK_F11)); keys.setKey(88, new Key(KeyEvent.VK_F12)); keys.setKey(96, new Key(KeyEvent.VK_INSERT)); keys.setKey(97, new Key(KeyEvent.VK_HOME)); keys.setKey(98, new Key(KeyEvent.VK_PAGE_UP)); keys.setKey(99, new Key(KeyEvent.VK_DIVIDE)); keys.setKey(100, new Key(KeyEvent.VK_PRINTSCREEN)); keys.setKey(101, new Key(KeyEvent.VK_DELETE)); keys.setKey(102, new Key(KeyEvent.VK_END)); keys.setKey(103, new Key(KeyEvent.VK_PAGE_DOWN)); keys.setKey(104, new Key(KeyEvent.VK_UP)); keys.setKey(105, new Key(KeyEvent.VK_SEPARATOR)); keys.setKey(110, new Key(KeyEvent.VK_ESCAPE)); keys.setKey(111, new Key(KeyEvent.VK_FINAL)); keys.setKey(112, new Key(KeyEvent.VK_CONTROL)); keys.setKey(113, new Key(KeyEvent.VK_LEFT)); keys.setKey(114, new Key(KeyEvent.VK_DOWN)); keys.setKey(115, new Key(KeyEvent.VK_RIGHT)); keys.setKey(116, new Key(KeyEvent.VK_PAUSE)); }
1,831
private int loadLib(String filename) { SecurityManager sm = securityManager; // Be thread-safe! if (sm != null) sm.checkLink(filename); return VMRuntime.nativeLoad(filename); }
private static int loadLib(String filename) { SecurityManager sm = securityManager; // Be thread-safe! if (sm != null) sm.checkLink(filename); return VMRuntime.nativeLoad(filename); }
1,832
private int loadLib(String filename) { SecurityManager sm = securityManager; // Be thread-safe! if (sm != null) sm.checkLink(filename); return VMRuntime.nativeLoad(filename); }
private int loadLib(String filename) { SecurityManager sm = securityManager; // Be thread-safe! if (sm != null) sm.checkRead(filename); return VMRuntime.nativeLoad(filename); }
1,833
public String getFormat() { return null; }
public String getFormat() { return Registry.RAW_ENCODING_SHORT_NAME; }
1,834
Inet6Address(byte[] addr, String host) { super(addr, host); this.ipaddress = addr; }
Inet6Address(byte[] addr, String host) { super(addr, host); this.ipaddress = this.addr; }
1,835
public boolean equals(Object obj) { if (! (obj instanceof Inet6Address)) return false; Inet6Address tmp = (Inet6Address) obj; return super.equals(tmp) && this.ipaddress == tmp.ipaddress; }
public boolean equals(Object obj) { if (! (obj instanceof Inet6Address)) return false; Inet6Address tmp = (Inet6Address) obj; return super.equals(tmp) && this.ipaddress == tmp.ipaddress; }
1,836
public byte[] getAddress() { return ipaddress; }
public byte[] getAddress() { return (byte[]) ipaddress.clone(); }
1,837
InetAddress(byte[] ipaddr, String hostname) { addr = new byte[ipaddr.length]; for (int i = 0; i < ipaddr.length; i++) addr[i] = ipaddr[i]; this.hostName = hostname; lookup_time = System.currentTimeMillis(); family = 2; /* AF_INET */ }
InetAddress(byte[] ipaddr, String hostname) { addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone(); hostName = hostname; for (int i = 0; i < ipaddr.length; i++) addr[i] = ipaddr[i]; this.hostName = hostname; lookup_time = System.currentTimeMillis(); family = 2; /* AF_INET */ }
1,838
InetAddress(byte[] ipaddr, String hostname) { addr = new byte[ipaddr.length]; for (int i = 0; i < ipaddr.length; i++) addr[i] = ipaddr[i]; this.hostName = hostname; lookup_time = System.currentTimeMillis(); family = 2; /* AF_INET */ }
InetAddress(byte[] ipaddr, String hostname) { addr = new byte[ipaddr.length]; for (int i = 0; i < ipaddr.length; i++) addr[i] = ipaddr[i]; this.hostName = hostname; lookup_time = System.currentTimeMillis(); family = 2; /* AF_INET */ }
1,839
private void storeObject(int offset, Class<?> cls, Object obj, VmClassType<?> vmType) throws BuildException, ClassNotFoundException, JNodeClassNotFoundException { final Class< ? > sCls = cls.getSuperclass(); if (sCls != null) { final VmClassType< ? > vmSuperType = (VmClassType< ? >) loaderContext .loadClass(sCls.getName(), true); storeObject(offset, sCls, obj, vmSuperType); } try { final FieldInfo fieldInfo = getFieldInfo(cls); // final Field fields[] = cls.getDeclaredFields(); final Field[] fields = fieldInfo.getJdkInstanceFields(); final int len = fields.length; // AccessibleObject.setAccessible(fields, true); for (int i = 0; i < len; i++) { final VmField jnodeField = fieldInfo.getJNodeInstanceField(i); final Field jdkField = fields[i]; final int modifiers = jnodeField.getModifiers(); if ((modifiers & Modifier.STATIC) != 0) { throw new BuildException("Static field in instance list"); } final int fldOffset = offset + ((VmInstanceField) jnodeField).getOffset(); if ((jdkField == null) || ((modifiers & Modifier.TRANSIENT) != 0)) { if (jnodeField.isWide()) { os.set64(fldOffset, 0); } else if (!jnodeField.isPrimitive()) { os.setWord(fldOffset, 0); } else { switch (jnodeField.getTypeSize()) { case 1: os.set8(fldOffset, 0); break; case 2: os.set16(fldOffset, 0); break; case 4: os.set32(fldOffset, 0); break; default: throw new BuildException("Invalid typesize in: " + jnodeField); } } if (debugWriter != null) { debugWriter.println(jnodeField.getName() + " transient: 0"); } } else if (jnodeField.isPrimitive()) { final Class< ? > fType = jdkField.getType(); if (debugWriter != null) { debugWriter.println(jdkField.getName() + " " + jdkField.get(obj)); } if (fType == byte.class) { os.set8(fldOffset, jdkField.getByte(obj)); } else if (fType == boolean.class) { os.set8(fldOffset, (jdkField.getBoolean(obj)) ? 1 : 0); } else if (fType == char.class) { os.set16(fldOffset, jdkField.getChar(obj)); } else if (fType == short.class) { os.set16(fldOffset, jdkField.getShort(obj)); } else if (fType == int.class) { os.set32(fldOffset, jdkField.getInt(obj)); } else if (fType == float.class) { os.set32(fldOffset, Float.floatToIntBits(jdkField .getFloat(obj))); } else if (fType == long.class) { os.set64(fldOffset, jdkField.getLong(obj)); } else if (fType == double.class) { os.set64(fldOffset, Double.doubleToLongBits(jdkField .getDouble(obj))); } else { throw new BuildException("Unknown primitive class " + fType.getName()); } } else if (jnodeField.getDeclaringClass().isMagicType()) { final Object value = jdkField.get(obj); if (value == null) { os.writeWord(0); } else if (value instanceof UnboxedObject) { final UnboxedObject uobj = (UnboxedObject)value; os.writeWord(uobj.toLong()); } else { throw new BuildException("Cannot handle magic type " + value.getClass().getName()); } } else { Object value = jdkField.get(obj); try { testForValidEmit(value, cls.getName()); } catch (BuildException ex) { throw new BuildException("Cannot emit field " + jdkField.getName() + " of class " + cls.getName(), ex); } catch (JNodeClassNotFoundException ex) { BootLog .warn("JNode class not found " + ex.getMessage()); value = null; } bis.setObjectRef(fldOffset, value); } } } catch (IllegalAccessException ex) { throw new BuildException("emitting object: [" + obj + "]", ex); } catch (SecurityException ex) { throw new BuildException("emitting object: [" + obj + "]", ex); } }
private void storeObject(int offset, Class<?> cls, Object obj, VmClassType<?> vmType) throws BuildException, ClassNotFoundException, JNodeClassNotFoundException { final Class< ? > sCls = cls.getSuperclass(); if (sCls != null) { final VmClassType< ? > vmSuperType = (VmClassType< ? >) loaderContext .loadClass(sCls.getName(), true); storeObject(offset, sCls, obj, vmSuperType); } try { final FieldInfo fieldInfo = getFieldInfo(cls); // final Field fields[] = cls.getDeclaredFields(); final Field[] fields = fieldInfo.getJdkInstanceFields(); final int len = fields.length; // AccessibleObject.setAccessible(fields, true); for (int i = 0; i < len; i++) { final VmField jnodeField = fieldInfo.getJNodeInstanceField(i); final Field jdkField = fields[i]; final int modifiers = jnodeField.getModifiers(); if ((modifiers & Modifier.STATIC) != 0) { throw new BuildException("Static field in instance list"); } final int fldOffset = offset + ((VmInstanceField) jnodeField).getOffset(); if ((jdkField == null) || ((modifiers & Modifier.TRANSIENT) != 0)) { if (jnodeField.isWide()) { os.set64(fldOffset, 0); } else if (!jnodeField.isPrimitive()) { os.setWord(fldOffset, 0); } else { switch (jnodeField.getTypeSize()) { case 1: os.set8(fldOffset, 0); break; case 2: os.set16(fldOffset, 0); break; case 4: os.set32(fldOffset, 0); break; default: throw new BuildException("Invalid typesize in: " + jnodeField); } } if (debugWriter != null) { debugWriter.println(jnodeField.getName() + " transient: 0"); } } else if (jnodeField.isPrimitive()) { final Class< ? > fType = jdkField.getType(); if (debugWriter != null) { debugWriter.println(jdkField.getName() + " " + jdkField.get(obj)); } if (fType == byte.class) { os.set8(fldOffset, jdkField.getByte(obj)); } else if (fType == boolean.class) { os.set8(fldOffset, (jdkField.getBoolean(obj)) ? 1 : 0); } else if (fType == char.class) { os.set16(fldOffset, jdkField.getChar(obj)); } else if (fType == short.class) { os.set16(fldOffset, jdkField.getShort(obj)); } else if (fType == int.class) { os.set32(fldOffset, jdkField.getInt(obj)); } else if (fType == float.class) { os.set32(fldOffset, Float.floatToIntBits(jdkField .getFloat(obj))); } else if (fType == long.class) { os.set64(fldOffset, jdkField.getLong(obj)); } else if (fType == double.class) { os.set64(fldOffset, Double.doubleToLongBits(jdkField .getDouble(obj))); } else { throw new BuildException("Unknown primitive class " + fType.getName()); } } else if (jnodeField.isAddressType()) { final Object value = jdkField.get(obj); if (value == null) { os.writeWord(0); } else if (value instanceof UnboxedObject) { final UnboxedObject uobj = (UnboxedObject)value; os.writeWord(uobj.toLong()); } else { throw new BuildException("Cannot handle magic type " + value.getClass().getName()); } } else { Object value = jdkField.get(obj); try { testForValidEmit(value, cls.getName()); } catch (BuildException ex) { throw new BuildException("Cannot emit field " + jdkField.getName() + " of class " + cls.getName(), ex); } catch (JNodeClassNotFoundException ex) { BootLog .warn("JNode class not found " + ex.getMessage()); value = null; } bis.setObjectRef(fldOffset, value); } } } catch (IllegalAccessException ex) { throw new BuildException("emitting object: [" + obj + "]", ex); } catch (SecurityException ex) { throw new BuildException("emitting object: [" + obj + "]", ex); } }
1,841
private void storeObject(int offset, Class<?> cls, Object obj, VmClassType<?> vmType) throws BuildException, ClassNotFoundException, JNodeClassNotFoundException { final Class< ? > sCls = cls.getSuperclass(); if (sCls != null) { final VmClassType< ? > vmSuperType = (VmClassType< ? >) loaderContext .loadClass(sCls.getName(), true); storeObject(offset, sCls, obj, vmSuperType); } try { final FieldInfo fieldInfo = getFieldInfo(cls); // final Field fields[] = cls.getDeclaredFields(); final Field[] fields = fieldInfo.getJdkInstanceFields(); final int len = fields.length; // AccessibleObject.setAccessible(fields, true); for (int i = 0; i < len; i++) { final VmField jnodeField = fieldInfo.getJNodeInstanceField(i); final Field jdkField = fields[i]; final int modifiers = jnodeField.getModifiers(); if ((modifiers & Modifier.STATIC) != 0) { throw new BuildException("Static field in instance list"); } final int fldOffset = offset + ((VmInstanceField) jnodeField).getOffset(); if ((jdkField == null) || ((modifiers & Modifier.TRANSIENT) != 0)) { if (jnodeField.isWide()) { os.set64(fldOffset, 0); } else if (!jnodeField.isPrimitive()) { os.setWord(fldOffset, 0); } else { switch (jnodeField.getTypeSize()) { case 1: os.set8(fldOffset, 0); break; case 2: os.set16(fldOffset, 0); break; case 4: os.set32(fldOffset, 0); break; default: throw new BuildException("Invalid typesize in: " + jnodeField); } } if (debugWriter != null) { debugWriter.println(jnodeField.getName() + " transient: 0"); } } else if (jnodeField.isPrimitive()) { final Class< ? > fType = jdkField.getType(); if (debugWriter != null) { debugWriter.println(jdkField.getName() + " " + jdkField.get(obj)); } if (fType == byte.class) { os.set8(fldOffset, jdkField.getByte(obj)); } else if (fType == boolean.class) { os.set8(fldOffset, (jdkField.getBoolean(obj)) ? 1 : 0); } else if (fType == char.class) { os.set16(fldOffset, jdkField.getChar(obj)); } else if (fType == short.class) { os.set16(fldOffset, jdkField.getShort(obj)); } else if (fType == int.class) { os.set32(fldOffset, jdkField.getInt(obj)); } else if (fType == float.class) { os.set32(fldOffset, Float.floatToIntBits(jdkField .getFloat(obj))); } else if (fType == long.class) { os.set64(fldOffset, jdkField.getLong(obj)); } else if (fType == double.class) { os.set64(fldOffset, Double.doubleToLongBits(jdkField .getDouble(obj))); } else { throw new BuildException("Unknown primitive class " + fType.getName()); } } else if (jnodeField.getDeclaringClass().isMagicType()) { final Object value = jdkField.get(obj); if (value == null) { os.writeWord(0); } else if (value instanceof UnboxedObject) { final UnboxedObject uobj = (UnboxedObject)value; os.writeWord(uobj.toLong()); } else { throw new BuildException("Cannot handle magic type " + value.getClass().getName()); } } else { Object value = jdkField.get(obj); try { testForValidEmit(value, cls.getName()); } catch (BuildException ex) { throw new BuildException("Cannot emit field " + jdkField.getName() + " of class " + cls.getName(), ex); } catch (JNodeClassNotFoundException ex) { BootLog .warn("JNode class not found " + ex.getMessage()); value = null; } bis.setObjectRef(fldOffset, value); } } } catch (IllegalAccessException ex) { throw new BuildException("emitting object: [" + obj + "]", ex); } catch (SecurityException ex) { throw new BuildException("emitting object: [" + obj + "]", ex); } }
private void storeObject(int offset, Class<?> cls, Object obj, VmClassType<?> vmType) throws BuildException, ClassNotFoundException, JNodeClassNotFoundException { final Class< ? > sCls = cls.getSuperclass(); if (sCls != null) { final VmClassType< ? > vmSuperType = (VmClassType< ? >) loaderContext .loadClass(sCls.getName(), true); storeObject(offset, sCls, obj, vmSuperType); } try { final FieldInfo fieldInfo = getFieldInfo(cls); // final Field fields[] = cls.getDeclaredFields(); final Field[] fields = fieldInfo.getJdkInstanceFields(); final int len = fields.length; // AccessibleObject.setAccessible(fields, true); for (int i = 0; i < len; i++) { final VmField jnodeField = fieldInfo.getJNodeInstanceField(i); final Field jdkField = fields[i]; final int modifiers = jnodeField.getModifiers(); if ((modifiers & Modifier.STATIC) != 0) { throw new BuildException("Static field in instance list"); } final int fldOffset = offset + ((VmInstanceField) jnodeField).getOffset(); if ((jdkField == null) || ((modifiers & Modifier.TRANSIENT) != 0)) { if (jnodeField.isWide()) { os.set64(fldOffset, 0); } else if (!jnodeField.isPrimitive()) { os.setWord(fldOffset, 0); } else { switch (jnodeField.getTypeSize()) { case 1: os.set8(fldOffset, 0); break; case 2: os.set16(fldOffset, 0); break; case 4: os.set32(fldOffset, 0); break; default: throw new BuildException("Invalid typesize in: " + jnodeField); } } if (debugWriter != null) { debugWriter.println(jnodeField.getName() + " transient: 0"); } } else if (jnodeField.isPrimitive()) { final Class< ? > fType = jdkField.getType(); if (debugWriter != null) { debugWriter.println(jdkField.getName() + " " + jdkField.get(obj)); } if (fType == byte.class) { os.set8(fldOffset, jdkField.getByte(obj)); } else if (fType == boolean.class) { os.set8(fldOffset, (jdkField.getBoolean(obj)) ? 1 : 0); } else if (fType == char.class) { os.set16(fldOffset, jdkField.getChar(obj)); } else if (fType == short.class) { os.set16(fldOffset, jdkField.getShort(obj)); } else if (fType == int.class) { os.set32(fldOffset, jdkField.getInt(obj)); } else if (fType == float.class) { os.set32(fldOffset, Float.floatToIntBits(jdkField .getFloat(obj))); } else if (fType == long.class) { os.set64(fldOffset, jdkField.getLong(obj)); } else if (fType == double.class) { os.set64(fldOffset, Double.doubleToLongBits(jdkField .getDouble(obj))); } else { throw new BuildException("Unknown primitive class " + fType.getName()); } } else if (jnodeField.getDeclaringClass().isMagicType()) { final Object value = jdkField.get(obj); if (value == null) { os.setWord(fldOffset, 0); } else if (value instanceof UnboxedObject) { final UnboxedObject uobj = (UnboxedObject)value; os.writeWord(uobj.toLong()); } else { throw new BuildException("Cannot handle magic type " + value.getClass().getName()); } } else { Object value = jdkField.get(obj); try { testForValidEmit(value, cls.getName()); } catch (BuildException ex) { throw new BuildException("Cannot emit field " + jdkField.getName() + " of class " + cls.getName(), ex); } catch (JNodeClassNotFoundException ex) { BootLog .warn("JNode class not found " + ex.getMessage()); value = null; } bis.setObjectRef(fldOffset, value); } } } catch (IllegalAccessException ex) { throw new BuildException("emitting object: [" + obj + "]", ex); } catch (SecurityException ex) { throw new BuildException("emitting object: [" + obj + "]", ex); } }
1,842
private void storeObject(int offset, Class<?> cls, Object obj, VmClassType<?> vmType) throws BuildException, ClassNotFoundException, JNodeClassNotFoundException { final Class< ? > sCls = cls.getSuperclass(); if (sCls != null) { final VmClassType< ? > vmSuperType = (VmClassType< ? >) loaderContext .loadClass(sCls.getName(), true); storeObject(offset, sCls, obj, vmSuperType); } try { final FieldInfo fieldInfo = getFieldInfo(cls); // final Field fields[] = cls.getDeclaredFields(); final Field[] fields = fieldInfo.getJdkInstanceFields(); final int len = fields.length; // AccessibleObject.setAccessible(fields, true); for (int i = 0; i < len; i++) { final VmField jnodeField = fieldInfo.getJNodeInstanceField(i); final Field jdkField = fields[i]; final int modifiers = jnodeField.getModifiers(); if ((modifiers & Modifier.STATIC) != 0) { throw new BuildException("Static field in instance list"); } final int fldOffset = offset + ((VmInstanceField) jnodeField).getOffset(); if ((jdkField == null) || ((modifiers & Modifier.TRANSIENT) != 0)) { if (jnodeField.isWide()) { os.set64(fldOffset, 0); } else if (!jnodeField.isPrimitive()) { os.setWord(fldOffset, 0); } else { switch (jnodeField.getTypeSize()) { case 1: os.set8(fldOffset, 0); break; case 2: os.set16(fldOffset, 0); break; case 4: os.set32(fldOffset, 0); break; default: throw new BuildException("Invalid typesize in: " + jnodeField); } } if (debugWriter != null) { debugWriter.println(jnodeField.getName() + " transient: 0"); } } else if (jnodeField.isPrimitive()) { final Class< ? > fType = jdkField.getType(); if (debugWriter != null) { debugWriter.println(jdkField.getName() + " " + jdkField.get(obj)); } if (fType == byte.class) { os.set8(fldOffset, jdkField.getByte(obj)); } else if (fType == boolean.class) { os.set8(fldOffset, (jdkField.getBoolean(obj)) ? 1 : 0); } else if (fType == char.class) { os.set16(fldOffset, jdkField.getChar(obj)); } else if (fType == short.class) { os.set16(fldOffset, jdkField.getShort(obj)); } else if (fType == int.class) { os.set32(fldOffset, jdkField.getInt(obj)); } else if (fType == float.class) { os.set32(fldOffset, Float.floatToIntBits(jdkField .getFloat(obj))); } else if (fType == long.class) { os.set64(fldOffset, jdkField.getLong(obj)); } else if (fType == double.class) { os.set64(fldOffset, Double.doubleToLongBits(jdkField .getDouble(obj))); } else { throw new BuildException("Unknown primitive class " + fType.getName()); } } else if (jnodeField.getDeclaringClass().isMagicType()) { final Object value = jdkField.get(obj); if (value == null) { os.writeWord(0); } else if (value instanceof UnboxedObject) { final UnboxedObject uobj = (UnboxedObject)value; os.writeWord(uobj.toLong()); } else { throw new BuildException("Cannot handle magic type " + value.getClass().getName()); } } else { Object value = jdkField.get(obj); try { testForValidEmit(value, cls.getName()); } catch (BuildException ex) { throw new BuildException("Cannot emit field " + jdkField.getName() + " of class " + cls.getName(), ex); } catch (JNodeClassNotFoundException ex) { BootLog .warn("JNode class not found " + ex.getMessage()); value = null; } bis.setObjectRef(fldOffset, value); } } } catch (IllegalAccessException ex) { throw new BuildException("emitting object: [" + obj + "]", ex); } catch (SecurityException ex) { throw new BuildException("emitting object: [" + obj + "]", ex); } }
private void storeObject(int offset, Class<?> cls, Object obj, VmClassType<?> vmType) throws BuildException, ClassNotFoundException, JNodeClassNotFoundException { final Class< ? > sCls = cls.getSuperclass(); if (sCls != null) { final VmClassType< ? > vmSuperType = (VmClassType< ? >) loaderContext .loadClass(sCls.getName(), true); storeObject(offset, sCls, obj, vmSuperType); } try { final FieldInfo fieldInfo = getFieldInfo(cls); // final Field fields[] = cls.getDeclaredFields(); final Field[] fields = fieldInfo.getJdkInstanceFields(); final int len = fields.length; // AccessibleObject.setAccessible(fields, true); for (int i = 0; i < len; i++) { final VmField jnodeField = fieldInfo.getJNodeInstanceField(i); final Field jdkField = fields[i]; final int modifiers = jnodeField.getModifiers(); if ((modifiers & Modifier.STATIC) != 0) { throw new BuildException("Static field in instance list"); } final int fldOffset = offset + ((VmInstanceField) jnodeField).getOffset(); if ((jdkField == null) || ((modifiers & Modifier.TRANSIENT) != 0)) { if (jnodeField.isWide()) { os.set64(fldOffset, 0); } else if (!jnodeField.isPrimitive()) { os.setWord(fldOffset, 0); } else { switch (jnodeField.getTypeSize()) { case 1: os.set8(fldOffset, 0); break; case 2: os.set16(fldOffset, 0); break; case 4: os.set32(fldOffset, 0); break; default: throw new BuildException("Invalid typesize in: " + jnodeField); } } if (debugWriter != null) { debugWriter.println(jnodeField.getName() + " transient: 0"); } } else if (jnodeField.isPrimitive()) { final Class< ? > fType = jdkField.getType(); if (debugWriter != null) { debugWriter.println(jdkField.getName() + " " + jdkField.get(obj)); } if (fType == byte.class) { os.set8(fldOffset, jdkField.getByte(obj)); } else if (fType == boolean.class) { os.set8(fldOffset, (jdkField.getBoolean(obj)) ? 1 : 0); } else if (fType == char.class) { os.set16(fldOffset, jdkField.getChar(obj)); } else if (fType == short.class) { os.set16(fldOffset, jdkField.getShort(obj)); } else if (fType == int.class) { os.set32(fldOffset, jdkField.getInt(obj)); } else if (fType == float.class) { os.set32(fldOffset, Float.floatToIntBits(jdkField .getFloat(obj))); } else if (fType == long.class) { os.set64(fldOffset, jdkField.getLong(obj)); } else if (fType == double.class) { os.set64(fldOffset, Double.doubleToLongBits(jdkField .getDouble(obj))); } else { throw new BuildException("Unknown primitive class " + fType.getName()); } } else if (jnodeField.getDeclaringClass().isMagicType()) { final Object value = jdkField.get(obj); if (value == null) { os.writeWord(0); } else if (value instanceof UnboxedObject) { final UnboxedObject uobj = (UnboxedObject)value; os.setWord(fldOffset, uobj.toLong()); } else if (value instanceof Label) { final Label lbl = (Label)value; bis.setObjectRef(fldOffset, lbl); } else { throw new BuildException("Cannot handle magic type " + value.getClass().getName()); } } else { Object value = jdkField.get(obj); try { testForValidEmit(value, cls.getName()); } catch (BuildException ex) { throw new BuildException("Cannot emit field " + jdkField.getName() + " of class " + cls.getName(), ex); } catch (JNodeClassNotFoundException ex) { BootLog .warn("JNode class not found " + ex.getMessage()); value = null; } bis.setObjectRef(fldOffset, value); } } } catch (IllegalAccessException ex) { throw new BuildException("emitting object: [" + obj + "]", ex); } catch (SecurityException ex) { throw new BuildException("emitting object: [" + obj + "]", ex); } }
1,843
private void jbInit() throws Exception { this.setSize(new Dimension(400,300)); Properties sesProps = new Properties(); // Start loading properties - Host must exist sesProps.put(SESSION_HOST,getParameter("host")); if (isSpecified("-e")) sesProps.put(SESSION_TN_ENHANCED,"1"); if (isSpecified("-p")) { sesProps.put(SESSION_HOST_PORT,getParameter("-p")); }// if (isSpecified("-f",args))// propFileName = getParm("-f",args); if (isSpecified("-cp")) sesProps.put(SESSION_CODE_PAGE ,getParameter("-cp")); if (isSpecified("-gui")) sesProps.put(SESSION_USE_GUI,"1"); if (isSpecified("-132")) sesProps.put(SESSION_SCREEN_SIZE,SCREEN_SIZE_27X132_STR); else sesProps.put(SESSION_SCREEN_SIZE,SCREEN_SIZE_24X80_STR); // socks proxy host argument if (isSpecified("-sph")) { sesProps.put(SESSION_PROXY_HOST ,getParameter("-sph")); } // socks proxy port argument if (isSpecified("-spp")) sesProps.put(SESSION_PROXY_PORT ,getParameter("-spp")); // check if device name is specified if (isSpecified("-dn")) sesProps.put(SESSION_DEVICE_NAME ,getParameter("-dn")); if (isSpecified("-L")) LangTool.init(parseLocale(getParameter("-L"))); else LangTool.init(); manager = new SessionManager(); Session s = manager.openSession(sesProps,"","Test Applet"); this.getContentPane().add(s); s.grabFocus(); s.connect(); }
private void jbInit() throws Exception { this.setSize(new Dimension(400,300)); Properties sesProps = new Properties(); // Start loading properties - Host must exist sesProps.put(SESSION_HOST,getParameter("host")); if (isSpecified("-e")) sesProps.put(SESSION_TN_ENHANCED,"1"); if (isSpecified("-p")) { sesProps.put(SESSION_HOST_PORT,getParameter("-p")); }// if (isSpecified("-f",args))// propFileName = getParm("-f",args); if (isSpecified("-cp")) sesProps.put(SESSION_CODE_PAGE ,getParameter("-cp")); if (isSpecified("-gui")) sesProps.put(SESSION_USE_GUI,"1"); if (isSpecified("-132")) sesProps.put(SESSION_SCREEN_SIZE,SCREEN_SIZE_27X132_STR); else sesProps.put(SESSION_SCREEN_SIZE,SCREEN_SIZE_24X80_STR); // socks proxy host argument if (isSpecified("-sph")) { sesProps.put(SESSION_PROXY_HOST ,getParameter("-sph")); } // socks proxy port argument if (isSpecified("-spp")) sesProps.put(SESSION_PROXY_PORT ,getParameter("-spp")); // check if device name is specified if (isSpecified("-dn")) sesProps.put(SESSION_DEVICE_NAME ,getParameter("-dn")); if (isSpecified("-L")) LangTool.init(parseLocale(getParameter("-L"))); else LangTool.init(); manager = new SessionManager(); Session s = manager.openSession(sesProps,"","Test Applet"); this.getContentPane().add(s); s.connect(); }
1,844
public void layoutContainer(Container c) { Dimension size = c.getSize(); Insets insets = c.getInsets(); int width = size.width - insets.left - insets.right; int height = size.height - insets.top - insets.bottom; // MenuBar is always present and located at the top left corner. Dimension menupref = menuBar.getPreferredSize(); menuBar.setBounds(insets.left, insets.top, menupref.width, height); int loc = width + insets.left - 1; int top = insets.top + 1; int buttonWidth = height - 2; int buttonHeight = height - 4; if (closeButton.isVisible()) { loc -= buttonWidth + 2; closeButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (maxButton.isVisible()) { loc -= buttonWidth + 2; maxButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (iconButton.isVisible()) { loc -= buttonWidth + 2; iconButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (title != null) title.setBounds(insets.left + menupref.width, insets.top, loc - menupref.width - insets.left, height); }
public void layoutContainer(Container c) { Dimension size = c.getSize(); Insets insets = c.getInsets(); int width = size.width - insets.left - insets.right; int height = size.height - insets.top - insets.bottom; // MenuBar is always present and located at the top left corner. Dimension menupref = menuBar.getPreferredSize(); menuBar.setBounds(insets.left, insets.top, menupref.width, height); int loc = width + insets.left - 1; int top = insets.top + 1; int buttonHeight = height - 4; if (closeButton.isVisible()) { loc -= buttonWidth + 2; closeButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (maxButton.isVisible()) { loc -= buttonWidth + 2; maxButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (iconButton.isVisible()) { loc -= buttonWidth + 2; iconButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (title != null) title.setBounds(insets.left + menupref.width, insets.top, loc - menupref.width - insets.left, height); }
1,845
public void layoutContainer(Container c) { Dimension size = c.getSize(); Insets insets = c.getInsets(); int width = size.width - insets.left - insets.right; int height = size.height - insets.top - insets.bottom; // MenuBar is always present and located at the top left corner. Dimension menupref = menuBar.getPreferredSize(); menuBar.setBounds(insets.left, insets.top, menupref.width, height); int loc = width + insets.left - 1; int top = insets.top + 1; int buttonWidth = height - 2; int buttonHeight = height - 4; if (closeButton.isVisible()) { loc -= buttonWidth + 2; closeButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (maxButton.isVisible()) { loc -= buttonWidth + 2; maxButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (iconButton.isVisible()) { loc -= buttonWidth + 2; iconButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (title != null) title.setBounds(insets.left + menupref.width, insets.top, loc - menupref.width - insets.left, height); }
public void layoutContainer(Container c) { Dimension size = c.getSize(); Insets insets = c.getInsets(); int width = size.width - insets.left - insets.right; int height = size.height - insets.top - insets.bottom; // MenuBar is always present and located at the top left corner. Dimension menupref = menuBar.getPreferredSize(); menuBar.setBounds(insets.left, insets.top, menupref.width, height); int loc = width + insets.left - 1; int top = insets.top + 1; int buttonWidth = height - 2; int buttonHeight = height - 4; if (closeButton.isVisible()) { loc -= buttonWidth + 2; closeButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (maxButton.isVisible()) { loc -= buttonWidth + 2; maxButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (iconButton.isVisible()) { loc -= buttonWidth + 2; iconButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (title != null) title.setBounds(insets.left + menupref.width, insets.top, loc - menupref.width - insets.left, height); }
1,846
public void layoutContainer(Container c) { Dimension size = c.getSize(); Insets insets = c.getInsets(); int width = size.width - insets.left - insets.right; int height = size.height - insets.top - insets.bottom; // MenuBar is always present and located at the top left corner. Dimension menupref = menuBar.getPreferredSize(); menuBar.setBounds(insets.left, insets.top, menupref.width, height); int loc = width + insets.left - 1; int top = insets.top + 1; int buttonWidth = height - 2; int buttonHeight = height - 4; if (closeButton.isVisible()) { loc -= buttonWidth + 2; closeButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (maxButton.isVisible()) { loc -= buttonWidth + 2; maxButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (iconButton.isVisible()) { loc -= buttonWidth + 2; iconButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (title != null) title.setBounds(insets.left + menupref.width, insets.top, loc - menupref.width - insets.left, height); }
public void layoutContainer(Container c) { Dimension size = c.getSize(); Insets insets = c.getInsets(); int width = size.width - insets.left - insets.right; int height = size.height - insets.top - insets.bottom; // MenuBar is always present and located at the top left corner. Dimension menupref = menuBar.getPreferredSize(); menuBar.setBounds(insets.left, insets.top, menupref.width, height); int loc = width + insets.left - 1; int top = insets.top + 1; int buttonWidth = height - 2; int buttonHeight = height - 4; if (closeButton.isVisible()) { loc -= buttonWidth + 2; closeButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (maxButton.isVisible()) { loc -= buttonWidth + 2; maxButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (iconButton.isVisible()) { loc -= buttonWidth + 2; iconButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (title != null) title.setBounds(insets.left + menupref.width, insets.top, loc - menupref.width - insets.left, height); }
1,847
public void layoutContainer(Container c) { Dimension size = c.getSize(); Insets insets = c.getInsets(); int width = size.width - insets.left - insets.right; int height = size.height - insets.top - insets.bottom; // MenuBar is always present and located at the top left corner. Dimension menupref = menuBar.getPreferredSize(); menuBar.setBounds(insets.left, insets.top, menupref.width, height); int loc = width + insets.left - 1; int top = insets.top + 1; int buttonWidth = height - 2; int buttonHeight = height - 4; if (closeButton.isVisible()) { loc -= buttonWidth + 2; closeButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (maxButton.isVisible()) { loc -= buttonWidth + 2; maxButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (iconButton.isVisible()) { loc -= buttonWidth + 2; iconButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (title != null) title.setBounds(insets.left + menupref.width, insets.top, loc - menupref.width - insets.left, height); }
public void layoutContainer(Container c) { Dimension size = c.getSize(); Insets insets = c.getInsets(); int width = size.width - insets.left - insets.right; int height = size.height - insets.top - insets.bottom; // MenuBar is always present and located at the top left corner. Dimension menupref = menuBar.getPreferredSize(); menuBar.setBounds(insets.left, insets.top, menupref.width, height); int loc = width + insets.left - 1; int top = insets.top + 1; int buttonWidth = height - 2; int buttonHeight = height - 4; if (closeButton.isVisible()) { loc -= buttonWidth + 2; closeButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (maxButton.isVisible()) { loc -= buttonWidth + 2; maxButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (iconButton.isVisible()) { loc -= buttonWidth + 2; iconButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (title != null) title.setBounds(insets.left + menupref.width, insets.top, loc - menupref.width - insets.left, height); }
1,848
protected void installDefaults() { // FIXME: move icons to defaults. UIDefaults defaults = UIManager.getLookAndFeelDefaults(); setFont(defaults.getFont("InternalFrame.titleFont")); selectedTextColor = defaults.getColor("InternalFrame.activeTitleForeground"); selectedTitleColor = defaults.getColor("InternalFrame.activeTitleBackground"); notSelectedTextColor = defaults.getColor("InternalFrame.inactiveTitleForeground"); notSelectedTitleColor = defaults.getColor("InternalFrame.inactiveTitleBackground"); }
protected void installDefaults() { // FIXME: move icons to defaults. UIDefaults defaults = UIManager.getLookAndFeelDefaults(); title.setFont(defaults.getFont("InternalFrame.titleFont")); selectedTextColor = defaults.getColor("InternalFrame.activeTitleForeground"); selectedTitleColor = defaults.getColor("InternalFrame.activeTitleBackground"); notSelectedTextColor = defaults.getColor("InternalFrame.inactiveTitleForeground"); notSelectedTitleColor = defaults.getColor("InternalFrame.inactiveTitleBackground"); }
1,850
protected void installListeners() { propertyChangeListener = new PropertyChangeHandler(); frame.addPropertyChangeListener(propertyChangeListener); }
protected void installListeners() { propertyChangeListener = createPropertyChangeListener(); frame.addPropertyChangeListener(propertyChangeListener); }
1,852
public void paintComponent(Graphics g) { paintTitleBackground(g); Font f = g.getFont(); FontMetrics fm = g.getFontMetrics(f); if (frame.getTitle() != null && title != null) { Color saved = g.getColor(); if (frame.isSelected()) g.setColor(selectedTextColor); else g.setColor(notSelectedTextColor); title.setText(getTitle(frame.getTitle(), fm, title.getBounds().width)); SwingUtilities.paintComponent(g, title, null, title.getBounds()); g.setColor(saved); } }
public void paintComponent(Graphics g) { paintTitleBackground(g); Font f = g.getFont(); FontMetrics fm = g.getFontMetrics(f); if (frame.getTitle() != null && title != null) { Color saved = g.getColor(); if (frame.isSelected()) g.setColor(selectedTextColor); else g.setColor(notSelectedTextColor); title.setText(getTitle(frame.getTitle(), fm, title.getBounds().width)); SwingUtilities.paintComponent(g, title, null, title.getBounds()); g.setColor(saved); } }
1,853
protected void setButtonIcons() { Icon icon = UIManager.getIcon("InternalFrame.closeIcon"); if (icon != null) closeButton.setIcon(icon); icon = UIManager.getIcon("InternalFrame.iconifyIcon"); if (icon != null) iconButton.setIcon(icon); icon = UIManager.getIcon("InternalFrame.maximizeIcon"); if (icon != null) maxButton.setIcon(icon); }
protected void setButtonIcons() { Icon icon = UIManager.getIcon("InternalFrame.closeIcon"); if (icon != null) closeButton.setIcon(icon); icon = UIManager.getIcon("InternalFrame.iconifyIcon"); if (icon != null) iconButton.setIcon(icon); icon = UIManager.getIcon("InternalFrame.maximizeIcon"); if (icon != null) maxButton.setIcon(icon); }
1,855
protected void installListeners() { // install combo box's listeners propertyChangeListener = createPropertyChangeListener(); comboBox.addPropertyChangeListener(propertyChangeListener); focusListener = createFocusListener(); comboBox.addFocusListener(focusListener); listBox.addFocusListener(focusListener); itemListener = createItemListener(); comboBox.addItemListener(itemListener); keyListener = createKeyListener(); comboBox.addKeyListener(keyListener); mouseListener = createMouseListener(); arrowButton.addMouseListener(mouseListener); // install listeners that listen to combo box model listDataListener = createListDataListener(); comboBox.getModel().addListDataListener(listDataListener); }
protected void installListeners() { // install combo box's listeners propertyChangeListener = createPropertyChangeListener(); comboBox.addPropertyChangeListener(propertyChangeListener); focusListener = createFocusListener(); comboBox.addFocusListener(focusListener); listBox.addFocusListener(focusListener); itemListener = createItemListener(); comboBox.addItemListener(itemListener); keyListener = createKeyListener(); comboBox.addKeyListener(keyListener); mouseListener = createMouseListener(); arrowButton.addMouseListener(mouseListener); // install listeners that listen to combo box model listDataListener = createListDataListener(); comboBox.getModel().addListDataListener(listDataListener); }
1,858
public void setPopupVisible(JComboBox c, boolean v) { if (v) { popup.show(); popup.getList().requestFocus(); } else popup.hide(); }
public void setPopupVisible(JComboBox c, boolean v) if (v) popup.show(); popup.getList().requestFocus(); } else popup.hide(); }
1,859
public void setPopupVisible(JComboBox c, boolean v) { if (v) { popup.show(); popup.getList().requestFocus(); } else popup.hide(); }
public void setPopupVisible(JComboBox c, boolean v) { if (v) { popup.show(); popup.getList().requestFocus(); } else popup.hide(); }
1,860
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value != null) { if (value instanceof JTextField) return new JTextField(((JTextField)value).getText()); super.setText(value.toString()); } else // null is rendered as an empty cell. super.setText(""); setOpaque(true); if (table == null) return this; if (isSelected) { super.setBackground(table.getSelectionBackground()); super.setForeground(table.getSelectionForeground()); } else { if (background != null) super.setBackground(background); else super.setBackground(table.getBackground()); if (foreground != null) super.setForeground(foreground); else super.setForeground(table.getForeground()); } if (hasFocus) { setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); if (table.isCellEditable(row, column)) { super.setBackground(UIManager.getColor("Table.focusCellBackground")); super.setForeground(UIManager.getColor("Table.focusCellForeground")); } } else setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setFont(table.getFont()); // If the current background is equal to the table's background, then we // can avoid filling the background by setting the renderer opaque. Color back = getBackground(); setOpaque(back != null && back.equals(table.getBackground())); return this; }
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value != null) { if (value instanceof JTextField) return new JTextField(((JTextField)value).getText()); super.setText(value.toString()); } else // null is rendered as an empty cell. super.setText(""); setOpaque(true); if (table == null) return this; if (isSelected) { super.setBackground(table.getSelectionBackground()); super.setForeground(table.getSelectionForeground()); } else { if (background != null) super.setBackground(background); else super.setBackground(table.getBackground()); if (foreground != null) super.setForeground(foreground); else super.setForeground(table.getForeground()); } if (hasFocus) { setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); if (table.isCellEditable(row, column)) { super.setBackground(UIManager.getColor("Table.focusCellBackground")); super.setForeground(UIManager.getColor("Table.focusCellForeground")); } } else setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setFont(table.getFont()); // If the current background is equal to the table's background, then we // can avoid filling the background by setting the renderer opaque. Color back = getBackground(); setOpaque(back != null && back.equals(table.getBackground())); return this; }
1,863
protected void setValue(Object value) { super.setText((value!=null) ? value.toString() : ""); }
protected void setValue(Object value) { if (value != null) setText(value.toString()); else setText(""); }
1,864
public InstantiationException() { super(); }
public InstantiationException() { super(); }
1,865
public SwingPanelPeer(Panel panel) { super(); SwingToolkit.add(panel, this); SwingToolkit.copyAwtProperties(panel, this); setLayout(null); }
public SwingPanelPeer(Panel panel) { this.panel = panel; SwingToolkit.add(panel, this); SwingToolkit.copyAwtProperties(panel, this); setLayout(null); }
1,866
public final boolean requestFocus(Component lightweightChild, boolean temporary, boolean focusedWindowChangeAllowed, long time) { return true; }
public final boolean requestFocus(Component lightweightChild, boolean temporary, boolean focusedWindowChangeAllowed, long time) { return true; }
1,867
public SwingMenuPeer(SwingToolkit toolkit, Menu menu, JComponent jComponent) { super(toolkit, menu, jComponent); }
public SwingMenuPeer(SwingToolkit toolkit, Menu menu, JComponent jComponent) { super(toolkit, menu, jComponent); }
1,868
public TestConfig getConfig(Class configClazz, Class clazz, String testName) { TestKey key = new TestKey(clazz, testName); Iterator it = (Iterator) iterators.get(key); if(it == null) { List cfgs = (List) configs.get(configClazz); it = cfgs.iterator(); iterators.put(key, it); } TestConfig cfg = (TestConfig) it.next(); log.info(key+" got config "+cfg); return cfg; }
public TestConfig getConfig(Class configClazz, Class clazz, String testName) { TestKey key = new TestKey(clazz, testName); Iterator it = (Iterator) iterators.get(key); if(it == null) { List cfgs = (List) configs.get(configClazz); it = cfgs.iterator(); iterators.put(key, it); } TestConfig cfg = (TestConfig) it.next(); log.info(key+" got config "+cfg); return cfg; }
1,869
public TestConfig getConfig(Class configClazz, Class clazz, String testName) { TestKey key = new TestKey(clazz, testName); Iterator it = (Iterator) iterators.get(key); if(it == null) { List cfgs = (List) configs.get(configClazz); it = cfgs.iterator(); iterators.put(key, it); } TestConfig cfg = (TestConfig) it.next(); log.info(key+" got config "+cfg); return cfg; }
public TestConfig getConfig(Class configClazz, Class clazz, String testName) { TestKey key = new TestKey(clazz, testName); Iterator it = (Iterator) iterators.get(key); if(it == null) { List cfgs = (List) configs.get(configClazz); it = cfgs.iterator(); iterators.put(key, it); } TestConfig cfg = (TestConfig) it.next(); log.info(key+" got config "+cfg); return cfg; }
1,870
public boolean isCurrentFieldHighlightedEntry() { return currentField.isHiglightedEntry(); }
public boolean isCurrentFieldHighlightedEntry() { if (currentField != null) return currentField.isHiglightedEntry(); else return false; }
1,871
public ScreenField setField(int attr, int row, int col, int len, int ffw1, int ffw2, int fcw1, int fcw2) { ScreenField sf = null; screenFields[nextField] = new ScreenField(screen); screenFields[nextField].setField(attr,row,col,len,ffw1,ffw2,fcw1,fcw2); sf = screenFields[nextField++]; sizeFields++; // set the field id if it is not a bypass field // this is used for cursor progression if (!sf.isBypassField()) sf.setFieldId(++fieldIds); // check if the cursor progression field flag should be set.// if ((fcw1 & 0x88) == 0x88) if (fcw1 == 0x88) cpfExists = true; if (currentField != null) { currentField.next = sf; sf.prev = currentField; } currentField = sf; // check if the Modified Data Tag was set while creating the field masterMDT = currentField.mdt; return currentField; }
public ScreenField setField(int attr, int row, int col, int len, int ffw1, int ffw2, int fcw1, int fcw2) { ScreenField sf = null; screenFields[nextField] = new ScreenField(screen); screenFields[nextField].setField(attr,row,col,len,ffw1,ffw2,fcw1,fcw2); sf = screenFields[nextField++]; sizeFields++; // set the field id if it is not a bypass field // this is used for cursor progression if (!sf.isBypassField()) sf.setFieldId(++fieldIds); // check if the cursor progression field flag should be set.// if ((fcw1 & 0x88) == 0x88) if (fcw1 == 0x88) cpfExists = true; if (currentField != null) { currentField.next = sf; sf.prev = currentField; } currentField = sf; // check if the Modified Data Tag was set while creating the field if (!masterMDT) masterMDT = currentField.mdt; return currentField; }
1,872
protected boolean gotoField(ScreenField f) { if (f != null) { goto_XY(f.startPos()); return true; } else { return false; } }
protected boolean gotoField(ScreenField f) { if (f != null) { goto_XY(f.startPos()); return true; } else { return false; } }
1,873
protected boolean gotoField(ScreenField f) { if (f != null) { goto_XY(f.startPos()); return true; } else { return false; } }
protected boolean gotoField(ScreenField f) { if (f != null) { goto_XY(f.startPos()); return true; } else { return false; } }
1,874
public ScreenField setField(int attr, int row, int col, int len, int ffw1, int ffw2, int fcw1, int fcw2) {// startRow = row;// startCol = col; startPos = (row * s.getCols()) + col; endPos = startPos + length -1; cursorProg = 0; fieldId = 0; length = len; endPos = startPos + length -1; this.attr = attr; setFFWs(ffw1,ffw2); setFCWs(fcw1,fcw2); next = null; prev = null; return this; }
public ScreenField setField(int attr, int len, int ffw1, int ffw2, int fcw1, int fcw2) {// startRow = row;// startCol = col; startPos = (row * s.getCols()) + col; endPos = startPos + length -1; cursorProg = 0; fieldId = 0; length = len; endPos = startPos + length -1; this.attr = attr; setFFWs(ffw1,ffw2); setFCWs(fcw1,fcw2); next = null; prev = null; return this; }
1,875
public ScreenField setField(int attr, int row, int col, int len, int ffw1, int ffw2, int fcw1, int fcw2) {// startRow = row;// startCol = col; startPos = (row * s.getCols()) + col; endPos = startPos + length -1; cursorProg = 0; fieldId = 0; length = len; endPos = startPos + length -1; this.attr = attr; setFFWs(ffw1,ffw2); setFCWs(fcw1,fcw2); next = null; prev = null; return this; }
public ScreenField setField(int attr, int row, int col, int len, int ffw1, int ffw2, int fcw1, int fcw2) {// startRow = row;// startCol = col; startPos = (row * s.getCols()) + col; endPos = startPos + length -1; cursorProg = 0; fieldId = 0; length = len; endPos = startPos + length -1; this.attr = attr; setFFWs(ffw1,ffw2); setFCWs(fcw1,fcw2); next = null; prev = null; return this; }
1,876
public ProtectionDomain[] combine (final ProtectionDomain[] current, final ProtectionDomain[] assigned) { LinkedList domains = new LinkedList(); Principal[] principals = (Principal[]) subject.getPrincipals().toArray (new Principal[0]); if (current != null) { for (int i = 0; i < current.length; i++) { domains.add (new ProtectionDomain (current[i].getCodeSource(), current[i].getPermissions(), current[i].getClassLoader(), principals)); } } if (assigned != null) { for (int i = 0; i < assigned.length; i++) { domains.add (assigned[i]); } } return (ProtectionDomain[]) domains.toArray (new ProtectionDomain[domains.size()]); }
public ProtectionDomain[] combine (final ProtectionDomain[] current, final ProtectionDomain[] assigned) { LinkedList domains = new LinkedList(); Principal[] principals = (Principal[]) subject.getPrincipals().toArray (new Principal[0]); if (current != null) { for (int i = 0; i < current.length; i++) { domains.add (new ProtectionDomain (current[i].getCodeSource(), current[i].getPermissions(), current[i].getClassLoader(), principals)); } } if (assigned != null) { for (int i = 0; i < assigned.length; i++) { domains.add (assigned[i]); } } return (ProtectionDomain[]) domains.toArray (new ProtectionDomain[domains.size()]); }
1,878
public void drawImageBuffer(Graphics2D gg2d,int x, int y, int width, int height) { synchronized (lock) { gg2d.drawImage(bi.getSubimage(x,y,width,height),null,x,y); } }
public void drawImageBuffer(Graphics2D gg2d,int x, int y, int width, int height) { gg2d.drawImage(bi.getSubimage(x,y,width,height),null,x,y); } }
1,879
public void drawImageBuffer(Graphics2D gg2d,int x, int y, int width, int height) { synchronized (lock) { gg2d.drawImage(bi.getSubimage(x,y,width,height),null,x,y); } }
public void drawImageBuffer(Graphics2D gg2d,int x, int y, int width, int height) { synchronized (lock) { gg2d.drawImage(bi.getSubimage(x,y,width,height),null,x,y);
1,880
protected void updateImage(Rectangle r) { updateImage(r.x,r.y,r.width,r.height); }
protected void updateImage(Rectangle r) { updateImage(r.x,r.y,r.width,r.height); }
1,881
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,884
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; String command = e.getActionCommand(); if (command.equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,885
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,886
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (command.equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,887
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (command.equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,888
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,889
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (command.equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,890
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,891
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,892
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,893
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,894
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,895
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,896
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,897
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (command.equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,898
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,899
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (command.equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,900
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,901
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (command.equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,902
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,903
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (command.equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,904
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,905
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (command.indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (command.indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,906
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (command.equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (command.equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (command.equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (command.equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (command.equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (command.equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (command.equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("clearSelection")) { table.clearSelection(); } else if (command.equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (command.equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (command.equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (command.equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (command.equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (command.equals ("selectPreviousRowCell")), false); } else if (command.equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (command.equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectAll")) { table.selectAll(); } else if (command.equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,907
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (command.equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,908
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (command.equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,909
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,910
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,911
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,912
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (command.equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,913
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,914
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,915
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
public void actionPerformed (ActionEvent e) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(colMax, colMax); } else if (e.getActionCommand().equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstColumn")) { rowModel.setSelectionInterval(rowLead, rowLead); colModel.setSelectionInterval(0, 0); } else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); colModel.setSelectionInterval(colLead,colLead); } else if (e.getActionCommand().equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("selectPreviousColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (e.getActionCommand().equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (e.getActionCommand().equals("clearSelection")) { table.clearSelection(); } else if (e.getActionCommand().equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (e.getActionCommand().equals("selectNextRowCell") || e.getActionCommand().equals("selectPreviousRowCell") || e.getActionCommand().equals("selectNextColumnCell") || e.getActionCommand().equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (e.getActionCommand().indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (e.getActionCommand().equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (e.getActionCommand().equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (e.getActionCommand().indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (e.getActionCommand().equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (e.getActionCommand().equals ("selectPreviousRowCell")), false); } else if (e.getActionCommand().equals("selectNextColumn")) { rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (e.getActionCommand().equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (e.getActionCommand().equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (e.getActionCommand().equals("selectAll")) { table.selectAll(); } else if (e.getActionCommand().equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (e.getActionCommand().equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else { // If we're here that means we bound this TableAction class // to a keyboard input but we either want to ignore that input // or we just haven't implemented its action yet. } if (table.isEditing() && e.getActionCommand() != "startEditing") table.editingCanceled(new ChangeEvent("update")); table.repaint(); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
1,916
public NetworkException(String message, Throwable cause) { super(message); initCause(cause); }
public NetworkException(String message, Throwable cause) { super(message); initCause(cause); }
1,918
public static ComponentUI createUI(JComponent component) { if (instance == null) instance = new MetalComboBoxUI(); return instance; }
public static ComponentUI createUI(JComponent component) { if (instances == null) instances = new HashMap(); Object o = instances.get(component); MetalComboBoxUI instance; if (o == null) { instance = new MetalComboBoxUI(); return instance; }
1,919
private void processCC1 (byte byte1) {// System.out.println(" Control byte1 " + Integer.toBinaryString(byte1 & 0xff)); if ((byte1 & 0x04) == 0x04) { Toolkit.getDefaultToolkit().beep(); } if ((byte1 & 0x02) == 0x02) { screen52.setMessageLightOff(); } if ((byte1 & 0x01) == 0x01) { screen52.setMessageLightOn(); } if ((byte1 & 0x01) == 0x01 && (byte1 & 0x02) == 0x02) { screen52.setMessageLightOn(); } // reset blinking cursor seems to control whether to set or not set the // the cursor position. No documentation for this just testing and // looking at the bit settings of this field. This was a pain in the ass! // // if it is off '0' then keep existing cursor positioning information // if it is on '1' then reset the cursor positioning information // *** Note *** unless we receive bit 4 on at the same time // this seems to work so far if ((byte1 & 0x20) == 0x20 && (byte1 & 0x08) == 0x00) { screen52.setPendingInsert(false,1,1); } // in enhanced mode we sometimes only receive bit 6 turned on which // is reset blinking cursor if ((byte1 & 0x20) == 0x20 && enhanced) { cursorOn = true; } if (!screen52.isStatusErrorCode() && (byte1 & 0x08) == 0x08) {// screen52.setStatus(screen52.STATUS_SYSTEM,screen52.STATUS_VALUE_OFF,null); cursorOn = true; } if ((byte1 & 0x20) == 0x20 && (byte1 & 0x08) == 0x00) { screen52.setPendingInsert(false,1,1); } }
private void processCC1 (byte byte1) {// System.out.println(" Control byte1 " + Integer.toBinaryString(byte1 & 0xff)); if ((byte1 & 0x04) == 0x04) { Toolkit.getDefaultToolkit().beep(); } if ((byte1 & 0x02) == 0x02) { screen52.setMessageLightOff(); } if ((byte1 & 0x01) == 0x01) { screen52.setMessageLightOn(); } if ((byte1 & 0x01) == 0x01 && (byte1 & 0x02) == 0x02) { screen52.setMessageLightOn(); } // reset blinking cursor seems to control whether to set or not set the // the cursor position. No documentation for this just testing and // looking at the bit settings of this field. This was a pain in the ass! // // if it is off '0' then keep existing cursor positioning information // if it is on '1' then reset the cursor positioning information // *** Note *** unless we receive bit 4 on at the same time // this seems to work so far if ((byte1 & 0x20) == 0x20 && (byte1 & 0x08) == 0x00) { screen52.setPendingInsert(false); } // in enhanced mode we sometimes only receive bit 6 turned on which // is reset blinking cursor if ((byte1 & 0x20) == 0x20 && enhanced) { cursorOn = true; } if (!screen52.isStatusErrorCode() && (byte1 & 0x08) == 0x08) {// screen52.setStatus(screen52.STATUS_SYSTEM,screen52.STATUS_VALUE_OFF,null); cursorOn = true; } if ((byte1 & 0x20) == 0x20 && (byte1 & 0x08) == 0x00) { screen52.setPendingInsert(false); } }
1,921
private boolean writeToDisplay(boolean controlsExist) { int pos = 0; boolean error=false; boolean done=false; int attr; byte nextOne; byte control0 = 0; byte control1 = 0; int saRows = screen52.getRows(); int saCols = screen52.getCols(); try { if (controlsExist) { control0 = bk.getNextByte(); control1 = bk.getNextByte(); processCC0(control0); } while (bk.hasNext() && !done) {// pos = bk.getCurrentPos();// int rowc = screen52.getCurrentRow();// int colc = screen52.getCurrentCol(); switch (bk.getNextByte()) { case 1: // SOH - Start of Header Order error = processSOH(); break; case 02: // RA - Repeat to address int row = screen52.getCurrentRow(); int col = screen52.getCurrentCol(); int toRow = bk.getNextByte(); int toCol = bk.getNextByte() & 0xff; if (toRow >= row) { int repeat = bk.getNextByte(); // a little intelligence here I hope if (row == 1 && col == 2 && toRow == screen52.getRows() && toCol == screen52.getCols()) screen52.clearScreen(); else { if (repeat != 0) repeat = getASCIIChar(repeat); int times = ((toRow * screen52.getCols()) + toCol) - ((row * screen52.getCols()) + col); while (times-- >= 0) { screen52.setChar(repeat); } } } else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x23," RA invalid"); error =true; } break; case 03: // EA - Erase to address int EArow = screen52.getCurrentRow(); int EAcol = screen52.getCurrentCol(); int toEARow = bk.getNextByte(); int toEACol = bk.getNextByte() & 0xff; int EALength = bk.getNextByte() & 0xff; while (--EALength > 0) { bk.getNextByte(); } char EAAttr = (char)0; // a little intelligence here I hope if (EArow == 1 && EAcol == 2 && toEARow == screen52.getRows() && toEACol == screen52.getCols()) screen52.clearScreen(); else { int times = ((toEARow * screen52.getCols()) + toEACol) - ((EArow * screen52.getCols()) + EAcol); while (times-- >= 0) { screen52.setChar(EAAttr); } } break; case 04: // Command - Escape done = true; break; case 16: // TD - Transparent Data bk.getNextByte(); int j = bk.getNextByte(); // length while (j-- > 0) bk.getNextByte(); break; case 17: // SBA - set buffer address order (row column) int saRow = bk.getNextByte(); int saCol = bk.getNextByte() & 0xff; // make sure it is in bounds if (saRow >= 0 && saRow <= screen52.getRows() && saCol >= 0 && saCol <= screen52.getCols()) { screen52.goto_XY(saRow,saCol); // now set screen position for output } else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x22,"invalid row/col order" + " saRow = " + saRow + " saRows = " + screen52.getRows() + " saCol = " + saCol); error = true; } break; case 18: // WEA - Extended Attribute bk.getNextByte(); bk.getNextByte(); break; case 19: // IC - Insert Cursor case 20: // MC - Move Cursor int icX = bk.getNextByte(); int icY = bk.getNextByte() & 0xff; if (icX >= 0 && icX <= saRows && icY >= 0 && icY <= saCols)// System.out.println(" IC " + icX + " " + icY); screen52.setPendingInsert(true,icX,icY); else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x22," IC/IM position invalid "); error = true; } break; case 21: // WTDSF - Write To Display Structured Field order error = writeToDisplayStructuredField(); break; case 29: // SF - Start of Field int fcw1 = 0; int fcw2 = 0; int ffw1 = 0; int ffw0 = bk.getNextByte() & 0xff; // FFW if ((ffw0 & 0x40) == 0x40) { ffw1 = bk.getNextByte() & 0xff; // FFW 1 fcw1 = bk.getNextByte() & 0xff; // check for field control word if (!isAttribute(fcw1)) { fcw2 = bk.getNextByte() & 0xff; // FCW 2 attr = bk.getNextByte() & 0xff; // attribute field } else { attr = fcw1; // attribute of field fcw1 = 0; } } else { attr = ffw0; } int fLength = (bk.getNextByte() & 0xff) << 8 | bk.getNextByte() & 0xff; screen52.addField(attr,fLength, ffw0,ffw1,fcw1,fcw2); break; default: // all others must be output to screen byte byte0 = bk.getByteOffset(-1); if (isAttribute(byte0)) { screen52.setAttr(byte0); } else { if (!screen52.isStatusErrorCode()) { if (!isData(byte0)) {// if (byte0 == 255) {// sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x42,// " Attempt to send FF to screen");// }// else screen52.setChar(byte0); } else// screen52.setChar(getASCIIChar(byte0)); screen52.setChar(codePage.ebcdic2uni(byte0)); } else { if (byte0 == 0) screen52.setChar(byte0); else screen52.setChar(getASCIIChar(byte0)); } } break; } if (error) done = true; } } catch (Exception e) { System.out.println("write to display " + e.getMessage()); }; processCC1(control1); return error; }
private boolean writeToDisplay(boolean controlsExist) { int pos = 0; boolean error=false; boolean done=false; int attr; byte nextOne; byte control0 = 0; byte control1 = 0; int saRows = screen52.getRows(); int saCols = screen52.getCols(); try { if (controlsExist) { control0 = bk.getNextByte(); control1 = bk.getNextByte(); processCC0(control0); } while (bk.hasNext() && !done) {// pos = bk.getCurrentPos();// int rowc = screen52.getCurrentRow();// int colc = screen52.getCurrentCol(); switch (bk.getNextByte()) { case 1: // SOH - Start of Header Order error = processSOH(); break; case 02: // RA - Repeat to address int row = screen52.getCurrentRow(); int col = screen52.getCurrentCol(); int toRow = bk.getNextByte(); int toCol = bk.getNextByte() & 0xff; if (toRow >= row) { int repeat = bk.getNextByte(); // a little intelligence here I hope if (row == 1 && col == 2 && toRow == screen52.getRows() && toCol == screen52.getCols()) screen52.clearScreen(); else { if (repeat != 0) repeat = getASCIIChar(repeat); int times = ((toRow * screen52.getCols()) + toCol) - ((row * screen52.getCols()) + col); while (times-- >= 0) { screen52.setChar(repeat); } } } else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x23," RA invalid"); error =true; } break; case 03: // EA - Erase to address int EArow = screen52.getCurrentRow(); int EAcol = screen52.getCurrentCol(); int toEARow = bk.getNextByte(); int toEACol = bk.getNextByte() & 0xff; int EALength = bk.getNextByte() & 0xff; while (--EALength > 0) { bk.getNextByte(); } char EAAttr = (char)0; // a little intelligence here I hope if (EArow == 1 && EAcol == 2 && toEARow == screen52.getRows() && toEACol == screen52.getCols()) screen52.clearScreen(); else { int times = ((toEARow * screen52.getCols()) + toEACol) - ((EArow * screen52.getCols()) + EAcol); while (times-- >= 0) { screen52.setChar(EAAttr); } } break; case 04: // Command - Escape done = true; break; case 16: // TD - Transparent Data bk.getNextByte(); int j = bk.getNextByte(); // length while (j-- > 0) bk.getNextByte(); break; case 17: // SBA - set buffer address order (row column) int saRow = bk.getNextByte(); int saCol = bk.getNextByte() & 0xff; // make sure it is in bounds if (saRow >= 0 && saRow <= screen52.getRows() && saCol >= 0 && saCol <= screen52.getCols()) { screen52.goto_XY(saRow,saCol); // now set screen position for output } else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x22,"invalid row/col order" + " saRow = " + saRow + " saRows = " + screen52.getRows() + " saCol = " + saCol); error = true; } break; case 18: // WEA - Extended Attribute bk.getNextByte(); bk.getNextByte(); break; case 19: // IC - Insert Cursor // MC - Move Cursor int icX = bk.getNextByte(); int icY = bk.getNextByte() & 0xff; if (icX >= 0 && icX <= saRows && icY >= 0 && icY <= saCols)// System.out.println(" IC " + icX + " " + icY); screen52.setPendingInsert(true,icX,icY); else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x22," IC/IM position invalid "); error = true; } break; case 21: // WTDSF - Write To Display Structured Field order error = writeToDisplayStructuredField(); break; case 29: // SF - Start of Field int fcw1 = 0; int fcw2 = 0; int ffw1 = 0; int ffw0 = bk.getNextByte() & 0xff; // FFW if ((ffw0 & 0x40) == 0x40) { ffw1 = bk.getNextByte() & 0xff; // FFW 1 fcw1 = bk.getNextByte() & 0xff; // check for field control word if (!isAttribute(fcw1)) { fcw2 = bk.getNextByte() & 0xff; // FCW 2 attr = bk.getNextByte() & 0xff; // attribute field } else { attr = fcw1; // attribute of field fcw1 = 0; } } else { attr = ffw0; } int fLength = (bk.getNextByte() & 0xff) << 8 | bk.getNextByte() & 0xff; screen52.addField(attr,fLength, ffw0,ffw1,fcw1,fcw2); break; default: // all others must be output to screen byte byte0 = bk.getByteOffset(-1); if (isAttribute(byte0)) { screen52.setAttr(byte0); } else { if (!screen52.isStatusErrorCode()) { if (!isData(byte0)) {// if (byte0 == 255) {// sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x42,// " Attempt to send FF to screen");// }// else screen52.setChar(byte0); } else// screen52.setChar(getASCIIChar(byte0)); screen52.setChar(codePage.ebcdic2uni(byte0)); } else { if (byte0 == 0) screen52.setChar(byte0); else screen52.setChar(getASCIIChar(byte0)); } } break; } if (error) done = true; } } catch (Exception e) { System.out.println("write to display " + e.getMessage()); }; processCC1(control1); return error; }
1,923
private boolean writeToDisplay(boolean controlsExist) { int pos = 0; boolean error=false; boolean done=false; int attr; byte nextOne; byte control0 = 0; byte control1 = 0; int saRows = screen52.getRows(); int saCols = screen52.getCols(); try { if (controlsExist) { control0 = bk.getNextByte(); control1 = bk.getNextByte(); processCC0(control0); } while (bk.hasNext() && !done) {// pos = bk.getCurrentPos();// int rowc = screen52.getCurrentRow();// int colc = screen52.getCurrentCol(); switch (bk.getNextByte()) { case 1: // SOH - Start of Header Order error = processSOH(); break; case 02: // RA - Repeat to address int row = screen52.getCurrentRow(); int col = screen52.getCurrentCol(); int toRow = bk.getNextByte(); int toCol = bk.getNextByte() & 0xff; if (toRow >= row) { int repeat = bk.getNextByte(); // a little intelligence here I hope if (row == 1 && col == 2 && toRow == screen52.getRows() && toCol == screen52.getCols()) screen52.clearScreen(); else { if (repeat != 0) repeat = getASCIIChar(repeat); int times = ((toRow * screen52.getCols()) + toCol) - ((row * screen52.getCols()) + col); while (times-- >= 0) { screen52.setChar(repeat); } } } else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x23," RA invalid"); error =true; } break; case 03: // EA - Erase to address int EArow = screen52.getCurrentRow(); int EAcol = screen52.getCurrentCol(); int toEARow = bk.getNextByte(); int toEACol = bk.getNextByte() & 0xff; int EALength = bk.getNextByte() & 0xff; while (--EALength > 0) { bk.getNextByte(); } char EAAttr = (char)0; // a little intelligence here I hope if (EArow == 1 && EAcol == 2 && toEARow == screen52.getRows() && toEACol == screen52.getCols()) screen52.clearScreen(); else { int times = ((toEARow * screen52.getCols()) + toEACol) - ((EArow * screen52.getCols()) + EAcol); while (times-- >= 0) { screen52.setChar(EAAttr); } } break; case 04: // Command - Escape done = true; break; case 16: // TD - Transparent Data bk.getNextByte(); int j = bk.getNextByte(); // length while (j-- > 0) bk.getNextByte(); break; case 17: // SBA - set buffer address order (row column) int saRow = bk.getNextByte(); int saCol = bk.getNextByte() & 0xff; // make sure it is in bounds if (saRow >= 0 && saRow <= screen52.getRows() && saCol >= 0 && saCol <= screen52.getCols()) { screen52.goto_XY(saRow,saCol); // now set screen position for output } else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x22,"invalid row/col order" + " saRow = " + saRow + " saRows = " + screen52.getRows() + " saCol = " + saCol); error = true; } break; case 18: // WEA - Extended Attribute bk.getNextByte(); bk.getNextByte(); break; case 19: // IC - Insert Cursor case 20: // MC - Move Cursor int icX = bk.getNextByte(); int icY = bk.getNextByte() & 0xff; if (icX >= 0 && icX <= saRows && icY >= 0 && icY <= saCols)// System.out.println(" IC " + icX + " " + icY); screen52.setPendingInsert(true,icX,icY); else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x22," IC/IM position invalid "); error = true; } break; case 21: // WTDSF - Write To Display Structured Field order error = writeToDisplayStructuredField(); break; case 29: // SF - Start of Field int fcw1 = 0; int fcw2 = 0; int ffw1 = 0; int ffw0 = bk.getNextByte() & 0xff; // FFW if ((ffw0 & 0x40) == 0x40) { ffw1 = bk.getNextByte() & 0xff; // FFW 1 fcw1 = bk.getNextByte() & 0xff; // check for field control word if (!isAttribute(fcw1)) { fcw2 = bk.getNextByte() & 0xff; // FCW 2 attr = bk.getNextByte() & 0xff; // attribute field } else { attr = fcw1; // attribute of field fcw1 = 0; } } else { attr = ffw0; } int fLength = (bk.getNextByte() & 0xff) << 8 | bk.getNextByte() & 0xff; screen52.addField(attr,fLength, ffw0,ffw1,fcw1,fcw2); break; default: // all others must be output to screen byte byte0 = bk.getByteOffset(-1); if (isAttribute(byte0)) { screen52.setAttr(byte0); } else { if (!screen52.isStatusErrorCode()) { if (!isData(byte0)) {// if (byte0 == 255) {// sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x42,// " Attempt to send FF to screen");// }// else screen52.setChar(byte0); } else// screen52.setChar(getASCIIChar(byte0)); screen52.setChar(codePage.ebcdic2uni(byte0)); } else { if (byte0 == 0) screen52.setChar(byte0); else screen52.setChar(getASCIIChar(byte0)); } } break; } if (error) done = true; } } catch (Exception e) { System.out.println("write to display " + e.getMessage()); }; processCC1(control1); return error; }
private boolean writeToDisplay(boolean controlsExist) { int pos = 0; boolean error=false; boolean done=false; int attr; byte nextOne; byte control0 = 0; byte control1 = 0; int saRows = screen52.getRows(); int saCols = screen52.getCols(); try { if (controlsExist) { control0 = bk.getNextByte(); control1 = bk.getNextByte(); processCC0(control0); } while (bk.hasNext() && !done) {// pos = bk.getCurrentPos();// int rowc = screen52.getCurrentRow();// int colc = screen52.getCurrentCol(); switch (bk.getNextByte()) { case 1: // SOH - Start of Header Order error = processSOH(); break; case 02: // RA - Repeat to address int row = screen52.getCurrentRow(); int col = screen52.getCurrentCol(); int toRow = bk.getNextByte(); int toCol = bk.getNextByte() & 0xff; if (toRow >= row) { int repeat = bk.getNextByte(); // a little intelligence here I hope if (row == 1 && col == 2 && toRow == screen52.getRows() && toCol == screen52.getCols()) screen52.clearScreen(); else { if (repeat != 0) repeat = getASCIIChar(repeat); int times = ((toRow * screen52.getCols()) + toCol) - ((row * screen52.getCols()) + col); while (times-- >= 0) { screen52.setChar(repeat); } } } else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x23," RA invalid"); error =true; } break; case 03: // EA - Erase to address int EArow = screen52.getCurrentRow(); int EAcol = screen52.getCurrentCol(); int toEARow = bk.getNextByte(); int toEACol = bk.getNextByte() & 0xff; int EALength = bk.getNextByte() & 0xff; while (--EALength > 0) { bk.getNextByte(); } char EAAttr = (char)0; // a little intelligence here I hope if (EArow == 1 && EAcol == 2 && toEARow == screen52.getRows() && toEACol == screen52.getCols()) screen52.clearScreen(); else { int times = ((toEARow * screen52.getCols()) + toEACol) - ((EArow * screen52.getCols()) + EAcol); while (times-- >= 0) { screen52.setChar(EAAttr); } } break; case 04: // Command - Escape done = true; break; case 16: // TD - Transparent Data bk.getNextByte(); int j = bk.getNextByte(); // length while (j-- > 0) bk.getNextByte(); break; case 17: // SBA - set buffer address order (row column) int saRow = bk.getNextByte(); int saCol = bk.getNextByte() & 0xff; // make sure it is in bounds if (saRow >= 0 && saRow <= screen52.getRows() && saCol >= 0 && saCol <= screen52.getCols()) { screen52.goto_XY(saRow,saCol); // now set screen position for output } else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x22,"invalid row/col order" + " saRow = " + saRow + " saRows = " + screen52.getRows() + " saCol = " + saCol); error = true; } break; case 18: // WEA - Extended Attribute bk.getNextByte(); bk.getNextByte(); break; case 19: // IC - Insert Cursor case 20: // MC - Move Cursor int icX = bk.getNextByte(); int icY = bk.getNextByte() & 0xff; if (icX >= 0 && icX <= saRows && icY >= 0 && icY <= saCols) {// System.out.println(" IC " + icX + " " + icY); screen52.setPendingInsert(true,icX,icY); else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x22," IC/IM position invalid "); error = true; } break; case 21: // WTDSF - Write To Display Structured Field order error = writeToDisplayStructuredField(); break; case 29: // SF - Start of Field int fcw1 = 0; int fcw2 = 0; int ffw1 = 0; int ffw0 = bk.getNextByte() & 0xff; // FFW if ((ffw0 & 0x40) == 0x40) { ffw1 = bk.getNextByte() & 0xff; // FFW 1 fcw1 = bk.getNextByte() & 0xff; // check for field control word if (!isAttribute(fcw1)) { fcw2 = bk.getNextByte() & 0xff; // FCW 2 attr = bk.getNextByte() & 0xff; // attribute field } else { attr = fcw1; // attribute of field fcw1 = 0; } } else { attr = ffw0; } int fLength = (bk.getNextByte() & 0xff) << 8 | bk.getNextByte() & 0xff; screen52.addField(attr,fLength, ffw0,ffw1,fcw1,fcw2); break; default: // all others must be output to screen byte byte0 = bk.getByteOffset(-1); if (isAttribute(byte0)) { screen52.setAttr(byte0); } else { if (!screen52.isStatusErrorCode()) { if (!isData(byte0)) {// if (byte0 == 255) {// sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x42,// " Attempt to send FF to screen");// }// else screen52.setChar(byte0); } else// screen52.setChar(getASCIIChar(byte0)); screen52.setChar(codePage.ebcdic2uni(byte0)); } else { if (byte0 == 0) screen52.setChar(byte0); else screen52.setChar(getASCIIChar(byte0)); } } break; } if (error) done = true; } } catch (Exception e) { System.out.println("write to display " + e.getMessage()); }; processCC1(control1); return error; }
1,924
public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant, boolean use_forwarding ) throws ServantAlreadyActive, ObjectAlreadyActive, WrongPolicy { checkDiscarding(); required(ServantRetentionPolicyValue.RETAIN); // If the UNIQUE_ID applies, the servant being passed must not be // already active. if (applies(IdUniquenessPolicyValue.UNIQUE_ID)) { activeObjectMap.Obj sx = aom.findServant(a_servant, false); if (sx != null) throw new ServantAlreadyActive(); } activeObjectMap.Obj exists = aom.get(an_Object_Id); if (exists != null) { if (exists.servant == null) { locateServant(an_Object_Id, a_servant, exists, use_forwarding); exists.setDeactivated(false); } else if (exists.isDeactiveted()) { exists.setDeactivated(false); incarnate(exists, an_Object_Id, a_servant, use_forwarding); } else throw new ObjectAlreadyActive(); } else { servantDelegate delegate = new servantDelegate(a_servant, this, an_Object_Id); connectDelegate(an_Object_Id, delegate); } }
public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant, boolean use_forwarding ) throws ServantAlreadyActive, ObjectAlreadyActive, WrongPolicy { checkDiscarding(); required(ServantRetentionPolicyValue.RETAIN); // If the UNIQUE_ID applies, the servant being passed must not be // already active. if (applies(IdUniquenessPolicyValue.UNIQUE_ID)) { activeObjectMap.Obj sx = aom.findServant(a_servant, false); if (sx != null) throw new ServantAlreadyActive(); } activeObjectMap.Obj exists = aom.get(an_Object_Id); if (exists != null) { if (exists.servant == null) { locateServant(an_Object_Id, a_servant, exists, use_forwarding); exists.setDeactivated(false); } else if (exists.isDeactiveted()) { exists.setDeactivated(false); incarnate(exists, an_Object_Id, a_servant, use_forwarding); } else throw new ObjectAlreadyActive(); } else { servantDelegate delegate = new servantDelegate(a_servant, this, an_Object_Id); connectDelegate(an_Object_Id, delegate); } }
1,926
public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant, boolean use_forwarding ) throws ServantAlreadyActive, ObjectAlreadyActive, WrongPolicy { checkDiscarding(); required(ServantRetentionPolicyValue.RETAIN); // If the UNIQUE_ID applies, the servant being passed must not be // already active. if (applies(IdUniquenessPolicyValue.UNIQUE_ID)) { activeObjectMap.Obj sx = aom.findServant(a_servant, false); if (sx != null) throw new ServantAlreadyActive(); } activeObjectMap.Obj exists = aom.get(an_Object_Id); if (exists != null) { if (exists.servant == null) { locateServant(an_Object_Id, a_servant, exists, use_forwarding); exists.setDeactivated(false); } else if (exists.isDeactiveted()) { exists.setDeactivated(false); incarnate(exists, an_Object_Id, a_servant, use_forwarding); } else throw new ObjectAlreadyActive(); } else { servantDelegate delegate = new servantDelegate(a_servant, this, an_Object_Id); connectDelegate(an_Object_Id, delegate); } }
public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant, boolean use_forwarding ) throws ServantAlreadyActive, ObjectAlreadyActive, WrongPolicy { checkDiscarding(); required(ServantRetentionPolicyValue.RETAIN); // If the UNIQUE_ID applies, the servant being passed must not be // already active. if (applies(IdUniquenessPolicyValue.UNIQUE_ID)) { activeObjectMap.Obj sx = aom.findServant(a_servant, false); if (sx != null) throw new ServantAlreadyActive(); } activeObjectMap.Obj exists = aom.get(an_Object_Id); if (exists != null) { if (exists.servant == null) { locateServant(an_Object_Id, a_servant, exists, use_forwarding); exists.setDeactivated(false); } else if (exists.isDeactiveted()) { exists.setDeactivated(false); incarnate(exists, an_Object_Id, a_servant, use_forwarding); } else throw new ObjectAlreadyActive(); } else { servantDelegate delegate = new servantDelegate(a_servant, this, an_Object_Id); connectDelegate(an_Object_Id, delegate); } }
1,927
public TRANSIENT(String reason, int minor, CompletionStatus completed) { super(reason, minor, completed); }
public TRANSIENT(String message) { super(reason, minor, completed); }
1,928
public TRANSIENT(String reason, int minor, CompletionStatus completed) { super(reason, minor, completed); }
public TRANSIENT(String reason, int minor, CompletionStatus completed) { super(message, 0, CompletionStatus.COMPLETED_NO); }
1,929
public void setLocation(Point2D p) { setLocation(p.getX(), p.getY()); }
public void setLocation(Point2D p) { setLocation(p.getX(), p.getY()); }
1,930
public Dimension getPreferredSize(JComponent c) { if (isAcceleratorHidden()) return super.getPreferredSize(c); else { Insets insets = c.getInsets(); JToolTip tt = (JToolTip) c; String tipText = tt.getTipText(); if (tipText != null) { FontMetrics fm = c.getFontMetrics(c.getFont()); int prefH = fm.getHeight() + insets.top + insets.bottom; int prefW = fm.stringWidth(tipText) + insets.left + insets.right; // this seems to be the first opportunity we have to get the // accelerator string from the component (if it has one) acceleratorString = fetchAcceleratorString(c); if (acceleratorString != null) { prefW += padSpaceBetweenStrings; fm = c.getFontMetrics(acceleratorFont); prefW += fm.stringWidth(acceleratorString); } return new Dimension(prefW, prefH); } else return new Dimension(0, 0); } }
public Dimension getPreferredSize(JComponent c) { if (isAcceleratorHidden()) return super.getPreferredSize(c); else { Insets insets = c.getInsets(); JToolTip tt = (JToolTip) c; String tipText = tt.getTipText(); if (tipText != null) { FontMetrics fm = c.getFontMetrics(c.getFont()); int prefH = fm.getHeight() + insets.top + insets.bottom; int prefW = fm.stringWidth(tipText) + insets.left + insets.right; // this seems to be the first opportunity we have to get the // accelerator string from the component (if it has one) acceleratorString = fetchAcceleratorString(c); if (acceleratorString != null) { prefW += padSpaceBetweenStrings; fm = c.getFontMetrics(acceleratorFont); prefW += fm.stringWidth(acceleratorString); } return new Dimension(prefW, prefH); } else return new Dimension(0, 0); } }
1,931
public Dimension getPreferredSize(JComponent c) { if (isAcceleratorHidden()) return super.getPreferredSize(c); else { Insets insets = c.getInsets(); JToolTip tt = (JToolTip) c; String tipText = tt.getTipText(); if (tipText != null) { FontMetrics fm = c.getFontMetrics(c.getFont()); int prefH = fm.getHeight() + insets.top + insets.bottom; int prefW = fm.stringWidth(tipText) + insets.left + insets.right; // this seems to be the first opportunity we have to get the // accelerator string from the component (if it has one) acceleratorString = fetchAcceleratorString(c); if (acceleratorString != null) { prefW += padSpaceBetweenStrings; fm = c.getFontMetrics(acceleratorFont); prefW += fm.stringWidth(acceleratorString); } return new Dimension(prefW, prefH); } else return new Dimension(0, 0); } }
public Dimension getPreferredSize(JComponent c) { if (isAcceleratorHidden()) return super.getPreferredSize(c); else { Insets insets = c.getInsets(); JToolTip tt = (JToolTip) c; String tipText = tt.getTipText(); if (tipText != null) { FontMetrics fm = c.getFontMetrics(c.getFont()); int prefH = fm.getHeight() + insets.top + insets.bottom; int prefW = fm.stringWidth(tipText) + insets.left + insets.right; // this seems to be the first opportunity we have to get the // accelerator string from the component (if it has one) acceleratorString = fetchAcceleratorString(c); if (acceleratorString != null) { prefW += padSpaceBetweenStrings; fm = c.getFontMetrics(acceleratorFont); prefW += fm.stringWidth(acceleratorString); } return new Dimension(prefW, prefH); } else return new Dimension(0, 0); } }
1,932
public void paint(Graphics g, JComponent c) { JToolTip tip = (JToolTip) c; String text = tip.getTipText(); Toolkit t = tip.getToolkit(); if (text == null) return; Rectangle vr = new Rectangle(); vr = SwingUtilities.calculateInnerArea(tip, vr); Rectangle ir = new Rectangle(); Rectangle tr = new Rectangle(); FontMetrics fm = t.getFontMetrics(tip.getFont()); int ascent = fm.getAscent(); SwingUtilities.layoutCompoundLabel(tip, fm, text, null, SwingConstants.CENTER, SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.CENTER, vr, ir, tr, 0); Color saved = g.getColor(); g.setColor(Color.BLACK); g.drawString(text, vr.x, vr.y + ascent); // paint accelerator if (acceleratorString != null) { g.setFont(acceleratorFont); g.setColor(acceleratorForeground); fm = t.getFontMetrics(acceleratorFont); int width = fm.stringWidth(acceleratorString); g.drawString(acceleratorString, vr.x + vr.width - width - padSpaceBetweenStrings / 2, vr.y + vr.height - fm.getDescent()); } g.setColor(saved); }
public void paint(Graphics g, JComponent c) { JToolTip tip = (JToolTip) c; String text = tip.getTipText(); Toolkit t = tip.getToolkit(); if (text == null) return; Rectangle vr = new Rectangle(); vr = SwingUtilities.calculateInnerArea(tip, vr); Rectangle ir = new Rectangle(); Rectangle tr = new Rectangle(); FontMetrics fm = t.getFontMetrics(tip.getFont()); int ascent = fm.getAscent(); SwingUtilities.layoutCompoundLabel(tip, fm, text, null, SwingConstants.CENTER, SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.CENTER, vr, ir, tr, 0); Color saved = g.getColor(); g.setColor(Color.BLACK); g.drawString(text, vr.x, vr.y + ascent); // paint accelerator if (acceleratorString != null) { g.setFont(acceleratorFont); g.setColor(acceleratorForeground); fm = t.getFontMetrics(acceleratorFont); int width = fm.stringWidth(acceleratorString); g.drawString(acceleratorString, vr.x + vr.width - width - padSpaceBetweenStrings / 2, vr.y + vr.height - fm.getDescent()); } g.setColor(saved); }
1,934