rem
stringlengths
0
477k
add
stringlengths
0
313k
context
stringlengths
6
599k
Rectangle hibounds = new Rectangle(hiLoc.x, hiLoc.y, cellWidth,
Rectangle hibounds = new Rectangle(hiLoc.x, hiLoc.y, width,
public Rectangle getCellBounds(JList l, int index1, int index2) { maybeUpdateLayoutState(); if (l != list || cellWidth == -1) return null; int minIndex = Math.min(index1, index2); int maxIndex = Math.max(index1, index2); Point loc = indexToLocation(list, minIndex); Rectangle bounds = new Rectangle(loc.x, loc.y, cellWidth, getCellHeight(minIndex)); for (int i = minIndex + 1; i <= maxIndex; i++) { Point hiLoc = indexToLocation(list, i); Rectangle hibounds = new Rectangle(hiLoc.x, hiLoc.y, cellWidth, getCellHeight(i)); bounds = bounds.union(hibounds); } return bounds; }
if (updateLayoutStateNeeded != 0 || !list.isValid())
if (updateLayoutStateNeeded != 0)
protected void maybeUpdateLayoutState() { if (updateLayoutStateNeeded != 0 || !list.isValid()) { updateLayoutState(); updateLayoutStateNeeded = 0; } }
if (list.getLayoutOrientation() == JList.VERTICAL) cellWidth = Math.max(cellWidth, list.getSize().width);
protected void updateLayoutState() { int nrows = list.getModel().getSize(); cellHeight = -1; cellWidth = -1; if (cellHeights == null || cellHeights.length != nrows) cellHeights = new int[nrows]; ListCellRenderer rend = list.getCellRenderer(); // Update the cellHeight(s) fields. int fixedCellHeight = list.getFixedCellHeight(); if (fixedCellHeight > 0) { cellHeight = fixedCellHeight; cellHeights = null; } else { cellHeight = -1; for (int i = 0; i < nrows; ++i) { Component flyweight = rend.getListCellRendererComponent(list, list.getModel().getElementAt(i), i, list.isSelectedIndex(i), list.getSelectionModel().getAnchorSelectionIndex() == i); Dimension dim = flyweight.getPreferredSize(); cellHeights[i] = dim.height; } } // Update the cellWidth field. int fixedCellWidth = list.getFixedCellWidth(); if (fixedCellWidth > 0) cellWidth = fixedCellWidth; else { for (int i = 0; i < nrows; ++i) { Component flyweight = rend.getListCellRendererComponent(list, list.getModel().getElementAt(i), i, list.isSelectedIndex(i), list.getSelectionModel().getAnchorSelectionIndex() == i); Dimension dim = flyweight.getPreferredSize(); cellWidth = Math.max(cellWidth, dim.width); } if (list.getLayoutOrientation() == JList.VERTICAL) cellWidth = Math.max(cellWidth, list.getSize().width); } }
return new String[] { "org.jnode.vm.x86.compiler", "org.jnode.vm.x86.compiler.stup" };
return new String[] { "org.jnode.vm.x86.compiler", "org.jnode.vm.x86.compiler.stub" };
public String[] getCompilerPackages() { return new String[] { "org.jnode.vm.x86.compiler", "org.jnode.vm.x86.compiler.stup" }; }
log.debug("using firstProvider "+firstProvName);
private FontProvider getProvider(Font font) { FontProvider prov = getFirstProvider(); final String firstProvName = prov.getName(); if (prov.provides(font)) { log.debug("using firstProvider "+firstProvName); return prov; } log.debug("getProvider for "+font.getName()+ " ("+providers.size()+" availables)"); for (FontProvider prv : providers.values()) { if(firstProvName.equals(prv.getName())) continue; // skip the first provider log.debug("font="+font+" provider="+prv); if (prv.provides(font)) { log.debug("provider found"); return prv; } } log.debug("font="+font+" NO PROVIDER"); return null; }
log.debug("getProvider for "+font.getName()+ " ("+providers.size()+" availables)"); for (FontProvider prv : providers.values()) { if(firstProvName.equals(prv.getName())) continue;
for (FontProvider prv : providers.values()) { if(firstProvName.equals(prv.getName())) continue;
private FontProvider getProvider(Font font) { FontProvider prov = getFirstProvider(); final String firstProvName = prov.getName(); if (prov.provides(font)) { log.debug("using firstProvider "+firstProvName); return prov; } log.debug("getProvider for "+font.getName()+ " ("+providers.size()+" availables)"); for (FontProvider prv : providers.values()) { if(firstProvName.equals(prv.getName())) continue; // skip the first provider log.debug("font="+font+" provider="+prv); if (prv.provides(font)) { log.debug("provider found"); return prv; } } log.debug("font="+font+" NO PROVIDER"); return null; }
log.debug("font="+font+" provider="+prv);
private FontProvider getProvider(Font font) { FontProvider prov = getFirstProvider(); final String firstProvName = prov.getName(); if (prov.provides(font)) { log.debug("using firstProvider "+firstProvName); return prov; } log.debug("getProvider for "+font.getName()+ " ("+providers.size()+" availables)"); for (FontProvider prv : providers.values()) { if(firstProvName.equals(prv.getName())) continue; // skip the first provider log.debug("font="+font+" provider="+prv); if (prv.provides(font)) { log.debug("provider found"); return prv; } } log.debug("font="+font+" NO PROVIDER"); return null; }
log.debug("provider found");
private FontProvider getProvider(Font font) { FontProvider prov = getFirstProvider(); final String firstProvName = prov.getName(); if (prov.provides(font)) { log.debug("using firstProvider "+firstProvName); return prov; } log.debug("getProvider for "+font.getName()+ " ("+providers.size()+" availables)"); for (FontProvider prv : providers.values()) { if(firstProvName.equals(prv.getName())) continue; // skip the first provider log.debug("font="+font+" provider="+prv); if (prv.provides(font)) { log.debug("provider found"); return prv; } } log.debug("font="+font+" NO PROVIDER"); return null; }
lastPaintPosition = new Point(); cachedBlitFrom = new Point(); cachedBlitTo = new Point(); cachedBlitSize = new Dimension(); cachedBlitPaint = new Rectangle();
public JViewport() { setOpaque(true); setScrollMode(BLIT_SCROLL_MODE); setLayout(createLayoutManager()); updateUI(); }
paintComponent(g);
Component view = getView(); if (view == null) return; Point pos = getViewPosition(); Rectangle viewBounds = view.getBounds(); Rectangle portBounds = getBounds(); if (viewBounds.width == 0 || viewBounds.height == 0 || portBounds.width == 0 || portBounds.height == 0) return; switch (getScrollMode()) { case JViewport.BACKINGSTORE_SCROLL_MODE: paintBackingStore(g); break; case JViewport.BLIT_SCROLL_MODE: paintBlit(g); break; case JViewport.SIMPLE_SCROLL_MODE: default: paintSimple(g); break; } damaged = false;
public void paint(Graphics g) { paintComponent(g); }
damaged = true;
public void reshape(int x, int y, int w, int h) { boolean changed = (x != getX()) || (y != getY()) || (w != getWidth()) || (h != getHeight()); super.reshape(x, y, w, h); if (changed) fireStateChanged(); }
damaged = true;
public void revalidate() { fireStateChanged(); super.revalidate(); }
repaint();
public void setViewPosition(Point p) { Component view = getView(); if (view != null) { Point q = new Point(-p.x, -p.y); view.setLocation(q); fireStateChanged(); } }
isViewSizeSet = true;
public void setViewSize(Dimension newSize) { viewSize = newSize; Component view = getView(); if (view != null) view.setSize(viewSize); isViewSizeSet = true; fireStateChanged(); }
} isViewSizeSet = true; }
public void setViewSize(Dimension newSize) { viewSize = newSize; Component view = getView(); if (view != null) view.setSize(viewSize); isViewSizeSet = true; fireStateChanged(); }
blockSize=(int)fs.getBlockSize();
blockSize=fs.getBlockSize();
public INodeTable(Ext2FileSystem fs, int firstBlock) throws IOException { this.fs = fs; this.firstBlock = firstBlock; blockSize=(int)fs.getBlockSize(); blockCount = (int)Math.ceil( (double)(fs.getSuperblock().getINodesPerGroup()*INode.INODE_LENGTH) / (double) blockSize); }
final VmAbstractHeap firstHeap = heapManager.getFirstHeap();
final VmAbstractHeap firstHeap = heapManager.getHeapList();
final void gc() { // Prepare final VmBootHeap bootHeap = heapManager.getBootHeap(); final VmAbstractHeap firstHeap = heapManager.getFirstHeap(); stats.lastGCTime = System.currentTimeMillis(); final boolean locking = (writeBarrier != null); final boolean verbose = debug; helper.stopThreadsAtSafePoint(); heapManager.setGcActive(true); try { // Mark //helper.stopThreadsAtSafePoint(); //heapManager.setGcActive(true); try { if (verbose) { Unsafe.debug("<mark/>"); } markHeap(bootHeap, firstHeap, locking); } finally { //heapManager.setGcActive(false); //helper.restartThreads(); } // Sweep if (verbose) { Unsafe.debug("<sweep/>"); } sweep(firstHeap); // Cleanup if (verbose) { Unsafe.debug("<cleanup/>"); } cleanup(bootHeap, firstHeap); // Verification if (debug) { if (verbose) { Unsafe.debug("<verify/>"); } verify(bootHeap, firstHeap); } } finally { heapManager.setGcActive(false); heapManager.resetCurrentHeap(); helper.restartThreads(); } // Start the finalization process heapManager.triggerFinalization(); if (verbose) { Unsafe.debug("</gc free="); Unsafe.debug(heapManager.getFreeMemory()); Unsafe.debug("/>"); if (debug) { System.out.println(stats); } } }
final Vm vm = new Vm(arch, new DefaultHeapManager(clsMgr, helper,
final Vm vm = new Vm(version, arch, new DefaultHeapManager(clsMgr, helper,
private final void doExecute() throws BuildException { debug = (getProject().getProperty("jnode.debug") != null); final long lmJar = jarFile.lastModified(); final long lmKernel = kernelFile.lastModified(); final long lmDest = destFile.lastModified(); final long lmPIL = getPluginListFile().lastModified(); final PluginList piList; final long lmPI; try { log("plugin-list: " + getPluginListFile(), Project.MSG_DEBUG); piList = getPluginList(); lmPI = piList.lastModified(); } catch (PluginException ex) { throw new BuildException(ex); } catch (IOException ex) { throw new BuildException(ex); } if ((lmJar < lmDest) && (lmKernel < lmDest) && (lmPIL < lmDest) && (lmPI < lmDest)) { // No need to do anything, skip return; } if (debugFile != null) { debugFile.delete(); } try { System.getProperties().setProperty(BUILDTIME_PROPERTY, "1"); // Load the plugin descriptors final PluginRegistry piRegistry; piRegistry = new PluginRegistryModel(piList.getPluginList()); //piRegistry = new // PluginRegistryModel(piList.getDescriptorUrlList()); testPluginPrerequisites(piRegistry); /* Now create the processor */ final VmArchitecture arch = getArchitecture(); final NativeStream os = createNativeStream(); clsMgr = new VmSystemClassLoader(classesURL, arch, new BuildObjectResolver(os, this)); blockedObjects.add(clsMgr); blockedObjects.add(clsMgr.getStatics()); blockedObjects.add(clsMgr.getStatics().getTable()); if (debug) { log("Building in DEBUG mode", Project.MSG_WARN); } // Create the VM final HeapHelper helper = new HeapHelperImpl(arch); final Vm vm = new Vm(arch, new DefaultHeapManager(clsMgr, helper, clsMgr.getStatics()), clsMgr.getStatics(), debug); blockedObjects.add(vm); final VmProcessor proc = createProcessor(clsMgr.getStatics()); log("Building for " + proc.getCPUID()); final Label clInitCaller = new Label("$$clInitCaller"); VmType systemClasses[] = VmType.initializeForBootImage(clsMgr); for (int i = 0; i < systemClasses.length; i++) { clsMgr.addLoadedClass(systemClasses[ i].getName(), systemClasses[ i]); } // First copy the native kernel file copyKernel(os); os.setObjectRef(bootHeapStart); // Setup a call to our first java method initImageHeader(os, clInitCaller, vm, piRegistry); // Create the initial stack createInitialStack(os, initialStack, initialStackPtr); /* Now load the classes */ loadClass(VmMethodCode.class); loadClass(Unsafe.class); loadClass(VmSystemClassLoader.class); loadClass(VmType[].class); loadClass(Vm.class); loadClass(VmBootHeap.class); loadClass(VmDefaultHeap.class); loadClass(VmHeapManager.class); loadClass(VmStatics.class); loadClass(vm.getHeapManager().getClass()); loadClass(HeapHelper.class); loadClass(HeapHelperImpl.class); loadSystemClasses(); /* Now emit the processor */ os.getObjectRef(proc); /* Let the compilers load its native symbol offsets */ final NativeCodeCompiler[] cmps = arch.getCompilers(); for (int i = 0; i < cmps.length; i++) { final NativeCodeCompiler cmp = cmps[ i]; cmp.initialize(clsMgr); os.getObjectRef(cmp); } // Load the jarfile as byte-array copyJarFile(os); // Now emit all object images to the actual image emitObjects(os, arch, blockedObjects); // Disallow the loading of new classes clsMgr.setFailOnNewLoad(true); emitObjects(os, arch, blockedObjects); // Emit the classmanager log("Emit vm", Project.MSG_VERBOSE); blockedObjects.remove(vm); emitObjects(os, arch, blockedObjects); // Twice, this is intended! emitObjects(os, arch, blockedObjects); /* Set the bootclasses */ log("prepare bootClassArray", Project.MSG_VERBOSE); final VmType bootClasses[] = clsMgr.prepareAfterBootstrap(); os.getObjectRef(bootClasses); emitObjects(os, arch, blockedObjects); // Twice, this is intended! emitObjects(os, arch, blockedObjects); // Emit the classmanager log("Emit clsMgr", Project.MSG_VERBOSE); // Turn auto-compilation on clsMgr.setCompileRequired(); blockedObjects.remove(clsMgr); emitObjects(os, arch, blockedObjects); // Twice, this is intended! emitObjects(os, arch, blockedObjects); // Emit the classmanager log("Emit statics", Project.MSG_VERBOSE); blockedObjects.remove(clsMgr.getStatics()); emitObjects(os, arch, blockedObjects); // Twice, this is intended! emitObjects(os, arch, blockedObjects); // Emit the remaining objects log("Emit rest; blocked=" + blockedObjects, Project.MSG_VERBOSE); emitObjects(os, arch, null); log("statics table 0x" + NumberUtils.hex(os.getObjectRef( clsMgr.getStatics().getTable()).getOffset()), Project.MSG_VERBOSE); /* Write static initializer code */ emitStaticInitializerCalls(os, bootClasses, clInitCaller); // This is the end of the image X86Stream.ObjectInfo dummyObjectAtEnd = os .startObject(loadClass(VmMethodCode.class)); pageAlign(os); dummyObjectAtEnd.markEnd(); os.setObjectRef(imageEnd); os.setObjectRef(bootHeapEnd); /* Link all native symbols */ linkNativeSymbols(os); // Patch multiboot header patchHeader(os); // Store the image storeImage(os); // Generate the listfile printLabels(os, bootClasses, clsMgr.getStatics()); // Generate debug info for (int i = 0; i < cmps.length; i++) { cmps[ i].dumpStatistics(); } final int bootHeapSize = os.getObjectRef(bootHeapEnd).getOffset() - os.getObjectRef(bootHeapStart).getOffset(); final int bootHeapBitmapSize = (bootHeapSize / ObjectLayout.OBJECT_ALIGN) >> 3; log("Boot heap size " + (bootHeapSize >>> 10) + "K bitmap size " + (bootHeapBitmapSize >>> 10) + "K"); clsMgr.getStatics().dumpStatistics(System.out); logStatistics(os); BytecodeParser.dumpStatistics(); log("Optimized methods : " + totalHighMethods + ", avg size " + (totalHighMethodSize / totalHighMethods) + ", tot size " + totalHighMethodSize); log("Ondemand comp. methods: " + totalLowMethods + ", avg size " + (totalLowMethodSize / totalLowMethods) + ", tot size " + totalLowMethodSize); log("Done."); os.clear(); } catch (Throwable ex) { ex.printStackTrace(); throw new BuildException(ex); } }
g.drawRect(t.x, t.y, t.width, t.height);
g.drawRect(t.x, t.y, t.width - 2, t.height - 2);
protected void paintFocus(Graphics g, Rectangle t, Dimension d) { g.setColor(focusColor); g.drawRect(t.x, t.y, t.width, t.height); // FIXME: we seem to be drawing too tight a rectangle here, perhaps there // is some padding to do somewhere??? }
if (b.hasFocus() && b.isFocusPainted())
if (b.hasFocus() && b.isFocusPainted() && b.isEnabled())
public void paint(Graphics g, JComponent c) { AbstractButton b = (AbstractButton) c; Rectangle tr = new Rectangle(); Rectangle ir = new Rectangle(); Rectangle vr = new Rectangle(); Font f = c.getFont(); g.setFont(f); Icon currentIcon = null; if (b.isSelected() && b.isEnabled()) currentIcon = b.getSelectedIcon(); else if (!b.isSelected() && b.isEnabled()) currentIcon = b.getIcon(); else if (b.isSelected() && !b.isEnabled()) currentIcon = b.getDisabledSelectedIcon(); else // (!b.isSelected() && !b.isEnabled()) currentIcon = b.getDisabledIcon(); SwingUtilities.calculateInnerArea(b, vr); String text = SwingUtilities.layoutCompoundLabel (c, g.getFontMetrics(f), b.getText(), currentIcon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), vr, ir, tr, b.getIconTextGap() + defaultTextShiftOffset); if (currentIcon != null) { currentIcon.paintIcon(c, g, ir.x, ir.y); } if (text != null) paintText(g, b, tr, text); // TODO: Figure out what is the size parameter? if (b.hasFocus() && b.isFocusPainted()) paintFocus(g, tr, null); }
attribOrder.add(0, DATAFORMAT_XML_ATTRIBUTE_NAME);
protected void init() { super.init(); classXDFNodeName = "field"; // order matters! these are in *reverse* order of their // occurence in the XDF DTD attribOrder.add(0, NOTELIST_XML_ATTRIBUTE_NAME); attribOrder.add(0, RELATION_XML_ATTRIBUTE_NAME); attribOrder.add(0, UNITS_XML_ATTRIBUTE_NAME); attribOrder.add(0, DATAFORMAT_XML_ATTRIBUTE_NAME); attribOrder.add(0, DISABLEDVALUE_XML_ATTRIBUTE_NAME); attribOrder.add(0, UNDERFLOWVALUE_XML_ATTRIBUTE_NAME); attribOrder.add(0, OVERFLOWVALUE_XML_ATTRIBUTE_NAME); attribOrder.add(0, NOTANUMBERVALUE_XML_ATTRIBUTE_NAME); attribOrder.add(0, NODATAVALUE_XML_ATTRIBUTE_NAME); attribOrder.add(0, INFINITENEGATIVEVALUE_XML_ATTRIBUTE_NAME); attribOrder.add(0, INFINITEVALUE_XML_ATTRIBUTE_NAME); attribOrder.add(0, GREATERTHANOREQUALVALUE_XML_ATTRIBUTE_NAME); attribOrder.add(0, GREATERTHANVALUE_XML_ATTRIBUTE_NAME); attribOrder.add(0, LESSTHANOREQUALVALUE_XML_ATTRIBUTE_NAME); attribOrder.add(0, LESSTHANVALUE_XML_ATTRIBUTE_NAME); attribOrder.add(0, CLASS_XML_ATTRIBUTE_NAME); attribOrder.add(0, IDREF_XML_ATTRIBUTE_NAME); attribOrder.add(0, ID_XML_ATTRIBUTE_NAME); attribOrder.add(0, DESCRIPTION_XML_ATTRIBUTE_NAME); attribOrder.add(0, NAME_XML_ATTRIBUTE_NAME); //set up the attribute hashtable key with the default initial value attribHash.put(NOTELIST_XML_ATTRIBUTE_NAME, new Attribute(Collections.synchronizedList(new ArrayList()), Constants.LIST_TYPE)); attribHash.put(RELATION_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.OBJECT_TYPE)); //double check attribHash.put(UNITS_XML_ATTRIBUTE_NAME, new Attribute(new Units(), Constants.OBJECT_TYPE)); attribHash.put(DATAFORMAT_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.OBJECT_TYPE)); attribHash.put(CLASS_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(DISABLEDVALUE_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(OVERFLOWVALUE_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(UNDERFLOWVALUE_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(NOTANUMBERVALUE_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(NODATAVALUE_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(INFINITENEGATIVEVALUE_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(INFINITEVALUE_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(GREATERTHANOREQUALVALUE_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(GREATERTHANVALUE_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(LESSTHANOREQUALVALUE_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(LESSTHANVALUE_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(IDREF_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(ID_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(DESCRIPTION_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); attribHash.put(NAME_XML_ATTRIBUTE_NAME, new Attribute(null, Constants.STRING_TYPE)); };
if (isCoreObjectMethod(methods[j])) { continue; }
static ProxyData getProxyData(ProxyType pt) { Map method_set = (Map) ProxySignature.coreMethods.clone(); boolean in_package = false; // true if we encounter non-public interface ProxyData data = new ProxyData(); data.interfaces = pt.interfaces; // if interfaces is too large, we croak later on when the constant // pool overflows int i = data.interfaces.length; while (--i >= 0) { Class inter = data.interfaces[i]; if (! inter.isInterface()) throw new IllegalArgumentException("not an interface: " + inter); try { if (Class.forName(inter.getName(), false, pt.loader) != inter) throw new IllegalArgumentException("not accessible in " + "classloader: " + inter); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("not accessible in " + "classloader: " + inter); } if (! Modifier.isPublic(inter.getModifiers())) if (in_package) { String p = getPackage(inter); if (! data.pack.equals(p)) throw new IllegalArgumentException("non-public interfaces " + "from different " + "packages"); } else { in_package = true; data.pack = getPackage(inter); } for (int j = i-1; j >= 0; j--) if (data.interfaces[j] == inter) throw new IllegalArgumentException("duplicate interface: " + inter); Method[] methods = inter.getMethods(); int j = methods.length; while (--j >= 0) { ProxySignature sig = new ProxySignature(methods[j]); ProxySignature old = (ProxySignature) method_set.put(sig, sig); if (old != null) sig.checkCompatibility(old); } } i = method_set.size(); data.methods = new Method[i]; data.exceptions = new Class[i][]; Iterator itr = method_set.values().iterator(); while (--i >= 0) { ProxySignature sig = (ProxySignature) itr.next(); data.methods[i] = sig.method; data.exceptions[i] = (Class[]) sig.exceptions .toArray(new Class[sig.exceptions.size()]); } return data; }
public synchronized void read(BlockDeviceAPI device, long offset) throws IOException { byte[] data = new byte[entries.size() * 32]; device.read(offset, data, 0, data.length); read(data);
protected synchronized void read() throws IOException { entries.setSize((int)file.getLengthOnDisk() / 32); final byte[] data = new byte[entries.size() * 32]; file.read(0, data, 0, data.length); read(data);
public synchronized void read(BlockDeviceAPI device, long offset) throws IOException { byte[] data = new byte[entries.size() * 32]; device.read(offset, data, 0, data.length); //System.out.println("Directory at offset :" + offset); //System.out.println("Length in bytes = " + entries.size() * 32); read(data); resetDirty(); }
if (tex instanceof SyntaxError) { Help.getInfo(cx).usage();
if (tex instanceof SyntaxErrorException) { try { Help.getInfo(cx).usage(); } catch (HelpException ex1) { ex1.printStackTrace(); }
public void run() { try { // System.err.println("Registering shell in new thread."); ShellUtils.getShellManager().registerShell(commandShell);//workaround // to // ensure // access // to // the // command // shell // in // this // new // thread? try { AccessController.doPrivileged(new InvokeAction(method, null, args)); } catch (PrivilegedActionException ex) { throw ex.getException(); } if (!isBlocking()) { //somebody already hit ctrl-c. } else { finished = true; // System.err.println("Finished invocation, notifying // blockers."); //done with invoke, stop waiting for a ctrl-c unblock(); } } catch (InvocationTargetException ex) { Throwable tex = ex.getTargetException(); if (tex instanceof SyntaxError) { Help.getInfo(cx).usage(); err.println(tex.getMessage()); unblock(); } else { err.println("Exception in command"); tex.printStackTrace(err); unblock(); } } catch (Exception ex) { err.println("Exception in command"); ex.printStackTrace(err); unblock(); } finished = true; }
bad.minor = Minor.Any;
public static ForwardRequest extract(Any any) { try { return ((ForwardRequestHolder) any.extract_Streamable()).value; } catch (ClassCastException cex) { BAD_OPERATION bad = new BAD_OPERATION(id() + " expected"); bad.initCause(cex); throw bad; } }
Ext2Debugger.debug("Ext2Entry(iNode, name): name="+name+
log.debug("Ext2Entry(iNode, name): name="+name+
public Ext2Entry(INode iNode, String name, int type) { this.iNode = iNode; this.name = name; this.type = type; this.valid = true; Ext2Debugger.debug("Ext2Entry(iNode, name): name="+name+ (isDirectory()?" is a directory ":"")+ (isFile()?" is a file ":""), 2); }
(isFile()?" is a file ":""), 2);
(isFile()?" is a file ":""));
public Ext2Entry(INode iNode, String name, int type) { this.iNode = iNode; this.name = name; this.type = type; this.valid = true; Ext2Debugger.debug("Ext2Entry(iNode, name): name="+name+ (isDirectory()?" is a directory ":"")+ (isFile()?" is a file ":""), 2); }
hide();
setVisible(false);
public void doDefaultCloseAction() { fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING); switch (getDefaultCloseOperation()) { case HIDE_ON_CLOSE: hide(); break; case DISPOSE_ON_CLOSE: dispose(); break; } }
this.rhs = getOperand(rhsIndex); refs = new Operand[] { rhs };
refs = new Operand[] { getOperand(rhsIndex) };
public VariableRefAssignQuad(int address, IRBasicBlock block, int lhsIndex, int rhsIndex) { super(address, block, lhsIndex); this.rhs = getOperand(rhsIndex); refs = new Operand[] { rhs }; setDeadCode(true); }
if (rhs instanceof Variable) { Variable v = (Variable) rhs;
if (refs[0] instanceof Variable) { Variable v = (Variable) refs[0];
public void doPass2(BootableHashMap liveVariables) { setDeadCode(true); if (rhs instanceof Variable) { Variable v = (Variable) rhs; v.setLastUseAddress(this.getAddress()); liveVariables.put(v, v); } }
return rhs;
return refs[0];
public Operand getRHS() { return rhs; }
return rhs;
return refs[0];
public Operand propagate(Variable operand) { return rhs; }
return getAddress() + ": " + getLHS().toString() + " = " + rhs.toString();
return getAddress() + ": " + getLHS().toString() + " = " + refs[0];
public String toString() { return getAddress() + ": " + getLHS().toString() + " = " + rhs.toString(); }
protected boolean gotoField(ScreenField f) {
public boolean gotoField(int f) {
protected boolean gotoField(ScreenField f) { if (f != null) { goto_XY(f.startPos()); return true; } else { return false; } }
if (f != null) {
int sizeFields = screenFields.getSize();
protected boolean gotoField(ScreenField f) { if (f != null) { goto_XY(f.startPos()); return true; } else { return false; } }
goto_XY(f.startPos()); return true; } else {
if (f > sizeFields || f <= 0)
protected boolean gotoField(ScreenField f) { if (f != null) { goto_XY(f.startPos()); return true; } else { return false; } }
return gotoField(screenFields.getCurrentField());
protected boolean gotoField(ScreenField f) { if (f != null) { goto_XY(f.startPos()); return true; } else { return false; } }
bad.minor = Minor.Any;
public static WrongPolicy extract(Any any) { try { EmptyExceptionHolder h = (EmptyExceptionHolder) any.extract_Streamable(); return (WrongPolicy) h.value; } catch (ClassCastException cex) { BAD_OPERATION bad = new BAD_OPERATION("WrongPolicy expected"); bad.initCause(cex); throw bad; } }
super();
this.textArea = textArea;
public SwingTextAreaPeer(TextArea textArea) { super(); switch (textArea.getScrollbarVisibility()) { case TextArea.SCROLLBARS_BOTH: SwingToolkit.add(textArea, new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS)); break; case TextArea.SCROLLBARS_HORIZONTAL_ONLY: SwingToolkit.add(textArea, new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS)); break; case TextArea.SCROLLBARS_VERTICAL_ONLY: SwingToolkit.add(textArea, new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER)); break; case TextArea.SCROLLBARS_NONE: SwingToolkit.add(textArea, this); break; } SwingToolkit.copyAwtProperties(textArea, this); setText(textArea.getText()); setRows(textArea.getRows()); setColumns(textArea.getColumns()); setEditable(textArea.isEditable()); }
return 0.0F;
float align; if (axis == X_AXIS) align = 0.0F; else align = super.getAlignment(axis); return align;
public float getAlignment(int axis) { // FIXME: This is very likely not 100% correct. Work this out. return 0.0F; }
return 0.0F;
align = super.getAlignment(axis);
public float getAlignment(int axis) { if (axis == X_AXIS) return 0.0F; else if (getViewCount() > 0) { float prefHeight = getPreferredSpan(Y_AXIS); float firstRowHeight = getView(0).getPreferredSpan(Y_AXIS); return (firstRowHeight / 2.F) / prefHeight; } else return 0.0F; }
return (firstRowHeight / 2.F) / prefHeight;
align = (firstRowHeight / 2.F) / prefHeight;
public float getAlignment(int axis) { if (axis == X_AXIS) return 0.0F; else if (getViewCount() > 0) { float prefHeight = getPreferredSpan(Y_AXIS); float firstRowHeight = getView(0).getPreferredSpan(Y_AXIS); return (firstRowHeight / 2.F) / prefHeight; } else return 0.0F; }
return 0.0F;
align = 0.0F; return align;
public float getAlignment(int axis) { if (axis == X_AXIS) return 0.0F; else if (getViewCount() > 0) { float prefHeight = getPreferredSpan(Y_AXIS); float firstRowHeight = getView(0).getPreferredSpan(Y_AXIS); return (firstRowHeight / 2.F) / prefHeight; } else return 0.0F; }
array = new int[sizes.length]; for (index = 0; index < sizes.length; index++) { array[index] = sizes[index]; }
array = new int[sizes.length]; for (index = 0; index < sizes.length; index++) array[index] = sizes[index];
public int[] getSizes() { // Variables int[] array; int index; // Create New Array array = new int[sizes.length]; for (index = 0; index < sizes.length; index++) { array[index] = sizes[index]; } // for // Return Newly created array return array; } // getSizes()
public void setSizes(int[] sizes) { int index; this.sizes = new int[sizes.length]; for (index = 0; index < sizes.length; index++) { this.sizes[index] = sizes[index]; }
public void setSizes(int[] sizes) { int index; this.sizes = new int[sizes.length]; for (index = 0; index < sizes.length; index++) this.sizes[index] = sizes[index];
public void setSizes(int[] sizes) { // Variables int index; // Initialize Sizes this.sizes = new int[sizes.length]; for (index = 0; index < sizes.length; index++) { this.sizes[index] = sizes[index]; } // for } // setSizes()
MockFloppyDeviceFactory factory = (MockFloppyDeviceFactory) FSDriverUtils.getFloppyDeviceFactory();
MockFloppyDeviceFactory factory; try { factory = (MockFloppyDeviceFactory) FloppyDriverUtils.getFloppyDeviceFactory(); } catch (NamingException ex) { throw (IOException)new IOException().initCause(ex); }
public void init(TestConfig config, MockObjectTestCase testCase) throws IOException { // set the current testCase for our factory MockFloppyDeviceFactory factory = (MockFloppyDeviceFactory) FSDriverUtils.getFloppyDeviceFactory(); factory.setTestCase((MockObjectTestCase) testCase); DeviceFinder deviceFinder = new FloppyControllerFinder(); StubDeviceManager.INSTANCE.removeAll(); StubDeviceManager.INSTANCE.add(deviceFinder, new FloppyDeviceToDriverMapper()); FloppyDriver driver = (FloppyDriver) findDriver(deviceFinder, "fd0"); log.debug("findDriver->"+driver); init(null, driver, null); }
return getEncoded(IKeyPairCodec.RAW_FORMAT);
return getEncoded(defaultFormat);
public byte[] getEncoded() { return getEncoded(IKeyPairCodec.RAW_FORMAT); }
public UShortSeqHolder(short[] initial_value)
public UShortSeqHolder()
public UShortSeqHolder(short[] initial_value) { value = initial_value; typecode.setLength(value.length); }
value = initial_value; typecode.setLength(value.length);
public UShortSeqHolder(short[] initial_value) { value = initial_value; typecode.setLength(value.length); }
bad.minor = Minor.Any;
public static ForwardRequest extract(Any any) { try { return ((ForwardRequestHolder) any.extract_Streamable()).value; } catch (ClassCastException cex) { BAD_OPERATION bad = new BAD_OPERATION("ForwardRequest expected"); bad.initCause(cex); throw bad; } }
e.printStackTrace();
log.warn("In constructor: ", e);
public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } }
System.out.println("Parameter " + parm + " is specified as: " + getParameter(parm));
log.info("Parameter " + parm + " is specified as: " + getParameter(parm));
private boolean isSpecified(String parm) { if (getParameter(parm) != null) { System.out.println("Parameter " + parm + " is specified as: " + getParameter(parm)); return true; } return false; }
System.out.println(" We have loaded a new one");
log.info(" We have loaded a new one");
private void jbInit() throws Exception { this.setSize(new Dimension(400,300)); Properties sesProps = new Properties(); System.out.println(" We have loaded a new one"); // 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(); loadSystemProperty("SESSION_CONNECT_USER"); loadSystemProperty("SESSION_CONNECT_PASSWORD"); loadSystemProperty("SESSION_CONNECT_PROGRAM"); loadSystemProperty("SESSION_CONNECT_LIBRARY"); loadSystemProperty("SESSION_CONNECT_MENU"); manager = new SessionManager(); final Session s = manager.openSession(sesProps,"","Test Applet"); this.getContentPane().add(s); s.connect(); SwingUtilities.invokeLater(new Runnable() { public void run() { s.grabFocus(); } }); }
g.drawPolygon(bright);
g.drawPolyline(bright.xpoints, bright.ypoints, bright.npoints);
public void paintThumb(Graphics g) { Color saved_color = g.getColor(); Polygon thumb = new Polygon(); Point a = new Point(thumbRect.x, thumbRect.y); Point b = new Point(a); Point c = new Point(a); Point d = new Point(a); Point e = new Point(a); Polygon bright; Polygon dark; Polygon all; // This will be in X-dimension if the slider is inverted and y if it isn't. int turnPoint; if (slider.getOrientation() == JSlider.HORIZONTAL) { turnPoint = thumbRect.height * 3 / 4; b.translate(thumbRect.width, 0); c.translate(thumbRect.width, turnPoint); d.translate(thumbRect.width / 2, thumbRect.height); e.translate(0, turnPoint); bright = new Polygon(new int[] { b.x, a.x, e.x, d.x }, new int[] { b.y, a.y, e.y, d.y }, 4); dark = new Polygon(new int[] { b.x, c.x, d.x }, new int[] { b.y, c.y, d.y }, 3); all = new Polygon(new int[] { a.x + 1, b.x, c.x, d.x, e.x + 1 }, new int[] { a.y + 1, b.y + 1, c.y, d.y + 1, e.y }, 5); } else { turnPoint = thumbRect.width * 3 / 4; b.translate(turnPoint, 0); c.translate(thumbRect.width, thumbRect.height / 2); d.translate(turnPoint, thumbRect.height); e.translate(0, thumbRect.height); bright = new Polygon(new int[] { c.x, b.x, a.x, e.x }, new int[] { c.y, b.y, a.y, e.y }, 4); dark = new Polygon(new int[] { c.x, d.x, e.x + 1 }, new int[] { c.y, d.y, e.y }, 3); all = new Polygon(new int[] { a.x + 1, b.x, c.x - 1, d.x, e.x + 1 }, new int[] { a.y + 1, b.y + 1, c.y, d.y, e.y }, 5); } g.setColor(Color.WHITE); g.drawPolygon(bright); g.setColor(Color.BLACK); g.drawPolygon(dark); g.setColor(Color.GRAY); g.fillPolygon(all); g.setColor(saved_color); }
g.drawPolygon(dark);
g.drawPolyline(dark.xpoints, dark.ypoints, dark.npoints);
public void paintThumb(Graphics g) { Color saved_color = g.getColor(); Polygon thumb = new Polygon(); Point a = new Point(thumbRect.x, thumbRect.y); Point b = new Point(a); Point c = new Point(a); Point d = new Point(a); Point e = new Point(a); Polygon bright; Polygon dark; Polygon all; // This will be in X-dimension if the slider is inverted and y if it isn't. int turnPoint; if (slider.getOrientation() == JSlider.HORIZONTAL) { turnPoint = thumbRect.height * 3 / 4; b.translate(thumbRect.width, 0); c.translate(thumbRect.width, turnPoint); d.translate(thumbRect.width / 2, thumbRect.height); e.translate(0, turnPoint); bright = new Polygon(new int[] { b.x, a.x, e.x, d.x }, new int[] { b.y, a.y, e.y, d.y }, 4); dark = new Polygon(new int[] { b.x, c.x, d.x }, new int[] { b.y, c.y, d.y }, 3); all = new Polygon(new int[] { a.x + 1, b.x, c.x, d.x, e.x + 1 }, new int[] { a.y + 1, b.y + 1, c.y, d.y + 1, e.y }, 5); } else { turnPoint = thumbRect.width * 3 / 4; b.translate(turnPoint, 0); c.translate(thumbRect.width, thumbRect.height / 2); d.translate(turnPoint, thumbRect.height); e.translate(0, thumbRect.height); bright = new Polygon(new int[] { c.x, b.x, a.x, e.x }, new int[] { c.y, b.y, a.y, e.y }, 4); dark = new Polygon(new int[] { c.x, d.x, e.x + 1 }, new int[] { c.y, d.y, e.y }, 3); all = new Polygon(new int[] { a.x + 1, b.x, c.x - 1, d.x, e.x + 1 }, new int[] { a.y + 1, b.y + 1, c.y, d.y, e.y }, 5); } g.setColor(Color.WHITE); g.drawPolygon(bright); g.setColor(Color.BLACK); g.drawPolygon(dark); g.setColor(Color.GRAY); g.fillPolygon(all); g.setColor(saved_color); }
if ((gapEnd - gapStart) < strLen) shiftEnd(strLen + DEFAULT_BUFSIZE);
replace(where, 0, str.toCharArray(), str.length());
public UndoableEdit insertString(int where, String str) throws BadLocationException { // check arguments int length = length(); int strLen = str.length(); if (where >= length) throw new BadLocationException("the where argument cannot be greater" + " than the content length", where); // check if the gap is big enough to hold the string if ((gapEnd - gapStart) < strLen) // make room for this string and some more shiftEnd(strLen + DEFAULT_BUFSIZE); // are we at the gap boundary? if (where != gapStart) shiftGap(where); // now we can simple copy the string into the gap and adjust the // gap boundaries System.arraycopy(str.toCharArray(), 0, buffer, gapStart, strLen); gapStart += strLen; return null; }
if (where != gapStart) shiftGap(where); System.arraycopy(str.toCharArray(), 0, buffer, gapStart, strLen); gapStart += strLen;
public UndoableEdit insertString(int where, String str) throws BadLocationException { // check arguments int length = length(); int strLen = str.length(); if (where >= length) throw new BadLocationException("the where argument cannot be greater" + " than the content length", where); // check if the gap is big enough to hold the string if ((gapEnd - gapStart) < strLen) // make room for this string and some more shiftEnd(strLen + DEFAULT_BUFSIZE); // are we at the gap boundary? if (where != gapStart) shiftGap(where); // now we can simple copy the string into the gap and adjust the // gap boundaries System.arraycopy(str.toCharArray(), 0, buffer, gapStart, strLen); gapStart += strLen; return null; }
if (where != gapStart) shiftGap(where);
replace(where, nitems, null, 0);
public UndoableEdit remove(int where, int nitems) throws BadLocationException { // check arguments int length = length(); if (where >= length) throw new BadLocationException("the where argument cannot be greater" + " than the content length", where); if ((where + nitems) > length) throw new BadLocationException("where + nitems cannot be greater" + " than the content length", where + nitems); // check if we are at the gap boundary if (where != gapStart) shiftGap(where); // now we simply have to enlarge the gap gapEnd += nitems; return null; }
gapEnd += nitems;
public UndoableEdit remove(int where, int nitems) throws BadLocationException { // check arguments int length = length(); if (where >= length) throw new BadLocationException("the where argument cannot be greater" + " than the content length", where); if ((where + nitems) > length) throw new BadLocationException("where + nitems cannot be greater" + " than the content length", where + nitems); // check if we are at the gap boundary if (where != gapStart) shiftGap(where); // now we simply have to enlarge the gap gapEnd += nitems; return null; }
}
protected void replace(int position, int rmSize, Object addItems, int addSize) { // Remove content shiftGap(position); gapEnd += rmSize; // If gap is too small, enlarge the gap. if ((gapEnd - gapStart) < addSize) shiftEnd(addSize); // Add new items to the buffer. System.arraycopy(addItems, 0, buffer, gapStart, addSize); gapStart += addSize; }
}
protected void shiftGap(int newGapStart) { int newGapEnd = newGapStart + (gapEnd - gapStart); // Update the positions between newGapEnd and (old) gapEnd. The marks // must be shifted by (gapEnd - newGapEnd). int index1 = Collections.binarySearch(positions, new GapContentPosition( gapEnd)); int index2 = Collections.binarySearch(positions, new GapContentPosition( newGapEnd)); if (index1 > 0 && index2 > 0) { int i1 = Math.min(index1, index2); int i2 = Math.max(index1, index2); for (ListIterator i = positions.listIterator(i1); i.hasNext();) { if (i.nextIndex() > i2) break; GapContentPosition p = (GapContentPosition) i.next(); p.mark += gapEnd - newGapEnd; } if (newGapStart == gapStart) return; else if (newGapStart < gapStart) { System.arraycopy(buffer, newGapStart, buffer, newGapEnd, gapStart - newGapStart); gapStart = newGapStart; gapEnd = newGapEnd; } else { System.arraycopy(buffer, gapEnd, buffer, gapStart, newGapStart - gapStart); gapStart = newGapStart; gapEnd = newGapEnd; } } }
this.bytes = bytes; this.microseconds = microseconds;
this.byteLength = bytes; this.microsecondLength = microseconds;
public MidiFileFormat(int type, float divisionType, int resolution, int bytes, long microseconds) { this.type = type; this.divisionType = divisionType; this.resolution = resolution; this.bytes = bytes; this.microseconds = microseconds; }
return bytes;
return byteLength;
public int getByteLength() { return bytes; }
return microseconds;
return microsecondLength;
public long getMicrosecondLength() { return microseconds; }
final Graphics g = getGraphics(); if (g != null) { if (id == PaintEvent.PAINT) { ((Component)component).paint(g); } else { ((Component)component).update(g); } g.dispose(); }
processPaintEvent((PaintEvent)event);
public void handleEvent(AWTEvent event) { Unsafe.debug("handleEvent(" + event + ")"); final int id = event.getID(); switch (id) { case PaintEvent.PAINT: case PaintEvent.UPDATE: { final Graphics g = getGraphics(); if (g != null) { //Point p = component.getLocationOnScreen(); //g.translate(p.x, p.y); if (id == PaintEvent.PAINT) { ((Component)component).paint(g); } else { ((Component)component).update(g); } //g.translate(-p.x, -p.y); g.dispose(); } } break; } }
GrubFatFormatter ff = (GrubFatFormatter)createFormatter();
GrubFatFormatter ff = createFormatter();
protected void formatDevice(Device device) throws IOException { /* Format the MBR & partitiontable */ GrubBootSector mbr = (GrubBootSector)(createFormatter().getBootSector()); mbr.getPartition(0).clear(); mbr.getPartition(1).clear(); mbr.getPartition(2).clear(); mbr.getPartition(3).clear(); IBMPartitionTableEntry pte = mbr.getPartition(0); pte.setBootIndicator(true); pte.setStartLba(1); pte.setNrSectors(geom.getTotalSectors() - 1); pte.setSystemIndicator(IBMPartitionTypes.PARTTYPE_DOS_FAT16_LT32M); pte.setStartCHS(geom.getCHS(pte.getStartLba())); pte.setEndCHS(geom.getCHS(pte.getStartLba() + pte.getNrSectors() - 1)); /*System.out.println("partition table:"); for (int i = 0; i < 4; i++) { System.out.println("" + i + " " + mbr.getPartition(i)); }*/ /* Format partition 0 */ part0 = new MappedBlockDeviceSupport(device, pte.getStartLba() * bytesPerSector, pte.getNrSectors() * bytesPerSector); GrubFatFormatter ff = (GrubFatFormatter)createFormatter(); ff.setInstallPartition(0x0000FFFF); ff.format(part0); GrubBootSector part0bs = (GrubBootSector)ff.getBootSector(); /* Fixup stage2 sector in MBR */ mbr.setStage2Sector(pte.getStartLba() + part0bs.getStage2Sector()); try { mbr.write((BlockDeviceAPI)device.getAPI(BlockDeviceAPI.class)); } catch (ApiNotFoundException ex) { throw new IOException("BlockDeviceAPI not found on device", ex); } //System.out.println("mbr stage2 sector=" + mbr.getStage2Sector()); }
Font l_font = font;
Font txFont = font;
public void drawText(Graphics2D g, String text, Font font, int x, int y) { FontProvider prv = getProvider(font); Font l_font = font; if (prv == null) { l_font = new Font("Luxi Sans", Font.PLAIN, 10); //log.error("No FontProvider for font=" + font + " using " + l_font + " instead."); prv = getProvider(l_font); } final TextRenderer renderer = prv.getTextRenderer(l_font); renderer.render(g, text, x, y); }
l_font = new Font("Luxi Sans", Font.PLAIN, 10); prv = getProvider(l_font);
txFont = getTranslatedFont(font); prv = getProvider(txFont);
public void drawText(Graphics2D g, String text, Font font, int x, int y) { FontProvider prv = getProvider(font); Font l_font = font; if (prv == null) { l_font = new Font("Luxi Sans", Font.PLAIN, 10); //log.error("No FontProvider for font=" + font + " using " + l_font + " instead."); prv = getProvider(l_font); } final TextRenderer renderer = prv.getTextRenderer(l_font); renderer.render(g, text, x, y); }
final TextRenderer renderer = prv.getTextRenderer(l_font); renderer.render(g, text, x, y);
if (prv != null) { final TextRenderer renderer = prv.getTextRenderer(txFont); renderer.render(g, text, x, y); } else { log.error("No provider found for font " + txFont); }
public void drawText(Graphics2D g, String text, Font font, int x, int y) { FontProvider prv = getProvider(font); Font l_font = font; if (prv == null) { l_font = new Font("Luxi Sans", Font.PLAIN, 10); //log.error("No FontProvider for font=" + font + " using " + l_font + " instead."); prv = getProvider(l_font); } final TextRenderer renderer = prv.getTextRenderer(l_font); renderer.render(g, text, x, y); }
final FontProvider prv = getProvider(font);
FontProvider prv = getProvider(font); Font txFont = font; if (prv == null) { txFont = getTranslatedFont(font); prv = getProvider(txFont); }
public FontMetrics getFontMetrics(Font font) { final FontProvider prv = getProvider(font); if (prv != null) { return prv.getFontMetrics(font); } else { return new EmptyFontMetrics(font); } }
return prv.getFontMetrics(font);
return prv.getFontMetrics(txFont);
public FontMetrics getFontMetrics(Font font) { final FontProvider prv = getProvider(font); if (prv != null) { return prv.getFontMetrics(font); } else { return new EmptyFontMetrics(font); } }
return new EmptyFontMetrics(font);
log.error("No provider found for font " + txFont); return new EmptyFontMetrics(txFont);
public FontMetrics getFontMetrics(Font font) { final FontProvider prv = getProvider(font); if (prv != null) { return prv.getFontMetrics(font); } else { return new EmptyFontMetrics(font); } }
m.minor = Minor.IOR;
public void write(cdrOutput out) { try { // Need to write the Internet profile into the separate // stream as we must know the size in advance. cdrOutput b = out.createEncapsulation(); version.write(b); b.write_string(host); b.write_ushort((short) (port & 0xFFFF)); // Write the object key. b.write_long(key.length); b.write(key); // Number of the tagged components. b.write_long(1 + components.size()); b.write_long(CodeSets_profile.TAG_CODE_SETS); CodeSets.write(b); TaggedComponent t; for (int i = 0; i < components.size(); i++) { t = (TaggedComponent) components.get(i); TaggedComponentHelper.write(b, t); } b.close(); } catch (Exception e) { MARSHAL m = new MARSHAL("Unable to write Internet profile."); m.initCause(e); throw m; } }
bad.minor = Minor.Any;
public static AdapterInactive extract(Any any) { try { EmptyExceptionHolder h = (EmptyExceptionHolder) any.extract_Streamable(); return (AdapterInactive) h.value; } catch (ClassCastException cex) { BAD_OPERATION bad = new BAD_OPERATION("AdapterInactive expected"); bad.initCause(cex); throw bad; } }
throw new NullPointerException();
return 0;
public static int getHashCode(Object obj) { if (obj == null) { throw new NullPointerException(); } else { return ObjectReference.fromObject(obj).toAddress().toInt(); } }
throw new MARSHAL(NOT_APPLICABLE);
MARSHAL m = new MARSHAL(NOT_APPLICABLE); m.minor = Minor.Inappropriate; throw m;
public DynAny create_dyn_any(Any _0) throws InconsistentTypeCode { throw new MARSHAL(NOT_APPLICABLE); }
throw new MARSHAL(NOT_APPLICABLE);
MARSHAL m = new MARSHAL(NOT_APPLICABLE); m.minor = Minor.Inappropriate; throw m;
public DynAny create_dyn_any_from_type_code(TypeCode _0) throws InconsistentTypeCode { throw new MARSHAL(NOT_APPLICABLE); }
JTextComponent.KeyBinding[] bindings = (JTextComponent.KeyBinding[]) UIManager.get(prefix + ".keyBindings");
InputMapUIResource m = (InputMapUIResource) UIManager.get(prefix + ".focusInputMap"); if (m != null) { KeyStroke[] keys = m.keys(); int len = keys.length; bindings = new JTextComponent.KeyBinding[len]; for (int i = 0; i < len; i++) { KeyStroke curr = keys[i]; bindings[i] = new JTextComponent.KeyBinding(curr, (String) m.get(curr)); } }
protected Keymap createKeymap() { String prefix = getPropertyPrefix(); JTextComponent.KeyBinding[] bindings = (JTextComponent.KeyBinding[]) UIManager.get(prefix + ".keyBindings"); if (bindings == null) { bindings = new JTextComponent.KeyBinding[0]; // FIXME: Putting something into the defaults map is certainly wrong. // Must be fixed somehow. UIManager.put(prefix + ".keyBindings", bindings); } Keymap km = JTextComponent.addKeymap(getKeymapName(), JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP)); JTextComponent.loadKeymap(km, bindings, textComponent.getActions()); return km; }
UIManager.put(prefix + ".keyBindings", bindings);
UIManager.put(prefix + ".focusInputMap", bindings);
protected Keymap createKeymap() { String prefix = getPropertyPrefix(); JTextComponent.KeyBinding[] bindings = (JTextComponent.KeyBinding[]) UIManager.get(prefix + ".keyBindings"); if (bindings == null) { bindings = new JTextComponent.KeyBinding[0]; // FIXME: Putting something into the defaults map is certainly wrong. // Must be fixed somehow. UIManager.put(prefix + ".keyBindings", bindings); } Keymap km = JTextComponent.addKeymap(getKeymapName(), JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP)); JTextComponent.loadKeymap(km, bindings, textComponent.getActions()); return km; }
SwingUtilities.replaceUIActionMap(textComponent, getActionMap());
SwingUtilities.replaceUIActionMap(textComponent, createActionMap()); ActionMap parentActionMap = new ActionMapUIResource(); Action[] actions = textComponent.getActions(); for (int j = 0; j < actions.length; j++) { Action currAction = actions[j]; parentActionMap.put(currAction.getValue(Action.NAME), currAction); } SwingUtilities.replaceUIActionMap(textComponent, parentActionMap);
protected void installKeyboardActions() { // load any bindings for the older Keymap interface Keymap km = JTextComponent.getKeymap(getKeymapName()); if (km == null) km = createKeymap(); textComponent.setKeymap(km); // load any bindings for the newer InputMap / ActionMap interface SwingUtilities.replaceUIInputMap(textComponent, JComponent.WHEN_FOCUSED, getInputMap(JComponent.WHEN_FOCUSED)); SwingUtilities.replaceUIActionMap(textComponent, getActionMap()); }
{ Event oldStyleEvent; oldStyleEvent = Component.translateEvent(event); if (oldStyleEvent != null)
void dispatchEventImpl(AWTEvent event){ Event oldStyleEvent; // This is overridden by subclasses that support events. /* Convert AWT 1.1 event to AWT 1.0 event */ oldStyleEvent = Component.translateEvent(event); if (oldStyleEvent != null) { postEvent(oldStyleEvent); } /* Do local processing */ processEvent(event);}
postEvent(oldStyleEvent); }
void dispatchEventImpl(AWTEvent event){ Event oldStyleEvent; // This is overridden by subclasses that support events. /* Convert AWT 1.1 event to AWT 1.0 event */ oldStyleEvent = Component.translateEvent(event); if (oldStyleEvent != null) { postEvent(oldStyleEvent); } /* Do local processing */ processEvent(event);}
getParent() { return(parent); }
public MenuContainer getParent() { return parent; }
getParent(){ return(parent);}
paramString() {
protected String paramString() {
paramString(){ return "name=" + getName();}
processEvent(AWTEvent event) {
protected void processEvent(AWTEvent event) {
processEvent(AWTEvent event){ /* Pass a focus event to the focus listener for the accessibility context. */ if (event instanceof FocusEvent) { if (focusListener != null) { switch (event.id) { case FocusEvent.FOCUS_GAINED: focusListener.focusGained((FocusEvent) event); break; case FocusEvent.FOCUS_LOST: focusListener.focusLost((FocusEvent) event); break; } } }}
vr.x = br.width - ar.width;
vr.x = br.width - ar.width - defaultTextIconGap;
protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { JMenuItem m = (JMenuItem) c; Rectangle tr = new Rectangle(); // text rectangle Rectangle ir = new Rectangle(); // icon rectangle Rectangle vr = new Rectangle(); // view rectangle Rectangle br = new Rectangle(); // border rectangle Rectangle ar = new Rectangle(); // accelerator rectangle Rectangle cr = new Rectangle(); // checkIcon rectangle int vertAlign = m.getVerticalAlignment(); int horAlign = m.getHorizontalAlignment(); int vertTextPos = m.getVerticalTextPosition(); int horTextPos = m.getHorizontalTextPosition(); Font f = m.getFont(); g.setFont(f); FontMetrics fm = g.getFontMetrics(f); SwingUtilities.calculateInnerArea(m, br); SwingUtilities.calculateInsetArea(br, m.getInsets(), vr); paintBackground(g, m, m.getBackground()); /* MenuItems insets are equal to menuItems margin, space between text and menuItems border. We need to paint insets region as well. */ Insets insets = m.getInsets(); br.x -= insets.left; br.y -= insets.top; br.width += insets.right + insets.left; br.height += insets.top + insets.bottom; // Menu item is considered to be highlighted when it is selected. // But we don't want to paint the background of JCheckBoxMenuItems if ((m.isSelected() && checkIcon == null) || m.getModel().isArmed() && (m.getParent() instanceof MenuElement)) { if (m.isContentAreaFilled()) { g.setColor(selectionBackground); g.fillRect(br.x, br.y, br.width, br.height); } } else { if (m.isContentAreaFilled()) { g.setColor(m.getBackground()); g.fillRect(br.x, br.y, br.width, br.height); } } // If this menu item is a JCheckBoxMenuItem then paint check icon if (checkIcon != null) { SwingUtilities.layoutCompoundLabel(m, fm, null, checkIcon, vertAlign, horAlign, vertTextPos, horTextPos, vr, cr, tr, defaultTextIconGap); checkIcon.paintIcon(m, g, cr.x, cr.y); // We need to calculate position of the menu text and position of // user menu icon if there exists one relative to the check icon. // So we need to adjust view rectangle s.t. its starting point is at // checkIcon.width + defaultTextIconGap. vr.x = cr.x + cr.width + defaultTextIconGap; } // if this is a submenu, then paint arrow icon to indicate it. if (arrowIcon != null && (c instanceof JMenu)) { if (! ((JMenu) c).isTopLevelMenu()) { int width = arrowIcon.getIconWidth(); int height = arrowIcon.getIconHeight(); arrowIcon.paintIcon(m, g, vr.width - width + defaultTextIconGap, vr.y + 2); } } // paint text and user menu icon if it exists Icon i = m.getIcon(); SwingUtilities.layoutCompoundLabel(c, fm, m.getText(), i, vertAlign, horAlign, vertTextPos, horTextPos, vr, ir, tr, defaultTextIconGap); if (i != null) i.paintIcon(c, g, ir.x, ir.y); paintText(g, m, tr, m.getText()); // paint accelerator String acceleratorText = ""; if (m.getAccelerator() != null) { acceleratorText = getAcceleratorText(m.getAccelerator()); fm = g.getFontMetrics(acceleratorFont); ar.width = fm.stringWidth(acceleratorText); ar.x = br.width - ar.width; vr.x = br.width - ar.width; SwingUtilities.layoutCompoundLabel(m, fm, acceleratorText, null, vertAlign, horAlign, vertTextPos, horTextPos, vr, ir, ar, defaultTextIconGap); paintAccelerator(g, m, ar, acceleratorText); } }
parentInputMap.put(KeyStroke.getKeyStroke (((KeyStroke)keys[i]).getKeyCode(), convertModifiers (((KeyStroke)keys[i]).getModifiers())), (String)ancestorMap.get((KeyStroke)keys[i]));
KeyStroke stroke = (KeyStroke)keys[i]; String actionString = (String) ancestorMap.get(stroke);
protected void installKeyboardActions() { UIDefaults defaults = UIManager.getLookAndFeelDefaults(); InputMap ancestorMap = (InputMap)defaults.get("Table.ancestorInputMap"); InputMapUIResource parentInputMap = new InputMapUIResource(); // FIXME: The JDK uses a LazyActionMap for parentActionMap ActionMap parentActionMap = new ActionMap(); action = new TableAction(); Object keys[] = ancestorMap.allKeys(); // Register key bindings in the UI InputMap-ActionMap pair // Note that we register key bindings with both the old and new modifier // masks: InputEvent.SHIFT_MASK and InputEvent.SHIFT_DOWN_MASK and so on. for (int i = 0; i < keys.length; i++) { parentInputMap.put(KeyStroke.getKeyStroke (((KeyStroke)keys[i]).getKeyCode(), convertModifiers (((KeyStroke)keys[i]).getModifiers())), (String)ancestorMap.get((KeyStroke)keys[i])); parentInputMap.put(KeyStroke.getKeyStroke (((KeyStroke)keys[i]).getKeyCode(), ((KeyStroke)keys[i]).getModifiers()), (String)ancestorMap.get((KeyStroke)keys[i])); parentActionMap.put ((String)ancestorMap.get((KeyStroke)keys[i]), new ActionListenerProxy (action, (String)ancestorMap.get((KeyStroke)keys[i]))); } // Set the UI InputMap-ActionMap pair to be the parents of the // JTable's InputMap-ActionMap pair parentInputMap.setParent (table.getInputMap (JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).getParent()); parentActionMap.setParent(table.getActionMap().getParent()); table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT). setParent(parentInputMap); table.getActionMap().setParent(parentActionMap); }
parentInputMap.put(KeyStroke.getKeyStroke (((KeyStroke)keys[i]).getKeyCode(), ((KeyStroke)keys[i]).getModifiers()), (String)ancestorMap.get((KeyStroke)keys[i]));
parentInputMap.put(KeyStroke.getKeyStroke(stroke.getKeyCode(), stroke.getModifiers()), actionString);
protected void installKeyboardActions() { UIDefaults defaults = UIManager.getLookAndFeelDefaults(); InputMap ancestorMap = (InputMap)defaults.get("Table.ancestorInputMap"); InputMapUIResource parentInputMap = new InputMapUIResource(); // FIXME: The JDK uses a LazyActionMap for parentActionMap ActionMap parentActionMap = new ActionMap(); action = new TableAction(); Object keys[] = ancestorMap.allKeys(); // Register key bindings in the UI InputMap-ActionMap pair // Note that we register key bindings with both the old and new modifier // masks: InputEvent.SHIFT_MASK and InputEvent.SHIFT_DOWN_MASK and so on. for (int i = 0; i < keys.length; i++) { parentInputMap.put(KeyStroke.getKeyStroke (((KeyStroke)keys[i]).getKeyCode(), convertModifiers (((KeyStroke)keys[i]).getModifiers())), (String)ancestorMap.get((KeyStroke)keys[i])); parentInputMap.put(KeyStroke.getKeyStroke (((KeyStroke)keys[i]).getKeyCode(), ((KeyStroke)keys[i]).getModifiers()), (String)ancestorMap.get((KeyStroke)keys[i])); parentActionMap.put ((String)ancestorMap.get((KeyStroke)keys[i]), new ActionListenerProxy (action, (String)ancestorMap.get((KeyStroke)keys[i]))); } // Set the UI InputMap-ActionMap pair to be the parents of the // JTable's InputMap-ActionMap pair parentInputMap.setParent (table.getInputMap (JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).getParent()); parentActionMap.setParent(table.getActionMap().getParent()); table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT). setParent(parentInputMap); table.getActionMap().setParent(parentActionMap); }
parentActionMap.put ((String)ancestorMap.get((KeyStroke)keys[i]), new ActionListenerProxy (action, (String)ancestorMap.get((KeyStroke)keys[i])));
parentActionMap.put (actionString, new ActionListenerProxy (action, actionString));
protected void installKeyboardActions() { UIDefaults defaults = UIManager.getLookAndFeelDefaults(); InputMap ancestorMap = (InputMap)defaults.get("Table.ancestorInputMap"); InputMapUIResource parentInputMap = new InputMapUIResource(); // FIXME: The JDK uses a LazyActionMap for parentActionMap ActionMap parentActionMap = new ActionMap(); action = new TableAction(); Object keys[] = ancestorMap.allKeys(); // Register key bindings in the UI InputMap-ActionMap pair // Note that we register key bindings with both the old and new modifier // masks: InputEvent.SHIFT_MASK and InputEvent.SHIFT_DOWN_MASK and so on. for (int i = 0; i < keys.length; i++) { parentInputMap.put(KeyStroke.getKeyStroke (((KeyStroke)keys[i]).getKeyCode(), convertModifiers (((KeyStroke)keys[i]).getModifiers())), (String)ancestorMap.get((KeyStroke)keys[i])); parentInputMap.put(KeyStroke.getKeyStroke (((KeyStroke)keys[i]).getKeyCode(), ((KeyStroke)keys[i]).getModifiers()), (String)ancestorMap.get((KeyStroke)keys[i])); parentActionMap.put ((String)ancestorMap.get((KeyStroke)keys[i]), new ActionListenerProxy (action, (String)ancestorMap.get((KeyStroke)keys[i]))); } // Set the UI InputMap-ActionMap pair to be the parents of the // JTable's InputMap-ActionMap pair parentInputMap.setParent (table.getInputMap (JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).getParent()); parentActionMap.setParent(table.getActionMap().getParent()); table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT). setParent(parentInputMap); table.getActionMap().setParent(parentActionMap); }
IDEBus ideBus = FSDriverUtils.getIDEDeviceFactory().createIDEBus(parentDev, primary);
IDEBus ideBus; try { ideBus = IDEDriverUtils.getIDEDeviceFactory().createIDEBus(parentDev, primary); } catch (NamingException ex) { throw new DriverException(ex); }
public static IDEDevice createIDEDevice(Device parentDev, TestCase testCase, final boolean supp48bitsAddr, final long deviceSize) throws IllegalArgumentException, DriverException, ResourceNotFreeException { if((deviceSize % IDEConstants.SECTOR_SIZE) != 0) { throw new IllegalArgumentException("deviceSize("+deviceSize+ ") must be a multiple of SECTOR_SIZE("+IDEConstants.SECTOR_SIZE+")"); } boolean master = true; boolean primary = true; IDEBus ideBus = FSDriverUtils.getIDEDeviceFactory().createIDEBus(parentDev, primary); // must have length 256 (see IDEDriveDescriptor) int[] data = new int[256]; Boolean atapi = Boolean.valueOf(true); final MockObjectTestCase mockTestCase = (MockObjectTestCase) testCase; MockInitializer initializer = new MockInitializer() { public void init(Mock mockDesc) { Boolean bSupp48bitsAddr = Boolean.valueOf(supp48bitsAddr); mockDesc.expects(mockTestCase.atLeastOnce()). method("supports48bitAddressing"). withNoArguments().will(new ReturnStub(bSupp48bitsAddr)); long nbSectors = deviceSize / IDEConstants.SECTOR_SIZE; Long lNbSectors = new Long(nbSectors); String methodName = supp48bitsAddr ? "getSectorsIn48bitAddressing" : "getSectorsIn28bitAddressing"; mockDesc.expects(mockTestCase.atLeastOnce()). method(methodName). withNoArguments().will(new ReturnStub(lNbSectors)); } }; Class[] clsArgs = {int[].class, boolean.class}; Object[] args = {data, atapi}; IDEDriveDescriptor desc = (IDEDriveDescriptor) MockUtils.createMockObject(IDEDriveDescriptor.class, initializer, clsArgs, args); DefaultIDEControllerDriver ctrlDriver = new DefaultIDEControllerDriver(); IDEDevice device = new IDEDevice(ideBus, primary, master, "hdTest", desc, ctrlDriver); return device; }
repaintLeadCell();
public void focusGained(FocusEvent e) { // TODO: Implement this properly. }
repaintLeadCell();
public void focusLost(FocusEvent e) { // TODO: Implement this properly. }
table.requestFocusInWindow();
public void mousePressed(MouseEvent e) { if (table.isEnabled()) { ListSelectionModel rowModel = table.getSelectionModel(); ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int colLead = colModel.getLeadSelectionIndex(); begin = new Point(e.getX(), e.getY()); curr = new Point(e.getX(), e.getY()); //if control is pressed and the cell is already selected, deselect it if (e.isControlDown() && table. isCellSelected(table.rowAtPoint(begin),table.columnAtPoint(begin))) { table.getSelectionModel(). removeSelectionInterval(table.rowAtPoint(begin), table.rowAtPoint(begin)); table.getColumnModel().getSelectionModel(). removeSelectionInterval(table.columnAtPoint(begin), table.columnAtPoint(begin)); } else updateSelection(e.isControlDown()); // If we were editing, but the moved to another cell, stop editing if (rowLead != rowModel.getLeadSelectionIndex() || colLead != colModel.getLeadSelectionIndex()) if (table.isEditing()) table.editingStopped(new ChangeEvent(e)); } }
DefaultListSelectionModel rowModel = (DefaultListSelectionModel) table.getSelectionModel(); DefaultListSelectionModel colModel = (DefaultListSelectionModel) table.getColumnModel().getSelectionModel();
JTable table = (JTable) e.getSource(); DefaultListSelectionModel rowModel = (DefaultListSelectionModel) table.getSelectionModel(); DefaultListSelectionModel colModel = (DefaultListSelectionModel) table.getColumnModel().getSelectionModel();
public void actionPerformed (ActionEvent e) { DefaultListSelectionModel rowModel = (DefaultListSelectionModel) table.getSelectionModel(); DefaultListSelectionModel colModel = (DefaultListSelectionModel) table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; String command = e.getActionCommand(); if (command.equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectLastColumn")) { colModel.setSelectionInterval(colMax, colMax); } else if (command.equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (command.equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); } else if (command.equals("selectFirstColumn")) { colModel.setSelectionInterval(0, 0); } else if (command.equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); } else if (command.equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); } else if (command.equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); } else if (command.equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); } else if (command.equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); } else if (command.equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); } else if (command.equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("selectPreviousColumn")) { colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (command.equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("clearSelection")) { table.clearSelection(); } else if (command.equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (command.equals("selectNextRowCell") || command.equals("selectPreviousRowCell") || command.equals("selectNextColumnCell") || command.equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (command.indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (command.equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (command.equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (command.indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (command.equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (command.equals ("selectPreviousRowCell")), false); } else if (command.equals("selectNextColumn")) { colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (command.equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectAll")) { table.selectAll(); } else if (command.equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("selectNextRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just "selectNextRow" rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectPreviousRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousRow rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.min(rowLead -1, 0)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectNextColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectNextColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else colModel.moveLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectPreviousColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else colModel.moveLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("addToSelection")) { if (!table.isEditing()) { int oldRowAnchor = rowModel.getAnchorSelectionIndex(); int oldColAnchor = colModel.getAnchorSelectionIndex(); rowModel.addSelectionInterval(rowLead, rowLead); colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(oldRowAnchor); colModel.setAnchorSelectionIndex(oldColAnchor); } } else if (command.equals("extendTo")) { rowModel.setSelectionInterval(rowModel.getAnchorSelectionIndex(), rowLead); colModel.setSelectionInterval(colModel.getAnchorSelectionIndex(), colLead); } else if (command.equals("toggleAndAnchor")) { if (rowModel.isSelectedIndex(rowLead)) rowModel.removeSelectionInterval(rowLead, rowLead); else rowModel.addSelectionInterval(rowLead, rowLead); if (colModel.isSelectedIndex(colLead)) colModel.removeSelectionInterval(colLead, colLead); else colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(rowLead); colModel.setAnchorSelectionIndex(colLead); } else if (command.equals("stopEditing")) { table.editingStopped(new ChangeEvent(command)); } 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. // Uncomment the following line to print the names of unused bindings // when their keys are pressed // System.out.println ("not implemented: "+e.getActionCommand()); } // Any commands whose keyStrokes should be used by the Editor should not // cause editing to be stopped: ie, the SPACE sends "addToSelection" but // if the table is in editing mode, the space should not cause us to stop // editing because it should be used by the Editor. if (table.isEditing() && command != "startEditing" && command != "addToSelection") table.editingStopped(new ChangeEvent("update")); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
String command = e.getActionCommand();
String command = (String) getValue("__command__");
public void actionPerformed (ActionEvent e) { DefaultListSelectionModel rowModel = (DefaultListSelectionModel) table.getSelectionModel(); DefaultListSelectionModel colModel = (DefaultListSelectionModel) table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; String command = e.getActionCommand(); if (command.equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectLastColumn")) { colModel.setSelectionInterval(colMax, colMax); } else if (command.equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (command.equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); } else if (command.equals("selectFirstColumn")) { colModel.setSelectionInterval(0, 0); } else if (command.equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); } else if (command.equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); } else if (command.equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); } else if (command.equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); } else if (command.equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); } else if (command.equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); } else if (command.equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("selectPreviousColumn")) { colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (command.equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("clearSelection")) { table.clearSelection(); } else if (command.equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (command.equals("selectNextRowCell") || command.equals("selectPreviousRowCell") || command.equals("selectNextColumnCell") || command.equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (command.indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (command.equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (command.equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (command.indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (command.equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (command.equals ("selectPreviousRowCell")), false); } else if (command.equals("selectNextColumn")) { colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (command.equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectAll")) { table.selectAll(); } else if (command.equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("selectNextRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just "selectNextRow" rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectPreviousRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousRow rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.min(rowLead -1, 0)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectNextColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectNextColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else colModel.moveLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectPreviousColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else colModel.moveLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("addToSelection")) { if (!table.isEditing()) { int oldRowAnchor = rowModel.getAnchorSelectionIndex(); int oldColAnchor = colModel.getAnchorSelectionIndex(); rowModel.addSelectionInterval(rowLead, rowLead); colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(oldRowAnchor); colModel.setAnchorSelectionIndex(oldColAnchor); } } else if (command.equals("extendTo")) { rowModel.setSelectionInterval(rowModel.getAnchorSelectionIndex(), rowLead); colModel.setSelectionInterval(colModel.getAnchorSelectionIndex(), colLead); } else if (command.equals("toggleAndAnchor")) { if (rowModel.isSelectedIndex(rowLead)) rowModel.removeSelectionInterval(rowLead, rowLead); else rowModel.addSelectionInterval(rowLead, rowLead); if (colModel.isSelectedIndex(colLead)) colModel.removeSelectionInterval(colLead, colLead); else colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(rowLead); colModel.setAnchorSelectionIndex(colLead); } else if (command.equals("stopEditing")) { table.editingStopped(new ChangeEvent(command)); } 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. // Uncomment the following line to print the names of unused bindings // when their keys are pressed // System.out.println ("not implemented: "+e.getActionCommand()); } // Any commands whose keyStrokes should be used by the Editor should not // cause editing to be stopped: ie, the SPACE sends "addToSelection" but // if the table is in editing mode, the space should not cause us to stop // editing because it should be used by the Editor. if (table.isEditing() && command != "startEditing" && command != "addToSelection") table.editingStopped(new ChangeEvent("update")); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex();
if (rowLead == getFirstVisibleRowIndex(table)) target = Math.max(0, rowLead - (getLastVisibleRowIndex(table) - getFirstVisibleRowIndex(table) + 1)); else target = getFirstVisibleRowIndex(table);
public void actionPerformed (ActionEvent e) { DefaultListSelectionModel rowModel = (DefaultListSelectionModel) table.getSelectionModel(); DefaultListSelectionModel colModel = (DefaultListSelectionModel) table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; String command = e.getActionCommand(); if (command.equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectLastColumn")) { colModel.setSelectionInterval(colMax, colMax); } else if (command.equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (command.equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); } else if (command.equals("selectFirstColumn")) { colModel.setSelectionInterval(0, 0); } else if (command.equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); } else if (command.equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); } else if (command.equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); } else if (command.equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); } else if (command.equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); } else if (command.equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); } else if (command.equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("selectPreviousColumn")) { colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (command.equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("clearSelection")) { table.clearSelection(); } else if (command.equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (command.equals("selectNextRowCell") || command.equals("selectPreviousRowCell") || command.equals("selectNextColumnCell") || command.equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (command.indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (command.equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (command.equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (command.indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (command.equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (command.equals ("selectPreviousRowCell")), false); } else if (command.equals("selectNextColumn")) { colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (command.equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectAll")) { table.selectAll(); } else if (command.equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("selectNextRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just "selectNextRow" rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectPreviousRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousRow rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.min(rowLead -1, 0)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectNextColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectNextColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else colModel.moveLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectPreviousColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else colModel.moveLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("addToSelection")) { if (!table.isEditing()) { int oldRowAnchor = rowModel.getAnchorSelectionIndex(); int oldColAnchor = colModel.getAnchorSelectionIndex(); rowModel.addSelectionInterval(rowLead, rowLead); colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(oldRowAnchor); colModel.setAnchorSelectionIndex(oldColAnchor); } } else if (command.equals("extendTo")) { rowModel.setSelectionInterval(rowModel.getAnchorSelectionIndex(), rowLead); colModel.setSelectionInterval(colModel.getAnchorSelectionIndex(), colLead); } else if (command.equals("toggleAndAnchor")) { if (rowModel.isSelectedIndex(rowLead)) rowModel.removeSelectionInterval(rowLead, rowLead); else rowModel.addSelectionInterval(rowLead, rowLead); if (colModel.isSelectedIndex(colLead)) colModel.removeSelectionInterval(colLead, colLead); else colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(rowLead); colModel.setAnchorSelectionIndex(colLead); } else if (command.equals("stopEditing")) { table.editingStopped(new ChangeEvent(command)); } 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. // Uncomment the following line to print the names of unused bindings // when their keys are pressed // System.out.println ("not implemented: "+e.getActionCommand()); } // Any commands whose keyStrokes should be used by the Editor should not // cause editing to be stopped: ie, the SPACE sends "addToSelection" but // if the table is in editing mode, the space should not cause us to stop // editing because it should be used by the Editor. if (table.isEditing() && command != "startEditing" && command != "addToSelection") table.editingStopped(new ChangeEvent("update")); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex();
if (colLead == getLastVisibleColumnIndex(table)) target = Math.min(colMax, colLead + (getLastVisibleColumnIndex(table) - getFirstVisibleColumnIndex(table) + 1)); else target = getLastVisibleColumnIndex(table);
public void actionPerformed (ActionEvent e) { DefaultListSelectionModel rowModel = (DefaultListSelectionModel) table.getSelectionModel(); DefaultListSelectionModel colModel = (DefaultListSelectionModel) table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; String command = e.getActionCommand(); if (command.equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectLastColumn")) { colModel.setSelectionInterval(colMax, colMax); } else if (command.equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (command.equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); } else if (command.equals("selectFirstColumn")) { colModel.setSelectionInterval(0, 0); } else if (command.equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); } else if (command.equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); } else if (command.equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); } else if (command.equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); } else if (command.equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); } else if (command.equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); } else if (command.equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("selectPreviousColumn")) { colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (command.equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("clearSelection")) { table.clearSelection(); } else if (command.equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (command.equals("selectNextRowCell") || command.equals("selectPreviousRowCell") || command.equals("selectNextColumnCell") || command.equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (command.indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (command.equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (command.equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (command.indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (command.equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (command.equals ("selectPreviousRowCell")), false); } else if (command.equals("selectNextColumn")) { colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (command.equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectAll")) { table.selectAll(); } else if (command.equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("selectNextRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just "selectNextRow" rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectPreviousRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousRow rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.min(rowLead -1, 0)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectNextColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectNextColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else colModel.moveLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectPreviousColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else colModel.moveLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("addToSelection")) { if (!table.isEditing()) { int oldRowAnchor = rowModel.getAnchorSelectionIndex(); int oldColAnchor = colModel.getAnchorSelectionIndex(); rowModel.addSelectionInterval(rowLead, rowLead); colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(oldRowAnchor); colModel.setAnchorSelectionIndex(oldColAnchor); } } else if (command.equals("extendTo")) { rowModel.setSelectionInterval(rowModel.getAnchorSelectionIndex(), rowLead); colModel.setSelectionInterval(colModel.getAnchorSelectionIndex(), colLead); } else if (command.equals("toggleAndAnchor")) { if (rowModel.isSelectedIndex(rowLead)) rowModel.removeSelectionInterval(rowLead, rowLead); else rowModel.addSelectionInterval(rowLead, rowLead); if (colModel.isSelectedIndex(colLead)) colModel.removeSelectionInterval(colLead, colLead); else colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(rowLead); colModel.setAnchorSelectionIndex(colLead); } else if (command.equals("stopEditing")) { table.editingStopped(new ChangeEvent(command)); } 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. // Uncomment the following line to print the names of unused bindings // when their keys are pressed // System.out.println ("not implemented: "+e.getActionCommand()); } // Any commands whose keyStrokes should be used by the Editor should not // cause editing to be stopped: ie, the SPACE sends "addToSelection" but // if the table is in editing mode, the space should not cause us to stop // editing because it should be used by the Editor. if (table.isEditing() && command != "startEditing" && command != "addToSelection") table.editingStopped(new ChangeEvent("update")); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex();
if (colLead == getFirstVisibleColumnIndex(table)) target = Math.max(0, colLead - (getLastVisibleColumnIndex(table) - getFirstVisibleColumnIndex(table) + 1)); else target = getFirstVisibleColumnIndex(table);
public void actionPerformed (ActionEvent e) { DefaultListSelectionModel rowModel = (DefaultListSelectionModel) table.getSelectionModel(); DefaultListSelectionModel colModel = (DefaultListSelectionModel) table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; String command = e.getActionCommand(); if (command.equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectLastColumn")) { colModel.setSelectionInterval(colMax, colMax); } else if (command.equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (command.equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); } else if (command.equals("selectFirstColumn")) { colModel.setSelectionInterval(0, 0); } else if (command.equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); } else if (command.equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); } else if (command.equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); } else if (command.equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); } else if (command.equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); } else if (command.equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); } else if (command.equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("selectPreviousColumn")) { colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (command.equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("clearSelection")) { table.clearSelection(); } else if (command.equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (command.equals("selectNextRowCell") || command.equals("selectPreviousRowCell") || command.equals("selectNextColumnCell") || command.equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (command.indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (command.equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (command.equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (command.indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (command.equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (command.equals ("selectPreviousRowCell")), false); } else if (command.equals("selectNextColumn")) { colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (command.equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectAll")) { table.selectAll(); } else if (command.equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("selectNextRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just "selectNextRow" rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectPreviousRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousRow rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.min(rowLead -1, 0)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectNextColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectNextColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else colModel.moveLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectPreviousColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else colModel.moveLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("addToSelection")) { if (!table.isEditing()) { int oldRowAnchor = rowModel.getAnchorSelectionIndex(); int oldColAnchor = colModel.getAnchorSelectionIndex(); rowModel.addSelectionInterval(rowLead, rowLead); colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(oldRowAnchor); colModel.setAnchorSelectionIndex(oldColAnchor); } } else if (command.equals("extendTo")) { rowModel.setSelectionInterval(rowModel.getAnchorSelectionIndex(), rowLead); colModel.setSelectionInterval(colModel.getAnchorSelectionIndex(), colLead); } else if (command.equals("toggleAndAnchor")) { if (rowModel.isSelectedIndex(rowLead)) rowModel.removeSelectionInterval(rowLead, rowLead); else rowModel.addSelectionInterval(rowLead, rowLead); if (colModel.isSelectedIndex(colLead)) colModel.removeSelectionInterval(colLead, colLead); else colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(rowLead); colModel.setAnchorSelectionIndex(colLead); } else if (command.equals("stopEditing")) { table.editingStopped(new ChangeEvent(command)); } 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. // Uncomment the following line to print the names of unused bindings // when their keys are pressed // System.out.println ("not implemented: "+e.getActionCommand()); } // Any commands whose keyStrokes should be used by the Editor should not // cause editing to be stopped: ie, the SPACE sends "addToSelection" but // if the table is in editing mode, the space should not cause us to stop // editing because it should be used by the Editor. if (table.isEditing() && command != "startEditing" && command != "addToSelection") table.editingStopped(new ChangeEvent("update")); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
(command.equals ("selectPreviousColumnCell")));
command.equals("selectPreviousColumnCell"));
public void actionPerformed (ActionEvent e) { DefaultListSelectionModel rowModel = (DefaultListSelectionModel) table.getSelectionModel(); DefaultListSelectionModel colModel = (DefaultListSelectionModel) table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; String command = e.getActionCommand(); if (command.equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectLastColumn")) { colModel.setSelectionInterval(colMax, colMax); } else if (command.equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (command.equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); } else if (command.equals("selectFirstColumn")) { colModel.setSelectionInterval(0, 0); } else if (command.equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); } else if (command.equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); } else if (command.equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); } else if (command.equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); } else if (command.equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); } else if (command.equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); } else if (command.equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("selectPreviousColumn")) { colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (command.equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("clearSelection")) { table.clearSelection(); } else if (command.equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (command.equals("selectNextRowCell") || command.equals("selectPreviousRowCell") || command.equals("selectNextColumnCell") || command.equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (command.indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (command.equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (command.equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (command.indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (command.equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (command.equals ("selectPreviousRowCell")), false); } else if (command.equals("selectNextColumn")) { colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (command.equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectAll")) { table.selectAll(); } else if (command.equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("selectNextRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just "selectNextRow" rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectPreviousRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousRow rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.min(rowLead -1, 0)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectNextColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectNextColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else colModel.moveLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectPreviousColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else colModel.moveLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("addToSelection")) { if (!table.isEditing()) { int oldRowAnchor = rowModel.getAnchorSelectionIndex(); int oldColAnchor = colModel.getAnchorSelectionIndex(); rowModel.addSelectionInterval(rowLead, rowLead); colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(oldRowAnchor); colModel.setAnchorSelectionIndex(oldColAnchor); } } else if (command.equals("extendTo")) { rowModel.setSelectionInterval(rowModel.getAnchorSelectionIndex(), rowLead); colModel.setSelectionInterval(colModel.getAnchorSelectionIndex(), colLead); } else if (command.equals("toggleAndAnchor")) { if (rowModel.isSelectedIndex(rowLead)) rowModel.removeSelectionInterval(rowLead, rowLead); else rowModel.addSelectionInterval(rowLead, rowLead); if (colModel.isSelectedIndex(colLead)) colModel.removeSelectionInterval(colLead, colLead); else colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(rowLead); colModel.setAnchorSelectionIndex(colLead); } else if (command.equals("stopEditing")) { table.editingStopped(new ChangeEvent(command)); } 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. // Uncomment the following line to print the names of unused bindings // when their keys are pressed // System.out.println ("not implemented: "+e.getActionCommand()); } // Any commands whose keyStrokes should be used by the Editor should not // cause editing to be stopped: ie, the SPACE sends "addToSelection" but // if the table is in editing mode, the space should not cause us to stop // editing because it should be used by the Editor. if (table.isEditing() && command != "startEditing" && command != "addToSelection") table.editingStopped(new ChangeEvent("update")); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }
(command.equals ("selectPreviousRowCell")));
command.equals("selectPreviousRowCell"));
public void actionPerformed (ActionEvent e) { DefaultListSelectionModel rowModel = (DefaultListSelectionModel) table.getSelectionModel(); DefaultListSelectionModel colModel = (DefaultListSelectionModel) table.getColumnModel().getSelectionModel(); int rowLead = rowModel.getLeadSelectionIndex(); int rowMax = table.getModel().getRowCount() - 1; int colLead = colModel.getLeadSelectionIndex(); int colMax = table.getModel().getColumnCount() - 1; String command = e.getActionCommand(); if (command.equals("selectPreviousRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectLastColumn")) { colModel.setSelectionInterval(colMax, colMax); } else if (command.equals("startEditing")) { if (table.isCellEditable(rowLead, colLead)) table.editCellAt(rowLead,colLead); } else if (command.equals("selectFirstRowExtendSelection")) { rowModel.setLeadSelectionIndex(0); } else if (command.equals("selectFirstColumn")) { colModel.setSelectionInterval(0, 0); } else if (command.equals("selectFirstColumnExtendSelection")) { colModel.setLeadSelectionIndex(0); } else if (command.equals("selectLastRow")) { rowModel.setSelectionInterval(rowMax,rowMax); } else if (command.equals("selectNextRowExtendSelection")) { rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectFirstRow")) { rowModel.setSelectionInterval(0,0); } else if (command.equals("selectNextColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectLastColumnExtendSelection")) { colModel.setLeadSelectionIndex(colMax); } else if (command.equals("selectPreviousColumnExtendSelection")) { colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("selectNextRow")) { rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); } else if (command.equals("scrollUpExtendSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("selectPreviousRow")) { rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.max(rowLead - 1, 0)); } else if (command.equals("scrollRightChangeSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("selectPreviousColumn")) { colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else if (command.equals("scrollLeftChangeSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setSelectionInterval(target, target); rowModel.setSelectionInterval(rowLead, rowLead); } else if (command.equals("clearSelection")) { table.clearSelection(); } else if (command.equals("cancel")) { // FIXME: implement other parts of "cancel" like undo-ing last // selection. Right now it just calls editingCancelled if // we're currently editing. if (table.isEditing()) table.editingCanceled(new ChangeEvent("cancel")); } else if (command.equals("selectNextRowCell") || command.equals("selectPreviousRowCell") || command.equals("selectNextColumnCell") || command.equals("selectPreviousColumnCell")) { // If nothing is selected, select the first cell in the table if (table.getSelectedRowCount() == 0 && table.getSelectedColumnCount() == 0) { rowModel.setSelectionInterval(0, 0); colModel.setSelectionInterval(0, 0); return; } // If the lead selection index isn't selected (ie a remove operation // happened, then set the lead to the first selected cell in the // table if (!table.isCellSelected(rowLead, colLead)) { rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), rowModel.getMinSelectionIndex()); colModel.addSelectionInterval(colModel.getMinSelectionIndex(), colModel.getMinSelectionIndex()); return; } // multRowsSelected and multColsSelected tell us if multiple rows or // columns are selected, respectively boolean multRowsSelected, multColsSelected; multRowsSelected = table.getSelectedRowCount() > 1 && table.getRowSelectionAllowed(); multColsSelected = table.getSelectedColumnCount() > 1 && table.getColumnSelectionAllowed(); // If there is just one selection, select the next cell, and wrap // when you get to the edges of the table. if (!multColsSelected && !multRowsSelected) { if (command.indexOf("Column") != -1) advanceSingleSelection(colModel, colMax, rowModel, rowMax, (command.equals ("selectPreviousColumnCell"))); else advanceSingleSelection(rowModel, rowMax, colModel, colMax, (command.equals ("selectPreviousRowCell"))); return; } // rowMinSelected and rowMaxSelected are the minimum and maximum // values respectively of selected cells in the row selection model // Similarly for colMinSelected and colMaxSelected. int rowMaxSelected = table.getRowSelectionAllowed() ? rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; int rowMinSelected = table.getRowSelectionAllowed() ? rowModel.getMinSelectionIndex() : 0; int colMaxSelected = table.getColumnSelectionAllowed() ? colModel.getMaxSelectionIndex() : table.getModel().getColumnCount() - 1; int colMinSelected = table.getColumnSelectionAllowed() ? colModel.getMinSelectionIndex() : 0; // If there are multiple rows and columns selected, select the next // cell and wrap at the edges of the selection. if (command.indexOf("Column") != -1) advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, rowModel, rowMinSelected, rowMaxSelected, (command.equals ("selectPreviousColumnCell")), true); else advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, colModel, colMinSelected, colMaxSelected, (command.equals ("selectPreviousRowCell")), false); } else if (command.equals("selectNextColumn")) { colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else if (command.equals("scrollLeftExtendSelection")) { int target; if (colLead == getFirstVisibleColumnIndex()) target = Math.max (0, colLead - (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getFirstVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("scrollDownChangeSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("scrollRightExtendSelection")) { int target; if (colLead == getLastVisibleColumnIndex()) target = Math.min (colMax, colLead + (getLastVisibleColumnIndex() - getFirstVisibleColumnIndex() + 1)); else target = getLastVisibleColumnIndex(); colModel.setLeadSelectionIndex(target); rowModel.setLeadSelectionIndex(rowLead); } else if (command.equals("selectAll")) { table.selectAll(); } else if (command.equals("selectLastRowExtendSelection")) { rowModel.setLeadSelectionIndex(rowMax); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollDownExtendSelection")) { int target; if (rowLead == getLastVisibleRowIndex()) target = Math.min (rowMax, rowLead + (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getLastVisibleRowIndex(); rowModel.setLeadSelectionIndex(target); colModel.setLeadSelectionIndex(colLead); } else if (command.equals("scrollUpChangeSelection")) { int target; if (rowLead == getFirstVisibleRowIndex()) target = Math.max (0, rowLead - (getLastVisibleRowIndex() - getFirstVisibleRowIndex() + 1)); else target = getFirstVisibleRowIndex(); rowModel.setSelectionInterval(target, target); colModel.setSelectionInterval(colLead, colLead); } else if (command.equals("selectNextRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just "selectNextRow" rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), Math.min(rowLead + 1, rowMax)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); } else if (command.equals("selectPreviousRowChangeLead")) { if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousRow rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), Math.min(rowLead -1, 0)); colModel.setSelectionInterval(colLead,colLead); } else rowModel.moveLeadSelectionIndex(Math.max(rowLead - 1, 0)); } else if (command.equals("selectNextColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectNextColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.min(colLead + 1, colMax), Math.min(colLead + 1, colMax)); } else colModel.moveLeadSelectionIndex(Math.min(colLead + 1, colMax)); } else if (command.equals("selectPreviousColumnChangeLead")) { if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) { // just selectPreviousColumn rowModel.setSelectionInterval(rowLead,rowLead); colModel.setSelectionInterval(Math.max(colLead - 1, 0), Math.max(colLead - 1, 0)); } else colModel.moveLeadSelectionIndex(Math.max(colLead - 1, 0)); } else if (command.equals("addToSelection")) { if (!table.isEditing()) { int oldRowAnchor = rowModel.getAnchorSelectionIndex(); int oldColAnchor = colModel.getAnchorSelectionIndex(); rowModel.addSelectionInterval(rowLead, rowLead); colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(oldRowAnchor); colModel.setAnchorSelectionIndex(oldColAnchor); } } else if (command.equals("extendTo")) { rowModel.setSelectionInterval(rowModel.getAnchorSelectionIndex(), rowLead); colModel.setSelectionInterval(colModel.getAnchorSelectionIndex(), colLead); } else if (command.equals("toggleAndAnchor")) { if (rowModel.isSelectedIndex(rowLead)) rowModel.removeSelectionInterval(rowLead, rowLead); else rowModel.addSelectionInterval(rowLead, rowLead); if (colModel.isSelectedIndex(colLead)) colModel.removeSelectionInterval(colLead, colLead); else colModel.addSelectionInterval(colLead, colLead); rowModel.setAnchorSelectionIndex(rowLead); colModel.setAnchorSelectionIndex(colLead); } else if (command.equals("stopEditing")) { table.editingStopped(new ChangeEvent(command)); } 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. // Uncomment the following line to print the names of unused bindings // when their keys are pressed // System.out.println ("not implemented: "+e.getActionCommand()); } // Any commands whose keyStrokes should be used by the Editor should not // cause editing to be stopped: ie, the SPACE sends "addToSelection" but // if the table is in editing mode, the space should not cause us to stop // editing because it should be used by the Editor. if (table.isEditing() && command != "startEditing" && command != "addToSelection") table.editingStopped(new ChangeEvent("update")); table.scrollRectToVisible (table.getCellRect(rowModel.getLeadSelectionIndex(), colModel.getLeadSelectionIndex(), false)); }