001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.propertiesview;
016:
017: import java.awt.Component;
018: import java.awt.Cursor;
019: import java.awt.Font;
020: import java.awt.event.MouseAdapter;
021: import java.awt.event.MouseEvent;
022: import java.awt.event.MouseMotionAdapter;
023:
024: import javax.swing.JTable;
025: import javax.swing.ListSelectionModel;
026: import javax.swing.UIManager;
027: import javax.swing.table.AbstractTableModel;
028: import javax.swing.table.DefaultTableCellRenderer;
029: import javax.swing.table.TableColumn;
030:
031: import com.metaboss.applications.designstudio.Application;
032:
033: /* Properties panel table */
034:
035: public class PropertiesTable extends JTable {
036: private TableColumn mFirstColumn = null;
037: private TableColumn mSecondColumn = null;
038: private boolean mMoving = false;
039: private boolean mLoading = true;
040:
041: public PropertiesTable(AbstractTableModel pModel) {
042: super (pModel);
043:
044: setTableHeader(null);
045: setCellSelectionEnabled(false);
046: setRowSelectionAllowed(false);
047: setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
048: setGridColor(UIManager.getColor("control").darker());
049: setBackground(UIManager.getColor("control"));
050:
051: mFirstColumn = getColumnModel().getColumn(0);
052: mSecondColumn = getColumnModel().getColumn(1);
053:
054: mFirstColumn.setWidth(getFirstColumnWidth());
055: mFirstColumn.setMinWidth(getFirstColumnWidth());
056: mFirstColumn.setMaxWidth(getFirstColumnWidth());
057: mFirstColumn.setCellRenderer(new PropertiesCellrenderer(true));
058:
059: mSecondColumn
060: .setCellRenderer(new PropertiesCellrenderer(false));
061:
062: addMouseMotionListener(new TableMouseMotionAdapter(this ));
063: addMouseListener(new TableMouseAdapter());
064:
065: mLoading = false;
066: }
067:
068: public int getFirstColumnWidth() {
069: return 180;
070: }
071:
072: protected void processMouseMotionEvent(MouseEvent e) {
073: super .processMouseMotionEvent(e);
074: if (mMoving)
075: setFirstColumnWidth(e.getX());
076: }
077:
078: public void reshape(int x, int y, int w, int h) {
079: super .reshape(x, y, w, h);
080: if (!mLoading && getWidth() > 0)
081: setFirstColumnWidth(mFirstColumn.getWidth());
082: }
083:
084: private boolean isMoveCursor(int x) {
085: return (x > mFirstColumn.getWidth() - 5 && x < mFirstColumn
086: .getWidth() + 5);
087: }
088:
089: private void setFirstColumnWidth(int pWidth) {
090: if (pWidth < 20)
091: pWidth = 20;
092: if (pWidth > getWidth() - 20)
093: pWidth = getWidth() - 20;
094:
095: mFirstColumn.setWidth(pWidth);
096: mFirstColumn.setMinWidth(pWidth);
097: mFirstColumn.setMaxWidth(pWidth);
098: }
099:
100: /* Mouse Adapter class */
101:
102: public class TableMouseAdapter extends MouseAdapter {
103: public void mousePressed(MouseEvent e) {
104: super .mousePressed(e);
105: if (isMoveCursor(e.getX()))
106: mMoving = true;
107: }
108:
109: public void mouseReleased(MouseEvent e) {
110: super .mouseReleased(e);
111: mMoving = false;
112: }
113: }
114:
115: /* Table Mouse Moution Adapter class */
116:
117: public class TableMouseMotionAdapter extends MouseMotionAdapter {
118: private JTable mTable = null;
119:
120: public TableMouseMotionAdapter(JTable pTable) {
121: super ();
122: mTable = pTable;
123: }
124:
125: public void mouseMoved(MouseEvent e) {
126: if (isMoveCursor(e.getX()))
127: mTable.setCursor(new Cursor(Cursor.W_RESIZE_CURSOR));
128: else
129: mTable.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
130: }
131: }
132:
133: /* Cell Renderer */
134:
135: public class PropertiesCellrenderer extends
136: DefaultTableCellRenderer {
137: private boolean mUseFont = false;
138:
139: public PropertiesCellrenderer(boolean pUseFont) {
140: super ();
141: mUseFont = pUseFont;
142: }
143:
144: public void setFont(Font font) {
145: if (mUseFont)
146: super .setFont(Application.DEFAULT_FONT_BOLD);
147: else
148: super .setFont(font);
149: }
150:
151: public Component getTableCellRendererComponent(JTable table,
152: Object value, boolean isSelected, boolean hasFocus,
153: int row, int column) {
154: if (!getCellSelectionEnabled()) {
155: this .setBackground(UIManager.getColor("control"));
156: super .getTableCellRendererComponent(table, value,
157: false, false, row, column);
158: return this;
159: } else
160: return super.getTableCellRendererComponent(table,
161: value, isSelected, hasFocus, row, column);
162: }
163: }
164: }
|