List of usage examples for java.awt Cursor HAND_CURSOR
int HAND_CURSOR
To view the source code for java.awt Cursor HAND_CURSOR.
Click Source Link
From source file:org.colombbus.tangara.EditorFrame.java
/** * This method initializes msgButtons//from w w w.j a v a 2s . c om * * @return javax.swing.JPanel */ private JPanel getMsgButtons() { if (msgButtons == null) { toProgramLabel = new JLabel(); toProgramLabel.setText(Messages.getString("EditorFrame.button.copyInProgramMode")); //$NON-NLS-1$ toProgramLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 13)); //$NON-NLS-1$ toProgramLabel.setForeground(new Color(60, 87, 174)); toProgramLabel .setIcon(new ImageIcon(getClass().getResource("/org/colombbus/tangara/to_program_off.png"))); //$NON-NLS-1$ toProgramLabel.setEnabled(false); toProgramLabel.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mousePressed(java.awt.event.MouseEvent e) { console.insertCodeToProgram(); } @Override public void mouseExited(java.awt.event.MouseEvent e) { if (!noCodeSelected) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); toProgramLabel.setForeground(new Color(60, 87, 174)); } } @Override public void mouseEntered(java.awt.event.MouseEvent e) { if (!noCodeSelected) { setCursor(new Cursor(Cursor.HAND_CURSOR)); toProgramLabel.setForeground(new Color(100, 100, 255)); } } }); selectAllLabel = new JLabel(); selectAllLabel.setText(Messages.getString("EditorFrame.button.selectAll")); //$NON-NLS-1$ selectAllLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 13)); //$NON-NLS-1$ selectAllLabel.setForeground(new Color(60, 87, 174)); selectAllLabel.setIcon(new ImageIcon(getClass().getResource("/org/colombbus/tangara/select_all.png"))); //$NON-NLS-1$ selectAllLabel.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mousePressed(java.awt.event.MouseEvent e) { console.selectAll(); } @Override public void mouseExited(java.awt.event.MouseEvent e) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); selectAllLabel.setForeground(new Color(60, 87, 174)); } @Override public void mouseEntered(java.awt.event.MouseEvent e) { setCursor(new Cursor(Cursor.HAND_CURSOR)); selectAllLabel.setForeground(new Color(100, 100, 255)); } }); deselectAllLabel = new JLabel(); deselectAllLabel.setText(Messages.getString("EditorFrame.button.deselectAll")); //$NON-NLS-1$ deselectAllLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 13)); //$NON-NLS-1$ deselectAllLabel.setForeground(new Color(60, 87, 174)); deselectAllLabel .setIcon(new ImageIcon(getClass().getResource("/org/colombbus/tangara/select_none.png"))); //$NON-NLS-1$ deselectAllLabel.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mousePressed(java.awt.event.MouseEvent e) { console.clearSelection(); } @Override public void mouseExited(java.awt.event.MouseEvent e) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); deselectAllLabel.setForeground(new Color(60, 87, 174)); } @Override public void mouseEntered(java.awt.event.MouseEvent e) { setCursor(new Cursor(Cursor.HAND_CURSOR)); deselectAllLabel.setForeground(new Color(100, 100, 255)); } }); JLabel separatorLabel1 = new JLabel(" "); //$NON-NLS-1$ JLabel separatorLabel2 = new JLabel(" "); //$NON-NLS-1$ msgButtons = new JPanel(); msgButtons.setLayout(new FlowLayout()); msgButtons.setBackground(new Color(240, 240, 240)); msgButtons.add(toProgramLabel); msgButtons.add(separatorLabel1); msgButtons.add(selectAllLabel); msgButtons.add(separatorLabel2); msgButtons.add(deselectAllLabel); } return msgButtons; }
From source file:org.datacleaner.windows.AnalysisJobBuilderWindowImpl.java
private void applyMenuPopupButttonStyling(PopupButton popupButton) { popupButton.setBorder(new EmptyBorder(10, 4, 10, 4)); popupButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); popupButton.setFocusPainted(false);/*from ww w. j a v a2s . com*/ WidgetUtils.setDarkButtonStyle(popupButton); popupButton.setHorizontalTextPosition(SwingConstants.LEFT); }
From source file:org.datacleaner.windows.AnalysisJobBuilderWindowImpl.java
private JToggleButton createViewToggleButton(final String text, final String iconPath) { final ImageIcon icon = imageManager.getImageIcon(iconPath); final JToggleButton button = new JToggleButton(text, icon); button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); button.setFont(WidgetUtils.FONT_SMALL); button.setForeground(WidgetUtils.BG_COLOR_BRIGHTEST); button.setBackground(WidgetUtils.BG_COLOR_DARK); button.setBorderPainted(false);/*from w ww .ja v a 2 s . c o m*/ button.setBorder(new CompoundBorder(WidgetUtils.BORDER_THIN, new EmptyBorder(0, 4, 0, 4))); return button; }
From source file:corelyzer.ui.CorelyzerGLCanvas.java
/** * Handles mouse dragging events: panning, sliding sections, sliding tracks, * and trackpad based zooming.//from w w w . j av a 2 s.c o m */ public void mouseDragged(final MouseEvent e) { Point currentPos = e.getPoint(); int dX = currentPos.x - prePos.x; int dY = currentPos.y - prePos.y; float sx, sy; float w, h; canvasLock.lock(); w = SceneGraph.getCanvasWidth(canvasId); h = SceneGraph.getCanvasHeight(canvasId); sx = w / canvas.getWidth(); sy = h / canvas.getHeight(); this.convertMousePointToSceneSpace(currentPos, scenePos); // play a bit measuring test if (canvasMode == CorelyzerApp.APP_MEASURE_MODE) { SceneGraph.positionMouse(scenePos[0], scenePos[1]); // some work for panning // automatically pan mode canvas.setCursor(new Cursor(Cursor.MOVE_CURSOR)); SceneGraph.panScene(-dX * sx, -dY * sy); canvasLock.unlock(); prePos = currentPos; CorelyzerApp.getApp().updateGLWindows(); return; } else if (canvasMode == CorelyzerApp.APP_CLAST_MODE || canvasMode == CorelyzerApp.APP_CUT_MODE) { SceneGraph.positionMouse(scenePos[0], scenePos[1]); // Don't have a selected section, just pan if (selectedTrackSection == -1) { canvas.setCursor(new Cursor(Cursor.MOVE_CURSOR)); SceneGraph.panScene(-dX * sx, -dY * sy); } canvasLock.unlock(); prePos = currentPos; CorelyzerApp.getApp().updateGLWindows(); return; } // check focused marker manipulation if (MANIPULATE_MODE == 1) { float dx, dy; dx = scenePos[0] - prescenePos[0]; dy = scenePos[1] - prescenePos[1]; prescenePos[0] = scenePos[0]; prescenePos[1] = scenePos[1]; SceneGraph.manipulateMarker(canvasId, dx, dy); SceneGraph.positionMouse(scenePos[0], scenePos[1]); canvasLock.unlock(); prePos = currentPos; CorelyzerApp.getApp().updateGLWindows(); return; } else { if (e.isAltDown()) // slide track section { // TODO consider separate move of section image and graph // moveSectionImage & moveSectionGraph if (selectedTrack >= 0 && selectedTrackSection >= 0) { if (canvas.getCursor().getType() != Cursor.HAND_CURSOR) { canvas.setCursor(new Cursor(Cursor.HAND_CURSOR)); } // depth orientation float tX = SceneGraph.getDepthOrientation() ? dX * sx : dY * sy; // allow vertical movements? float tY = 0; // float tY = SceneGraph.getDepthOrientation() ? // (dY * sy) : (-dX * sx); if (selectedGraph >= 0) { // moving graph instead of whole section SceneGraph.moveSectionGraph(selectedTrack, selectedTrackSection, tX, tY); } else { Object[] sections = CorelyzerApp.getApp().getSectionList().getSelectedValues(); int[] secids = new int[sections.length]; for (int i = 0; i < sections.length; i++) { CoreSection cs = (CoreSection) sections[i]; secids[i] = (cs != null ? cs.getId() : -1); } SceneGraph.moveSections(selectedTrack, secids, tX, tY); } // broadcast event to plugins String msg = ""; msg = msg + selectedTrack + "\t" + selectedTrackSection; msg = msg + "\t" + dX * sx / SceneGraph.getCanvasDPIX(canvasId) + "\t0"; CorelyzerApp.getApp().getPluginManager() .broadcastEventToPlugins(CorelyzerPluginEvent.SECTION_MOVED, msg); } } else if (e.isShiftDown()) { // slide track if (selectedTrack >= 0) { if (canvas.getCursor().getType() != Cursor.HAND_CURSOR) { canvas.setCursor(new Cursor(Cursor.HAND_CURSOR)); } // fine tune allows depth movements if (isFineTune() && finetuneDialog != null) { // depth orientation if (SceneGraph.getDepthOrientation()) { // landscape SceneGraph.moveTrack(selectedTrack, dX * sx, dY * sy); } else { // Portrait SceneGraph.moveTrack(selectedTrack, dY * sy, -dX * sx); } float currentTrackPosX = SceneGraph.getTrackXPos(selectedTrack); float canvasDPIX = SceneGraph.getCanvasDPIX(0); JTextField fineTuneCoreADepthStatus = finetuneDialog.getCoreAAdjustedDepthTextField(); JTextField fineTuneCoreBDepthStatus = finetuneDialog.getCoreBAdjustedDepthTextField(); int coreANativeID = finetuneDialog.getCoreANativeID(); int coreBNativeID = finetuneDialog.getCoreBNativeID(); float coreAOrigDepth = finetuneDialog.getCoreAOrigDepth(); float coreBOrigDepth = finetuneDialog.getCoreBOrigDepth(); if (fineTuneCoreADepthStatus != null && coreANativeID == selectedTrack) { float depth = coreAOrigDepth + 2.54f * currentTrackPosX / (100 * canvasDPIX); fineTuneCoreADepthStatus.setText(String.valueOf(depth)); } if (fineTuneCoreBDepthStatus != null && coreBNativeID == selectedTrack) { float depth = coreBOrigDepth + 2.54f * currentTrackPosX / (100 * canvasDPIX); fineTuneCoreBDepthStatus.setText(String.valueOf(depth)); } } else { // normal // depth orientation if (SceneGraph.getDepthOrientation()) { SceneGraph.moveTrack(selectedTrack, 0.0f, dY * sy); } else { SceneGraph.moveTrack(selectedTrack, 0.0f, -dX * sx); } } // broadcast message to plugins String msg = ""; msg = msg + selectedTrack; msg = msg + "\t0\t" + dY * sx / SceneGraph.getCanvasDPIY(canvasId); CorelyzerApp.getApp().getPluginManager() .broadcastEventToPlugins(CorelyzerPluginEvent.TRACK_MOVED, msg); } } else if (e.isControlDown()) // zooming { sy = (float) dY / (float) canvas.getHeight(); SceneGraph.scaleScene(1.0f + sy); } else if (PAN_MODE == 1) { // automatically pan mode canvas.setCursor(new Cursor(Cursor.MOVE_CURSOR)); SceneGraph.panScene(-dX * sx, -dY * sy); } } // end of else (manipulation mode) SceneGraph.positionMouse(scenePos[0], scenePos[1]); canvasLock.unlock(); prePos = currentPos; CorelyzerApp.getApp().updateGLWindows(); }
From source file:com.openbravo.pos.util.JRViewer411.java
protected void createHyperlinks(List<JRPrintElement> elements, int offsetX, int offsetY) { if (elements != null && elements.size() > 0) { for (Iterator<JRPrintElement> it = elements.iterator(); it.hasNext();) { JRPrintElement element = it.next(); JRImageMapRenderer imageMap = null; if (element instanceof JRPrintImage) { JRRenderable renderer = ((JRPrintImage) element).getRenderer(); if (renderer instanceof JRImageMapRenderer) { imageMap = (JRImageMapRenderer) renderer; if (!imageMap.hasImageAreaHyperlinks()) { imageMap = null; }//from w w w . j a va 2 s . c om } } boolean hasImageMap = imageMap != null; JRPrintHyperlink hyperlink = null; if (element instanceof JRPrintHyperlink) { hyperlink = (JRPrintHyperlink) element; } boolean hasHyperlink = !hasImageMap && hyperlink != null && hyperlink.getHyperlinkTypeValue() != HyperlinkTypeEnum.NONE; boolean hasTooltip = hyperlink != null && hyperlink.getHyperlinkTooltip() != null; if (hasHyperlink || hasImageMap || hasTooltip) { JPanel link; if (hasImageMap) { Rectangle renderingArea = new Rectangle(0, 0, element.getWidth(), element.getHeight()); link = new ImageMapPanel(renderingArea, imageMap); } else //hasImageMap { link = new JPanel(); if (hasHyperlink) { link.addMouseListener(mouseListener); } } if (hasHyperlink) { link.setCursor(new Cursor(Cursor.HAND_CURSOR)); } link.setLocation((int) ((element.getX() + offsetX) * realZoom), (int) ((element.getY() + offsetY) * realZoom)); link.setSize((int) (element.getWidth() * realZoom), (int) (element.getHeight() * realZoom)); link.setOpaque(false); String toolTip = getHyperlinkTooltip(hyperlink); if (toolTip == null && hasImageMap) { toolTip = "";//not null to register the panel as having a tool tip } link.setToolTipText(toolTip); pnlLinks.add(link); linksMap.put(link, hyperlink); } if (element instanceof JRPrintFrame) { JRPrintFrame frame = (JRPrintFrame) element; int frameOffsetX = offsetX + frame.getX() + frame.getLineBox().getLeftPadding().intValue(); int frameOffsetY = offsetY + frame.getY() + frame.getLineBox().getTopPadding().intValue(); createHyperlinks(frame.getElements(), frameOffsetX, frameOffsetY); } } } }
From source file:neg.JRViewer.java
protected void createHyperlinks(List elements, int offsetX, int offsetY) { if (elements != null && elements.size() > 0) { for (Iterator it = elements.iterator(); it.hasNext();) { JRPrintElement element = (JRPrintElement) it.next(); JRImageMapRenderer imageMap = null; if (element instanceof JRPrintImage) { JRRenderable renderer = ((JRPrintImage) element).getRenderer(); if (renderer instanceof JRImageMapRenderer) { imageMap = (JRImageMapRenderer) renderer; if (!imageMap.hasImageAreaHyperlinks()) { imageMap = null; }/*www. jav a2s . c o m*/ } } boolean hasImageMap = imageMap != null; JRPrintHyperlink hyperlink = null; if (element instanceof JRPrintHyperlink) { hyperlink = (JRPrintHyperlink) element; } boolean hasHyperlink = !hasImageMap && hyperlink != null && hyperlink.getHyperlinkType() != JRHyperlink.HYPERLINK_TYPE_NONE; boolean hasTooltip = hyperlink != null && hyperlink.getHyperlinkTooltip() != null; if (hasHyperlink || hasImageMap || hasTooltip) { JPanel link; if (hasImageMap) { Rectangle renderingArea = new Rectangle(0, 0, element.getWidth(), element.getHeight()); link = new ImageMapPanel(renderingArea, imageMap); } else //hasImageMap { link = new JPanel(); if (hasHyperlink) { link.addMouseListener(mouseListener); } } if (hasHyperlink) { link.setCursor(new Cursor(Cursor.HAND_CURSOR)); } link.setLocation((int) ((element.getX() + offsetX) * realZoom), (int) ((element.getY() + offsetY) * realZoom)); link.setSize((int) (element.getWidth() * realZoom), (int) (element.getHeight() * realZoom)); link.setOpaque(false); String toolTip = getHyperlinkTooltip(hyperlink); if (toolTip == null && hasImageMap) { toolTip = "";//not null to register the panel as having a tool tip } link.setToolTipText(toolTip); pnlLinks.add(link); linksMap.put(link, element); } if (element instanceof JRPrintFrame) { JRPrintFrame frame = (JRPrintFrame) element; int frameOffsetX = offsetX + frame.getX() + frame.getLineBox().getLeftPadding().intValue(); int frameOffsetY = offsetY + frame.getY() + frame.getLineBox().getTopPadding().intValue(); createHyperlinks(frame.getElements(), frameOffsetX, frameOffsetY); } } } }
From source file:ExText.java
/** * Responds to a button1 event (press, release, or drag). On a press, the * method adds a wakeup criterion to the behavior's set, callling for the * behavior to be awoken on each frame. On a button prelease, this criterion * is removed from the set./* w ww . j a v a 2 s.c om*/ * * @param mouseEvent * the MouseEvent to respond to */ public void onButton1(MouseEvent mev) { if (subjectTransformGroup == null) return; int x = mev.getX(); int y = mev.getY(); if (mev.getID() == MouseEvent.MOUSE_PRESSED) { // Mouse button pressed: record position and change // the wakeup criterion to include elapsed time wakeups // so we can animate. previousX = x; previousY = y; initialX = x; initialY = y; // Swap criterion... parent class will not reschedule us mouseCriterion = mouseAndAnimationCriterion; // Change to a "move" cursor if (parentComponent != null) { savedCursor = parentComponent.getCursor(); parentComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } return; } if (mev.getID() == MouseEvent.MOUSE_RELEASED) { // Mouse button released: restore original wakeup // criterion which only includes mouse activity, not // elapsed time mouseCriterion = savedMouseCriterion; // Switch the cursor back if (parentComponent != null) parentComponent.setCursor(savedCursor); return; } previousX = x; previousY = y; }
From source file:cn.pholance.datamanager.common.components.JRViewer.java
protected void createHyperlinks(List<JRPrintElement> elements, int offsetX, int offsetY) { if (elements != null && elements.size() > 0) { for (Iterator<JRPrintElement> it = elements.iterator(); it.hasNext();) { JRPrintElement element = it.next(); ImageMapRenderable imageMap = null; if (element instanceof JRPrintImage) { Renderable renderer = ((JRPrintImage) element).getRenderable(); if (renderer instanceof ImageMapRenderable) { imageMap = (ImageMapRenderable) renderer; if (!imageMap.hasImageAreaHyperlinks()) { imageMap = null; }/*from w w w .j a va 2 s . c o m*/ } } boolean hasImageMap = imageMap != null; JRPrintHyperlink hyperlink = null; if (element instanceof JRPrintHyperlink) { hyperlink = (JRPrintHyperlink) element; } boolean hasHyperlink = !hasImageMap && hyperlink != null && hyperlink.getHyperlinkTypeValue() != HyperlinkTypeEnum.NONE; boolean hasTooltip = hyperlink != null && hyperlink.getHyperlinkTooltip() != null; if (hasHyperlink || hasImageMap || hasTooltip) { JPanel link; if (hasImageMap) { Rectangle renderingArea = new Rectangle(0, 0, element.getWidth(), element.getHeight()); link = new ImageMapPanel(renderingArea, imageMap); } else //hasImageMap { link = new JPanel(); if (hasHyperlink) { link.addMouseListener(mouseListener); } } if (hasHyperlink) { link.setCursor(new Cursor(Cursor.HAND_CURSOR)); } link.setLocation((int) ((element.getX() + offsetX) * realZoom), (int) ((element.getY() + offsetY) * realZoom)); link.setSize((int) (element.getWidth() * realZoom), (int) (element.getHeight() * realZoom)); link.setOpaque(false); String toolTip = getHyperlinkTooltip(hyperlink); if (toolTip == null && hasImageMap) { toolTip = "";//not null to register the panel as having a tool tip } link.setToolTipText(toolTip); pnlLinks.add(link); linksMap.put(link, hyperlink); } if (element instanceof JRPrintFrame) { JRPrintFrame frame = (JRPrintFrame) element; int frameOffsetX = offsetX + frame.getX() + frame.getLineBox().getLeftPadding().intValue(); int frameOffsetY = offsetY + frame.getY() + frame.getLineBox().getTopPadding().intValue(); createHyperlinks(frame.getElements(), frameOffsetX, frameOffsetY); } } } }
From source file:simMPLS.ui.simulator.JVentanaHija.java
/** * Este mtodo se llama cuando se presiona un botn del ratn en el panel de * simulacin. Si se hace sobre un elemento de la topologa, lo marca como * seleccionado./*from w ww .ja v a2s. com*/ * When the mouse button is pressed on a node * @since 1.0 * @param evt El evento que provoca la llamada. */ private void clicEnPanelSimulacion(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clicEnPanelSimulacion if (evt.getButton() == MouseEvent.BUTTON1) { TTopology topo = escenario.getTopology(); TTopologyElement et = topo.obtenerElementoEnPosicion(evt.getPoint()); if (et != null) { this.setCursor(new Cursor(Cursor.HAND_CURSOR)); if (et.getElementType() == TTopologyElement.NODO) { TNode nt = (TNode) et; nodoSeleccionado = nt; if (nodoSeleccionado != null) { nodoSeleccionado.setStatus(TNode.SELECCIONADO); this.escenario.setModified(true); } } } else { this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); this.setToolTipText(null); } panelSimulacion.repaint(); } }
From source file:op.care.med.inventory.PnlInventory.java
private JPanel createContentPanel4(final MedStock stock) { // final String key = stock.getID() + ".xstock"; // if (!contentmap.containsKey(key)) { final JPanel pnlTX = new JPanel(new VerticalLayout()); // pnlTX.setLayout(new BoxLayout(pnlTX, BoxLayout.PAGE_AXIS)); pnlTX.setOpaque(true);//from w ww . j a v a 2 s. c o m // pnlTX.setBackground(Color.white); synchronized (lstInventories) { pnlTX.setBackground(getColor(SYSConst.light2, lstInventories.indexOf(stock.getInventory()) % 2 != 0)); } /*** * _ _ _ _______ __ * / \ __| | __| |_ _\ \/ / * / _ \ / _` |/ _` | | | \ / * / ___ \ (_| | (_| | | | / \ * /_/ \_\__,_|\__,_| |_| /_/\_\ * */ JideButton btnAddTX = GUITools.createHyperlinkButton("nursingrecords.inventory.newmedstocktx", SYSConst.icon22add, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new DlgTX(new MedStockTransaction(stock, BigDecimal.ONE, MedStockTransactionTools.STATE_EDIT_MANUAL), new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); final MedStockTransaction myTX = (MedStockTransaction) em.merge(o); MedStock myStock = em.merge(stock); em.lock(myStock, LockModeType.OPTIMISTIC); em.lock(myStock.getInventory(), LockModeType.OPTIMISTIC); em.lock(em.merge(myTX.getStock().getInventory().getResident()), LockModeType.OPTIMISTIC); em.getTransaction().commit(); createCP4(myStock.getInventory()); buildPanel(); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager() .addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } } }); } }); btnAddTX.setEnabled(!stock.isClosed()); pnlTX.add(btnAddTX); /*** * ____ _ _ _ _______ __ * / ___|| |__ _____ __ __ _| | | |_ _\ \/ /___ * \___ \| '_ \ / _ \ \ /\ / / / _` | | | | | \ // __| * ___) | | | | (_) \ V V / | (_| | | | | | / \\__ \ * |____/|_| |_|\___/ \_/\_/ \__,_|_|_| |_| /_/\_\___/ * */ OPDE.getMainframe().setBlocked(true); OPDE.getDisplayManager().setProgressBarMessage(new DisplayMessage(SYSTools.xx("misc.msg.wait"), -1, 100)); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { int progress = 0; List<MedStockTransaction> listTX = MedStockTransactionTools.getAll(stock); OPDE.getDisplayManager().setProgressBarMessage( new DisplayMessage(SYSTools.xx("misc.msg.wait"), progress, listTX.size())); BigDecimal rowsum = MedStockTools.getSum(stock); // BigDecimal rowsum = MedStockTools.getSum(stock); // Collections.sort(stock.getStockTransaction()); for (final MedStockTransaction tx : listTX) { progress++; OPDE.getDisplayManager().setProgressBarMessage( new DisplayMessage(SYSTools.xx("misc.msg.wait"), progress, listTX.size())); String title = "<html><table border=\"0\">" + "<tr>" + "<td width=\"130\" align=\"left\">" + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT) .format(tx.getPit()) + "<br/>[" + tx.getID() + "]" + "</td>" + "<td width=\"200\" align=\"center\">" + SYSTools.catchNull(tx.getText(), "--") + "</td>" + "<td width=\"100\" align=\"right\">" + NumberFormat.getNumberInstance().format(tx.getAmount()) + "</td>" + "<td width=\"100\" align=\"right\">" + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "") + NumberFormat.getNumberInstance().format(rowsum) + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + (stock.getTradeForm().isWeightControlled() ? "<td width=\"100\" align=\"right\">" + NumberFormat.getNumberInstance().format(tx.getWeight()) + "g" + "</td>" : "") + "<td width=\"100\" align=\"left\">" + SYSTools.anonymizeUser(tx.getUser().getUID()) + "</td>" + "</tr>" + "</table>" + "</font></html>"; rowsum = rowsum.subtract(tx.getAmount()); final DefaultCPTitle pnlTitle = new DefaultCPTitle(title, null); // pnlTitle.getLeft().addMouseListener(); if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, "nursingrecords.inventory")) { /*** * ____ _ _______ __ * | _ \ ___| |_ _\ \/ / * | | | |/ _ \ | | | \ / * | |_| | __/ | | | / \ * |____/ \___|_| |_| /_/\_\ * */ final JButton btnDelTX = new JButton(SYSConst.icon22delete); btnDelTX.setPressedIcon(SYSConst.icon22deletePressed); btnDelTX.setAlignmentX(Component.RIGHT_ALIGNMENT); btnDelTX.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnDelTX.setContentAreaFilled(false); btnDelTX.setBorder(null); btnDelTX.setToolTipText(SYSTools.xx("nursingrecords.inventory.tx.btndelete.tooltip")); btnDelTX.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo(SYSTools.xx("misc.questions.delete1") + "<br/><i>" + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT) .format(tx.getPit()) + " " + tx.getUser().getUID() + "</i><br/>" + SYSTools.xx("misc.questions.delete2"), SYSConst.icon48delete, new Closure() { @Override public void execute(Object answer) { if (answer.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedStockTransaction myTX = em.merge(tx); MedStock myStock = em.merge(stock); em.lock(em.merge( myTX.getStock().getInventory().getResident()), LockModeType.OPTIMISTIC); em.lock(myStock, LockModeType.OPTIMISTIC); em.lock(myStock.getInventory(), LockModeType.OPTIMISTIC); em.remove(myTX); // myStock.getStockTransaction().remove(myTX); em.getTransaction().commit(); // synchronized (lstInventories) { // int indexInventory = lstInventories.indexOf(stock.getInventory()); // int indexStock = lstInventories.get(indexInventory).getMedStocks().indexOf(stock); // lstInventories.get(indexInventory).getMedStocks().remove(stock); // lstInventories.get(indexInventory).getMedStocks().add(indexStock, myStock); // } // synchronized (linemap) { // linemap.remove(myTX); // } createCP4(myStock.getInventory()); buildPanel(); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage() .indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager() .addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } } }); } }); btnDelTX.setEnabled( !stock.isClosed() && (tx.getState() == MedStockTransactionTools.STATE_DEBIT || tx.getState() == MedStockTransactionTools.STATE_EDIT_MANUAL)); pnlTitle.getRight().add(btnDelTX); } /*** * _ _ _ _______ __ * | | | |_ __ __| | ___ |_ _\ \/ / * | | | | '_ \ / _` |/ _ \ | | \ / * | |_| | | | | (_| | (_) | | | / \ * \___/|_| |_|\__,_|\___/ |_| /_/\_\ * */ final JButton btnUndoTX = new JButton(SYSConst.icon22undo); btnUndoTX.setPressedIcon(SYSConst.icon22Pressed); btnUndoTX.setAlignmentX(Component.RIGHT_ALIGNMENT); btnUndoTX.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnUndoTX.setContentAreaFilled(false); btnUndoTX.setBorder(null); btnUndoTX.setToolTipText(SYSTools.xx("nursingrecords.inventory.tx.btnUndoTX.tooltip")); btnUndoTX.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo( SYSTools.xx("misc.questions.undo1") + "<br/><i>" + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT) .format(tx.getPit()) + " " + tx.getUser().getUID() + "</i><br/>" + SYSTools.xx("misc.questions.undo2"), SYSConst.icon48undo, new Closure() { @Override public void execute(Object answer) { if (answer.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedStock myStock = em.merge(stock); final MedStockTransaction myOldTX = em.merge(tx); myOldTX.setState(MedStockTransactionTools.STATE_CANCELLED); final MedStockTransaction myNewTX = em .merge(new MedStockTransaction(myStock, myOldTX.getAmount().negate(), MedStockTransactionTools.STATE_CANCEL_REC)); myOldTX.setText(SYSTools.xx("misc.msg.reversedBy") + ": " + DateFormat .getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT) .format(myNewTX.getPit())); myNewTX.setText(SYSTools.xx("misc.msg.reversalFor") + ": " + DateFormat .getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT) .format(myOldTX.getPit())); // myStock.getStockTransaction().add(myNewTX); // myStock.getStockTransaction().remove(tx); // myStock.getStockTransaction().add(myOldTX); em.lock(em .merge(myNewTX.getStock().getInventory().getResident()), LockModeType.OPTIMISTIC); em.lock(myStock, LockModeType.OPTIMISTIC); em.lock(myStock.getInventory(), LockModeType.OPTIMISTIC); em.getTransaction().commit(); // synchronized (lstInventories) { // int indexInventory = lstInventories.indexOf(stock.getInventory()); // int indexStock = lstInventories.get(indexInventory).getMedStocks().indexOf(stock); // lstInventories.get(indexInventory).getMedStocks().remove(stock); // lstInventories.get(indexInventory).getMedStocks().add(indexStock, myStock); // } // synchronized (linemap) { // linemap.remove(tx); // } createCP4(myStock.getInventory()); buildPanel(); // SwingUtilities.invokeLater(new Runnable() { // @Override // public void run() { // synchronized (linemap) { // GUITools.flashBackground(linemap.get(myOldTX), Color.RED, 2); // GUITools.flashBackground(linemap.get(myNewTX), Color.YELLOW, 2); // } // } // }); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage() .indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager() .addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } } }); } }); btnUndoTX.setEnabled(!stock.isClosed() && (tx.getState() == MedStockTransactionTools.STATE_DEBIT || tx.getState() == MedStockTransactionTools.STATE_EDIT_MANUAL)); pnlTitle.getRight().add(btnUndoTX); if (stock.getTradeForm().isWeightControlled() && OPDE.getAppInfo() .isAllowedTo(InternalClassACL.MANAGER, "nursingrecords.inventory")) { /*** * _ __ __ _ _ _ * ___ ___| |\ \ / /__(_) __ _| |__ | |_ * / __|/ _ \ __\ \ /\ / / _ \ |/ _` | '_ \| __| * \__ \ __/ |_ \ V V / __/ | (_| | | | | |_ * |___/\___|\__| \_/\_/ \___|_|\__, |_| |_|\__| * |___/ */ final JButton btnSetWeight = new JButton(SYSConst.icon22scales); btnSetWeight.setPressedIcon(SYSConst.icon22Pressed); btnSetWeight.setAlignmentX(Component.RIGHT_ALIGNMENT); btnSetWeight.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnSetWeight.setContentAreaFilled(false); btnSetWeight.setBorder(null); btnSetWeight.setToolTipText(SYSTools.xx("nursingrecords.inventory.tx.btnUndoTX.tooltip")); btnSetWeight.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { BigDecimal weight; new DlgYesNo(SYSConst.icon48scales, new Closure() { @Override public void execute(Object o) { if (!SYSTools.catchNull(o).isEmpty()) { BigDecimal weight = (BigDecimal) o; EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedStock myStock = em.merge(stock); final MedStockTransaction myTX = em.merge(tx); em.lock(myTX, LockModeType.OPTIMISTIC); myTX.setWeight(weight); em.lock(myStock, LockModeType.OPTIMISTIC); em.lock(myStock.getInventory(), LockModeType.OPTIMISTIC); em.getTransaction().commit(); createCP4(myStock.getInventory()); buildPanel(); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager() .addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } } }, "nursingrecords.bhp.weight", NumberFormat.getNumberInstance().format(tx.getWeight()), new Validator<BigDecimal>() { @Override public boolean isValid(String value) { BigDecimal bd = parse(value); return bd != null && bd.compareTo(BigDecimal.ZERO) > 0; } @Override public BigDecimal parse(String text) { return SYSTools.parseDecimal(text); } }); } }); btnSetWeight.setEnabled( !stock.isClosed() && (tx.getState() == MedStockTransactionTools.STATE_DEBIT || tx.getState() == MedStockTransactionTools.STATE_CREDIT || tx.getState() == MedStockTransactionTools.STATE_EDIT_MANUAL)); pnlTitle.getRight().add(btnSetWeight); } pnlTX.add(pnlTitle.getMain()); } return null; } @Override protected void done() { OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); return pnlTX; }