package com.dwave.util; /* * DockingPanel * * Copyright (C) 2000 D-Wave Systems Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import javax.swing.*; import java.util.Hashtable; import java.util.Enumeration; import java.awt.event.*; import java.awt.*; import com.dwave.layout.*; import com.dwave.gui.DWaveToolbar; /** * @author Michael Coury * @author J.P. Hilton * @version 1.0 10/20/2000 * * @see com.dwave.gui.DWaveToolbar * @see com.dwave.util.DockingException */ public class DockingPanel extends JPanel implements java.io.Serializable { int orientation; Hashtable toolbarStorage; int totalx, totaly; public static final int VERTICAL = 0, HORIZONTAL = 1; public DockingPanel() { } public DockingPanel(int newOrientation) { super (); if (newOrientation == 0 || newOrientation == 1) { orientation = newOrientation; if(orientation == DockingPanel.HORIZONTAL) { FlowLayout flowLayout = new FlowLayout(FlowLayout.LEFT); this.setLayout (flowLayout); } else { VerticalFlowLayout flowLayout = new VerticalFlowLayout(VerticalFlowLayout.TOP); this.setLayout (flowLayout); } this.setVisible(true); toolbarStorage = new Hashtable(0, 0.75f); } } public int getOrientation () { return orientation; } public void setOrientation(int orientation) { this.orientation = orientation; } public void trackToolbar(MouseEvent me, DWaveToolbar aToolbar) { if(!aToolbar.isDocked()) aToolbar.setDragHandleColor(Color.red); } public void dockToolbar(DWaveToolbar aToolbar) { if(!aToolbar.isDocked()) { aToolbar.setOwner(this); if(aToolbar.getOrientation() != this.orientation) try { aToolbar.setOrientation(this.orientation); aToolbar.toolbarLayout(); } catch(DockingException de) { de.printStackTrace(); } JPanel bar = aToolbar.getPanel(); aToolbar.setDragHandleColor(Color.darkGray); toolbarStorage.put(aToolbar.getTitle(), bar); int w = bar.getWidth(), h = bar.getHeight(); aToolbar.setDocked(true); switch(orientation) { case(DockingPanel.HORIZONTAL): this.add(bar); totalx += w; break; case(DockingPanel.VERTICAL): this.add(bar); totaly += h; break; default: break; } bar.setVisible(true); } } public void undockToolbar(DWaveToolbar aToolbar) { if(aToolbar.getOrientation() != DockingPanel.HORIZONTAL) { aToolbar.setOrientation(DockingPanel.HORIZONTAL); try { aToolbar.toolbarLayout(); } catch(DockingException de) { de.printStackTrace(); } } toolbarStorage.remove(aToolbar.getTitle()); } }