📄 gantttreetable.java
字号:
public void setID(String id) { this.id = id; } public void setDisplayed(boolean disp) { this.displayed = disp; } public boolean isDisplayed() { return this.displayed; } public String getID() { return this.id; } public void setOrder(int order) { this.order = order; } public int getOrder() { return this.order; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } public Object clone() { DisplayedColumn dc = new DisplayedColumn(this.id); dc.setDisplayed(this.isDisplayed()); dc.setOrder(this.getOrder()); dc.setWidth(this.getWidth()); return dc; } public String toString() { return "[ID = " + id + ", displayed = " + displayed + ", order = " + order + "]"; } /* * (non-Javadoc) * * @see java.lang.Comparable#compareTo(java.lang.Object) */ public int compareTo(Object o) { if (o == null) return 0; if (o instanceof DisplayedColumn) { DisplayedColumn dc = (DisplayedColumn) o; if (this.order != dc.order) return this.order - dc.order; return this.id.compareTo(dc.id); } return 0; } } /** * This actionListener manages the column to be hiden or displayed. It has a * TableColumn and hide it or display it * * @author bbaranne Mar 1, 2005 */ class ColumnKeeper implements ActionListener { /** * the initial index of the table column. */ private int index; /** * True if the table column is displayed, false otherwise. */ private boolean isShown = true; /** * The managed table column. */ protected TableColumn column; /** * Creates a new ColumnKeeper for the given TableColumn. * * @param tc * TableColumn to manage. */ public ColumnKeeper(TableColumn tc) { column = tc; index = column.getModelIndex(); } /** * Set the initial index of the table column. * * @param initIndex * The initial index of the table column. */ public void setInitIndex(int initIndex) { index = initIndex; } /** * Returns the initial index of the table column. * * @return The initial index of the table column. */ public int getInitIndex() { return index; } /** * Hides the table column. */ void hide() { getTable().getColumnModel().removeColumn(column); isShown = false; String name = (String) column.getHeaderValue(); String id = getIdForName(name); Iterator it = listDisplayedColumns.iterator(); while (it.hasNext()) { DisplayedColumn dc = (DisplayedColumn) it.next(); if (dc.getID().equals(id)) dc.setDisplayed(false); } // Thread t = new Thread(){ // public void run(){ calculateWidth(); revalidate(); // } // }; // SwingUtilities.invokeLater(t); } /** * Shows the table column. */ void show() { boolean reloadInfo = false; getTable().getColumnModel().addColumn(column); try { int columnViewIndexOld = index; int columnModelIndexActual = column.getModelIndex(); if (column.getIdentifier().equals( GanttTreeTableModel.strColInfo)) reloadInfo = true; int columnViewIndexActual = getTable() .convertColumnIndexToView(columnModelIndexActual); getTable() .moveColumn(columnViewIndexActual, columnViewIndexOld); } catch (IllegalArgumentException e) { index = getTable().getModel().getColumnCount() - 1; } isShown = true; String name = (String) column.getHeaderValue(); String id = getIdForName(name); boolean found = false; Iterator it = listDisplayedColumns.iterator(); while (it.hasNext()) { DisplayedColumn dc = (DisplayedColumn) it.next(); if (dc.getID().equals(id)) { dc.setDisplayed(true); found = true; } } if (!found && id != null) { DisplayedColumn dc = new DisplayedColumn(id); dc.setDisplayed(true); listDisplayedColumns.add(dc); } if (reloadInfo) if (Mediator.getDelayManager() != null) Mediator.getDelayManager().fireDelayObservation(); // Thread t = new Thread(){ // public void run(){ calculateWidth(); revalidate(); // } // }; // SwingUtilities.invokeLater(t); } public void actionPerformed(ActionEvent e) { Mediator.getGanttProjectSingleton().getUndoManager().undoableEdit( "HIDE OR SHOW A COLUMN", new Runnable() { public void run() { if (!isShown) show(); else hide(); getTable().repaint(); } }); } } /** * This class handles the mouse actions on the treetable header. * * @author bbaranne Mar 1, 2005 * @version 1.0 Show the popupMenu when popup is triggered. */ class HeaderMouseListener extends MouseAdapter { /** * Creates a new HeaderMouseListener */ public HeaderMouseListener() { super(); } /* * Something ugly !! TODO find a means to display the popupmenu with the * right UI. */ boolean first = false; /** * @inheritDoc Shows the popupMenu to hide/show columns and to add * custom columns. */ public void mousePressed(MouseEvent e) { handlePopupTrigger(e); } public void mouseReleased(MouseEvent e) { handlePopupTrigger(e); } private void handlePopupTrigger(MouseEvent e) { if (e.isPopupTrigger()) { createPopupMenu(); Component c = (Component) e.getSource(); // reorderPopuMenu(); popupMenu.show(c, e.getX(), e.getY()); clickPoint = e.getPoint();// popupMenu.getLocationOnScreen(); CustomColumn cc = null; try { cc = Mediator.getCustomColumnsStorage().getCustomColumn( getTable().getColumnName( getTable().columnAtPoint(e.getPoint()))); } catch (CustomColumnsException e1) { // TODO Auto-generated catch block // e1.printStackTrace(); } if (cc != null) jmiDeleteColumn.setEnabled(true); else jmiDeleteColumn.setEnabled(false); } } } /** * The class replaces the cell editor used in the hierarchical column of the * tree table. * * @author bbaranne (Benoit Baranne) */ class NameCellEditor extends DefaultCellEditor { private JTextField field = null; public NameCellEditor() { super(new JTextField()); field = (JTextField) this.editorComponent; } public Component getTableCellEditorComponent(JTable arg0, Object arg1, boolean arg2, int arg3, int arg4) { final JTextField result = (JTextField) super.getTableCellEditorComponent(arg0, arg1, arg2, arg3, arg4); result.selectAll();// result.addFocusListener(new FocusAdapter() {// public void focusGained(FocusEvent arg0) {// super.focusGained(arg0);// ((JTextComponent)result).selectAll();// }//// public void focusLost(FocusEvent arg0) {// // TODO Auto-generated method stub// super.focusLost(arg0);// }// // });// return result; }// public void requestFocus() { SwingUtilities.invokeLater(new Runnable() { public void run() { field.requestFocus(); field.selectAll(); } }); } } /** * This class repaints the GraphicArea and the table every time the table * model has been modified. TODO Add the refresh functionnality when * available. * * @author Benoit Baranne */ class ModelListener implements TableModelListener { public void tableChanged(TableModelEvent e) { // Mediator.getGanttProjectSingleton().getArea().repaint(); // getTable().repaint(); Mediator.getGanttProjectSingleton().repaint(); } } public void editNewTask(Task t) { TreePath selectedPath = getTree().getSelectionPath(); int c = getTable().convertColumnIndexToView( getTable().getColumn(GanttTreeTableModel.strColName) .getModelIndex()); NameCellEditor nameCellEditor = (NameCellEditor) getTable().getCellEditor(-1, c); getTreeTable().editCellAt(getTree().getRowForPath(selectedPath), c); nameCellEditor.requestFocus(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -