List of usage examples for org.eclipse.swt.widgets Display getCurrent
public static Display getCurrent()
From source file:PrintKTableExample.java
public static String show(String title, String message, String buttons) { MsgBox box = new MsgBox(Display.getCurrent(), title, message, buttons); box.open();// w w w .j a v a2 s . c o m box.dispose(); return box.pressedButton; }
From source file:PrintKTableExample.java
protected void createShell(Shell parent) { guiDisplay = Display.getCurrent(); // Shell// ww w .java 2 s .c o m if (parent != null) guiShell = new Shell(parent, getShellStyle()); else guiShell = new Shell(Display.getCurrent(), getShellStyle()); createShellLayout(); createShellComposits(); }
From source file:PrintKTableExample.java
/** Returns the requested Image */ public static Image getImage(String name) { return loadImageResource(Display.getCurrent(), "/gfx/" + name + ".gif"); }
From source file:PrintKTableExample.java
/** * Creates a new KTable.// w w w. java 2 s .com * * possible styles: SWT.V_SCROLL - show vertical scrollbar and allow * vertical scrolling by arrow keys SWT.H_SCROLL - show horizontal scrollbar * and allow horizontal scrolling by arrow keys SWT.FLAT - no border * drawing. * * After creation a table model should be added using setModel(). */ public KTable(Composite parent, int style) { // Oberklasse initialisieren super(parent, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | style); // inits m_GC = new GC(this); m_Display = Display.getCurrent(); m_Selection = new HashMap(); m_CellEditor = null; flatStyleSpecified = ((style | SWT.FLAT) == style); m_RowSelectionMode = false; m_MultiSelectMode = false; m_TopRow = 0; m_LeftColumn = 0; m_FocusRow = 0; m_FocusCol = 0; m_RowsVisible = 0; m_RowsFullyVisible = 0; m_ColumnsVisible = 0; m_ColumnsFullyVisible = 0; m_ResizeColumnIndex = -1; m_ResizeRowIndex = -1; m_ResizeRowTop = -1; m_NewRowSize = -1; m_ResizeColumnLeft = -1; m_Capture = false; m_ClickColumnIndex = -1; m_ClickRowIndex = -1; m_LineRestore = null; m_LineX = 0; m_LineY = 0; cellSelectionListeners = new ArrayList(10); cellResizeListeners = new ArrayList(10); // Listener createListeners(); }
From source file:PrintKTableExample.java
protected void onMouseMove(MouseEvent e) { if (m_Model == null) return;/*from www . jav a2s .com*/ // show resize cursor? if ((m_ResizeColumnIndex != -1) || (getColumnForResize(e.x, e.y) >= 0)) setCursor(new Cursor(m_Display, SWT.CURSOR_SIZEWE)); else if ((m_ResizeRowIndex != -1) || (getRowForResize(e.x, e.y) >= 0)) setCursor(new Cursor(m_Display, SWT.CURSOR_SIZENS)); else setCursor(null); if (e.button == 1) { // extend selection? if (m_ClickColumnIndex != -1 && m_MultiSelectMode) { int row = calcRowNum(e.y); int col = calcColumnNum(e.x); if (row >= m_Model.getFixedRowCount() && col >= m_Model.getFixedColumnCount()) { m_ClickColumnIndex = col; m_ClickRowIndex = row; focusCell(col, row, (e.stateMask | SWT.SHIFT)); } } } // column resize? if (m_ResizeColumnIndex != -1) { Rectangle rect = getClientArea(); int oldSize = m_Model.getColumnWidth(m_ResizeColumnIndex); if (e.x > rect.x + rect.width - 1) e.x = rect.x + rect.width - 1; int newSize = e.x - m_ResizeColumnLeft; if (newSize < 5) newSize = 5; int leftX = getColumnLeft(m_ResizeColumnIndex); int rightX = getColumnRight(m_ResizeColumnIndex); m_Model.setColumnWidth(m_ResizeColumnIndex, newSize); newSize = m_Model.getColumnWidth(m_ResizeColumnIndex); GC gc = new GC(this); gc.copyArea(rightX, 0, rect.width - rightX, rect.height, leftX + newSize, 0); drawCol(gc, m_ResizeColumnIndex); if (newSize < oldSize) { int delta = oldSize - newSize; redraw(rect.width - delta, 0, delta, rect.height, false); } gc.dispose(); } // row resize? if (m_ResizeRowIndex != -1) { Rectangle rect = getClientArea(); GC gc = new GC(this); // calculate new size if (e.y > rect.y + rect.height - 1) e.y = rect.y + rect.height - 1; m_NewRowSize = e.y - m_ResizeRowTop; if (m_NewRowSize < m_Model.getRowHeightMinimum()) m_NewRowSize = m_Model.getRowHeightMinimum(); // restore old line area if (m_LineRestore != null) { gc.drawImage(m_LineRestore, m_LineX, m_LineY); } // safe old picture and draw line gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); int lineEnd = getColumnRight(m_LeftColumn + m_ColumnsVisible - 1); m_LineRestore = new Image(m_Display, lineEnd, 1); m_LineX = rect.x + 1; m_LineY = m_ResizeRowTop + m_NewRowSize - 1; gc.copyArea(m_LineRestore, m_LineX, m_LineY); gc.drawLine(m_LineX, m_LineY, rect.x + lineEnd, m_LineY); gc.dispose(); } }
From source file:PrintKTableExample.java
protected Control createControl() { m_Combo = new CCombo(m_Table, SWT.READ_ONLY); m_Combo.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); if (m_Items != null) m_Combo.setItems(m_Items);// w ww.j av a2 s . c o m m_Combo.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { try { onKeyPressed(e); } catch (Exception ex) { } } }); /* * m_Combo.addTraverseListener(new TraverseListener() { public void * keyTraversed(TraverseEvent arg0) { onTraverse(arg0); } }); */ return m_Combo; }
From source file:PrintKTableExample.java
public KTableCellRenderer() { m_Display = Display.getCurrent(); }
From source file:PrintKTableExample.java
/** * Standard implementation for CellRenderer. Draws a cell at the given * position. Uses the .getString() method of content to get a String * representation to draw.// w w w. j a v a2s .c om * * @param gc * The gc to draw on * @param rect * The coordinates and size of the cell (add 1 to width and hight * to include the borders) * @param col * The column * @param row * The row * @param content * The content of the cell (as given by the table model) * @param focus * True if the cell is selected * @param fixed * True if the cell is fixed (unscrollable header cell) * @param clicked * True if the cell is currently clicked (useful e.g. to paint a * pressed button) */ public void drawCell(GC gc, Rectangle rect, int col, int row, Object content, boolean focus, boolean fixed, boolean clicked) { if (fixed) { rect.height += 1; rect.width += 1; gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND)); if (clicked) { SWTX.drawButtonDown(gc, content.toString(), SWTX.ALIGN_HORIZONTAL_LEFT | SWTX.ALIGN_VERTICAL_CENTER, null, SWTX.ALIGN_HORIZONTAL_RIGHT | SWTX.ALIGN_VERTICAL_CENTER, rect); } else { SWTX.drawButtonUp(gc, content.toString(), SWTX.ALIGN_HORIZONTAL_LEFT | SWTX.ALIGN_VERTICAL_CENTER, null, SWTX.ALIGN_HORIZONTAL_RIGHT | SWTX.ALIGN_VERTICAL_CENTER, rect); } return; } Color textColor; Color backColor; Color vBorderColor; Color hBorderColor; if (focus) { textColor = m_Display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT); backColor = (m_Display.getSystemColor(SWT.COLOR_LIST_SELECTION)); vBorderColor = m_Display.getSystemColor(SWT.COLOR_LIST_SELECTION); hBorderColor = m_Display.getSystemColor(SWT.COLOR_LIST_SELECTION); } else { textColor = m_Display.getSystemColor(SWT.COLOR_LIST_FOREGROUND); backColor = m_Display.getSystemColor(SWT.COLOR_LIST_BACKGROUND); vBorderColor = m_Display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); hBorderColor = m_Display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); } gc.setForeground(hBorderColor); gc.drawLine(rect.x, rect.y + rect.height, rect.x + rect.width, rect.y + rect.height); gc.setForeground(vBorderColor); gc.drawLine(rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + rect.height); gc.setBackground(backColor); gc.setForeground(textColor); gc.fillRectangle(rect); SWTX.drawTextImage(gc, content.toString(), SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER, null, SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER, rect.x + 3, rect.y, rect.width - 3, rect.height); }
From source file:PrintKTableExample.java
public TownExampleRenderer() { m_Display = Display.getCurrent(); }
From source file:PrintKTableExample.java
public TownExampleContent(String name, String country) { this.name = name; this.country = country; image = loadImageResource(Display.getCurrent(), "/gfx/" + name + ".gif"); System.out.println(image);/*from ww w . jav a2 s . co m*/ notes = "Double click to edit and use \n" + "Shift+Enter to start a new line..."; }