rem
stringlengths 0
477k
| add
stringlengths 0
313k
| context
stringlengths 6
599k
|
---|---|---|
return null; | return new AccessibleJList(); | public AccessibleContext getAccessibleContext() { return null; } |
Object obj = filelist.getSelectedValue(); | Object obj = new String(parentPath + entry.getText()); | public void actionPerformed(ActionEvent e) { Object obj = filelist.getSelectedValue(); if (obj != null) { File f = filechooser.getFileSystemView().createFileObject(obj .toString()); if (filechooser.isTraversable(f) && filechooser.getFileSelectionMode() == JFileChooser.FILES_ONLY) filechooser.setCurrentDirectory(f); else { filechooser.setSelectedFile(f); filechooser.approveSelection(); closeDialog(); } } } |
File f = filechooser.getFileSystemView().createFileObject(obj .toString()); if (filechooser.isTraversable(f) && filechooser.getFileSelectionMode() == JFileChooser.FILES_ONLY) | File f = filechooser.getFileSystemView().createFileObject( obj.toString()); if (filechooser.isTraversable(f) && filechooser.isDirectorySelectionEnabled()) | public void actionPerformed(ActionEvent e) { Object obj = filelist.getSelectedValue(); if (obj != null) { File f = filechooser.getFileSystemView().createFileObject(obj .toString()); if (filechooser.isTraversable(f) && filechooser.getFileSelectionMode() == JFileChooser.FILES_ONLY) filechooser.setCurrentDirectory(f); else { filechooser.setSelectedFile(f); filechooser.approveSelection(); closeDialog(); } } } |
File f = fsv.createFileObject(list.getSelectedValue().toString()); | String path = list.getSelectedValue().toString(); File f = fsv.createFileObject(path); | public void mouseClicked(MouseEvent e) { if (list.getSelectedValue() == null) return; FileSystemView fsv = filechooser.getFileSystemView(); if (timer.isRunning() && list.getSelectedValue().toString().equals(lastSelected.toString())) { File f = fsv.createFileObject(lastSelected.toString()); timer.stop(); if (filechooser.isTraversable(f)) { filechooser.setCurrentDirectory(f); filechooser.rescanCurrentDirectory(); } else { filechooser.setSelectedFile(f); filechooser.approveSelection(); closeDialog(); } } else { File f = fsv.createFileObject(list.getSelectedValue().toString()); if (filechooser.isTraversable(f)) { setDirectorySelected(true); setDirectory(f); } else { setDirectorySelected(false); setDirectory(null); } lastSelected = list.getSelectedValue().toString(); timer.restart(); } } |
lastSelected = list.getSelectedValue().toString(); | lastSelected = path; parentPath = path.substring(0, path.lastIndexOf("/") + 1); entry.setText(path.substring(path.lastIndexOf("/") + 1)); | public void mouseClicked(MouseEvent e) { if (list.getSelectedValue() == null) return; FileSystemView fsv = filechooser.getFileSystemView(); if (timer.isRunning() && list.getSelectedValue().toString().equals(lastSelected.toString())) { File f = fsv.createFileObject(lastSelected.toString()); timer.stop(); if (filechooser.isTraversable(f)) { filechooser.setCurrentDirectory(f); filechooser.rescanCurrentDirectory(); } else { filechooser.setSelectedFile(f); filechooser.approveSelection(); closeDialog(); } } else { File f = fsv.createFileObject(list.getSelectedValue().toString()); if (filechooser.isTraversable(f)) { setDirectorySelected(true); setDirectory(f); } else { setDirectorySelected(false); setDirectory(null); } lastSelected = list.getSelectedValue().toString(); timer.restart(); } } |
JTextField entry = new JTextField(); | entry = new JTextField(); | public void installComponents(JFileChooser fc) { JLabel look = new JLabel("Look In:"); parents = new JComboBox(); parents.setRenderer(new CBLabelRenderer()); boxEntries(); look.setLabelFor(parents); JPanel parentsPanel = new JPanel(); parentsPanel.add(look); parentsPanel.add(parents); JPanel buttonPanel = new JPanel(); upFolderButton = new JButton(); upFolderButton.setIcon(upFolderIcon); buttonPanel.add(upFolderButton); homeFolderButton = new JButton(); homeFolderButton = new JButton(homeFolderIcon); buttonPanel.add(homeFolderButton); newFolderButton = new JButton(); newFolderButton.setIcon(newFolderIcon); buttonPanel.add(newFolderButton); ButtonGroup toggles = new ButtonGroup(); JToggleButton listViewButton = new JToggleButton(); listViewButton.setIcon(listViewIcon); toggles.add(listViewButton); buttonPanel.add(listViewButton); JToggleButton detailsViewButton = new JToggleButton(); detailsViewButton.setIcon(detailsViewIcon); toggles.add(detailsViewButton); buttonPanel.add(detailsViewButton); JPanel topPanel = new JPanel(); topPanel.setLayout(new java.awt.FlowLayout()); topPanel.add(parentsPanel); topPanel.add(buttonPanel); accessoryPanel = new JPanel(); if (filechooser.getAccessory() != null) accessoryPanel.add(filechooser.getAccessory(), BorderLayout.CENTER); filelist = new JList(model); filelist.setVisibleRowCount(6); JScrollPane scrollp = new JScrollPane(filelist); scrollp.setPreferredSize(new Dimension(400, 175)); filelist.setBackground(Color.WHITE); filelist.setLayoutOrientation(JList.VERTICAL_WRAP); filelist.setCellRenderer(new ListLabelRenderer()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; JPanel centrePanel = new JPanel(); centrePanel.setLayout(new GridBagLayout()); centrePanel.add(scrollp, c); c.gridx = 1; centrePanel.add(accessoryPanel, c); JLabel fileNameLabel = new JLabel("File Name:"); JLabel fileTypesLabel = new JLabel("Files of Type:"); JTextField entry = new JTextField(); filters = new JComboBox(); filterEntries(); fileNameLabel.setLabelFor(entry); fileNameLabel.setHorizontalTextPosition(SwingConstants.LEFT); fileTypesLabel.setLabelFor(filters); fileTypesLabel.setHorizontalTextPosition(SwingConstants.LEFT); closePanel = new JPanel(); accept = getApproveButton(filechooser); cancel = new JButton(cancelButtonText); cancel.setMnemonic(cancelButtonMnemonic); cancel.setToolTipText(cancelButtonToolTipText); closePanel.add(accept); closePanel.add(cancel); c.anchor = GridBagConstraints.WEST; c.weighty = 0; c.weightx = 0; c.gridx = 0; bottomPanel = new JPanel(); bottomPanel.setLayout(new GridBagLayout()); bottomPanel.add(fileNameLabel, c); c.gridy = 1; bottomPanel.add(fileTypesLabel, c); c.gridx = 1; c.gridy = 0; c.weightx = 1; c.weighty = 1; bottomPanel.add(entry, c); c.gridy = 1; bottomPanel.add(filters, c); c.fill = GridBagConstraints.NONE; c.gridy = 2; c.anchor = GridBagConstraints.EAST; bottomPanel.add(closePanel, c); filechooser.setLayout(new BorderLayout()); filechooser.add(topPanel, BorderLayout.NORTH); filechooser.add(centrePanel, BorderLayout.CENTER); filechooser.add(bottomPanel, BorderLayout.SOUTH); } |
Object path = filechooser.getCurrentDirectory(); if (path != null) parentPath = path.toString().substring(path.toString().lastIndexOf("/")); | public void installUI(JComponent c) { if (c instanceof JFileChooser) { JFileChooser fc = (JFileChooser) c; fc.resetChoosableFileFilters(); createModel(); clearIconCache(); installDefaults(fc); installComponents(fc); installListeners(fc); } } |
|
newaxis.setAxisId(null); | newaxis.setAxisId(findUniqueIdName(AxisObj,newaxis.getAxisId())); AxisObj.put(newaxis.getAxisId(), newaxis); | public Object action (SaxDocumentHandler handler, AttributeList attrs) { // create new object appropriately Axis newaxis = new Axis(); newaxis.setXMLAttributes(attrs); // set XML attributes from passed list // Every axis must have *either* axisId *or* an axisIdRef // else, its illegal! String axisId = null; String axisIdRef = null; if ( (axisId = newaxis.getAxisId()) != null || (axisIdRef = newaxis.getAxisIdRef()) != null ) { // add this object to the lookup table, if it has an ID if (axisId != null) { // a warning check, just in case if (AxisObj.containsKey(axisId)) Log.warnln("More than one axis node with axisId=\""+axisId+"\", using latest node." ); // add this into the list of axis objects AxisObj.put(axisId, newaxis); } // If there is a reference object, clone it to get // the new axis if (axisIdRef != null) { if (AxisObj.containsKey(axisIdRef)) { BaseObject refAxisObj = (BaseObject) AxisObj.get(axisIdRef); try { newaxis = (Axis) refAxisObj.clone(); } catch (java.lang.CloneNotSupportedException e) { Log.errorln("Weird error, cannot clone axis object. Aborting read."); System.exit(-1); } // override attrs with those in passed list newaxis.setXMLAttributes(attrs); newaxis.setAxisId(null); // shouldnt have the axisId from refObj } else { Log.warnln("Error: Reader got an axis with AxisIdRef=\""+axisIdRef+"\" but no previous axis has that id! Ignoring add axis request."); return (Object) null; } } // add this axis to the current array object CurrentArray.addAxis(newaxis); // I dont believe this is actually used // CurrentDatatypeObject = newaxis; } else { Log.errorln("Axis object:"+newaxis+" lacks either axisId or axisIdRef, ignoring!"); } return newaxis; } |
List iterationList = myLocator.getIterationOrder(); Iterator liter = iterationList.iterator(); while (liter.hasNext()) { Axis axis = (Axis) liter.next(); Log.errorln("ITERATION AXIS NAME:"+axis.getName()); } | public void action (SaxDocumentHandler handler) { // we stopped reading datanode, lower count by one DataNodeLevel--; // we might still be nested within a data node // if so, return now to accumulate more data within the DATABLOCK if(DataNodeLevel != 0) return; // now we are ready to read in untagged data (both delimited/formmatted styles) // from the DATABLOCK // Note: unfortunately we are reduced to using regex style matching // instead of a buffer read in formatted reads. Come back and // improve this later if possible. XMLDataIOStyle formatObj = CurrentArray.getXMLDataIOStyle(); if ( formatObj instanceof DelimitedXMLDataIOStyle || formatObj instanceof FormattedXMLDataIOStyle ) { // determine the size of the dataFormat (s) in our dataCube if (CurrentArray.hasFieldAxis()) { // if there is a field axis, then its set to the number of fields FieldAxis fieldAxis = CurrentArray.getFieldAxis(); MaxDataFormatIndex = (fieldAxis.getLength()-1); } else { // its homogeneous MaxDataFormatIndex = 0; } Locator myLocator = CurrentArray.createLocator();List iterationList = myLocator.getIterationOrder();Iterator liter = iterationList.iterator();while (liter.hasNext()) { Axis axis = (Axis) liter.next(); Log.errorln("ITERATION AXIS NAME:"+axis.getName());} myLocator.setIterationOrder(AxisReadOrder); CurrentDataFormatIndex = 0; ArrayList strValueList;// boolean dataHasSpecialIntegers = false; // set up appropriate instructions for reading if ( formatObj instanceof FormattedXMLDataIOStyle ) {/* $template = $formatObj->_templateNotation(1); $recordSize = $formatObj->bytes(); $data_has_special_integers = $formatObj->hasSpecialIntegers;*/ // snag the string representation of the values strValueList = formattedSplitStringIntoStringObjects( DATABLOCK.toString(), ((FormattedXMLDataIOStyle) formatObj) ); if (strValueList.size() == 0) { Log.errorln("Error: XDF Reader is unable to acquire formatted data, bad format?"); System.exit(-1); } } else { // snag the string representation of the values strValueList = splitStringIntoStringObjects( DATABLOCK.toString(), ((DelimitedXMLDataIOStyle) formatObj).getDelimiter(), ((DelimitedXMLDataIOStyle) formatObj).getRepeatable(), ((DelimitedXMLDataIOStyle) formatObj).getRecordTerminator() ); } // fire data into dataCube Iterator iter = strValueList.iterator(); while (iter.hasNext()) { DataFormat CurrentDataFormat = DataFormatList[CurrentDataFormatIndex]; // adding data based on what type.. addDataToCurrentArray(myLocator, (String) iter.next(), CurrentDataFormat); // bump up DataFormat appropriately if (MaxDataFormatIndex > 0) { int currentFastAxisCoordinate = myLocator.getAxisLocation(FastestAxis); if ( currentFastAxisCoordinate != LastFastAxisCoordinate ) { LastFastAxisCoordinate = currentFastAxisCoordinate; if (CurrentDataFormatIndex == MaxDataFormatIndex) CurrentDataFormatIndex = 0; else CurrentDataFormatIndex++; } } myLocator.next(); } } else if ( formatObj instanceof TaggedXMLDataIOStyle ) { // Tagged case: do nothing } else { Log.errorln("ERROR: Completely unknown DATA IO style:"+formatObj.toString() +" aborting read!"); System.exit(-1); } } |
|
addDataToCurrentArray(myLocator, (String) iter.next(), CurrentDataFormat); | String thisData = (String) iter.next(); addDataToCurrentArray(myLocator, thisData, CurrentDataFormat); | public void action (SaxDocumentHandler handler) { // we stopped reading datanode, lower count by one DataNodeLevel--; // we might still be nested within a data node // if so, return now to accumulate more data within the DATABLOCK if(DataNodeLevel != 0) return; // now we are ready to read in untagged data (both delimited/formmatted styles) // from the DATABLOCK // Note: unfortunately we are reduced to using regex style matching // instead of a buffer read in formatted reads. Come back and // improve this later if possible. XMLDataIOStyle formatObj = CurrentArray.getXMLDataIOStyle(); if ( formatObj instanceof DelimitedXMLDataIOStyle || formatObj instanceof FormattedXMLDataIOStyle ) { // determine the size of the dataFormat (s) in our dataCube if (CurrentArray.hasFieldAxis()) { // if there is a field axis, then its set to the number of fields FieldAxis fieldAxis = CurrentArray.getFieldAxis(); MaxDataFormatIndex = (fieldAxis.getLength()-1); } else { // its homogeneous MaxDataFormatIndex = 0; } Locator myLocator = CurrentArray.createLocator();List iterationList = myLocator.getIterationOrder();Iterator liter = iterationList.iterator();while (liter.hasNext()) { Axis axis = (Axis) liter.next(); Log.errorln("ITERATION AXIS NAME:"+axis.getName());} myLocator.setIterationOrder(AxisReadOrder); CurrentDataFormatIndex = 0; ArrayList strValueList;// boolean dataHasSpecialIntegers = false; // set up appropriate instructions for reading if ( formatObj instanceof FormattedXMLDataIOStyle ) {/* $template = $formatObj->_templateNotation(1); $recordSize = $formatObj->bytes(); $data_has_special_integers = $formatObj->hasSpecialIntegers;*/ // snag the string representation of the values strValueList = formattedSplitStringIntoStringObjects( DATABLOCK.toString(), ((FormattedXMLDataIOStyle) formatObj) ); if (strValueList.size() == 0) { Log.errorln("Error: XDF Reader is unable to acquire formatted data, bad format?"); System.exit(-1); } } else { // snag the string representation of the values strValueList = splitStringIntoStringObjects( DATABLOCK.toString(), ((DelimitedXMLDataIOStyle) formatObj).getDelimiter(), ((DelimitedXMLDataIOStyle) formatObj).getRepeatable(), ((DelimitedXMLDataIOStyle) formatObj).getRecordTerminator() ); } // fire data into dataCube Iterator iter = strValueList.iterator(); while (iter.hasNext()) { DataFormat CurrentDataFormat = DataFormatList[CurrentDataFormatIndex]; // adding data based on what type.. addDataToCurrentArray(myLocator, (String) iter.next(), CurrentDataFormat); // bump up DataFormat appropriately if (MaxDataFormatIndex > 0) { int currentFastAxisCoordinate = myLocator.getAxisLocation(FastestAxis); if ( currentFastAxisCoordinate != LastFastAxisCoordinate ) { LastFastAxisCoordinate = currentFastAxisCoordinate; if (CurrentDataFormatIndex == MaxDataFormatIndex) CurrentDataFormatIndex = 0; else CurrentDataFormatIndex++; } } myLocator.next(); } } else if ( formatObj instanceof TaggedXMLDataIOStyle ) { // Tagged case: do nothing } else { Log.errorln("ERROR: Completely unknown DATA IO style:"+formatObj.toString() +" aborting read!"); System.exit(-1); } } |
LastFastAxisCoordinate = 0; | LastFastAxisCoordinate = -1; | public Object action (SaxDocumentHandler handler, AttributeList attrs) { // we only need to do these things for the first time we enter // a data node if (DataNodeLevel == 0) { // update the array dataCube with passed attributes CurrentArray.getDataCube().setXMLAttributes(attrs); // determine the size of the dataFormat (s) in our dataCube if (CurrentArray.hasFieldAxis()) { // if there is a field axis, then its set to the number of fields FieldAxis fieldAxis = CurrentArray.getFieldAxis(); MaxDataFormatIndex = (fieldAxis.getLength()-1); } else { // its homogeneous MaxDataFormatIndex = 0; } // reset to start of which dataformat type we currently are reading CurrentDataFormatIndex = 0; // reset the list of dataformats we are reading DataFormatList = CurrentArray.getDataFormatList(); } XMLDataIOStyle readObj = CurrentArray.getXMLDataIOStyle(); FastestAxis = (AxisInterface) CurrentArray.getAxisList().get(0); LastFastAxisCoordinate = 0; if ( readObj instanceof TaggedXMLDataIOStyle) { TaggedLocatorObj = CurrentArray.createLocator(); } else { // A safety. We clear datablock when this is the first datanode we // have entered DATABLOCK is used in cases where we read in untagged data if (DataNodeLevel == 0) DATABLOCK = new StringBuffer (); } // entered a datanode, raise the count // this (partially helps) declare we are now reading data, DataNodeLevel++; return readObj; } |
newfieldaxis.setAxisId(findUniqueIdName(AxisObj, newfieldaxis.getAxisId())); AxisObj.put(newfieldaxis.getAxisId(), newfieldaxis); | public Object action (SaxDocumentHandler handler, AttributeList attrs) { // create new object appropriately FieldAxis newfieldaxis = new FieldAxis(); newfieldaxis.setXMLAttributes(attrs); // set XML attributes from passed list // Every axis must have *either* axisId *or* an axisIdRef // else, its illegal! String axisId = null; String axisIdRef = null; if ( (axisId = newfieldaxis.getAxisId()) != null || (axisIdRef = newfieldaxis.getAxisIdRef()) != null ) { // add this object to the lookup table, if it has an ID if (axisId != null) { // a warning check, just in case if (AxisObj.containsKey(axisId)) Log.warnln("More than one axis node with axisId=\""+axisId+"\", using latest node." ); // add this into the list of axis objects AxisObj.put(axisId, newfieldaxis); } // If there is a reference object, clone it to get // the new axis if (axisIdRef != null) { if (AxisObj.containsKey(axisIdRef)) { BaseObject refAxisObj = (BaseObject) AxisObj.get(axisIdRef); try { newfieldaxis = (FieldAxis) refAxisObj.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 newfieldaxis.setXMLAttributes(attrs); } else { Log.warnln("Error: Reader got an fieldaxis with AxisIdRef=\""+axisIdRef+"\" but no previous field axis has that id! Ignoring add fieldAxis request."); return (Object) null; } } // add this axis to the current array object CurrentArray.addFieldAxis(newfieldaxis); } else { Log.errorln("FieldAxis object:"+newfieldaxis+" lacks either axisId or axisIdRef, ignoring!"); } return newfieldaxis; } |
|
newfield.setFieldId(null); | newfield.setFieldId(findUniqueIdName(FieldObj, newfield.getFieldId())); FieldObj.put(newfield.getFieldId(), 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(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; } |
newnote.setNoteId(null); | newnote.setNoteId(findUniqueIdName(NoteObj, newnote.getNoteId())); NoteObj.put(newnote.getNoteId(), 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(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; } |
FormattedXMLDataIOStyle readObj = new FormattedXMLDataIOStyle (CurrentArray, DataIOStyleAttribs); | 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; } } | 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; } |
AxisInterface FastAxis = (AxisInterface) CurrentArray.getAxisList().get(0); AxisInterface SlowAxis = (AxisInterface) CurrentArray.getAxisList().get(1); | 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); } } |
|
Log.errorln("setData:["+thisString+"]["+dataLocator.getAxisLocation(FastAxis)+","+dataLocator.getAxisLocation(SlowAxis)+"]"); | 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); } } |
|
Log.debugln("Got Data:["+thisData+"] ("+dataPosition+","+endDataPosition+")"); | Log.debugln("Got Formatted DataCell:["+thisData+"]"); | 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; } |
super.remove(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); | public void remove(Component component) { super.remove(component); } |
public void setModel(SingleSelectionModel model) | public void setModel(SingleSelectionModel m) | 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); } } |
if (model != this.model) | if (m != 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); } } |
this.model.removeChangeListener(changeListener); this.model = model; this.model.addChangeListener(changeListener); | if (oldModel != null && changeListener != null) oldModel.removeChangeListener(changeListener); model = m; if (model != null) { if (changeListener != null) changeListener = createChangeListener(); model.addChangeListener(changeListener); } | 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); } } |
throws NotImplementedException | protected void decodeLineStyle(Object lineStyleFlag) throws NotImplementedException { // FIXME: not implemented } |
|
if (lineStyleFlag == null || lineStyleFlag.equals(LINE_STYLE_VALUE_ANGLED)) lineStyle = LINE_STYLE_ANGLED; else if (lineStyleFlag.equals(LINE_STYLE_VALUE_HORIZONTAL)) lineStyle = LINE_STYLE_HORIZONTAL; else if (lineStyleFlag.equals(LINE_STYLE_VALUE_NONE)) lineStyle = LINE_STYLE_NONE; else lineStyle = LINE_STYLE_ANGLED; | protected void decodeLineStyle(Object lineStyleFlag) throws NotImplementedException { // FIXME: not implemented } |
|
Object lineStyleProp = c.getClientProperty(LINE_STYLE_PROPERTY); decodeLineStyle(lineStyleProp); if (lineStyleListener == null) lineStyleListener = new LineStyleListener(); c.addPropertyChangeListener(lineStyleListener); | public void installUI(JComponent c) { // TODO: What to do here, if anything? super.installUI(c); } |
|
if (lineStyle == LINE_STYLE_HORIZONTAL) paintHorizontalSeparators(g, c); | public void paint(Graphics g, JComponent c) { // Calls BasicTreeUI's paint since it takes care of painting all // types of icons. super.paint(g, c); } |
|
if (lineStyle == LINE_STYLE_ANGLED) | protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) { super.paintHorizontalPartOfLeg(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf); } |
|
throws NotImplementedException | protected void paintHorizontalSeparators(Graphics g, JComponent c) throws NotImplementedException { // FIXME: not implemented } |
|
g.setColor(UIManager.getColor("Tree.line")); Rectangle clip = g.getClipBounds(); int row0 = getRowForPath(tree, getClosestPathForLocation(tree, 0, clip.y)); int row1 = getRowForPath(tree, getClosestPathForLocation(tree, 0, clip.y + clip.height - 1)); if (row0 >= 0 && row1 >= 0) { for (int i = row0; i <= row1; i++) { TreePath p = getPathForRow(tree, i); if (p != null && p.getPathCount() == 2) { Rectangle r = getPathBounds(tree, getPathForRow(tree, i)); if (r != null) { g.drawLine(clip.x, r.y, clip.x + clip.width, r.y); } } } } | protected void paintHorizontalSeparators(Graphics g, JComponent c) throws NotImplementedException { // FIXME: not implemented } |
|
if (lineStyle == LINE_STYLE_ANGLED) | protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path) { super.paintVerticalPartOfLeg(g, clipBounds, insets, path); } |
|
if (lineStyleListener != null) c.removePropertyChangeListener(lineStyleListener); lineStyleListener = null; | public void uninstallUI(JComponent c) { // TODO: What to do here? super.uninstallUI(c); } |
|
keys.setKey(51, new Key('w', 'M',KeyEvent.VK_M)); | keys.setKey(51, new Key('w', 'W',KeyEvent.VK_M)); | 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)); } |
private int loadLib(String filename) | private static int loadLib(String filename) | private int loadLib(String filename) { SecurityManager sm = securityManager; // Be thread-safe! if (sm != null) sm.checkLink(filename); return VMRuntime.nativeLoad(filename); } |
sm.checkLink(filename); | sm.checkRead(filename); | private int loadLib(String filename) { SecurityManager sm = securityManager; // Be thread-safe! if (sm != null) sm.checkLink(filename); return VMRuntime.nativeLoad(filename); } |
return null; | return Registry.RAW_ENCODING_SHORT_NAME; | public String getFormat() { return null; } |
this.ipaddress = addr; | this.ipaddress = this.addr; | Inet6Address(byte[] addr, String host) { super(addr, host); this.ipaddress = addr; } |
Inet6Address tmp = (Inet6Address) obj; return super.equals(tmp) && this.ipaddress == tmp.ipaddress; | return super.equals(obj); | public boolean equals(Object obj) { if (! (obj instanceof Inet6Address)) return false; Inet6Address tmp = (Inet6Address) obj; return super.equals(tmp) && this.ipaddress == tmp.ipaddress; } |
return ipaddress; | return (byte[]) ipaddress.clone(); | public byte[] getAddress() { return ipaddress; } |
addr = new byte[ipaddr.length]; | addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone(); hostName = hostname; | 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 */ } |
for (int i = 0; i < ipaddr.length; i++) addr[i] = ipaddr[i]; this.hostName = hostname; | 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 */ } |
|
dispose(); | public void setClosed(boolean b) throws PropertyVetoException { if (b && ! isClosed()) { fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING); fireVetoableChange(IS_CLOSED_PROPERTY, false, true); isClosed = b; firePropertyChange(IS_CLOSED_PROPERTY, false, true); fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED); } } |
|
} else if (jnodeField.getDeclaringClass().isMagicType()) { | } else if (jnodeField.isAddressType()) { | 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); } } |
os.writeWord(0); | os.setWord(fldOffset, 0); | 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); } } |
os.writeWord(uobj.toLong()); | os.setWord(fldOffset, uobj.toLong()); } else if (value instanceof Label) { final Label lbl = (Label)value; bis.setObjectRef(fldOffset, lbl); | 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); } } |
s.grabFocus(); | 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(); } |
|
int buttonWidth = height - 2; | 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); } |
|
loc -= buttonWidth + 2; closeButton.setBounds(loc, top, buttonWidth, buttonHeight); | int buttonWidth = closeIcon.getIconWidth(); loc -= buttonWidth + 2; closeButton.setBounds(loc, top, buttonWidth, buttonHeight); | 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); } |
loc -= buttonWidth + 2; maxButton.setBounds(loc, top, buttonWidth, buttonHeight); | int buttonWidth = maxIcon.getIconWidth(); loc -= buttonWidth + 2; maxButton.setBounds(loc, top, buttonWidth, buttonHeight); | 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); } |
loc -= buttonWidth + 2; iconButton.setBounds(loc, top, buttonWidth, buttonHeight); | int buttonWidth = iconIcon.getIconWidth(); loc -= buttonWidth + 2; iconButton.setBounds(loc, top, buttonWidth, buttonHeight); | 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); } |
maxButton.setText(null); | protected void createButtons() { closeButton = new PaneButton(closeAction); if (!frame.isClosable()) closeButton.setVisible(false); iconButton = new PaneButton(iconifyAction); if (!frame.isIconifiable()) iconButton.setVisible(false); maxButton = new PaneButton(maximizeAction); if (!frame.isMaximizable()) maxButton.setVisible(false); } |
|
setFont(defaults.getFont("InternalFrame.titleFont")); | title.setFont(defaults.getFont("InternalFrame.titleFont")); | 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"); } |
closeIcon = UIManager.getIcon("InternalFrame.closeIcon"); iconIcon = UIManager.getIcon("InternalFrame.iconifyIcon"); maxIcon = UIManager.getIcon("InternalFrame.maximizeIcon"); | 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"); } |
|
propertyChangeListener = new PropertyChangeHandler(); | propertyChangeListener = createPropertyChangeListener(); | protected void installListeners() { propertyChangeListener = new PropertyChangeHandler(); frame.addPropertyChangeListener(propertyChangeListener); } |
Font f = g.getFont(); FontMetrics fm = g.getFontMetrics(f); | 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); } } |
|
Font f = title.getFont(); g.setFont(f); FontMetrics fm = g.getFontMetrics(f); | 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); } } |
|
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); | if (closeIcon != null) closeButton.setIcon(closeIcon); if (iconIcon != null) iconButton.setIcon(iconIcon); if (maxIcon != null) maxButton.setIcon(maxIcon); | 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); } |
closeIcon = null; iconIcon = null; maxIcon = null; | protected void uninstallDefaults() { setFont(null); selectedTextColor = null; selectedTitleColor = null; notSelectedTextColor = null; notSelectedTitleColor = null; } |
|
arrowButton.setFocusable(false); | public void configureArrowButton() { arrowButton.setEnabled(comboBox.isEnabled()); arrowButton.setFont(comboBox.getFont()); } |
|
comboBox.addFocusListener(focusListener); listBox.addFocusListener(focusListener); | editor.addFocusListener(focusListener); | 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); } |
{ | public void setPopupVisible(JComboBox c, boolean v) { if (v) { popup.show(); popup.getList().requestFocus(); } else popup.hide(); } |
|
popup.getList().requestFocus(); } | public void setPopupVisible(JComboBox c, boolean v) { if (v) { popup.show(); popup.getList().requestFocus(); } else popup.hide(); } |
|
if (comboBox.isEditable()) editor.requestFocus(); else comboBox.requestFocus(); | public void setPopupVisible(JComboBox c, boolean v) { if (v) { popup.show(); popup.getList().requestFocus(); } else popup.hide(); } |
|
if( o == null ) throw new NullPointerException(); | public static Object invoke(VmMethod method, Object o, Object[] args) throws InvocationTargetException { int argCount = method.getNoArguments(); int argsLength = (args == null) ? 0 : args.length; if (argCount != argsLength) { throw new IllegalArgumentException("Invalid number of arguments"); } if (!method.isStatic()) { Unsafe.pushObject(o); } else { method.getDeclaringClass().initialize(); } for (int i = 0; i < argCount; i++) { final VmType<?> argType = method.getArgumentType(i); final Object arg = args[i]; if (argType.isPrimitive()) { int v = 0; long lv = 0; boolean wide = false; if (arg == null) { /* do nothing */ } else if (arg instanceof Boolean) { v = ((Boolean) arg).booleanValue() ? 1 : 0; } else if (arg instanceof Byte) { v = ((Byte) arg).byteValue(); } else if (arg instanceof Character) { v = ((Character) arg).charValue(); } else if (arg instanceof Short) { v = ((Short) arg).shortValue(); } else if (arg instanceof Integer) { v = ((Integer) arg).intValue(); } else if (arg instanceof Long) { lv = ((Long) arg).longValue(); wide = true; } else if (arg instanceof Float) { v = Float.floatToRawIntBits(((Float) arg).floatValue()); } else if (arg instanceof Double) { lv = Double.doubleToRawLongBits(((Double) arg) .doubleValue()); wide = true; } final Class argClass = argType.asClass(); if ((argClass == Long.TYPE) || (argClass == Double.TYPE)) { // Wide argument if (wide) { Unsafe.pushLong(lv); } else { Unsafe.pushLong(v); } } else { // Normal argument if (wide) { Unsafe.pushInt((int) lv); } else { Unsafe.pushInt(v); } } } else { // Non-primitive argument Unsafe.pushObject(arg); } } try { if (method.isReturnVoid()) { Unsafe.invokeVoid(method); return null; } else if (method.isReturnObject()) { return Unsafe.invokeObject(method); } else if (method.isReturnWide()) { long rc = Unsafe.invokeLong(method); final Class<?> retType = method.getReturnType().asClass(); if (Long.TYPE == retType) { return new Long(rc); } else { return new Double(Double.longBitsToDouble(rc)); } } else { int rc = Unsafe.invokeInt(method); final Class retType = method.getReturnType().asClass(); if (Byte.TYPE == retType) { return new Byte((byte) rc); } else if (Boolean.TYPE == retType) { return Boolean.valueOf(rc != 0); } else if (Character.TYPE == retType) { return new Character((char) rc); } else if (Short.TYPE == retType) { return new Short((short) rc); } else if (Float.TYPE == retType) { return new Float(Float.intBitsToFloat(rc)); } else { return new Integer(rc); } } } catch (Throwable ex) { throw new InvocationTargetException(ex); } } |
|
if (value != null) { if (value instanceof JTextField) return new JTextField(((JTextField)value).getText()); super.setText(value.toString()); } else super.setText(""); | setValue(value); | 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; } |
super.setText((value!=null) ? value.toString() : ""); | if (value != null) setText(value.toString()); else setText(""); | protected void setValue(Object value) { super.setText((value!=null) ? value.toString() : ""); } |
public InstantiationException() { super(); | public InstantiationException() { | public InstantiationException() { super(); } |
super(); | this.panel = panel; | public SwingPanelPeer(Panel panel) { super(); SwingToolkit.add(panel, this); SwingToolkit.copyAwtProperties(panel, this); setLayout(null); } |
public final boolean requestFocus(Component lightweightChild, boolean temporary, boolean focusedWindowChangeAllowed, long time) { return true; | public final void requestFocus() { jComponent.requestFocus(); SwingComponentPeer oldFocusPeer; Component fc = toolkit.getFocusHandler().getFocusedComponent(); if (fc != null) { oldFocusPeer = (SwingComponentPeer) fc.getPeer(); } else { oldFocusPeer = null; } toolkit.getFocusHandler().setFocusedComponent((Component) component); if (oldFocusPeer != null && oldFocusPeer.isFocusTraversable()) { } if (isFocusTraversable()) { } | public final boolean requestFocus(Component lightweightChild, boolean temporary, boolean focusedWindowChangeAllowed, long time) { return true; } |
public SwingMenuPeer(SwingToolkit toolkit, Menu menu, JComponent jComponent) { super(toolkit, menu, jComponent); | public SwingMenuPeer(SwingToolkit toolkit, Menu menu) { super(toolkit, menu, new JMenu()); | public SwingMenuPeer(SwingToolkit toolkit, Menu menu, JComponent jComponent) { super(toolkit, menu, jComponent); } |
Iterator it = (Iterator) iterators.get(key); if(it == null) | synchronized(iterators) | 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; } |
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; | 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; } |
return currentField.isHiglightedEntry(); | if (currentField != null) return currentField.isHiglightedEntry(); else return false; | public boolean isCurrentFieldHighlightedEntry() { return currentField.isHiglightedEntry(); } |
masterMDT = currentField.mdt; | if (!masterMDT) masterMDT = currentField.mdt; | 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; } |
protected boolean gotoField(ScreenField f) { if (f != null) { goto_XY(f.startPos()); return true; | public boolean gotoField(int f) { int sizeFields = screenFields.getSize(); if (f > sizeFields || f <= 0) return false; screenFields.setCurrentField(screenFields.getField(f-1)); while (screenFields.isCurrentFieldBypassField() && f < sizeFields) { screenFields.setCurrentField(screenFields.getField(f++)); | protected boolean gotoField(ScreenField f) { if (f != null) { goto_XY(f.startPos()); return true; } else { return false; } } |
else { return false; } | return gotoField(screenFields.getCurrentField()); | protected boolean gotoField(ScreenField f) { if (f != null) { goto_XY(f.startPos()); return true; } else { return false; } } |
public ScreenField setField(int attr, int row, int col, int len, int ffw1, int ffw2, | public ScreenField setField(int attr, int len, int ffw1, int ffw2, | 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; } |
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; | return setField(attr, s.getCurrentRow() - 1, s.getCurrentCol() - 1, len, ffw1, ffw2, fcw1, fcw2); | 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; } |
this.checkBox = checkBox; | public SwingCheckboxPeer(Checkbox checkBox) { SwingToolkit.add(checkBox, this); SwingToolkit.copyAwtProperties(checkBox, this); setText(checkBox.getLabel()); setState(checkBox.getState()); } |
|
Principal[] principals = (Principal[]) subject.getPrincipals().toArray (new Principal[0]); | Principal[] principals = null; if (subject != null) principals = (Principal[]) subject.getPrincipals().toArray (new Principal[0]); | 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()]); } |
synchronized (lock) { | 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); } } |
|
protected void updateImage(Rectangle r) { updateImage(r.x,r.y,r.width,r.height); | protected synchronized void updateImage(int x, int y , int width, int height) { if (gg2d == null) { gg2d = (Graphics2D)gui.getGraphics(); } if (gui.rubberband != null && gui.rubberband.isAreaSelected()) { gui.rubberband.erase(); } if (bi == null || gg2d == null) { if (bi == null) System.out.println("bi was null in update image"); if (gg2d == null) System.out.println("gg2d was null in update image"); return; } g2d.setClip(x,y,width,height); if (!cursorActive && x + width <= bi.getWidth(null) && y + height <= (bi.getHeight(null) - fmWidth)) { paintComponent2(g2d); } if (gui.rubberband != null && gui.rubberband.isAreaSelected()) { gui.rubberband.draw(); } if (x == 0) width += bi.offLeft; else x += bi.offLeft; if (y == 0) height += bi.offTop; else y += bi.offTop; gui.repaint(x,y,width, height); | protected void updateImage(Rectangle r) { updateImage(r.x,r.y,r.width,r.height); } |
if (id == null) throw new NullPointerException(); | public void setID(String id) { this.ID = id; } |
|
timezones0.put("CEST", tz); | static synchronized HashMap timezones() { if (timezones0 == null) { HashMap timezones = new HashMap(); timezones0 = timezones; TimeZone tz; // Automatically generated by scripts/timezones.pl // XXX - Should we read this data from a file? tz = new SimpleTimeZone(-11000 * 3600, "MIT"); timezones0.put("MIT", tz); timezones0.put("Pacific/Apia", tz); timezones0.put("Pacific/Midway", tz); timezones0.put("Pacific/Niue", tz); timezones0.put("Pacific/Pago_Pago", tz); tz = new SimpleTimeZone (-10000 * 3600, "America/Adak", Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("America/Adak", tz); tz = new SimpleTimeZone(-10000 * 3600, "HST"); timezones0.put("HST", tz); timezones0.put("Pacific/Fakaofo", tz); timezones0.put("Pacific/Honolulu", tz); timezones0.put("Pacific/Johnston", tz); timezones0.put("Pacific/Rarotonga", tz); timezones0.put("Pacific/Tahiti", tz); tz = new SimpleTimeZone(-9500 * 3600, "Pacific/Marquesas"); timezones0.put("Pacific/Marquesas", tz); tz = new SimpleTimeZone (-9000 * 3600, "AST", Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("AST", tz); timezones0.put("America/Anchorage", tz); timezones0.put("America/Juneau", tz); timezones0.put("America/Nome", tz); timezones0.put("America/Yakutat", tz); tz = new SimpleTimeZone(-9000 * 3600, "Pacific/Gambier"); timezones0.put("Pacific/Gambier", tz); tz = new SimpleTimeZone (-8000 * 3600, "PST", Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("PST", tz); timezones0.put("PST8PDT", tz); timezones0.put("America/Dawson", tz); timezones0.put("America/Los_Angeles", tz); timezones0.put("America/Tijuana", tz); timezones0.put("America/Vancouver", tz); timezones0.put("America/Whitehorse", tz); timezones0.put("US/Pacific-New", tz); tz = new SimpleTimeZone(-8000 * 3600, "Pacific/Pitcairn"); timezones0.put("Pacific/Pitcairn", tz); tz = new SimpleTimeZone (-7000 * 3600, "MST", Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("MST", tz); timezones0.put("MST7MDT", tz); timezones0.put("America/Boise", tz); timezones0.put("America/Chihuahua", tz); timezones0.put("America/Denver", tz); timezones0.put("America/Edmonton", tz); timezones0.put("America/Inuvik", tz); timezones0.put("America/Mazatlan", tz); timezones0.put("America/Shiprock", tz); timezones0.put("America/Yellowknife", tz); tz = new SimpleTimeZone(-7000 * 3600, "MST7"); timezones0.put("MST7", tz); timezones0.put("PNT", tz); timezones0.put("America/Dawson_Creek", tz); timezones0.put("America/Hermosillo", tz); timezones0.put("America/Phoenix", tz); tz = new SimpleTimeZone (-6000 * 3600, "CST", Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("CST", tz); timezones0.put("CST6CDT", tz); timezones0.put("America/Cambridge_Bay", tz); timezones0.put("America/Cancun", tz); timezones0.put("America/Chicago", tz); timezones0.put("America/Menominee", tz); timezones0.put("America/Merida", tz); timezones0.put("America/Mexico_City", tz); timezones0.put("America/Monterrey", tz); timezones0.put("America/Rainy_River", tz); timezones0.put("America/Winnipeg", tz); tz = new SimpleTimeZone(-6000 * 3600, "America/Belize"); timezones0.put("America/Belize", tz); timezones0.put("America/Costa_Rica", tz); timezones0.put("America/El_Salvador", tz); timezones0.put("America/Guatemala", tz); timezones0.put("America/Managua", tz); timezones0.put("America/Regina", tz); timezones0.put("America/Swift_Current", tz); timezones0.put("America/Tegucigalpa", tz); timezones0.put("Pacific/Galapagos", tz); tz = new SimpleTimeZone (-6000 * 3600, "Pacific/Easter", Calendar.OCTOBER, 9, -Calendar.SUNDAY, 0 * 3600, Calendar.MARCH, 9, -Calendar.SUNDAY, 0 * 3600); timezones0.put("Pacific/Easter", tz); tz = new SimpleTimeZone (-5000 * 3600, "America/Grand_Turk", Calendar.APRIL, 1, Calendar.SUNDAY, 0 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600); timezones0.put("America/Grand_Turk", tz); timezones0.put("America/Havana", tz); tz = new SimpleTimeZone(-5000 * 3600, "EST5"); timezones0.put("EST5", tz); timezones0.put("IET", tz); timezones0.put("America/Bogota", tz); timezones0.put("America/Cayman", tz); timezones0.put("America/Eirunepe", tz); timezones0.put("America/Guayaquil", tz); timezones0.put("America/Indiana/Indianapolis", tz); timezones0.put("America/Indiana/Knox", tz); timezones0.put("America/Indiana/Marengo", tz); timezones0.put("America/Indiana/Vevay", tz); timezones0.put("America/Indianapolis", tz); timezones0.put("America/Iqaluit", tz); timezones0.put("America/Jamaica", tz); timezones0.put("America/Lima", tz); timezones0.put("America/Panama", tz); timezones0.put("America/Pangnirtung", tz); timezones0.put("America/Port-au-Prince", tz); timezones0.put("America/Porto_Acre", tz); timezones0.put("America/Rankin_Inlet", tz); tz = new SimpleTimeZone (-5000 * 3600, "EST", Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("EST", tz); timezones0.put("EST5EDT", tz); timezones0.put("America/Detroit", tz); timezones0.put("America/Kentucky/Louisville", tz); timezones0.put("America/Kentucky/Monticello", tz); timezones0.put("America/Louisville", tz); timezones0.put("America/Montreal", tz); timezones0.put("America/Nassau", tz); timezones0.put("America/New_York", tz); timezones0.put("America/Nipigon", tz); timezones0.put("America/Thunder_Bay", tz); tz = new SimpleTimeZone(-4000 * 3600, "PRT"); timezones0.put("PRT", tz); timezones0.put("America/Anguilla", tz); timezones0.put("America/Antigua", tz); timezones0.put("America/Aruba", tz); timezones0.put("America/Barbados", tz); timezones0.put("America/Boa_Vista", tz); timezones0.put("America/Caracas", tz); timezones0.put("America/Curacao", tz); timezones0.put("America/Dominica", tz); timezones0.put("America/Grenada", tz); timezones0.put("America/Guadeloupe", tz); timezones0.put("America/Guyana", tz); timezones0.put("America/La_Paz", tz); timezones0.put("America/Manaus", tz); timezones0.put("America/Martinique", tz); timezones0.put("America/Montserrat", tz); timezones0.put("America/Port_of_Spain", tz); timezones0.put("America/Porto_Velho", tz); timezones0.put("America/Puerto_Rico", tz); timezones0.put("America/Santo_Domingo", tz); timezones0.put("America/St_Kitts", tz); timezones0.put("America/St_Lucia", tz); timezones0.put("America/St_Thomas", tz); timezones0.put("America/St_Vincent", tz); timezones0.put("America/Tortola", tz); tz = new SimpleTimeZone (-4000 * 3600, "America/Asuncion", Calendar.OCTOBER, 1, Calendar.SUNDAY, 0 * 3600, Calendar.FEBRUARY, -1, Calendar.SUNDAY, 0 * 3600); timezones0.put("America/Asuncion", tz); tz = new SimpleTimeZone (-4000 * 3600, "America/Cuiaba", Calendar.OCTOBER, 2, Calendar.SUNDAY, 0 * 3600, Calendar.FEBRUARY, 3, Calendar.SUNDAY, 0 * 3600); timezones0.put("America/Cuiaba", tz); tz = new SimpleTimeZone (-4000 * 3600, "America/Goose_Bay", Calendar.APRIL, 1, Calendar.SUNDAY, 60000, Calendar.OCTOBER, -1, Calendar.SUNDAY, 60000); timezones0.put("America/Goose_Bay", tz); tz = new SimpleTimeZone (-4000 * 3600, "America/Glace_Bay", Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("America/Glace_Bay", tz); timezones0.put("America/Halifax", tz); timezones0.put("America/Thule", tz); timezones0.put("Atlantic/Bermuda", tz); tz = new SimpleTimeZone (-4000 * 3600, "America/Santiago", Calendar.OCTOBER, 9, -Calendar.SUNDAY, 0 * 3600, Calendar.MARCH, 9, -Calendar.SUNDAY, 0 * 3600); timezones0.put("America/Santiago", tz); timezones0.put("Antarctica/Palmer", tz); tz = new SimpleTimeZone (-4000 * 3600, "Atlantic/Stanley", Calendar.SEPTEMBER, 2, Calendar.SUNDAY, 0 * 3600, Calendar.APRIL, 16, -Calendar.SUNDAY, 0 * 3600); timezones0.put("Atlantic/Stanley", tz); tz = new SimpleTimeZone (-3500 * 3600, "CNT", Calendar.APRIL, 1, Calendar.SUNDAY, 60000, Calendar.OCTOBER, -1, Calendar.SUNDAY, 60000); timezones0.put("CNT", tz); timezones0.put("America/St_Johns", tz); tz = new SimpleTimeZone (-3000 * 3600, "America/Araguaina", Calendar.OCTOBER, 2, Calendar.SUNDAY, 0 * 3600, Calendar.FEBRUARY, 3, Calendar.SUNDAY, 0 * 3600); timezones0.put("America/Araguaina", tz); timezones0.put("America/Sao_Paulo", tz); tz = new SimpleTimeZone(-3000 * 3600, "AGT"); timezones0.put("AGT", tz); timezones0.put("America/Belem", tz); timezones0.put("America/Buenos_Aires", tz); timezones0.put("America/Catamarca", tz); timezones0.put("America/Cayenne", tz); timezones0.put("America/Cordoba", tz); timezones0.put("America/Fortaleza", tz); timezones0.put("America/Jujuy", tz); timezones0.put("America/Maceio", tz); timezones0.put("America/Mendoza", tz); timezones0.put("America/Montevideo", tz); timezones0.put("America/Paramaribo", tz); timezones0.put("America/Recife", tz); timezones0.put("America/Rosario", tz); tz = new SimpleTimeZone (-3000 * 3600, "America/Godthab", Calendar.MARCH, 30, -Calendar.SATURDAY, 22000 * 3600, Calendar.OCTOBER, 30, -Calendar.SATURDAY, 22000 * 3600); timezones0.put("America/Godthab", tz); tz = new SimpleTimeZone (-3000 * 3600, "America/Miquelon", Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("America/Miquelon", tz); tz = new SimpleTimeZone(-2000 * 3600, "America/Noronha"); timezones0.put("America/Noronha", tz); timezones0.put("Atlantic/South_Georgia", tz); tz = new SimpleTimeZone (-1000 * 3600, "America/Scoresbysund", Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600); timezones0.put("America/Scoresbysund", tz); timezones0.put("Atlantic/Azores", tz); tz = new SimpleTimeZone(-1000 * 3600, "Atlantic/Cape_Verde"); timezones0.put("Atlantic/Cape_Verde", tz); timezones0.put("Atlantic/Jan_Mayen", tz); tz = new SimpleTimeZone(0 * 3600, "GMT"); timezones0.put("GMT", tz); timezones0.put("UTC", tz); timezones0.put("Africa/Abidjan", tz); timezones0.put("Africa/Accra", tz); timezones0.put("Africa/Bamako", tz); timezones0.put("Africa/Banjul", tz); timezones0.put("Africa/Bissau", tz); timezones0.put("Africa/Casablanca", tz); timezones0.put("Africa/Conakry", tz); timezones0.put("Africa/Dakar", tz); timezones0.put("Africa/El_Aaiun", tz); timezones0.put("Africa/Freetown", tz); timezones0.put("Africa/Lome", tz); timezones0.put("Africa/Monrovia", tz); timezones0.put("Africa/Nouakchott", tz); timezones0.put("Africa/Ouagadougou", tz); timezones0.put("Africa/Sao_Tome", tz); timezones0.put("Africa/Timbuktu", tz); timezones0.put("Atlantic/Reykjavik", tz); timezones0.put("Atlantic/St_Helena", tz); timezones0.put("Europe/Belfast", tz); timezones0.put("Europe/Dublin", tz); timezones0.put("Europe/London", tz); tz = new SimpleTimeZone (0 * 3600, "WET", Calendar.MARCH, -1, Calendar.SUNDAY, 1000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 1000 * 3600); timezones0.put("WET", tz); timezones0.put("Atlantic/Canary", tz); timezones0.put("Atlantic/Faeroe", tz); timezones0.put("Atlantic/Madeira", tz); timezones0.put("Europe/Lisbon", tz); tz = new SimpleTimeZone(1000 * 3600, "Africa/Algiers"); timezones0.put("Africa/Algiers", tz); timezones0.put("Africa/Bangui", tz); timezones0.put("Africa/Brazzaville", tz); timezones0.put("Africa/Douala", tz); timezones0.put("Africa/Kinshasa", tz); timezones0.put("Africa/Lagos", tz); timezones0.put("Africa/Libreville", tz); timezones0.put("Africa/Luanda", tz); timezones0.put("Africa/Malabo", tz); timezones0.put("Africa/Ndjamena", tz); timezones0.put("Africa/Niamey", tz); timezones0.put("Africa/Porto-Novo", tz); timezones0.put("Africa/Tunis", tz); tz = new SimpleTimeZone (1000 * 3600, "Africa/Windhoek", Calendar.SEPTEMBER, 1, Calendar.SUNDAY, 2000 * 3600, Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Africa/Windhoek", tz); tz = new SimpleTimeZone (1000 * 3600, "CET", Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("CET", tz); timezones0.put("ECT", tz); timezones0.put("MET", tz); timezones0.put("Africa/Ceuta", tz); timezones0.put("Arctic/Longyearbyen", tz); timezones0.put("Europe/Amsterdam", tz); timezones0.put("Europe/Andorra", tz); timezones0.put("Europe/Belgrade", tz); timezones0.put("Europe/Berlin", tz); timezones0.put("Europe/Bratislava", tz); timezones0.put("Europe/Brussels", tz); timezones0.put("Europe/Budapest", tz); timezones0.put("Europe/Copenhagen", tz); timezones0.put("Europe/Gibraltar", tz); timezones0.put("Europe/Ljubljana", tz); timezones0.put("Europe/Luxembourg", tz); timezones0.put("Europe/Madrid", tz); timezones0.put("Europe/Malta", tz); timezones0.put("Europe/Monaco", tz); timezones0.put("Europe/Oslo", tz); timezones0.put("Europe/Paris", tz); timezones0.put("Europe/Prague", tz); timezones0.put("Europe/Rome", tz); timezones0.put("Europe/San_Marino", tz); timezones0.put("Europe/Sarajevo", tz); timezones0.put("Europe/Skopje", tz); timezones0.put("Europe/Stockholm", tz); timezones0.put("Europe/Tirane", tz); timezones0.put("Europe/Vaduz", tz); timezones0.put("Europe/Vatican", tz); timezones0.put("Europe/Vienna", tz); timezones0.put("Europe/Warsaw", tz); timezones0.put("Europe/Zagreb", tz); timezones0.put("Europe/Zurich", tz); tz = new SimpleTimeZone (2000 * 3600, "ART", Calendar.APRIL, -1, Calendar.FRIDAY, 0 * 3600, Calendar.SEPTEMBER, -1, Calendar.THURSDAY, 23000 * 3600); timezones0.put("ART", tz); timezones0.put("Africa/Cairo", tz); tz = new SimpleTimeZone(2000 * 3600, "CAT"); timezones0.put("CAT", tz); timezones0.put("Africa/Blantyre", tz); timezones0.put("Africa/Bujumbura", tz); timezones0.put("Africa/Gaborone", tz); timezones0.put("Africa/Harare", tz); timezones0.put("Africa/Johannesburg", tz); timezones0.put("Africa/Kigali", tz); timezones0.put("Africa/Lubumbashi", tz); timezones0.put("Africa/Lusaka", tz); timezones0.put("Africa/Maputo", tz); timezones0.put("Africa/Maseru", tz); timezones0.put("Africa/Mbabane", tz); timezones0.put("Africa/Tripoli", tz); timezones0.put("Europe/Riga", tz); timezones0.put("Europe/Tallinn", tz); timezones0.put("Europe/Vilnius", tz); tz = new SimpleTimeZone (2000 * 3600, "Asia/Amman", Calendar.MARCH, -1, Calendar.THURSDAY, 0 * 3600, Calendar.SEPTEMBER, -1, Calendar.THURSDAY, 0 * 3600); timezones0.put("Asia/Amman", tz); tz = new SimpleTimeZone (2000 * 3600, "Asia/Beirut", Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600); timezones0.put("Asia/Beirut", tz); tz = new SimpleTimeZone (2000 * 3600, "Asia/Damascus", Calendar.APRIL, 1, 0, 0 * 3600, Calendar.OCTOBER, 1, 0, 0 * 3600); timezones0.put("Asia/Damascus", tz); tz = new SimpleTimeZone (2000 * 3600, "Asia/Gaza", Calendar.APRIL, 3, Calendar.FRIDAY, 0 * 3600, Calendar.OCTOBER, 3, Calendar.FRIDAY, 0 * 3600); timezones0.put("Asia/Gaza", tz); tz = new SimpleTimeZone (2000 * 3600, "Asia/Jerusalem", Calendar.APRIL, 1, 0, 1000 * 3600, Calendar.OCTOBER, 1, 0, 1000 * 3600); timezones0.put("Asia/Jerusalem", tz); tz = new SimpleTimeZone (2000 * 3600, "EET", Calendar.MARCH, -1, Calendar.SUNDAY, 3000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600); timezones0.put("EET", tz); timezones0.put("Asia/Istanbul", tz); timezones0.put("Asia/Nicosia", tz); timezones0.put("Europe/Athens", tz); timezones0.put("Europe/Bucharest", tz); timezones0.put("Europe/Chisinau", tz); timezones0.put("Europe/Helsinki", tz); timezones0.put("Europe/Istanbul", tz); timezones0.put("Europe/Kiev", tz); timezones0.put("Europe/Nicosia", tz); timezones0.put("Europe/Simferopol", tz); timezones0.put("Europe/Sofia", tz); timezones0.put("Europe/Uzhgorod", tz); timezones0.put("Europe/Zaporozhye", tz); tz = new SimpleTimeZone (2000 * 3600, "Europe/Kaliningrad", Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Europe/Kaliningrad", tz); timezones0.put("Europe/Minsk", tz); tz = new SimpleTimeZone (3000 * 3600, "Asia/Baghdad", Calendar.APRIL, 1, 0, 3000 * 3600, Calendar.OCTOBER, 1, 0, 3000 * 3600); timezones0.put("Asia/Baghdad", tz); tz = new SimpleTimeZone (3000 * 3600, "Europe/Moscow", Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Europe/Moscow", tz); timezones0.put("Europe/Tiraspol", tz); tz = new SimpleTimeZone(3000 * 3600, "EAT"); timezones0.put("EAT", tz); timezones0.put("Africa/Addis_Ababa", tz); timezones0.put("Africa/Asmera", tz); timezones0.put("Africa/Dar_es_Salaam", tz); timezones0.put("Africa/Djibouti", tz); timezones0.put("Africa/Kampala", tz); timezones0.put("Africa/Khartoum", tz); timezones0.put("Africa/Mogadishu", tz); timezones0.put("Africa/Nairobi", tz); timezones0.put("Antarctica/Syowa", tz); timezones0.put("Asia/Aden", tz); timezones0.put("Asia/Bahrain", tz); timezones0.put("Asia/Kuwait", tz); timezones0.put("Asia/Qatar", tz); timezones0.put("Asia/Riyadh", tz); timezones0.put("Indian/Antananarivo", tz); timezones0.put("Indian/Comoro", tz); timezones0.put("Indian/Mayotte", tz); tz = new SimpleTimeZone(3500 * 3600, "Asia/Tehran"); timezones0.put("Asia/Tehran", tz); tz = new SimpleTimeZone (4000 * 3600, "Asia/Baku", Calendar.MARCH, -1, Calendar.SUNDAY, 1000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 1000 * 3600); timezones0.put("Asia/Baku", tz); tz = new SimpleTimeZone (4000 * 3600, "Asia/Aqtau", Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600); timezones0.put("Asia/Aqtau", tz); timezones0.put("Asia/Tbilisi", tz); tz = new SimpleTimeZone (4000 * 3600, "Asia/Yerevan", Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Asia/Yerevan", tz); timezones0.put("Europe/Samara", tz); tz = new SimpleTimeZone(4000 * 3600, "NET"); timezones0.put("NET", tz); timezones0.put("Asia/Dubai", tz); timezones0.put("Asia/Muscat", tz); timezones0.put("Indian/Mahe", tz); timezones0.put("Indian/Mauritius", tz); timezones0.put("Indian/Reunion", tz); tz = new SimpleTimeZone(4500 * 3600, "Asia/Kabul"); timezones0.put("Asia/Kabul", tz); tz = new SimpleTimeZone (5000 * 3600, "Asia/Aqtobe", Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600); timezones0.put("Asia/Aqtobe", tz); tz = new SimpleTimeZone (5000 * 3600, "Asia/Bishkek", Calendar.MARCH, -1, Calendar.SUNDAY, 2500 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2500 * 3600); timezones0.put("Asia/Bishkek", tz); tz = new SimpleTimeZone (5000 * 3600, "Asia/Yekaterinburg", Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Asia/Yekaterinburg", tz); tz = new SimpleTimeZone(5000 * 3600, "PLT"); timezones0.put("PLT", tz); timezones0.put("Asia/Ashgabat", tz); timezones0.put("Asia/Dushanbe", tz); timezones0.put("Asia/Karachi", tz); timezones0.put("Asia/Samarkand", tz); timezones0.put("Asia/Tashkent", tz); timezones0.put("Indian/Chagos", tz); timezones0.put("Indian/Kerguelen", tz); timezones0.put("Indian/Maldives", tz); tz = new SimpleTimeZone(5500 * 3600, "IST"); timezones0.put("IST", tz); timezones0.put("Asia/Calcutta", tz); tz = new SimpleTimeZone(5750 * 3600, "Asia/Katmandu"); timezones0.put("Asia/Katmandu", tz); tz = new SimpleTimeZone(6000 * 3600, "BST"); timezones0.put("BST", tz); timezones0.put("Antarctica/Mawson", tz); timezones0.put("Asia/Colombo", tz); timezones0.put("Asia/Dhaka", tz); timezones0.put("Asia/Thimphu", tz); tz = new SimpleTimeZone (6000 * 3600, "Asia/Almaty", Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600); timezones0.put("Asia/Almaty", tz); tz = new SimpleTimeZone (6000 * 3600, "Asia/Novosibirsk", Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Asia/Novosibirsk", tz); timezones0.put("Asia/Omsk", tz); tz = new SimpleTimeZone(6500 * 3600, "Asia/Rangoon"); timezones0.put("Asia/Rangoon", tz); timezones0.put("Indian/Cocos", tz); tz = new SimpleTimeZone(7000 * 3600, "VST"); timezones0.put("VST", tz); timezones0.put("Antarctica/Davis", tz); timezones0.put("Asia/Bangkok", tz); timezones0.put("Asia/Hovd", tz); timezones0.put("Asia/Jakarta", tz); timezones0.put("Asia/Phnom_Penh", tz); timezones0.put("Asia/Saigon", tz); timezones0.put("Asia/Vientiane", tz); timezones0.put("Indian/Christmas", tz); tz = new SimpleTimeZone (7000 * 3600, "Asia/Krasnoyarsk", Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Asia/Krasnoyarsk", tz); tz = new SimpleTimeZone(8000 * 3600, "CTT"); timezones0.put("CTT", tz); timezones0.put("Antarctica/Casey", tz); timezones0.put("Asia/Brunei", tz); timezones0.put("Asia/Chungking", tz); timezones0.put("Asia/Harbin", tz); timezones0.put("Asia/Hong_Kong", tz); timezones0.put("Asia/Kashgar", tz); timezones0.put("Asia/Kuala_Lumpur", tz); timezones0.put("Asia/Kuching", tz); timezones0.put("Asia/Macao", tz); timezones0.put("Asia/Manila", tz); timezones0.put("Asia/Shanghai", tz); timezones0.put("Asia/Singapore", tz); timezones0.put("Asia/Taipei", tz); timezones0.put("Asia/Ujung_Pandang", tz); timezones0.put("Asia/Ulaanbaatar", tz); timezones0.put("Asia/Urumqi", tz); timezones0.put("Australia/Perth", tz); tz = new SimpleTimeZone (8000 * 3600, "Asia/Irkutsk", Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Asia/Irkutsk", tz); tz = new SimpleTimeZone(9000 * 3600, "JST"); timezones0.put("JST", tz); timezones0.put("Asia/Dili", tz); timezones0.put("Asia/Jayapura", tz); timezones0.put("Asia/Pyongyang", tz); timezones0.put("Asia/Seoul", tz); timezones0.put("Asia/Tokyo", tz); timezones0.put("Pacific/Palau", tz); tz = new SimpleTimeZone (9000 * 3600, "Asia/Yakutsk", Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Asia/Yakutsk", tz); tz = new SimpleTimeZone (9500 * 3600, "Australia/Adelaide", Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Australia/Adelaide", tz); timezones0.put("Australia/Broken_Hill", tz); tz = new SimpleTimeZone(9500 * 3600, "ACT"); timezones0.put("ACT", tz); timezones0.put("Australia/Darwin", tz); tz = new SimpleTimeZone(10000 * 3600, "Antarctica/DumontDUrville"); timezones0.put("Antarctica/DumontDUrville", tz); timezones0.put("Australia/Brisbane", tz); timezones0.put("Australia/Lindeman", tz); timezones0.put("Pacific/Guam", tz); timezones0.put("Pacific/Port_Moresby", tz); timezones0.put("Pacific/Saipan", tz); timezones0.put("Pacific/Truk", tz); timezones0.put("Pacific/Yap", tz); tz = new SimpleTimeZone (10000 * 3600, "Asia/Vladivostok", Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Asia/Vladivostok", tz); tz = new SimpleTimeZone (10000 * 3600, "Australia/Hobart", Calendar.OCTOBER, 1, Calendar.SUNDAY, 2000 * 3600, Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Australia/Hobart", tz); tz = new SimpleTimeZone (10000 * 3600, "AET", Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("AET", tz); timezones0.put("Australia/Melbourne", tz); timezones0.put("Australia/Sydney", tz); tz = new SimpleTimeZone (10500 * 3600, "Australia/Lord_Howe", Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, 500 * 3600); timezones0.put("Australia/Lord_Howe", tz); tz = new SimpleTimeZone (11000 * 3600, "Asia/Magadan", Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Asia/Magadan", tz); tz = new SimpleTimeZone(11000 * 3600, "SST"); timezones0.put("SST", tz); timezones0.put("Pacific/Efate", tz); timezones0.put("Pacific/Guadalcanal", tz); timezones0.put("Pacific/Kosrae", tz); timezones0.put("Pacific/Noumea", tz); timezones0.put("Pacific/Ponape", tz); tz = new SimpleTimeZone(11500 * 3600, "Pacific/Norfolk"); timezones0.put("Pacific/Norfolk", tz); tz = new SimpleTimeZone (12000 * 3600, "NST", Calendar.OCTOBER, 1, Calendar.SUNDAY, 2000 * 3600, Calendar.MARCH, 3, Calendar.SUNDAY, 2000 * 3600); timezones0.put("NST", tz); timezones0.put("Antarctica/McMurdo", tz); timezones0.put("Antarctica/South_Pole", tz); timezones0.put("Pacific/Auckland", tz); tz = new SimpleTimeZone (12000 * 3600, "Asia/Anadyr", Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); timezones0.put("Asia/Anadyr", tz); timezones0.put("Asia/Kamchatka", tz); tz = new SimpleTimeZone(12000 * 3600, "Pacific/Fiji"); timezones0.put("Pacific/Fiji", tz); timezones0.put("Pacific/Funafuti", tz); timezones0.put("Pacific/Kwajalein", tz); timezones0.put("Pacific/Majuro", tz); timezones0.put("Pacific/Nauru", tz); timezones0.put("Pacific/Tarawa", tz); timezones0.put("Pacific/Wake", tz); timezones0.put("Pacific/Wallis", tz); tz = new SimpleTimeZone (12750 * 3600, "Pacific/Chatham", Calendar.OCTOBER, 1, Calendar.SUNDAY, 2750 * 3600, Calendar.MARCH, 3, Calendar.SUNDAY, 2750 * 3600); timezones0.put("Pacific/Chatham", tz); tz = new SimpleTimeZone(13000 * 3600, "Pacific/Enderbury"); timezones0.put("Pacific/Enderbury", tz); timezones0.put("Pacific/Tongatapu", tz); tz = new SimpleTimeZone(14000 * 3600, "Pacific/Kiritimati"); timezones0.put("Pacific/Kiritimati", tz); } return timezones0; } |
|
ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); | DefaultListSelectionModel rowModel = (DefaultListSelectionModel) table.getSelectionModel(); DefaultListSelectionModel colModel = (DefaultListSelectionModel) table.getColumnModel().getSelectionModel(); | 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)); } |
if (e.getActionCommand().equals("selectPreviousRowExtendSelection")) | String command = e.getActionCommand(); if (command.equals("selectPreviousRowExtendSelection")) | 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)); } |
else if (e.getActionCommand().equals("selectLastColumn")) { table.clearSelection(); | else if (command.equals("selectLastColumn")) { | 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)); } |
else if (e.getActionCommand().equals("startEditing")) | else if (command.equals("startEditing")) | 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)); } |
else if (e.getActionCommand().equals("selectFirstRowExtendSelection")) | else if (command.equals("selectFirstRowExtendSelection")) | 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)); } |
else if (e.getActionCommand().equals("selectFirstColumn")) | else if (command.equals("selectFirstColumn")) | 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)); } |
else if (e.getActionCommand().equals("selectFirstColumnExtendSelection")) | else if (command.equals("selectFirstColumnExtendSelection")) | 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)); } |
else if (e.getActionCommand().equals("selectLastRow")) | else if (command.equals("selectLastRow")) | 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)); } |
else if (e.getActionCommand().equals("selectNextRowExtendSelection")) | else if (command.equals("selectNextRowExtendSelection")) | 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)); } |
else if (e.getActionCommand().equals("selectFirstRow")) | else if (command.equals("selectFirstRow")) | 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)); } |
else if (e.getActionCommand().equals("selectNextColumnExtendSelection")) | else if (command.equals("selectNextColumnExtendSelection")) | 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)); } |
else if (e.getActionCommand().equals("selectLastColumnExtendSelection")) | else if (command.equals("selectLastColumnExtendSelection")) | 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)); } |
else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection")) | else if (command.equals("selectPreviousColumnExtendSelection")) | 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)); } |
else if (e.getActionCommand().equals("selectNextRow")) | else if (command.equals("selectNextRow")) | 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)); } |
else if (e.getActionCommand().equals("scrollUpExtendSelection")) | else if (command.equals("scrollUpExtendSelection")) | 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)); } |
else if (e.getActionCommand().equals("selectPreviousRow")) | else if (command.equals("selectPreviousRow")) | 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)); } |
Subsets and Splits