List of usage examples for javax.swing JComponent repaint
public void repaint()
From source file:com.haulmont.cuba.desktop.gui.components.DesktopScrollBoxLayout.java
protected void requestRepaint() { if (!scheduledRepaint) { SwingUtilities.invokeLater(new Runnable() { @Override/*from w w w . j ava 2 s.c o m*/ public void run() { JComponent view = DesktopComponentsHelper.getComposition(content); view.revalidate(); view.repaint(); scheduledRepaint = false; } }); scheduledRepaint = true; } }
From source file:net.sf.nmedit.patchmodifier.mutator.VariationTransferHandler.java
public boolean importData(JComponent c, Transferable t) { //System.out.println("import data"); Variation target;/*from w w w .j a va2s. co m*/ Vector<Integer> data = null; if (!canImport(c, t.getTransferDataFlavors())) { return false; } try { target = (Variation) c; if (t.isDataFlavorSupported(variationFlavor)) { data = ((VariationTransferData) t.getTransferData(variationFlavor)).getVariationData(); } else { return false; } } catch (UnsupportedFlavorException ufe) { if (log.isErrorEnabled()) { log.error("importData: unsupported data flavor", ufe); } return false; } catch (IOException ioe) { if (log.isErrorEnabled()) { log.error("importData: I/O exception", ioe); } return false; } target.getState().updateValues(new Vector<Integer>(data)); c.repaint(); return true; }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected JComponent showWindowThisTab(Window window, String caption, String description) { getDialogParams().reset();//from w w w .ja v a 2 s . com window.setWidth("100%"); window.setHeight("100%"); JComponent layout; if (isMainWindowManager) { layout = (JComponent) tabsPane.getSelectedComponent(); } else { layout = (JComponent) frame.getContentPane().getComponent(0); } WindowBreadCrumbs breadCrumbs = tabs.get(layout); if (breadCrumbs == null) throw new IllegalStateException("BreadCrumbs not found"); Window currentWindow = breadCrumbs.getCurrentWindow(); Window currentWindowFrame = (Window) currentWindow.getFrame(); windowOpenMode.get(currentWindowFrame).setFocusOwner(frame.getFocusOwner()); Set<Map.Entry<Window, Integer>> set = windows.entrySet(); boolean pushed = false; for (Map.Entry<Window, Integer> entry : set) { if (entry.getKey().equals(currentWindow)) { windows.remove(currentWindow); stacks.get(breadCrumbs).push(entry); pushed = true; break; } } if (!pushed) { stacks.get(breadCrumbs).push(new AbstractMap.SimpleEntry<>(currentWindow, null)); } windows.remove(window); layout.remove(DesktopComponentsHelper.getComposition(currentWindow)); JComponent component = DesktopComponentsHelper.getComposition(window); layout.add(component); breadCrumbs.addWindow(window); if (isMainWindowManager) { setActiveWindowCaption(caption, description, tabsPane.getSelectedIndex()); } else { setTopLevelWindowCaption(caption); component.revalidate(); component.repaint(); } return layout; }
From source file:edu.ku.brc.af.ui.forms.TableViewObj.java
/** * Deletes a Row in the table and there an data object * @param rowIndex the item to be deleted *//*from w ww.j a v a2 s. co m*/ protected void deleteRow(final int rowIndex) { FormDataObjIFace dObj = (FormDataObjIFace) dataObjList.get(rowIndex); if (dObj != null) { Object[] delBtnLabels = { getResourceString(addSearch ? "Remove" : "Delete"), getResourceString("CANCEL") }; int rv = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(), UIRegistry.getLocalizedMessage(addSearch ? "ASK_REMOVE" : "ASK_DELETE", dObj.getIdentityTitle()), getResourceString(addSearch ? "Remove" : "Delete"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, delBtnLabels, delBtnLabels[1]); if (rv == JOptionPane.YES_OPTION) { boolean doOtherSide = true; DBTableInfo parentTblInfo = DBTableIdMgr.getInstance() .getByShortClassName(parentDataObj.getClass().getSimpleName()); if (parentTblInfo != null) { DBTableChildIFace ci = parentTblInfo.getItemByName(cellName); if (ci instanceof DBRelationshipInfo) { DBRelationshipInfo ri = (DBRelationshipInfo) ci; doOtherSide = ri.getType() == DBRelationshipInfo.RelationshipType.OneToMany; log.debug(ri.getType()); } } doOtherSide = false; parentDataObj.removeReference(dObj, dataSetFieldName, doOtherSide || addSearch); if (addSearch && mvParent != null && dObj.getId() != null) { mvParent.getTopLevel().addToBeSavedItem(dObj); } // 'addSearch' is used in FormViewObj, but here maybe we need to use 'doOtherSide' if (addSearch && mvParent != null && dObj.getId() != null) { mvParent.getTopLevel().addToBeSavedItem(dObj); } dataObjList.remove(rowIndex); model.fireDataChanged(); table.invalidate(); JComponent comp = mvParent.getTopLevel(); comp.validate(); comp.repaint(); reorderItems(rowIndex); tellMultiViewOfChange(); table.getSelectionModel().clearSelection(); updateUI(false); mvParent.getTopLevel().getCurrentValidator().setHasChanged(true); mvParent.getTopLevel().getCurrentValidator().validateForm(); mvParent.getCurrentValidator().setHasChanged(true); mvParent.getMultiViewParent().getCurrentValidator().validateForm(); if (!addSearch) { // Delete a child object by caching it in the Top Level MultiView if (mvParent != null && !mvParent.isTopLevel()) { mvParent.getTopLevel().addDeletedItem(dObj); String delMsg = (businessRules != null) ? businessRules.getDeleteMsg(dObj) : ""; UIRegistry.getStatusBar().setText(delMsg); } } } } }
From source file:edu.ku.brc.af.ui.forms.TableViewObj.java
/** * Can create a new item or edit an existing it; or view and existing item. * @param rowIndex the index tho be editted * @param isEdit whether we are editing or view * @param isNew hwther the object is new *//* ww w. j av a 2s.com*/ @SuppressWarnings("unchecked") protected FormDataObjIFace editRow(final FormDataObjIFace dObjArg, final int rowIndex, final boolean isNew) { FormDataObjIFace dObj = dObjArg; // Add it in here so the Business Rules has a parent object to // get state from. if (!doSpecialAdd && parentDataObj != null && isEditing && isNew) { parentDataObj.addReference(dObj, dataSetFieldName); } /* XXX bug #9497: boolean editable = isEditing && (perm.canModify() || (perm.canAdd() && (isNew || isNewObj(dObj)))); final ViewBasedDisplayIFace dialog = FormHelper.createDataObjectDialog(mainComp, dObj, editable, isNew);*/ final ViewBasedDisplayIFace dialog = FormHelper.createDataObjectDialog(mainComp, dObj, isEditing, isNew); if (dialog != null) { // Now we need to get the MultiView and add it into the MV tree MultiView multiView = dialog.getMultiView(); // Note: The 'real' parent is the parent of the current MultiView // this is because the table's MultiView doesn't have a validator. MultiView realParent = mvParent.getMultiViewParent(); if (realParent != null) { realParent.addChildMV(multiView); } multiView.addCurrentValidator(); if (isNew && multiView.getCurrentViewAsFormViewObj() != null) { multiView.getCurrentViewAsFormViewObj().getBusinessRules().addChildrenToNewDataObjects(dObj); } dialog.setParentData(parentDataObj); DataProviderSessionIFace localSession = null; try { if (!isSkippingAttach) { if (dObj.getId() != null) { localSession = DataProviderFactory.getInstance().createSession(); //dObj = localSession.merge(dObj); localSession.attach(dObj); try { localSession.attach(dObj); } catch (org.hibernate.HibernateException ex) { String msg = ex.getMessage(); if (StringUtils.isNotEmpty(msg) && StringUtils.contains(msg, "dirty collection")) { //dObj = localSession.merge(dObj); } } } dialog.setSession(localSession); } if (isNew) { FormViewObj fvo = dialog.getMultiView().getCurrentViewAsFormViewObj(); if (fvo != null) { fvo.setCreatingNewObject(true); if (fvo.getBusinessRules() != null) { fvo.getBusinessRules().afterCreateNewObj(dObj); } } } dialog.setData(dObj); if (localSession != null) { localSession.close(); localSession = null; } dialog.setSession(null); dialog.createUI(); if (addSearch && includeAddBtn && isEditing && isNew) { dialog.setDoSave(true); dialog.getOkBtn().setText(UIRegistry.getResourceString("SAVE")); } dialog.showDisplay(true); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TableViewObj.class, ex); } finally { if (localSession != null) { localSession.close(); } } // OK, now unhook everything (MVs and the validators) multiView.removeCurrentValidator(); if (realParent != null) { realParent.removeChildMV(multiView); } if (isEditing) { if (dialog.getBtnPressed() == ViewBasedDisplayIFace.OK_BTN) { dialog.getMultiView().getDataFromUI(); if (mvParent != null) { tellMultiViewOfChange(); Object daObj = dialog.getMultiView().getCurrentViewAsFormViewObj() != null ? dialog.getMultiView().getCurrentViewAsFormViewObj().getCurrentDataObj() : null; if (daObj == null) { daObj = dialog.getMultiView().getData(); } dObj = daObj instanceof FormDataObjIFace ? (FormDataObjIFace) daObj : dObj; if (isNew) { if (daObj instanceof Orderable) { // They really should all be Orderable, // but just in case we check each one. int maxOrder = -1; for (Object obj : dataObjList) { if (obj instanceof Orderable) { maxOrder = Math.max(((Orderable) obj).getOrderIndex(), maxOrder); } } ((Orderable) daObj).setOrderIndex(maxOrder + 1); if (orderUpBtn == null) { addOrderablePanel(); } } dataObjList.add(daObj); if (dataObjList != null && dataObjList.size() > 0) { if (dataObjList.get(0) instanceof Comparable<?>) { Collections.sort((List) dataObjList); } } if (origDataSet != null) { origDataSet.add(daObj); } model.setValueAt(daObj, 0, dataObjList.size() - 1); } model.fireDataChanged(); table.invalidate(); table.repaint(); JComponent comp = mvParent.getTopLevel(); comp.validate(); comp.repaint(); } if (doSpecialAdd && parentDataObj != null && isEditing && isNew) { parentDataObj.addReference(dObj, dataSetFieldName); } } else if (dialog.isCancelled()) { // since it was added in before the dlg was shown we now need to remove. if (parentDataObj != null && isEditing && isNew) { parentDataObj.removeReference(dObj, dataSetFieldName); } if (mvParent.getMultiViewParent() != null) { if (mvParent.getMultiViewParent().getCurrentValidator() != null) { // rods 04/28/11 - it shouldn't turn on the save btn on Cancel //mvParent.getCurrentValidator().setHasChanged(true); mvParent.getMultiViewParent().getCurrentValidator().validateForm(); } multiView.getCurrentViewAsFormViewObj().doWasCacelled(); } } } dialog.dispose(); } else if (parentDataObj != null) { parentDataObj.removeReference(dObj, dataSetFieldName); } return dObj; }
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * _more_//from w ww.j ava 2 s .c om * * @param c _more_ */ public void doRepaint(JComponent c) { boolean callRepaint = false; synchronized (REPAINT_MUTEX) { repaintCnt--; if (repaintCnt == 0) { callRepaint = true; } } if (callRepaint) { c.repaint(); } }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected void closeWindow(Window window, WindowOpenInfo openInfo) { if (!disableSavingScreenHistory) { screenHistorySupport.saveScreenHistory(window, openInfo.getOpenMode()); }//from w w w. j a v a 2 s .c o m switch (openInfo.getOpenMode()) { case DIALOG: { JDialog dialog = (JDialog) openInfo.getData(); dialog.setVisible(false); dialog.dispose(); cleanupAfterModalDialogClosed(window); fireListeners(window, tabs.size() != 0); break; } case NEW_TAB: case NEW_WINDOW: { JComponent layout = (JComponent) openInfo.getData(); layout.remove(DesktopComponentsHelper.getComposition(window)); if (isMainWindowManager) { tabsPane.remove(layout); } WindowBreadCrumbs windowBreadCrumbs = tabs.get(layout); if (windowBreadCrumbs != null) { windowBreadCrumbs.clearListeners(); windowBreadCrumbs.removeWindow(); } tabs.remove(layout); stacks.remove(windowBreadCrumbs); fireListeners(window, tabs.size() != 0); if (!isMainWindowManager) { closeFrame(getFrame()); } break; } case THIS_TAB: { JComponent layout = (JComponent) openInfo.getData(); final WindowBreadCrumbs breadCrumbs = tabs.get(layout); if (breadCrumbs == null) throw new IllegalStateException("Unable to close screen: breadCrumbs not found"); breadCrumbs.removeWindow(); Window currentWindow = breadCrumbs.getCurrentWindow(); if (!stacks.get(breadCrumbs).empty()) { Map.Entry<Window, Integer> entry = stacks.get(breadCrumbs).pop(); putToWindowMap(entry.getKey(), entry.getValue()); } JComponent component = DesktopComponentsHelper.getComposition(currentWindow); Window currentWindowFrame = (Window) currentWindow.getFrame(); final java.awt.Component focusedCmp = windowOpenMode.get(currentWindowFrame).getFocusOwner(); if (focusedCmp != null) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { focusedCmp.requestFocus(); } }); } layout.remove(DesktopComponentsHelper.getComposition(window)); if (App.getInstance().getConnection().isConnected()) { layout.add(component); if (isMainWindowManager) { // If user clicked on close button maybe selectedIndex != tabsPane.getSelectedIndex() // Refs #1117 int selectedIndex = 0; while ((selectedIndex < tabs.size()) && (tabsPane.getComponentAt(selectedIndex) != layout)) { selectedIndex++; } if (selectedIndex == tabs.size()) { selectedIndex = tabsPane.getSelectedIndex(); } setActiveWindowCaption(currentWindow.getCaption(), currentWindow.getDescription(), selectedIndex); } else { setTopLevelWindowCaption(currentWindow.getCaption()); component.revalidate(); component.repaint(); } } fireListeners(window, tabs.size() != 0); break; } default: throw new UnsupportedOperationException(); } }